Skip to content

Instantly share code, notes, and snippets.

@auramo
Created August 6, 2015 12:35
Show Gist options
  • Select an option

  • Save auramo/b44dd089e4b5db70b6fc to your computer and use it in GitHub Desktop.

Select an option

Save auramo/b44dd089e4b5db70b6fc to your computer and use it in GitHub Desktop.

Revisions

  1. auramo created this gist Aug 6, 2015.
    70 changes: 70 additions & 0 deletions figwheel-emacs-cider.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,70 @@
    ## 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).