caching in #+call: lines

* lisp/ob.el (org-babel-set-current-result-hash): Change the hash of the
  results for the current code block.
  (org-babel-current-result-hash): Fix documentation.
* lisp/ob-lob.el (org-babel-lob-execute): Don't re-execute the called
  function if the current call line hash matches that in its results.
This commit is contained in:
Eric Schulte 2012-06-28 11:49:47 -06:00
parent 054f99d373
commit 89bb446a0b
2 changed files with 30 additions and 11 deletions

View file

@ -119,16 +119,27 @@ if so then run the appropriate source block from the Library."
(defun org-babel-lob-execute (info)
"Execute the lob call specified by INFO."
(let ((params (org-babel-process-params
(org-babel-merge-params
org-babel-default-header-args
(org-babel-params-from-properties)
(org-babel-parse-header-arguments
(org-babel-clean-text-properties
(concat ":var results="
(mapconcat #'identity (butlast info) " "))))))))
(org-babel-execute-src-block
nil (list "emacs-lisp" "results" params nil nil (nth 2 info)))))
(flet ((mkinfo (p) (list "emacs-lisp" "results" p nil nil (nth 2 info))))
(let* ((pre-params (org-babel-merge-params
org-babel-default-header-args
(org-babel-params-from-properties)
(org-babel-parse-header-arguments
(org-babel-clean-text-properties
(concat ":var results="
(mapconcat #'identity (butlast info) " "))))))
(pre-info (mkinfo pre-params))
(cache? (and (cdr (assoc :cache pre-params))
(string= "yes" (cdr (assoc :cache pre-params)))))
(new-hash (when cache? (org-babel-sha1-hash pre-info)))
(old-hash (when cache? (org-babel-current-result-hash))))
(if (and cache? (equal new-hash old-hash))
(save-excursion (goto-char (org-babel-where-is-src-block-result))
(forward-line 1)
(message "%S" (org-babel-read-result)))
(prog1 (org-babel-execute-src-block
nil (mkinfo (org-babel-process-params pre-params)))
;; update the hash
(org-babel-set-current-result-hash new-hash))))))
(provide 'ob-lob)

View file

@ -1048,10 +1048,18 @@ the current subtree."
(sha1 it))))))
(defun org-babel-current-result-hash ()
"Return the in-buffer hash associated with INFO."
"Return the current in-buffer hash."
(org-babel-where-is-src-block-result)
(org-babel-clean-text-properties (match-string 3)))
(defun org-babel-set-current-result-hash (hash)
"Set the current in-buffer hash to HASH."
(org-babel-where-is-src-block-result)
(save-excursion (goto-char (match-beginning 3))
;; (mapc #'delete-overlay (overlays-at (point)))
(replace-match hash nil nil nil 3)
(org-babel-hide-hash)))
(defun org-babel-hide-hash ()
"Hide the hash in the current results line.
Only the initial `org-babel-hash-show' characters of the hash