From mboxrd@z Thu Jan 1 00:00:00 1970 From: "numbchild@gmail.com" Subject: Re: babel header argument :var is not expanded when tangling Date: Mon, 25 Dec 2017 20:45:58 +0800 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="001a113edae017947f0561298e45" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:40576) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eTS9H-0007xf-Lv for emacs-orgmode@gnu.org; Mon, 25 Dec 2017 07:46:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eTS9G-0008Vm-99 for emacs-orgmode@gnu.org; Mon, 25 Dec 2017 07:46:31 -0500 Received: from mail-ot0-x22a.google.com ([2607:f8b0:4003:c0f::22a]:38998) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eTS9G-0008V6-2U for emacs-orgmode@gnu.org; Mon, 25 Dec 2017 07:46:30 -0500 Received: by mail-ot0-x22a.google.com with SMTP id 37so1872678otv.6 for ; Mon, 25 Dec 2017 04:46:29 -0800 (PST) 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: Grant Rettke Cc: Org-mode --001a113edae017947f0561298e45 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I see. I will use noweb style for now. But should tangle expand :var variables when tangling? I think this is the correct behaviour. [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 Sun, Dec 24, 2017 at 11:40 PM, Grant Rettke wrote: > > Here is a quick test: > > > > * Test tangle will auto expand and substitute :var > > > > #+begin_src js :tangle kk.js > > console.log("hello, world!"); > > #+end_src > > > > #+begin_src js :var name=3D"chris" :tangle require-kk.js > > // require("kk.js"); > > console.log("Hi, ", name); > > #+end_src > > > > #+RESULTS: > > : Hi, chris > > > > #+NAME: check whether tangle expand and substitute :var > > #+begin_src shell > > cat require-kk.js > > #+end_src > > > > #+RESULTS: check whether tangle expand and substitute :var > > : var name=3D"chris"; > > : console.log("Hi, ", name); > > > > The upper result should be: ~console.log("Hi, ", "chris");~. > > Here are your two source blocks. They each do literate programming, > one with Variable style and the other with Noweb style. When you > evaluate them you get an identical result. When you tangle them you > get two different pieces of code, that generate the same result. You > can peek at what the tangled code will look like by calling > org-babel-expand-src-block inside the source block. That is how it > will look in the tangled file. I think that want Noweb style. > > When I use the Variable approach like this > > #+begin_src js :var name=3D"chris" :tangle kk.js > console.log("Hi, ", name); > #+end_src > > I get this in the tangled output file > > var name=3D"chris"; > console.log("Hi, ", name); > > When I use the the Noweb approach like this > > #+NAME: name > #+BEGIN_SRC emacs-lisp > chris > #+END_SRC > > #+NAME: org_gcr_2017-12-23_mara_3D887FDD-163D-4BE1-80E8-464BF29DABEA > #+BEGIN_SRC js :tangle noweb-kk.js :comments no > console.log("Hi, ", "=C2=ABname=C2=BB"); > #+END_SRC > > I get this in the tangled output file > > console.log("Hi, ", "chris"); > > WDYT? > --001a113edae017947f0561298e45 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

I see. I will use noweb style for now.
But should tangle expand :var variables when tangling? I think this is th= e correct behaviour.

=
[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 Sun, Dec 24, 2017 at 11:40 PM, Grant Rett= ke <gcr@wisdomandwonder.com> wrote:
> Here is a quick test:
>
> * Test tangle will auto expand and substitute :var
>
> #+begin_src js :tangle kk.js
> console.log("hello, world!");
> #+end_src
>
> #+begin_src js :var name=3D"chris" :tangle require-kk.js
> // require("kk.js");
> console.log("Hi, ", name);
> #+end_src
>
> #+RESULTS:
> : Hi,=C2=A0 chris
>
> #+NAME: check whether tangle expand and substitute :var
> #+begin_src shell
> cat require-kk.js
> #+end_src
>
> #+RESULTS: check whether tangle expand and substitute :var
> : var name=3D"chris";
> : console.log("Hi, ", name);
>
> The upper result should be: ~console.log("Hi, ", "chris= ");~.

Here are your two source blocks. They each do literate programming,<= br> one with Variable style and the other with Noweb style. When you
evaluate them you get an identical result. When you tangle them you
get two different pieces of code, that generate the same result. You
can peek at what the tangled code will look like by calling
org-babel-expand-src-block inside the source block. That is how it
will look in the tangled file. I think that want Noweb style.

When I use the Variable approach like this

#+begin_src js :var name=3D"chris" :tangle kk.js
console.log("Hi, ", name);
#+end_src

I get this in the tangled output file

var name=3D"chris";
console.log("Hi, ", name);

When I use the the Noweb approach like this

#+NAME: name
#+BEGIN_SRC emacs-lisp
chris
#+END_SRC

#+NAME: org_gcr_2017-12-23_mara_3D887FDD-163D-4BE1-80E8-464BF29DA= BEA
#+BEGIN_SRC js :tangle noweb-kk.js :comments no
console.log("Hi, ", "=C2=ABname=C2=BB");
#+END_SRC

I get this in the tangled=C2=A0 output file

console.log("Hi, ", "chris");

WDYT?

--001a113edae017947f0561298e45--