Clojure mode in Emacs

Filed under: clojure emacs 

You learn something new every day, and today was no different for me.

First off, it turns out Emacs has a package management system (at least since 22). It's called ELPA and it makes it much easier to install Emacs extensions. This is the feature we'll use to install clojure-mode.

First, get ELPA installed: copy and paste the following elisp code from the ELPA site into your *scratch* buffer:

(let ((buffer (url-retrieve-synchronously
              "http://tromey.com/elpa/package-install.el")))
 (save-excursion
   (set-buffer buffer)
   (goto-char (point-min))
   (re-search-forward "^$" nil 'move)
   (eval-region (point) (point-max))
   (kill-buffer (current-buffer))))

Next, eval this code by putting your cursor after the last parentheses and pressing Control+j (C-j). This will install ELPA and create a default ~/.emacs file for you.

Next, we tell the ELPA package to download and install clojure-mode. In emacs, press M-x package-install (Alt+x package-install) and enter clojure-mode when prompted. This will download the package and install it for you so that it's automatically loaded when emacs starts.

That's it! Now whenever you load a .clj file, emacs will switch to clojure-mode.



0 comments Leave a comment