Skip to content

Commit 8987e77

Browse files
committed
Add support for starting a shadow-cljs ClojureScript REPL
1 parent c4f1643 commit 8987e77

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

cider.el

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,20 @@ dependencies."
646646
(unless (cider-library-present-p "boot-cljs-repl")
647647
(user-error "The Boot ClojureScript REPL is not available. Please check https://github.com/adzerk-oss/boot-cljs-repl/blob/master/README.md")))
648648

649+
(defun cider-check-shadow-cljs-requirements ()
650+
"Check whether we can start a shadow-cljs REPL."
651+
(unless (cider-library-present-p "shadow-cljs")
652+
(user-error "The shadow-cljs ClojureScript REPL is not available")))
653+
654+
(defun cider-shadow-cljs-init-form ()
655+
"Generate the init form for a shadow-cljs REPL.
656+
657+
We have to prompt the user to select a build, that's why
658+
this is a command, not just a string."
659+
(let ((form "(do (require '[shadow.cljs.devtools.api :as shadow]) (shadow/watch :%s) (shadow/nrepl-select :%s))")
660+
(build (string-remove-prefix ":" (read-from-minibuffer "Select shadow-cljs build: "))))
661+
(format form build build)))
662+
649663
(defconst cider-cljs-repl-types
650664
'(("Rhino" "(cemerick.piggieback/cljs-repl (cljs.repl.rhino/repl-env))"
651665
nil)
@@ -658,11 +672,14 @@ dependencies."
658672
("Weasel" "(do (require 'weasel.repl.websocket) (cemerick.piggieback/cljs-repl (weasel.repl.websocket/repl-env :ip \"127.0.0.1\" :port 9001)))"
659673
cider-check-weasel-requirements)
660674
("Boot" "(do (require 'adzerk.boot-cljs-repl) (adzerk.boot-cljs-repl/start-repl))"
661-
cider-check-boot-requirements))
675+
cider-check-boot-requirements)
676+
("Shadow" cider-shadow-cljs-init-form cider-check-shadow-cljs-requirements))
662677
"A list of supported ClojureScript REPLs.
663678
664679
For each one we have its name, the form we need to evaluate in a Clojure
665-
REPL to start the ClojureScript REPL and functions to very their requirements.")
680+
REPL to start the ClojureScript REPL and functions to very their requirements.
681+
682+
The form should be either a string or a function producing a string.")
666683

667684
(defcustom cider-default-cljs-repl nil
668685
"The default ClojureScript REPL to start.
@@ -692,10 +709,14 @@ you're working on."
692709

693710
(defun cider-cljs-repl-form (repl-type)
694711
"Get the cljs REPL form for REPL-TYPE."
695-
(cadr (seq-find
696-
(lambda (entry)
697-
(equal (car entry) repl-type))
698-
cider-cljs-repl-types)))
712+
(let ((repl-form (cadr (seq-find
713+
(lambda (entry)
714+
(equal (car entry) repl-type))
715+
cider-cljs-repl-types))))
716+
;; repl-form can be either a string or a function producing a string
717+
(if (symbolp repl-form)
718+
(funcall repl-form)
719+
repl-form)))
699720

700721
(defun cider-verify-cljs-repl-requirements (repl-type)
701722
"Verify that the requirements for REPL-TYPE are met."

0 commit comments

Comments
 (0)