瀏覽代碼

Fix noweb expansion during export

* lisp/ob-core.el (org-babel-sha1-hash): Add optional argument to
  specify context.
(org-babel-execute-src-block): Use new argument.
* lisp/ob-exp.el (org-babel-exp-src-block): Use new argument.
(org-babel-exp-results): Fix context.

Reported-by: Ken Mankoff <mankoff@gmail.com>
<http://lists.gnu.org/r/emacs-orgmode/2018-06/msg00117.html>
Nicolas Goaziou 7 年之前
父節點
當前提交
8e54cafeb2
共有 2 個文件被更改,包括 12 次插入8 次删除
  1. 10 6
      lisp/ob-core.el
  2. 2 2
      lisp/ob-exp.el

+ 10 - 6
lisp/ob-core.el

@@ -645,7 +645,7 @@ block."
       (let* ((params (nth 2 info))
       (let* ((params (nth 2 info))
 	     (cache (let ((c (cdr (assq :cache params))))
 	     (cache (let ((c (cdr (assq :cache params))))
 		      (and (not arg) c (string= "yes" c))))
 		      (and (not arg) c (string= "yes" c))))
-	     (new-hash (and cache (org-babel-sha1-hash info)))
+	     (new-hash (and cache (org-babel-sha1-hash info :eval)))
 	     (old-hash (and cache (org-babel-current-result-hash)))
 	     (old-hash (and cache (org-babel-current-result-hash)))
 	     (current-cache (and new-hash (equal new-hash old-hash))))
 	     (current-cache (and new-hash (equal new-hash old-hash))))
 	(cond
 	(cond
@@ -1221,11 +1221,14 @@ the current subtree."
       (widen))))
       (widen))))
 
 
 ;;;###autoload
 ;;;###autoload
-(defun org-babel-sha1-hash (&optional info)
-  "Generate an sha1 hash based on the value of info."
+(defun org-babel-sha1-hash (&optional info context)
+  "Generate a sha1 hash based on the value of INFO.
+CONTEXT specifies the context of evaluation.  It can be `:eval',
+`:export', `:tangle'.  A nil value means `:eval'."
   (interactive)
   (interactive)
   (let ((print-level nil)
   (let ((print-level nil)
-	(info (or info (org-babel-get-src-block-info))))
+	(info (or info (org-babel-get-src-block-info)))
+	(context (or context :eval)))
     (setf (nth 2 info)
     (setf (nth 2 info)
 	  (sort (copy-sequence (nth 2 info))
 	  (sort (copy-sequence (nth 2 info))
 		(lambda (a b) (string< (car a) (car b)))))
 		(lambda (a b) (string< (car a) (car b)))))
@@ -1253,8 +1256,9 @@ the current subtree."
 	   ;; expanded body
 	   ;; expanded body
 	   (lang (nth 0 info))
 	   (lang (nth 0 info))
 	   (params (nth 2 info))
 	   (params (nth 2 info))
-	   (body (if (org-babel-noweb-p params :eval)
-			   (org-babel-expand-noweb-references info) (nth 1 info)))
+	   (body (if (org-babel-noweb-p params context)
+		     (org-babel-expand-noweb-references info)
+		   (nth 1 info)))
 	   (expand-cmd (intern (concat "org-babel-expand-body:" lang)))
 	   (expand-cmd (intern (concat "org-babel-expand-body:" lang)))
 	   (assignments-cmd (intern (concat "org-babel-variable-assignments:"
 	   (assignments-cmd (intern (concat "org-babel-variable-assignments:"
 					    lang)))
 					    lang)))

+ 2 - 2
lisp/ob-exp.el

@@ -107,7 +107,7 @@ Assume point is at block opening line."
 				   (symbol-value lang-headers))
 				   (symbol-value lang-headers))
 			      (append (org-babel-params-from-properties lang)
 			      (append (org-babel-params-from-properties lang)
 				      (list raw-params)))))))
 				      (list raw-params)))))))
-	  (setf hash (org-babel-sha1-hash info)))
+	  (setf hash (org-babel-sha1-hash info :export)))
 	(org-babel-exp-do-export info 'block hash)))))
 	(org-babel-exp-do-export info 'block hash)))))
 
 
 (defcustom org-babel-exp-call-line-template
 (defcustom org-babel-exp-call-line-template
@@ -376,7 +376,7 @@ block will be evaluated.  Optional argument SILENT can be used to
 inhibit insertion of results into the buffer."
 inhibit insertion of results into the buffer."
   (unless (and hash (equal hash (org-babel-current-result-hash)))
   (unless (and hash (equal hash (org-babel-current-result-hash)))
     (let ((lang (nth 0 info))
     (let ((lang (nth 0 info))
-	  (body (if (org-babel-noweb-p (nth 2 info) :eval)
+	  (body (if (org-babel-noweb-p (nth 2 info) :export)
 		    (org-babel-expand-noweb-references
 		    (org-babel-expand-noweb-references
 		     info org-babel-exp-reference-buffer)
 		     info org-babel-exp-reference-buffer)
 		  (nth 1 info)))
 		  (nth 1 info)))