summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2016-11-19 07:35:23 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2016-11-19 07:35:23 +0100
commitcd4186c5c363881a13d00463fbc1ba21018c95fd (patch)
treee63f9f907201f22ab6a9b01077e9f3d23fbd0eb2
parent56c0ce4a8db7a401d3d58b0dd8b7b5c440f66e76 (diff)
downloadorg-mode-cd4186c5c363881a13d00463fbc1ba21018c95fd.tar.gz
ob-clojure: Small refactoring
* lisp/ob-clojure.el (org-babel-execute:clojure): Small refactoring.
-rw-r--r--lisp/ob-clojure.el139
1 files changed, 69 insertions, 70 deletions
diff --git a/lisp/ob-clojure.el b/lisp/ob-clojure.el
index f508e6b..dff7c23 100644
--- a/lisp/ob-clojure.el
+++ b/lisp/ob-clojure.el
@@ -103,83 +103,82 @@ If the value is nil, timeout is disabled."
The underlying process performed by the 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 (assq :show-process params))
(response (list 'dict))
- status
result)
(cl-case org-babel-clojure-backend
(cider
(require 'cider)
(let ((result-params (cdr (assq :result-params params))))
- ;; Check if the user wants to show the process in an output
- ;; buffer/window.
- (when show
- ;; Create a new window with the show output buffer.
- (switch-to-buffer-other-window sbuffer)
-
- ;; Run the Clojure code in nREPL.
- (nrepl-request:eval
- expanded
- (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 as well.
- (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")))
- (cider-current-connection)
- (cider-current-session))
-
- ;; 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)
- (redisplay))
-
- ;; Delete the show buffer & window when the processing is
- ;; finalized.
- (mapc #'delete-window (get-buffer-window-list sbuffer nil t))
- (kill-buffer sbuffer)
-
- ;; Put the output or the value in the result section of the
- ;; code block.
- (setq result
- (concat (nrepl-dict-get response
- (if (or (member "output" result-params)
- (member "pp" result-params))
- "out"
- "value"))
- (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.
- (unless show
- (setq response (let ((nrepl-sync-request-timeout
- org-babel-clojure-sync-nrepl-timeout))
- (nrepl-sync-request:eval expanded
- (cider-current-connection)
- (cider-current-session))))
- (setq result
- (concat
- (nrepl-dict-get response (if (or (member "output" result-params)
- (member "pp" result-params))
- "out"
- "value"))
- (nrepl-dict-get response "ex")
- (nrepl-dict-get response "root-ex")
- (nrepl-dict-get response "err"))))))
+ (if (not show)
+ ;; Run code without showing the process.
+ (progn
+ (setq response
+ (let ((nrepl-sync-request-timeout
+ org-babel-clojure-sync-nrepl-timeout))
+ (nrepl-sync-request:eval expanded
+ (cider-current-connection)
+ (cider-current-session))))
+ (setq result
+ (concat
+ (nrepl-dict-get response
+ (if (or (member "output" result-params)
+ (member "pp" result-params))
+ "out"
+ "value"))
+ (nrepl-dict-get response "ex")
+ (nrepl-dict-get response "root-ex")
+ (nrepl-dict-get response "err"))))
+ ;; Show the process in an output buffer/window.
+ (let ((process-buffer (switch-to-buffer-other-window
+ "*Clojure Show Process Sub Buffer*"))
+ status)
+ ;; Run the Clojure code in nREPL.
+ (nrepl-request:eval
+ expanded
+ (lambda (resp)
+ (when (member "out" resp)
+ ;; Print the output of the nREPL in the output buffer.
+ (princ (nrepl-dict-get resp "out") process-buffer))
+ (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") process-buffer)
+ (princ (nrepl-dict-get resp "root-ex") process-buffer))
+ (when (member "err" resp)
+ ;; In case there is an error, then add it to the
+ ;; output buffer as well.
+ (princ (nrepl-dict-get resp "err") process-buffer))
+ (nrepl--merge response resp)
+ ;; Update the status of the nREPL output session.
+ (setq status (nrepl-dict-get response "status")))
+ (cider-current-connection)
+ (cider-current-session))
+
+ ;; 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)
+ (redisplay))
+
+ ;; Delete the show buffer & window when the processing is
+ ;; finalized.
+ (mapc #'delete-window
+ (get-buffer-window-list process-buffer nil t))
+ (kill-buffer process-buffer)
+
+ ;; Put the output or the value in the result section of
+ ;; the code block.
+ (setq result
+ (concat
+ (nrepl-dict-get response
+ (if (or (member "output" result-params)
+ (member "pp" result-params))
+ "out"
+ "value"))
+ (nrepl-dict-get response "ex")
+ (nrepl-dict-get response "root-ex")
+ (nrepl-dict-get response "err")))))))
(slime
(require 'slime)
(with-temp-buffer