Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dogenpunk/3ed05f61976c70b604166a2264f01277 to your computer and use it in GitHub Desktop.
Save dogenpunk/3ed05f61976c70b604166a2264f01277 to your computer and use it in GitHub Desktop.
Setup dynamic Clojurescript and Quil environment with emacs and figwheel

My environment

  • emacs 26.1
  • cider 0.17.0
  • leiningen 2.8.1 on Java 1.8.0_05
  • ~/.lein/profiles.clj : {:user {:plugins []}}

Project setup

In a terminal, run these commands:

lein new quil-cljs minimal-quil
cd minimal-quil
lein figwheel
  • When figwheel is ready to connect, open a browser on http://localhost:3449
  • You should see a circle following a circular trajectory while changing its colour

simple emacs cider-connect (no cljs repl)

  • M-x find-file : .../minimal-quil/src/minimal_quil/core.cljs

  • M-x cider-connect

    • host: localhost
    • port for host: 3449
  • Minibuffer should display message: "[nREPL] Direct connection to localhost:3449 established"

  • Now change something in the core.cljs file (e.g. change q/ellipse to q/rect)

  • M-x save-buffer

  • You should see the ellipse change into a rectangle in the browser

more advanced cider-jack-in-cljs

  • M-x find-file : .../minimal-quil/project.clj
  • add these dev dependencies:
...
  :profiles {:dev {:dependencies [[cider/piggieback "0.3.10"]
                                  [figwheel-sidecar "0.5.16"]]
                   :source-paths ["cljs_src"]
                   :repl-options {:nrepl-middleware [cider.piggieback/wrap-cljs-repl]}}}
...
  • M-x find-file : .../minimal-quil/src/minimal_quil/core.cljs

  • M-x cider-jack-in-cljs

    • select ClojureScript REPL type: figwheel
  • When lein figwheel is ready to connect, open a browser on http://localhost:3449

  • The *cider-repl minimal-quil(cljs)* buffer should display a cljs.user> prompt

  • Try (+ 2 3) ; it will compile the cljs to javascript, execute it in your browser and return the result in your repl

  • Try (js/alert "Hello World!") in the repl

  • M-x find-file : .../minimal-quil/src/minimal_quil/core.cljs

  • (+ 2 3) M-x cider-eval-defun-at-point

  • You now have the dynamic environment you're used to when developing clojure in emacs

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