mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-09-29 18:36:26 +00:00
ob-clojure: Small refactoring
* lisp/ob-clojure.el (org-babel-execute:clojure): Small refactoring.
This commit is contained in:
parent
56c0ce4a8d
commit
cd4186c5c3
|
@ -103,37 +103,52 @@ If the value is nil, timeout is disabled."
|
||||||
The underlying process performed by the code block can be output
|
The underlying process performed by the code block can be output
|
||||||
using the :show-process parameter."
|
using the :show-process parameter."
|
||||||
(let ((expanded (org-babel-expand-body:clojure body params))
|
(let ((expanded (org-babel-expand-body:clojure body params))
|
||||||
(sbuffer "*Clojure Show Process Sub Buffer*")
|
|
||||||
(show (assq :show-process params))
|
(show (assq :show-process params))
|
||||||
(response (list 'dict))
|
(response (list 'dict))
|
||||||
status
|
|
||||||
result)
|
result)
|
||||||
(cl-case org-babel-clojure-backend
|
(cl-case org-babel-clojure-backend
|
||||||
(cider
|
(cider
|
||||||
(require 'cider)
|
(require 'cider)
|
||||||
(let ((result-params (cdr (assq :result-params params))))
|
(let ((result-params (cdr (assq :result-params params))))
|
||||||
;; Check if the user wants to show the process in an output
|
(if (not show)
|
||||||
;; buffer/window.
|
;; Run code without showing the process.
|
||||||
(when show
|
(progn
|
||||||
;; Create a new window with the show output buffer.
|
(setq response
|
||||||
(switch-to-buffer-other-window sbuffer)
|
(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.
|
;; Run the Clojure code in nREPL.
|
||||||
(nrepl-request:eval
|
(nrepl-request:eval
|
||||||
expanded
|
expanded
|
||||||
(lambda (resp)
|
(lambda (resp)
|
||||||
(when (member "out" resp)
|
(when (member "out" resp)
|
||||||
;; Print the output of the nREPL in the output buffer.
|
;; Print the output of the nREPL in the output buffer.
|
||||||
(princ (nrepl-dict-get resp "out") (get-buffer sbuffer)))
|
(princ (nrepl-dict-get resp "out") process-buffer))
|
||||||
(when (member "ex" resp)
|
(when (member "ex" resp)
|
||||||
;; In case there is an exception, then add it to the
|
;; In case there is an exception, then add it to the
|
||||||
;; output buffer as well.
|
;; output buffer as well.
|
||||||
(princ (nrepl-dict-get resp "ex") (get-buffer sbuffer))
|
(princ (nrepl-dict-get resp "ex") process-buffer)
|
||||||
(princ (nrepl-dict-get resp "root-ex") (get-buffer sbuffer)))
|
(princ (nrepl-dict-get resp "root-ex") process-buffer))
|
||||||
(when (member "err" resp)
|
(when (member "err" resp)
|
||||||
;; In case there is an error, then add it to the
|
;; In case there is an error, then add it to the
|
||||||
;; output buffer as well.
|
;; output buffer as well.
|
||||||
(princ (nrepl-dict-get resp "err") (get-buffer sbuffer)))
|
(princ (nrepl-dict-get resp "err") process-buffer))
|
||||||
(nrepl--merge response resp)
|
(nrepl--merge response resp)
|
||||||
;; Update the status of the nREPL output session.
|
;; Update the status of the nREPL output session.
|
||||||
(setq status (nrepl-dict-get response "status")))
|
(setq status (nrepl-dict-get response "status")))
|
||||||
|
@ -148,38 +163,22 @@ using the :show-process parameter."
|
||||||
|
|
||||||
;; Delete the show buffer & window when the processing is
|
;; Delete the show buffer & window when the processing is
|
||||||
;; finalized.
|
;; finalized.
|
||||||
(mapc #'delete-window (get-buffer-window-list sbuffer nil t))
|
(mapc #'delete-window
|
||||||
(kill-buffer sbuffer)
|
(get-buffer-window-list process-buffer nil t))
|
||||||
|
(kill-buffer process-buffer)
|
||||||
|
|
||||||
;; Put the output or the value in the result section of the
|
;; Put the output or the value in the result section of
|
||||||
;; code block.
|
;; the code block.
|
||||||
(setq result
|
(setq result
|
||||||
(concat (nrepl-dict-get response
|
(concat
|
||||||
|
(nrepl-dict-get response
|
||||||
(if (or (member "output" result-params)
|
(if (or (member "output" result-params)
|
||||||
(member "pp" result-params))
|
(member "pp" result-params))
|
||||||
"out"
|
"out"
|
||||||
"value"))
|
"value"))
|
||||||
(nrepl-dict-get response "ex")
|
(nrepl-dict-get response "ex")
|
||||||
(nrepl-dict-get response "root-ex")
|
(nrepl-dict-get response "root-ex")
|
||||||
(nrepl-dict-get response "err"))))
|
(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"))))))
|
|
||||||
(slime
|
(slime
|
||||||
(require 'slime)
|
(require 'slime)
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
|
|
Loading…
Reference in a new issue