From: Niels Giesen <niels.giesen@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: Put result output in different type of code block than original
Date: Tue, 11 Oct 2011 22:55:34 +0200 [thread overview]
Message-ID: <87botndz95.fsf@gmail.com> (raw)
In-Reply-To: <80zkh75v3y.fsf@somewhere.org> (Sebastien Vauban's message of "Tue, 11 Oct 2011 18:52:17 +0200")
To all people in this thread,
Thank you for all the responses.
The echoing of #+begin_src and #end_src is indeed a workaround that I
had not thought of myself, though it is not that general, and puts stuff
in the source that really oughtn't be there.
In the mean time I came up with a piece of advise to
`org-babel-insert-result' that does the trick in a general way.
#+begin_src emacs-lisp
(defadvice org-babel-insert-result (around pft/output-type)
(let* ((all-params (caddr info))
(lang (or (cdr (assoc :out all-params)) lang)))
ad-do-it))
(ad-activate 'org-babel-insert-result)
#+end_src
Use it with :out your-choice-of-lang
And while I was at it, I added indentation:
#+begin_src elisp
(defadvice org-babel-insert-result (around pft/output-indent)
(let* ((all-params (caddr info))
(indent-after (assoc :indent-after all-params)))
ad-do-it
(when indent-after
(save-excursion
(when (re-search-forward
"#\\+begin_src " nil t)
(beginning-of-line)
(org-edit-special)
(indent-region (point-min) (point-max))
(org-edit-src-exit))))))
#+end_src
so... this it what it does:
#+begin_src sh :results output code :out json :indent-after
echo "{\"peul\":\"erwt\",\n\"graan\":\"rijst\"}"
#+end_src
#+results:
#+BEGIN_SRC json
{"peul":"erwt",
"graan":"rijst"}
#+END_SRC
I do not know whether it plays nice with all other input forms and
:result parameters, as there seem to be some special handlers for e.g.
LaTeX and emacs-lisp, but I guess this would help the AWK->SQL case too.
If this works well enough, these pieces of advise may serve as a basis
for a patch to `org-babel-insert-result'. What do you think?
--
http://pft.github.com/
next prev parent reply other threads:[~2011-10-11 20:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-10 15:44 Put result output in different type of code block than original Niels Giesen
2011-10-11 8:55 ` Rasmus Pank Roulund
2011-10-11 9:06 ` Rainer M Krug
2011-10-11 14:04 ` Sebastien Vauban
2011-10-11 16:01 ` Burton Samograd
2011-10-11 16:52 ` Sebastien Vauban
2011-10-11 20:55 ` Niels Giesen [this message]
2011-10-11 14:32 ` Eric Schulte
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=87botndz95.fsf@gmail.com \
--to=niels.giesen@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).