From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kaushal Modi Subject: Re: How to use noweb reference with argument in other languages? Date: Tue, 20 Jun 2017 16:57:03 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="94eb2c1cd16ca9ddfe0552672442" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:56567) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dNMSu-00074G-1i for emacs-orgmode@gnu.org; Tue, 20 Jun 2017 12:57:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dNMSp-0003hT-QT for emacs-orgmode@gnu.org; Tue, 20 Jun 2017 12:57:20 -0400 Received: from mail-lf0-x22e.google.com ([2a00:1450:4010:c07::22e]:35283) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dNMSp-0003hE-DO for emacs-orgmode@gnu.org; Tue, 20 Jun 2017 12:57:15 -0400 Received: by mail-lf0-x22e.google.com with SMTP id p189so79007070lfe.2 for ; Tue, 20 Jun 2017 09:57:15 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: "numbchild@gmail.com" Cc: emacs-org list --94eb2c1cd16ca9ddfe0552672442 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Jun 19, 2017 at 7:41 PM numbchild@gmail.com wrote: > 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=3D"" :noweb-ref sh-print-something > echo "$str" > #+END_SRC > > #+BEGIN_SRC sh :results output :noweb yes > echo "hello, " > <> > #+END_SRC > > #+RESULTS: > ``` > > Emacs reports error: > > org-babel-ref-resolve: Reference =E2=80=98sh-print-something=E2=80=99 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=3D"" echo echo $str #+END_SRC #+BEGIN_SRC shell :results output :noweb yes echo "hello, " <> #+END_SRC #+RESULTS: : hello, : stardiviner Changes: (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 <> inserts the *results* of the code block "foo", not "foo" a= s 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 "<> 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=3D"foo" :results output print('echo "' + str + '"') #+END_SRC #+RESULTS: sh-print-something : echo "foo" #+BEGIN_SRC shell :results output :noweb yes echo "hello, " <> #+END_SRC #+RESULTS: : hello, : stardiviner --=20 Kaushal Modi --94eb2c1cd16ca9ddfe0552672442 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Mon, Jun 19= , 2017 at 7:41 PM numbchild@gmail.co= m <numbchild@gmail.com>= ; wrote:
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.
=C2=A0
When I use your `:noweb-ref` style l= ike this:

```org
* noweb reference with argument

#+BEGIN_SRC s= h :var str=3D"" :noweb-ref sh-print-something
<= /div>
echo "$str"
#+= END_SRC

#+BEGIN_SRC sh :results output :noweb yes
ec= ho "hello, "
<<sh-print-something(str=3D"stardi= viner")>>
#+END_SRC

#+RESULTS:
```

Emacs reports error:

org-babel-r= ef-resolve: Reference =E2=80=98sh-print-something=E2=80=99 not found in thi= s buffer.

Org-mode version:=C2=A0Org mode version 9.0.= 8 (9.0.8-elpaplus @ /home/stardiviner/Code/Emacs/org-mode/lisp/)

I stand corrected; for the stuff t= hat you are doing, I believe the code block name needs to go to #+NAME inst= ead of to :noweb-ref.

Below works (Hit C-c C-c in = the second source block and approve evaluating that code block:
<= br>
* noweb reference with argument

#+NAME: sh-print-something
#+BEGIN_SRC shell :var str=3D&qu= ot;"
echo echo $str
#+END_SRC

=
#+BEGIN_SRC shell :results output :noweb yes
echo "hell= o, "
<<sh-print-something(str=3D"stardiviner"= ;)>>
#+END_SRC

#+RESULTS:
: hello,
: stardiviner

Cha= nges:

(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=3D1)>> inserts the *results* of t= he 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=3D1= )>> inserts the *results*", even the below would work the same w= ay as we care about the results output by the first block, not how those re= sults are obtained.

* noweb reference with ar= gument

#+NAME: sh-print-something
#+BEGI= N_SRC python :var str=3D"foo" :results output
print(= 9;echo "' + str + '"')
#+END_SRC
=
#+RESULTS: sh-print-something
: echo "foo&quo= t;

#+BEGIN_SRC shell :results output :noweb yes
echo "hello, "
<<sh-print-something(str= =3D"stardiviner")>>
#+END_SRC

#+RESULTS:
: hello,=C2=A0
: stardiviner

--

Kaushal Modi

--94eb2c1cd16ca9ddfe0552672442--