summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <schulte.eric@gmail.com>2014-06-06 12:50:14 -0400
committerEric Schulte <schulte.eric@gmail.com>2014-06-06 12:50:14 -0400
commit7469454f548c38a33632dc8e528dba5fd6876d77 (patch)
treeaf119bb21c60cb46d707266a77c87eef534a172f
parent0ba8b4f2ea4cc300d52dd5a5224a4551251fa20b (diff)
downloadorg-mode-7469454f548c38a33632dc8e528dba5fd6876d77.tar.gz
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.
-rw-r--r--lisp/ob-awk.el16
1 files changed, 9 insertions, 7 deletions
diff --git a/lisp/ob-awk.el b/lisp/ob-awk.el
index ed98afd..0429fc7 100644
--- a/lisp/ob-awk.el
+++ b/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