summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <schulte.eric@gmail.com>2011-02-27 11:01:56 -0700
committerEric Schulte <schulte.eric@gmail.com>2011-02-27 11:01:56 -0700
commit563994842d44f049c98ef0dcf7be94006ce1d9ee (patch)
tree0e3e8d514148177dfddfe2b89f6695ad6bb57d4d
parentdd31a84af65dfcadb8d334ea0d92c24d86fd9491 (diff)
downloadorg-mode-563994842d44f049c98ef0dcf7be94006ce1d9ee.tar.gz
ob-exp: better caching on export
- calling org-babel-process-params on the parameters before the hash is calculated - calculating the hash before the noweb references are expanded * lisp/ob-exp.el (org-babel-exp-src-block): When block will eventually be evaluated, pre-calculate the hash before noweb expansion, and expand the parameters before hash calculation. (org-babel-exp-do-export): Pass pre-calculated hash through to `org-babel-exp-results'. (org-babel-exp-results): Compare pre-calculated hash to results hash.
-rw-r--r--lisp/ob-exp.el35
1 files changed, 20 insertions, 15 deletions
diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el
index c99defc..67566d9 100644
--- a/lisp/ob-exp.el
+++ b/lisp/ob-exp.el
@@ -120,17 +120,21 @@ none ----- do not display either code or results upon export"
(goto-char (match-beginning 0))
(let* ((info (org-babel-get-src-block-info 'light))
(lang (nth 0 info))
- (raw-params (nth 2 info)))
+ (raw-params (nth 2 info)) hash)
;; bail if we couldn't get any info from the block
(when info
- (org-babel-exp-in-export-file
- (setf (nth 2 info)
- (org-babel-merge-params
- org-babel-default-header-args
- (org-babel-params-from-buffer)
- (org-babel-params-from-properties lang)
- (if (boundp lang-headers) (eval lang-headers) nil)
- raw-params)))
+ ;; if we're actually going to need the parameters
+ (when (member (cdr (assoc :exports (nth 2 info))) '("both" "results"))
+ (org-babel-exp-in-export-file
+ (setf (nth 2 info)
+ (org-babel-process-params
+ (org-babel-merge-params
+ org-babel-default-header-args
+ (org-babel-params-from-buffer)
+ (org-babel-params-from-properties lang)
+ (if (boundp lang-headers) (eval lang-headers) nil)
+ raw-params))))
+ (setf hash (org-babel-sha1-hash info)))
;; expand noweb references in the original file
(setf (nth 1 info)
(if (and (cdr (assoc :noweb (nth 2 info)))
@@ -138,7 +142,7 @@ none ----- do not display either code or results upon export"
(org-babel-expand-noweb-references
info (get-file-buffer org-current-export-file))
(nth 1 info)))
- (org-babel-exp-do-export info 'block)))))
+ (org-babel-exp-do-export info 'block hash)))))
(defun org-babel-exp-inline-src-blocks (start end)
"Process inline source blocks between START and END for export.
@@ -224,7 +228,7 @@ options are taken from `org-babel-default-header-args'."
(setq end (+ end (- (length replacement) (length (match-string 0)))))
(if replacement (replace-match replacement t t))))))
-(defun org-babel-exp-do-export (info type)
+(defun org-babel-exp-do-export (info type &optional hash)
"Return a string with the exported content of a code block.
The function respects the value of the :exports header argument."
(flet ((silently () (let ((session (cdr (assoc :session (nth 2 info)))))
@@ -234,16 +238,17 @@ The function respects the value of the :exports header argument."
(case (intern (or (cdr (assoc :exports (nth 2 info))) "code"))
('none (silently) (clean) "")
('code (silently) (clean) nil)
- ('results (org-babel-exp-results info type) "")
- ('both (org-babel-exp-results info type) nil))))
+ ('results (org-babel-exp-results info type nil hash) "")
+ ('both (org-babel-exp-results info type nil hash) nil))))
-(defun org-babel-exp-results (info type &optional silent)
+(defun org-babel-exp-results (info type &optional silent hash)
"Evaluate and return the results of the current code block for export.
Results are prepared in a manner suitable for export by org-mode.
This function is called by `org-babel-exp-do-export'. The code
block will be evaluated. Optional argument SILENT can be used to
inhibit insertion of results into the buffer."
- (when org-export-babel-evaluate
+ (when (and org-export-babel-evaluate
+ (not (equal hash (org-babel-result-hash))))
(let ((lang (nth 0 info))
(body (nth 1 info)))
(setf (nth 2 info) (org-babel-exp-in-export-file