Skip to content

Indent "let", "when" and "while" as function form if not at start #497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@

* [#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.
* [#483](https://github.com/clojure-emacs/clojure-mode/issues/483): Support alignment for reader conditionals, with the new `clojure-align-reader-conditionals` user option.
* [#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

### Bugs fixed

5 changes: 4 additions & 1 deletion clojure-mode.el
Original file line number Diff line number Diff line change
@@ -1304,7 +1304,10 @@ symbol properties."
'clojure-indent-function)
(get (intern-soft (match-string 1 function-name))
'clojure-backtracking-indent)))
(when (string-match (rx (or "let" "when" "while") (syntax symbol))
;; indent symbols starting if, when, ...
;; such as if-let, when-let, ...
;; like if, when, ...
(when (string-match (rx string-start (or "if" "when" "let" "while") (syntax symbol))
function-name)
(clojure--get-indent-method (substring (match-string 0 function-name) 0 -1)))))

4 changes: 3 additions & 1 deletion test/clojure-mode-indentation-test.el
Original file line number Diff line number Diff line change
@@ -421,7 +421,9 @@ values of customisable variables."
(def-full-indent-test let-when-while-forms
"(let-alist [x 1]\n ())"
"(while-alist [x 1]\n ())"
"(when-alist [x 1]\n ())")
"(when-alist [x 1]\n ())"
"(if-alist [x 1]\n ())"
"(indents-like-fn-when-let-while-if-are-not-the-start [x 1]\n ())")

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