]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix treesit-induce-sparse-tree
authorYuan Fu <casouri@gmail.com>
Sun, 25 Sep 2022 03:52:32 +0000 (20:52 -0700)
committerYuan Fu <casouri@gmail.com>
Sun, 25 Sep 2022 04:11:31 +0000 (21:11 -0700)
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

index 5917931e444c1067b0ed68582b6caeb609f2870f..1a61e354cfd162104b40391c73bf281aa1cc43b2 100644 (file)
@@ -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