emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Diego Zamboni <diego@zzamboni.org>
To: "Berry, Charles" <ccberry@ucsd.edu>
Cc: Org-mode <emacs-orgmode@gnu.org>
Subject: Re: Exporting noweb-ref's without disabling org-babel processing
Date: Thu, 24 Oct 2019 14:02:39 +0200	[thread overview]
Message-ID: <CAGY83Efr5mN78R07wMbF=GPRPOygW0xX0=4jiMmtgf9t4Vck0A@mail.gmail.com> (raw)
In-Reply-To: <13AFA234-5B6C-4526-9838-03EB57B82899@ucsd.edu>

[-- Attachment #1: Type: text/plain, Size: 5828 bytes --]

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.
<<super-duper-code>> 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 "<<super-duper-code>>=" 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 <ccberry@ucsd.edu> 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 <<my-code>> 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
>   <<super-duper-code>>
>   )
>   ,#+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
> | <<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 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:
> >
> > <<super-duper-code>>=
> >  ...
> >
> > 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
> >
>
>
>

[-- Attachment #2: Type: text/html, Size: 7392 bytes --]

      reply	other threads:[~2019-10-24 12:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-22 20:29 Exporting noweb-ref's without disabling org-babel processing Diego Zamboni
2019-10-23 16:50 ` Berry, Charles
2019-10-24 12:02   ` Diego Zamboni [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAGY83Efr5mN78R07wMbF=GPRPOygW0xX0=4jiMmtgf9t4Vck0A@mail.gmail.com' \
    --to=diego@zzamboni.org \
    --cc=ccberry@ucsd.edu \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).