Skip to content

Commit

Permalink
Support watching several shadow-cljs builds.
Browse files Browse the repository at this point in the history
Add a cider-shadow-watched-builds customization variable which is the list of
builds to watch. If not defined fallback on watching the default build set in
cider-shadow-default-options or prompt the user.
  • Loading branch information
ageneau committed Dec 10, 2020
1 parent b197dbc commit 818ba0c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### New features

* [#2909](https://github.com/clojure-emacs/cider/issues/2909): Add new customization variable `cider-inspector-auto-select-buffer` to control the auto selection of the inspector buffer.
* Add a new customization variable cider-shadow-watched-builds to allow watching several shadow-cljs builds at the same time.

### Bugs fixed

Expand Down
32 changes: 23 additions & 9 deletions cider.el
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,11 @@ Generally you should not disable this unless you run into some faulty check."
options
(concat ":" options)))

(defcustom cider-shadow-watched-builds nil
"Defines the list of builds `shadow-cljs' should watch."
:type '(repeat string)
:package-version '(cider . "0.26.2"))

(defcustom cider-shadow-default-options nil
"Defines default `shadow-cljs' options."
:type 'string
Expand Down Expand Up @@ -758,17 +763,26 @@ not just a string."
We have to prompt the user to select a build, that's why
this is a command, not just a string."
(let* ((shadow-require "(require '[shadow.cljs.devtools.api :as shadow])")

(default-build (cider-normalize-cljs-init-options
(or cider-shadow-default-options
(car cider-shadow-watched-builds)
(completing-read "Select shadow-cljs build: "
(cider--shadow-get-builds)))))

(watched-builds (or (mapcar #'cider-normalize-cljs-init-options cider-shadow-watched-builds)
(list default-build)))

(watched-builds-form (mapconcat (lambda (build) (format "(shadow/watch %s)" build))
watched-builds
" "))
;; form used for user-defined builds
(user-build-form "(do %s (shadow/watch %s) (shadow/nrepl-select %s))")
(user-build-form "(do %s %s (shadow/nrepl-select %s))")
;; form used for built-in builds like :browser-repl and :node-repl
(default-build-form "(do %s (shadow/%s))")
(options (or cider-shadow-default-options
(completing-read "Select shadow-cljs build: "
(cider--shadow-get-builds))))
(build (cider-normalize-cljs-init-options options)))
(if (member build '(":browser-repl" ":node-repl"))
(format default-build-form shadow-require (string-remove-prefix ":" build))
(format user-build-form shadow-require build build))))
(default-build-form "(do %s (shadow/%s))"))
(if (member default-build '(":browser-repl" ":node-repl"))
(format default-build-form shadow-require (string-remove-prefix ":" default-build))
(format user-build-form shadow-require watched-builds-form default-build))))

(defcustom cider-figwheel-main-default-options nil
"Defines the `figwheel.main/start' options.
Expand Down
3 changes: 2 additions & 1 deletion doc/modules/ROOT/pages/cljs/shadow-cljs.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ root of your project.
[source,clojure]
----
((nil . ((cider-default-cljs-repl . shadow)
(cider-shadow-default-options . "<your-build-name-here>"))))
(cider-shadow-default-options . "<your-build-name-here>")
(cider-shadow-watched-builds . ("<first-build>" "<other-build>")))))
----

=== Using cider-connect-cljs
Expand Down

0 comments on commit 818ba0c

Please sign in to comment.