My Clojure Emacs Setup (I'll show mine if you show yours)
Friday, December 5, 2008
When I first started experimenting with
Clojure a couple of months ago, I posted a
setup summary on my blog. However, Clojure has been going through
a period of change and some of the setup steps that I listed in that
post are no longer ones that I use. Also, as I use Clojure more, I
adapt my Emacs setup to reflect that. So, I thought it was worthwhile
to document what my setup looks like at the moment (hopefully,
starting a mini-meme that others
will emulate on their blogs - it's always nice to see how others setup their
development environment). The
relevant directories/files in my home directory are illustrated
here:

The green directories/files are Clojure code only, the blue
directories/files are Emacs Lisp files related to my Clojure
setup, and the yellow files are bash commands related to my Clojure
setup:
- ~/bin: This directory contains my own custom
commands. In it, I have two bash scripts related to Clojure:
- clj-build: A script that I use for regularly refreshing Clojure, clojure-contribs (a commonly used library of Clojure extensions), clojure-mode (to provide basic Clojure editing support in Emacs), slime (to provide advanced Lisp editing/interaction support in Emacs), and swank-clojure (which adds Clojure-specific support to slime). Since major Clojure changes can "break" some functionality in these other packages, it is almost always a good idea to update everything at once. I typically wait for a few days after a major upgrade to Clojure before I do a refresh as this gives the people who support the other libraries time to "catch up" to the new Clojure. The command downloads and builds the latest developer releases of everything after first deleting the existing ones (Note: I know I could have just updated; however, for these packages, I prefer to just nuke everything and start over).
- clj-cmd: This is a "stub" command to call Clojure. The actual command (with appropriate class path and other Java settings) is defined in my .emacs file.
- ~/lisp: I use multiple Lisp implementations, so I store
all my Lisp-related stuff under this directory.
- ~/lisp/docs/java: The Java javadoc documentation directory (accessed by the "slime-browse-local-javadoc" function in my .emacs file).
- ~/lisp/clj: The directory where I store everything
related to Clojure.
- ~/lisp/clj/clojure: The actual Clojure install directory.
- ~/lisp/clj/clojure-contrib: The directory containing a commonly used library of Clojure extensions.
- ~/lisp/clj/clojure-mode: An Emacs Lisp library that provides basic Clojure editing support in Emacs.
- ~/lisp/clj/swank-clojure: An Emacs Lisp library that provides Clojure-specific support to slime.
- ~/lisp/clj/slime: An Emacs Lisp library that provides advanced Lisp
editing/interaction support in Emacs.
- ~/lisp/clj/slime/contrib: An Emacs Lisp library that provides certain "optional" slime functionality.
- ~/lisp/clj/src: A directory where I store my own Clojure source code as well as code/packages from other Clojure developers.
- ~/.clojure: I have a user.clj file that contains any Clojure code that I want executed on startup. Currently, this file just has the Java documentation functionality that I've covered in a previous post and some "convenience" functions.
- ~/.emacs: The Clojure setup in my .emacs file is pretty basic. Essentially, all I do is setup things for slime/swank, add a few "convenience" functions for accessing Java documentation when I'm programming in Clojure, and add some shortcut keys. One thing to note is that I set the Clojure binary command for swank by defining an environmental variable that is also used by the "clj-cmd" bash file. This gives me the flexibility to add or comment out different Clojure startup options in the .emacs file and just re-evaluate the "setenv" statement before starting the Clojure REPL (this is nice if you're playing around a lot with different Java packages in your classpath or different JVM startup options).
Update-2009-01-04: There were some "breaking" changes made to SLIME around December 23, 2008 (the SLIME REPL was moved out into the "contribs" directory and is treated as an optional module by SLIME). I have updated my .emacs startup to reflect the necessary startup changes. There are also a few additional customizations that are included as well since I'm now using paredit with Clojure/SLIME too. In addition, some things that I originally had in my user.clj file have now become part of clojure-contrib so have been removed. One additional change that I've made is that I've moved the Javadoc documentation directory from ~/lisp/clj/java to ~/lisp/docs/java.

