* How to call a code block by its name in the :prologue header argument?
@ 2021-02-12 1:50 Rodrigo Morales
0 siblings, 0 replies; only message in thread
From: Rodrigo Morales @ 2021-02-12 1:50 UTC (permalink / raw)
* The problem
Let's suppose we have this simple code block
which contain some commands that we want to execute before the
commands that are presented below. Therefore, we use the =:prologue=
#+begin_src bash :noweb yes :prologue "<<my-named-code-block>>"
However, when evaluating the code block, the buffer =*Org-Babel Error
Output*= is opened with the following content. Apparently, this
happens because the noweb reference added in the prologue is not
expanded. Therefore, =bash= executes =<<foo>>= which results in the
error shown below.
bash: line 2: warning: here-document at line 1 delimited by end-of-file (wanted `my-named-code-block')
bash: line 2: syntax error near unexpected token `newline'
bash: line 2: `<<my-named-code-block>>'
* The question
How can I add the content of a code block as the =:prologue= of
another code block?
* Additional information
I don't want to add =<<foo>>= inside the code block (see below for
example) since that would imply that the content of the code block is
explicitly changed. Note that this doesn't happen when using
=:prologue= because it can be set through different ways that don't
imply changing the content of the code block where the commands are
intended to be executed.
* A possible solution
I was thinking in the following solution: Find/Create a function which
gets the content of a code block as an string given its name so that
it could be called as it follows
#+begin_src bash :prologue (get-code-block-as-string "my-named-code-block")
Recall that this would work because =:prologue= accept strings (see
#+begin_src bash :prologue "echo foo\necho bar"
* Relevant information
Found the following relevant sources of information
 A user had asked this in a question in Stack Overflow but he
didn't get any significant response.
 Some user created a thread in the emacs-orgmode mailing list
asking why noweb expansion occurs before prologue expansion and
presents an example similar to mine. The thread didn't get any
[3, 4] In a thread in the emacs-orgmode mailing list, this was asked
before but the only solution provided was to insert a noweb reference
inside the code block.
IRC: rdrg109 (freenode)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-02-12 1:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-12 1:50 How to call a code block by its name in the :prologue header argument? Rodrigo Morales
Code repositories for project(s) associated with this inbox:
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).