11## ClojureScript
22
3- CIDER works with ClojureScript, but you should keep in mind that not all
4- the functionality available with Clojure exists for ClojureScript (at least
5- not yet). To give you a concrete example - things like running tests and
6- the debugger are currently Clojure-only features.
3+ CIDER works well with ClojureScript, but not all CIDER features are
4+ available in ClojureScript (yet). For instance, the test runner and
5+ debugger are currently Clojure-only features. Unlike the Clojure
6+ ecosystem that is dominated by Leiningen and Boot, the ClojureScript
7+ ecosystem has a number of different choices for REPLs. You'll have to
8+ decide which one you want to run and how you want CIDER to interact
9+ with it. This chapter describes some of the more common choices
10+ and the configurations required to get them working.
711
812
913### Piggieback
1014
1115ClojureScript support relies on the [ piggieback] [ ] nREPL middleware
1216being present in your REPL session. There's one exception to this,
13- though - [ shadow-cljs] [ ] . It has its own nREPL middleware and doesn't rely
17+ though: [ shadow-cljs] [ ] . It has its own nREPL middleware and doesn't rely
1418on piggieback at all.
1519
16- If ` cider-inject-dependencies-at-jack-in ` is enabled ( which is the default) then
17- piggieback will be automatically added and configured for your project when
18- doing ` cider-jack-in-cljs ` .
20+ If ` cider-inject-dependencies-at-jack-in ` is enabled, which it is by
21+ default, then piggieback will be automatically added and configured
22+ for your project when doing ` cider-jack-in-cljs ` .
1923
20- If this configuration option is disabled or you're going to connect to
21- an already running nREPL server using ` cider-connect-cljs ` - continue
22- reading ahead .
24+ If ` cider-inject-dependencies-at-jack-in ` is disabled or you're going
25+ to connect to an already running nREPL server using
26+ ` cider-connect-cljs ` , use the configuration in the following section .
2327
2428#### Manual Piggieback Setup
2529
26- To setup piggieback add the following dependencies to your project
27- (` project.clj ` in Leiningen based project or ` build.boot ` in Boot
30+ To setup piggieback, add the following dependencies to your project
31+ (` project.clj ` in a Leiningen based project or ` build.boot ` in a Boot
2832project):
2933
3034``` clojure
@@ -50,32 +54,37 @@ or in `build.boot`:
5054
5155### Starting a ClojureScript REPL
5256
53- There are many ClojureScript REPLs out there and it's often hard to wrap your
54- head around them and the differences between them. You'd do well to read [ this
55- awesome article] ( https://lambdaisland.com/guides/clojure-repls/clojurescript-repls )
56- before proceeding with the rest of the instructions listed here.
57+ !!! Tip
5758
58- Open a file in your project and issue <kbd >M-x</kbd >
59+ There are many ClojureScript REPLs available, each offering a
60+ different set of capabilities and features. As background for this
61+ section, you might want to read [this awesome
62+ article](https://lambdaisland.com/guides/clojure-repls/clojurescript-repls)
63+ before proceeding.
64+
65+ Open a file in your project and type <kbd >M-x</kbd >
5966` cider-jack-in-cljs ` <kbd >RET</kbd >. This will start up the nREPL
60- server, and then create a ClojureScript REPL buffer for you, one .
67+ server and create a ClojureScript REPL buffer.
6168
6269!!! Note
6370
6471 Prior to CIDER 0.18, `cider-jack-in-cljs` would create both a Clojure and
6572 a ClojureScript REPL. In CIDER 0.18+ if you want to create both REPLs
6673 you'll have to use `cider-jack-in-clj&cljs` instead.
6774
68- When you have a combination of Clojure and ClojureScript REPLs all
69- usual CIDER commands will be automatically directed to the appropriate
70- REPL, depending on whether you're visiting a ` .clj ` or a ` .cljs ` file.
75+ When you have a combination of Clojure and ClojureScript REPLs, CIDER
76+ will automatically direct all the usual CIDER commands to the
77+ appropriate REPL based on whether you're currently visitng a ` .clj ` or
78+ ` .cljs ` file.
7179
72- ` cider-jack-in-cljs ` will prompt you about the type of
73- ClojureScript to start. Keep in mind that some of the REPLs will
74- require some additional setup, before you can make use of them (e.g. you'll
75- need to have Node.js installed to be able to start a node REPL) .
80+ ` cider-jack-in-cljs ` will prompt you for the type of ClojureScript
81+ REPL you want to start. Keep in mind that some of the REPLs will
82+ require you to configure additional setup. For example, you'll need to
83+ have Node.js installed to be able to start a Node REPL.
7684
77- You can suppress the prompt the REPL to use by setting ` cider-default-cljs-repl ` .
78- Here's an example that will make Nashorn the default:
85+ If you frequently use the same ClojureScript REPL, you can set
86+ ` cider-default-cljs-repl ` and CIDER will skip the prompt and use this
87+ instead. For example, the following will make Nashorn the default:
7988
8089``` el
8190(setq cider-default-cljs-repl 'nashorn)
@@ -106,20 +115,20 @@ You can also modify the known ClojureScript REPLs on a per-project basis using
106115 (cider-default-cljs-repl . super-cljs)))
107116```
108117
109- You can also create a ClojureScript REPL with the command
110- ` cider-jack-in-sibling-clojurescript ` in cases where you already have a
111- Clojure REPL running .
118+ If you already have a Clojure REPL running and want to add a
119+ ClojureScript REPL, you can invoke
120+ ` cider-jack-in-sibling-clojurescript ` to add it .
112121
113- Continue reading for the additional setup needed for the various ClojureScript
114- REPLs out there .
122+ The following sections describe the configurations for several common
123+ CloudScript REPL use cases .
115124
116- ### Browser-connected ClojureScript REPL
125+ ### Browser-Connected ClojureScript REPL
117126
118127Using Weasel, you can also have a browser-connected REPL.
119128
1201291 . Add ` [weasel "0.7.0"] ` to your project's ` :dependencies ` .
121130
122- 2 . Issue <kbd >M-x</kbd > ` cider-jack-in-cljs ` <kbd >RET</kbd > and choose
131+ 2 . Type <kbd >M-x</kbd > ` cider-jack-in-cljs ` <kbd >RET</kbd > and choose
123132 the ` Weasel ` option when prompted about the ClojureScript REPL type you want
124133 to use.
125134
@@ -131,15 +140,15 @@ Using Weasel, you can also have a browser-connected REPL.
131140(repl/connect " ws://localhost:9001" )
132141```
133142
134- 4 . Open a file in your project and issue <kbd >M-x</kbd > ` cider-jack-in-cljs ` .
143+ 4 . Open a file in your project and type <kbd >M-x</kbd > ` cider-jack-in-cljs ` .
135144
136145Provided that a Piggieback-enabled ClojureScript environment is active in your
137146REPL session, code loading and evaluation will work seamlessly regardless of the
138147presence of the ` cider-nrepl ` middleware. If the middleware is present then most
139148other features of CIDER will also be enabled (including code completion,
140149documentation lookup, the namespace browser, and macroexpansion).
141150
142- ### Browser-connected ClojureScript REPL in Boot project
151+ ### Browser-Connected ClojureScript REPL in Boot Projects
143152
1441531 . Add this to your dependencies in ` build.boot ` :
145154
@@ -166,10 +175,10 @@ and this at the end of `build.boot`:
166175 (cljs )))
167176```
168177
169- 2 . Issue <kbd >M-x</kbd > ` customize-variable ` <kbd >RET</kbd > ` cider-boot-parameters `
178+ 2 . Type <kbd >M-x</kbd > ` customize-variable ` <kbd >RET</kbd > ` cider-boot-parameters `
170179 and insert ` dev ` .
171180
172- 3 . Open a file in your project and issue <kbd >M-x</kbd > ` cider-jack-in-cljs ` .
181+ 3 . Open a file in your project and type <kbd >M-x</kbd > ` cider-jack-in-cljs ` .
173182
1741835 . Connect to the running server with your browser. The address is printed on the terminal, but it's probably ` http://localhost:3000 ` .
175184
@@ -195,7 +204,7 @@ You can also use [Figwheel](https://github.com/bhauman/lein-figwheel) with CIDER
195204```
196205
197206Keep in mind that figwheel 0.5.16 is the first to support piggieback
198- 0.3. If you're using an older figwheel you should stick to piggieback
207+ 0.3. If you're using an older figwheel, you should stick to piggieback
1992080.2.2 (which uses the old ` com.cemerick/piggieback ` package coordinates).
200209
2012103 . Add this to your dev ` :repl-options ` (not needed for ` cider-jack-in-cljs ` ):
@@ -205,7 +214,7 @@ Keep in mind that figwheel 0.5.16 is the first to support piggieback
205214```
206215
2072164 . Start the REPL with ` cider-jack-in-cljs ` (<kbd >C-c C-x (C-)j (C-)s</kbd >). Select
208- ` figwheel ` when prompted about the ClojureScript REPL type.
217+ ` figwheel ` when prompted for the ClojureScript REPL type.
209218
2102195 . Open a browser to the Figwheel URL so that it can connect to your application.
211220
@@ -221,10 +230,10 @@ You should also check out
221230
222231You can also use [ Figwheel-main] ( https://github.com/bhauman/figwheel-main ) with CIDER.
223232
224- 1 . Add this to your dev ` :dependencies ` :
233+ 1 . Add this to your dev ` :dependencies ` (not needed for ` cider-jack-in-cljs ` ) :
225234
226235``` clojure
227- [cider/piggieback " 0.3.10" ] ; not needed for cider-jack-in-cljs
236+ [cider/piggieback " 0.3.10" ]
228237```
229238
2302392 . Add this to your dev ` :repl-options ` (not needed for ` cider-jack-in-cljs ` ):
@@ -233,30 +242,31 @@ You can also use [Figwheel-main](https://github.com/bhauman/figwheel-main) with
233242:nrepl-middleware [cider.piggieback/wrap-cljs-repl]
234243```
235244
236- 3 . Start the REPL with ` cider-jack-in-cljs ` (<kbd >C-c C-x (C-)j (C-)s</kbd >). Select
237- ` figwheel-main ` when prompted about the ClojureScript REPL type.
245+ 3 . Start the REPL with ` cider-jack-in-cljs ` (<kbd >C-c C-x (C-)j
246+ (C-)s</kbd >). When CIDER prompts about the ClojureScript REPL type,
247+ type ` figwheel-main ` .
238248
2392494 . Select the Figwheel build to run when prompted for it. (e.g. ` :dev ` ).
240250
241251### Using shadow-cljs
242252
243- Provided you've configured your project correctly you can simply use
244- ` cider-jack-in-cljs ` to use ` shadow-cljs ` .
253+ Provided you've configured your project correctly, you can simply use
254+ ` cider-jack-in-cljs ` for ` shadow-cljs ` .
245255
246- This will automatically start the shadow-cljs server and connect to it. You'll also
247- be prompted for the build to use.
256+ This will automatically start the shadow-cljs server and connect to
257+ it. You'll also be prompted for the build to use.
248258
249259Alternatively you can start the server manually with something like:
250260
251- ```
252- npx shadow-cljs server
261+ ``` sh
262+ $ npx shadow-cljs server
253263```
254264
255265And connect to it with ` cider-connect ` .
256266
257- Lastly, if you already have a running server watching a build, for instance you
258- have already run ` npx shadow-cljs watch :dev ` , you can use the ` shadow-select `
259- CLJS REPL and specify ` :dev ` when prompted.
267+ If you already have a running server watching a build ( for instance
268+ you have already run ` npx shadow-cljs watch :dev ` ) , you can use the
269+ ` shadow-select ` CLJS REPL and specify ` :dev ` when prompted.
260270
261271[ leiningen ] : http://leiningen.org/
262272[ boot ] : http://boot-clj.com/
@@ -265,14 +275,16 @@ CLJS REPL and specify `:dev` when prompted.
265275
266276## Working with ` .cljc ` files
267277
268- Ordinarily, CIDER dispatches code from ` clj ` files to Clojure REPLs and ` cljs `
269- files to ClojureScript REPLs. However, ` cljc ` files have two possible connection
270- targets. By default, CIDER tries to evaluate ` cljc ` files in all matching
271- connection buffers, both ` clj ` and ` cljs ` (if present).
272-
273- Simply put - if you're evaluating the code ` (+ 2 2) ` in a ` cljc ` file and you
274- have an active Clojure and and active ClojureScript REPL, then the code is going
275- to be evaluated twice - once for each of the REPLs. In fact, you can create
276- multiple clj and cljs sibling connections (<kbd >C-c C-x C-s C-s/j</kbd >) within
277- Cider session and evaluation will be directed into all REPLs simultaneously. See
278- [ Managing Connections] ( managing_connections.md ) for more details.
278+ Ordinarily, CIDER dispatches code from ` clj ` files to Clojure REPLs
279+ and ` cljs ` files to ClojureScript REPLs. But` cljc ` files have two
280+ possible connection targets, both of which are valid. So, by default,
281+ CIDER tries to evaluate ` cljc ` files in all matching connection
282+ buffers, both ` clj ` and ` cljs ` , if present.
283+
284+ Thus, if you're evaluating the code ` (+ 2 2) ` in a ` cljc ` file and you
285+ have both an active Clojure and ClojureScript REPL then the code is
286+ going to be evaluated twice, once in each of the REPLs. In fact, you
287+ can create multiple clj and cljs sibling connections (<kbd >C-c C-x C-s
288+ C-s/j</kbd >) within a CIDER session and evaluation will be directed
289+ into all REPLs simultaneously. See [ Managing
290+ Connections] ( managing_connections.md ) for more details.
0 commit comments