emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-29 ce7b7e5af3: Remove comment-start-skip preset in tree-sitter ind


From: Yuan Fu
Subject: emacs-29 ce7b7e5af3: Remove comment-start-skip preset in tree-sitter indentation engine
Date: Sun, 18 Dec 2022 17:48:47 -0500 (EST)

branch: emacs-29
commit ce7b7e5af3ddb2863c0c4f6f7c91d1b6c205f1a0
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>

    Remove comment-start-skip preset in tree-sitter indentation engine
    
    Comment indentation should use a adaptive-fill-based indent, rather
    than comment-start-skip.
    
    Also remove manual description of removed variables in treesit.el and
    add documentation for n-p-gp upon request.
    
    * doc/lispref/modes.texi (Parser-based Indentation)
    * lisp/treesit.el (treesit-simple-indent-presets): Add n-p-gp, remove
    treesit-comment-start/end, remove comment-start-skip.
    
    * doc/lispref/parsing.texi (Tree-sitter major modes): Remove
    treesit-comment-start/end.
---
 doc/lispref/modes.texi      | 28 +++++++++++++++-------------
 doc/lispref/parsing.texi    | 14 --------------
 lisp/progmodes/c-ts-mode.el |  1 -
 lisp/treesit.el             | 22 +++++++---------------
 4 files changed, 22 insertions(+), 43 deletions(-)

diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index 9ff9614a66..c44938f392 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -4967,12 +4967,22 @@ first child where parent is @code{argument_list}, use
 (match nil "argument_list" nil nil 0 0)
 @end example
 
+@item n-p-gp
+Short for ``node-parent-grandparent'', this matcher is a function of 3
+arguments: @var{node-type}, @var{parent-type}, and
+@var{grandparent-type}.  It returns a function that is called with 3
+arguments: @var{node}, @var{parent}, and @var{bol}, and returns
+non-@code{nil} if: (1) @var{node-type} matches @var{node}'s type, and
+(2) @var{parent-type} matches @var{parent}'s type, and (3)
+@var{grandparent-type} matches @var{parent}'s parent's type.  If any
+of @var{node-type}, @var{parent-type}, and @var{grandparent-type} is
+@code{nil}, this function doesn't check for it.
+
 @item comment-end
 This matcher is a function that is called with 3 arguments:
 @var{node}, @var{parent}, and @var{bol}, and returns non-@code{nil} if
 point is before a comment ending token.  Comment ending tokens are
-defined by regular expression @code{treesit-comment-end}
-(@pxref{Tree-sitter major modes, treesit-comment-end}).
+defined by regular expression @code{comment-end-skip}
 
 @item first-sibling
 This anchor is a function that is called with 3 arguments: @var{node},
@@ -5009,19 +5019,11 @@ This is useful as the beginning of the buffer is always 
at column 0.
 
 @item comment-start
 This anchor is a function that is called with 3 arguments: @var{node},
-@var{parent}, and @var{bol}, and returns the position right after the
+@var{parent}, and @var{bol}, and returns the position after the
 comment-start token.  Comment-start tokens are defined by regular
-expression @code{treesit-comment-start} (@pxref{Tree-sitter major
-modes, treesit-comment-start}).  This function assumes @var{parent} is
-the comment node.
+expression @code{comment-start-skip}.  This function assumes
+@var{parent} is the comment node.
 
-@item comment-start-skip
-This anchor is a function that is called with 3 arguments: @var{node},
-@var{parent}, and @var{bol}, and returns the position after the
-comment-start token and any whitespace characters following that
-token.  Comment-start tokens are defined by regular expression
-@code{treesit-comment-start}.  This function assumes @var{parent} is
-the comment node.
 @end ftable
 @end defvar
 
diff --git a/doc/lispref/parsing.texi b/doc/lispref/parsing.texi
index af7be2ebf3..adb4c5e6e0 100644
--- a/doc/lispref/parsing.texi
+++ b/doc/lispref/parsing.texi
@@ -1735,20 +1735,6 @@ For more information of these built-in tree-sitter 
features,
 For supporting mixing of multiple languages in a major mode,
 @pxref{Multiple Languages}.
 
-Setting the following local variables allows tree-sitter's indentation
-engine to correctly indent multi-line comments:
-
-@defvar treesit-comment-start
-This should be a regular expression matching an opening comment token.
-For example, it should match @samp{//}, @samp{////}, @samp{/*},
-@samp{/****}, etc., in C.
-@end defvar
-
-@defvar treesit-comment-end
-This should be a regular expression matching a closing comment token.
-For example, it should match @samp{*/}, @samp{****/}, etc., in C.
-@end defvar
-
 @node Tree-sitter C API
 @section Tree-sitter C API Correspondence
 
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 97e29ca13b..8ed1a77637 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -103,7 +103,6 @@ MODE is either `c' or `cpp'."
            ((node-is "case") parent-bol 0)
            ((node-is "preproc_arg") no-indent)
            ((and (parent-is "comment") comment-end) comment-start -1)
-           ((parent-is "comment") comment-start-skip 0)
            ((node-is "labeled_statement") parent-bol 0)
            ((parent-is "labeled_statement") parent-bol c-ts-mode-indent-offset)
            ((match "preproc_ifdef" "compound_statement") point-min 0)
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 16e1a16dbf..82757d298e 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -1047,7 +1047,6 @@ See `treesit-simple-indent-presets'.")
                        (or (null node-index-max)
                            (<= (treesit-node-index node)
                                node-index-max))))))
-        ;; TODO: Document if genuinely useful.
         (cons 'n-p-gp
               (lambda (node-t parent-t grand-parent-t)
                 (lambda (node parent &rest _)
@@ -1108,12 +1107,6 @@ See `treesit-simple-indent-presets'.")
                   (re-search-forward comment-start-skip)
                   (skip-syntax-backward "-")
                   (point))))
-        (cons 'comment-start-skip
-              (lambda (_n parent &rest _)
-                (save-excursion
-                  (goto-char (treesit-node-start parent))
-                  (re-search-forward comment-start-skip)
-                  (point))))
         ;; TODO: Document.
         (cons 'grand-parent
               (lambda (_n parent &rest _)
@@ -1188,6 +1181,10 @@ no-node
 
     Checks that NODE's type matches regexp TYPE.
 
+\(n-p-gp NODE-TYPE PARENT-TYPE GRANDPARENT-TYPE)
+
+    Checks that NODE, its parent, and its grandparent's type.
+
 \(query QUERY)
 
     Queries PARENT with QUERY, and checks if NODE is
@@ -1230,14 +1227,9 @@ point-min
 
 comment-start
 
-    Returns the position after a match for `treesit-comment-start'.
-    Assumes PARENT is a comment node.
-
-comment-start-skip
-
-    Goes to the position that comment-start would return, skips
-    whitespace after that, and returns the resulting position.
-    Assumes PARENT is a comment node.")
+    Goes to the position that `comment-start-skip' would return,
+    skips whitespace backwards, and returns the resulting
+    position.  Assumes PARENT is a comment node.")
 
 (defun treesit--simple-indent-eval (exp)
   "Evaluate EXP.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]