From 3693952e3b36148b9f294a7ccdb361d86a3cdd6f Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Sun, 20 Nov 2011 13:19:01 -0700 Subject: [PATCH] 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. --- lisp/ob-ref.el | 7 ++++++- testing/lisp/test-ob.el | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lisp/ob-ref.el b/lisp/ob-ref.el index 071408787..0ce5e8649 100644 --- a/lisp/ob-ref.el +++ b/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))))) diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index 47d3b16af..de66a9768 100644 --- a/testing/lisp/test-ob.el +++ b/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