Clojure layer

Description

This layer adds support for Clojure language using CIDER.

Features:

Install

Layer

To use this configuration layer, add it to your ~/.spacemacs. You will need to add clojure to the existing dotspacemacs-configuration-layers list in this file.

Pretty Symbols

Pretty symbols for anonymous functions, set literals and partial, like (λ [a] (+ a 5)), ƒ(+ % 5), ∈{2 4 6} and Ƥ.

To enable this feature, add the following snippet to the dotspacemacs/user-config section of your ~/.spacemacs file:

 (setq clojure-enable-fancify-symbols t)

Or set this variable when loading the configuration layer:

 (setq-default dotspacemacs-configuration-layers
 '((clojure :variables clojure-enable-fancify-symbols t)))

CIDER and clj-refactor

Note that recent versions of CIDER automatically inject the required dependencies into your boot or leiningen configuration when you connect to the REPL. Thus, the configuration instructions below only apply to CIDER 0.10 and older. Most users should be able to just run SPC m s i to connect to the CIDER REPL and skip the rest of this section.

Quick Start with boot
(require 'boot.repl)

(swap! boot.repl/*default-dependencies* conj
      '[refactor-nrepl "1.2.0-SNAPSHOT"]
      '[cider/cider-nrepl "0.10.0-SNAPSHOT"])

(swap! boot.repl/*default-middleware* conj
      'refactor-nrepl.middleware/wrap-refactor)
  • Run SPC m s i in any of the clojure source files to connect to the CIDER REPL. Note that a build.boot file must be present in your working directory for Cider to recognize the presence of boot.
Quick Start with lein
 {:repl {:plugins [[cider/cider-nrepl "0.10.0-SNAPSHOT"]
                   [refactor-nrepl "2.0.0-SNAPSHOT"]]
         :dependencies [[alembic "0.3.2"]
                        [org.clojure/tools.nrepl "0.2.12"]]}}
  • After creating your project with lein new app <projectname> or importing an existing project, run SPC m s i in any of the clojure source files to connect to the CIDER REPL.
More details

More info regarding installation of nREPL middleware can be found here:

Usage

Cheatsheet

This layers installs the clojure-cheathseet package which embeds this useful cheatsheet into Emacs.

Type SPC m h c to display the cheatsheet then type in some terms (space separated) to narrow down the list. For example, try typing in sort map to see some functions that deal with sorting maps.

Structuraly safe editing

This layer adds support for evil-cleverparens which allows to safely edit lisp code by keeping the s-expressions balanced.

By default this mode is not activated. You can turn it on locally on the active buffer with SPC m T s (s for safe).

To turn it on automatically for all clojure buffers call the following function in your dotspacemacs/user-config function:

(spacemacs/toggle-evil-safe-lisp-structural-editing-on-register-hook-clojure-mode)

or to enable it for all supported modes:

(spacemacs/toggle-evil-safe-lisp-structural-editing-on-register-hooks)

When enabled the symbol 🆂 should be displayed in the mode-line.

Key Bindings

Working with clojure files (barfage, slurpage & more)

Spacemacs comes with a special lisp-state for working with lisp code that supports slurpage, barfage and more tools you'll likely want when working with lisp.

As this state works the same for all files, the documentation is in global DOCUMENTATION.org. In general, use SPC k to interact with the lisp-state.

Leader

Documentation

Key BindingDescription
SPC m h acider apropos
SPC m h cclojure cheatsheet
SPC m h gcider grimoire
SPC m h hcider doc
SPC m h jcider javadoc
SPC m h ncider browse ns

Evaluation

Key BindingDescription
SPC m e ;eval sexp and show result as comment
SPC m e beval buffer
SPC m e eeval last sexp
SPC m e feval function at point
SPC m e reval region
SPC m e mcider macroexpand 1
SPC m e Mcider macroexpand all
SPC m e pprint last sexp (clojure interaction mode only)
SPC m e Peval last sexp and pretty print result in separate buffer
SPC m e weval last sexp and replace with result

Goto

Key BindingDescription
SPC m g bgo back
SPC m g Cbrowse classpath
SPC m g ggoto var
SPC m g egoto error
SPC m g rgoto resource
SPC m g nbrowse namespaces
SPC m g Nbrowse all namespaces

REPL

Key BindingDescription
SPC m ,handle shortcut (cider-repl-handle-shortcut)
SPC m s bsend and eval buffer in REPL
SPC m s Bsend and eval buffer and switch to REPL in insert state
SPC m s cconnect to REPL (cider-connect) or clear repl buffer (cider-repl-clear-buffer)
SPC m s Cclear REPL (cider-find-and-clear-repl-output)
SPC m s esend and eval last sexp in REPL
SPC m s Esend and eval last sexp and switch to REPL in insert state
SPC m s fsend and eval function in REPL
SPC m s Fsend and eval function and switch to REPL in insert state
SPC m s istart REPL (cider-jack-in)
SPC m s Istart clojurescript REPL (cider-jack-in-clojurescript)
SPC m s nsend and eval ns form in REPL
SPC m s Nsend and eval ns form and switch to REPL in insert state
SPC m s qkill REPL (cider-quit)
SPC m s oswitch to other repl instance (cider-repl-switch-to-other)
SPC m s rsend and eval region in REPL
SPC m s Rsend and eval region and switch to REPL in insert state
SPC m s sswitch to REPL or jump to last file or last clj buffer from repl (cider-repl)
SPC m s xrefresh REPL
SPC m s Xrestart REPL

Tests

Key BindingDescription
SPC m t arun all tests in namespace
SPC m t rre-run test failures for namespace
SPC m t trun test at point

Toggles

Key BindingDescription
SPC m T etoggle englighten mode
SPC m T ftoggle REPL font-locking
SPC m T etoggle cider-enlighten-mode
SPC m T ptoggle REPL pretty-printing
SPC m T itoggle indentation style
SPC m T ttoggle auto test mode

Debugging

Key BindingDescription
SPC m d binstrument expression at point
SPC m d edisplay last stacktrace
SPC m d rreload namespaces
SPC m d vinspect expression at point
SPC m d iinspect expression at point
SPC m d fquery form at point
SPC m d wopen sayid workspace window
SPC m d Eone time display of value at cursor
SPC m d !reload traces and clear sayid workspace
SPC m d cclear workspace trace log
SPC m d xclear workspace traces and log
SPC m d sshow what is currently traced
SPC m d Sshow what is currently traced in current namespace
SPC m d Vset the view
SPC m d hshow sayid help (keybindings may not be accurate)
SPC m d t yrecursively trace every namespace in given dir
SPC m d t ptrace namespaces by regex
SPC m d t btrace current file's namespace
SPC m d t eenable existing trace on current function
SPC m d t Eenable existing trace on all functions
SPC m d t ddisable existing trace on current function
SPC m d t Ddisable existing trace on all functions
SPC m d t ncreate inner trace on function
SPC m d t ocreate outer trace on function
SPC m d t rremove trace on function
SPC m d t Kremove all traces

Refactoring

Key BindingDescription
SPC m r ?describe refactoring
SPC m r a dadd declaration
SPC m r a iadd import to ns
SPC m r a madd missing libspec
SPC m r a padd project dependency
SPC m r a radd require to ns
SPC m r a uadd use to ns
SPC m r c (convert coll to list
SPC m r c 'convert coll to quoted list
SPC m r c {convert coll to map
SPC m r c #convert coll to set
SPC m r c [convert coll to vector
SPC m r c :toggle between keyword and string
SPC m r c icycle if
SPC m r c nclean ns
SPC m r c pcycle privacy
SPC m r d kdestructure keys
SPC m r e cextract constant
SPC m r e dextract definition
SPC m r e fextract function
SPC m r e lexpand let
SPC m r f ufind usages
SPC m r f ecreate fn from example
SPC m r h dhotload dependency
SPC m r i lintroduce let
SPC m r i sinline symbol
SPC m r m fmove form
SPC m r m lmove to let
SPC m r p cproject clean
SPC m r p fpromote function
SPC m r r dremove debug fns
SPC m r r frename file
SPC m r r lremove let
SPC m r r rremove unused requires
SPC m r r srename symbol
SPC m r r ureplace use
SPC m r s nsort ns
SPC m r s psort project dependencies
SPC m r s rstop referring
SPC m r s cshow changelog
SPC m r t fthread first all
SPC m r t hthread
SPC m r t lthread last all
SPC m r u aunwind all
SPC m r u pupdate project dependencies
SPC m r u wunwind

Reformatting

Key BindingDescription
SPC m f lrealign current form
SPC m f b or SPC m =reformat current buffer

CIDER Buffers

In general, q should always quit the popped up buffer.

stacktrace-mode

Key BindingDescription
C-jnext cause
C-kprevious cause
TABcycle current cause
0cycle all causes
1cycle cause 1
2cycle cause 2
3cycle cause 3
4cycle cause 4
5cycle cause 5
atoggle all
ctoggle clj
dtoggle duplicates
Jtoggle java
rtoggle repl
Ttoggle tooling

inspector-mode

Key BindingDescription
TABnext inspectable object
Shift-TABprevious inspectable object
RETinspect object
Lpop to the parent object
nnext page in paginated view
Nprevious page in paginated view
rrefresh
sset a new page size

test-report-mode

Key BindingDescription
C-jnext result
C-kprevious result
RETjump to test
dediff test result
eshow stacktrace
rrerun failed tests
trun test
Trun tests

Sayid Buffers

sayid-mode

Key BindingDescription
enterpop to function
ddef value to $s/*
fquery for calls to function
Fquery to calls to function with modifier
ishow only this instance
Ishow only this instance with modifier
wshow full workspace trace
njump to next call
Njump to previous call
Ppretty print value
Cclear workspace trace log
L or Backspaceprevious buffer state
Shift-Backspaceforward buffer state
egenerate instance expression and put in kill ring
Hdisplay help (keybindings may not be accurate)
C-s vtoggle view
C-s Vset view

sayid-traced-mode

Key BindingDescription
enterdrill into ns at point
eenable trace
ddisable trace
Eenable all traces
Ddisable all traces
iapply inner trace to function at point
oapply outer trace to function at point
rremove trace at point
backspacego back to trace overview
hdisplay help (keybindings may not be accurate)

sayid-pprint

Key BindingDescription
entershow path in minibuffer
ienter child node
oenter parent node
nenter next sibling node
penter previous sibling node

cider-repl-mode

Key BindingDescription
C-jnext input
C-kprevious input

Development Notes

Indentation

With a new functionality of Cider to read the custom indentation rules from the var's metadata, it is better for consistency reasons to not add the custom indentation rules to Spacemacs, but to add them to the metadata of those specific vars.