summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstardiviner <numbchild@gmail.com>2018-10-23 19:23:45 +0800
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2018-10-25 10:33:16 +0200
commit2c5df17ed1d7f61d4b3cbb92d17de2c25baa354e (patch)
tree123f5448d580a996d4b868b88b8ac065c996a2ea
parent4456dc88097815bc91fa062e459e093f4536cb41 (diff)
downloadorg-mode-2c5df17ed1d7f61d4b3cbb92d17de2c25baa354e.tar.gz
ob-clojure: Support new CIDER using sesman to manage sessions
* ob-clojure.el (org-babel-clojure-initiate-session): Improve ob-clojure initialize session way to support CIDER new API. * etc/ORG-NEWS: Add declare for new :session support feature.
-rw-r--r--etc/ORG-NEWS11
-rw-r--r--lisp/ob-clojure.el22
2 files changed, 28 insertions, 5 deletions
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 2a6e9fc..2bef7a1 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -225,6 +225,17 @@ This is consistent with the naming of =org-dblock-write:columnview=
options, where =:match= is also used as a headlines filter.
** New features
+*** Add ~:session~ support of ob-clojure for CIDER
+You can initialize source block session with Babel default keybinding
+=[C-c C-v C-z]= to use =sesman= session manager to link current
+project, directory or buffer with specific Clojure session, or
+=cider-jack-in= a new CIDER REPL if no CIDER REPLs available. In older
+CIDER version which has not =sesman= integrated, only has
+=cider-jack-in= without Clojure project is supported.
+#+begin_src clojure :session
+(dissoc Clojure 'JVM)
+(conj clojurists "stardiviner")
+#+end_src
*** Add ~:results link~ support for Babel
With this output format, create a link to the file specified in
diff --git a/lisp/ob-clojure.el b/lisp/ob-clojure.el
index 048ba37..e02b2d8 100644
--- a/lisp/ob-clojure.el
+++ b/lisp/ob-clojure.el
@@ -46,6 +46,7 @@
(declare-function cider-jack-in "ext:cider" (&optional prompt-project cljs-too))
(declare-function cider-current-connection "ext:cider-client" (&optional type))
(declare-function cider-current-ns "ext:cider-client" ())
+(declare-function cider-repls "ext:cider-connection" (&optional type ensure))
(declare-function nrepl--merge "ext:nrepl-client" (dict1 dict2))
(declare-function nrepl-dict-get "ext:nrepl-client" (dict key))
(declare-function nrepl-dict-put "ext:nrepl-client" (dict key value))
@@ -55,6 +56,8 @@
(defvar nrepl-sync-request-timeout)
(defvar cider-buffer-ns)
+(defvar sesman-system)
+(defvar cider-version)
(defvar org-babel-tangle-lang-exts)
(add-to-list 'org-babel-tangle-lang-exts '("clojure" . "clj"))
@@ -221,11 +224,20 @@ using the :show-process parameter."
;; CIDER jack-in to the Clojure project directory.
((eq org-babel-clojure-backend 'cider)
(require 'cider)
- (let ((session-buffer (save-window-excursion
- (cider-jack-in t)
- (current-buffer))))
- (if (org-babel-comint-buffer-livep session-buffer)
- (progn (sit-for .25) session-buffer))))
+ (let ((session-buffer
+ (save-window-excursion
+ (if (version< cider-version "0.18.0")
+ ;; Older CIDER (without sesman) still need to use
+ ;; old way.
+ (cider-jack-in nil) ;jack-in without project
+ ;; New CIDER (with sesman to manage sessions).
+ (unless (cider-repls)
+ (let ((sesman-system 'CIDER))
+ (call-interactively 'sesman-link-with-directory))))
+ (current-buffer))))
+ (when (org-babel-comint-buffer-livep session-buffer)
+ (sit-for .25)
+ session-buffer)))
((eq org-babel-clojure-backend 'slime)
(error "Session evaluation with SLIME is not supported"))
(t