|
From: | address@hidden |
Subject: | Re: [O] How to use noweb reference with argument in other languages? |
Date: | Wed, 21 Jun 2017 10:03:50 +0800 |
Which Org-mode version are you using? I'm using the latest Org-mode version from source code branch `master`.I am using the same.When I use your `:noweb-ref` style like this:```org* noweb reference with argument#+BEGIN_SRC sh :var str="" :noweb-ref sh-print-somethingecho "$str"#+END_SRC#+BEGIN_SRC sh :results output :noweb yesecho "hello, "<<sh-print-something(str="stardiviner")>> #+END_SRC#+RESULTS:```Emacs reports error:org-babel-ref-resolve: Reference ‘sh-print-something’ not found in this buffer.Org-mode version: Org mode version 9.0.8 (9.0.8-elpaplus @ /home/stardiviner/Code/Emacs/org-mode/lisp/) I stand corrected; for the stuff that you are doing, I believe the code block name needs to go to #+NAME instead of to :noweb-ref.Below works (Hit C-c C-c in the second source block and approve evaluating that code block:* noweb reference with argument#+NAME: sh-print-something#+BEGIN_SRC shell :var str=""echo echo $str#+END_SRC#+BEGIN_SRC shell :results output :noweb yesecho "hello, "<<sh-print-something(str="stardiviner")>> #+END_SRC#+RESULTS:: hello,: stardivinerChanges:(1) Switched back to #+NAME from :noweb-ref. Looks like if you need to pass args, the reference name needs to be a code block name because <<foo(bar=1)>> inserts the *results* of the code block "foo", not "foo" as it is.(2) So in the first block, you need to have code that *outputs* "echo $str" with $str set to your set arg.(3) Use shell instead of sh.To stress the point of "<<foo(bar=1)>> inserts the *results*", even the below would work the same way as we care about the results output by the first block, not how those results are obtained.* noweb reference with argument#+NAME: sh-print-something#+BEGIN_SRC python :var str="foo" :results outputprint('echo "' + str + '"')#+END_SRC#+RESULTS: sh-print-something: echo "foo"#+BEGIN_SRC shell :results output :noweb yesecho "hello, "<<sh-print-something(str="stardiviner")>> #+END_SRC#+RESULTS:: hello,: stardiviner--Kaushal Modi
[Prev in Thread] | Current Thread | [Next in Thread] |