From mboxrd@z Thu Jan 1 00:00:00 1970 From: Niels Giesen Subject: Re: Put result output in different type of code block than original Date: Tue, 11 Oct 2011 22:55:34 +0200 Message-ID: <87botndz95.fsf@gmail.com> References: <80sjmz7hf9.fsf@somewhere.org> <87zkh7qzz9.fsf@interalia.com> <80zkh75v3y.fsf@somewhere.org> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([140.186.70.92]:50166) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RDjK4-0003OE-LW for emacs-orgmode@gnu.org; Tue, 11 Oct 2011 16:53:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RDjK3-0007Hn-IM for emacs-orgmode@gnu.org; Tue, 11 Oct 2011 16:53:12 -0400 Received: from mail-ey0-f169.google.com ([209.85.215.169]:49944) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RDjK3-0007ET-Dl for emacs-orgmode@gnu.org; Tue, 11 Oct 2011 16:53:11 -0400 Received: by eye4 with SMTP id 4so40688eye.0 for ; Tue, 11 Oct 2011 13:53:10 -0700 (PDT) In-Reply-To: <80zkh75v3y.fsf@somewhere.org> (Sebastien Vauban's message of "Tue, 11 Oct 2011 18:52:17 +0200") 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: emacs-orgmode@gnu.org 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/