diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el index bfb3aa85b..a45439fb0 100644 --- a/lisp/ob-exp.el +++ b/lisp/ob-exp.el @@ -110,8 +110,7 @@ none ----- do not display either code or results upon export" (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))) - (string= "yes" (cdr (assoc :noweb (nth 2 info))))) + (if (org-babel-noweb-p (nth 2 info) :export) (org-babel-expand-noweb-references info (get-file-buffer org-current-export-file)) (nth 1 info))) @@ -133,8 +132,7 @@ options and are taken from `org-babel-default-inline-header-args'." (unless (org-babel-in-example-or-verbatim) ;; expand noweb references in the original file (setf (nth 1 info) - (if (and (cdr (assoc :noweb params)) - (string= "yes" (cdr (assoc :noweb params)))) + (if (org-babel-noweb-p params :export) (org-babel-expand-noweb-references info (get-file-buffer org-current-export-file)) (nth 1 info))) diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index 0b4eaf1fa..d7c4d7e9c 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -342,11 +342,7 @@ code blocks by language." body params (and (fboundp assignments-cmd) (funcall assignments-cmd params)))))) - (if (and (cdr (assoc :noweb params)) ;; expand noweb refs - (let ((nowebs (split-string - (cdr (assoc :noweb params))))) - (or (member "yes" nowebs) - (member "tangle" nowebs)))) + (if (org-babel-noweb-p params :tangle) (org-babel-expand-noweb-references info) (nth 1 info))))) (comment diff --git a/lisp/ob.el b/lisp/ob.el index b51cc513b..43e2b726d 100644 --- a/lisp/ob.el +++ b/lisp/ob.el @@ -482,12 +482,9 @@ block." (new-hash (when cache? (org-babel-sha1-hash info))) (old-hash (when cache? (org-babel-current-result-hash))) (body (setf (nth 1 info) - (let ((noweb (cdr (assoc :noweb params)))) - (if (and noweb - (or (string= "yes" noweb) - (string= "tangle" noweb))) - (org-babel-expand-noweb-references info) - (nth 1 info))))) + (if (org-babel-noweb-p params :eval) + (org-babel-expand-noweb-references info) + (nth 1 info)))) (dir (cdr (assoc :dir params))) (default-directory (or (and dir (file-name-as-directory dir)) default-directory)) @@ -561,8 +558,7 @@ arguments and pop open the results in a preview buffer." (lambda (el1 el2) (string< (symbol-name (car el1)) (symbol-name (car el2))))))) (body (setf (nth 1 info) - (if (and (cdr (assoc :noweb params)) - (string= "yes" (cdr (assoc :noweb params)))) + (if (org-babel-noweb-p params :eval) (org-babel-expand-noweb-references info) (nth 1 info)))) (expand-cmd (intern (concat "org-babel-expand-body:" lang))) (assignments-cmd (intern (concat "org-babel-variable-assignments:" @@ -657,8 +653,7 @@ session." (lang (nth 0 info)) (params (nth 2 info)) (body (setf (nth 1 info) - (if (and (cdr (assoc :noweb params)) - (string= "yes" (cdr (assoc :noweb params)))) + (if (org-babel-noweb-p params :eval) (org-babel-expand-noweb-references info) (nth 1 info)))) (session (cdr (assoc :session params))) @@ -1954,7 +1949,7 @@ parameters when merging lists." (:tangle ;; take the latest -- always overwrite (setq tangle (or (list (cdr pair)) tangle))) (:noweb - (setq noweb (e-merge '(("yes" "no" "tangle")) noweb + (setq noweb (e-merge '(("yes" "no" "tangle" "no-export")) noweb (split-string (or (cdr pair) ""))))) (:cache (setq cache (e-merge '(("yes" "no")) cache @@ -1987,6 +1982,20 @@ This results in much faster noweb reference expansion but does not properly allow code blocks to inherit the \":noweb-ref\" header argument from buffer or subtree wide properties.") +(defun org-babel-noweb-p (params context) + "Check if PARAMS require expansion in CONTEXT. +CONTEXT may be one of :tangle, :export or :eval." + (flet ((intersection (as bs) + (when as + (if (member (car as) bs) + (car as) + (intersection (cdr as) bs))))) + (intersection (case context + (:tangle '("yes" "tangle" "no-export")) + (:eval '("yes" "no-export")) + (:export '("yes"))) + (split-string (or (cdr (assoc :noweb params)) ""))))) + (defun org-babel-expand-noweb-references (&optional info parent-buffer) "Expand Noweb references in the body of the current source code block.