If you are new to Emacs, you may find the Emacs Starter Kit helpful. GNU Emacs 23 or 24 is recommended; forks like XEmacs and Aquamacs are not supported but may work.
Open or create a Clojure .clj file, and you should find that clojure-mode enabled since built-in functions and forms are syntax-highlighted.
There are multiple approaches for interacting with a live Clojure process:
- SLIME and Swank Clojure: a rich, complex mode that provides various commands to communicate with an external Clojure instance via a socket.
- inferior-lisp: a simple mode that will start a Clojure instance as a subprocess and then communicates with its REPL via stdin/stdout pipes.
In both cases, you need to launch a Clojure subprocess. This is most commonly done using a tool such as Leiningen.
SLIME and Swank Clojure
M-x clojure-jack-in once Leiningen is installed to begin a Slime session for the current project.
The most commonly-used key bindings are
C-c C-k to compile the current file,
M-. to jump to a definition, and
C-c M-p to change the namespace of the repl session.
For more key bindings and other details see the swank-clojure readme.
Automated VM Setup
If you don't mind working in a virtual machine, you can get a fully-automated VM set up with Emacs configured using Slime and Swank-Clojure using Vagrant: https://github.com/Seajure/emacs-clojure-vagrant
The simplest way to eval expressions at a Clojure REPL is to set Clojure to be your inferior-lisp program (inferior as in a subprocess, not as in worse-than) as follows:
- M-x describe-variable inferior-lisp-program
- Customize the variable to point to a command that launches a Clojure REPL. You can use an absolute path, or a relative path that will be interpreted relative to the current directory in emacs. For example:
- M-x inferior-lisp (or C-c C-z)
- Use C-x C-e at the end of an expression to evaluate it, showing the result in the inferior-lisp buffer. C-c C-l will load the current file. C-M-x can evaluate a whole def form.