From 685b2967247597f75d22cb77896bc8a70503b2c3 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Tue, 25 Jun 2013 07:55:32 -0600 Subject: [PATCH] evaluate elisp header args at original call site * lisp/ob-core.el (org-babel-execute-src-block): Ensure that the location is set before anything else is done. * lisp/ob-ref.el (org-babel-ref-parse): Evaluate Emacs Lisp values in header arguments at the location of the original code block. * testing/lisp/test-ob.el (test-ob/location-of-header-arg-eval): Test defending the new header argument evaluation behavior. --- lisp/ob-core.el | 8 +++++--- lisp/ob-ref.el | 5 ++++- testing/lisp/test-ob.el | 23 +++++++++++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 79df71fe2..c5ed93998 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -562,7 +562,11 @@ Optionally supply a value for PARAMS which will be merged with the header arguments specified at the front of the source code block." (interactive) - (let* ((info (if info + (let* ((org-babel-current-src-block-location + (or org-babel-current-src-block-location + (nth 6 info) + (org-babel-where-is-src-block-head))) + (info (if info (copy-tree info) (org-babel-get-src-block-info))) (merged-params (org-babel-merge-params (nth 2 info) params))) @@ -571,8 +575,6 @@ block." (let* ((params (if params (org-babel-process-params merged-params) (nth 2 info))) - (org-babel-current-src-block-location - (or org-babel-current-src-block-location (nth 6 info))) (cachep (and (not arg) (cdr (assoc :cache params)) (string= "yes" (cdr (assoc :cache params))))) (new-hash (when cachep (org-babel-sha1-hash info))) diff --git a/lisp/ob-ref.el b/lisp/ob-ref.el index a2814eae3..5a3c8ba2e 100644 --- a/lisp/ob-ref.el +++ b/lisp/ob-ref.el @@ -83,7 +83,10 @@ the variable." (let ((var (match-string 1 assignment)) (ref (match-string 2 assignment))) (cons (intern var) - (let ((out (org-babel-read ref))) + (let ((out (save-excursion + (when org-babel-current-src-block-location + (goto-char org-babel-current-src-block-location)) + (org-babel-read ref)))) (if (equal out ref) (if (string-match "^\".*\"$" ref) (read ref) diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index 6a8403ef9..11925899e 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -1144,6 +1144,29 @@ echo \"$data\" (org-babel-execute-src-block) (buffer-string))))) +(ert-deftest test-ob/location-of-header-arg-eval () + "Test location of header argument evaluation." + (org-test-with-temp-text " +#+name: top-block +#+begin_src emacs-lisp :var pt=(point) + pt +#+end_src + +#+name: bottom-block +#+begin_src emacs-lisp :var pt=top-block() + pt +#+end_src +" + ;; the value of the second block should be greater than the first + (should + (< (progn (re-search-forward org-babel-src-block-regexp nil t) + (goto-char (match-beginning 0)) + (prog1 (save-match-data (org-babel-execute-src-block)) + (goto-char (match-end 0)))) + (progn (re-search-forward org-babel-src-block-regexp nil t) + (goto-char (match-beginning 0)) + (org-babel-execute-src-block)))))) + (provide 'test-ob) ;;; test-ob ends here -- 2.11.4.GIT