Skewer -- Emacs Live Browser Interaction
Inspired by Emacs Rocks! Episode 11 on swank-js, I spent the last week writing a new extension to Emacs to improve support for web development. It's called Skewer and it allows you to interact with a browser like you would an inferior Lisp process. It's written in pure Emacs Lisp, operates as a servlet for my Elisp webserver, and requires no special support from your browser or any other external programs, making it portable and very easy to set up.
The video also on YouTube.
It works a little bit like impatient-mode. First, the browser makes a long poll to Emacs. When you're ready to send code to the browser to evaluate, Emacs wraps the expression in a bit of JSON and sends it to the browser. The browser responds with the result and starts another long poll.
As such, the browser doesn't need to do anything special to support Skewer. If it can run jQuery, it can be skewered. I've tested it and found it working successfully on the latest versions of all the major browsers, including you-know-who.
What's wrong with swank-js?
The problem with swank-js is the complicated setup. It requires a
cooperating Node.js server, a particular version of SLIME, and a lot
of patience. I could never get it working, and if I did I wouldn't
want to have to do all that setup again on another computer. In
contrast, Skewer is just another Emacs package, no special setup
needed. Thanks to
package.el installing and using it should be no
more difficult than installing any other package.
Most importantly, with Skewer I can capture the setup in my .emacs.d repository where it will automatically work across any operating system, so long as it has Emacs installed.
I already used Skewer to develop a little boids toy, which I'm using to demonstrate the mode (the video). Unlike my previous experiences in web development, this was extremely enjoyable -- probably because it felt a lot like I was writing Lisp. And unlike any Lisp I've used so far, I had a canvas to draw on with my live code. That's a satisfying tool to have.
Due to those prior poor experiences, I had avoided web development for a long time. But now that I have some decent tools configured I'm going to get into it more. In fact, I've decided I'm completely done with writing Java applets. Bounze will have been my last one.
This has become a pattern for me. When I want to start using a new language or platform I need to figure out a work-flow with Emacs. This involves trying out new modes, reading about how other people do it, and, ultimately, when I found out the existing stuff is inadequate I build my own extensions to create the work-flow I desire. I did this with Java, recently with psl-mode (which was to be expected), and now web development.
Here's to splashing!