Re: [O] Possible to use src block to generate org headlines for export?

2014-07-26 Thread Nicolas Goaziou
 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--start8---   --8--start8---

 #+PROPERTY: results drawer #+PROPERTY: results drawer  


 * Test * Test

 #+name: dtrn   #+name: dtrn
 #+begin_src R :exports both#+begin_src R :exports both 

   hellohello   
 #+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



Re: [O] Possible to use src block to generate org headlines for export?

2014-07-26 Thread Andreas Leha
Nicolas Goaziou m...@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--start8---   --8--start8---

 #+PROPERTY: results drawer #+PROPERTY: results drawer  


 * Test * Test

 #+name: dtrn   #+name: dtrn
 #+begin_src R :exports both#+begin_src R :exports both 

   hellohello   
 #+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




Re: [O] Possible to use src block to generate org headlines for export?

2014-07-25 Thread Nicolas Goaziou
Hello,

Andreas Leha andreas.l...@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



Re: [O] Possible to use src block to generate org headlines for export?

2014-07-25 Thread Andreas Leha
Hi Nicolas,

Nicolas Goaziou m...@nicolasgoaziou.fr writes:

 Hello,

 Andreas Leha andreas.l...@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




Re: [O] Possible to use src block to generate org headlines for export?

2014-07-25 Thread Nicolas Goaziou
Andreas Leha andreas.l...@med.uni-goettingen.de writes:

 Nicolas Goaziou m...@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



Re: [O] Possible to use src block to generate org headlines for export?

2014-07-25 Thread Andreas Leha
Nicolas Goaziou m...@nicolasgoaziou.fr writes:

 Andreas Leha andreas.l...@med.uni-goettingen.de writes:

 Nicolas Goaziou m...@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




Re: [O] Possible to use src block to generate org headlines for export?

2014-07-25 Thread Thorsten Jolitz
Andreas Leha andreas.l...@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@gmail.com][Email
from Thorsten Jolitz: {BUG} src_blocks - :results ra]]

-- 
cheers,
Thorsten




Re: [O] Possible to use src block to generate org headlines for export?

2014-07-25 Thread Nicolas Goaziou
Andreas Leha andreas.l...@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



Re: [O] Possible to use src block to generate org headlines for export?

2014-07-25 Thread Andreas Leha
Nicolas Goaziou m...@nicolasgoaziou.fr writes:

 Andreas Leha andreas.l...@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--start8---   --8--start8---
#+PROPERTY: results drawer #+PROPERTY: results drawer  
   
* Test * Test  
#+name: dtrn   #+name: dtrn
#+begin_src R :exports both#+begin_src R :exports both 
  hellohello   
#+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




Re: [O] Possible to use src block to generate org headlines for export?

2014-07-24 Thread Andreas Leha
Hi all,

Nick Dokos ndo...@gmail.com writes:

 Charles Berry ccbe...@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




Re: [O] Possible to use src block to generate org headlines for export?

2014-07-24 Thread Charles Berry
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




Re: [O] Possible to use src block to generate org headlines for export?

2014-07-24 Thread Nick Dokos
Charles Berry ccbe...@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





Re: [O] Possible to use src block to generate org headlines for export?

2014-07-24 Thread Brett Viren
Matt Lundin m...@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.


pgptNgTBz8D6F.pgp
Description: PGP signature


Re: [O] Possible to use src block to generate org headlines for export?

2014-07-23 Thread Brett Viren
Matt Lundin m...@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.


pgpX0dUH7NC9P.pgp
Description: PGP signature


Re: [O] Possible to use src block to generate org headlines for export?

2014-07-23 Thread Matt Lundin
Hi Brett,

Brett Viren b...@bnl.gov writes:

 Matt Lundin m...@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---



Re: [O] Possible to use src block to generate org headlines for export?

2014-07-23 Thread Charles Berry
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




Re: [O] Possible to use src block to generate org headlines for export?

2014-07-23 Thread Rick Frankel

On 2014-07-22 22:35, Matt Lundin wrote:

Nick Dokos ndo...@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



Re: [O] Possible to use src block to generate org headlines for export?

2014-07-23 Thread Matt Lundin
Charles Berry ccbe...@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



Re: [O] Possible to use src block to generate org headlines for export?

2014-07-23 Thread Brett Viren
Matt Lundin m...@imapmail.org writes:

 Brett Viren b...@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.


pgp43MvSLzUiN.pgp
Description: PGP signature


Re: [O] Possible to use src block to generate org headlines for export?

2014-07-23 Thread Matt Lundin
Brett Viren b...@bnl.gov writes:

 Matt Lundin m...@imapmail.org writes:

 Brett Viren b...@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



Re: [O] Possible to use src block to generate org headlines for export?

2014-07-23 Thread Nick Dokos
Charles Berry ccbe...@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




[O] Possible to use src block to generate org headlines for export?

2014-07-22 Thread Matt Lundin
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-1span class=section-number-21/span Headline One/h2
/div
div id=outline-container-sec-2 class=outline-2
h2 id=sec-2span class=section-number-22/span Headline Two/h2
/div
div id=outline-container-sec-3 class=outline-2
h2 id=sec-3span class=section-number-23/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



Re: [O] Possible to use src block to generate org headlines for export?

2014-07-22 Thread Nick Dokos
Matt Lundin m...@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-1span class=section-number-21/span Headline One/h2
 /div
 div id=outline-container-sec-2 class=outline-2
 h2 id=sec-2span class=section-number-22/span Headline Two/h2
 /div
 div id=outline-container-sec-3 class=outline-2
 h2 id=sec-3span class=section-number-23/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




Re: [O] Possible to use src block to generate org headlines for export?

2014-07-22 Thread Matt Lundin
Nick Dokos ndo...@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



Re: [O] Possible to use src block to generate org headlines for export?

2014-07-22 Thread Matt Lundin
Correction below...

Matt Lundin m...@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