diff options
author | Bozhidar Batsov <bozhidar@batsov.com> | 2018-05-21 09:17:12 +0300 |
---|---|---|
committer | Bozhidar Batsov <bozhidar@batsov.com> | 2018-05-21 09:17:12 +0300 |
commit | 31d4f0fb7a572d00efaad5c8bca65d6a437d5eab (patch) | |
tree | 5a6ef46e4afa473e25ef8ad8021eb99f8a4ce138 | |
parent | ab25ea6c6632b4557460f49146ae728e19ba1e94 (diff) |
Make the ClojureScript deps injection configurable and document it
-rw-r--r-- | cider.el | 37 | ||||
-rw-r--r-- | doc/clojurescript.md | 21 |
2 files changed, 52 insertions, 6 deletions
@@ -919,15 +919,46 @@ own buffer." (user-error "`cider-jack-in' is not allowed without a Clojure project"))) (user-error "The %s executable isn't on your `exec-path'" command)))) +(defvar cider-jack-in-cljs-dependencies nil + "List of dependencies where elements are lists of artifact name and version. +Added to `cider-jack-in-dependencies' when doing `cider-jack-in-cljs'.") +(put 'cider-jack-in-cljs-dependencies 'risky-local-variable t) +(cider-add-to-alist 'cider-jack-in-cljs-dependencies "cider/piggieback" "0.3.5") + +(defvar cider-jack-in-cljs-lein-plugins nil + "List of Leiningen plugins to be injected at jack-in. +Added to `cider-jack-in-lein-plugins' when doing `cider-jack-in-cljs'. +Each element is a list of artifact name and version, followed optionally by +keyword arguments. The only keyword argument currently accepted is +`:predicate', which should be given a function that takes the list (name, +version, and keyword arguments) and returns non-nil to indicate that the +plugin should actually be injected. (This is useful primarily for packages +that extend CIDER, not for users. For example, a refactoring package might +want to inject some middleware only when within a project context.)") +(put 'cider-jack-in-cljs-lein-plugins 'risky-local-variable t) + +(defvar cider-jack-in-cljs-nrepl-middlewares nil + "List of Clojure variable names. +Added to `cider-jack-in-nrepl-middlewares' when doing `cider-jack-in-cljs'. +Each of these Clojure variables should hold a vector of nREPL middlewares. +Instead of a string, an element can be a list containing a string followed +by optional keyword arguments. The only keyword argument currently +accepted is `:predicate', which should be given a function that takes the +list (string and keyword arguments) and returns non-nil to indicate that +the middlewares should actually be injected.") +(put 'cider-jack-in-cljs-nrepl-middlewares 'risky-local-variable t) +(add-to-list 'cider-jack-in-cljs-nrepl-middlewares "cider.piggieback/wrap-cljs-repl") + ;;;###autoload (defun cider-jack-in-clojurescript (&optional prompt-project) "Start an nREPL server and connect to it both Clojure and ClojureScript REPLs. If PROMPT-PROJECT is t, then prompt for the project for which to start the server." (interactive "P") - ;; TODO: That should be streamlined and made configurable - (let ((cider-jack-in-dependencies (cons '("cider/piggieback" "0.3.5") cider-jack-in-dependencies)) - (cider-jack-in-nrepl-middlewares (cons "cider.piggieback/wrap-cljs-repl" cider-jack-in-nrepl-middlewares))) + ;; We override the standard jack-in deps to inject additional ClojureScript-specific deps + (let ((cider-jack-in-dependencies (append cider-jack-in-dependencies cider-jack-in-cljs-dependencies)) + (cider-jack-in-lein-plugins (append cider-jack-in-lein-plugins cider-jack-in-cljs-lein-plugins)) + (cider-jack-in-nrepl-middlewares (append cider-jack-in-nrepl-middlewares cider-jack-in-cljs-nrepl-middlewares))) (cider-jack-in prompt-project 'cljs-too))) ;;;###autoload diff --git a/doc/clojurescript.md b/doc/clojurescript.md index 506c1b3c..d52f2084 100644 --- a/doc/clojurescript.md +++ b/doc/clojurescript.md @@ -5,11 +5,24 @@ the functionality available with Clojure exists for ClojureScript (at least not yet). To give you a concrete example - things like running tests and the debugger are currently Clojure-only features. + +### Piggieback + ClojureScript support relies on the [piggieback][] nREPL middleware being present in your REPL session. There's one exception to this, though - [shadow-cljs][]. It has its own nREPL middleware and doesn't rely on piggieback at all. +If `cider-inject-dependencies-at-jack-in` is enabled (which is the default) then +piggieback will be automatically added and configured for your project when +doing `cider-jack-in-cljs`. + +If this configuration option is disabled or you're going to connect to +an already running nREPL server using `cider-connect-cljs` - continue +reading ahead. + +#### Manual Piggieback Setup + To setup piggieback add the following dependencies to your project (`project.clj` in Leiningen based project or `build.boot` in Boot project): @@ -35,6 +48,8 @@ or in `build.boot`: repl {:middleware '[cider.piggieback/wrap-cljs-repl]}) ``` +### Starting a ClojureScript REPL + 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) @@ -126,7 +141,7 @@ documentation lookup, the namespace browser, and macroexpansion). [adzerk/boot-cljs-repl "X.Y.Z" :scope "test"] [pandeiro/boot-http "X.Y.Z" :scope "test"] [weasel "0.7.0" :scope "test"] -[cider/piggieback "0.3.4" :scope "test"] +[cider/piggieback "0.3.4" :scope "test"] ; not needed for cider-jack-in-cljs ``` and this at the end of `build.boot`: @@ -163,7 +178,7 @@ You can also use [Figwheel](https://github.com/bhauman/lein-figwheel) with CIDER 2. Add these to your dev `:dependencies`: ```clojure -[cider/piggieback "0.3.4"] +[cider/piggieback "0.3.4"] ; not needed for cider-jack-in-cljs [figwheel-sidecar "0.5.16"] ; use here whatever the current version of figwheel is ``` @@ -171,7 +186,7 @@ Keep in mind that figwheel 0.5.16 is the first to support piggieback 0.3. If you're using an older figwheel you should stick to piggieback 0.2.2 (which uses the old `com.cemerick/piggieback` package coordinates). -3. Add this to your dev `:repl-options`: +3. Add this to your dev `:repl-options` (not needed for `cider-jack-in-cljs`): ```clojure :nrepl-middleware [cider.piggieback/wrap-cljs-repl] |