From mboxrd@z Thu Jan 1 00:00:00 1970 From: Diego Zamboni Subject: Re: Exporting noweb-ref's without disabling org-babel processing Date: Thu, 24 Oct 2019 14:02:39 +0200 Message-ID: References: <13AFA234-5B6C-4526-9838-03EB57B82899@ucsd.edu> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000fd8d820595a6cf8c" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:43339) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNbpO-0008Qo-P7 for emacs-orgmode@gnu.org; Thu, 24 Oct 2019 08:03:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNbpM-0007qj-FD for emacs-orgmode@gnu.org; Thu, 24 Oct 2019 08:02:54 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]:50455) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iNbpL-0007qP-VD for emacs-orgmode@gnu.org; Thu, 24 Oct 2019 08:02:52 -0400 Received: by mail-wm1-x331.google.com with SMTP id q13so2545581wmj.0 for ; Thu, 24 Oct 2019 05:02:51 -0700 (PDT) In-Reply-To: <13AFA234-5B6C-4526-9838-03EB57B82899@ucsd.edu> 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: "Berry, Charles" Cc: Org-mode --000000000000fd8d820595a6cf8c Content-Type: text/plain; charset="UTF-8" Hi Chuck, Thanks for your answer - I didn't know about that behavior of #+CALL, and I'm sure it will be useful sometime. However, this is not exactly what I was getting at. Here's what I want: 1. First of all, my code needs to tangle correctly - for this I use :noweb and :noweb-ref in some of the chunks, to structure things better. org-babel-tangle produces a working source file. 2. Upon export, most source blocks should export as-they-are. However, when I use :noweb or :noweb-ref, I want two things: a) Noweb chunk names should not be expanded upon export - e.g. <> should be exported like that b) Chunks with :noweb-ref should be identified by their chunk name in the exported code, e.g. prepended by "<>=" in the line before the chunk name. 3. As part of the explanation in my org file, I have some other source blocks (e.g. Ditaa) which are not part of the tangle output, but rather I use to produce diagrams or other stuff. For these, I need ":exports results" behavior. And here's my current status: 1. Works, basic org-babel functionality, no issues :) 2.a. Works by setting ":noweb no-export", no problems. 2.b. Works by modifying my exporter to include the necessary text in the exported output. *However*, the exporter can only access the :noweb-ref header argument if the =org-export-use-babel= variable is set to =nil=. Otherwise, it seems that all org-babel related headers (including :noweb, :noweb-ref and :exports) are removed from the block before it gets passed to the exporter functions. 3. Only works if =org-export-use-babel= is set to =t=, since otherwise org-babel (who does the selection of what gets exported based on :exports) never gets called. Basically, my problem is the contradiction between (2.b) and (3) above, with respect to the org-export-use-babel variable. What I would like to know is if there is a way to keep the :noweb and :noweb-ref header arguments in the block, even after org-babel processes them. For (2.b), I also experimented with setting =org-babel-exp-code-template=, unfortunately I encountered two problems: 1. =org-fill-template= sorts keys by length, which meant that when "%noweb-ref" appears in the template, it always gets interpreted as "%noweb" followed by the string "-ref". 2. I only want the value of :noweb-ref to be output when the parameter is specified, but =org-fill-template= doesn't handle that sort of logic - the header argument is always expanded in the template, even when its value might be missing or "no". So, I'm still looking for a good solution to my problem. In the meantime, I can generate my Ditaa diagrams separately and just include the output in my org file, which is not tragic but not the most elegant :) Hope this further clarifies things! Best, --Diego On Wed, Oct 23, 2019 at 6:51 PM Berry, Charles wrote: > Diego, > > I am not sure I understand. Here is my interpretation: > > You wish to have `:exports both' behavior in your org export. > > You want noweb references in the exported code to render as > angle-bracketed chunk names, such as <> rather than being expanded > in place. > > If that is what you want, you can use the feature of CALL keywords that > resets the header arguments for the src block it calls to obtain different > behavior with the same code. For example: > > #+begin_src org > ,#+name: template-chunk > ,#+begin_src emacs-lisp :noweb no > (concat c b a > <> > ) > ,#+end_src > > ,#+CALL: template-chunk() :noweb yes :var a="A" b="B" c="C" > > ,#+begin_src emacs_lisp :noweb-ref super-duper-code > (concat a b c) > ,#+end_src > #+end_src > > exports as > > --8<---------------cut here---------------start------------->8--- > ,---- > | (concat c b a > | <> > | ) > `---- > > ,---- > | CBAABC > `---- > > > ,---- > | (concat a b c) > `---- > --8<---------------cut here---------------end--------------->8--- > > HTH, > > Chuck > > > On Oct 22, 2019, at 1:29 PM, Diego Zamboni wrote: > > > > Hi, > > > > I'm working on a Leanpub Markua exporter (not quite complete yet but > already usable, if you are interested: > https://github.com/zzamboni/ox-leanpub/tree/book-and-markua) > > > > I would like to include the value of :noweb-ref for code blocks in > exported output, like noweb originally did, e.g. something like this: > > > > #begin_src emacs_lisp :noweb-ref super-duper-code > > ... > > #end_src > > > > to produce something like this in the export: > > > > <>= > > ... > > > > After much poking around, I figured that the :noweb and :noweb-ref > header args are removed by org-babel *before* the src block makes it to the > exporter. I also discovered that by setting org-export-use-babel to nil I > could disable this behavior, which means that my exporter can access the > :noweb-ref argument by parsing the :parameters property (see > https://github.com/zzamboni/ox-leanpub/blob/book-and-markua/ox-leanpub-markua.el#L388 > ). > > > > This was good for my original purpose, but I just realized that this > also disables other useful org-babel features on export, such as the > processing of the :exports header argument, which means that both code and > results are always included in the export regardless of what :exports says > :) > > > > I have tried using org-babel-exp-code-template, but unfortunately if I > try to use "%noweb-ref" as a key in its value, it gets replaced by the > value of :noweb followed by "-ref" in every case. > > > > Is there some other way of accessing org-babel header arguments like > :noweb-ref from the exporter, but without having to disable org-babel > processing completely? Any other ideas for achieving what I want? > > > > Thanks for any ideas, > > --Diego > > > > > --000000000000fd8d820595a6cf8c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Chuck,

