summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBozhidar Batsov <bozhidar@batsov.com>2018-04-02 23:30:05 +0300
committerBozhidar Batsov <bozhidar@batsov.com>2018-04-02 23:30:05 +0300
commit8987e77a43d48013163a740cf2fa538105693083 (patch)
tree5e76f97986cc6de2750fd4288a379c97c04779f5
parentc4f164329c96c03b0002a40f088163d05093d988 (diff)
Add support for starting a shadow-cljs ClojureScript REPL
-rw-r--r--cider.el33
1 files changed, 27 insertions, 6 deletions
diff --git a/cider.el b/cider.el
index ab430666..79b70900 100644
--- a/cider.el
+++ b/cider.el
@@ -646,6 +646,20 @@ dependencies."
(unless (cider-library-present-p "boot-cljs-repl")
(user-error "The Boot ClojureScript REPL is not available. Please check https://github.com/adzerk-oss/boot-cljs-repl/blob/master/README.md")))
+(defun cider-check-shadow-cljs-requirements ()
+ "Check whether we can start a shadow-cljs REPL."
+ (unless (cider-library-present-p "shadow-cljs")
+ (user-error "The shadow-cljs ClojureScript REPL is not available")))
+
+(defun cider-shadow-cljs-init-form ()
+ "Generate the init form for a shadow-cljs REPL.
+
+We have to prompt the user to select a build, that's why
+this is a command, not just a string."
+ (let ((form "(do (require '[shadow.cljs.devtools.api :as shadow]) (shadow/watch :%s) (shadow/nrepl-select :%s))")
+ (build (string-remove-prefix ":" (read-from-minibuffer "Select shadow-cljs build: "))))
+ (format form build build)))
+
(defconst cider-cljs-repl-types
'(("Rhino" "(cemerick.piggieback/cljs-repl (cljs.repl.rhino/repl-env))"
nil)
@@ -658,11 +672,14 @@ dependencies."
("Weasel" "(do (require 'weasel.repl.websocket) (cemerick.piggieback/cljs-repl (weasel.repl.websocket/repl-env :ip \"127.0.0.1\" :port 9001)))"
cider-check-weasel-requirements)
("Boot" "(do (require 'adzerk.boot-cljs-repl) (adzerk.boot-cljs-repl/start-repl))"
- cider-check-boot-requirements))
+ cider-check-boot-requirements)
+ ("Shadow" cider-shadow-cljs-init-form cider-check-shadow-cljs-requirements))
"A list of supported ClojureScript REPLs.
For each one we have its name, the form we need to evaluate in a Clojure
-REPL to start the ClojureScript REPL and functions to very their requirements.")
+REPL to start the ClojureScript REPL and functions to very their requirements.
+
+The form should be either a string or a function producing a string.")
(defcustom cider-default-cljs-repl nil
"The default ClojureScript REPL to start.
@@ -692,10 +709,14 @@ you're working on."
(defun cider-cljs-repl-form (repl-type)
"Get the cljs REPL form for REPL-TYPE."
- (cadr (seq-find
- (lambda (entry)
- (equal (car entry) repl-type))
- cider-cljs-repl-types)))
+ (let ((repl-form (cadr (seq-find
+ (lambda (entry)
+ (equal (car entry) repl-type))
+ cider-cljs-repl-types))))
+ ;; repl-form can be either a string or a function producing a string
+ (if (symbolp repl-form)
+ (funcall repl-form)
+ repl-form)))
(defun cider-verify-cljs-repl-requirements (repl-type)
"Verify that the requirements for REPL-TYPE are met."