Skip to content

Commit 2063596

Browse files
sebmiqyantar92
authored andcommitted
ob-core.el: Add :noweb-prefix babel header argument
* lisp/ob-core.el (org-babel-expand-noweb-references): Add support for `noweb-prefix' header argument, to not repeat the prefix characters when expanding a noweb reference. (org-babel-common-header-args-w-values): (org-babel-safe-header-args): Add `noweb-prefix' value. * doc/org-manual.org: Document `noweb-prefix' babel header argument. * etc/ORG-NEWS: Document `:noweb-prefix'.
1 parent a3dac4d commit 2063596

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

doc/org-manual.org

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18760,6 +18760,23 @@ else:
1876018760
print('do things when false')
1876118761
#+end_example
1876218762

18763+
This prefix behavior can be turned off in a block by setting the
18764+
=noweb-prefix= header argument to =no=, as in:
18765+
18766+
#+begin_example
18767+
,#+BEGIN_SRC elisp :noweb-prefix no
18768+
(setq example-data "<<example>>")
18769+
,#+END_SRC
18770+
#+end_example
18771+
18772+
#+texinfo: @noindent
18773+
which expands to:
18774+
18775+
#+begin_example
18776+
(setq example-data "this is the
18777+
multi-line body of example")
18778+
#+end_example
18779+
1876318780
When in doubt about the outcome of a source code block expansion, you
1876418781
can preview the results with the following command:
1876518782

etc/ORG-NEWS

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ The entry points are ~org-persist-register~, ~org-persist-unregister~,
150150
~org-persist-read~, and ~org-persist-read-all~. Storing circular
151151
structures is supported. Storing references between different
152152
variables is also supported (see =:inherit= key in
153-
~org-persist-register~).
153+
~org-persist-register~).
154154

155155
The library permits storing buffer-local variables. Such variables
156156
are linked to the buffer text, file =inode=, and file path.
@@ -175,6 +175,10 @@ the =compact-itemx= export option, or globally using the
175175
Items in a description list that begin with =Function:=, =Variable:=
176176
or certain related prefixes are converted using Texinfo definition
177177
commands.
178+
*** New =:noweb-prefix= babel header argument
179+
180+
=:noweb-prefix= can be set to =no= to prevent the prefix characters
181+
from being repeated when expanding a multiline noweb reference.
178182

179183
** New functions and changes in function arguments
180184

lisp/ob-core.el

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ then run `org-babel-switch-to-session'."
413413
(noweb . ((yes no tangle no-export strip-export)))
414414
(noweb-ref . :any)
415415
(noweb-sep . :any)
416+
(noweb-prefix . ((no yes)))
416417
(output-dir . :any)
417418
(padline . ((yes no)))
418419
(post . :any)
@@ -438,8 +439,8 @@ specific header arguments as well.")
438439

439440
(defconst org-babel-safe-header-args
440441
'(:cache :colnames :comments :exports :epilogue :hlines :noeval
441-
:noweb :noweb-ref :noweb-sep :padline :prologue :rownames
442-
:sep :session :tangle :wrap
442+
:noweb :noweb-ref :noweb-sep :noweb-prefix :padline
443+
:prologue :rownames :sep :session :tangle :wrap
443444
(:eval . ("never" "query"))
444445
(:results . (lambda (str) (not (string-match "file" str)))))
445446
"A list of safe header arguments for babel source blocks.
@@ -2827,6 +2828,10 @@ block but are passed literally to the \"example-block\"."
28272828
(lang (nth 0 info))
28282829
(body (nth 1 info))
28292830
(comment (string= "noweb" (cdr (assq :comments (nth 2 info)))))
2831+
(noweb-prefix (let ((v (assq :noweb-prefix (nth 2 info))))
2832+
(or (not v)
2833+
(and (org-not-nil (cdr v))
2834+
(not (equal (cdr v) "no"))))))
28302835
(noweb-re (format "\\(.*?\\)\\(%s\\)"
28312836
(with-current-buffer parent-buffer
28322837
(org-babel-noweb-wrap))))
@@ -2923,9 +2928,11 @@ block but are passed literally to the \"example-block\"."
29232928
(push info (gethash ref cache))))))
29242929
(funcall expand-references id cache)))))
29252930
;; Interpose PREFIX between every line.
2926-
(mapconcat #'identity
2927-
(split-string expansion "[\n\r]")
2928-
(concat "\n" prefix))))))
2931+
(if noweb-prefix
2932+
(mapconcat #'identity
2933+
(split-string expansion "[\n\r]")
2934+
(concat "\n" prefix))
2935+
expansion)))))
29292936
body t t 2)))
29302937

29312938
(defun org-babel--script-escape-inner (str)

0 commit comments

Comments
 (0)