From 10f96a8c57b031b521ae8ba5a02413b94ece423b Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Sat, 1 Oct 2022 20:29:35 -0700 Subject: [PATCH] Improve documentation of tree-sitter search functions * doc/lispref/parsing.texi (Retrieving Node): Update manual. * src/treesit.c (treesit-search-subtree) (treesit-search-forwardn) (treesit-induce-sparse-tree): Mention case-insensitivity. * lisp/treesit.el (treesit-simple-indent): Mention case-insensitivity. --- doc/lispref/parsing.texi | 16 ++++++++-------- lisp/treesit.el | 4 ++-- src/treesit.c | 10 ++++++---- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/doc/lispref/parsing.texi b/doc/lispref/parsing.texi index 4ae2c4e3411..05f4050b541 100644 --- a/doc/lispref/parsing.texi +++ b/doc/lispref/parsing.texi @@ -575,10 +575,10 @@ looks for named child. @defun treesit-search-subtree node predicate &optional all backward limit This function traverses the subtree of @var{node} (including @var{node}), and match @var{predicate} with each node along the way. -And @var{predicate} is a regexp that matches against each node's type, -or a function that takes a node and returns nil/non-nil. If a node -matches, that node is returned, if no node ever matches, nil is -returned. +And @var{predicate} is a regexp that matches (case-insensitively) +against each node's type, or a function that takes a node and returns +nil/non-nil. If a node matches, that node is returned, if no node +ever matches, nil is returned. By default, this function only traverses named nodes, if @var{all} is non-nil, it traverses all nodes. If @var{backward} is non-nil, it @@ -590,8 +590,8 @@ that number of levels down in the tree. This function is somewhat similar to @code{treesit-search-subtree}. It also traverse the parse tree and match each node with @var{predicate} (except for @var{start}), where @var{predicate} can be -a regexp or a function. For a tree like the below where @var{start} -is marked 1, this function traverses as numbered: +a (case-insensitive) regexp or a function. For a tree like the below +where @var{start} is marked 1, this function traverses as numbered: @example @group @@ -629,8 +629,8 @@ This function creates a sparse tree from @var{root}'s subtree. Basically, it takes the subtree under @var{root}, and combs it so only the nodes that match @var{predicate} are left, like picking out grapes on the vine. Like previous functions, @var{predicate} can be a regexp -string that matches against each node's type, or a function that takes -a node and return nil/non-nil. +string that matches against each node's type case-insensitively, or a +function that takes a node and return nil/non-nil. For example, for a subtree on the left that consist of both numbers and letters, if @var{predicate} is ``letter only'', the returned tree diff --git a/lisp/treesit.el b/lisp/treesit.el index 4f56a143871..100bf9ac670 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -703,8 +703,8 @@ indentation (target) is in green, current indentation is in red." Stops at the first node after point that matches PREDICATE. PREDICATE can be either a regexp that matches against each node's -type, or a function that takes a node and returns nil/non-nil for -match/no match. +type case-insensitively, or a function that takes a node and +returns nil/non-nil for match/no match. If a node matches, move to that node and return the node, otherwise return nil. SIDE controls whether we move to the start diff --git a/src/treesit.c b/src/treesit.c index c9bccb123f0..d72c99a9747 100644 --- a/src/treesit.c +++ b/src/treesit.c @@ -1973,7 +1973,8 @@ DEFUN ("treesit-search-subtree", Traverse the subtree of NODE, and match PREDICATE with each node along the way. PREDICATE is a regexp string that matches against each -node's type, or a function that takes a node and returns nil/non-nil. +node's type case-insensitively, or a function that takes a node and +returns nil/non-nil. By default, only traverse named nodes, if ALL is non-nil, traverse all nodes. If BACKWARD is non-nil, traverse backwards. If LIMIT is @@ -2018,8 +2019,8 @@ DEFUN ("treesit-search-forward", Start traversing the tree from node START, and match PREDICATE with each node along the way (except START). PREDICATE is a regexp string -that matches against each node's type, or a function that takes a node -and returns nil/non-nil. +that matches against each node's type case-insensitively, or a +function that takes a node and returns nil/non-nil. By default, only search for named nodes, if ALL is non-nil, search for all nodes. If BACKWARD is non-nil, search backwards. @@ -2122,7 +2123,8 @@ DEFUN ("treesit-induce-sparse-tree", Basically, take the subtree under ROOT, and comb it so only the nodes that match PREDICATE are left, like picking out grapes on the vine. -PREDICATE is a regexp string that matches against each node's type. +PREDICATE is a regexp string that matches against each node's type +case-insensitively. For a subtree on the left that consist of both numbers and letters, if PREDICATE is "is letter", the returned tree is the one on the right. -- 2.39.2