Skip to content

Instantly share code, notes, and snippets.

@felipebueno
Forked from auramo/figwheel-emacs-cider.txt
Created December 4, 2015 15:34
Show Gist options
  • Save felipebueno/f61562f322902d33a470 to your computer and use it in GitHub Desktop.
Save felipebueno/f61562f322902d33a470 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 . Figwheel has to be running already of course.

Some more documentation on Figwheel + NREPL in case you are having trouble.

The CIDER site.

CIDER nREPL site.

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