[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Put result output in different type of code block than original

From: Niels Giesen
Subject: Re: [O] Put result output in different type of code block than original
Date: Tue, 11 Oct 2011 22:55:34 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

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-activate 'org-babel-insert-result)

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)))
    (when indent-after
       (when (re-search-forward
              "#\\+begin_src " nil t)
         (indent-region (point-min) (point-max))

so... this it what it does:

#+begin_src sh :results output code :out json :indent-after
  echo "{\"peul\":\"erwt\",\n\"graan\":\"rijst\"}"

#+BEGIN_SRC json

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?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]