Thanks for your answer - I di= dn't know about that behavior of=C2=A0 #+CALL, and I'm sure it will= be useful sometime.

However, this is not exactly = what I was getting at. Here's what I want:

1. = First of all, my code needs to tangle correctly - for this I use :noweb and= :noweb-ref in some of the chunks, to structure things better. org-babel-ta= ngle produces a working source file.

2. Upon expor= t, most source blocks should export as-they-are. However, when I use :noweb= or :noweb-ref, I want two things:
=C2=A0 =C2=A0a) Noweb chunk na= mes should not be expanded upon export - e.g. <<super-duper-code>&= gt; should be exported like that
=C2=A0 =C2=A0b) Chunks with :now= eb-ref should be identified by their chunk name in the exported code, e.g. = prepended by "<<super-duper-code>>=3D" in the line be= fore the chunk name.

3. As part of the explanation= in my org file, I have some other source blocks (e.g. Ditaa) which are not= part of=C2=A0 the tangle output, but rather I use=C2=A0 to produce diagram= s or other stuff. For these, I need ":exports results" behavior.<= /div>

And here's my current status:

1. Works, basic org-babel functionality, no issues :)
2.= a. Works by setting ":noweb no-export", no problems.
2.= b. Works by modifying my exporter to include the necessary text in the expo= rted output. *However*, the exporter can only access the :noweb-ref header = argument=C2=A0 if the =3Dorg-export-use-babel=3D variable is set to =3Dnil= =3D. Otherwise, it seems that all org-babel related headers (including :now= eb, :noweb-ref and :exports) are removed from the block before it gets pass= ed to the exporter functions.
3. Only works if =3Dorg-export-use-= babel=3D is set to =3Dt=3D, since otherwise org-babel (who=C2=A0 does the s= election of what gets exported based on=C2=A0 :exports) never gets called.<= /div>

Basically, my problem is the contradiction between= (2.b) and (3) above, with respect to the org-export-use-babel variable. Wh= at I would like to know is if there is a way to keep the :noweb and :noweb-= ref=C2=A0 header arguments in the block, even after org-babel processes the= m.

