HN2new | past | comments | ask | show | jobs | submitlogin

I spent the weekend playing with ClojureScript One, and this line really stood out for me:

"Moreover, JS is really fast to write and test. Write – save – refresh[2]; it’s an absurdly fast dev cycle that lets me iterate on questionable portions of the code much faster than any environment I’ve worked in."

With ClojureScript and Emacs, this cycle is replaced with "write - C-x C-e" (For the unfamiliar, Ctrl-x Ctrl-e sends the Lisp form immediately before the cursor to the compiler, and sends the resulting JavaScript to the browser for execution. It lets you evaluate bits of code directly from your editing buffer. It's the classic Lisp and Emacs set up and it's fantastic.)

Is there no browser-connected REPL for regular-ole JavaScript? I don't know the details of the ClojureScript implementation, but I would imagine you could hack it up to use plain JS. I'm sure I sound like a smug Lisp weenie, but actually I'm just hoping that this does exist in case I ever have to use regular JS.

edit I found something call mozrepl but this seems specific to Firefox. https://github.com/bard/mozrepl/wiki/Emacs-integration



Yep, here it is: https://github.com/swank-js/swank-js

It works really, really well. In fact, it's using exactly the same protocol and Emacs libraries that ClojureScript uses (SLIME). It's really neat to see SLIME still being used today for such cool and practical things.


Oh, that's very cool, I didn't think to search for "swank". Thanks!


I rely on LiveReload (http://livereload.com/) for my day-to-day web dev work. Point it at a repo folder and a browser window, and any time any files are changed in the repo it'll intelligently update the browser window (full page refresh for HTML/JS changes, partial refresh for CSS-only changes). It can also be configured to auto-compile SASS/LESS/CoffeeScript/etc, and/or execute arbitrary shell commands on save. The Mac version costs $10 (haven't tried the Windows port yet), but it's unbelievably fantastic.


I have been hacking on ClojureScript recently as well (spent the weekend playing with ClojureScript One also!), but I am not an Emacs user (I use Vim). Can you explain the part about sending JavaScript to the browser without refresh from a normal repl (lein repl)? I see this advertised by ClojureScript but not an explanation as to how it works (probably assuming experienced lispers). My method for working has been save, ctrl+tab to browser, ctrl+f5 to refresh.


Honestly, this can actually be a PITA to set up for vanilla ClojureScript apps because the order of steps is very important, and one of the rad things about ClojureScript One for beginners (myself included) is that it's seems much easier to get working, so if you're not an Emacs user to begin with, I would clone ClojureScript One and follow along to try it out. There are some nice scripts and Clojure code meant for dev-time that come with it that smooth out the edges a bit.

But in general, you have to set up your inferior-lisp-program in Emacs with the shell script desribed here: https://github.com/clojure/clojurescript/wiki/Emacs-%26-infe... (for ClojureScript One, it suffices to use "lein repl" as your inf-lisp.)

Then you need to (:require [clojure.browser.repl :as repl) in your ns, and run (repl/repl "http://localhost:9000 ") (there's a space here to prevent HN from swallowing the close-quote, but it shouldn't be there) at the beginning of your ClojureScript app.

Start the REPL in Emacs (M-x inferior-lisp RET, ie press Alt-x, type "inferior-lisp", hit return) and then open the browser and point it at your app. Test it by typing (js/alert) in Emacs. Then, when you're in a ClojureScript buffer (or any Lisp buffer, I think) C-x C-e will send the form before the point to the REPL, which is actually connected to the browser.

I'll leave setting it up for Vim as an exercise for the reader (kidding, kind of, I just don't have any idea if any one has worked on this yet, although there are Vim modes for regular Clojure, so maybe)


Oops, this is wrong: (repl/repl "http://localhost:9000 ") Should be (repl/connect "http://localhost:9000/repl ")

I also kind of misread MatthewPhillips post and thought he was looking for Emacs instructions. For sending code to the browser from a normal REPL, (started with `lein repl`) I think a good place to start is these two files from Cljs One:

https://github.com/brentonashworth/one/blob/master/src/app/c...

https://github.com/brentonashworth/one/blob/master/src/lib/c...

Together they should help in setting this up for a vanilla Cljs project, or require them in your fork of Cljs One and start a REPL.


I use Vim and did get something similar setup for ClojureScript. I used a lein repl running in Gnu Screen and sent clojurescript from Vim to the browser based repl using vim-slime https://github.com/jpalardy/vim-slime. It worked very well.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: