Browse Source

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.
Eric Schulte 13 years ago
parent
commit
abf3060e47
3 changed files with 23 additions and 20 deletions
  1. 2 4
      lisp/ob-exp.el
  2. 1 5
      lisp/ob-tangle.el
  3. 20 11
      lisp/ob.el

+ 2 - 4
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)))

+ 1 - 5
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

+ 20 - 11
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.