瀏覽代碼

named and caching call lines working

* lisp/ob-core.el (org-babel-current-result-hash): Additional info
  argument so that named call line results may be found.
  (org-babel-set-current-result-hash): Additional info argument so
  that named call line results may be found.
* lisp/ob-lob.el (org-babel-lob-execute): Passing info to hash finding
  functions so that named results may be found.
Eric Schulte 11 年之前
父節點
當前提交
cd3bc12a29
共有 3 個文件被更改,包括 31 次插入17 次删除
  1. 4 4
      lisp/ob-core.el
  2. 5 3
      lisp/ob-lob.el
  3. 22 10
      testing/lisp/test-ob-lob.el

+ 4 - 4
lisp/ob-core.el

@@ -1246,14 +1246,14 @@ the current subtree."
         (when (org-called-interactively-p 'interactive) (message hash))
         hash))))
 
-(defun org-babel-current-result-hash ()
+(defun org-babel-current-result-hash (&optional info)
   "Return the current in-buffer hash."
-  (org-babel-where-is-src-block-result)
+  (org-babel-where-is-src-block-result nil info)
   (org-no-properties (match-string 5)))
 
-(defun org-babel-set-current-result-hash (hash)
+(defun org-babel-set-current-result-hash (hash info)
   "Set the current in-buffer hash to HASH."
-  (org-babel-where-is-src-block-result)
+  (org-babel-where-is-src-block-result nil info)
   (save-excursion (goto-char (match-beginning 5))
 		  (mapc #'delete-overlay (overlays-at (point)))
 		  (forward-char org-babel-hash-show)

+ 5 - 3
lisp/ob-lob.el

@@ -154,17 +154,19 @@ if so then run the appropriate source block from the Library."
 				  (cons :c-var (cdr (assoc :var params)))
 				  (assq-delete-all :var (copy-tree params))))
 				(subseq pre-info 3))))))
-	 (old-hash (when cache-p (org-babel-current-result-hash)))
+	 (old-hash (when cache-p (org-babel-current-result-hash pre-info)))
 	 (org-babel-current-src-block-location (point-marker)))
     (if (and cache-p (equal new-hash old-hash))
-	(save-excursion (goto-char (org-babel-where-is-src-block-result))
+	(save-excursion (goto-char (org-babel-where-is-src-block-result
+				    nil pre-info))
 			(forward-line 1)
 			(message "%S" (org-babel-read-result)))
       (prog1 (let* ((proc-params (org-babel-process-params pre-params))
 		     org-confirm-babel-evaluate)
 	       (org-babel-execute-src-block nil (funcall mkinfo proc-params)))
 	;; update the hash
-	(when new-hash (org-babel-set-current-result-hash new-hash))))))
+	(when new-hash
+	  (org-babel-set-current-result-hash new-hash pre-info))))))
 
 (provide 'ob-lob)
 

+ 22 - 10
testing/lisp/test-ob-lob.el

@@ -105,29 +105,34 @@ for export
     (should (progn (org-export-execute-babel-code) t))))
 
 (ert-deftest test-ob-lob/caching-call-line ()
-  (require 'ox)
-  (let ((temporary-value-for-test nil))
+  (let ((temporary-value-for-test 0))
     (org-test-with-temp-text "
 #+name: call-line-caching-example
 #+begin_src emacs-lisp :var bar=\"baz\"
-  (setq temporary-value-for-test (not temporary-value-for-test))
+  (setq temporary-value-for-test (+ 1 temporary-value-for-test))
 #+end_src
 
 #+call: call-line-caching-example(\"qux\") :cache yes
 "
       (goto-char (point-max)) (forward-line -1)
       ;; first execution should flip value to t
-      (should (org-babel-lob-execute (org-babel-lob-get-info)))
+      (should (equal (org-babel-lob-execute (org-babel-lob-get-info)) 1))
       ;; if cached, second evaluation will retain the t value
-      (should (org-babel-lob-execute (org-babel-lob-get-info))))))
+      ;;
+      ;; Note: This instance tests for equality with "1".  We would
+      ;; prefer if the cached result returned was actually 1, however
+      ;; this is not the current behavior so this test is encoding
+      ;; undesired behavior (because the current goal is simply to see
+      ;; that caching is used on call lines).
+      ;;
+      (should (equal (org-babel-lob-execute (org-babel-lob-get-info)) "1")))))
 
 (ert-deftest test-ob-lob/named-caching-call-line ()
-  (require 'ox)
-  (let ((temporary-value-for-test nil))
+  (let ((temporary-value-for-test 0))
     (org-test-with-temp-text "
 #+name: call-line-caching-example
 #+begin_src emacs-lisp :var bar=\"baz\"
-  (setq temporary-value-for-test (not temporary-value-for-test))
+  (setq temporary-value-for-test (+ 1 temporary-value-for-test))
 #+end_src
 
 #+name: call-line-caching-called
@@ -135,9 +140,16 @@ for export
 "
       (goto-char (point-max)) (forward-line -1)
       ;; first execution should flip value to t
-      (should (org-babel-lob-execute (org-babel-lob-get-info)))
+      (should (equal (org-babel-lob-execute (org-babel-lob-get-info)) 1))
       ;; if cached, second evaluation will retain the t value
-      (should (org-babel-lob-execute (org-babel-lob-get-info))))))
+      ;;
+      ;; Note: This instance tests for equality with "1".  We would
+      ;; prefer if the cached result returned was actually 1, however
+      ;; this is not the current behavior so this test is encoding
+      ;; undesired behavior (because the current goal is simply to see
+      ;; that caching is used on call lines).
+      ;;
+      (should (equal (org-babel-lob-execute (org-babel-lob-get-info)) "1")))))
 
 (provide 'test-ob-lob)