* org-clojure - How to emit an example block?
@ 2014-02-08 20:48 Phill Wolf
2014-02-08 22:15 ` Thomas S. Dye
0 siblings, 1 reply; 4+ messages in thread
From: Phill Wolf @ 2014-02-08 20:48 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 662 bytes --]
How can a Clojure source block contribute its standard-output results as an
example block? I tried ":results output org" but it expressed the standard
output as a quoted string with \n's where I expected newlines. For a point
of comparison, org-python seems to be able to do what I want, if "begin_src
org" is effectively the same as "begin_example". (Is it?)
#+BEGIN_SRC clojure :results output org :exports both
(println "Hello")
(println "world")
#+END_SRC
#+RESULTS:
#+BEGIN_SRC org
"Hello\nworld\n"
#+END_SRC
#+BEGIN_SRC python :results output org :exports both
print "Hello"
print "world"
#+END_SRC
#+RESULTS:
#+BEGIN_SRC org
Hello
world
#+END_SRC
[-- Attachment #2: Type: text/html, Size: 864 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: org-clojure - How to emit an example block?
2014-02-08 20:48 org-clojure - How to emit an example block? Phill Wolf
@ 2014-02-08 22:15 ` Thomas S. Dye
2014-02-08 23:29 ` Phill Wolf
0 siblings, 1 reply; 4+ messages in thread
From: Thomas S. Dye @ 2014-02-08 22:15 UTC (permalink / raw)
To: Phill Wolf; +Cc: emacs-orgmode
Phill Wolf <phill.wolf@gmail.com> writes:
> How can a Clojure source block contribute its standard-output results as an
> example block?
See the :wrap header argument. Something like :wrap example should get
you close.
hth,
Tom
--
Thomas S. Dye
http://www.tsdye.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: org-clojure - How to emit an example block?
2014-02-08 22:15 ` Thomas S. Dye
@ 2014-02-08 23:29 ` Phill Wolf
2014-02-09 7:57 ` Bastien
0 siblings, 1 reply; 4+ messages in thread
From: Phill Wolf @ 2014-02-08 23:29 UTC (permalink / raw)
To: Thomas S. Dye; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1348 bytes --]
ob-clojure.el should use separate cider functions for value and output
results, in order to avoid expressing standard output as some kind of
programming-language string with embedded \n notation. I experimentally
adjusted my copy of ob-clojure (obtained from git clone -b master today)
like this:
(1) In the cider block, access the result-params.
(2) Put either 'cider-get-value or 'cider-get-raw-value into a variable,
depending on the result-params.
(3) funcall the variable instead of using cider-get-raw-value directly.
(0) Up at the top, add a declare-function for cider-get-value, next to the
declare-function for cider-get-raw-value.
(defun org-babel-execute:clojure (body params)
"Execute a block of Clojure code with Babel."
(let ((expanded (org-babel-expand-body:clojure body params))
result)
(case org-babel-clojure-backend
(cider
(require 'cider)
(let* ((result-params (cdr (assoc :result-params params)))
(cider-call-fn (cond ((member "output" result-params)
'cider-get-value)
((member "value" result-params)
'cider-get-raw-value)
(t 'cider-get-raw-value))))
(setq result
(or (funcall cider-call-fn [...]
Together with :wrap example as suggested by Thomas S. Dye, the results are
exemplary.
[-- Attachment #2: Type: text/html, Size: 1815 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: org-clojure - How to emit an example block?
2014-02-08 23:29 ` Phill Wolf
@ 2014-02-09 7:57 ` Bastien
0 siblings, 0 replies; 4+ messages in thread
From: Bastien @ 2014-02-09 7:57 UTC (permalink / raw)
To: Phill Wolf; +Cc: emacs-orgmode, Thomas S. Dye
Hi Phill,
thanks for your work on this.
Phill Wolf <phill.wolf@gmail.com> writes:
> (1) In the cider block, access the result-params.
> (2) Put either 'cider-get-value or 'cider-get-raw-value into a
> variable, depending on the result-params.
> (3) funcall the variable instead of using cider-get-raw-value
> directly.
> (0) Up at the top, add a declare-function for cider-get-value, next
> to the declare-function for cider-get-raw-value.
Can you repost your changes as a patch?
Please read http://orgmode.org/worg/org-contribute.html
carefully on how to submit a patch.
If you don't have time to write a full patch, just open
the updated ob-clojure.el in Emacs and `C-x v =' to create
a patch buffer and send it to the list.
Thanks!
--
Bastien
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-02-09 7:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-08 20:48 org-clojure - How to emit an example block? Phill Wolf
2014-02-08 22:15 ` Thomas S. Dye
2014-02-08 23:29 ` Phill Wolf
2014-02-09 7:57 ` Bastien
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).