This episode is for subscribers only. Sign Up or Log in to watch it.

14. Using Figwheel With Emacs, part 1: inf-clojure-mode

Published 16 August 16

Learn how to integrate Figwheel’s browser connected REPL into Emacs, for an ever greater degree of interactive development, using inf-clojure-mode.

Show notes

Figwheel is one of the greatest tools available for ClojureScript. It provides hot code reloading, so every time you save a ClojureScript file, your browser is updated live. It does the same for CSS, and also provides a browser connected REPL, so you can interact with your running application.

I’ll set up a basic project skeleton, containing a single ClojureScript source file, a resources directory for things like HTML and CSS, which will also contain the compiled ClojureScript, and a project.clj for Leiningen.

The easiest way to use Figwheel is through its Leiningen plugin. Add it to project.clj, and also configure a single ClojureScript build with the figwheel: true flag set. This config compiles each ClojureScript file under src to a JavaScript file under resources/public/js/out. The entry point for the browser will be js/figmacs.js.

(defproject figmacs "0.1.0"
  :dependencies [[org.clojure/clojure "1.9.0-alpha10"]
                 [org.clojure/clojurescript "1.9.89"]]

  :plugins [[lein-figwheel "0.5.4-7"]]

  :cljsbuild {:builds
              [{:id "figmacs"
                :source-paths ["src/"]
                :figwheel true
                :compiler {:main "figmacs.core"
                           :asset-path "js/out"
                           :output-to "resources/public/js/figmacs.js"
                           :output-dir "resources/public/js/out"}}]})

It’s possible to integrate the Figwheel REPL with Emacs, which gives you the type of interactive development that LISP and Emacs developers are used to. There’s a couple ways to go about it though, so I want to dig into this a bit.

We configured our ClojureScript build to use figmacs.core as main namespace, so let’s create that. I’ll enable console print, and then print something to the console so we see it’s working.

(ns figmacs.core)


(println "Figwheel is live!")

Inferior LISP

Emacs Manual: External Lisp


GitHub: clojure-emacs/inf-clojure

If you don’t have MELPA set up yet something like this should do the trick

   '("melpa" . "")
   t) ;; append MELPA to the list of package sources

(package-initialize) ;; initialize the package system

(unless (file-exists-p "~/.emacs.d/elpa/archives/melpa")
  (package-refresh-contents)) ;; fetch the list of packages

(package-install 'inf-clojure)

Keybindings (inf-clojure-minor-mode). All the “eval” commands take an optional prefix argument which makes them switch to the REPL buffer.