From 902649a170ab651cffe2bbb421e1331b23c7ed01 Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Wed, 16 Nov 2022 15:13:05 -0800 Subject: [PATCH] Fix treesit-search-forward not matching leaf nodes * src/treesit.c: Match against NODE at start of the loop. --- src/treesit.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/treesit.c b/src/treesit.c index 1e1238eefd3..a05efaf5db5 100644 --- a/src/treesit.c +++ b/src/treesit.c @@ -2654,8 +2654,17 @@ treesit_search_forward (TSNode *start, Lisp_Object pred, Lisp_Object parser, (while node (setq node (treesit-search-forward node))) */ + bool initial = true; while (true) { + if (!initial /* We don't match START. */ + && treesit_traverse_match_predicate (node, pred, parser)) + { + *start = node; + return true; + } + initial = false; + TSNode next = treesit_traverse_sibling_helper (node, forward, named); while (ts_node_is_null (next)) { -- 2.39.2