From mboxrd@z Thu Jan 1 00:00:00 1970 From: Martin Alsinet Subject: Re: org-babel source block unevaluated into variable? Date: Thu, 26 Oct 2017 12:06:27 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="001a11469c62205ff9055c72016c" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:42212) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7gvu-0007VD-Ah for emacs-orgmode@gnu.org; Thu, 26 Oct 2017 08:06:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e7gvn-0007zF-U1 for emacs-orgmode@gnu.org; Thu, 26 Oct 2017 08:06:46 -0400 Received: from mail-wm0-f41.google.com ([74.125.82.41]:56443) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e7gvn-0007yl-K3 for emacs-orgmode@gnu.org; Thu, 26 Oct 2017 08:06:39 -0400 Received: by mail-wm0-f41.google.com with SMTP id z3so7813136wme.5 for ; Thu, 26 Oct 2017 05:06:39 -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: =?UTF-8?Q?Johan_W=2E_Kl=C3=BCwer?= Cc: emacs-orgmode@gnu.org --001a11469c62205ff9055c72016c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Johan: Maybe this one would work for you: #+NAME: first #+BEGIN_SRC js function one() { return 1; } #+END_SRC #+NAME: second #+BEGIN_SRC js function two() { return 2; } #+END_SRC #+NAME: third #+BEGIN_SRC js function three() { return 3; } #+END_SRC #+NAME: all #+BEGIN_SRC sh :results output :noweb yes echo " <> <> function test(){ console.log('test');} <>" #+END_SRC #+BEGIN_SRC python :results output :var code=3Dall print code #+END_SRC #+RESULTS: #+begin_example function two() { return 2 } function one() { return 1; } function test(){ console.log('test');} function three() { return 3; } #+end_example On Thu, Oct 26, 2017 at 6:17 AM Johan W. Kl=C3=BCwer wrote: > Thanks Martin, > > These are good suggestions, but it's not quite what I am after. In your > second example, I would like ":var code=3Dexample" to make "code" carry t= he > full (and expanded) text of the "example" block, i.e. to have > > echo ls -alh > > as the result -- the code itself, unevaluated. > > Johan > > 2017-10-25 17:52 GMT+02:00 Martin Alsinet : > >> Johan: >> >> To use expanded noweb references you can use text source blocks >> >> #+NAME: lscode >> #+BEGIN_SRC *text* >> ls -alh >> #+END_SRC >> >> >> #+NAME: example >> #+BEGIN_SRC sh :noweb yes >> echo <> >> #+END_SRC >> >> #+RESULTS: example >> : ls -alh >> >> >> #+BEGIN_SRC emacs-lisp :var code=3Dexample >> (message code) >> #+END_SRC >> >> #+RESULTS: >> : ls -alh >> >> >> Mart=C3=ADn >> >> On Wed, Oct 25, 2017 at 10:36 AM Martin Alsinet >> wrote: >> >>> Johan: >>> >>> You can try the following: >>> >>> #+NAME: lscode >>> #+BEGIN_ASCII >>> ls -alh >>> #+END_ASCII >>> >>> #+BEGIN_SRC emacs-lisp :var code=3Dlscode >>> (message code) >>> #+END_SRC >>> >>> #+RESULTS: >>> : ls -alh >>> >>> I haven't tried the noweb references, but it does return the code block >>> in the variable. >>> >>> >>> Mart=C3=ADn >>> >>> On Wed, Oct 25, 2017 at 9:22 AM Johan W. Kl=C3=BCwer < >>> johan.w.kluwer@gmail.com> wrote: >>> >>>> Is there a way to assign the uninterpreted content of an executable >>>> source block to a variable? Preferably, using a :var header argument? = That >>>> is, return the text in the block, not the result of evaluating it, and >>>> preferably with noweb references expanded. >>>> >>>> "example" blocks return text the way I want, but they can't be >>>> evaluated, and of course noweb is ruled out for them. >>>> >>>> The function org-babel-ref-resolve could to the job if there were a >>>> switch to block evaluation. >>>> >>>> >>>> Why this is interesting: I wish to use url-hexify-string on the text o= f >>>> a named SPARQL query. >>>> >>>> Cheers, Johan >>>> >>> > --001a11469c62205ff9055c72016c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Johan:

Maybe this one would work = for you:

#+NAME= : first
#+BEGIN_SRC js=
function one() {
=C2=A0 =C2=A0 return 1;
}
#+END_SRC


#+NAME: second<= /font>
#+BEGIN_SRC js<= /div>
function two() {
=
=C2=A0 =C2=A0 return 2;
}
#+END_SRC


#+NAME: third
#+BEGIN_SRC js
function three() {
=C2=A0 =C2=A0 return 3;
= }
#+END_SRC


#+NAME: all
<= font size=3D"2" face=3D"monospace">#+BEGIN_SRC sh :results output :noweb ye= s
echo "
<<second>><= /div>

<<first>>

function test(){ console.log('test');}

<<third>>"
#+END_SRC



#+= BEGIN_SRC python :results output :var code=3Dall
print code
#+END_SRC

#+RESULTS:
#+begin_example

function two() {
=C2=A0 =C2=A0 return 2
}

function on= e() {
=C2=A0 =C2=A0 re= turn 1;
}
=

function test(){ console.log('test');}

function three() {
=C2=A0 =C2=A0 return 3;
}

#+= end_example



2017-10-25 17:52 GMT+02:00 Martin Alsinet <martin@alsinet.com.ar&= gt;:
Johan:<= /div>

To use expanded noweb references you can use text sourc= e blocks

#+NAME: lscode
#+BEGIN_SRC text
ls -alh
#+END_SRC


#+NAME: example
#+= BEGIN_SRC sh :noweb yes
echo <<lscode>>
#+END_SRC

=
#+RESULTS: example
: ls -alh


#+BEGIN_SRC emacs-lisp :var code=3Dexample
(message code)
#+END_SRC

#+= RESULTS:
: ls -alh


Mart=C3=ADn
<= /div>

On Wed, Oct 25,= 2017 at 10:36 AM Martin Alsinet <martin@alsinet.com.ar> wrote:
Johan:

You can t= ry the following:

#+NAME: lscode
#+BEGIN_ASCII
ls -al= h
#+END_ASCII

#+BEGIN_SRC ema= cs-lisp :var code=3Dlscode
(message code)
#+= END_SRC

#+RESULTS:
: ls -alh

I haven't tried the noweb references, but= it does return the code block in the variable.

Mart=C3=ADn

On Wed, Oct 25, 2017 at 9:22 AM Johan W. Kl=C3=BCwer <johan.w.kluwer@gmail= .com> wrote:
Is there a way to assign the uninterpreted content of an executable = source block to a variable? Preferably, using a :var header argument? That = is, return the text in the block, not the result of evaluating it, and pref= erably with noweb references expanded.

"e= xample" blocks return text the way I want, but they can't be evalu= ated, and of course noweb is ruled out for them.

The function org-babel-ref-resolve could to the job if there were a swit= ch to block evaluation.


Why thi= s is interesting: I wish to use url-hexify-string on the text of a named SP= ARQL query.

Cheers, Johan

--001a11469c62205ff9055c72016c--