diff --git a/CHANGELOG.md b/CHANGELOG.md index 05f489a3..df8180b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/clojure-mode.el b/clojure-mode.el index 603b5ed4..9f758436 100644 --- a/clojure-mode.el +++ b/clojure-mode.el @@ -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))))) diff --git a/test/clojure-mode-indentation-test.el b/test/clojure-mode-indentation-test.el index 6f22503f..51af55c0 100644 --- a/test/clojure-mode-indentation-test.el +++ b/test/clojure-mode-indentation-test.el @@ -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))