[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/clojure-ts-mode ff5d7e13dc 05/14: Semantic indentation of
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/clojure-ts-mode ff5d7e13dc 05/14: Semantic indentation of method implementations |
Date: |
Fri, 8 Sep 2023 18:59:18 -0400 (EDT) |
branch: elpa/clojure-ts-mode
commit ff5d7e13dc53cc5da0e8139b04e02d90f61d9065
Author: Danny Freeman <danny@dfreeman.email>
Commit: Danny Freeman <danny@dfreeman.email>
Semantic indentation of method implementations
method implemenations like
(deftype MyType
Object
(toString [this]
"hello"))
Look like regular function calls, but should be indented like defns.
Found myself wanting to calling a node aunt or uncle, but nodes aren't
gendered. Internet suggested auncle or pibling. Auncle sounds better to
me.
---
clojure-ts-mode.el | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/clojure-ts-mode.el b/clojure-ts-mode.el
index 817e4721bb..9ff592f0e9 100644
--- a/clojure-ts-mode.el
+++ b/clojure-ts-mode.el
@@ -615,6 +615,26 @@ See `treesit-simple-indent-rules'."
clojure-ts--symbols-with-body-expressions-regexp
first-child)))))
+(defconst clojure-ts--reifying-symbol-regexp
+ (eval-and-compile
+ (rx line-start
+ (or "deftype" "defrecord"
+ "reify" "proxy" "extend-type" "extend-protocol")))
+ "A regular expression matching a symbol used to define a concrete type.")
+
+(defun clojure-ts--match-method-body (node parent _bol)
+ "Matches a `NODE' in the body of a `PARENT' method implementation.
+A method implementation referes to concrete implemntations being defined in
+forms like deftype, defrecord, reify, proxy, etc."
+ (and
+ (clojure-ts--list-node-p parent)
+ (let* ((grandparent (treesit-node-parent parent))
+ ;; auncle: gender neutral sibling of parent, aka child of grandparent
+ (first-auncle (treesit-node-child grandparent 0 t)))
+ (and (clojure-ts--list-node-p grandparent)
+ (clojure-ts--symbol-matches-p clojure-ts--reifying-symbol-regexp
+ first-auncle)))))
+
(defvar clojure-ts--threading-macro
(eval-and-compile
(rx (and "->" (? ">") line-end)))
@@ -623,7 +643,7 @@ See `treesit-simple-indent-rules'."
(defun clojure-ts--match-threading-macro-arg (_node parent _)
"Match NODE if it is an argument to a PARENT threading macro."
;; We want threading macros to indent 2 only if the ->> is on it's own line.
- ;; If not, then align functoin arg.
+ ;; If not, then align function arg.
(and (clojure-ts--list-node-p parent)
(let ((first-child (treesit-node-child parent 0 t)))
(clojure-ts--symbol-matches-p
@@ -640,6 +660,7 @@ See `treesit-simple-indent-rules'."
`((clojure
((parent-is "source") parent-bol 0)
;; https://guide.clojure.style/#body-indentation
+ (clojure-ts--match-method-body parent 2)
(clojure-ts--match-expression-in-body parent 2)
;; https://guide.clojure.style/#threading-macros-alignment
(clojure-ts--match-threading-macro-arg prev-sibling 0)
@@ -654,7 +675,7 @@ See `treesit-simple-indent-rules'."
(defun clojure-ts--configured-indent-rules ()
"Gets the configured choice of indent rules."
(cond
- ((eq clojure-ts-indent-style 'semantic) clojure-ts--semantic-indent-rules)
+ ((eq clojure-ts-indent-style 'semantic) (clojure-ts--semantic-indent-rules))
((eq clojure-ts-indent-style 'fixed) clojure-ts--fixed-indent-rules)
(t (error
(format
- [nongnu] elpa/clojure-ts-mode updated (2225190ee5 -> 881756c8f5), ELPA Syncer, 2023/09/08
- [nongnu] elpa/clojure-ts-mode ae2e248601 01/14: First pass at semantic indentation, ELPA Syncer, 2023/09/08
- [nongnu] elpa/clojure-ts-mode ca3914aa7a 02/14: Name inline indent helper functions instead of using lambdas, ELPA Syncer, 2023/09/08
- [nongnu] elpa/clojure-ts-mode ff5d7e13dc 05/14: Semantic indentation of method implementations,
ELPA Syncer <=
- [nongnu] elpa/clojure-ts-mode b6f6d37959 10/14: Update changelog to include information about semantic indentation, ELPA Syncer, 2023/09/08
- [nongnu] elpa/clojure-ts-mode a8a321500e 13/14: More documentation updates, ELPA Syncer, 2023/09/08
- [nongnu] elpa/clojure-ts-mode 85871fdbc8 03/14: Match threading alignment of cljfmt, clojure-mode, ELPA Syncer, 2023/09/08
- [nongnu] elpa/clojure-ts-mode 64d8fde253 04/14: Semantic indentation docs, ELPA Syncer, 2023/09/08
- [nongnu] elpa/clojure-ts-mode a87821629f 07/14: Fix docstring font-locking, try to clarify various regex names, ELPA Syncer, 2023/09/08
- [nongnu] elpa/clojure-ts-mode 0c4bd2bfce 06/14: Indent example file, ELPA Syncer, 2023/09/08
- [nongnu] elpa/clojure-ts-mode d4e0f1ae44 09/14: Move thing-settings out of the middle of indent-related functions, ELPA Syncer, 2023/09/08
- [nongnu] elpa/clojure-ts-mode 177ac05434 08/14: Indent within docstrings - not working 100%, ELPA Syncer, 2023/09/08
- [nongnu] elpa/clojure-ts-mode 1675f12e26 12/14: Unused argument causing linter to fail, ELPA Syncer, 2023/09/08
- [nongnu] elpa/clojure-ts-mode 881756c8f5 14/14: Remove unused function, ELPA Syncer, 2023/09/08