Re: [O] Put result output in different type of code block than original
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/
Re: [O] Put result output in different type of code block than original
Hi Burton, Burton Samograd wrote: > "Sebastien Vauban" writes: >> Hi Rainer and Niels, >> >> Rainer M Krug wrote: >>> On Mon, Oct 10, 2011 at 5:44 PM, Niels Giesen wrote: Say I've got a sh code block invoking curl to some json api, is it possible some way to specify that the format of the output when :results output code is in a json code block and *not* a sh code block? >> >> FYI, this is a need I also have, for example AWK outputting SQL code. There >> has been some threads about this, but nothing is implemented so far in this >> direction. >> #+begin_src sh :results output code :exports both curl https://our-service.org/getstuff?username=dirk\&password=catsbrithday\&fmt=json #+end_src >>> >>> Does >>> >>> #+begin_src sh :results output :exports both >>> echo #+BEGIN_SRC json >>> curl >>> https://our-service.org/getstuff?username=dirk\&password=catsbrithday\&fmt=json >>> echo #+END_SRC >>> #+end_src >>> >>> help? >> >> I like very much the idea of your workaround. Great thought! >> >> Though, nope, it does not help the OP, because the echo lines don't output >> anything here, as # is the symbol to begin a comment (in shell scripts). So, >> the first line simply outputs a blank line... > > Could you escape the comment character by using \#? Yes, that does work as well (alternative to Eric's quoting method): #+begin_src sh :results output raw :exports both echo \#+BEGIN_SRC json echo curl echo https://our-service.org/getstuff?username=dirk\&password=catsbrithday\&fmt=json echo \#+END_SRC #+end_src but my point was intended to be more general: this workaround may be difficult to use for differnet languages to marry (my own need, in the past, was for AWK outputting SQL + another I've forgotten about right now). Anyway, this currently can be made to work, as shown. Best regards, Seb PS- I was expecting that multiple evaluations of the code block would lead to multiple results blocks, because of the raw specifier. It's not the case. Is is perfectly normal and explainable, or a corner case which favors -- in this case -- this workaround? -- Sebastien Vauban
Re: [O] Put result output in different type of code block than original
"Sebastien Vauban" writes: > Hi Rainer and Niels, > > Rainer M Krug wrote: >> On Mon, Oct 10, 2011 at 5:44 PM, Niels Giesen wrote: >>> Say I've got a sh code block invoking curl to some json api, is it possible >>> some way to specify that the format of the output when :results output code >>> is in a json code block and *not* a sh code block? > > FYI, this is a need I also have, for example AWK outputting SQL code. There > has been some threads about this, but nothing is implemented so far in this > direction. > >>> #+begin_src sh :results output code :exports both >>> curl >>> https://our-service.org/getstuff?username=dirk\&password=catsbrithday\&fmt=json >>> #+end_src >> >> Does >> >> #+begin_src sh :results output :exports both >> echo #+BEGIN_SRC json >> curl >> https://our-service.org/getstuff?username=dirk\&password=catsbrithday\&fmt=json >> echo #+END_SRC >> #+end_src >> >> help? > > I like very much the idea of your workaround. Great thought! > > Though, nope, it does not help the OP, because the echo lines don't output > anything here, as # is the symbol to begin a comment (in shell scripts). So, > the first line simply outputs a blank line... Could you escape the comment character by using \#? -- Burton Samograd
Re: [O] Put result output in different type of code block than original
Niels Giesen writes: > Hi, > > Say I've got a sh code block invoking curl to some json api, is it possible > some way to specify that the format of the output when :results output code > is in a json code block and *not* a sh code block? > Hi Niels, Currently there is no way to specify the type of returned source code block. Hopefully one of Rainer or Rasmus' suggestions to this thread should serve as a sufficient work around. I would augment Rainer's solution changing it to the following... #+begin_src sh :results scalar raw echo "#+begin_src json" curl https://our-service.org/getstuff?username=dirk\&password=catsbrithday\&fmt=json echo "#+end_src json" #+end_src which works for me -- or presumably would work for me if our-service could getstfff for dirk with password catsbirthday. Cheers -- Eric > > #+begin_src sh :results output code :exports both > curl > https://our-service.org/getstuff?username=dirk\&password=catsbrithday\&fmt=json > #+end_src > > #+results: > #+BEGIN_SRC sh > {"userinfo" : {"id" : "QNCNFQUKKBCTTMAOIUFNOQVLDUFAJV", "fullname" : "Gekke > Dirk", "role" : "user"}} > #+END_SRC > > whereas I'd like it to be > > #+results: > #+BEGIN_SRC json > {"userinfo" : {"id" : "QNCNFQUKKBCTTMAOIUFNOQVLDUFAJV", "fullname" : "Gekke > Dirk", "role" : "user"}} > #+END_SRC > > Any thoughts on how to go about this? Do other people have this same issue > and should there come an option in babel that handles this (one language > outputting source code for another?), or is there a way to specify ones own > outputter? -- Eric Schulte http://cs.unm.edu/~eschulte/
Re: [O] Put result output in different type of code block than original
Hi Rainer and Niels, Rainer M Krug wrote: > On Mon, Oct 10, 2011 at 5:44 PM, Niels Giesen wrote: >> Say I've got a sh code block invoking curl to some json api, is it possible >> some way to specify that the format of the output when :results output code >> is in a json code block and *not* a sh code block? FYI, this is a need I also have, for example AWK outputting SQL code. There has been some threads about this, but nothing is implemented so far in this direction. >> #+begin_src sh :results output code :exports both >> curl >> https://our-service.org/getstuff?username=dirk\&password=catsbrithday\&fmt=json >> #+end_src > > Does > > #+begin_src sh :results output :exports both > echo #+BEGIN_SRC json > curl > https://our-service.org/getstuff?username=dirk\&password=catsbrithday\&fmt=json > echo #+END_SRC > #+end_src > > help? I like very much the idea of your workaround. Great thought! Though, nope, it does not help the OP, because the echo lines don't output anything here, as # is the symbol to begin a comment (in shell scripts). So, the first line simply outputs a blank line... Best regards, Seb -- Sebastien Vauban
Re: [O] Put result output in different type of code block than original
On Mon, Oct 10, 2011 at 5:44 PM, Niels Giesen wrote: > Hi, > > Say I've got a sh code block invoking curl to some json api, is it possible > some way to specify that the format of the output when :results output code > is in a json code block and *not* a sh code block? > > #+begin_src sh :results output code :exports both > curl > https://our-service.org/getstuff?username=dirk\&password=catsbrithday\&fmt=json > #+end_src > > Does #+begin_src sh :results output :exports both echo #+BEGIN_SRC json curl https://our-service.org/getstuff?username=dirk\&password=catsbrithday\&fmt=json echo #+END_SRC #+end_src help? Rainer > #+results: > #+BEGIN_SRC sh > {"userinfo" : {"id" : "QNCNFQUKKBCTTMAOIUFNOQVLDUFAJV", "fullname" : "Gekke > Dirk", "role" : "user"}} > #+END_SRC > > whereas I'd like it to be > > #+results: > #+BEGIN_SRC json > {"userinfo" : {"id" : "QNCNFQUKKBCTTMAOIUFNOQVLDUFAJV", "fullname" : "Gekke > Dirk", "role" : "user"}} > #+END_SRC > > Any thoughts on how to go about this? Do other people have this same issue > and should there come an option in babel that handles this (one language > outputting source code for another?), or is there a way to specify ones own > outputter? > > -- > http://pft.github.com > -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Stellenbosch University South Africa Tel : +33 - (0)9 53 10 27 44 Cell: +33 - (0)6 85 62 59 98 Fax (F): +33 - (0)9 58 10 27 44 Fax (D):+49 - (0)3 21 21 25 22 44 email: rai...@krugs.de Skype: RMkrug
Re: [O] Put result output in different type of code block than original
Niels Giesen writes: > Hi, > > Say I've got a sh code block invoking curl to some json api, is it possible > some way to specify that the format of the output when :results output code > is in a json code block and *not* a sh code block? Does this help you? (Lacking a relevant example) #+begin_src R :results output latex 1+1 #+end_src #+results: #+BEGIN_LaTeX [1] 2 #+END_LaTeX –Rasmus -- Sent from my Emacs
[O] Put result output in different type of code block than original
Hi, Say I've got a sh code block invoking curl to some json api, is it possible some way to specify that the format of the output when :results output code is in a json code block and *not* a sh code block? #+begin_src sh :results output code :exports both curl https://our-service.org/getstuff?username=dirk\&password=catsbrithday\&fmt=json #+end_src #+results: #+BEGIN_SRC sh {"userinfo" : {"id" : "QNCNFQUKKBCTTMAOIUFNOQVLDUFAJV", "fullname" : "Gekke Dirk", "role" : "user"}} #+END_SRC whereas I'd like it to be #+results: #+BEGIN_SRC json {"userinfo" : {"id" : "QNCNFQUKKBCTTMAOIUFNOQVLDUFAJV", "fullname" : "Gekke Dirk", "role" : "user"}} #+END_SRC Any thoughts on how to go about this? Do other people have this same issue and should there come an option in babel that handles this (one language outputting source code for another?), or is there a way to specify ones own outputter? -- http://pft.github.com