[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master a4de6d8dd3b 1/7: Add treesit-node-match-p
From: |
Yuan Fu |
Subject: |
master a4de6d8dd3b 1/7: Add treesit-node-match-p |
Date: |
Fri, 14 Apr 2023 20:04:47 -0400 (EDT) |
branch: master
commit a4de6d8dd3b6a5ac39737812e17a2a8d766e9f3a
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Add treesit-node-match-p
* src/treesit.c (Ftreesit_node_match_p): New function.
---
src/treesit.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/src/treesit.c b/src/treesit.c
index dbbfa29c19d..b15a53236e4 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -3612,6 +3612,37 @@ a regexp. */)
return parent;
}
+DEFUN ("treesit-node-match-p",
+ Ftreesit_node_match_p,
+ Streesit_node_match_p, 2, 2, 0,
+ doc: /* Check whether NODE matches PREDICATE.
+
+PREDICATE can be a regexp matching node type, a predicate function,
+and more, see `treesit-things-definition' for detail. Return non-nil
+if NODE matches PRED, nil otherwise. */)
+ (Lisp_Object node, Lisp_Object predicate)
+{
+ CHECK_TS_NODE (node);
+
+ Lisp_Object signal_data = Qnil;
+ if (!treesit_traverse_validate_predicate (predicate, &signal_data))
+ xsignal1 (Qtreesit_invalid_predicate, signal_data);
+
+ Lisp_Object parser = XTS_NODE (node)->parser;
+ TSTreeCursor cursor = ts_tree_cursor_new (XTS_NODE (node)->node);
+
+ specpdl_ref count = SPECPDL_INDEX ();
+ record_unwind_protect_ptr (treesit_traverse_cleanup_cursor, &cursor);
+
+ bool match = false;
+ match = treesit_traverse_match_predicate (&cursor, predicate,
+ parser, false);
+
+ unbind_to (count, Qnil);
+
+ return match ? Qt : Qnil;
+}
+
DEFUN ("treesit-subtree-stat",
Ftreesit_subtree_stat,
Streesit_subtree_stat, 1, 1, 0,
@@ -3879,6 +3910,7 @@ then in the system default locations for dynamic
libraries, in that order. */);
defsubr (&Streesit_search_subtree);
defsubr (&Streesit_search_forward);
defsubr (&Streesit_induce_sparse_tree);
+ defsubr (&Streesit_node_match_p);
defsubr (&Streesit_subtree_stat);
#endif /* HAVE_TREE_SITTER */
defsubr (&Streesit_available_p);
- master updated (c60b59e04c3 -> 67ab357cdcc), Yuan Fu, 2023/04/14
- master a4de6d8dd3b 1/7: Add treesit-node-match-p,
Yuan Fu <=
- master 293029458c8 2/7: Make use of the new pred shapes in treesit.el, Yuan Fu, 2023/04/14
- master 00fba2a4d54 6/7: Add a recursion level limit for tree-sitter search predicates, Yuan Fu, 2023/04/14
- master 67ab357cdcc 7/7: Support treesit-thing-settings in search functions, Yuan Fu, 2023/04/14
- master 9e5c00268ed 3/7: Convert PATTERN and REGEXP to PRED in tree-sitter functions, Yuan Fu, 2023/04/14
- master 531b343c3c7 4/7: Add treesit-thing-settings, Yuan Fu, 2023/04/14
- master 9f777475be5 5/7: ; Minor fixes in treesit.c, Yuan Fu, 2023/04/14