project.clj should have this line:
:figwheel { :nrepl-port 7888 }
At the defproject-level.
It enables external tools to connect to the Figwheel REPL. To connect Emacs CIDER mode to the Figwheel REPL, do the following steps.
Clojure-mode should be pretty much from the same time period than CIDER. For example these versions from Emacs package manager (source: melpa) did the trick:
- cider 20150531.252
- clojure-mode 20150517.6
Let's install plugins locally to:
~.lein/profiles.clj
The contents should look like this:
{:user {:plugins [[cider/cider-nrepl "0.9.0-SNAPSHOT"]]
:dependencies [[org.clojure/tools.nrepl "0.2.7"]]}}
- Start figwheel like in the previous section, e.g.
rlwrap lein figwheel [build id if you use such things]
- Start your main app which connects to lein figwheel via websocket
- Run M-x
cider-connect
in Emacs. It asks for host (localhost) and port (7888) - In the prompt you get after the jack-in, run these commands:
(use 'figwheel-sidecar.repl-api)
(cljs-repl)
After those steps you should have the same REPL available inside Emacs than you did in shell in the previous section. But you'll have all the CIDER Clojure goodness available instead of just dumb command-line.
To make things easier, you can also add these to your .emacs or emacs.d/init.el:
(add-hook 'cider-connected-hook '(lambda ()
(cider-interactive-eval
"(use 'figwheel-sidecar.repl-api)\n(cljs-repl)\n")))
(defun figwheel-connect ()
(interactive)
(cider-connect "localhost" "7888"))
After that, all you have to do in emacs is M-x figwheel-connect and press . Figwheel has to be running already of course.
Some more documentation on Figwheel + NREPL in case you are having trouble.