CIDER is the Clojure IDE and REPL for Emacs. It is built on top of nREPL, the Clojure networked REPL server and replaces the direct use of nREPL in Emacs.
In this article we are using CIDER that is packaged in Emacs Live, a very complete, well organised and extensible configuration for Clojure and many other things in Emacs.
CIDER includes the standard interactive code evaluation developers are used to. There are also many other features that I want to explore further, including error and warning highlighting, human-friendly stacktraces, smart code completion, definition & documentation lookup, value inspector & function tracing, interactive macroexpansion, Grimoire integration,
clojure.test integration, classpath browser, namespace browser, nREPL session management, scratchpad, minibuffer code evaluation, integration with company-mode and auto-complete-mode
CIDER is now the default in the latest version of Emacs Live, so there no set up to do if you already have the latest version. If you need to update, or are not sure you are on the latest version of Emacs live, simply run a git pull from within
git pull origin master
If you dont have Emacs Live, you can install it from the Emacs Live Github repository and either clone the repository into
~/.emacs.d (moving or deleting any existing directory) or preferably use the install script that also sets up a
~/.live-packs extension directory.
You can find the available versions of the cider-nrepl plugin on Clojars.org. The plugin version should be the same version of CIDER you are using in your Emacs configuration, which at the time of writing was 0.8.1.
Either create a new Clojure project using
lein new my-project-name or open an existing project in Emacs (either the
project.clj file or a
.clj file from
With your cursor in the Clojure file buffer, run CIDER using the keybinding
C-c M-j or the emacs command
Alternatively, you could run a REPL using
lein replon the command line and connect to that REPL using
M-x cider. You will be prompted for the connection details of the running repl, ie. host, port.
There are a number of Cider keyboard shortcuts (keybindings) already defined, here are some of the most common ones I use:
C-c C-e- evaluates the form immediately before the cursor and shows the result in the minibuffer. So place your cursor right after the closing parentheses
)of your expression, hit the keybinding and see the minibuffer for the result.
C-c M-e- the same as above except the result is sent to the REPL
C-c C-k- evaluate the whole buffer. So with the cursor in a Clojure source file, all the forms / expressions are evaluate as if the code was loaded in from scratch.
C-c C-d d- show the documentaion as you would with
(doc function-name). Place the cursor over a function name, hit the keybinding and see the documenation for that funtion. This also works inside the REPL buffer, so no need to use
(doc), which is not loaded by default.
C-c M-n- switch to namespace of current Clojure buffer. So with the cursor in a Clojure source file, hit the keybinding and your REPL buffer will now be in the namespace for that Clojure code.
Changing into a namespace does not automatically evaluate the code in that namespace, so evaluate the whole buffer
C-c C-kor evaluate specific expressions (forms)
C-c M-e. Once evaluated, you can evaluate that code in the REPL.
M-x cider-jump-to-varprompts you for a var, a function
(defn)or symbol name
(def)and moves the cursor to its definition. If the cusor is already on a matching name the the cursor jumps straight to that definition.
M-x cider-quit- close the REPL and its associated buffer.
There are many more things you can do within Clojure files and the REPL, so take a look at the Cider keyboard shortcuts (keybindings) once you have the basics mastered.
Some further reading around CIDER:
- Cider keyboard shortcuts (keybindings)
Clojure on Emacs - A CIDER workflow hack - Kris Jenkins
Have fun and be productive with CIDER, Emacs and Clojure. If you have any other suggestions on getting them most out of these tools, please let me know.
This work is licensed under a Creative Commons Attribution 4.0 ShareAlike License, including custom images & stylesheets. Permissions beyond the scope of this license may be available at @jr0cket