emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Diego Zamboni <diego@zzamboni.org>
To: Org-mode <emacs-orgmode@gnu.org>
Subject: How to wrap Org code generated by a source block?
Date: Tue, 10 Nov 2020 15:13:21 +0100	[thread overview]
Message-ID: <CAGY83EdYRpHnv8xVkMxMe5KYTqG_j8fO+7rCyoOnjbzeXDqqDQ@mail.gmail.com> (raw)

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

Hi everyone,

I want to generate some parts of my document programmatically from an
emacs-lisp src block - i.e. the code produces Org markup which I want to
then export. Is there a way to wrap the #+RESULTS block in an environment
that still gets evaluated as Org text (e.g. when exporting)?

More details:

Here's a sample src block which shows the kind of thing I need to do:

#+begin_src emacs-lisp :results value raw :exports results
(mapconcat
 (lambda (b) (format "#+begin_%s
Generated %s block at %s
,#+end_%s" b b (current-time-string) b))
 '("example" "quote") "\n")
#+end_src

Using =:results value raw= in the header produces the result from the block
without wrapping it in any blocks, which is exactly what I need. E.g.:

#+RESULTS:
#+begin_example
Generated example block at Tue Nov 10 15:07:45 2020
#+end_example
#+begin_quote
Generated quote block at Tue Nov 10 15:07:45 2020
#+end_quote

HOWEVER, this has the problem that when I re-evaluate the code block, only
the first block below #+RESULTS gets replaced, pushing the others downward,
so I end up with something like this after a couple of times:

#+RESULTS:
#+begin_example
Generated example block at Tue Nov 10 15:08:42 2020
#+end_example
#+begin_quote
Generated quote block at Tue Nov 10 15:08:42 2020
#+end_quote
#+begin_quote
Generated quote block at Tue Nov 10 15:08:39 2020
#+end_quote
#+begin_quote
Generated quote block at Tue Nov 10 15:07:45 2020
#+end_quote

If I remove the "raw" then the results get wrapped in an example block (or
any other that I specify with =:wrap=), which means they get correctly
replaced every time, but not evaluated as Org text:

#+RESULTS:
: #+begin_example
: Generated example block at Tue Nov 10 15:09:46 2020
: #+end_example
: #+begin_quote
: Generated quote block at Tue Nov 10 15:09:46 2020
: #+end_quote

So again, my question is: is there a way to wrap the #+RESULTS block in an
environment that still gets evaluated as Org text (e.g. when exporting), so
that I can rerun the code block without having to manually trim the results
block afterwards?

Thanks!
--Diego

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

             reply	other threads:[~2020-11-10 14:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-10 14:13 Diego Zamboni [this message]
2020-11-10 17:41 ` Berry, Charles via General discussions about Org-mode.
2020-11-10 18:10   ` Diego Zamboni
2020-11-10 20:13     ` Berry, Charles via General discussions about Org-mode.
2020-11-11  1:44     ` Ihor Radchenko

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=CAGY83EdYRpHnv8xVkMxMe5KYTqG_j8fO+7rCyoOnjbzeXDqqDQ@mail.gmail.com \
    --to=diego@zzamboni.org \
    --cc=emacs-orgmode@gnu.org \
    --subject='Re: How to wrap Org code generated by a source block?' \
    /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

Code repositories for project(s) associated with this 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).