Skip to content

Commit 4638468

Browse files
committed
Merge pull request bbatsov#48 from ska2342/master
Hints for formatting cond (and other pairwise grouping constructs)
2 parents 82f506d + 90aa0f7 commit 4638468

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,9 @@ of commas and line breaks.
238238
```
239239

240240
* Do not place blank lines in the middle of a function or
241-
macro definition.
241+
macro definition. An exception can be made to indicate grouping of
242+
pairwise constructs as found in e.g. `let` and `cond`.
243+
242244
* Where feasible, avoid making lines longer than 80 characters.
243245
* Avoid trailing whitespace.
244246
* Use one file per namespace.
@@ -600,6 +602,37 @@ compile-time constants.
600602
:dunno)
601603
```
602604

605+
* Use short forms in `cond` and related. If not possible give visual
606+
hints for the pairwise grouping with comments or empty lines.
607+
608+
```Clojure
609+
;; good
610+
(cond
611+
(test1) (action1)
612+
(test2) (action2)
613+
:else (default-action))
614+
615+
;; okish
616+
(cond
617+
;; test case 1
618+
(test1)
619+
(long-function-name-which-requires-a-new-line
620+
(complicated-sub-form
621+
(-> 'which-spans
622+
multiple-lines)))
623+
624+
(test2)
625+
(another-very-long-function-name
626+
(yet-another-sub-form
627+
(-> 'which-spans
628+
multiple-lines)))
629+
630+
:else
631+
(the-fall-through-default-case
632+
(which-also-spans 'multiple
633+
'lines)))
634+
```
635+
603636
* Use a `set` as a predicate when appropriate.
604637

605638
```Clojure

0 commit comments

Comments
 (0)