Skip to content

Commit

Permalink
[Fix clojure-emacs#1881] Add cider-cljs-*-repl defcustom and hook `…
Browse files Browse the repository at this point in the history
…boot-cljs-repl`

This patch firstly adds two more defcustoms, `cider-cljs-boot-repl` and
`cider-cljs-gradle-repl`, that will be queried by the
`cider-cljs-repl-form` function on `cider-jack-in-clojurescript`

Secondly, it adds a clause in `cider--cljs-repl-types` that allows to
automatically call `adzerk.boot-cljs-repl/start-repl` in case `boot` is
the project type.
  • Loading branch information
arichiardi committed Jan 26, 2017
1 parent 240c6ed commit 7b2e3e2
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 18 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* [#1544](https://github.com/clojure-emacs/cider/issues/1544): Add a new defcustom `nrepl-use-ssh-fallback-for-remote-hosts` to control the behavior of `nrepl-connect` (and in turn that of `cider-connect`) for remote hosts.
* [#1910](https://github.com/clojure-emacs/cider/issues/1910): Add custom company-mode completion style to show fuzzy completions from Compliment.
* Introduce `cider-*-global-options` for customizing options that are not related to tasks.
* [#1731](https://github.com/clojure-emacs/cider/issues/1731): Change code in order to use the new `cider.tasks/add-middleware` boot tasks.
* [#1731](https://github.com/clojure-emacs/cider/issues/1731): Add `cider-cljs-boot-repl` and `cider-cljs-gradle-repl` defcustom and hook `boot-cljs-repl`.

### Changes

Expand All @@ -29,6 +29,7 @@
* [#1875](https://github.com/clojure-emacs/cider/issues/1875): Ensure cljc buffers can load buffer into both clj and cljs repls.
* [#1897](https://github.com/clojure-emacs/cider/issues/1897): Bind TAB in stacktrace buffers in the terminal.
* [#1895](https://github.com/clojure-emacs/cider/issues/1895): Connect to the same host:port after `cider-restart` if the connection was established with `cider-connect`.
* [#1881](https://github.com/clojure-emacs/cider/issues/1881): Error starting ClojureScript Repl with Boot project

## 0.14.0 (2016-10-13)

Expand Down
8 changes: 5 additions & 3 deletions cider-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,11 @@ Returns to the buffer in which the command was invoked."
("Clojurescript"
["Start a Clojure REPL, and a ClojureScript REPL" cider-jack-in-clojurescript
:help "Starts an nREPL server, connects a Clojure REPL to it, and then a ClojureScript REPL.
Configure `cider-cljs-lein-repl' to change the ClojureScript REPL to use."]
Configure `cider-cljs-*-repl' to change the ClojureScript REPL to use for your build tool."]
["Create a ClojureScript REPL from a Clojure REPL" cider-create-sibling-cljs-repl]
["Configure the ClojureScript REPL to use" (customize-variable 'cider-cljs-lein-repl)])
["Form for launching a ClojureScript REPL via Leiningen" (customize-variable 'cider-cljs-lein-repl)]
["Form for launching a ClojureScript REPL via Boot" (customize-variable 'cider-cljs-boot-repl)]
["Form for launching a ClojureScript REPL via Gradle" (customize-variable 'cider-cljs-gradle-repl)])
"--"
["Connection info" cider-display-connection-info
:active cider-connections]
Expand Down Expand Up @@ -342,7 +344,7 @@ Configure `cider-cljs-lein-repl' to change the ClojureScript REPL to use."]
:help "Connects to a REPL that's already running."]
["Start a Clojure REPL, and a ClojureScript REPL" cider-jack-in-clojurescript
:help "Starts an nREPL server, connects a Clojure REPL to it, and then a ClojureScript REPL.
Configure `cider-cljs-lein-repl' to change the ClojureScript REPL to use."]
Configure `cider-cljs-lein-repl', `cider-cljs-boot-repl' and `cider-cljs-gradle-repl' to change the ClojureScript REPL to use."]
"--"
["View manual online" cider-view-manual])))

Expand Down
43 changes: 39 additions & 4 deletions cider.el
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,9 @@ dependencies."
("(do (require 'cljs.repl.node) (cemerick.piggieback/cljs-repl (cljs.repl.node/repl-env)))"
"Node" " (requires NodeJS to be installed)")
("(do (require 'weasel.repl.websocket) (cemerick.piggieback/cljs-repl (weasel.repl.websocket/repl-env :ip \"127.0.0.1\" :port 9001)))"
"Weasel" " (see Readme for additional configuration)")))
"Weasel" " (see http://cider.readthedocs.io/en/latest/up_and_running/#browser-connected-clojurescript-repl)")
("(do (require 'adzerk.boot-cljs-repl) (adzerk.boot-cljs-repl/start-repl))"
"Boot-cljs-repl" " (see https://github.com/adzerk-oss/boot-cljs-repl/blob/master/README.md")))

(defcustom cider-cljs-lein-repl "(cemerick.piggieback/cljs-repl (cljs.repl.rhino/repl-env))"
"Clojure form that returns a ClojureScript REPL environment.
Expand All @@ -446,8 +448,40 @@ it should start a ClojureScript REPL."
cider--cljs-repl-types)
(string :tag "Custom"))
:safe (lambda (x) (assoc x cider--cljs-repl-types))
:package-version '(cider . "0.11.0")
:group 'cider)

(defcustom cider-cljs-boot-repl "(do (require 'adzerk.boot-cljs-repl) (adzerk.boot-cljs-repl/start-repl))"
"Clojure form that returns a ClojureScript REPL environment.
This is only used in boot projects. It is evaluated in a Clojure REPL and
it should start a ClojureScript REPL."
:type `(choice ,@(seq-map (lambda (x) `(const :tag ,(apply #'concat (cdr x)) ,(car x)))
cider--cljs-repl-types)
(string :tag "Custom"))
:safe (lambda (x) (assoc x cider--cljs-repl-types))
:package-version '(cider . "0.15.0")
:group 'cider)

(defcustom cider-cljs-gradle-repl "(cemerick.piggieback/cljs-repl (cljs.repl.rhino/repl-env))"
"Clojure form that returns a ClojureScript REPL environment.
This is only used in gradle projects. It is evaluated in a Clojure REPL and
it should start a ClojureScript REPL."
:type `(choice ,@(seq-map (lambda (x) `(const :tag ,(apply #'concat (cdr x)) ,(car x)))
cider--cljs-repl-types)
(string :tag "Custom"))
:safe (lambda (x) (assoc x cider--cljs-repl-types))
:package-version '(cider . "0.15.0")
:group 'cider)

(defun cider-cljs-repl-form (project-type)
"Return a Clojure form that returns a ClojureScript REPL environment
based on PROJECT-TYPE."
(pcase project-type
("lein" cider-cljs-lein-repl)
("boot" cider-cljs-boot-repl)
("gradle" cider-cljs-gradle-repl)
(_ (error "Unsupported project type `%s'" project-type))))

(defun cider--offer-to-open-app-in-browser (server-buffer)
"Look for a server address in SERVER-BUFFER and offer to open it."
(when (buffer-live-p server-buffer)
Expand Down Expand Up @@ -475,7 +509,8 @@ should be the regular Clojure REPL started by the server process filter."
(when (buffer-live-p nrepl-server-buffer)
(get-buffer-process nrepl-server-buffer)))))
(cljs-proc (apply #'nrepl-start-client-process client-process-args))
(cljs-buffer (process-buffer cljs-proc)))
(cljs-buffer (process-buffer cljs-proc))
(cljs-repl-form (cider-cljs-repl-form (cider-project-type))))
(with-current-buffer cljs-buffer
;; The new connection has now been bumped to the top, but it's still a
;; Clojure REPL! Additionally, some ClojureScript REPLs can actually take
Expand All @@ -484,14 +519,14 @@ should be the regular Clojure REPL started by the server process filter."
;; original Clojure REPL. Our solution is to bump the original REPL back
;; up the list, so it takes priority on Clojure requests.
(cider-make-connection-default client-buffer)
(pcase (assoc cider-cljs-lein-repl cider--cljs-repl-types)
(pcase (assoc cljs-repl-form cider--cljs-repl-types)
(`(,_ ,name ,info)
(message "Starting a %s REPL%s" name (or info "")))
(_ (message "Starting a custom ClojureScript REPL")))
(cider-nrepl-send-request
(list "op" "eval"
"ns" (cider-current-ns)
"code" cider-cljs-lein-repl)
"code" cljs-repl-form)
(cider-repl-handler (current-buffer)))
(cider--offer-to-open-app-in-browser nrepl-server-buffer))))

Expand Down
20 changes: 10 additions & 10 deletions doc/up_and_running.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ helpful for identifying each host.

## ClojureScript usage

ClojureScript support relies on the
[piggieback][] nREPL middleware being
ClojureScript support relies on the [piggieback][] nREPL middleware being
present in your REPL session.

Add the following dependencies to your project (`project.clj` in Leiningen based project
Expand All @@ -104,8 +103,9 @@ or in `built.boot`:
repl {:middleware '[cemerick.piggieback/wrap-cljs-repl]})
```

Issue <kbd>M-x</kbd> `customize-variable` <kbd>RET</kbd> `cider-cljs-lein-repl` if
you'd like to change the REPL used (the default is `rhino`).
Issue <kbd>M-x</kbd> `customize-variable` <kbd>RET</kbd> and either
`cider-cljs-lein-repl`, `cider-cljs-boot-repl` or `cider-cljs-gradle-repl` if
you'd like to change the REPL used (the default is `rhino` where possible).

Open a file in your project and issue <kbd>M-x</kbd>
`cider-jack-in-clojurescript` <kbd>RET</kbd>. This will start up the nREPL
Expand All @@ -120,7 +120,8 @@ Using Weasel, you can also have a browser-connected REPL.

1. Add `[weasel "0.7.0"]` to your project's `:dependencies`.

2. Issue <kbd>M-x</kbd> `customize-variable` <kbd>RET</kbd> `cider-cljs-lein-repl`
2. Issue <kbd>M-x</kbd> `customize-variable` <kbd>RET</kbd> plus either
`cider-cljs-lein-repl`, `cider-cljs-boot-repl` or `cider-cljs-gradle-repl`
and choose the `Weasel` option.

3. Add this to your ClojureScript code:
Expand Down Expand Up @@ -156,7 +157,7 @@ and this at the end of `build.boot`:
```clojure
(require
'[adzerk.boot-cljs :refer [cljs]]
'[adzerk.boot-cljs-repl :refer [cljs-repl start-repl]]
'[adzerk.boot-cljs-repl :refer [cljs-repl]]
'[pandeiro.boot-http :refer [serve]])

(deftask dev []
Expand All @@ -166,11 +167,10 @@ and this at the end of `build.boot`:
(cljs)))
```

2. Start `boot dev` in a terminal.
2. Issue <kbd>M-x</kbd> `customize-variable` <kbd>RET</kbd> `cider-boot-parameters`
and insert `dev`.

3. <kbd>M-x</kbd> `cider-connect` to localhost and select the repl process.

4. Execute `(start-repl)` at the prompt: `boot.user> (start-repl)`.
3. Open a file in your project and issue <kbd>M-x</kbd> `cider-jack-in-clojurescript`.

5. Connect to the running server with your browser. The address is printed on the terminal, but it's probably `http://localhost:3000`.

Expand Down

0 comments on commit 7b2e3e2

Please sign in to comment.