emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Rick Frankel <rick@rickster.com>
To: Matt Lundin <mdl@imapmail.org>
Cc: Nick Dokos <ndokos@gmail.com>, emacs-orgmode@gnu.org
Subject: Re: Possible to use src block to generate org headlines for export?
Date: Wed, 23 Jul 2014 12:09:48 -0400	[thread overview]
Message-ID: <e09bc218c377275931827dcdf59c74c3@mail.rickster.com> (raw)
In-Reply-To: <8738dshkdw.fsf@fastmail.fm>

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

      parent reply	other threads:[~2014-07-23 16:10 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e09bc218c377275931827dcdf59c74c3@mail.rickster.com \
    --to=rick@rickster.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=mdl@imapmail.org \
    --cc=ndokos@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).