emacsorg-modeliterate-programmingorg-babelnoweb

Org-Mode: call the noweb insertion from the noweb insertion


a and b -- python functions, c -- simple noweb insertion to python source-blocks, and d -- noweb insertion to function with noweb insertion. Function c -- is working, but function d -- not, because python trying execute insertions but this is invalid syntax. Is it possible to run noweb insertion from the noweb insertion?

#+NAME: a
#+BEGIN_SRC python
a = 1
#+END_SRC

#+NAME: b
#+BEGIN_SRC python
b = 1
#+END_SRC

#+NAME: c
#+BEGIN_SRC python :noweb yes :results output
<<a>>
<<b>>
c = a + b
print c
#+END_SRC

#+NAME: d
#+BEGIN_SRC python :noweb yes :results output
<<c>>

d = c * 2
print d
#+END_SRC

Solution

  • During the experiments, I found that this construction works (all noweb insertion must be in the last code block):

    #+NAME: a
    #+BEGIN_SRC python
    a = 1
    #+END_SRC
    
    #+NAME: b
    #+BEGIN_SRC python
    b = 1
    #+END_SRC
    
    #+NAME: c
    #+BEGIN_SRC python
    c = a + b
    #+END_SRC
    
    #+NAME: d
    #+BEGIN_SRC python :noweb yes :results output
    <<a>>
    <<b>>
    <<c>>
    
    d = c * 2
    print d
    #+END_SRC