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.
This commit is contained in:
Eric Schulte 2013-06-25 07:55:32 -06:00
parent acb00702d5
commit 685b296724
3 changed files with 32 additions and 4 deletions

View file

@ -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 the header arguments specified at the front of the source code
block." block."
(interactive) (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) (copy-tree info)
(org-babel-get-src-block-info))) (org-babel-get-src-block-info)))
(merged-params (org-babel-merge-params (nth 2 info) params))) (merged-params (org-babel-merge-params (nth 2 info) params)))
@ -571,8 +575,6 @@ block."
(let* ((params (if params (let* ((params (if params
(org-babel-process-params merged-params) (org-babel-process-params merged-params)
(nth 2 info))) (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)) (cachep (and (not arg) (cdr (assoc :cache params))
(string= "yes" (cdr (assoc :cache params))))) (string= "yes" (cdr (assoc :cache params)))))
(new-hash (when cachep (org-babel-sha1-hash info))) (new-hash (when cachep (org-babel-sha1-hash info)))

View file

@ -83,7 +83,10 @@ the variable."
(let ((var (match-string 1 assignment)) (let ((var (match-string 1 assignment))
(ref (match-string 2 assignment))) (ref (match-string 2 assignment)))
(cons (intern var) (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 (equal out ref)
(if (string-match "^\".*\"$" ref) (if (string-match "^\".*\"$" ref)
(read ref) (read ref)

View file

@ -1144,6 +1144,29 @@ echo \"$data\"
(org-babel-execute-src-block) (org-babel-execute-src-block)
(buffer-string))))) (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) (provide 'test-ob)
;;; test-ob ends here ;;; test-ob ends here