1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-29 07:58:28 +00:00

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.
This commit is contained in:
Yuan Fu 2022-12-18 14:11:54 -08:00
parent c1e015ae32
commit ce7b7e5af3
No known key found for this signature in database
GPG Key ID: 56E19BC57664A442
4 changed files with 23 additions and 44 deletions

View File

@ -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
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.
@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.
comment-start token. Comment-start tokens are defined by regular
expression @code{comment-start-skip}. This function assumes
@var{parent} is the comment node.
@end ftable
@end defvar

View File

@ -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

View File

@ -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)

View File

@ -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.