summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <schulte.eric@gmail.com>2013-06-25 07:55:32 -0600
committerEric Schulte <schulte.eric@gmail.com>2013-06-25 09:59:56 -0600
commit685b2967247597f75d22cb77896bc8a70503b2c3 (patch)
treea4bbc826a090ec82e6effbeb7c902c41253460bf
parentacb00702d57a6cc2f7e4bc7db2587b2d9a3ab042 (diff)
downloadorg-mode-685b2967247597f75d22cb77896bc8a70503b2c3.tar.gz
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.
-rw-r--r--lisp/ob-core.el8
-rw-r--r--lisp/ob-ref.el5
-rw-r--r--testing/lisp/test-ob.el23
3 files changed, 32 insertions, 4 deletions
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 79df71f..c5ed939 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 a2814ea..5a3c8ba 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 6a8403e..1192589 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