Skip to content

Commit bf141b0

Browse files
committed
[Fix #600] Accept nested list indent specs in validation
clojure--valid-unquoted-indent-spec-p rejected specs with nested lists like letfn's (1 ((:defn)) nil), causing dir-locals eval to prompt unnecessarily. Now handles nested list specs and nil elements.
1 parent 6854495 commit bf141b0

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

CHANGELOG.md

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

1818
### Bugs fixed
1919

20+
* [#600](https://github.com/clojure-emacs/clojure-mode/issues/600): Fix `clojure--valid-put-clojure-indent-call-p` rejecting valid indent specs with nested lists (e.g. `letfn`'s `(1 ((:defn)) nil)`).
2021
* Fix typos in `clojure-mode-extra-font-locking`: `halt-when?` -> `halt-when`, `simple-indent?` -> `simple-ident?`.
2122
* Fix `doc` and `find-doc` misplaced under `clojure.core` instead of `clojure.repl` in extra font-locking.
2223

clojure-mode.el

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,13 +1870,14 @@ This function also returns nil meaning don't specify the indentation."
18701870
Validate it with respect to
18711871
https://docs.cider.mx/cider/indent_spec.html e.g. (2 :form
18721872
:form (1)))."
1873-
(or (integerp spec)
1873+
(or (null spec)
1874+
(integerp spec)
18741875
(memq spec '(:form :defn))
18751876
(and (listp spec)
1876-
(not (null spec))
18771877
(or (integerp (car spec))
1878-
(memq (car spec) '(:form :defn)))
1879-
(cl-every 'clojure--valid-unquoted-indent-spec-p (cdr spec)))))
1878+
(memq (car spec) '(:form :defn))
1879+
(listp (car spec)))
1880+
(cl-every 'clojure--valid-unquoted-indent-spec-p spec))))
18801881

18811882
(defun clojure--valid-indent-spec-p (spec)
18821883
"Check that the indentation SPEC (quoted if a list) is valid.

test/clojure-mode-indentation-test.el

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,45 @@ x
834834
(call-interactively #'clojure-align)
835835
(expect (string= (buffer-string) "{:a 2, :c 4}")))))
836836

837+
(describe "clojure--valid-indent-spec-p"
838+
(it "should accept integers"
839+
(expect (clojure--valid-indent-spec-p '1) :to-be-truthy))
840+
841+
(it "should accept :defn and :form keywords"
842+
(expect (clojure--valid-indent-spec-p ':defn) :to-be-truthy)
843+
(expect (clojure--valid-indent-spec-p ':form) :to-be-truthy))
844+
845+
(it "should accept quoted list specs"
846+
(expect (clojure--valid-indent-spec-p '(quote (2 :form :form (1)))) :to-be-truthy))
847+
848+
(it "should accept nested specs like letfn's ((:defn))"
849+
(expect (clojure--valid-indent-spec-p '(quote (1 ((:defn)) nil))) :to-be-truthy))
850+
851+
(it "should accept nil as a valid spec element"
852+
(expect (clojure--valid-indent-spec-p '(quote (1))) :to-be-truthy)
853+
(expect (clojure--valid-indent-spec-p '(quote (:defn))) :to-be-truthy)))
854+
855+
(describe "clojure--valid-put-clojure-indent-call-p"
856+
(it "should accept letfn-style indent spec"
857+
(expect (clojure--valid-put-clojure-indent-call-p
858+
'(put-clojure-indent 'letfn '(1 ((:defn)) nil)))
859+
:to-be-truthy))
860+
861+
(it "should accept simple indent specs"
862+
(expect (clojure--valid-put-clojure-indent-call-p
863+
'(put-clojure-indent 'defrecord '(2 :form :form (1))))
864+
:to-be-truthy))
865+
866+
(it "should accept keyword indent specs"
867+
(expect (clojure--valid-put-clojure-indent-call-p
868+
'(put-clojure-indent 'fn :defn))
869+
:to-be-truthy))
870+
871+
(it "should reject invalid specs"
872+
(expect (clojure--valid-put-clojure-indent-call-p
873+
'(put-clojure-indent 'foo "bar"))
874+
:to-throw)))
875+
837876
(provide 'clojure-mode-indentation-test)
838877

839878
;;; clojure-mode-indentation-test.el ends here

0 commit comments

Comments
 (0)