This is the official manual for the latest Org-mode release.

Table of Contents

Next: , Previous: session, Up: Specific header arguments


14.8.2.15 :noweb

The :noweb header argument controls expansion of Noweb syntax references (see Noweb reference syntax). Expansions occur when source code blocks are evaluated, tangled, or exported.

Noweb prefix lines

Noweb insertions now honor prefix characters that appear before the Noweb syntax reference.

This behavior is illustrated in the following example. Because the <<example>> noweb reference appears behind the SQL comment syntax, each line of the expanded noweb reference will be commented.

With:

     #+NAME: example
     #+BEGIN_SRC text
     this is the
     multi-line body of example
     #+END_SRC

this ‘src’ code block:

     #+BEGIN_SRC sql :noweb yes
     -- <<example>>
     #+END_SRC

expands to:

     -- this is the
     -- multi-line body of example

Since this change will not affect noweb replacement text without newlines in them, inline noweb references are acceptable.

This feature can also be used for management of indentation in exported code snippets.

With:

     #+NAME: if-true
     #+BEGIN_SRC python :exports none
     print('Do things when True')
     #+END_SRC
     
     #+NAME: if-false
     #+BEGIN_SRC python :exports none
     print('Do things when False')
     #+END_SRC

this ‘src’ code block:

     #+BEGIN_SRC python :noweb yes :results output
     if True:
         <<if-true>>
     else:
         <<if-false>>
     #+END_SRC

expands to:

     if True:
         print('Do things when True')
     else:
         print('Do things when False')

and evaluates to:

     Do things when True