From: Eric Schulte <schulte.eric@gmail.com>
To: Org Mode Mailing List <emacs-orgmode@gnu.org>
Subject: [RFC] new :post header argument for post-processing of code block results
Date: Sun, 31 Mar 2013 19:17:46 -0600 [thread overview]
Message-ID: <87bo9zoxqd.fsf@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 514 bytes --]
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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: example.org --]
[-- Type: text/x-org, Size: 1640 bytes --]
#+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 <<EOF
| 1 | 2 |
| 3 | 4 |
EOF
#+end_src
#+RESULTS:
:RESULTS:
#+attr_latex: width=5cm
| 1 | 2 |
| 3 | 4 |
:END:
This code block does the same thing as the previous one, but using
different values and arguments.
#+header: :post add-attr(width="0.5\\textwidth",data=(identity *this*))
#+begin_src sh :results output wrap
cat <<EOF
| 5 | 6 |
| 7 | 8 |
EOF
#+end_src
#+RESULTS:
:RESULTS:
#+attr_latex: width=0.5\textwidth
| 5 | 6 |
| 7 | 8 |
:END:
* another unrelated example
Say we only care about the size of our results, then we could use the
following.
#+name: wc
#+begin_src sh data=""
echo "$data"|wc
#+end_src
This code block checks the size of some Emacs Lisp data (in this case
my =load-path= variable).
#+begin_src emacs-lisp :post wc(data=(identity *this*))
load-path
#+end_src
#+RESULTS:
: 160 160 6783
[-- Attachment #3: Type: text/plain, Size: 274 bytes --]
Does this new header argument seem useful? Any suggestions for better
syntax which don't add too much conceptual or code complexity?
Thanks,
Footnotes:
[1] http://thread.gmane.org/gmane.emacs.orgmode/69339
[2] http://thread.gmane.org/gmane.emacs.orgmode/68700
[3]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0001-post-header-arg-post-processes-code-block-results.patch --]
[-- Type: text/x-patch, Size: 1407 bytes --]
From f83f31d82c0c660c74a2af7114d4e23c9b37c095 Mon Sep 17 00:00:00 2001
From: Eric Schulte <schulte.eric@gmail.com>
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
[-- Attachment #5: Type: text/plain, Size: 47 bytes --]
--
Eric Schulte
http://cs.unm.edu/~eschulte
next reply other threads:[~2013-04-01 1:18 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-01 1:17 Eric Schulte [this message]
2013-04-01 5:30 ` [RFC] new :post header argument for post-processing of code block results Aaron Ecay
2013-04-03 14:30 ` Eric Schulte
2013-04-04 2:18 ` Eric Schulte
2013-04-04 9:54 ` Bastien
2013-04-04 12:47 ` Eric Schulte
2013-04-04 12:54 ` Bastien
2014-12-12 16:37 ` Christian Nybø
2013-04-16 12:47 ` Eric S Fraga
2013-04-16 15:23 ` Eric Schulte
2013-04-16 20:42 ` Andreas Leha
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=87bo9zoxqd.fsf@gmail.com \
--to=schulte.eric@gmail.com \
--cc=emacs-orgmode@gnu.org \
/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).