Emacs, Clojure and Windows

How to: Latest Clojure in Windows Vista (and others) with EmacsW32

Plan A:

  1. Download EmacsW32 and install it from: http://ourcomments.org/cgi-bin/emacsw32-dl-latest.pl. You need to set HOME environment variable to point to your home directory. Note: the path is case sensitive! Otherwise Emacs will write all its stuff into users AppData directory.

  2. Install ELPA, copy the following to *scratch* buffer in Emacs:
    (let ((buffer (url-retrieve-synchronously
    (set-buffer buffer)
    (goto-char (point-min))
    (re-search-forward "^$" nil 'move)
    (eval-region (point) (point-max))
    (kill-buffer (current-buffer))))
    Place cursor right at the end of the last parentheses and press CTRL-j, which will run the code.

  3. M-x means press ALT-x in Emacs, write the text after it, and press enter. Tab completion works. Try package- to find out different commands.
    M-x package-install
    clojure-mode (press enter)

  4. At this point you need to install Git. Best way to do this in Windows Vista seems to be msysgit at this point. One could also install Git through Cygwin, but installing Cygwin just for Git seems a bit too much work.
    msysgit is found here: http://code.google.com/p/msysgit/downloads/list. Use the full installer.
    Personally I don't click Windows integration on, because it throws crap into my context menu, which is supremely annoying.

  5. Download and install Apache Ant. Set it into your path. This includes downloading and extracting the archive, setting ANT_HOME to Ant root, Ant bin directory into PATH, and JAVA_HOME pointing to JDK root (if you haven't already).

  6. M-x clojure-install. This will take a while as it downloads everything required from Git repositories and compiles them. I used c:/code/clj as my Clojure installation root.

  7. Add (clojure-slime-config "PATH") to your .emacs config file, where PATH is the path to your Clojure installation, which you specified during M-x clojure-install.

  8. Optionally you can M-x package-install paredit for some additional lispy goodness.

  9. Read up some documentation on Emacs, SLIME and Clojure. Happy hacking!

The installation might still have some warts which can be fixed by editing .emacs. Add the following to the end:
(clojure-slime-config "c:/code/clj")
(add-hook 'slime-connected-hook (lambda () (require 'clojure-mode)))

I don't like the toolbar so (tool-bar-mode -1) removes that.

Additionally, you might want to include additional libraries into Java classpath, which can be done by writing the following into .emacs configuration file, before package-initialize:
(setq swank-clojure-extra-classpaths (list "c:/code/java/libs/swt/swt.jar" "c:/more/java/libs/foo.jar"))

Plan B: Install Clojure Box, which uses Clojure 1.0.0