For (2.b), I=C2=A0 also experimented with setti= ng =3Dorg-babel-exp-code-template=3D, unfortunately I encountered two probl= ems:

1. =3Dorg-fill-template=3D sorts keys=C2=A0 b= y length, which meant that when "%noweb-ref" appears in the templ= ate, it always gets interpreted as "%noweb" followed by the strin= g "-ref".
2. I only want the value of :noweb-ref to be = output when the parameter is specified, but =3Dorg-fill-template=3D doesn&#= 39;t handle that sort of logic - the header argument is always expanded in = the template, even when its value might be missing or "no".
=

So, I'm still looking for a good solution to my pro= blem. In the meantime, I can generate my Ditaa diagrams separately and just= include=C2=A0 the output in my org file, which is not tragic but not the m= ost elegant :)

Hope this further clarifies things!=

Best,
--Diego

=

On Wed, Oct 23, 2019 at 6:51 PM Berry, Charles <ccberry@ucsd.edu> wrote:
<= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft:1px solid rgb(204,204,204);padding-left:1ex">Diego,

I am not sure I understand. Here is my interpretation:

You wish to have `:exports both' behavior in your org export.

You want noweb references in the exported code to render as angle-bracketed= chunk names, such as <<my-code>> rather than being expanded in= place.

If that is what you want, you can use the feature of CALL keywords that res= ets the header arguments for the src block it calls to obtain different beh= avior with the same code. For example:

#+begin_src org
=C2=A0 ,#+name: template-chunk
=C2=A0 ,#+begin_src emacs-lisp :noweb no
=C2=A0 (concat c b a
=C2=A0 <<super-duper-code>>
=C2=A0 )
=C2=A0 ,#+end_src

=C2=A0 ,#+CALL: template-chunk() :noweb yes :var a=3D"A" b=3D&quo= t;B" c=3D"C"

=C2=A0 ,#+begin_src emacs_lisp :noweb-ref super-duper-code
=C2=A0 (concat a b c)
=C2=A0 ,#+end_src
#+end_src

exports as

--8<---------------cut here---------------start------------->8---
,----
| (concat c b a
| <<super-duper-code>>
| )
`----

,----
| CBAABC
`----


,----
| (concat a b c)
`----
--8<---------------cut here---------------end--------------->8---

HTH,

Chuck

> On Oct 22, 2019, at 1:29 PM, Diego Zamboni <diego@zzamboni.org> wrote:
>
> Hi,
>
> I'm working on a Leanpub Markua exporter (not quite complete yet b= ut already usable, if you are interested: https://github.com/zzamboni/ox-leanpub/tree/book-and-markua)
>
> I would like to include the value of :noweb-ref for code blocks in exp= orted output, like noweb originally did, e.g. something like this:
>
> #begin_src emacs_lisp :noweb-ref super-duper-code
> ...
> #end_src
>
> to produce something like this in the export:
>
> <<super-duper-code>>=3D
>=C2=A0 ...
>
> After much poking around, I figured that the :noweb and :noweb-ref hea= der args are removed by org-babel *before* the src block makes it to the ex= porter. I also discovered that by setting org-export-use-babel to nil I cou= ld disable this behavior, which means that my exporter can access the :nowe= b-ref argument by parsing the :parameters property (see https://github.com/zzamboni/ox-lea= npub/blob/book-and-markua/ox-leanpub-markua.el#L388).
>
> This was good for my original purpose, but I just realized that this a= lso disables other useful org-babel features on export, such as the process= ing of the :exports header argument, which means that both code and results= are always included in the export regardless of what :exports says :)
>
> I have tried using org-babel-exp-code-template, but unfortunately if I= try to use "%noweb-ref" as a key in its value, it gets replaced = by the value of :noweb followed by "-ref" in every case.
>
> Is there some other way of accessing org-babel header arguments like := noweb-ref from the exporter, but without having to disable org-babel proces= sing completely? Any other ideas for achieving what I want?
>
> Thanks for any ideas,
> --Diego
>


--000000000000fd8d820595a6cf8c--