Skip to content

Instantly share code, notes, and snippets.

@auramo
Created August 6, 2015 12:35
Show Gist options
  • Save auramo/b44dd089e4b5db70b6fc to your computer and use it in GitHub Desktop.
Save auramo/b44dd089e4b5db70b6fc to your computer and use it in GitHub Desktop.
figwheel emacs cider stuff
## Using Emacs CIDER as the Figwheel REPL tool
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.
### 1. Install CIDER and Clojure mode.
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
### 2. Set up leiningen plugins
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"]]}}
```
### 3. The startup sequence
1. Start figwheel like in the previous section, e.g. `rlwrap lein figwheel [build id if you use such things]`
2. Start your main app which connects to lein figwheel via websocket
3. Run M-x `cider-connect` in Emacs. It asks for host (localhost) and port (7888)
4. 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
<enter>. Figwheel has to be running already of course.
[Some more documentation on Figwheel + NREPL](https://github.com/bhauman/lein-figwheel/wiki/Using-the-Figwheel-REPL-within-NRepl) in case you are having trouble.
[The CIDER site](https://github.com/clojure-emacs/cider).
[CIDER nREPL site](https://github.com/clojure-emacs/cider-nrepl).
@jinwei233
Copy link

thanks for your guide!

@edvorg
Copy link

edvorg commented Sep 20, 2015

thank you. it helpful!

@crocket
Copy link

crocket commented Dec 27, 2015

I have an easier set of instruction on https://github.com/crocket/nrepl-figwheel-node-template

@zilongshanren
Copy link

it seems not working with the latest figwheel

@laheadle
Copy link

I still get:
user-error: cider-eval-last-sexp' needs a ClojureScript REPL. If you don't know what that means, you probably need to jack-in (C-c M-J').

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment