There may be other solutions, this is how I would do it:
#+begin_src sh :noweb yes :var res=test-fn()
: testvar=This is a test
The same can be done without introducing the dummy variable (as is described in the documentation):
#+begin_src sh :noweb yes
: testvar=This is a ...
I think there is already a parser for src block names in org-babel-src-block-names returning a list. The following provides programmed completion for that list:
(defun org-src-block-names--completion-function (str pred action)
(let ((tbl (org-babel-src-block-names)))
(`nil (try-completion str tbl pred))
To export a buffer without expanding noweb references, you can set the following at your src header, as per documentation:
#+begin_src language :noweb no-export
To define that globally, you can add the following at the top of your Org File:
#+property: header-args :noweb no-export
Or language specific:
#+property: header-args:languagename :noweb no-...
The reason why the error happens is because you haven't defined y in the x=y arguments.
If you update code as follows noweb will work
#+BEGIN_SRC python :noweb eval
return <<cubed(x=3)>> + <<cubed(x=3)>>
However I suspect this is not what you wanted ...
I understand your confusion.
The good news is that your code is already passing new lines correctly into your noweb call.
The reason you're seeing the eval: Symbol’s value as variable is void: a error is because of the generated elisp code.
If you execute the following code you'll see the same error message:
I think you're asking how to prefix only the first line of the noweb block. It will probably depend on the language your using, but I came up with this hack for bash:
please echo this line
date ## but not this one
cd test ## this one
ls -l ## or this one
Bad source code block, echo prepended to very line:
This is only a partial solution, but the dabbrev-expand method can be greatly improved by modifying the syntax table so that < and > are treated as delimiters:
(modify-syntax-entry ?< "(>" org-mode-syntax-table)
(modify-syntax-entry ?> ")<" org-mode-syntax-table)
This means that you don't have to go back and insert a space before using M-/...
The behavior you want is controlled by the variable org-babel-noweb-error-all-langs, whose default value is nil. Set it to t (e.g. via (setq org-babel-noweb-error-all-langs t) in your init file), and unresolvable noweb references will raise an error.
Your example works if I set all headers with :noweb yes and then only the last block has :tangle yes.
A simpler example:
Add this at the top of the file: #+PROPERTY: header-args :noweb yes :tangle no :exports code
Remove all header args from the code blocks.
Add :tangle yes header to the "full specification".