spacemacs/layers/+lang/clojure
syl20bnr 82fdd9a511 Use evil in holy-mode
Motivation

While disabling Evil in holy-mode makes its implementation shorter and
sounds elegant on the paper, in practice it puts a big burden on the
configuration parts which need to know if Evil is enable or not. This is
a bad separation of concerns and the bunch of fixes that we were forced
to do in the past weeks shows this issue. Those fixes were about
removing the knowledge of the activation of Evil by implementing new
dispatching functions to be used by layers, this is cumbersome and makes
Spacemacs layer configuration more subtle which is not good. There was
additional bad consequences of the removal of Evil state like the
impossibility to use Evil lisp state or iedit states, or we would have
been forced to implement a temporary activation of Evil which is
awkward.

Instead I reintroduce Evil as the central piece of Spacemacs design thus
Evil is now re-enabled in holy-mode. It provides the abstraction we need
to isolate editing styles and be able to grow the Spacemacs
configuration coverage sanely. Layers don't need to check whether the
holy mode is active or not and they don't need to know if Evil is
available (it is always available). We also don't need to write
additional dispatching functions, this is the job of Evil, and I think
it provides everything for this. Ideally configuration layer should be
implemented with only Evil in mind and the holy-mode (and hybrid-mode)
should magically make it work for Emacs style users, for instance we can
freely use `evil-insert-state` anywhere in the code without any guard.

Evil is now even more part of Spacemacs, we can really say that
Spacemacs is Emacs+Evil which is now an indivisible pair. Spacemacs
needed this stable API to continue on the right track.

While these changes should be rather transparent to the user, I'm sorry
for this experimental period, I failed to see all the implications of
such a change, I was just excited about the possibility to make Evil
optional. The reality is that Spacemacs has to embrace it and keep its
strong position on being Emacs+Evil at the core.

Implementation

- insert, motion and normal states are forced to emacs state using an
advice on `evil-insert-state`, `evil-motion-state` and
`evil-normal-state` respectively. These functions can be used freely in
the layer configuration.
- A new general hook `spacemacs-editing-style-hook` allow to hook any
code that need to be configured based on the editing style. Functions
hooked to this hook takes the current style as parameter, this
basically generalize the hook used to setup hjkl navigation bindings.
- ESC has been removed from the emacs state map.
- Revert unneeded changes
  - Revert "evil: enter insert-state only from normal-state"
    commit bdd702dfbe.
  - Revert "avoid being evil in deft with emacs editing style"
    commit f3a16f49ed.

Additional changes

All editing style packages have been moved to a layer called
`spacemacs-editing-styles`

Notes

I did not have time to attack hybrid mode, I should be able to do it
later.
2016-03-13 21:16:55 -04:00
..
img Use + instead of ! for layer categories 2015-09-11 00:13:51 -04:00
config.el Clean copyrights and update for year 2016 2016-01-11 21:42:17 -05:00
funcs.el Clean copyrights and update for year 2016 2016-01-11 21:42:17 -05:00
packages.el Use evil in holy-mode 2016-03-13 21:16:55 -04:00
README.org add 'cider-apropos functionalty to clojure layer 2016-02-25 20:31:31 +01:00

Clojure layer

/TakeV/spacemacs/media/commit/130cd48d0386d1c8a110ad4c341c34989baf6bf9/layers/+lang/clojure/img/clojure.png /TakeV/spacemacs/media/commit/130cd48d0386d1c8a110ad4c341c34989baf6bf9/layers/+lang/clojure/img/cider.png

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

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.

Quick Start with lein

  • Install lein via your OS package manager.
  • Create a file ~/.lein/profiles.clj with the following content:
  {: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 Binding Description
SPC m h a cider apropos
SPC m h g cider grimoire
SPC m h h cider doc
SPC m h j cider javadoc

Evaluation

Key Binding Description
SPC m e b eval buffer
SPC m e e eval last sexp
SPC m e f eval function at point
SPC m e r eval region
SPC m e w eval last sexp and replace with result

Goto

Key Binding Description
SPC m g b go back
SPC m g g goto var
SPC m g e goto error
SPC m g r goto resource

REPL

Key Binding Description
SPC m s b send and eval buffer in REPL
SPC m s B send and eval buffer and switch to REPL in insert state
SPC m s c connect to REPL (cider-connect)
SPC m s e send and eval last sexp in REPL
SPC m s E send and eval last sexp and switch to REPL in insert state
SPC m s f send and eval function in REPL
SPC m s F send and eval function and switch to REPL in insert state
SPC m s i start REPL (cider-jack-in)
SPC m s I start clojurescript REPL (cider-jack-in-clojurescript)
SPC m s n send and eval ns form in REPL
SPC m s N send and eval ns form and switch to REPL in insert state
SPC m s q kill REPL (cider-quit)
SPC m s o switch to other repl instance (cider-repl-switch-to-other)
SPC m s r send and eval region in REPL
SPC m s R send and eval region and switch to REPL in insert state
SPC m s s switch to REPL

Tests

Key Binding Description
SPC m t a run all tests in namespace
SPC m t r re-run test failures for namespace
SPC m t t run test at point

Toggles

Key Binding Description
SPC m T f toggle REPL font-locking
SPC m T p toggle REPL pretty-printing
SPC m T i toggle indentation style

Debugging

Key Binding Description
SPC m d r reload namepspaces
SPC m d b instrument expression at point
SPC m d e display last stacktrace
SPC m d i inspect expression at point

Refactoring

Key Binding Description
SPC m r ? describe refactoring
SPC m r a d add declaration
SPC m r a i add import to ns
SPC m r a m add missing libspec
SPC m r a p add project dependency
SPC m r a r add require to ns
SPC m r a u add use to ns
SPC m r c c cycle coll
SPC m r c i cycle if
SPC m r c n clean ns
SPC m r c p cycle privacy
SPC m r d k destructure keys
SPC m r e c extract constant
SPC m r e d extract definition
SPC m r e f extract function
SPC m r e l expand let
SPC m r f u find usages
SPC m r f e create fn from example
SPC m r h d hotload dependency
SPC m r i l introduce let
SPC m r i s inline symbol
SPC m r m f move form
SPC m r m l move to let
SPC m r p c project clean
SPC m r p f promote function
SPC m r r d remove debug fns
SPC m r r f rename file
SPC m r r l remove let
SPC m r r r remove unused requires
SPC m r r s rename symbol
SPC m r r u replace use
SPC m r s n sort ns
SPC m r s p sort project dependencies
SPC m r s r stop referring
SPC m r s c show changelog
SPC m r t f thread first all
SPC m r t h thread
SPC m r t l thread last all
SPC m r u a unwind all
SPC m r u p update project dependencies
SPC m r u w unwind

Reformatting

Key Binding Description
SPC m f l realign current form
SPC m f b reformat current buffer

CIDER Buffers

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

stacktrace-mode

Key Binding Description
C-j next cause
C-k previous cause
TAB cycle current cause
0 cycle all causes
1 cycle cause 1
2 cycle cause 2
3 cycle cause 3
4 cycle cause 4
5 cycle cause 5
a toggle all
c toggle clj
d toggle duplicates
J toggle java
r toggle repl
T toggle tooling

inspector-mode

Key Binding Description
TAB next inspectable object
Shift-TAB previous inspectable object
RET inspect object
L pop to the parent object
n next page in paginated view
N previous page in paginated view
r refresh
s set a new page size

test-report-mode

Key Binding Description
C-j next result
C-k previous result
RET jump to test
d ediff test result
e show stacktrace
r rerun tests
t run test
T run 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.