emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Rick Frankel
Subject: Re: [O] Possible to use src block to generate org headlines for export?
Date: Wed, 23 Jul 2014 12:09:48 -0400
User-agent: Roundcube Webmail/0.9.0

On 2014-07-22 22:35, Matt Lundin wrote:
Nick Dokos <address@hidden> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]