[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/clojure-ts-mode b708c7f15f 047/210: Rewrite the indent log
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/clojure-ts-mode b708c7f15f 047/210: Rewrite the indent logic |
Date: |
Thu, 31 Oct 2024 18:59:38 -0400 (EDT) |
branch: elpa/clojure-ts-mode
commit b708c7f15fb22b8b4547f8ffa8d2a84faa0422c9
Author: Artur Malabarba <bruce.connor.am@gmail.com>
Commit: Artur Malabarba <bruce.connor.am@gmail.com>
Rewrite the indent logic
[Fix #282 Fix #296] Use custom-code to calculate normal-indent.
Add tests for backtracking indent and several other scenarios.
Support a new notation for indent specs.
An indent spec can be:
- `nil` (or absent), meaning “indent like a regular function”.
- A list/vector meaning that this function/macro takes a number of
“special” arguments which are indented by more spaces (in CIDER
that's 4 spaces), and then all other arguments are indented like a
body (in CIDER that's 2 spaces).
- The first element is a number indicating how many "special"
arguments this function/macro takes.
- Each following element is an indent spec on its own, and it
applies to the argument on the same position as this element. So,
when the argument is a form, it specifies how to indent that
argument internally (if it's not a form the spec is irrelevant).
- If the function/macro has more aguments than the list has
elements, the last element of the list applies to all remaining
arguments.
So, for instance, if I specify the `deftype` spec as `[2 nil nil fn]`
(equivalent to `[2 nil nil [1]]`), it would be indented like this:
```
(deftype
ImageSelection
[data]
Transferable
(getTransferDataFlavors [this]
(some-function))
SomethingElse
(isDataFlavorSupported [this flavor]
(= imageFlavor flavor)))
```
(I put `ImageSelection` and `[data]` on their own lines just to show the
indentation).
Another example, `reify` as `[1 nil fn]`
```
(reify Object
(toString [this]
(f)
asodkaodkap))
```
Or something more complicated, `letfn` as `[1 [fn] nil]`
```
(letfn [(twice [x]
(* x 2))
(six-times [y]
(* (twice y) 3))]
(println "Twice 15 =" (twice 15))
(println "Six times 15 =" (six-times 15)))
```
---
clojure-mode-indentation-test.el | 85 +++++++++++++++++++++++++++++++++++++---
1 file changed, 79 insertions(+), 6 deletions(-)
diff --git a/clojure-mode-indentation-test.el b/clojure-mode-indentation-test.el
index 93de734750..01f4ebd7aa 100644
--- a/clojure-mode-indentation-test.el
+++ b/clojure-mode-indentation-test.el
@@ -110,28 +110,28 @@ values of customisable variables."
(check-indentation doc-strings-without-indent-specified
"
(defn some-fn
-|\"some doc string\""
+|\"some doc string\")"
"
(defn some-fn
- |\"some doc string\"")
+ |\"some doc string\")")
(check-indentation doc-strings-with-correct-indent-specified
"
(defn some-fn
- |\"some doc string\""
+ |\"some doc string\")"
"
(defn some-fn
- |\"some doc string\"")
+ |\"some doc string\")")
(check-indentation doc-strings-with-additional-indent-specified
"
(defn some-fn
|\"some doc string
- - some note\""
+ - some note\")"
"
(defn some-fn
|\"some doc string
- - some note\"")
+ - some note\")")
;; we can specify different indentation for symbol with some ns prefix
(put-clojure-indent 'bala 0)
@@ -189,6 +189,79 @@ values of customisable variables."
|(* x 2))]
:a)")
+(check-indentation fixed-normal-indent
+ "(cond
+ (or 1
+ 2) 3
+|:else 4)"
+ "(cond
+ (or 1
+ 2) 3
+ |:else 4)")
+
+(check-indentation fixed-normal-indent-2
+ "(fact {:spec-type
+ :charnock-column-id} #{\"charnock\"}
+|{:spec-type
+ :charnock-column-id} #{\"current_charnock\"})"
+ "(fact {:spec-type
+ :charnock-column-id} #{\"charnock\"}
+ |{:spec-type
+ :charnock-column-id} #{\"current_charnock\"})")
+
+
+;;; Backtracking indent
+(defmacro def-full-indent-test (name form)
+ "Verify that FORM corresponds to a properly indented sexp."
+ (declare (indent 1))
+ `(ert-deftest ,(intern (format "test-backtracking-%s" name)) ()
+ (with-temp-buffer
+ (clojure-mode)
+ (insert "\n" ,(replace-regexp-in-string "\n +" "\n " form))
+ (indent-region (point-min) (point-max))
+ (should (equal (buffer-string)
+ ,(concat "\n" form))))))
+
+(def-full-indent-test closing-paren
+ "(ns ca
+ (:gen-class)
+ )")
+
+(def-full-indent-test non-symbol-at-start
+ "{\"1\" 2
+ *3 4}")
+
+(def-full-indent-test non-symbol-at-start-2
+ "(\"1\" 2
+ *3 4)")
+
+(def-full-indent-test defrecord
+ "(defrecord TheNameOfTheRecord
+ [a pretty long argument list]
+ SomeType
+ (assoc [_ x]
+ (.assoc pretty x 10)))")
+
+(def-full-indent-test defrecord-2
+ "(defrecord TheNameOfTheRecord [a pretty long argument list]
+ SomeType (assoc [_ x]
+ (.assoc pretty x 10)))")
+
+(def-full-indent-test letfn
+ "(letfn [(f [x]
+ (* x 2))
+ (f [x]
+ (* x 2))]
+ (a b
+ c) (d)
+ e)")
+
+(def-full-indent-test reify
+ "(reify
+ Object
+ (x [_]
+ 1))")
+
(provide 'clojure-mode-indentation-test)
;; Local Variables:
- [nongnu] elpa/clojure-ts-mode 0267302ece 027/210: Code style, (continued)
- [nongnu] elpa/clojure-ts-mode 0267302ece 027/210: Code style, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode 9e13a002ad 036/210: Add tests and documentation for the indentation config changes, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode ac2ae956a6 034/210: Rename clojure-mode-test.el to clojure-mode-font-lock-test.el, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode e98c459e56 035/210: Fix doctring indentation issue in #241, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode 73f2635495 033/210: [Fix #271] Add indentation tests, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode 009c639c17 037/210: Implement commands for navigating over logical sexps, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode c1c4628eae 032/210: Fix font-locking of namespace-prefixed dynamic vars, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode eecf34ef10 041/210: Handle properly def* symbols, containing special chars, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode 0882089f5d 051/210: Merge pull request #326 from Malabarba/master, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode b0d3ed2620 042/210: Merge pull request #316 from BrunoBonacci/fix-font-locking, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode b708c7f15f 047/210: Rewrite the indent logic,
ELPA Syncer <=
- [nongnu] elpa/clojure-ts-mode fe0659d4c9 046/210: [Fix #278] Understand namespace aliases in backtracking indent, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode 1018c6e769 050/210: Font-lock namespaced keywords, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode db77aa7a36 044/210: [Fix #308 Fix #287 Fix #45] Corner-case indentation of multi-line sexps, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode a7609cffa1 052/210: [Fix #327] Indentation of a lonely close paren, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode bf62b1bde0 049/210: [Fix #325] Fix indent for spliced reader conditionals, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode 18fd667939 070/210: Make the ns regexp more permissive, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode ebf33a3a06 067/210: Add a test for namespaced default* symbols, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode a33c3e2dfd 065/210: Don't treat the symbol default as def* macro., ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode bff5ddc1b5 066/210: [Fix #344] Indentation for extend-type, ELPA Syncer, 2024/10/31
- [nongnu] elpa/clojure-ts-mode 077e3491bc 062/210: Improve clojure-find-def matching (support hyphens), ELPA Syncer, 2024/10/31