Skip to content

Commit 85016ef

Browse files
committed
[Docs] Document the integration with cljfmt
1 parent 3f85f10 commit 85016ef

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

doc/modules/ROOT/pages/usage/misc_features.adoc

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,46 @@ type kbd:[e] when browsing a spec to generate an example that
291291
meets the spec.
292292

293293
image::spec_browser_gen_example.png[Spec Browser Example]
294+
295+
== Formatting Code with cljfmt
296+
297+
While CIDER has it's own code formatting (identation) engine, you can also
298+
use it together with `cljfmt` - that's useful if you're working on a team
299+
that uses different editors and IDEs.
300+
301+
CIDER exposes several commands to interacted with `cljfmt`:
302+
303+
* `cider-format-defun`
304+
* `cider-format-region`
305+
* `cider-format-buffer`
306+
307+
Generally it's a good idea to add some hook like this one to make sure
308+
on each save operation your buffers are properly formatted:
309+
310+
[source,lisp]
311+
----
312+
(add-hook 'before-save-hook 'cider-format-buffer t t)
313+
----
314+
315+
Notice that you want to apply `cljfmt` **prior** to saving the buffer in question.
316+
317+
You can supply additional configuration to `cljfmt` via the configuration variable
318+
`cider-format-code-options`. Here's an example:
319+
320+
[source,lisp]
321+
----
322+
;; Let's assume you want to pass the following config
323+
;;
324+
;; {:indents {org.me/foo [[:inner 0]]}
325+
;; :alias-map {\"me\" \"org.me\"}}
326+
;;
327+
;; You'll need to encode it as an Emacs Lisp plist:
328+
329+
(setq cider-format-code-options
330+
'(("indents" (("org.me/foo" (("inner" 0)))))
331+
("alias-map" (("me" "org.me")))))
332+
----
333+
334+
NOTE: CIDER doesn't shell out to `cljfmt` - it interacts with it via nREPL
335+
(there's `format` middleware in `cider-nrepl`), which is faster that
336+
shelling out.

0 commit comments

Comments
 (0)