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:
(cemerick.austin.repls/browser-connected-repl-js)
(def repl-env (reset! cemerick.austin.repls/browser-repl-env (cemerick.austin/repl-env)))
(cemerick.austin.repls/cljs-repl repl-env)
(.alert js/window "Hi!")
should prove it.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)))