1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-29 07:58:21 +00:00

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

This commit is contained in:
Bastien Guerry 2012-01-02 19:52:50 +01:00
commit 8d7aa7dfa8
2 changed files with 35 additions and 9 deletions

View File

@ -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
argument. If @code{:noweb yes}, then a Noweb reference is expanded before
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
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
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
@section Key bindings and useful functions
@cindex code block, key bindings

View File

@ -1979,6 +1979,12 @@ parameters when merging lists."
'(results exports tangle noweb padline cache shebang comments))
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)
"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))
(body (nth 1 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)
(flet ((nb-add (text) (setq new-body (concat new-body 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)
(org-babel-ref-headline-body)))
;; find the expansion of reference in this buffer
(let (expansion)
(let ((rx (concat rx-prefix source-name))
expansion)
(save-excursion
(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
((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))))))))
(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)
;; possibly raise an error if named block doesn't exist
(if (member lang org-babel-noweb-error-langs)