summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBozhidar Batsov <bozhidar@batsov.com>2018-03-01 11:12:09 +0700
committerBozhidar Batsov <bozhidar@batsov.com>2018-03-01 11:12:09 +0700
commitdae5285ea9cc512f8fc3cfed3a248ae0dc273978 (patch)
tree43302b8a7d792338952f75e075f196b8d359823f
parent88f4fcf1d39a13ff336657b2cc4161ebb9d955d6 (diff)
[#2202] Decouple the ClojureScript REPL selection from the build tool being used
Now the user will simply be prompted for the REPL they want to start. Later we should make this smarter - compute a good default based on the project deps, don't show unsupported options, etc.
-rw-r--r--CHANGELOG.md1
-rw-r--r--cider-mode.el3
-rw-r--r--cider.el91
-rw-r--r--doc/up_and_running.md23
4 files changed, 37 insertions, 81 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fa9aa69c..ba0d8c09 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -29,6 +29,7 @@
* [#2151](https://github.com/clojure-emacs/cider/pull/2151): Improve formatting of spec in `cider-doc` buffer.
* Remove support for CLJX.
* [#2171](https://github.com/clojure-emacs/cider/issues/2171): Update `See Also` mappings for Clojure 1.9.
+* [#2202](https://github.com/clojure-emacs/cider/issues/2202): Make `cider-jack-in-clojurescript` prompt from the ClojureScript REPL type to use.
## 0.16.0 (2017-12-28)
diff --git a/cider-mode.el b/cider-mode.el
index 095e1a12..e45ffd65 100644
--- a/cider-mode.el
+++ b/cider-mode.el
@@ -374,8 +374,7 @@ Configure `cider-cljs-*-repl' to change the ClojureScript REPL to use for your b
["Connect to a ClojureScript REPL" cider-connect-clojurescript
:help "Connects to a ClojureScript 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', `cider-cljs-boot-repl' and `cider-cljs-gradle-repl' to change the ClojureScript REPL to use."]
+ :help "Starts an nREPL server, connects a Clojure REPL to it, and then a ClojureScript REPL."]
"--"
["View manual online" cider-view-manual])))
diff --git a/cider.el b/cider.el
index 96183531..d9ecf525 100644
--- a/cider.el
+++ b/cider.el
@@ -504,70 +504,31 @@ dependencies."
;;; ClojureScript REPL creation
-(defconst cider--cljs-repl-types
- '(("(cemerick.piggieback/cljs-repl (cljs.repl.rhino/repl-env))"
- "Rhino" "")
- ("(do (require 'figwheel-sidecar.repl-api) (figwheel-sidecar.repl-api/start-figwheel!) (figwheel-sidecar.repl-api/cljs-repl))"
- "Figwheel-sidecar" " (add figwheel-sidecar to your plugins)")
- ("(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 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.
-This is only used in lein 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.11.0")
- :group 'cider)
-
-(defcustom cider-cljs-clojure-repl "(cemerick.piggieback/cljs-repl (cljs.repl.rhino/repl-env))"
- "Clojure form that returns a ClojureScript REPL environment.
-This is only used in clj 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.17.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 returning a ClojureScript REPL environment based on PROJECT-TYPE."
- (pcase project-type
- ("lein" cider-cljs-lein-repl)
- ("boot" cider-cljs-boot-repl)
- ("clojure" cider-cljs-clojure-repl)
- ("gradle" cider-cljs-gradle-repl)
- (_ (error "Unsupported project type `%s'" project-type))))
+(defconst cider-cljs-repl-types
+ '(("Rhino" "(cemerick.piggieback/cljs-repl (cljs.repl.rhino/repl-env))" "")
+ ("Figwhell-sidecar" "(do (require 'figwheel-sidecar.repl-api) (figwheel-sidecar.repl-api/start-figwheel!) (figwheel-sidecar.repl-api/cljs-repl))"
+ " (add figwheel-sidecar to your plugins)")
+ ("Node" "(do (require 'cljs.repl.node) (cemerick.piggieback/cljs-repl (cljs.repl.node/repl-env)))"
+ " (requires NodeJS to be installed)")
+ ("Weasel" "(do (require 'weasel.repl.websocket) (cemerick.piggieback/cljs-repl (weasel.repl.websocket/repl-env :ip \"127.0.0.1\" :port 9001)))"
+ " (see http://cider.readthedocs.io/en/latest/up_and_running/#browser-connected-clojurescript-repl)")
+ ("Boot-cljs-repl" "(do (require 'adzerk.boot-cljs-repl) (adzerk.boot-cljs-repl/start-repl))"
+ " (see https://github.com/adzerk-oss/boot-cljs-repl/blob/master/README.md"))
+ "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 some installation instructions (if
+necessary).")
+
+(make-obsolete-variable 'cider-cljs-lein-repl "The ClojureScript REPL type is now selected interactively" "0.17")
+(make-obsolete-variable 'cider-cljs-boot-repl "The ClojureScript REPL type is now selected interactively" "0.17")
+(make-obsolete-variable 'cider-cljs-gradle-repl "The ClojureScript REPL type is now selected interactively" "0.17")
+
+(defun cider-select-cljs-repl ()
+ "Select the ClojureScript REPL to use with `cider-jack-in-clojurescript'."
+ (let* ((repl-types (mapcar #'car cider-cljs-repl-types))
+ (selected-type (completing-read "Select ClojureScript REPL type: " repl-types)))
+ (cadr (seq-find (lambda (entry) (equal (car entry) selected-type)) cider-cljs-repl-types))))
(defun cider--offer-to-open-app-in-browser (server-buffer)
"Look for a server address in SERVER-BUFFER and offer to open it."
@@ -600,7 +561,7 @@ should be the regular Clojure REPL started by the server process filter."
(get-buffer-process nrepl-server-buffer)))))
(cljs-proc (apply #'nrepl-start-client-process client-process-args))
(cljs-buffer (process-buffer cljs-proc))
- (cljs-repl-form (cider-cljs-repl-form (cider-project-type))))
+ (cljs-repl-form (cider-select-cljs-repl)))
(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
diff --git a/doc/up_and_running.md b/doc/up_and_running.md
index 7b12f345..ea4e7c9e 100644
--- a/doc/up_and_running.md
+++ b/doc/up_and_running.md
@@ -103,9 +103,10 @@ or in `built.boot`:
repl {:middleware '[cemerick.piggieback/wrap-cljs-repl]})
```
-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).
+There are many ClojureScript REPLs out there and it's often hard to wrap your
+head around them and the differences between them. You'd do well to read [this
+awesome article](https://lambdaisland.com/guides/clojure-repls/clojurescript-repls)
+before proceeding with the rest of the instructions listed here.
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
@@ -120,9 +121,9 @@ 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> plus either
- `cider-cljs-lein-repl`, `cider-cljs-boot-repl` or `cider-cljs-gradle-repl`
- and choose the `Weasel` option.
+2. Issue <kbd>M-x</kbd> `cider-jack-in-clojurescript` <kbd>RET</kbd> and choose
+ the `Weasel` option when prompted about the ClojureScript REPL type you want
+ to use.
3. Add this to your ClojureScript code:
@@ -196,15 +197,9 @@ You can also use [Figwheel](https://github.com/bhauman/lein-figwheel) with CIDER
:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]
```
-4. Instruct CIDER to use Figwheel in your Emacs config:
+4. Start the REPL with `cider-jack-in-clojurescript` (<kbd>C-c M-J</kbd>)
-```el
-(setq cider-cljs-lein-repl "(do (use 'figwheel-sidecar.repl-api) (start-figwheel!) (cljs-repl))")
-```
-
-5. Start the REPL with `cider-jack-in-clojurescript` (<kbd>C-c M-J</kbd>)
-
-6. Open a browser to the Figwheel URL so that it can connect to your application.
+5. Open a browser to the Figwheel URL so that it can connect to your application.
You now have two nREPL connections, one for Clojure and one for ClojureScript.
CIDER will determine which to use based on the type of file you're editing.