* ob-clojure-literate: CIDER jack-in outside of project by default

* contrib/lisp/ob-clojure-literate.el (ob-clojure-literate-project-location):
(ob-clojure-literate-default-session):
(ob-clojure-literate-auto-jackin): CIDER jack-in outside of project by
default.
This commit is contained in:
stardiviner 2018-03-22 01:21:22 +08:00 committed by Nicolas Goaziou
parent 434d232ca7
commit 5a1a1f3d9a
1 changed files with 30 additions and 20 deletions

View File

@ -35,8 +35,10 @@ Don't auto jack in by default for not rude."
:type 'boolean :type 'boolean
:group 'ob-clojure-literate) :group 'ob-clojure-literate)
(defcustom ob-clojure-literate-project-location (concat user-emacs-directory "Org-mode/") (defcustom ob-clojure-literate-project-location nil
"The location for `ob-clojure-literate' scaffold project." "The location for `ob-clojure-literate' scaffold project.
If it is nil, then `cider-jack-in' will jack-in outside of Clojure project.
If it is a directory, `ob-clojure-literate' will try to create Clojure project automatically."
:type 'string :type 'string
:group 'ob-clojure-literate) :group 'ob-clojure-literate)
@ -45,7 +47,7 @@ Don't auto jack in by default for not rude."
(defvar ob-clojure-literate-session-ns nil) (defvar ob-clojure-literate-session-ns nil)
(defvar ob-clojure-literate-cider-connections nil) (defvar ob-clojure-literate-cider-connections nil)
(defcustom ob-clojure-literate-default-session "*cider-repl ob-clojure*" (defcustom ob-clojure-literate-default-session "*cider-repl localhost*"
"The default session name for `ob-clojure-literate'." "The default session name for `ob-clojure-literate'."
:type 'string :type 'string
:group 'ob-clojure-literate) :group 'ob-clojure-literate)
@ -104,6 +106,13 @@ Don't auto jack in by default for not rude."
(defun ob-clojure-literate-auto-jackin () (defun ob-clojure-literate-auto-jackin ()
"Auto setup ob-clojure-literate scaffold and jack-in Clojure project." "Auto setup ob-clojure-literate scaffold and jack-in Clojure project."
(interactive) (interactive)
(cond
;; jack-in outside of Clojure project.
((null ob-clojure-literate-project-location)
(if (member (get-buffer "*cider-repl localhost*") cider-connections)
(message "CIDER default session already launched.")
(cider-jack-in nil)))
((not (null ob-clojure-literate-project-location))
(unless (file-directory-p (expand-file-name ob-clojure-literate-project-location)) (unless (file-directory-p (expand-file-name ob-clojure-literate-project-location))
(make-directory ob-clojure-literate-project-location t) (make-directory ob-clojure-literate-project-location t)
(let ((default-directory ob-clojure-literate-project-location)) (let ((default-directory ob-clojure-literate-project-location))
@ -121,6 +130,7 @@ Don't auto jack in by default for not rude."
(find-file (expand-file-name (concat ob-clojure-literate-project-location "ob-clojure/src/ob_clojure/core.clj"))) (find-file (expand-file-name (concat ob-clojure-literate-project-location "ob-clojure/src/ob_clojure/core.clj")))
(with-current-buffer "core.clj" (with-current-buffer "core.clj"
(cider-jack-in)))))) (cider-jack-in))))))
))
(defun ob-clojure-literate-set-local-cider-connections (toggle?) (defun ob-clojure-literate-set-local-cider-connections (toggle?)
"Set buffer local `cider-connections' for `ob-clojure-literate-mode' `TOGGLE?'." "Set buffer local `cider-connections' for `ob-clojure-literate-mode' `TOGGLE?'."