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'.
This commit is contained in:
parent
a3dac4d20a
commit
2063596b90
|
@ -18760,6 +18760,23 @@ else:
|
|||
print('do things when false')
|
||||
#+end_example
|
||||
|
||||
This prefix behavior can be turned off in a block by setting the
|
||||
=noweb-prefix= header argument to =no=, as in:
|
||||
|
||||
#+begin_example
|
||||
,#+BEGIN_SRC elisp :noweb-prefix no
|
||||
(setq example-data "<<example>>")
|
||||
,#+END_SRC
|
||||
#+end_example
|
||||
|
||||
#+texinfo: @noindent
|
||||
which expands to:
|
||||
|
||||
#+begin_example
|
||||
(setq example-data "this is the
|
||||
multi-line body of example")
|
||||
#+end_example
|
||||
|
||||
When in doubt about the outcome of a source code block expansion, you
|
||||
can preview the results with the following command:
|
||||
|
||||
|
|
|
@ -150,7 +150,7 @@ The entry points are ~org-persist-register~, ~org-persist-unregister~,
|
|||
~org-persist-read~, and ~org-persist-read-all~. Storing circular
|
||||
structures is supported. Storing references between different
|
||||
variables is also supported (see =:inherit= key in
|
||||
~org-persist-register~).
|
||||
~org-persist-register~).
|
||||
|
||||
The library permits storing buffer-local variables. Such variables
|
||||
are linked to the buffer text, file =inode=, and file path.
|
||||
|
@ -175,6 +175,10 @@ the =compact-itemx= export option, or globally using the
|
|||
Items in a description list that begin with =Function:=, =Variable:=
|
||||
or certain related prefixes are converted using Texinfo definition
|
||||
commands.
|
||||
*** New =:noweb-prefix= babel header argument
|
||||
|
||||
=:noweb-prefix= can be set to =no= to prevent the prefix characters
|
||||
from being repeated when expanding a multiline noweb reference.
|
||||
|
||||
** New functions and changes in function arguments
|
||||
|
||||
|
|
|
@ -413,6 +413,7 @@ then run `org-babel-switch-to-session'."
|
|||
(noweb . ((yes no tangle no-export strip-export)))
|
||||
(noweb-ref . :any)
|
||||
(noweb-sep . :any)
|
||||
(noweb-prefix . ((no yes)))
|
||||
(output-dir . :any)
|
||||
(padline . ((yes no)))
|
||||
(post . :any)
|
||||
|
@ -438,8 +439,8 @@ specific header arguments as well.")
|
|||
|
||||
(defconst org-babel-safe-header-args
|
||||
'(:cache :colnames :comments :exports :epilogue :hlines :noeval
|
||||
:noweb :noweb-ref :noweb-sep :padline :prologue :rownames
|
||||
:sep :session :tangle :wrap
|
||||
:noweb :noweb-ref :noweb-sep :noweb-prefix :padline
|
||||
:prologue :rownames :sep :session :tangle :wrap
|
||||
(:eval . ("never" "query"))
|
||||
(:results . (lambda (str) (not (string-match "file" str)))))
|
||||
"A list of safe header arguments for babel source blocks.
|
||||
|
@ -2827,6 +2828,10 @@ block but are passed literally to the \"example-block\"."
|
|||
(lang (nth 0 info))
|
||||
(body (nth 1 info))
|
||||
(comment (string= "noweb" (cdr (assq :comments (nth 2 info)))))
|
||||
(noweb-prefix (let ((v (assq :noweb-prefix (nth 2 info))))
|
||||
(or (not v)
|
||||
(and (org-not-nil (cdr v))
|
||||
(not (equal (cdr v) "no"))))))
|
||||
(noweb-re (format "\\(.*?\\)\\(%s\\)"
|
||||
(with-current-buffer parent-buffer
|
||||
(org-babel-noweb-wrap))))
|
||||
|
@ -2923,9 +2928,11 @@ block but are passed literally to the \"example-block\"."
|
|||
(push info (gethash ref cache))))))
|
||||
(funcall expand-references id cache)))))
|
||||
;; Interpose PREFIX between every line.
|
||||
(mapconcat #'identity
|
||||
(split-string expansion "[\n\r]")
|
||||
(concat "\n" prefix))))))
|
||||
(if noweb-prefix
|
||||
(mapconcat #'identity
|
||||
(split-string expansion "[\n\r]")
|
||||
(concat "\n" prefix))
|
||||
expansion)))))
|
||||
body t t 2)))
|
||||
|
||||
(defun org-babel--script-escape-inner (str)
|
||||
|
|
Loading…
Reference in New Issue