Fix treesit_cursor_helper_1 for zero-width nodes (bug#81436)

* lisp/treesit.el (treesit--some): Add edebug declare.
* src/treesit.c (treesit_cursor_helper_1): Don't use
ts_tree_cursor_goto_first_child_for_byte for zero-width nodes.
This commit is contained in:
Yuan Fu 2026-07-24 01:38:43 -07:00
parent 6b670907fa
commit 29bbd02347
No known key found for this signature in database
GPG key ID: 56E19BC57664A442
2 changed files with 8 additions and 4 deletions

View file

@ -3810,7 +3810,7 @@ the current line if the beginning of the defun is indented."
Return the first non-nil evaluation of BODY.
\(fn (SYM VAL) &rest BODY)"
(declare (indent 1))
(declare (indent 1) (debug ((symbolp form) body)))
(let ((result-sym (gensym))
(val-sym (gensym))
(sym (car sym-val))

View file

@ -4259,9 +4259,13 @@ treesit_cursor_helper_1 (TSTreeCursor *cursor, TSNode *target,
return true;
/* ts_tree_cursor_goto_first_child_for_byte is significantly faster,
so despite it having problems (see bug#60127), we try it
first. */
if (ts_tree_cursor_goto_first_child_for_byte (cursor, start_pos) == -1
so despite it having problems (see bug#60127), we try it first.
Also, ts_tree_cursor_goto_first_child_for_byte can't find
zero-width nodes (which exists and are legit, e.g., markdown's
block_continuation), because a zero-width node can't contain a pos
(end > pos). */
if (start_pos != end_pos
&& ts_tree_cursor_goto_first_child_for_byte (cursor, start_pos) == -1
&& !ts_tree_cursor_goto_first_child (cursor))
return false;