فهرست منبع

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.
Eric Schulte 11 سال پیش
والد
کامیت
685b296724
3فایلهای تغییر یافته به همراه32 افزوده شده و 4 حذف شده
  1. 5 3
      lisp/ob-core.el
  2. 4 1
      lisp/ob-ref.el
  3. 23 0
      testing/lisp/test-ob.el

+ 5 - 3
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
 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)))

+ 4 - 1
lisp/ob-ref.el

@@ -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)

+ 23 - 0
testing/lisp/test-ob.el

@@ -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