Why Emacs for Clojure?
Clojure's development culture is deeply intertwined with the REPL (Read-Eval-Print Loop). While many editors support Clojure, Emacs with CIDER (Clojure Interactive Development Environment that Rocks) offers the most seamless, battle-tested REPL integration available. Evaluating expressions inline, inspecting values, running tests without leaving your editor — it's a genuinely different way to write code.
Prerequisites
Before setting up Emacs for Clojure, you'll need:
- Emacs 28+ — Download from gnu.org/software/emacs or via your system package manager
- Java JDK 11+ — Clojure runs on the JVM
- Clojure CLI tools — Install via the official Clojure installer at clojure.org
- Leiningen (optional) — An alternative build tool, widely used in older projects
Step 1: Set Up a Package Manager
Modern Emacs configuration uses use-package for clean, declarative package setup. Add this to your ~/.emacs.d/init.el:
;; Bootstrap straight.el or use built-in package.el
(require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
Step 2: Install CIDER
CIDER is the cornerstone of Clojure development in Emacs. Install and configure it:
(use-package cider
:ensure t
:config
(setq cider-repl-display-help-banner nil)
(setq cider-repl-pop-to-buffer-on-connect 'display-only)
(setq cider-show-error-buffer t)
(setq cider-auto-select-error-buffer t))
Step 3: Install clojure-mode
clojure-mode provides syntax highlighting and structural editing for Clojure files:
(use-package clojure-mode
:ensure t
:mode (("\\.clj\\'" . clojure-mode)
("\\.cljs\\'" . clojurescript-mode)
("\\.cljc\\'" . clojurec-mode)))
Step 4: Add Paredit or Smartparens
Working with Lisp code means working with parentheses. Paredit keeps your parentheses balanced automatically and lets you move expressions structurally:
(use-package paredit
:ensure t
:hook ((clojure-mode . paredit-mode)
(cider-repl-mode . paredit-mode)))
Once you're used to paredit's structural editing commands, editing Lisp without it feels like programming with one hand tied behind your back.
Step 5: Connect CIDER to Your Project
Open a Clojure project directory, then start a REPL session:
- Open any
.cljfile in your project - Press M-x and type
cider-jack-in(or C-c M-j) - CIDER starts a nREPL server and connects automatically
Essential CIDER Keybindings
| Keybinding | Action |
|---|---|
| C-c C-e | Evaluate expression before cursor |
| C-c C-k | Evaluate the entire buffer |
| C-c C-d C-d | Show documentation for symbol at point |
| C-c C-t C-t | Run test at point |
| C-c C-t C-n | Run all tests in namespace |
| M-. | Jump to definition |
| M-, | Jump back |
You're Ready to Develop
With this setup, you have a full interactive Clojure development environment. The real power comes from evaluating code incrementally — write a function, evaluate it, call it in the REPL, iterate. This tight feedback loop is what Lisp programmers have enjoyed for decades, and CIDER brings it fully into the modern era.