From 11d31e89c46f348154519664a49d1f2466e9108c Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Mon, 23 Jan 2012 23:57:51 -0700 Subject: [PATCH 1/2] replace org-babel-noweb-separator variable with :noweb-sep header argument * doc/org.texi (noweb-sep): Document new header argument. * lisp/ob.el (org-babel-common-header-args-w-values): Add new header argument. (org-babel-expand-noweb-references): Use header argument rather than customization variable. --- doc/org.texi | 19 ++++++++++++++----- lisp/ob.el | 18 +++++++++--------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index deb8d0dde..5dee1d9ed 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -708,6 +708,7 @@ Specific header arguments * session:: Preserve the state of code evaluation * noweb:: Toggle expansion of noweb references * noweb-ref:: Specify block's noweb reference resolution target +* noweb-sep:: String used to separate noweb references * cache:: Avoid re-evaluating unchanged code blocks * sep:: Delimiter for writing tabular results outside Org * hlines:: Handle horizontal lines in tables @@ -13007,6 +13008,7 @@ argument in lowercase letters. The following header arguments are defined: * session:: Preserve the state of code evaluation * noweb:: Toggle expansion of noweb references * noweb-ref:: Specify block's noweb reference resolution target +* noweb-sep:: String used to separate noweb references * cache:: Avoid re-evaluating unchanged code blocks * sep:: Delimiter for writing tabular results outside Org * hlines:: Handle horizontal lines in tables @@ -13623,7 +13625,7 @@ Note that noweb replacement text that does not contain any newlines will not be affected by this change, so it is still possible to use inline noweb references. -@node noweb-ref, cache, noweb, Specific header arguments +@node noweb-ref, noweb-sep, noweb, Specific header arguments @subsubsection @code{:noweb-ref} When expanding ``noweb'' style references the bodies of all code block with @emph{either} a block name matching the reference name @emph{or} a @@ -13667,11 +13669,18 @@ inheritance}).}. #+END_SRC @end example -The @code{org-babel-noweb-separator} variable holds the string used to -separate accumulate noweb references like those above. By default this -variable holds a newline. +The @code{:noweb-sep} (see @ref{noweb-sep}) header argument holds the string +used to separate accumulate noweb references like those above. By default a +newline is used. -@node cache, sep, noweb-ref, Specific header arguments +@node noweb-sep, cache, noweb-ref, Specific header arguments +@subsubsection @code{:noweb-sep} + +The @code{:noweb-sep} header argument holds the string used to separate +accumulate noweb references (see @ref{noweb-ref}). By default a newline is +used. + +@node cache, sep, noweb-sep, Specific header arguments @subsubsection @code{:cache} The @code{:cache} header argument controls the use of in-buffer caching of diff --git a/lisp/ob.el b/lisp/ob.el index c13d13c4d..a32993a82 100644 --- a/lisp/ob.el +++ b/lisp/ob.el @@ -120,11 +120,6 @@ be used." :group 'org-babel :type 'string) -(defcustom org-babel-noweb-separator "\n" - "String used to separate accumulated noweb references." - :group 'org-babel - :type 'string) - (defvar org-babel-src-name-regexp "^[ \t]*#\\+name:[ \t]*" "Regular expression used to match a source name line.") @@ -388,6 +383,7 @@ then run `org-babel-pop-to-session'." (noeval) (noweb . ((yes no tangle))) (noweb-ref . :any) + (noweb-sep . :any) (padline . ((yes no))) (results . ((file list vector table scalar verbatim) (raw org html latex code pp wrap) @@ -2192,6 +2188,8 @@ block but are passed literally to the \"example-block\"." (while (re-search-forward rx nil t) (let* ((i (org-babel-get-src-block-info 'light)) (body (org-babel-expand-noweb-references i)) + (sep (or (cdr (assoc :noweb-sep (nth 2 i))) + "\n")) (full (if comment ((lambda (cs) (concat (c-wrap (car cs)) "\n" @@ -2199,13 +2197,15 @@ block but are passed literally to the \"example-block\"." (c-wrap (cadr cs)))) (org-babel-tangle-comment-links i)) body))) - (setq expansion (cons full expansion)))) + (setq expansion (cons sep (cons full expansion))))) (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)) + (sep (or (cdr (assoc :noweb-sep (nth 2 i))) + "\n")) (full (if comment ((lambda (cs) (concat (c-wrap (car cs)) "\n" @@ -2213,9 +2213,9 @@ block but are passed literally to the \"example-block\"." (c-wrap (cadr cs)))) (org-babel-tangle-comment-links i)) body))) - (setq expansion (cons full expansion)))))))) - (mapconcat #'identity (nreverse expansion) - org-babel-noweb-separator)) + (setq expansion + (cons sep (cons full expansion))))))))) + (mapconcat #'identity (nreverse (cdr expansion)) "")) ;; possibly raise an error if named block doesn't exist (if (member lang org-babel-noweb-error-langs) (error "%s" (concat From a706f424033fde4b334cfbd2185812bf5324a7d8 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Tue, 24 Jan 2012 00:02:33 -0700 Subject: [PATCH 2/2] update tests --- testing/examples/babel.org | 1 + testing/lisp/test-ob.el | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/testing/examples/babel.org b/testing/examples/babel.org index dfe8d1435..c55182864 100644 --- a/testing/examples/babel.org +++ b/testing/examples/babel.org @@ -228,6 +228,7 @@ src_sh{echo 3} Here is one at the beginning of a line. * using the =:noweb-ref= header argument :PROPERTIES: :ID: 54d68d4b-1544-4745-85ab-4f03b3cbd8a0 + :noweb-sep: "" :END: #+begin_src sh :tangle yes :noweb yes :shebang #!/bin/sh diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index 3eaedfcb0..c819facf2 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -566,11 +566,11 @@ on two lines #+end_src #+name: foo -#+begin_src sh +#+begin_src sh :noweb-sep \"\" bar #+end_src -#+begin_src sh :noweb-ref foo +#+begin_src sh :noweb-ref foo :noweb-sep \"\" baz #+end_src" (should (string= (org-babel-expand-noweb-references) "barbaz"))))