emacs-orgmode
[Top][All Lists]
Advanced

[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-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/



reply via email to

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