Skip to content

Commit 88c78bf

Browse files
Macrozbbatsov
authored andcommitted
Indent "let", "when" and "while" as function form if not at start (#497)
"let", "when" and "while" are considered to be a macro form normally: (when foo bar) Also you can introduce macros that start with "let", "when" or "while" that will be indented like macro forms: (when-foo-bar 1 2 3) But when "let", "when" and "while" are not in the beginning of a symbol they are now treated as function forms: (foo-when-bar 1 2 3)
1 parent fa2d6ff commit 88c78bf

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
* [#481](https://github.com/clojure-emacs/clojure-mode/issues/481): Support vertical alignment even in the presence of blank lines, with the new `clojure-align-separator` user option.
88
* [#483](https://github.com/clojure-emacs/clojure-mode/issues/483): Support alignment for reader conditionals, with the new `clojure-align-reader-conditionals` user option.
9+
* [#497](https://github.com/clojure-emacs/clojure-mode/pull/497) Indent "let", "when" and "while" as function form if not at start of a symbol
910

1011
### Bugs fixed
1112

clojure-mode.el

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,10 @@ symbol properties."
13071307
'clojure-indent-function)
13081308
(get (intern-soft (match-string 1 function-name))
13091309
'clojure-backtracking-indent)))
1310-
(when (string-match (rx (or "let" "when" "while") (syntax symbol))
1310+
;; indent symbols starting if, when, ...
1311+
;; such as if-let, when-let, ...
1312+
;; like if, when, ...
1313+
(when (string-match (rx string-start (or "if" "when" "let" "while") (syntax symbol))
13111314
function-name)
13121315
(clojure--get-indent-method (substring (match-string 0 function-name) 0 -1)))))
13131316

test/clojure-mode-indentation-test.el

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,9 @@ values of customisable variables."
421421
(def-full-indent-test let-when-while-forms
422422
"(let-alist [x 1]\n ())"
423423
"(while-alist [x 1]\n ())"
424-
"(when-alist [x 1]\n ())")
424+
"(when-alist [x 1]\n ())"
425+
"(if-alist [x 1]\n ())"
426+
"(indents-like-fn-when-let-while-if-are-not-the-start [x 1]\n ())")
425427

426428
(defun indent-cond (indent-point state)
427429
(goto-char (elt state 1))

0 commit comments

Comments
 (0)