diff options
author | Eric Schulte <schulte.eric@gmail.com> | 2014-01-18 13:36:07 -0700 |
---|---|---|
committer | Eric Schulte <schulte.eric@gmail.com> | 2014-01-18 13:40:57 -0700 |
commit | cd3bc12a29b7a62a23fc408edf9b81573c5c8d19 (patch) | |
tree | 7ae0ea1f4da14acb070d992164a531a7692db512 | |
parent | 93d272b4498d6f2893c1f8583adcf29f350c58bb (diff) | |
download | org-mode-cd3bc12a29b7a62a23fc408edf9b81573c5c8d19.tar.gz |
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.
-rw-r--r-- | lisp/ob-core.el | 8 | ||||
-rw-r--r-- | lisp/ob-lob.el | 8 | ||||
-rw-r--r-- | testing/lisp/test-ob-lob.el | 32 |
3 files changed, 31 insertions, 17 deletions
diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 5d3f035..95258e9 100644 --- a/lisp/ob-core.el +++ b/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) diff --git a/lisp/ob-lob.el b/lisp/ob-lob.el index d08dbf2..c93198a 100644 --- a/lisp/ob-lob.el +++ b/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) diff --git a/testing/lisp/test-ob-lob.el b/testing/lisp/test-ob-lob.el index 3a4411d..b0d079a 100644 --- a/testing/lisp/test-ob-lob.el +++ b/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) |