From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: [RFC] new :post header argument for post-processing of code block results Date: Sun, 31 Mar 2013 19:17:46 -0600 Message-ID: <87bo9zoxqd.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:56681) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMTNu-0005wT-Hq for emacs-orgmode@gnu.org; Sun, 31 Mar 2013 21:18:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UMTNr-0007ch-1O for emacs-orgmode@gnu.org; Sun, 31 Mar 2013 21:18:06 -0400 Received: from mail-da0-x22b.google.com ([2607:f8b0:400e:c00::22b]:40718) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMTNq-0007cU-Pc for emacs-orgmode@gnu.org; Sun, 31 Mar 2013 21:18:02 -0400 Received: by mail-da0-f43.google.com with SMTP id u36so854288dak.2 for ; Sun, 31 Mar 2013 18:18:02 -0700 (PDT) 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: Org Mode Mailing List --=-=-= Content-Type: text/plain Hi, I've been wanting to add the ability to post-process the results of a code block for some time, and some recent threads (e.g., [1] and [2]) could both have benefited from post-processing of code block output. The attached patch [3] adds a new :post header argument, which may be used to specify a code block reference to use to post-process the results of the current code block. The following example illustrates how this header argument could be used to add attr_latex lines to table code block results. --=-=-= Content-Type: text/x-org Content-Disposition: inline; filename=example.org #+Title: Proposed =post= Header Argument #+Author: Eric Schulte * a code block which does the post processing This code block adds latex width attributes to whatever =data= is passed to it. #+name: add-attr #+begin_src sh :var data="" :results output drawer :var width="\textwidth" echo "#+attr_latex: width=$width" echo "$data" #+end_src * two code blocks which use the post processing The following two code blocks demonstrate the use of the new =post= header argument, whcih we could add if it seems generally useful and not too confusing. This works by lexically binding the =*this*= variable to the results of the current code block, and then calling the =add-attr= code block to post-process these results. #+begin_src sh :results output wrap :post add-attr(width="5cm",data=(identity *this*)) cat <From f83f31d82c0c660c74a2af7114d4e23c9b37c095 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Sun, 31 Mar 2013 19:02:11 -0600 Subject: [PATCH] :post header arg post-processes code block results * lisp/ob-core.el (org-babel-common-header-args-w-values): Add :post to the list of header arguments. (org-babel-execute-src-block): Post process results when the :post header argument has been supplied. --- lisp/ob-core.el | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 723aa9d..e1321eb 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -456,6 +456,7 @@ then run `org-babel-pop-to-session'." (noweb-ref . :any) (noweb-sep . :any) (padline . ((yes no))) + (post . :any) (results . ((file list vector table scalar verbatim) (raw html latex org code pp drawer) (replace silent none append prepend) @@ -625,6 +626,11 @@ block." (not (listp result))) (list (list result)) result)) (funcall cmd body params))) + ;; possibly perform post process provided its appropriate + (when (cdr (assoc :post params)) + (let ((*this* result)) + (setq result (org-babel-ref-resolve + (cdr (assoc :post params)))))) ;; if non-empty result and :file then write to :file (when (cdr (assoc :file params)) (when result -- 1.8.2 --=-=-= Content-Type: text/plain -- Eric Schulte http://cs.unm.edu/~eschulte --=-=-=--