* Possible to use src block to generate org headlines for export?
@ 2014-07-22 23:52 Matt Lundin
2014-07-23 1:27 ` Nick Dokos
0 siblings, 1 reply; 25+ messages in thread
From: Matt Lundin @ 2014-07-22 23:52 UTC (permalink / raw
To: Org Mode
I am attempting to use a babel code snippet to generate org headlines
for export. However, I seem to be running into a corner case here.
AFAICT, the only way to generate headlines safely with babel is to wrap
them in a :RESULTS: drawer.
Take the following example:
--8<---------------cut here---------------start------------->8---
#+BEGIN_SRC perl :export results :results output org drawer
print "* Headline One\n";
print "* Headline Two\n";
print "* Headline Three\n";
#+END_SRC
--8<---------------cut here---------------end--------------->8---
If I hit the source block, it creates wraps the output in a drawer. This
protects the results, so when executing the source block again, babel
correctly detects the drawer and replaces the output rather than
multiplying it indefinitely, as it does with "raw".
--8<---------------cut here---------------start------------->8---
#+RESULTS:
:RESULTS:
* Headline One
* Headline Two
* Headline Three
:END:
--8<---------------cut here---------------end--------------->8---
The problem with the results drawer is that org-element (and thus ox.el)
does not recognize it as a drawer and thus includes :RESULTS: in the
export. The html output looks like this:
--8<---------------cut here---------------start------------->8---
<p>
:RESULTS:
</p>
<div id="outline-container-sec-1" class="outline-2">
<h2 id="sec-1"><span class="section-number-2">1</span> Headline One</h2>
</div>
<div id="outline-container-sec-2" class="outline-2">
<h2 id="sec-2"><span class="section-number-2">2</span> Headline Two</h2>
</div>
<div id="outline-container-sec-3" class="outline-2">
<h2 id="sec-3"><span class="section-number-2">3</span> Headline Three</h2>
<div class="outline-text-2" id="text-3">
</div>
</div>
</div>
--8<---------------cut here---------------end--------------->8---
In short, is there a more graceful and export-friendly way to use babel
to generate org headlines for export? Or is there an easy way to get the
export backend to delete the opening part of the drawer (i.e.,
:RESULTS:)?
Any advice would be greatly appreciated.
Thanks,
Matt
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Possible to use src block to generate org headlines for export?
2014-07-22 23:52 Possible to use src block to generate org headlines for export? Matt Lundin
@ 2014-07-23 1:27 ` Nick Dokos
2014-07-23 2:35 ` Matt Lundin
0 siblings, 1 reply; 25+ messages in thread
From: Nick Dokos @ 2014-07-23 1:27 UTC (permalink / raw
To: emacs-orgmode
Matt Lundin <mdl@imapmail.org> writes:
> I am attempting to use a babel code snippet to generate org headlines
> for export. However, I seem to be running into a corner case here.
>
> AFAICT, the only way to generate headlines safely with babel is to wrap
> them in a :RESULTS: drawer.
>
> Take the following example:
>
> #+BEGIN_SRC perl :export results :results output org drawer
> print "* Headline One\n";
> print "* Headline Two\n";
> print "* Headline Three\n";
> #+END_SRC
>
>
> If I hit the source block, it creates wraps the output in a drawer. This
> protects the results, so when executing the source block again, babel
> correctly detects the drawer and replaces the output rather than
> multiplying it indefinitely, as it does with "raw".
>
> #+RESULTS:
> :RESULTS:
> * Headline One
> * Headline Two
> * Headline Three
> :END:
>
>
> The problem with the results drawer is that org-element (and thus ox.el)
> does not recognize it as a drawer and thus includes :RESULTS: in the
> export. The html output looks like this:
>
> <p>
> :RESULTS:
> </p>
> <div id="outline-container-sec-1" class="outline-2">
> <h2 id="sec-1"><span class="section-number-2">1</span> Headline One</h2>
> </div>
> <div id="outline-container-sec-2" class="outline-2">
> <h2 id="sec-2"><span class="section-number-2">2</span> Headline Two</h2>
> </div>
> <div id="outline-container-sec-3" class="outline-2">
> <h2 id="sec-3"><span class="section-number-2">3</span> Headline Three</h2>
> <div class="outline-text-2" id="text-3">
> </div>
> </div>
> </div>
>
> In short, is there a more graceful and export-friendly way to use babel
> to generate org headlines for export? Or is there an easy way to get the
> export backend to delete the opening part of the drawer (i.e.,
> :RESULTS:)?
>
> Any advice would be greatly appreciated.
>
No solace for your pain alas. See
http://thread.gmane.org/gmane.emacs.orgmode/88557
My suggestion (as it was for Ronald, except that he had already rejected
it :-) ) would be to use raw: you lose the idempotency of results
production, but I don't know of any other problems.
--
Nick
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Possible to use src block to generate org headlines for export?
2014-07-23 1:27 ` Nick Dokos
@ 2014-07-23 2:35 ` Matt Lundin
2014-07-23 2:46 ` Matt Lundin
` (2 more replies)
0 siblings, 3 replies; 25+ messages in thread
From: Matt Lundin @ 2014-07-23 2:35 UTC (permalink / raw
To: Nick Dokos; +Cc: emacs-orgmode
Nick Dokos <ndokos@gmail.com> writes:
>>
>> In short, is there a more graceful and export-friendly way to use babel
>> to generate org headlines for export? Or is there an easy way to get the
>> export backend to delete the opening part of the drawer (i.e.,
>> :RESULTS:)?
>>
>> Any advice would be greatly appreciated.
>>
>
> No solace for your pain alas. See
> http://thread.gmane.org/gmane.emacs.orgmode/88557
>
> My suggestion (as it was for Ronald, except that he had already rejected
> it :-) ) would be to use raw: you lose the idempotency of results
> production, but I don't know of any other problems.
Thanks for the link. My ignorance of it shows how far behind I am on
orgmode ML reading!
I agree with Nicolas's argument that only headlines can contain
headlines.
That said, having the ability to generate org copy for export also seems
useful.
I wonder whether org-babel might take advantage of COMMENT headlines for
org output: E.g.
* COMMENT Here beginneth the results for code block named "do-some-magic"
* COMMENT Here endeth the results for code block named "do-some-magic"
Obviously, this could wreak havoc on ones outline structure, so some
extra magic would be needed to set the correct headline level.
However, since the headlines I'm generating are always at the end of the
file, I've hacked my way to a solution with the following:
--8<---------------cut here---------------start------------->8---
#+BEGIN_SRC emacs-lisp :exports none :results none
(save-excursion
(goto-char (point-min))
(while (re-search-forward "#\\+RESULTS: generate-blog-summary" nil t)
(beginning-of-line)
(delete-region (point) (point-max))))
#+END_SRC
#+NAME: generate-blog-summary
#+BEGIN_SRC perl :exports results :results output org raw
print "* Headline One\n";
print "* Headline Two\n";
print "* Headline Three\n";
#+END_SRC
--8<---------------cut here---------------end--------------->8---
Thus, each time I export, the emacs-lisp snippet nicely deletes the old
results, making space for the new ones.
Let's hope the real blog (when I get around to publishing it) is more
interesting than the example above. ;)
Best,
Matt
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Possible to use src block to generate org headlines for export?
2014-07-23 2:35 ` Matt Lundin
@ 2014-07-23 2:46 ` Matt Lundin
2014-07-23 13:42 ` Brett Viren
2014-07-23 16:09 ` Rick Frankel
2 siblings, 0 replies; 25+ messages in thread
From: Matt Lundin @ 2014-07-23 2:46 UTC (permalink / raw
To: Nick Dokos; +Cc: emacs-orgmode
Correction below...
Matt Lundin <mdl@imapmail.org> writes:
>
> #+BEGIN_SRC emacs-lisp :exports none :results none
> (save-excursion
> (goto-char (point-min))
> (while (re-search-forward "#\\+RESULTS: generate-blog-summary" nil t)
(when ...
> (beginning-of-line)
> (delete-region (point) (point-max))))
> #+END_SRC
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Possible to use src block to generate org headlines for export?
2014-07-23 2:35 ` Matt Lundin
2014-07-23 2:46 ` Matt Lundin
@ 2014-07-23 13:42 ` Brett Viren
2014-07-23 15:17 ` Matt Lundin
2014-07-23 16:09 ` Rick Frankel
2 siblings, 1 reply; 25+ messages in thread
From: Brett Viren @ 2014-07-23 13:42 UTC (permalink / raw
To: Matt Lundin; +Cc: Nick Dokos, emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 275 bytes --]
Matt Lundin <mdl@imapmail.org> writes:
> Let's hope the real blog (when I get around to publishing it) is more
> interesting than the example above. ;)
Maybe it would be more convenient to add the "meta-ness" you want as
part of a new exporter process?
-Brett.
[-- Attachment #2: Type: application/pgp-signature, Size: 180 bytes --]
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Possible to use src block to generate org headlines for export?
2014-07-23 13:42 ` Brett Viren
@ 2014-07-23 15:17 ` Matt Lundin
2014-07-23 16:06 ` Charles Berry
2014-07-23 19:53 ` Brett Viren
0 siblings, 2 replies; 25+ messages in thread
From: Matt Lundin @ 2014-07-23 15:17 UTC (permalink / raw
To: Brett Viren; +Cc: Nick Dokos, emacs-orgmode
Hi Brett,
Brett Viren <bv@bnl.gov> writes:
> Matt Lundin <mdl@imapmail.org> writes:
>
>> Let's hope the real blog (when I get around to publishing it) is more
>> interesting than the example above. ;)
>
> Maybe it would be more convenient to add the "meta-ness" you want as
> part of a new exporter process?
To change the "meta" wrappers for code block results, we would have to
modify org babel (ob-core.el). Right now, the only wrapper that org
babel uses to contain the results of *raw* org output is a :RESULTS:
drawer. However, headlines wrapped in a drawer is something that
org-element, by definition, cannot recognize. For the same reason, no
custom export backend is going to be able to recognize this element.
But I've discovered to my delight all this is moot.
The *best and simplest solution* for automatically generating org
headlines for export is...
...never to execute the source block by hand in org source file. That
way, the results will appear only in the *temporary* copy of the buffer
is parsed for export and one does need to worry about demarcating the
output with a :RESULTS: drawer...
--8<---------------cut here---------------start------------->8---
#+BEGIN_SRC perl :exports results :results output org raw
[code to generate org source]
#+END_SRC
--8<---------------cut here---------------end--------------->8---
The above works perfectly so long I as resist the temptation to hit C-c
C-c.[fn:1]
And that can be solved easily by adding the following line to the top of
the file:
--8<---------------cut here---------------start------------->8---
# -*- org-babel-no-eval-on-ctrl-c-ctrl-c: t; -*-
--8<---------------cut here---------------end--------------->8---
Isn't emacs wonderful?
In short, it is much easier than I assumed to use babel blocks (and any
language one wants) to generate org headlines destined for publishing.
This is amazing! The applications are endless. E.g., I will use this to
generate a blog summary when publishing my website. I'll post a tutorial
sometime soon. Suffice it to say, one can easily use babel blocks to
generate content on a web page, thus implementing the functionality of a
static site generator like Jekyll, docpad, octopress, etc. (but with
infinitely more flexibility).
Best,
Matt
Footnotes:
[fn:1] If one really needs to see the headlines in the original org
buffer, a hook can be used to remove the :RESULTS: drawer.
--8<---------------cut here---------------start------------->8---
(defun my-remove-stray-results-drawer (backend)
(when (eq backend 'html)
(while (re-search-forward "^\\s-*:RESULTS:\\s-*\n" nil t)
(replace-match ""))))
(add-hook 'org-export-before-parsing-hook 'my-remove-results-drawer)
--8<---------------cut here---------------end--------------->8---
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Possible to use src block to generate org headlines for export?
2014-07-23 15:17 ` Matt Lundin
@ 2014-07-23 16:06 ` Charles Berry
2014-07-23 17:07 ` Matt Lundin
2014-07-24 1:51 ` Nick Dokos
2014-07-23 19:53 ` Brett Viren
1 sibling, 2 replies; 25+ messages in thread
From: Charles Berry @ 2014-07-23 16:06 UTC (permalink / raw
To: emacs-orgmode
Matt Lundin <mdl <at> imapmail.org> writes:
[deleted]
> Footnotes:
>
> [fn:1] If one really needs to see the headlines in the original org
> buffer, a hook can be used to remove the :RESULTS: drawer.
>
> --8<---------------cut here---------------start------------->8---
> (defun my-remove-stray-results-drawer (backend)
> (when (eq backend 'html)
> (while (re-search-forward "^\\s-*:RESULTS:\\s-*\n" nil t)
> (replace-match ""))))
>
> (add-hook 'org-export-before-parsing-hook 'my-remove-results-drawer)
> --8<---------------cut here---------------end--------------->8---
>
>
Or wrap the results in a drawer when you type C-c C-c, but render them as
raw on export (which removes the drawer and replaces with raw results).
Like so:
#+header: :results (if (boundp 'backend) "raw" "drawer")
#+BEGIN_SRC emacs-lisp :exports both
(format "* headline\n1\n2\n5\n")
#+END_SRC
HTH,
Chuck
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Possible to use src block to generate org headlines for export?
2014-07-23 2:35 ` Matt Lundin
2014-07-23 2:46 ` Matt Lundin
2014-07-23 13:42 ` Brett Viren
@ 2014-07-23 16:09 ` Rick Frankel
2 siblings, 0 replies; 25+ messages in thread
From: Rick Frankel @ 2014-07-23 16:09 UTC (permalink / raw
To: Matt Lundin; +Cc: Nick Dokos, emacs-orgmode
On 2014-07-22 22:35, Matt Lundin wrote:
> Nick Dokos <ndokos@gmail.com> writes:
>
> In short, is there a more graceful and export-friendly way to use babel
> to generate org headlines for export? Or is there an easy way to get
> the
> export backend to delete the opening part of the drawer (i.e.,
> :RESULTS:)?
>
> Any advice would be greatly appreciated.
>
>
> No solace for your pain alas. See
> http://thread.gmane.org/gmane.emacs.orgmode/88557
>
> My suggestion (as it was for Ronald, except that he had already
> rejected
> it :-) ) would be to use raw: you lose the idempotency of results
> production, but I don't know of any other problems.
>
> However, since the headlines I'm generating are always at the end of
> the
> file, I've hacked my way to a solution with the following:
>
> #+BEGIN_SRC emacs-lisp :exports none :results none
> (save-excursion
> (goto-char (point-min))
> (while (re-search-forward "#\\+RESULTS: generate-blog-summary" nil t)
> (beginning-of-line)
> (delete-region (point) (point-max))))
> #+END_SRC
>
> #+NAME: generate-blog-summary
> #+BEGIN_SRC perl :exports results :results output org raw
> print "* Headline One\n";
> print "* Headline Two\n";
> print "* Headline Three\n";
> #+END_SRC
>
Close. I have a complex process which generates org source that is
then executed as part of the export. I generate org under a single
heading and give the heading a unique id. You can the goto the named
reference and `org-cut-subtree' to remove the output before
re-executing the block to generate the code. This way it can go
anywhere in the file and you don't have to worry about the
`RESULTS:' tag. Here's an abbreviated version of the code i use
(which generated a lot of org tables):
#+BEGIN_SRC org
,#+name: run-parse-spreadsheet
,#+BEGIN_SRC emacs-lisp :results raw none :exports results
(condition-case nil
(progn
(widen)
(org-id-goto "REFERENCE-TABLES")
(org-cut-subtree))
(error t))
(org-babel-goto-named-src-block "parse-spreadsheet")
(org-babel-execute-src-block
nil nil '((:eval . yes) (:results . "raw output")))
(org-table-map-tables 'org-table-align 'quietly)
,#+END_SRC
# *Note:* This is set to =:eval never= because the generated output
# needs to be removed before execution and "refreshed" after
# generation by executing the source block [[run-parse-spreadsheet]]
# above instead of running this directly.
,#+name: parse-spreadsheet
,#+HEADER: :var spreadsheet=spreadsheet
,#+BEGIN_SRC perl :results output :eval never
print join("\n",
"*** Tables",
":PROPERTIES:",
":ID: REFERENCE-TABLES",
":END:",
'',
);
print "**** Table 1\n";
# ...
,#+END_SRC
#+END_SRC
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Possible to use src block to generate org headlines for export?
2014-07-23 16:06 ` Charles Berry
@ 2014-07-23 17:07 ` Matt Lundin
2014-07-24 1:51 ` Nick Dokos
1 sibling, 0 replies; 25+ messages in thread
From: Matt Lundin @ 2014-07-23 17:07 UTC (permalink / raw
To: Charles Berry; +Cc: emacs-orgmode
Charles Berry <ccberry@ucsd.edu> writes:
> Matt Lundin <mdl <at> imapmail.org> writes:
>
> Or wrap the results in a drawer when you type C-c C-c, but render them as
> raw on export (which removes the drawer and replaces with raw results).
>
> Like so:
>
> #+header: :results (if (boundp 'backend) "raw" "drawer")
> #+BEGIN_SRC emacs-lisp :exports both
>
> (format "* headline\n1\n2\n5\n")
> #+END_SRC
Thanks so much! I'm clipping this for reference. This is very helpful
when one wants to preview the results in the buffer.
Best,
Matt
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Possible to use src block to generate org headlines for export?
2014-07-23 15:17 ` Matt Lundin
2014-07-23 16:06 ` Charles Berry
@ 2014-07-23 19:53 ` Brett Viren
2014-07-23 20:42 ` Matt Lundin
1 sibling, 1 reply; 25+ messages in thread
From: Brett Viren @ 2014-07-23 19:53 UTC (permalink / raw
To: Matt Lundin; +Cc: Nick Dokos, emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1273 bytes --]
Matt Lundin <mdl@imapmail.org> writes:
> Brett Viren <bv@bnl.gov> writes:
>>
>> Maybe it would be more convenient to add the "meta-ness" you want as
>> part of a new exporter process?
>
> To change the "meta" wrappers for code block results, we would have to
> modify org babel (ob-core.el).
Just to be clear (hopefully) I actually meant something different. I
was suggesting to *not* use org babel to produce your extra headlines.
Rather, have whatever logic produces them reside in some new exporter.
I'm may be making incorrect guesses as to what you are actually going
for with these extra headlines. You mentioning this is for a blog made
me think they are some kind of "standard augmentation" for every blog
post or something. If not then I'm probably barking up the wrong tree.
But if so, putting them into an exporter seems apt.
This is an approach I'm taking in a JSON+HTML exporter (analogous to the
latex+pdf one) that I'm working on. For example, I'd like to have a
"tag cloud" generated from tags on org headlines. This tag cloud won't
explicitly exist on the org side. Rather it will be implicitly produced
and updated by some (Python) code that runs as part of the JSON->HTML
stage of the exporter.
Cheers,
-Brett.
[-- Attachment #2: Type: application/pgp-signature, Size: 180 bytes --]
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Possible to use src block to generate org headlines for export?
2014-07-23 19:53 ` Brett Viren
@ 2014-07-23 20:42 ` Matt Lundin
2014-07-24 22:05 ` Brett Viren
0 siblings, 1 reply; 25+ messages in thread
From: Matt Lundin @ 2014-07-23 20:42 UTC (permalink / raw
To: Brett Viren; +Cc: emacs-orgmode
Brett Viren <bv@bnl.gov> writes:
> Matt Lundin <mdl@imapmail.org> writes:
>
>> Brett Viren <bv@bnl.gov> writes:
>>>
>>> Maybe it would be more convenient to add the "meta-ness" you want as
>>> part of a new exporter process?
>>
>> To change the "meta" wrappers for code block results, we would have to
>> modify org babel (ob-core.el).
>
> Just to be clear (hopefully) I actually meant something different. I
> was suggesting to *not* use org babel to produce your extra headlines.
> Rather, have whatever logic produces them reside in some new exporter.
>
> I'm may be making incorrect guesses as to what you are actually going
> for with these extra headlines. You mentioning this is for a blog made
> me think they are some kind of "standard augmentation" for every blog
> post or something. If not then I'm probably barking up the wrong tree.
> But if so, putting them into an exporter seems apt.
I am using org-babel (+ perl) to gather a page containing the content of
the most recent posts. I also export this page to rss via ox-rss.el. I
could simply use a perl script to generate the file during the export
process, but a babel source block makes it convenient to modify the text
before and after the dynamic content and to test modifications to the
code.
To generate dynamic content for just one page, babel works fine.
However, if I wanted to update every page with such content, it would
make *much* more sense (as you suggest) to create an exporter.
> This is an approach I'm taking in a JSON+HTML exporter (analogous to
> the latex+pdf one) that I'm working on. For example, I'd like to have
> a "tag cloud" generated from tags on org headlines. This tag cloud
> won't explicitly exist on the org side. Rather it will be implicitly
> produced and updated by some (Python) code that runs as part of the
> JSON->HTML stage of the exporter.
That sounds interesting. I look forward to hearing more!
Thanks for the clarification!
Best,
Matt
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Possible to use src block to generate org headlines for export?
2014-07-23 16:06 ` Charles Berry
2014-07-23 17:07 ` Matt Lundin
@ 2014-07-24 1:51 ` Nick Dokos
2014-07-24 10:21 ` Andreas Leha
2014-07-24 18:40 ` Charles Berry
1 sibling, 2 replies; 25+ messages in thread
From: Nick Dokos @ 2014-07-24 1:51 UTC (permalink / raw
To: emacs-orgmode
Charles Berry <ccberry@ucsd.edu> writes:
> Matt Lundin <mdl <at> imapmail.org> writes:
>
> [deleted]
>
>> Footnotes:
>>
>> [fn:1] If one really needs to see the headlines in the original org
>> buffer, a hook can be used to remove the :RESULTS: drawer.
>>
>> --8<---------------cut here---------------start------------->8---
>> (defun my-remove-stray-results-drawer (backend)
>> (when (eq backend 'html)
>> (while (re-search-forward "^\\s-*:RESULTS:\\s-*\n" nil t)
>> (replace-match ""))))
>>
>> (add-hook 'org-export-before-parsing-hook 'my-remove-results-drawer)
>> --8<---------------cut here---------------end--------------->8---
>>
>>
>
> Or wrap the results in a drawer when you type C-c C-c, but render them as
> raw on export (which removes the drawer and replaces with raw results).
>
> Like so:
>
> #+header: :results (if (boundp 'backend) "raw" "drawer")
> #+BEGIN_SRC emacs-lisp :exports both
>
> (format "* headline\n1\n2\n5\n")
> #+END_SRC
>
That's a very nice tip - one small weakness is that it'll do the wrong
thing if you just happen to have a binding for "backend" outside of the
export mechanism.
--
Nick
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Possible to use src block to generate org headlines for export?
2014-07-24 1:51 ` Nick Dokos
@ 2014-07-24 10:21 ` Andreas Leha
2014-07-25 8:31 ` Nicolas Goaziou
2014-07-24 18:40 ` Charles Berry
1 sibling, 1 reply; 25+ messages in thread
From: Andreas Leha @ 2014-07-24 10:21 UTC (permalink / raw
To: emacs-orgmode
Hi all,
Nick Dokos <ndokos@gmail.com> writes:
> Charles Berry <ccberry@ucsd.edu> writes:
>
>> Matt Lundin <mdl <at> imapmail.org> writes:
>>
>> [deleted]
>>
>>> Footnotes:
>>>
>>> [fn:1] If one really needs to see the headlines in the original org
>>> buffer, a hook can be used to remove the :RESULTS: drawer.
>>>
>>> --8<---------------cut here---------------start------------->8---
>>> (defun my-remove-stray-results-drawer (backend)
>>> (when (eq backend 'html)
>>> (while (re-search-forward "^\\s-*:RESULTS:\\s-*\n" nil t)
>>> (replace-match ""))))
>>>
>>> (add-hook 'org-export-before-parsing-hook 'my-remove-results-drawer)
>>> --8<---------------cut here---------------end--------------->8---
>>>
>>>
>>
>> Or wrap the results in a drawer when you type C-c C-c, but render them as
>> raw on export (which removes the drawer and replaces with raw results).
>>
>> Like so:
>>
>> #+header: :results (if (boundp 'backend) "raw" "drawer")
>> #+BEGIN_SRC emacs-lisp :exports both
>>
>> (format "* headline\n1\n2\n5\n")
>> #+END_SRC
>>
>
> That's a very nice tip - one small weakness is that it'll do the wrong
> thing if you just happen to have a binding for "backend" outside of the
> export mechanism.
Is that a valid feature request:
Allow the combination of :results raw and :results replace -- regardless
of the produced content?
IIUC the parser does not allow this right now. But (without any
knowledge on the parser) I can imagine
'special' results drawers that do not have any function/effect other than
delimiting babel results (plus possibly folding).
If these existed, I would even enable them by default no matter of 'raw'
or not.
Something like this:
--8<---------------cut here---------------start------------->8---
#+name: some_code
#+begin_src sh
echo "hello world"
#+end_src
#+begin_results some_code
: hello world
#+end_results
--8<---------------cut here---------------end--------------->8---
Regards,
Andreas
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Possible to use src block to generate org headlines for export?
2014-07-24 1:51 ` Nick Dokos
2014-07-24 10:21 ` Andreas Leha
@ 2014-07-24 18:40 ` Charles Berry
2014-07-24 19:41 ` Nick Dokos
1 sibling, 1 reply; 25+ messages in thread
From: Charles Berry @ 2014-07-24 18:40 UTC (permalink / raw
To: emacs-orgmode
Nick Dokos <ndokos <at> gmail.com> writes:
>
> Charles Berry <ccberry <at> ucsd.edu> writes:
>
> > Matt Lundin <mdl <at> imapmail.org> writes:
> >
> > [deleted]
[more deleted]
> > Or wrap the results in a drawer when you type C-c C-c, but render them as
> > raw on export (which removes the drawer and replaces with raw results).
> >
> > Like so:
> >
> > #+header: :results (if (boundp 'backend) "raw" "drawer")
> > #+BEGIN_SRC emacs-lisp :exports both
> >
> > (format "* headline\n1\n2\n5\n")
> > #+END_SRC
> >
>
> That's a very nice tip - one small weakness is that it'll do the wrong
> thing if you just happen to have a binding for "backend" outside of the
> export mechanism.
>
Fair enough. But getting assurance that an export process is really up and
running looked tricky to me - what with anonymous backends and `info' being
let-bound by babel. So this is what I came up with for a more robust test.
Hopefully, nobody will bind both `backend' and `org-export-current-backend'
to a common backend outside of doing an export...
#+BEGIN_SRC emacs-lisp
(defun org-export-if-exporting (export-val &optional other-val)
"If backend exists, is a backend, and is currently running
return EXPORT-VAL otherwise return OTHER-VAL or \"\"."
(if
(and (boundp 'backend)
(equal (car (append backend nil))
'cl-struct-org-export-backend)
(equal org-export-current-backend
(org-export-backend-name backend)))
export-val
(or other-val "")))
#+END_SRC
#+header: :results (org-export-if-exporting "raw")
#+BEGIN_SRC emacs-lisp :exports both
(format "* headline\n1\n2\n6\n")
#+END_SRC
Chuck
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Possible to use src block to generate org headlines for export?
2014-07-24 18:40 ` Charles Berry
@ 2014-07-24 19:41 ` Nick Dokos
0 siblings, 0 replies; 25+ messages in thread
From: Nick Dokos @ 2014-07-24 19:41 UTC (permalink / raw
To: emacs-orgmode
Charles Berry <ccberry@ucsd.edu> writes:
> Nick Dokos <ndokos <at> gmail.com> writes:
>
>>
>> Charles Berry <ccberry <at> ucsd.edu> writes:
>>
>> > Matt Lundin <mdl <at> imapmail.org> writes:
>> >
>> > [deleted]
> [more deleted]
>
>> > Or wrap the results in a drawer when you type C-c C-c, but render them as
>> > raw on export (which removes the drawer and replaces with raw results).
>> >
>> > Like so:
>> >
>> > #+header: :results (if (boundp 'backend) "raw" "drawer")
>> > #+BEGIN_SRC emacs-lisp :exports both
>> >
>> > (format "* headline\n1\n2\n5\n")
>> > #+END_SRC
>> >
>>
>> That's a very nice tip - one small weakness is that it'll do the wrong
>> thing if you just happen to have a binding for "backend" outside of the
>> export mechanism.
>>
>
> Fair enough. But getting assurance that an export process is really up and
> running looked tricky to me - what with anonymous backends and `info' being
> let-bound by babel. So this is what I came up with for a more robust test.
> Hopefully, nobody will bind both `backend' and `org-export-current-backend'
> to a common backend outside of doing an export...
>
>
> #+BEGIN_SRC emacs-lisp
> (defun org-export-if-exporting (export-val &optional other-val)
> "If backend exists, is a backend, and is currently running
> return EXPORT-VAL otherwise return OTHER-VAL or \"\"."
> (if
> (and (boundp 'backend)
> (equal (car (append backend nil))
> 'cl-struct-org-export-backend)
> (equal org-export-current-backend
> (org-export-backend-name backend)))
> export-val
> (or other-val "")))
>
> #+END_SRC
> #+header: :results (org-export-if-exporting "raw")
> #+BEGIN_SRC emacs-lisp :exports both
> (format "* headline\n1\n2\n6\n")
> #+END_SRC
>
>
Oh, man - I didn't mean that it needed hardening: it was a *very* small
weakness. I just meant to warn people so that they wouldn't do something
silly.
But thanks for going the extra distance.
Nick
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Possible to use src block to generate org headlines for export?
2014-07-23 20:42 ` Matt Lundin
@ 2014-07-24 22:05 ` Brett Viren
0 siblings, 0 replies; 25+ messages in thread
From: Brett Viren @ 2014-07-24 22:05 UTC (permalink / raw
To: Matt Lundin; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 219 bytes --]
Matt Lundin <mdl@imapmail.org> writes:
> That sounds interesting. I look forward to hearing more!
It's not yet usable for anything real but I'm keeping the work here:
https://github.com/brettviren/orgonpy
-Brett.
[-- Attachment #2: Type: application/pgp-signature, Size: 180 bytes --]
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Possible to use src block to generate org headlines for export?
2014-07-24 10:21 ` Andreas Leha
@ 2014-07-25 8:31 ` Nicolas Goaziou
2014-07-25 13:05 ` Andreas Leha
0 siblings, 1 reply; 25+ messages in thread
From: Nicolas Goaziou @ 2014-07-25 8:31 UTC (permalink / raw
To: Andreas Leha; +Cc: emacs-orgmode
Hello,
Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:
> Is that a valid feature request:
> Allow the combination of :results raw and :results replace -- regardless
> of the produced content?
>
> IIUC the parser does not allow this right now. But (without any
> knowledge on the parser) I can imagine
> 'special' results drawers that do not have any function/effect other than
> delimiting babel results (plus possibly folding).
> If these existed, I would even enable them by default no matter of 'raw'
> or not.
No matter how special the results drawer is, it cannot (and shouldn't)
contain headlines.
There are a few options to mark raw output even with headlines:
1. Use text properties to mark the part of the buffer generated by
a given source block. The main drawback is that Org is not just
plain text anymore (some information is hidden and cannot be found
just looking at the text).
2. Use comment cookies around the area:
# Raw Babel Output : src-name (begin)
* Some headline
# Raw Babel Output : src-name (end)
This is not very pretty. Also, it may be difficult to handle
overlapping changes around the same region.
OTOH, headlines are the only limitation to raw+replace behaviour. Some
decent workarounds to this problem were offered in this thread. We can
also live with it.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Possible to use src block to generate org headlines for export?
2014-07-25 8:31 ` Nicolas Goaziou
@ 2014-07-25 13:05 ` Andreas Leha
2014-07-25 13:23 ` Nicolas Goaziou
0 siblings, 1 reply; 25+ messages in thread
From: Andreas Leha @ 2014-07-25 13:05 UTC (permalink / raw
To: emacs-orgmode
Hi Nicolas,
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> Hello,
>
> Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:
>
>> Is that a valid feature request:
>> Allow the combination of :results raw and :results replace -- regardless
>> of the produced content?
>>
>> IIUC the parser does not allow this right now. But (without any
>> knowledge on the parser) I can imagine
>> 'special' results drawers that do not have any function/effect other than
>> delimiting babel results (plus possibly folding).
>> If these existed, I would even enable them by default no matter of 'raw'
>> or not.
>
> No matter how special the results drawer is, it cannot (and shouldn't)
> contain headlines.
>
You are the master of the parser...
> There are a few options to mark raw output even with headlines:
>
> 1. Use text properties to mark the part of the buffer generated by
> a given source block. The main drawback is that Org is not just
> plain text anymore (some information is hidden and cannot be found
> just looking at the text).
>
> 2. Use comment cookies around the area:
>
> # Raw Babel Output : src-name (begin)
> * Some headline
> # Raw Babel Output : src-name (end)
>
> This is not very pretty. Also, it may be difficult to handle
> overlapping changes around the same region.
>
> OTOH, headlines are the only limitation to raw+replace behaviour. Some
> decent workarounds to this problem were offered in this thread. We can
> also live with it.
>
IIUC, you are saying that raw+replace is possible right now for any
content in the results (other than headlines), if the results are in a
drawer?
Then, my follow-up question is simply, why are drawers not the default
for results, then? Is there any drawback (apart from an additional
line)?
Regards,
Andreas
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Possible to use src block to generate org headlines for export?
2014-07-25 13:05 ` Andreas Leha
@ 2014-07-25 13:23 ` Nicolas Goaziou
2014-07-25 13:39 ` Andreas Leha
0 siblings, 1 reply; 25+ messages in thread
From: Nicolas Goaziou @ 2014-07-25 13:23 UTC (permalink / raw
To: Andreas Leha; +Cc: emacs-orgmode
Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:
> Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
>> No matter how special the results drawer is, it cannot (and shouldn't)
>> contain headlines.
>
> You are the master of the parser...
That's why I carefully avoid shooting myself in the foot. There is (at
least) a good reason why only headlines can contain headlines, which is
speed, as a consequence of CFG.
> IIUC, you are saying that raw+replace is possible right now for any
> content in the results (other than headlines), if the results are in a
> drawer?
If the results are in a drawer, this is not "raw" anymore, but "drawer".
Anyway you can put anything in your drawer besides a headline and
another drawer.
> Then, my follow-up question is simply, why are drawers not the default
> for results, then? Is there any drawback (apart from an additional
> line)?
The block may insert a headline, or another drawer, within the results
drawer, thus breaking the document.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Possible to use src block to generate org headlines for export?
2014-07-25 13:23 ` Nicolas Goaziou
@ 2014-07-25 13:39 ` Andreas Leha
2014-07-25 14:26 ` Thorsten Jolitz
2014-07-25 16:08 ` Nicolas Goaziou
0 siblings, 2 replies; 25+ messages in thread
From: Andreas Leha @ 2014-07-25 13:39 UTC (permalink / raw
To: emacs-orgmode
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:
>
>> Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
>
>>> No matter how special the results drawer is, it cannot (and shouldn't)
>>> contain headlines.
>>
>> You are the master of the parser...
>
> That's why I carefully avoid shooting myself in the foot. There is (at
> least) a good reason why only headlines can contain headlines, which is
> speed, as a consequence of CFG.
>
>> IIUC, you are saying that raw+replace is possible right now for any
>> content in the results (other than headlines), if the results are in a
>> drawer?
>
> If the results are in a drawer, this is not "raw" anymore, but "drawer".
> Anyway you can put anything in your drawer besides a headline and
> another drawer.
But then, I do not understand your statement 'headlines are the only
limitation to raw+replace behaviour'.
This code block does not seem to respect 'raw+replace' for me:
#+name: dtrn
#+BEGIN_SRC R :results raw replace
nwords <- 500
nletters <- sapply(1:nwords, function(i) sample(1:10, 1))
words <- sapply(nletters, function(i) paste(sample(letters, i), collapse=""))
words[sample(nwords, 100)] <- "\n"
paste(words, collapse=" ")
#+END_SRC
>
>> Then, my follow-up question is simply, why are drawers not the default
>> for results, then? Is there any drawback (apart from an additional
>> line)?
>
> The block may insert a headline, or another drawer, within the results
> drawer, thus breaking the document.
>
I understand that. Will update my local 'defaults' then to drawer.
Regards,
Andreas
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Possible to use src block to generate org headlines for export?
2014-07-25 13:39 ` Andreas Leha
@ 2014-07-25 14:26 ` Thorsten Jolitz
2014-07-25 16:08 ` Nicolas Goaziou
1 sibling, 0 replies; 25+ messages in thread
From: Thorsten Jolitz @ 2014-07-25 14:26 UTC (permalink / raw
To: emacs-orgmode
Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:
> But then, I do not understand your statement 'headlines are the only
> limitation to raw+replace behaviour'.
>
> This code block does not seem to respect 'raw+replace' for me:
>
> #+name: dtrn
> #+BEGIN_SRC R :results raw replace
> nwords <- 500
> nletters <- sapply(1:nwords, function(i) sample(1:10, 1))
> words <- sapply(nletters, function(i) paste(sample(letters, i),
> collapse=""))
> words[sample(nwords, 100)] <- "\n"
> paste(words, collapse=" ")
> #+END_SRC
neither for me, see this thread (I hope the link works):
[[gnus:nntp+news.gmane.org:gmane.emacs.orgmode#87vbraroza.fsf@gmail.com][Email
from Thorsten Jolitz: {BUG} src_blocks - :results ra]]
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Possible to use src block to generate org headlines for export?
2014-07-25 13:39 ` Andreas Leha
2014-07-25 14:26 ` Thorsten Jolitz
@ 2014-07-25 16:08 ` Nicolas Goaziou
2014-07-26 0:26 ` Andreas Leha
1 sibling, 1 reply; 25+ messages in thread
From: Nicolas Goaziou @ 2014-07-25 16:08 UTC (permalink / raw
To: Andreas Leha; +Cc: emacs-orgmode
Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:
> But then, I do not understand your statement 'headlines are the only
> limitation to raw+replace behaviour'.
>
> This code block does not seem to respect 'raw+replace' for me:
>
> #+name: dtrn
> #+BEGIN_SRC R :results raw replace
> nwords <- 500
> nletters <- sapply(1:nwords, function(i) sample(1:10, 1))
> words <- sapply(nletters, function(i) paste(sample(letters, i), collapse=""))
> words[sample(nwords, 100)] <- "\n"
> paste(words, collapse=" ")
> #+END_SRC
That was not clear, indeed.
"raw" behaviour is only "useful" (i.e., mandatory) when you want to
insert a headline (or a drawer) as a result of a code block evaluation.
But then, you lose the ability to replace results. That's the limitation
I'm talking about.
In any other case, "drawer+replace" is the superior choice.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Possible to use src block to generate org headlines for export?
2014-07-25 16:08 ` Nicolas Goaziou
@ 2014-07-26 0:26 ` Andreas Leha
2014-07-26 8:07 ` Nicolas Goaziou
0 siblings, 1 reply; 25+ messages in thread
From: Andreas Leha @ 2014-07-26 0:26 UTC (permalink / raw
To: emacs-orgmode
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:
>
>> But then, I do not understand your statement 'headlines are the only
>> limitation to raw+replace behaviour'.
>>
>> This code block does not seem to respect 'raw+replace' for me:
>>
>> #+name: dtrn
>> #+BEGIN_SRC R :results raw replace
>> nwords <- 500
>> nletters <- sapply(1:nwords, function(i) sample(1:10, 1))
>> words <- sapply(nletters, function(i) paste(sample(letters, i), collapse=""))
>> words[sample(nwords, 100)] <- "\n"
>> paste(words, collapse=" ")
>> #+END_SRC
>
> That was not clear, indeed.
>
> "raw" behaviour is only "useful" (i.e., mandatory) when you want to
> insert a headline (or a drawer) as a result of a code block evaluation.
> But then, you lose the ability to replace results. That's the limitation
> I'm talking about.
>
> In any other case, "drawer+replace" is the superior choice.
Thanks for this clarification.
But in that case let me return to and refine my proposal: Why not have
"drawer" as the default unless "raw" is given?
One could argue, that the extent of the results is implicitly given
when the results are not "raw", but being explicit here would allow for
some additional features (such as different background for results -- is
anyone doing this? I'd be interested).
One could also argue, that the users are free to put their results in
drawers if they wish. But on the other hand what would be lost by
defaulting to drawers?
<<<<< main part ends here
Having said all that, I want to add, that I do not particularly like the
visual appearance of drawers for results blocks; I think they
- add one more line than necessary and they
- differ too much from the appearance of source blocks
This is the state in org This is what I'd prefer...
--8<------start-------->8--- --8<------start-------->8---
#+PROPERTY: results drawer #+PROPERTY: results drawer
* Test * Test
#+name: dtrn #+name: dtrn
#+begin_src R :exports both #+begin_src R :exports both
"hello" "hello"
#+end_src #+end_src
#+results: dtrn
:RESULTS: #+begin_results dtrn
hello hello
:END: #+end_results
--8<-------end--------->8--- --8<-------end--------->8---
But do not take this too seriously. I am more than happy to live with
the standard appearance of drawers here.
Regards,
Andreas
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Possible to use src block to generate org headlines for export?
2014-07-26 0:26 ` Andreas Leha
@ 2014-07-26 8:07 ` Nicolas Goaziou
2014-07-26 19:47 ` Andreas Leha
0 siblings, 1 reply; 25+ messages in thread
From: Nicolas Goaziou @ 2014-07-26 8:07 UTC (permalink / raw
To: Andreas Leha; +Cc: emacs-orgmode
> But in that case let me return to and refine my proposal: Why not have
> "drawer" as the default unless "raw" is given?
Probably because "raw" never breaks your document, and is less verbose
in the simplest cases (e.g., a single list, value, table...), which may
be common enough.
Anyway, it should be simple enough to switch to "drawer" as a default in
your setup.
> One could argue, that the extent of the results is implicitly given
> when the results are not "raw", but being explicit here would allow for
> some additional features (such as different background for results -- is
> anyone doing this? I'd be interested).
"raw" doesn't prevent to add a different background, if needed.
> This is the state in org This is what I'd prefer...
> --8<------start-------->8--- --8<------start-------->8---
>
> #+PROPERTY: results drawer #+PROPERTY: results drawer
>
>
> * Test * Test
>
> #+name: dtrn #+name: dtrn
> #+begin_src R :exports both #+begin_src R :exports both
>
> "hello" "hello"
> #+end_src #+end_src
>
>
> #+results: dtrn
> :RESULTS: #+begin_results dtrn
>
> hello hello
> :END: #+end_results
> --8<-------end--------->8--- --8<-------end--------->8---
What you prefer is a special block, which is not neutral during export
process. Of course, a "result" block type could be added to Org syntax,
but that would be redundant with drawers.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Possible to use src block to generate org headlines for export?
2014-07-26 8:07 ` Nicolas Goaziou
@ 2014-07-26 19:47 ` Andreas Leha
0 siblings, 0 replies; 25+ messages in thread
From: Andreas Leha @ 2014-07-26 19:47 UTC (permalink / raw
To: emacs-orgmode
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
>> But in that case let me return to and refine my proposal: Why not have
>> "drawer" as the default unless "raw" is given?
>
> Probably because "raw" never breaks your document, and is less verbose
> in the simplest cases (e.g., a single list, value, table...), which may
> be common enough.
>
> Anyway, it should be simple enough to switch to "drawer" as a default in
> your setup.
>
True.
>> One could argue, that the extent of the results is implicitly given
>> when the results are not "raw", but being explicit here would allow for
>> some additional features (such as different background for results -- is
>> anyone doing this? I'd be interested).
>
> "raw" doesn't prevent to add a different background, if needed.
>
I'd be very interested in that.
>> This is the state in org This is what I'd prefer...
>> --8<------start-------->8--- --8<------start-------->8---
>>
>> #+PROPERTY: results drawer #+PROPERTY: results drawer
>>
>>
>> * Test * Test
>>
>> #+name: dtrn #+name: dtrn
>> #+begin_src R :exports both #+begin_src R :exports both
>>
>> "hello" "hello"
>> #+end_src #+end_src
>>
>>
>> #+results: dtrn
>> :RESULTS: #+begin_results dtrn
>>
>> hello hello
>> :END: #+end_results
>> --8<-------end--------->8--- --8<-------end--------->8---
>
> What you prefer is a special block, which is not neutral during export
> process. Of course, a "result" block type could be added to Org syntax,
> but that would be redundant with drawers.
Thanks for your comment on this. Yes, a special block is indeed what I'd
prefer visually. And a "result" block type could be non-redundant with
drawers if it was allowed to contain headlines and drawers .... ;-)
But let's leave it there. As I said: I am quite fine with the drawers.
Regards,
Andreas
^ permalink raw reply [flat|nested] 25+ messages in thread
end of thread, other threads:[~2014-07-26 19:47 UTC | newest]
Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-22 23:52 Possible to use src block to generate org headlines for export? Matt Lundin
2014-07-23 1:27 ` Nick Dokos
2014-07-23 2:35 ` Matt Lundin
2014-07-23 2:46 ` Matt Lundin
2014-07-23 13:42 ` Brett Viren
2014-07-23 15:17 ` Matt Lundin
2014-07-23 16:06 ` Charles Berry
2014-07-23 17:07 ` Matt Lundin
2014-07-24 1:51 ` Nick Dokos
2014-07-24 10:21 ` Andreas Leha
2014-07-25 8:31 ` Nicolas Goaziou
2014-07-25 13:05 ` Andreas Leha
2014-07-25 13:23 ` Nicolas Goaziou
2014-07-25 13:39 ` Andreas Leha
2014-07-25 14:26 ` Thorsten Jolitz
2014-07-25 16:08 ` Nicolas Goaziou
2014-07-26 0:26 ` Andreas Leha
2014-07-26 8:07 ` Nicolas Goaziou
2014-07-26 19:47 ` Andreas Leha
2014-07-24 18:40 ` Charles Berry
2014-07-24 19:41 ` Nick Dokos
2014-07-23 19:53 ` Brett Viren
2014-07-23 20:42 ` Matt Lundin
2014-07-24 22:05 ` Brett Viren
2014-07-23 16:09 ` Rick Frankel
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.