nREPL Middleware Setup
You can skip this section if you don’t plan to use cider-connect or don’t care
about the advanced functionality that requires cider-nrepl.
|
Much of CIDER’s functionality depends on its own
nREPL middleware. cider-jack-in
(C-c C-x (C-)j (C-)j) automatically injects this middleware and other
dependencies as required. But if you prefer a standalone REPL, you will need to
invoke cider-connect instead of cider-jack-in and manually add the
dependencies to your Clojure project (explained in the following sections).
Setting Up a Standalone REPL
-
Leiningen
-
tools.deps
-
Launchpad
-
Gradle
-
Maven
Use the convenient plugin for defaults, either in your project’s
project.clj file or in the :repl profile in ~/.lein/profiles.clj.
:plugins [[cider/cider-nrepl "0.62.2"]]
A minimal profiles.clj for CIDER would be:
{:repl {:plugins [[cider/cider-nrepl "0.62.2"]]}}
Be careful not to place this in the :user profile, as this way CIDER’s
middleware will always get loaded, causing lein to start slower. You really
need it just for lein repl and this is what the :repl profile is for.
|
You can add the following aliases to your deps.edn in order to launch
a standalone Clojure(Script) nREPL server with CIDER middleware from
the commandline with something like clj -A:cider-clj. Then from emacs
run cider-connect or cider-connect-cljs.
:cider-clj {:extra-deps {cider/cider-nrepl {:mvn/version "0.62.2"}}
:main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware]"]}
:cider-cljs {:extra-deps {org.clojure/clojurescript {:mvn/version "1.10.339"}
cider/cider-nrepl {:mvn/version "0.62.2"}
cider/piggieback {:mvn/version "0.7.0"}}
:main-opts ["-m" "nrepl.cmdline" "--middleware"
"[cider.nrepl/cider-middleware,cider.piggieback/wrap-cljs-repl]"]}
| the suggested ClojureScript setup is apt for e.g. library development, but not for frontend development. For those cases, you may want to check out our shadow-cljs or figwheel setups instead. |
Launchpad lets you start a nREPL server from the command line, while including the middleware your editor requires and providing additional developer conveniences.
In your project, create bin/launchpad. The only requirement is babashka.
#!/usr/bin/env bb
(require '[babashka.deps :as deps])
(deps/add-deps '{:deps {com.lambdaisland/launchpad {:mvn/version "RELEASE"}}})
(require '[lambdaisland.launchpad :as launchpad])
(launchpad/main {})
Now bin/launchpad --emacs will start a Clojure process, and connect Emacs to your REPL, and include the
cider-nrepl middleware.
To load additional middleware, configure it inside bin/launchpad
;; <snip> ... as before ... <snip>
(launchpad/main {:middleware [your.custom/nrepl-middleware]})
See bin/launchpad --help or the README for more info.
| Make sure you’re using Clojurephant 0.4.0 or newer. |
dependencies {
devImplementation 'nrepl:nrepl:1.7.0'
devImplementation 'cider:cider-nrepl:0.62.2'
}
tasks.named('clojureRepl') {
middleware = ['cider.nrepl/cider-middleware']
}
You can then launch the nREPL server from the command line via: ./gradlew clojureRepl.
For more information, see the Clojurephant docs.
| This section is currently a stub. Contributions welcome! |
Using Embedded nREPL Server
If you’re embedding nREPL in your application, you’ll have to start the server with CIDER’s own nREPL handler.
(ns my-app
(:require [nrepl.server :as nrepl-server]
[cider.nrepl :refer (cider-nrepl-handler)]))
(defn -main
[]
(nrepl-server/start-server :port 7888 :handler cider-nrepl-handler))
It goes without saying that your project should depend on cider-nrepl.
CIDER and cider-nrepl projects are co-developed, but are not released in a
lock-step — they have differing versions. Usually, any recent version of
cider-nrepl should be (mostly) compatible with a recent version of CIDER. You
can check the required version of cider-nrepl for your version of CIDER by
looking at cider-required-middleware-version. See also the
compatibility
matrix.
|