[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/clojure-ts-mode ca3914aa7a 02/14: Name inline indent helpe
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/clojure-ts-mode ca3914aa7a 02/14: Name inline indent helper functions instead of using lambdas |
Date: |
Fri, 8 Sep 2023 18:59:17 -0400 (EDT) |
branch: elpa/clojure-ts-mode
commit ca3914aa7aa9645ab244658f8db781cc6f95111e
Author: dannyfreeman <danny@dfreeman.email>
Commit: Danny Freeman <danny@dfreeman.email>
Name inline indent helper functions instead of using lambdas
---
clojure-ts-mode.el | 65 ++++++++++++++++++++++++++----------------------------
1 file changed, 31 insertions(+), 34 deletions(-)
diff --git a/clojure-ts-mode.el b/clojure-ts-mode.el
index d014b15f7a..e7ec1f06a1 100644
--- a/clojure-ts-mode.el
+++ b/clojure-ts-mode.el
@@ -60,6 +60,7 @@
(declare-function treesit-node-type "treesit.c")
(declare-function treesit-node-child "treesit.c")
(declare-function treesit-node-child-by-field-name "treesit.c")
+(declare-function treesit-node-prev-sibling "treesit.c")
(defgroup clojure-ts nil
"Major mode for editing Clojure code with tree-sitter."
@@ -583,17 +584,33 @@ The possible values for this variable are
Taken from cljfmt:
https://github.com/weavejester/cljfmt/blob/fb26b22f569724b05c93eb2502592dfc2de898c3/cljfmt/resources/cljfmt/indents/clojure.clj")
-(defun clojure-ts--symbols-with-body-expressions-p (node)
- "Return non-nil if NODE is a function/macro symbol with a body argument."
+(defun clojure-ts--match-function-call-arg (node parent _bol)
+ "Match NODE if PARENT is a list expressing a function or macro call."
+ (and (clojure-ts--list-node-p parent)
+ ;; Can the following two clauses be replaced by checking indexes?
+ ;; Does the second child exist, and is it not equal to the current node?
+ (treesit-node-child parent 1 t)
+ (not (treesit-node-eq (treesit-node-child parent 1 t) node))
+ (let ((first-child (treesit-node-child parent 0 t)))
+ (or (clojure-ts--symbol-node-p first-child)
+ (clojure-ts--keyword-node-p first-child)))))
+
+(defun clojure-ts--match-expression-in-body (_node parent _bol)
+ "Match NODE if it is an expression used in a body argument.
+PARENT is expected to be a list literal.
+See `treesit-simple-indent-rules'."
(and
- (not
- (clojure-ts--symbol-matches-p
- ;; Symbols starting with this are false positives
- (rx line-start (or "default" "deflate" "defer"))
- node))
- (clojure-ts--symbol-matches-p
- clojure-ts--symbols-with-body-expressions-regexp
- node)))
+ (clojure-ts--list-node-p parent)
+ (let ((first-child (treesit-node-child parent 0 t)))
+ (and
+ (not
+ (clojure-ts--symbol-matches-p
+ ;; Symbols starting with this are false positives
+ (rx line-start (or "default" "deflate" "defer"))
+ first-child))
+ (clojure-ts--symbol-matches-p
+ clojure-ts--symbols-with-body-expressions-regexp
+ first-child)))))
(defvar clojure-ts--threading-macro
(eval-and-compile
@@ -607,30 +624,10 @@
https://github.com/weavejester/cljfmt/blob/fb26b22f569724b05c93eb2502592dfc2de89
(defvar clojure-ts--semantic-indent-rules
`((clojure
((parent-is "source") parent-bol 0)
- ((lambda (node parent _) ;; https://guide.clojure.style/#body-indentation
- (and (clojure-ts--list-node-p parent)
- (let ((first-child (treesit-node-child parent 0 t)))
- (clojure-ts--symbols-with-body-expressions-p first-child))))
- parent 2)
- ;; ;; We want threading macros to indent 2 only if the ->> is on it's own
line.
- ;; ;; If not, then align functoin args.
- ;; ((lambda (node parent _)
- ;; (and (clojure-ts--list-node-p parent)
- ;; (let ((first-child (treesit-node-child parent 0 t))
- ;; (second-child (treesit-node-child parent 1 t)))
- ;; (clojure-ts--debug "Second-child %S" (treesit-node))
- ;; (clojure-ts--threading-macro-p first-child))))
- ;; parent 2)
- ((lambda (node parent _) ;;
https://guide.clojure.style/#vertically-align-fn-args
- (and (clojure-ts--list-node-p parent)
- ;; Can the following two clauses be replaced by checking indexes?
- ;; Does the second child exist, and is it not equal to the
current node?
- (treesit-node-child parent 1 t)
- (not (treesit-node-eq (treesit-node-child parent 1 t) node))
- (let ((first-child (treesit-node-child parent 0 t)))
- (or (clojure-ts--symbol-node-p first-child)
- (clojure-ts--keyword-node-p first-child)))))
- (nth-sibling 2 nil) 0)
+ ;; https://guide.clojure.style/#body-indentation
+ (clojure-ts--match-expression-in-body parent 2)
+ ;; https://guide.clojure.style/#vertically-align-fn-args
+ (clojure-ts--match-function-call-arg (nth-sibling 2 nil) 0)
;; Literal Sequences
((parent-is "list_lit") parent 1) ;;
https://guide.clojure.style/#one-space-indent
((parent-is "vec_lit") parent 1) ;;
https://guide.clojure.style/#bindings-alignment
- [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 <=
- [nongnu] elpa/clojure-ts-mode ff5d7e13dc 05/14: Semantic indentation of method implementations, ELPA Syncer, 2023/09/08
- [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