From mboxrd@z Thu Jan 1 00:00:00 1970 From: "numbchild@gmail.com" Subject: Re: How to use noweb reference with argument in other languages? Date: Wed, 21 Jun 2017 10:03:50 +0800 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="001a11444ab04d273f05526ec9e7" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55442) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dNV0L-0004pM-6Q for emacs-orgmode@gnu.org; Tue, 20 Jun 2017 22:04:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dNV0J-0003bw-Nq for emacs-orgmode@gnu.org; Tue, 20 Jun 2017 22:04:25 -0400 Received: from mail-wr0-x232.google.com ([2a00:1450:400c:c0c::232]:33699) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dNV0J-0003bJ-Cw for emacs-orgmode@gnu.org; Tue, 20 Jun 2017 22:04:23 -0400 Received: by mail-wr0-x232.google.com with SMTP id r103so114526444wrb.0 for ; Tue, 20 Jun 2017 19:04:21 -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: Kaushal Modi Cc: emacs-org list --001a11444ab04d273f05526ec9e7 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable This is correct now. Thanks very much. You're right. [stardiviner] GPG key ID: 47C32433 IRC(freeenode): stardiviner Twitter: @numbchild Key fingerprint =3D 9BAA 92BC CDDD B9EF 3B36 CB99 B8C4 B8E5 47C3 2433 Blog: http://stardiviner.github.io/ On Wed, Jun 21, 2017 at 12:57 AM, Kaushal Modi wrote: > 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 no= t 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 evaluatin= g > 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"= 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 "<> 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 > > -- > > Kaushal Modi > --001a11444ab04d273f05526ec9e7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
This is correct now. Thanks very much. You're right.

[stardiviner]=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 <Hack this world!>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 GPG = key ID: 47C32433
IRC(freeenode): stardiviner =C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 Twitter:=C2=A0 @numbchild
Key fingerprint =3D 9BAA 92BC CDD= D B9EF 3B36=C2=A0 CB99 B8C4 B8E5 47C3 2433
Blog: http://stardiviner.github.io/
<= /div>

On Wed, Jun 21, 2017 at 12:57 AM, Kaushal Mo= di <kaushal.modi@gmail.com> wrote:
On Mon, Jun 19, 2017 at 7:41 PM numbchild@gmail.com <numbchild@gmail.com> wrot= e:
Whi= ch Org-mode version are you using? I'm using the latest Org-mode versio= n from source code branch `master`.

=
I am using the same.
=C2=A0
When I use your `:= noweb-ref` style like this:

```o= rg
* 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, "
<<sh-print-something(s= tr=3D"stardiviner")>>
#+END_SRC

#+RESULTS:
```
<= br>
Emacs reports error:

org-babel-ref-resolve: Reference =E2=80=98sh-print-something=E2= =80=99 not found in this 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 that you are doing, I believe the code b= lock 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 eva= luating that code block:

* noweb reference with argument

#+NAME: s= h-print-something
#+BEGIN_SRC shell :var str=3D""
=
echo echo $str
#+END_SRC

#+BEGIN_SR= C shell :results output :noweb yes
echo "he= llo, "
<<sh-print-something(str=3D"stardivin= er")>>
#+END_SRC

#+RESULTS:
: hello,
: stardiviner

=
Changes:

(1) Switched back to #+NAME fr= om :noweb-ref. Looks like if you need to pass args, the reference name need= s to be a code block name because <<foo(bar=3D1)>> inserts the = *results* of the code block "foo", not "foo" as it is.<= /div>
(2) So in the first block, you need to have code that *outputs* &= quot;echo $str" with $str set to your set arg.
(3) Use shell= instead of sh.

To stress the point of "<&= lt;foo(bar=3D1)>> inserts the *results*", even the below would w= ork the same way as we care about the results output by the first block, no= t how those results are obtained.

* noweb reference with argument

#+NAM= E: sh-print-something
#+BEGIN_SRC python :var str=3D"foo&quo= t; :results output
print('echo "' + str + '"= ;')
#+END_SRC

#+RESULTS: sh-print-so= mething
: echo "foo"

#+BEGIN_S= RC shell :results output :noweb yes
echo "h= ello, "
<<sh-print-something(str=3D"stardivi= ner")>>
#+END_SRC

#+RESULTS:<= /div>
: hello,=C2=A0
: stardiviner

<= /div>
--

Kaushal Modi<= /p>


--001a11444ab04d273f05526ec9e7--