How do I setup a Clojurescript REPL with emacs?

clojure emacs
emacs/cider
clojurescript tutorial
shadow-cljs release
figwheel
learn clojurescript
shadow-cljs deps edn
paredit clojure

I'm trying to setup an environment for Clojurescript. The problem I'm having is not knowing how to set it up so that I can connect to a Clojurescript Browser REPL from emacs, so I can evaluate forms right from the editor and have it show up in the browser.

Things I've tried:

I tried using Cemerick's piggieback and piggybacking on nREPL. I don't really know how to configure it from the documentation. I was able to get it to work after figuring out I had to make an index.html file in the root of the project folder. Except the server doesn't serve my assets.

I tried setting up inferior-lisp with the bash script from the Clojurescript wiki. However, whenever I try to run the inferior-lisp-program I'm getting "Wrong type argument: stringp, nil".

Here's my ideal workflow:

I have a project folder/resources/public folder that has my assets and html files. I can start a web server that serves those files somehow, either by ring or using python's simple http server. I'd be able to connect to a REPL from emacs and evaluate forms into it.

Cemerick to the rescue again: Austin (https://github.com/cemerick/austin) is exactly what you're after.

Austin gives you two options: either a REPL where the JS is evaluated in a browser (a "project REPL"), or a more complete, integrated browser-connected REPL. It sounds like the latter is what you're after, and you need to dig a little harder for its docs: https://github.com/cemerick/austin/tree/master/browser-connected-repl-sample

To get the browser-connected REPL working, Chas's example is fairly straightforward to follow, and boils down to:

  1. Add a little middleware or template magic to append a JS script element to your HTML page, and that script needs to contain the output of (cemerick.austin.repls/browser-connected-repl-js)
  2. Start up nREPL, start up your ring server, and then (def repl-env (reset! cemerick.austin.repls/browser-repl-env (cemerick.austin/repl-env))) to create a REPL environment.
  3. Turn the nREPL session from a Clojure to a ClojureScript REPL with (cemerick.austin.repls/cljs-repl repl-env)
  4. Connect to your still-running Ring server app with a browser, and you should be connected. (.alert js/window "Hi!") should prove it.
  5. Using the standard Emacs nREPL commands will work as expected, compiling ClojureScript into JavaScript and sending it to the browser for evaluation.

The main difference between Piggieback and Austin is those first and second steps: the atom is used by the middleware to add an inline JavaScript block that connects back to the nREPL. Since the HTTP URL is determined at runtime, the Ring server and client-side JavaScript need to work in concert.

FWIW I created a function in my user namespace to speed connecting the CLJS REPL:

(defn cljs-browser-repl
  "Fire up a browser-connected ClojureScript REPL"
  []
  (let [repl-env (reset! cemerick.austin.repls/browser-repl-env
                         (cemerick.austin/repl-env))]
    (cemerick.austin.repls/cljs-repl repl-env)))

Emacs and Inferior Clojure Interaction Mode, If you are using Emacs on OS X be sure to install exec-path-from-shell so that the Node.js REPL will work correctly. If you need exec-path-from-shell make sure  (4 replies) I'm trying to setup an environment for Clojurescript. The problem I'm having is not knowing how to set it up so that I can connect to a Clojurescript Browser REPL from emacs, so I can evaluate forms right from the editor and have it show up in the browser. Things I've tried: I tried using Cemerick's piggieback and piggybacking on nREPL.

I had similar problems after following the tutorial on https://github.com/clojure/clojurescript/wiki/Quick-Start

What helped me was the last suggestion on https://groups.google.com/forum/#!topic/clojure/_JWvqc3fENQ

Replacing the meta tag in index.html with

<meta content="text/html;charset=UTF-8" http-equiv="content-type">

Emacs, Figwheel Main provides tooling for developing ClojureScript applications. Emacs can support LISP editing and REPL interaction natively, without installing You can follow the instructions on the Emacs site to download and install Emacs. Then, in emacs you can do M-x set-variable inferior-lisp-program cljs-repl Then you can do C-c C-z from a clojurescript buffer. If you're going to do this often then you can write a function that does this automatically (in your .emacs): (defun cljs-repl () (interactive) (setq inferior-lisp-program "cljs-repl") (run-lisp))

How to Use Emacs, an Excellent Clojure Editor, Figure 2-1: A typical Emacs setup for working with Clojure—code on one side, REPL on the other. To get there, you'll start by installing Emacs and setting up a  Assuming you have a recent enough (>= 0.12.0) Node.js on your system, this will spin up node in the background and drop into a REPL. There's still no DOM since we're not targeting a browser, but you should get significantly better performance, and you have access to the Node APIs, so you can do things like access the network or work with files.

ClojureScript :: CIDER Docs, :repl-options {:nrepl-middleware [cider.piggieback/wrap-cljs-repl]} need to extend it, you should use cider-register-cljs-repl-type in your Emacs configuration​. CIDER allows you to start a REPL within Emacs and provides you with key bindings that allow you to interact with the REPL more efficiently. Go ahead and start a REPL session now. Using Emacs, open the file clojure-noob/src/clojure_noob/core.clj, which you created in Chapter 1. Next, use M-x cider-jack-in. This starts the REPL and creates a new buffer where you can interact with it.

Running figwheel with Emacs Inferior Clojure Interaction Mode , Figwheel builds your ClojureScript code and hot loads it into the browser as REPL from Emacs and can skip the complexity and configuration  Assuming you already have clojure-mode, run M-x package-list-packages and install inf-clojure. If you are using Emacs on OS X be sure to install exec-path-from-shell so that the Node.js REPL will work correctly. If you need exec-path-from-shell make sure to follow the Usage instructions.

Using the Figwheel REPL within nREPL · bhauman/lein-figwheel , Integration with Emacs/CIDER. Advanced. Quick and manual setup (existing cider users). The steps above for starting cljs-repl within  If your REPL is starting to get cluttered you can M-x cider-repl-clear-buffer to clear by first switching to the REPL buffer. The ability to continually change the code and play around with it is one of the things that makes Emacs and a lisp a great combination for development.

Comments
  • I recommend github.com/magomimmo/modern-cljs. It shows you how to implement your ideal workflow including even the Python one-liner for serving your public assets. Easily one of the best cljs resources available.
  • Dear 2018 readers: Please check out Figwheel (figwheel.org), or have a look at my answer at the bottom. Having a browser-connected REPL has gotten simpler!