From 9e339415b4c068242e7cd785d2ac95420f1934ba Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Sat, 24 Sep 2022 20:52:32 -0700 Subject: [PATCH] Fix treesit-induce-sparse-tree MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Because not-at-all-werid way we implemented ts_build_sparse_tree, it’s return value needs a bit post-processing (i.e., reverse its cdr). * src/treesit.c (Ftreesit_induce_sparse_tree): Reverse the top-level children list. (ts_build_sparse_tree): Add comment. --- src/treesit.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/treesit.c b/src/treesit.c index 5917931e444..1a61e354cfd 100644 --- a/src/treesit.c +++ b/src/treesit.c @@ -2041,7 +2041,9 @@ case, only 1 3 4 8 16 would be traversed. */) } /* Recursively traverse the tree under CURSOR, and append the result - subtree to PARENT's cdr. See more in `ts_build_sparse_tree'. */ + subtree to PARENT's cdr. See more in Ftreesit_induce_sparse_tree. + Note that the top-level children list is reversed, because + reasons. */ static void ts_build_sparse_tree (TSTreeCursor *cursor, Lisp_Object parent, Lisp_Object pred, @@ -2151,6 +2153,7 @@ regexp. */) ts_build_sparse_tree (&cursor, parent, predicate, process_fn, the_limit, no_limit, parser); + Fsetcdr (parent, Fnreverse (Fcdr (parent))); if (NILP (Fcdr (parent))) return Qnil; else -- 2.39.5