Skip to content

Commit 3baafc2

Browse files
committed
[Fix #349] Indent and font-lock (let|when|while)-* forms
1 parent 8b01df6 commit 3baafc2

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

clojure-mode.el

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,12 @@ Called by `imenu--generic-function'."
426426
"declare") t)
427427
"\\>")
428428
1 font-lock-keyword-face)
429+
;; Macros similar to let, when, and while
430+
(,(rx symbol-start
431+
(or "let" "when" "while") "-"
432+
(1+ (or (syntax word) (syntax symbol)))
433+
symbol-end)
434+
0 font-lock-keyword-face)
429435
(,(concat
430436
"\\<"
431437
(regexp-opt
@@ -667,7 +673,10 @@ symbol properties."
667673
(or (get (intern-soft (match-string 1 function-name))
668674
'clojure-indent-function)
669675
(get (intern-soft (match-string 1 function-name))
670-
'clojure-backtracking-indent)))))
676+
'clojure-backtracking-indent)))
677+
(when (string-match (rx (or "let" "when" "while") (syntax symbol))
678+
function-name)
679+
(clojure--get-indent-method (substring (match-string 0 function-name) 0 -1)))))
671680

672681
(defvar clojure--current-backtracking-depth 0)
673682

test/clojure-mode-font-lock-test.el

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ POS."
124124
(should (equal (clojure-test-face-at 8 8 "{:a.ias/some 20}") '(default clojure-keyword-face)))
125125
(should (equal (clojure-test-face-at 9 12 "{:a.ias/some 20}") '(clojure-keyword-face))))
126126

127+
(ert-deftest clojure-mode-syntax-table/fontify-let-when-while-type-forms ()
128+
:tags '(fontification syntax-table)
129+
(should (equal (clojure-test-face-at 2 11 "(when-alist [x 1]\n ())") 'font-lock-keyword-face))
130+
(should (equal (clojure-test-face-at 2 11 "(while-alist [x 1]\n ())") 'font-lock-keyword-face))
131+
(should (equal (clojure-test-face-at 2 11 "(let-alist [x 1]\n ())") 'various-faces)))
132+
127133
(ert-deftest clojure-mode-syntax-table/type ()
128134
:tags '(fontification syntax-table)
129135
(should (eq (clojure-test-face-at 1 9 "SomeClass") 'font-lock-type-face)))

test/clojure-mode-indentation-test.el

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ values of customisable variables."
335335
"(msg' 1
336336
10)")
337337

338+
(def-full-indent-test let-when-while-forms
339+
"(let-alist [x 1]\n ())"
340+
"(while-alist [x 1]\n ())"
341+
"(when-alist [x 1]\n ())")
338342

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

0 commit comments

Comments
 (0)