Преглед на файлове

improved variable handling for awk code blocks

  Thanks to Greg Minshall for suggesting these changes.

* lisp/ob-awk.el (org-babel-expand-body:awk): Simply return the body
  unmodified.
  (org-babel-execute:awk): Assign variables on the command line using
  the `-v' command line option to awk.
Eric Schulte преди 10 години
родител
ревизия
7469454f54
променени са 1 файла, в които са добавени 9 реда и са изтрити 7 реда
  1. 9 7
      lisp/ob-awk.el

+ 9 - 7
lisp/ob-awk.el

@@ -46,9 +46,6 @@
 
 (defun org-babel-expand-body:awk (body params)
   "Expand BODY according to PARAMS, return the expanded body."
-  (dolist (pair (mapcar #'cdr (org-babel-get-header params :var)))
-    (setf body (replace-regexp-in-string
-                (regexp-quote (format "$%s" (car pair))) (cdr pair) body)))
   body)
 
 (defun org-babel-execute:awk (body params)
@@ -68,10 +65,15 @@ called by `org-babel-execute-src-block'"
 		       (with-temp-file tmp
 			 (insert (org-babel-awk-var-to-awk res)))
 		       tmp))))
-         (cmd (mapconcat #'identity (remove nil (list org-babel-awk-command
-						      "-f" code-file
-						      cmd-line
-						      in-file))
+         (cmd (mapconcat #'identity
+			 (apply #'append
+				(list org-babel-awk-command
+				      "-f" code-file cmd-line)
+				(mapcar (lambda (pair)
+					  (format "-v %s=%s"
+						  (cadr pair) (cddr pair)))
+					(org-babel-get-header params :var))
+				(list in-file))
 			 " ")))
     (org-babel-reassemble-table
      (let ((results