Nrepl-based editors
For development workflows that require nREPL (e.g. Calva, Emacs with Cider) Reveal has a middleware that will show evaluation results produced by nrepl: vlaaad.reveal.nrepl/middleware, you will need to add it to your middleware list. The minimum required version of nrepl is 0.6.0.
Example of using this middleware with command line nrepl entry point:
...
Alternatively, you can create .nrepl.edn file in your project directory that will be picked up by nrepl. Example .nrepl.edn file:
{:middleware [vlaaad.reveal.nrepl/middleware]}
...
To reproduce
Create an empty deps.edn file:
{}
In the same directory create a .nrepl.edn file with reveal middleware:
{:middleware [vlaaad.reveal.nrepl/middleware]}
Open the deps.edn project file and jack in to the REPL with M-x cider-jack-in-clj RET.
Cider brings up an nREPL and connects to it, but there is no reveal middleware injected, i.e. no reveal window pops up.
This is because cider makes uses the --middleware command line option when invoking nREPL which takes precedence over the corresponding :middleware [vlaaad.reveal.nrepl/middleware option in .nrepl:
Luckily, cider has a couple of configuration variables that can be set to download extra dependencies and inject nREPL middlewares (cider-jack-in-dependencies and cider-jack-in-nrepl-middlewares respectively), that can be used to load reveal as part of the REPL upbringing process (called jack-in in cider's nomenclature).
Perhaps you might want to add the following in the documentation.
To configure CIDER to download and inject revaal in the nREPL middleware list:
First add a function in your Emacs init file that configures CIDER to download and inject the given reveal version in the nREPL middleware list at jack in:
(defun reveal-cider-add! (version)
"Injects vlaaad/reveal VERSION to cider's jack-in middleware list.
It only takes effect on the current buffer."
(require 'cider)
(make-local-variable 'cider-jack-in-dependencies)
(make-local-variable 'cider-jack-in-nrepl-middlewares)
(cider-add-to-alist 'cider-jack-in-dependencies "vlaaad/reveal" version)
(add-to-list 'cider-jack-in-nrepl-middlewares "vlaaad.reveal.nrepl/middleware"))
Make sure you either eval the above function or restart Emacs for it to take effect and then open your Clojure project file (e.g. deps.edn) and invoke M-x add-file-local-variable-prop-line RET eval RET (reveal-cider-add! "1.3.270") RET so that the function is called every time the file is opened. It will add the following magic line as a comment at the top of the file:
Jacking in from the project file should inject the reveal middleware and bring up the reveal window at REPL startup. The above command can be added to any file you usually jack in from, not just the project file.
Alternatively, you can instruct Emacs to run the function from any Clojure in the project. To do so open a file at your project root directory (e.g. deps.edn), and invoke M-x add-dir-local-variable RET clojure-mode RET eval RET (reveal-cider-add! "1.3.270") RET. This will create a .dir-locals.el file that instructs Emacs to run the cider configuration function for any file that loads clojure-mode in the project directory tree:
;;; Directory Local Variables
;;; For more information see (info "(emacs) Directory Variables")
((clojure-mode . ((eval . (reveal-cider-add! "1.3.270")))))
You might need to reopen the Clojure files for the above changes to take effect. You will be prompted if you would like to eval the function when opening the file.
There is yet a third, more intrusive way, to have cider always download and inject the reveal middleware in every jack in invocation irrespective of project file or directory, by adding the following into your emacs init file:
Hi,
the
.nrepl.edn
Nrepl-based editor integration instructions unfortunately do not work for Emacs CIDER.To reproduce
deps.edn
file:.nrepl.edn
file with reveal middleware:deps.edn
project file and jack in to the REPL withM-x cider-jack-in-clj RET
.This is because
cider
makes uses the--middleware
command line option when invoking nREPL which takes precedence over the corresponding:middleware [vlaaad.reveal.nrepl/middleware
option in.nrepl
:Settings passed via the command-line interface will take precedence over settings specified via the configuration files.
Luckily,
cider
has a couple of configuration variables that can be set to download extra dependencies and inject nREPL middlewares (cider-jack-in-dependencies
andcider-jack-in-nrepl-middlewares
respectively), that can be used to load reveal as part of the REPL upbringing process (called jack-in incider
's nomenclature).Perhaps you might want to add the following in the documentation.
To configure CIDER to download and inject revaal in the nREPL middleware list:
First add a function in your Emacs init file that configures CIDER to download and inject the given reveal version in the nREPL middleware list at jack in:
Make sure you either eval the above function or restart Emacs for it to take effect and then open your Clojure project file (e.g.
deps.edn
) and invokeM-x add-file-local-variable-prop-line RET eval RET (reveal-cider-add! "1.3.270") RET
so that the function is called every time the file is opened. It will add the following magic line as a comment at the top of the file:Jacking in from the project file should inject the reveal middleware and bring up the reveal window at REPL startup. The above command can be added to any file you usually jack in from, not just the project file.
Alternatively, you can instruct Emacs to run the function from any Clojure in the project. To do so open a file at your project root directory (e.g. deps.edn), and invoke
M-x add-dir-local-variable RET clojure-mode RET eval RET (reveal-cider-add! "1.3.270") RET
. This will create a.dir-locals.el
file that instructs Emacs to run the cider configuration function for any file that loads clojure-mode in the project directory tree:You might need to reopen the Clojure files for the above changes to take effect. You will be prompted if you would like to eval the function when opening the file.
See Specifying File Variables and Directory Local Variables in the Emacs manual for more information.
There is yet a third, more intrusive way, to have cider always download and inject the reveal middleware in every jack in invocation irrespective of project file or directory, by adding the following into your emacs init file:
I hope this is useful!
Thanks