Org-mode mailing list
 help / color / mirror / Atom feed
* How to wrap Org code generated by a source block?
@ 2020-11-10 14:13 Diego Zamboni
  2020-11-10 17:41 ` Berry, Charles via General discussions about Org-mode.
  0 siblings, 1 reply; 5+ messages in thread
From: Diego Zamboni @ 2020-11-10 14:13 UTC (permalink / raw)
  To: Org-mode

[-- 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 --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to wrap Org code generated by a source block?
  2020-11-10 14:13 How to wrap Org code generated by a source block? Diego Zamboni
@ 2020-11-10 17:41 ` Berry, Charles via General discussions about Org-mode.
  2020-11-10 18:10   ` Diego Zamboni
  0 siblings, 1 reply; 5+ messages in thread
From: Berry, Charles via General discussions about Org-mode. @ 2020-11-10 17:41 UTC (permalink / raw)
  To: Diego Zamboni; +Cc: Org-mode



> On Nov 10, 2020, at 6:13 AM, Diego Zamboni <diego@zzamboni.org> wrote:
> 
> 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)?
> 
> 


Try `:results drawer'

You can also do fancy stuff using `:wrap "src ..."' where `...' is a language and additional header args. One language choice is `org', but I don't think this approach is what you need.

HTH,
Chuck


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to wrap Org code generated by a source block?
  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
  0 siblings, 2 replies; 5+ messages in thread
From: Diego Zamboni @ 2020-11-10 18:10 UTC (permalink / raw)
  To: Berry, Charles; +Cc: Org-mode

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

Hi Chuck,

Thanks! =:results drawer= is exactly what I was looking for :)

I tried also with =:wrap src org=, but then upon export it's exported
literally as Org src code, instead of interpreted as such. The drawer was
exactly what I needed, and allows reevaluation of the block, replacing all
the results correctly.

Cheers,
--Diego


On Tue, Nov 10, 2020 at 6:41 PM Berry, Charles <ccberry@health.ucsd.edu>
wrote:

>
>
> > On Nov 10, 2020, at 6:13 AM, Diego Zamboni <diego@zzamboni.org> wrote:
> >
> > 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)?
> >
> >
>
>
> Try `:results drawer'
>
> You can also do fancy stuff using `:wrap "src ..."' where `...' is a
> language and additional header args. One language choice is `org', but I
> don't think this approach is what you need.
>
> HTH,
> Chuck
>

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to wrap Org code generated by a source block?
  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
  1 sibling, 0 replies; 5+ messages in thread
From: Berry, Charles via General discussions about Org-mode. @ 2020-11-10 20:13 UTC (permalink / raw)
  To: Diego Zamboni; +Cc: Org-mode



> On Nov 10, 2020, at 10:10 AM, Diego Zamboni <diego@zzamboni.org> wrote:
> 
> I tried also with =:wrap src org=, but then upon export it's exported literally as Org src code, instead of interpreted as such. The drawer was exactly what I needed, and allows reevaluation of the block, replacing all the results correctly.
> 

If you have loaded `ob-org.el', this is the moral equivalent to drawer:

#+header:  :wrap "src org :exports results :results replace"

But it is so awkward, I would not use it.

HTH,

Chuck




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to wrap Org code generated by a source block?
  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
  1 sibling, 0 replies; 5+ messages in thread
From: Ihor Radchenko @ 2020-11-11  1:44 UTC (permalink / raw)
  To: Diego Zamboni, Berry, Charles; +Cc: Org-mode

> I tried also with =:wrap src org=, but then upon export it's exported
> literally as Org src code, instead of interpreted as such.

An alternative might also be =:wrap export org=.


Diego Zamboni <diego@zzamboni.org> writes:

> Hi Chuck,
>
> Thanks! =:results drawer= is exactly what I was looking for :)
>
> I tried also with =:wrap src org=, but then upon export it's exported
> literally as Org src code, instead of interpreted as such. The drawer was
> exactly what I needed, and allows reevaluation of the block, replacing all
> the results correctly.
>
> Cheers,
> --Diego
>
>
> On Tue, Nov 10, 2020 at 6:41 PM Berry, Charles <ccberry@health.ucsd.edu>
> wrote:
>
>>
>>
>> > On Nov 10, 2020, at 6:13 AM, Diego Zamboni <diego@zzamboni.org> wrote:
>> >
>> > 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)?
>> >
>> >
>>
>>
>> Try `:results drawer'
>>
>> You can also do fancy stuff using `:wrap "src ..."' where `...' is a
>> language and additional header args. One language choice is `org', but I
>> don't think this approach is what you need.
>>
>> HTH,
>> Chuck
>>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-11-11  1:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-10 14:13 How to wrap Org code generated by a source block? Diego Zamboni
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

Org-mode mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://orgmode.org/list/0 list/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 list list/ https://orgmode.org/list \
		emacs-orgmode@gnu.org
	public-inbox-index list

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.orgmode
	nntp://news.gmane.io/gmane.emacs.orgmode


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git