Emacs support for the Clojure language
Pull request Compare This branch is 705 commits behind clojure-emacs:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Clojure Mode

Provides Emacs font-lock, indentation, and navigation for the Clojure programming language.

A more thorough walkthrough is available at clojure-doc.org


Available on both Marmalade and MELPA repos.

Marmalade is recommended as it has the latest stable version, but MELPA has a development snapshot for users who don't mind breakage but don't want to run from a git checkout.

If you're not already using Marmalade, add this to your ~/.emacs.d/init.el and load it with M-x eval-buffer.

(require 'package)
(add-to-list 'package-archives
             '("marmalade" . "http://marmalade-repo.org/packages/"))

If you're feeling adventurous and you'd like to use MELPA add this bit of code instead:

(require 'package)
(add-to-list 'package-archives
             '("melpa" . "http://melpa.milkbox.net/packages/") t)

And then you can install:

M-x package-refresh-contents

M-x package-install [RET] clojure-mode [RET]

or if you'd rather keep it in your dotfiles:

(unless (package-installed-p 'clojure-mode)
  (package-install 'clojure-mode))

On Emacs 23 you will need to get package.el yourself or install manually by placing clojure-mode.el on your load-path and requireing it.

Clojure Test Mode

This source repository also includes clojure-test-mode.el, which provides support for running Clojure tests (using the clojure.test framework) via nrepl.el and seeing feedback in the test buffer about which tests failed or errored. The installation instructions above should work for clojure-test-mode as well.

Once you have a repl session active, you can run the tests in the current buffer with C-c C-,. Failing tests and errors will be highlighted using overlays. To clear the overlays, use C-c k.

You can jump between implementation and test files with C-c C-t if your project is laid out in a way that clojure-test-mode expects. Your project root should have a src/ directory containing files that correspond to their namespace. It should also have a test/ directory containing files that correspond to their namespace, and the test namespaces should mirror the implementation namespaces with the addition of "-test" as the suffix to the last segment of the namespace.

So my.project.frob would be found in src/my/project/frob.clj and its tests would be in test/my/project/frob_test.clj in the my.project.frob-test namespace.


Using clojure-mode with Paredit is highly recommended. It helps ensure the structure of your forms is not compromised and offers a number of operations that work on code structure at a higher level than just characters and words.

It is also available using package.el from the above archives.

Use Paredit as you normally would any other minor mode; for instance:

;; (require 'paredit) if you didn't install it via package.el
(add-hook 'clojure-mode-hook 'paredit-mode)

See the cheat sheet for Paredit usage hints.

REPL Interaction

A number of options exist for connecting to a running Clojure process and evaluating code interactively.

Basic REPL

Use M-x run-lisp to open a simple REPL subprocess using Leiningen. Once that has opened, you can use C-c C-r to evaluate the region or C-c C-l to load the whole file.

If you don't use Leiningen, you can set inferior-lisp-program to a different REPL command.


You can also use Leiningen to start an enhanced REPL via nrepl.el.


Another option is Ritz, which is a bit more complicated but offers advanced debugging functionality using SLIME.

Swank Clojure

SLIME is available via swank-clojure in clojure-mode 1.x. SLIME support was removed in version 2.x in favor of nrepl.el.


Copyright © 2007-2013 Jeffrey Chu, Lennart Staflin, Phil Hagelberg, and contributors.

Distributed under the GNU General Public License; type C-h C-c to view it.