Subject: bug#73404: 30.0.50; [forward/kill/etc]-sexp commands do not behave as expected in tree-sitter modes

From: Juri Linkov <[email-masked]>
Date: Sun, 29 Dec 2024 19:58:01 +0200

> So clearly instead of overriding `scan-lists` and `scan-sexps`,
> better would be to add 3 new variables: `forward-list-function`,
> `down-list-function` and `up-list-function`.

Ok, now these 3 functions are added in lisp.el and overridden in treesit.el.

>> What I do know is that in general we'd also want an `up-sexp` operation.
>> Currently we have an ugly kludge in `up-list` to try and use
>> `forward-sexp-function` (which is ugly both because
>> `forward-sexp-function` doesn't really provide the functionality we
>> need, and because it mixes up sexp and list navigation), and it would be
>> good to clean it up.
>
> Agreed, this distinction is required for treesit.  Hopefully,
> this can be achieved by separating `forward-sexp-function`
> and `up-list-function` that in ts-modes could be set to new
> functions either `treesit-up-list` or `treesit-up-sexp`.

Like `treesit-forward-sexp-list` uses `forward-sexp-default-function`
to move between symbols inside lists, I'm going to add syntax-based
fallback in `treesit-down-list` and `treesit-up-list` as well.
This is useful in strings and comments.  This is what `up-list`
already does.  Unfortunately, currently there is such limitation
in `down-list`:

  (when (ppss-comment-or-string-start (syntax-ppss))
    (user-error "This command doesn't work in strings or comments"))

But this is not a problem for `treesit-down-list`.