ANN: Clojure Textmate Bundle 0.1
See the code, and README here: http://github.com/nullstyle/clojure-tmbundle/tree/master
About a month or so ago, I was re-introduced to Clojure, after having dismissed it as something too smart for me to handle, through the wonderful screencasts by Clojure creator Rich Hickey. This thing rocks the casbah. Rich has done an outstanding job.
Unfortunately, there is no Clojure bundle for TextMate, my editor of choice. That is until now. After a couple days of hacking, I’ve got a version that works well enough for me.
Here’s how it works: The initial command during a session will spawn an Interactive REPL in the background using GNU Screen. As you run commands, they get evaluated in that REPL and the evaluated result is printed in a normal TextMate HTML output window. At any time, you can connect to the screen session and interact with clojure as you normally would on the Terminal.
The implementation leaves something to be desired, given Java doesn’t have nice support for unix sockets, but so far the thing seems to work fine despite the hacks to setup the communication channel (over a TCP socket).
Currently, I bundle a recent version of Clojure with the bundle itself. Unfortunately, clojure takes the typical java project stance (IME, anyway) when it comes to distribution; here’s a jar, good luck. It isn’t ideal, in my opinion, so I bundle the whole damn thing, along with the defacto standard library for clojure (clojure-contrib), jline for readline support, and jna. That means that if you have ruby and screen installed, the only thing you need to do to get started with clojure is install this bundle.
Using the bundle
You’ve got to work in a textmate project. I use the project directory as name to help establish communication with the background REPL. You should name your source files .clj. Install the textmate LISP bundle to go along with this bundle. Apple-R will evaluate an expression in the REPL, booting one up if it isn’t yet running. It will take 5 seconds or so to start the clojure process. After that, additional commands should be really quick.
- Apple-R — sends the top-level expression underneath the cursor to the REPL, printing the result
- Apple-Shift-R — sends the current file to the REPL, printing the result from each top-level expression
- Apple-Option-R — Opens either Apple Terminal or iTerm and opens the screen session for the current REPL
Contributing and Feedback
Patches, Pull requests, and notes are always welcome.