summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <eric.schulte@gmx.com>2012-01-11 10:13:37 -0700
committerEric Schulte <eric.schulte@gmx.com>2012-01-11 10:15:20 -0700
commitabf3060e47f7445cfd070921d268a3aff206c992 (patch)
tree501a352096e5425d6c4fe767d6969635da059ffb
parent7423c15d3e28780c8489dd5fe9066932a53f23e7 (diff)
downloadorg-mode-abf3060e47f7445cfd070921d268a3aff206c992.tar.gz
new "no-export" option to :noweb header argument, and consolidated noweb logic
* lisp/ob-exp.el (org-babel-exp-src-block): Use `org-babel-noweb-p'. (org-babel-exp-inline-src-blocks): Use `org-babel-noweb-p'. * lisp/ob-tangle.el (org-babel-tangle-collect-blocks): Use `org-babel-noweb-p'. * lisp/ob.el (org-babel-execute-src-block): Use `org-babel-noweb-p'. (org-babel-expand-src-block): Use `org-babel-noweb-p'. (org-babel-load-in-session): Use `org-babel-noweb-p'. (org-babel-merge-params): Use `org-babel-noweb-p'. (org-babel-noweb-p): New function used to determine if noweb expansion should be carried out in a given context.
-rw-r--r--lisp/ob-exp.el6
-rw-r--r--lisp/ob-tangle.el6
-rw-r--r--lisp/ob.el31
3 files changed, 23 insertions, 20 deletions
diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el
index bfb3aa8..a45439f 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 0b4eaf1..d7c4d7e 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 b51cc51..43e2b72 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.