From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rick Frankel Subject: Re: Possible to use src block to generate org headlines for export? Date: Wed, 23 Jul 2014 12:09:48 -0400 Message-ID: References: <87zjg1gddd.fsf@fastmail.fm> <87wqb4amqb.fsf@gmail.com> <8738dshkdw.fsf@fastmail.fm> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:51981) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X9z7G-0001vv-8o for emacs-orgmode@gnu.org; Wed, 23 Jul 2014 12:10:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X9z79-0003lH-QI for emacs-orgmode@gnu.org; Wed, 23 Jul 2014 12:10:06 -0400 Received: from mail.rickster.com ([204.62.15.78]:38926) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X9z79-0003kR-Mb for emacs-orgmode@gnu.org; Wed, 23 Jul 2014 12:09:59 -0400 In-Reply-To: <8738dshkdw.fsf@fastmail.fm> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Matt Lundin Cc: Nick Dokos , emacs-orgmode@gnu.org On 2014-07-22 22:35, Matt Lundin wrote: > Nick Dokos 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