From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Lundin Subject: Re: Possible to use src block to generate org headlines for export? Date: Wed, 23 Jul 2014 10:17:36 -0500 Message-ID: <8761io2jnz.fsf@fastmail.fm> References: <87zjg1gddd.fsf@fastmail.fm> <87wqb4amqb.fsf@gmail.com> <8738dshkdw.fsf@fastmail.fm> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:36131) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X9yIa-00005M-Mz for emacs-orgmode@gnu.org; Wed, 23 Jul 2014 11:17:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X9yIU-00016j-UE for emacs-orgmode@gnu.org; Wed, 23 Jul 2014 11:17:44 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:52704) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X9yIU-00016d-MC for emacs-orgmode@gnu.org; Wed, 23 Jul 2014 11:17:38 -0400 In-Reply-To: (Brett Viren's message of "Wed, 23 Jul 2014 09:42:49 -0400") 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: Brett Viren Cc: Nick Dokos , emacs-orgmode@gnu.org Hi Brett, Brett Viren writes: > Matt Lundin 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---