Today I finally got round to trying out something i’d been meaning to look into for nearly a year, and seeing as clojure and editors seems to be a topic again I thought it would help add some diversity.
Acme is an editor unlike any other. It was designed by Rob Pike for Plan9 (although it’s available for unix-like systems using Plan9 from User Space). It’s designed to be an editor and shell. Unlike emacs and vim which encourage you to keep your hands on the keyboard, acme requires use of a 3-button mouse, and it supports something called mouse chording. A rough guide would be:
- Button 1: Select Text
- Button 2: Execute Command
- Button 3: Search/ acquire text (or load file)
- Button 1-2 Cutting
- Button 1-3 Pasting
- Button 1-2,3 Cut+Paste (Copy)
My introduction to acme was via Russ Cox’ video, which is a great starting point:
You can probably summarise the whole thing by saying that in acme – text is data. Once you type some text, it can be saved into a file, executed as a command or passed as an argument to a command.
Obviously this resonated with the clojure part of my brain. It occured to me that being able to select some clojure code in acme and evaluate it would make acme a great editor for clojure.
Thanks to nrepl the job is really quite easy. I wrote a very very simple nrepl client in go. You can find it on my github
All it does is read clojure code from stdin and send it to nrepl. This is really all there is to do. In acme you just need to type your command in one of the scratch areas:
Take a look at the below screenshot. You can see:
- In yellow: selected clojure code with mouse button 1
- In red: selected command with mouse button two
- Release the buttons and the window in the bottom right contains the evalutated code
Here’s a video of me doing it:
Clojure in Acme from Matthew Williams on Vimeo.
To get this setup yourself:
- Install plan9 from user space to get acme
- run lein repl in some terminal
- You’ll need a command line tool that can take clojure code on stdin and send it to nrepl. I used my own gonrepl tool- To use that you need to install go then run:
That’s it. Thanks for reading!