From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?Q?Johan_W=2E_Kl=C3=BCwer?= Subject: Re: org-babel source block unevaluated into variable? Date: Thu, 26 Oct 2017 14:02:25 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="94eb2c05ea82163574055c71f23d" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41300) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7grk-0005Xm-8T for emacs-orgmode@gnu.org; Thu, 26 Oct 2017 08:02:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e7gri-0005CU-UF for emacs-orgmode@gnu.org; Thu, 26 Oct 2017 08:02:28 -0400 Received: from mail-qk0-x235.google.com ([2607:f8b0:400d:c09::235]:49833) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e7gri-0005Bv-Ps for emacs-orgmode@gnu.org; Thu, 26 Oct 2017 08:02:26 -0400 Received: by mail-qk0-x235.google.com with SMTP id q83so3880300qke.6 for ; Thu, 26 Oct 2017 05:02:26 -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: Martin Alsinet Cc: emacs-orgmode@gnu.org --94eb2c05ea82163574055c71f23d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Following up: A function like this one should help. (defun expand-named-babel-block (block) (save-excursion (org-babel-goto-named-src-block block) (org-babel-expand-src-block))) However ... there's something strange here with org-babel-goto-named-src-block (org 9.0.9). It just jumps to the first source block in the file, which is not that useful :) I'll try to update org and see. 2017-10-26 13:17 GMT+02:00 Johan W. Kl=C3=BCwer : > 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 >>>> >>> > --94eb2c05ea82163574055c71f23d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Following up: A function like this one should help.
(defun expand-named-babel-block (block)
=C2=A0=C2=A0=C2=A0 (save-e= xcursion
=C2=A0=C2=A0=C2=A0 (org-babel-goto-named-src-block block)
= =C2=A0=C2=A0=C2=A0 (org-babel-expand-src-block)))

However ... = there's something strange here with org-babel-goto-named-src-block (org= 9.0.9). It just jumps to the first source block in the file, which is not = that useful :) I'll try to update org and see.

2017-10-26 13:17 GMT+02:00 Johan= W. Kl=C3=BCwer <johan.w.kluwer@gmail.com>:
Thanks Martin,
=
These are good suggestions, but it's not quite what I am afte= r. In your second example, I would like ":var code=3Dexample" to = make "code" carry the full (and expanded) text of the "examp= le" block, i.e. to have

=C2=A0 echo ls -= alh

as the result -- the code itself, unevalu= ated.

Johan

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

To use expanded noweb references y= ou can use text source blocks

<= /font>
#+NAME: lscode
#+BEGIN_SRC text<= /font>
ls -alh
#+END_SRC


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

#+RESULTS: example
= : ls -alh

<= /div>

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

#+RESULTS:
: ls -alh


<= div>Mart=C3=ADn

On Wed, Oct 25, 2017 at 10:36 AM Martin Alsinet <martin@alsinet.com.ar> = 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

#+RESUL= TS:
: ls -alh

I haven't tried t= he 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 co= ntent 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 j= ob if there were a switch to block evaluation.


Why this is interesting: I wish to use url-hexify-string on= the text of a named SPARQL query.

Cheers, Johan


--94eb2c05ea82163574055c71f23d--