(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},
@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
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
((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)
(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 _)
(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 _)
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
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.