Browse Source

Merge branch 'master' of orgmode.org:org-mode

Bastien Guerry 13 years ago
parent
commit
8d7aa7dfa8
2 changed files with 35 additions and 9 deletions
  1. 8 1
      doc/org.texi
  2. 27 8
      lisp/ob.el

+ 8 - 1
doc/org.texi

@@ -14001,7 +14001,8 @@ When a code block is tangled or evaluated, whether or not ``noweb''
 references are expanded depends upon the value of the @code{:noweb} header
 references are expanded depends upon the value of the @code{:noweb} header
 argument.  If @code{:noweb yes}, then a Noweb reference is expanded before
 argument.  If @code{:noweb yes}, then a Noweb reference is expanded before
 evaluation.  If @code{:noweb no}, the default, then the reference is not
 evaluation.  If @code{:noweb no}, the default, then the reference is not
-expanded before evaluation.
+expanded before evaluation.  See the @ref{noweb-ref} header argument for
+a more flexible way to resolve noweb references.
 
 
 Note: the default value, @code{:noweb no}, was chosen to ensure that
 Note: the default value, @code{:noweb no}, was chosen to ensure that
 correct code is not broken in a language, such as Ruby, where
 correct code is not broken in a language, such as Ruby, where
@@ -14009,6 +14010,12 @@ correct code is not broken in a language, such as Ruby, where
 syntactically valid in languages that you use, then please consider setting
 syntactically valid in languages that you use, then please consider setting
 the default value.
 the default value.
 
 
+Note: if noweb tangling is slow in large Org-mode files consider setting the
+@code{*org-babel-use-quick-and-dirty-noweb-expansion*} variable to true.
+This will result in faster noweb reference resolution at the expense of not
+correctly resolving inherited values of the @code{:noweb-ref} header
+argument.
+
 @node Key bindings and useful functions, Batch execution, Noweb reference syntax, Working With Source Code
 @node Key bindings and useful functions, Batch execution, Noweb reference syntax, Working With Source Code
 @section Key bindings and useful functions
 @section Key bindings and useful functions
 @cindex code block, key bindings
 @cindex code block, key bindings

+ 27 - 8
lisp/ob.el

@@ -1979,6 +1979,12 @@ parameters when merging lists."
      '(results exports tangle noweb padline cache shebang comments))
      '(results exports tangle noweb padline cache shebang comments))
     params))
     params))
 
 
+(defvar *org-babel-use-quick-and-dirty-noweb-expansion* nil
+  "Set to true to use regular expressions to expand noweb references.
+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-expand-noweb-references (&optional info parent-buffer)
 (defun org-babel-expand-noweb-references (&optional info parent-buffer)
   "Expand Noweb references in the body of the current source code block.
   "Expand Noweb references in the body of the current source code block.
 
 
@@ -2014,6 +2020,8 @@ block but are passed literally to the \"example-block\"."
          (lang (nth 0 info))
          (lang (nth 0 info))
          (body (nth 1 info))
          (body (nth 1 info))
 	 (comment (string= "noweb" (cdr (assoc :comments (nth 2 info)))))
 	 (comment (string= "noweb" (cdr (assoc :comments (nth 2 info)))))
+	 (rx-prefix (concat "\\(" org-babel-src-name-regexp "\\|"
+			    ":noweb-ref[ \t]+" "\\)"))
          (new-body "") index source-name evaluate prefix blocks-in-buffer)
          (new-body "") index source-name evaluate prefix blocks-in-buffer)
     (flet ((nb-add (text) (setq new-body (concat new-body text)))
     (flet ((nb-add (text) (setq new-body (concat new-body text)))
 	   (c-wrap (text)
 	   (c-wrap (text)
@@ -2054,21 +2062,32 @@ block but are passed literally to the \"example-block\"."
 		    (when (org-babel-ref-goto-headline-id source-name)
 		    (when (org-babel-ref-goto-headline-id source-name)
 		      (org-babel-ref-headline-body)))
 		      (org-babel-ref-headline-body)))
 		  ;; find the expansion of reference in this buffer
 		  ;; find the expansion of reference in this buffer
-		  (let (expansion)
+		  (let ((rx (concat rx-prefix source-name))
+			expansion)
 		    (save-excursion
 		    (save-excursion
 		      (goto-char (point-min))
 		      (goto-char (point-min))
-		      (org-babel-map-src-blocks nil
-			(let ((i (org-babel-get-src-block-info 'light)))
-			  (when (equal (or (cdr (assoc :noweb-ref (nth 2 i)))
-					   (nth 4 i))
-				       source-name)
-			    (let ((body (org-babel-expand-noweb-references i)))
+		      (if *org-babel-use-quick-and-dirty-noweb-expansion*
+			  (while (re-search-forward rx nil t)
+			    (let* ((i (org-babel-get-src-block-info 'light))
+				   (body (org-babel-expand-noweb-references i)))
 			      (if comment
 			      (if comment
 				  ((lambda (cs)
 				  ((lambda (cs)
 				     (concat (c-wrap (car cs)) "\n"
 				     (concat (c-wrap (car cs)) "\n"
 					     body "\n" (c-wrap (cadr cs))))
 					     body "\n" (c-wrap (cadr cs))))
 				   (org-babel-tangle-comment-links i))
 				   (org-babel-tangle-comment-links i))
-				(setq expansion (concat expansion body))))))))
+				(setq expansion (concat expansion body)))))
+			(org-babel-map-src-blocks nil
+			  (let ((i (org-babel-get-src-block-info 'light)))
+			    (when (equal (or (cdr (assoc :noweb-ref (nth 2 i)))
+					     (nth 4 i))
+					 source-name)
+			      (let ((body (org-babel-expand-noweb-references i)))
+				(if comment
+				    ((lambda (cs)
+				       (concat (c-wrap (car cs)) "\n"
+					       body "\n" (c-wrap (cadr cs))))
+				     (org-babel-tangle-comment-links i))
+				  (setq expansion (concat expansion body)))))))))
 		    expansion)
 		    expansion)
 		  ;; possibly raise an error if named block doesn't exist
 		  ;; possibly raise an error if named block doesn't exist
 		  (if (member lang org-babel-noweb-error-langs)
 		  (if (member lang org-babel-noweb-error-langs)