浏览代码

New option to update intermediate in-buffer results

* lisp/ob-ref.el (org-babel-update-intermediate): New custom variable.
  (org-babel-ref-resolve): Optionally update the in-buffer results of
  code blocks which are evaluated to resolve references.
Eric Schulte 13 年之前
父节点
当前提交
3693952e3b
共有 2 个文件被更改,包括 33 次插入1 次删除
  1. 6 1
      lisp/ob-ref.el
  2. 27 0
      testing/lisp/test-ob.el

+ 6 - 1
lisp/ob-ref.el

@@ -66,6 +66,9 @@
 (defvar org-babel-ref-split-regexp
   "[ \f\t\n\r\v]*\\(.+?\\)[ \f\t\n\r\v]*=[ \f\t\n\r\v]*\\(.+\\)[ \f\t\n\r\v]*")
 
+(defcustom org-babel-update-intermediate nil
+  "Update the in-buffer results of code blocks executed to resolve references.")
+
 (defun org-babel-ref-parse (assignment)
   "Parse a variable ASSIGNMENT in a header argument.
 If the right hand side of the assignment has a literal value
@@ -189,7 +192,9 @@ the variable."
 		  (table        (org-babel-read-table))
 		  (list         (org-babel-read-list))
 		  (file         (org-babel-read-link))
-		  (source-block (org-babel-execute-src-block nil nil params))
+		  (source-block (org-babel-execute-src-block
+				 nil nil (if org-babel-update-intermediate
+					     nil params)))
 		  (lob          (org-babel-execute-src-block
 				 nil lob-info params))
 		  (id           (org-babel-ref-headline-body)))))

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

@@ -504,6 +504,33 @@ on two lines
 "
     (should (= 10 (org-babel-execute-src-block)))))
 
+(ert-deftest test-ob/org-babel-update-intermediate ()
+  (org-test-with-temp-text "#+name: foo
+#+begin_src emacs-lisp
+  2
+#+end_src
+
+#+results: foo
+: 4
+
+#+begin_src emacs-lisp :var it=foo
+  (+ it 1)
+#+end_src"
+    (let ((org-babel-update-intermediate nil))
+      (goto-char (point-min))
+      (org-babel-next-src-block 2)
+      (should (= 3 (org-babel-execute-src-block)))
+      (goto-char (point-min))
+      (forward-line 6)
+      (should (looking-at ": 4")))
+    (let ((org-babel-update-intermediate t))
+      (goto-char (point-min))
+      (org-babel-next-src-block 2)
+      (should (= 3 (org-babel-execute-src-block)))
+      (goto-char (point-min))
+      (forward-line 6)
+      (should (looking-at ": 2")))))
+
 (provide 'test-ob)
 
 ;;; test-ob ends here