2015-12-02 14:23:39 +00:00
#+TITLE : Clojure layer
2015-06-10 16:44:30 +00:00
[[file:img/clojure.png ]] [[file:img/cider.png ]]
2016-03-31 02:59:55 +00:00
* Table of Contents :TOC_4_gh:noexport:
- [[#description ][Description ]]
- [[#features ][Features ]]
- [[#install ][Install ]]
- [[#layer ][Layer ]]
- [[#pretty-symbols ][Pretty Symbols ]]
- [[#cider-and-clj-refactor ][CIDER and clj-refactor ]]
- [[#quick-start-with-boot ][Quick Start with boot ]]
- [[#quick-start-with-lein ][Quick Start with lein ]]
- [[#more-details ][More details ]]
- [[#key-bindings ][Key Bindings ]]
- [[#working-with-clojure-files-barfage-slurpage--more ][Working with clojure files (barfage, slurpage & more) ]]
- [[#leader ][Leader ]]
- [[#documentation ][Documentation ]]
- [[#evaluation ][Evaluation ]]
- [[#goto ][Goto ]]
- [[#repl ][REPL ]]
- [[#tests ][Tests ]]
- [[#toggles ][Toggles ]]
- [[#debugging ][Debugging ]]
- [[#refactoring ][Refactoring ]]
- [[#reformatting ][Reformatting ]]
- [[#cider-buffers ][CIDER Buffers ]]
- [[#stacktrace-mode ][stacktrace-mode ]]
- [[#inspector-mode ][inspector-mode ]]
- [[#test-report-mode ][test-report-mode ]]
- [[#development-notes ][Development Notes ]]
- [[#indentation ][Indentation ]]
2015-06-10 16:44:30 +00:00
* Description
2015-08-16 09:12:37 +00:00
This layer adds support for [[http://clojure.org ][Clojure ]] language using [[https://github.com/clojure-emacs/cider ][CIDER ]].
2015-06-10 16:44:30 +00:00
* Features
2015-08-16 09:12:37 +00:00
- REPL via [[https://github.com/clojure-emacs/cider ][CIDER ]]
2016-04-13 03:31:38 +00:00
- Code formatting via [[https://github.com/clojure-emacs/cider ][CIDER ]] using [[https://github.com/weavejester/cljfmt ][Cljfmt ]]
2015-06-10 16:44:30 +00:00
- Refactoring via [[https://github.com/clojure-emacs/clj-refactor.el ][clj-refactor ]]
2016-01-28 21:30:47 +00:00
- Aligning of code forms via [[https://github.com/clojure-emacs/clojure-mode ][clojure-mode ]]
2016-04-13 03:31:38 +00:00
2015-06-10 16:44:30 +00:00
* Install
** Layer
2016-01-06 05:21:55 +00:00
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.
2015-06-10 16:44:30 +00:00
** Pretty Symbols
2015-06-10 21:16:01 +00:00
Pretty symbols for anonymous functions, set literals and partial, like =(λ [a]
(+ a 5))=, =ƒ(+ % 5)=, = ∈{2 4 6}= and =Ƥ= .
2015-06-10 16:44:30 +00:00
2015-09-28 06:05:18 +00:00
To enable this feature, add the following snippet to the
=dotspacemacs/user-config= section of your =~/.spacemacs= file:
2015-06-10 16:44:30 +00:00
#+BEGIN_SRC emacs-lisp
(setq clojure-enable-fancify-symbols t)
#+END_SRC
Or set this variable when loading the configuration layer:
#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-configuration-layers
'((clojure :variables clojure-enable-fancify-symbols t)))
#+END_SRC
2015-08-16 09:12:37 +00:00
** CIDER and clj-refactor
2016-08-26 11:16:15 +00:00
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.
2015-09-16 04:40:13 +00:00
*** Quick Start with boot
- Install =boot= (see https://github.com/boot-clj/boot#install)
- Create a file =~/.boot/profile.boot= with the following content:
#+BEGIN_SRC clojure
(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)
#+END_SRC
2016-09-05 17:33:02 +00:00
- 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.
2015-09-16 04:40:13 +00:00
2015-06-10 16:44:30 +00:00
*** Quick Start with lein
2016-03-27 16:21:43 +00:00
- Install =lein= version 2.5.2 or newer (see http://leiningen.org/ #install)
2015-06-10 16:44:30 +00:00
- Create a file =~/.lein/profiles.clj= with the following content:
2016-04-13 03:31:38 +00:00
2015-06-10 16:44:30 +00:00
#+BEGIN_SRC clojure
2015-11-22 19:38:19 +00:00
{:repl {:plugins [[cider/cider-nrepl "0.10.0-SNAPSHOT"]
2015-12-08 03:14:58 +00:00
[refactor-nrepl "2.0.0-SNAPSHOT"]]
2015-06-10 16:44:30 +00:00
:dependencies [[alembic "0.3.2"]
2015-12-08 03:14:58 +00:00
[org.clojure/tools.nrepl "0.2.12"]]}}
2015-06-10 16:44:30 +00:00
#+END_SRC
2015-09-05 11:32:11 +00:00
- After creating your project with ~lein new app <projectname>~ or
importing an existing project, run ~SPC m s i~ in any of the clojure
2015-09-16 04:40:13 +00:00
source files to connect to the CIDER REPL.
2015-09-05 11:32:11 +00:00
2015-06-10 16:44:30 +00:00
*** More details
More info regarding installation of nREPL middleware can be found here:
2015-08-16 09:12:37 +00:00
- CIDER: [[https://github.com/clojure-emacs/cider#installation ][cider_install ]]
2015-06-10 16:44:30 +00:00
- clj-refactor: [[https://github.com/clojure-emacs/refactor-nrepl ][refactor-nrepl ]]
2016-04-13 03:31:38 +00:00
2015-06-10 16:44:30 +00:00
* Key Bindings
2015-10-08 09:53:03 +00:00
** Working with clojure files (barfage, slurpage & more)
2015-10-09 10:15:35 +00:00
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.
2015-10-08 09:53:03 +00:00
2015-10-09 10:15:35 +00:00
As this state works the same for all files, the documentation is in global
[[https://github.com/syl20bnr/spacemacs/blob/master/doc/DOCUMENTATION.org#lisp-key-bindings ][DOCUMENTATION.org ]]. In general, use ~SPC k~ to interact with the lisp-state.
2015-06-10 16:44:30 +00:00
2015-08-16 09:12:37 +00:00
** Leader
*** Documentation
2015-06-10 16:44:30 +00:00
2016-03-07 23:14:21 +00:00
| 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 |
| ~SPC m h n~ | cider browse ns |
2015-06-10 16:44:30 +00:00
2015-08-16 09:12:37 +00:00
*** Evaluation
2015-06-10 16:44:30 +00:00
2016-03-07 23:14:21 +00:00
| 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 m~ | cider macroexpand 1 |
| ~SPC m e M~ | cider macroexpand all |
| ~SPC m e p~ | print last sexp (clojure interaction mode only) |
| ~SPC m e w~ | eval last sexp and replace with result |
2015-06-10 16:44:30 +00:00
2015-08-16 09:12:37 +00:00
*** Goto
2015-06-10 16:44:30 +00:00
2016-08-17 19:50:24 +00:00
| Key Binding | Description |
|-------------+-----------------------|
| ~SPC m g b~ | go back |
| ~SPC m g C~ | browse classpath |
| ~SPC m g g~ | goto var |
| ~SPC m g e~ | goto error |
| ~SPC m g r~ | goto resource |
| ~SPC m g n~ | browse namespaces |
| ~SPC m g N~ | browse all namespaces |
2015-06-10 16:44:30 +00:00
2015-08-16 09:12:37 +00:00
*** REPL
2016-03-07 23:14:21 +00:00
| Key Binding | Description |
|-------------+--------------------------------------------------------------------------------|
| ~SPC m ,~ | handle shortcut (cider-repl-handle-shortcut) |
| ~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) or clear repl buffer (cider-repl-clear-buffer) |
2016-10-03 04:23:52 +00:00
| ~SPC m s C~ | clear REPL (cider-find-and-clear-repl-output) |
2016-03-07 23:14:21 +00:00
| ~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 or jump to last file or last clj buffer from repl (cider-repl) |
2015-08-16 09:12:37 +00:00
*** Tests
2015-06-10 16:44:30 +00:00
| 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 |
2015-09-04 17:11:04 +00:00
*** Toggles
| Key Binding | Description |
|-------------+-----------------------------|
2016-08-17 19:50:24 +00:00
| ~SPC m T e~ | toggle englighten mode |
2015-10-09 10:15:35 +00:00
| ~SPC m T f~ | toggle REPL font-locking |
2016-03-07 23:14:21 +00:00
| ~SPC m T e~ | toggle cider-enlighten-mode |
2015-10-09 10:15:35 +00:00
| ~SPC m T p~ | toggle REPL pretty-printing |
| ~SPC m T i~ | toggle indentation style |
2016-08-17 19:50:24 +00:00
| ~SPC m T t~ | toggle auto test mode |
2015-09-04 17:11:04 +00:00
2015-08-16 09:12:37 +00:00
*** Debugging
2015-06-21 02:42:44 +00:00
| Key Binding | Description |
|-------------+--------------------------------|
2015-10-09 10:15:35 +00:00
| ~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 |
2015-06-21 02:42:44 +00:00
2015-08-16 09:12:37 +00:00
*** Refactoring
2015-08-25 01:07:59 +00:00
| Key Binding | Description |
|---------------+-----------------------------|
| ~SPC m r ?~ | describe refactoring |
2015-08-16 09:12:37 +00:00
| ~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 |
2015-10-02 11:45:27 +00:00
| ~SPC m r e d~ | extract definition |
2015-10-02 11:36:49 +00:00
| ~SPC m r e f~ | extract function |
2015-08-16 09:12:37 +00:00
| ~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
2016-04-13 03:31:38 +00:00
2016-10-03 02:21:30 +00:00
| Key Binding | Description |
|---------------------------+-------------------------|
| ~SPC m f l~ | realign current form |
| ~SPC m f b~ or ~SPC m =~ | reformat current buffer |
2015-08-16 09:12:37 +00:00
** CIDER Buffers
In general, ~q~ should always quit the popped up buffer.
*** stacktrace-mode
| Key Binding | Description |
|-------------+---------------------|
2015-08-25 01:07:59 +00:00
| ~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 |
2015-08-16 09:12:37 +00:00
*** inspector-mode
| Key Binding | Description |
|-------------+---------------------------------|
2015-08-25 01:07:59 +00:00
| ~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 |
2015-08-16 09:12:37 +00:00
*** test-report-mode
2017-01-23 11:25:48 +00:00
| Key Binding | Description |
|-------------+--------------------|
| ~C-j~ | next result |
| ~C-k~ | previous result |
| ~RET~ | jump to test |
| ~d~ | ediff test result |
| ~e~ | show stacktrace |
| ~r~ | rerun failed tests |
| ~t~ | run test |
| ~T~ | run tests |
2015-08-16 09:12:37 +00:00
2016-01-18 18:30:27 +00:00
* Development Notes
** Indentation
With a [[https://github.com/clojure-emacs/cider/blob/master/doc/Indent-Spec.md#indent-specification ][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.