CIDER is a Clojure IDE for Emacs.




CIDER provides a lot of really useful utilities for working with clojure. That said, it took me a while to get comfortable. Together with clj-refactor and clojure-mode the host of configuration options and keybindings can be totally overwhelming. I'll explain my configuration and workflow below in hopes that it provides a nice starting point.

Emacs Configuration

use-package is a macro for configuring packages in emacs. Let's use it to configure clojure-mode first.

(use-package clojure-mode
  :ensure t
  :mode (("\\.clj\\'" . clojure-mode)
         ("\\.edn\\'" . clojure-mode))
  :init
  (add-hook 'clojure-mode-hook #'yas-minor-mode)         
  (add-hook 'clojure-mode-hook #'linum-mode)             
  (add-hook 'clojure-mode-hook #'subword-mode)           
  (add-hook 'clojure-mode-hook #'smartparens-mode)       
  (add-hook 'clojure-mode-hook #'rainbow-delimiters-mode)
  (add-hook 'clojure-mode-hook #'eldoc-mode)             
  (add-hook 'clojure-mode-hook #'idle-highlight-mode))
  • I always want clojure-mode installed on my system so I designate :ensure t
  • activate clojure-mode whenever I open a file with the .clj or .edn extensions
  • use :init to add hooks for minor-modes we want activated before the clojure-mode package is loaded. These are just some of the minor-modes I personally find useful when writing clojure. You'll have to ensure that these modes are installed separately.smartparens-mode and similar modes like paredit and lispy are quite useful for programming in languages with nested delimeters like Clojure.


Now let's configure CIDER:

(use-package cider
  :ensure t
  :defer t
  :init (add-hook 'cider-mode-hook #'clj-refactor-mode)
  :diminish subword-mode
  :config
  (setq nrepl-log-messages t                  
        cider-repl-display-in-current-window t
        cider-repl-use-clojure-font-lock t    
        cider-prompt-save-file-on-load 'always-save
        cider-font-lock-dynamically '(macro core function var)
        nrepl-hide-special-buffers t            
        cider-overlays-use-font-lock t)         
  (cider-repl-toggle-pretty-printing))

What's going on here?

  • ensure cider is installed
  • activate clj-refactor-mode with cider with add-hook
  • :diminish hides the subword-mode minor mode symbol from the mode-line if diminish.el is installed


The :config keyword specifies code to be executed after the package is loaded. Here we configure some of cider's variables. Each of the following settings is explained in detail in the CIDER readme too:

  • nrepl-log-messages: useful for debugging
  • cider-repl-display-in-current-window: switch to REPL in this window
  • cider-repl-use-clojure-font-lock: syntax highlighting in REPL
  • cider-prompt-save-file-on-load: just always save when loading buffer
  • cider-font-lock-dynamically: syntax highlight all namespaces
  • nrepl-hide-special-buffers: hide nrepl buffers from menu
  • cider-overlays-use-font-lock: syntax highlight evaluation overlays
  • cider-repl-toggle-pretty-printing: REPL always pretty-prints results


I'll leave you with some of the other package configurations for related modes (some referenced above). Enjoy!:

(use-package cider-eval-sexp-fu
  :defer t)

(use-package clj-refactor
  :defer t
  :ensure t
  :diminish clj-refactor-mode
  :config (cljr-add-keybindings-with-prefix "C-c C-m"))

(use-package smartparens
  :defer t
  :ensure t
  :diminish smartparens-mode
  :init
  (setq sp-override-key-bindings
        '(("C-<right>" . nil)
          ("C-<left>" . nil)
          ("C-)" . sp-forward-slurp-sexp)
          ("M-<backspace>" . nil)
          ("C-(" . sp-forward-barf-sexp)))
  :config
  (use-package smartparens-config)
  (sp-use-smartparens-bindings)
  (sp--update-override-key-bindings)
  :commands (smartparens-mode show-smartparens-mode))

Up next I'll cover a digestible subset of CIDER commands…