branch: elpa/clojure-mode
commit 52782b84e87a73e38bfb54bf82406f2d23d742a3
Author: Bozhidar Batsov <[email protected]>
Commit: Bozhidar Batsov <[email protected]>
[Fix #610] Treat all paren lists as data in edn-mode
In EDN files there are no function calls, so paren lists like
(:key1 :value1 :key2 :value2) should use data-style indentation
(aligned at column 1 inside the paren) rather than function-call
style indentation.
Add `(derived-mode-p 'edn-mode)` as the first check in
`clojure--not-function-form-p` so that all list forms in EDN
buffers are treated as data.
Also fix indentation of a seq-find call to satisfy the linter.
---
clojure-mode.el | 3 ++-
test/edn-mode-indentation-test.el | 13 +++++++++----
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/clojure-mode.el b/clojure-mode.el
index 50c651fb4d..e468cc5446 100644
--- a/clojure-mode.el
+++ b/clojure-mode.el
@@ -1725,7 +1725,8 @@ accepted by `clojure-indent-style'."
(defun clojure--not-function-form-p ()
"Non-nil if form at point doesn't represent a function call."
- (or (member (char-after) '(?\[ ?\{))
+ (or (derived-mode-p 'edn-mode)
+ (member (char-after) '(?\[ ?\{))
(save-excursion ;; Catch #?@ (:cljs ...)
(skip-chars-backward "\r\n[:blank:]")
(when (eq (char-before) ?@)
diff --git a/test/edn-mode-indentation-test.el
b/test/edn-mode-indentation-test.el
index 47e46e13ba..a66e59fb96 100644
--- a/test/edn-mode-indentation-test.el
+++ b/test/edn-mode-indentation-test.el
@@ -56,22 +56,27 @@
(it "should align let arguments instead of using body indentation"
(with-edn-buffer "\n(let [x 1]\nx)"
(indent-region (point-min) (point-max))
- (expect (buffer-string) :to-equal "\n(let [x 1]\n x)")))
+ (expect (buffer-string) :to-equal "\n(let [x 1]\n x)")))
(it "should align if arguments instead of using body indentation"
(with-edn-buffer "\n(if true\n1\n2)"
(indent-region (point-min) (point-max))
- (expect (buffer-string) :to-equal "\n(if true\n 1\n 2)")))
+ (expect (buffer-string) :to-equal "\n(if true\n 1\n 2)")))
(it "should align cond arguments instead of using body indentation"
(with-edn-buffer "\n(cond a\nb)"
(indent-region (point-min) (point-max))
- (expect (buffer-string) :to-equal "\n(cond a\n b)")))
+ (expect (buffer-string) :to-equal "\n(cond a\n b)")))
(it "should align do arguments instead of using body indentation"
(with-edn-buffer "\n(do a\nb)"
(indent-region (point-min) (point-max))
- (expect (buffer-string) :to-equal "\n(do a\n b)"))))
+ (expect (buffer-string) :to-equal "\n(do a\n b)")))
+
+ (it "should align keyword lists as data (issue #610)"
+ (with-edn-buffer "\n(:key1 :value1\n:key2 :value2)"
+ (indent-region (point-min) (point-max))
+ (expect (buffer-string) :to-equal "\n(:key1 :value1\n :key2
:value2)"))))
(describe "maps, vectors, and sets indent normally"