I noticed that you included some of my previous fixes in
Org-babel-clojure, so here are the latest work I did. I updated it to
work with the latest code on Git. I did two things with these fixes:
(1) I better handle any possible error or exceptions that may be
raised by nREPL by displaying any errors in the RESULTS section
(2) I added a new header option called ":show-process" which create
a new window/buffer to display anything that is outputted by the
Clojure code in the code block.
In the past, I did refer to this as ":async", but as we discussed at
that time, it really was not async. So I changed the naming of this
new feature to remove this ambiguity.
In any case, I did update the worg documentation accordingly too.
Finally I updated ORG-NEWS in the 9.1 section.
I think you can merge patch 2 and 3. ORG-NEWS updates usually do not
require their own
See the patch files attached to this email.
Thank you. Some nit-picks follow.
Subject: [PATCH 1/2] Better error handling with nREPL. Displaying any possible
errors or exceptions in the result block. Adding a new :show-process header
option such that the underlying process of a Clojure block code get output in
a new buffer and a new window such that the developer can see what is going
Could you provide a proper commit message? In particular, each modified
function has to be specified there.
(defun org-babel-execute:clojure (body params)
- "Execute a block of Clojure code with Babel."
+ "Execute a block of Clojure code with Babel. The underlying process
performed by the
"The underlying..." has to go on the line below.
+ code block can be output using the :show-process parameter"
(let ((expanded (org-babel-expand-body:clojure body params))
+ (sbuffer "*Clojure Show Process Sub Buffer*")
+ (show (if (assoc :show-process params) t nil))
(show (assq :show-process params))
+ (response (cons 'dict nil))
(response (list 'dict))
+ ; Check if the user want show the process in an output buffer/window
Need ";;" instead of ";". Also, full stop missing at the end.
+ (when show
+ ; Create a new window with the show output buffer
;; Create.... output buffer.
+ (switch-to-buffer-other-window sbuffer)
+ ; Run the Clojure code in nREPL
+ (lambda (resp)
+ (when (member "out" resp)
+ ; Print the output of the nREPL in the output buffer
+ (princ (nrepl-dict-get resp "out") (get-buffer sbuffer)))
+ (when (member "ex" resp)
+ ; In case there is an exception, then add it to the output
buffer as well
+ (princ (nrepl-dict-get resp "ex") (get-buffer sbuffer))
+ (princ (nrepl-dict-get resp "root-ex") (get-buffer sbuffer)))
+ (when (member "err" resp)
+ ; In case there is an error, then add it to the output buffer
+ (princ (nrepl-dict-get resp "err") (get-buffer sbuffer)))
+ (nrepl--merge response resp)
+ ; Update the status of the nREPL output session
+ (setq status (nrepl-dict-get response "status")))
+ ; Wait until the nREPL code finished to be processed
+ (while (not (member "done" status))
+ (nrepl-dict-put response "status" (remove "need-input" status))
+ (accept-process-output nil 0.01)
+ ; Delete the show buffer & window when the processing is finalized
+ (let ((wins (get-buffer-window-list sbuffer nil t)))
+ (dolist (win wins)
+ (delete-window win))
+ (kill-buffer sbuffer))
(mapc #'delete-window (get-buffer-window-list sbuffer nil t))
+ ; Put the output or the value in the result section of the code
+ (setq result (concat (nrepl-dict-get response
+ (if (or (member "output"
+ (member "pp"
+ (nrepl-dict-get response "ex")
+ (nrepl-dict-get response "root-ex")
+ (nrepl-dict-get response "err"))))
+ ; Check if user want to run code without showing the process
+ (when (not show)
(unless show ...)