README.org

Clojure layer

img/clojure.png img/cider.png

Table of Contents

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:

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 gcider grimoire
SPC m h hcider doc
SPC m h jcider javadoc
SPC m h ncider browse ns

Evaluation

Key BindingDescription
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 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)

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

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 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

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.