[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/clojure-ts-mode 177ac05434 08/14: Indent within docstrings
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/clojure-ts-mode 177ac05434 08/14: Indent within docstrings - not working 100% |
Date: |
Fri, 8 Sep 2023 18:59:18 -0400 (EDT) |
branch: elpa/clojure-ts-mode
commit 177ac05434fa2aed037be05707ca57f63df59ef5
Author: Danny Freeman <danny@dfreeman.email>
Commit: Danny Freeman <danny@dfreeman.email>
Indent within docstrings - not working 100%
This indentation is pretty aggressive.
When trying to indent MORE than what clojure-ts-mode would like
(defn foo
"doc string
default to indent here
but indenting out here is difficult
because treesit indent will pull it back to 2 spaces from (defn"
...)
---
clojure-ts-mode.el | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 46 insertions(+), 1 deletion(-)
diff --git a/clojure-ts-mode.el b/clojure-ts-mode.el
index a94e1ae9af..c65a6b30db 100644
--- a/clojure-ts-mode.el
+++ b/clojure-ts-mode.el
@@ -405,6 +405,10 @@ Only intended for use at development time.")
"Return non-nil if NODE is a Clojure symbol."
(string-equal "sym_lit" (treesit-node-type node)))
+(defun clojure-ts--string-node-p (node)
+ "Return non-nil if NODE is a Clojure string literal."
+ (string-equal "str_lit" (treesit-node-type node)))
+
(defun clojure-ts--keyword-node-p (node)
"Return non-nil if NODE is a Clojure keyword."
(string-equal "kwd_lit" (treesit-node-type node)))
@@ -681,9 +685,50 @@ forms like deftype, defrecord, reify, proxy, etc."
1 ;; NODE is the first arg, offset 1 from start of *->> symbol
0)) ;; arg 2...n, match indentation of the previous argument
-(defvar clojure-ts--semantic-indent-rules
+(defun clojure-ts--match-fn-docstring (node)
+ "Match NODE when it is a docstring for PARENT function definition node."
+ ;; A string that is the third node in a function defn block
+ (let ((parent (treesit-node-parent node)))
+ (and (treesit-node-eq node (treesit-node-child parent 2 t))
+ (let ((first-auncle (treesit-node-child parent 0 t)))
+ (clojure-ts--symbol-matches-p
+ clojure-ts--definition-symbol-regexp
+ first-auncle)))))
+
+(defun clojure-ts--match-def-docstring (node)
+ "Match NODE when it is a docstring for PARENT variable definition node."
+ ;; A string that is the fourth node in a variable definition block.
+ (let ((parent (treesit-node-parent node)))
+ (and (treesit-node-eq node (treesit-node-child parent 2 t))
+ ;; There needs to be a value after the string.
+ ;; If there is no 4th child, then this string is the value.
+ (treesit-node-child parent 3 t)
+ (let ((first-auncle (treesit-node-child parent 0 t)))
+ (clojure-ts--symbol-matches-p
+ clojure-ts--variable-definition-symbol-regexp
+ first-auncle)))))
+
+(defun clojure-ts--match-method-docstring (node)
+ "Match NODE when it is a docstring in a method definition."
+ (let* ((grandparent (treesit-node-parent ;; the protocol/interface
+ (treesit-node-parent node))) ;; the method definition
+ (first-grandauncle (treesit-node-child grandparent 0 t)))
+ (clojure-ts--symbol-matches-p
+ clojure-ts--interface-def-symbol-regexp
+ first-grandauncle)))
+
+(defun clojure-ts--match-docstring (_node parent _bol)
+ "Match PARENT when it is a docstring node."
+ (and (clojure-ts--string-node-p parent) ;; We are IN a string
+ (or (clojure-ts--match-def-docstring parent)
+ (clojure-ts--match-fn-docstring parent)
+ (clojure-ts--match-method-docstring parent))))
+
+(defun clojure-ts--semantic-indent-rules ()
+ "Return a list of indentation rules for `treesit-simple-indent-rules'."
`((clojure
((parent-is "source") parent-bol 0)
+ (clojure-ts--match-docstring parent 0)
;; https://guide.clojure.style/#body-indentation
(clojure-ts--match-method-body parent 2)
(clojure-ts--match-expression-in-body parent 2)
- [nongnu] elpa/clojure-ts-mode ae2e248601 01/14: First pass at semantic indentation, (continued)
- [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, 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 <=
- [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
- [nongnu] elpa/clojure-ts-mode 211dc1452b 11/14: Update README docs to include new configuration options, ELPA Syncer, 2023/09/08