Subject: bug#62238: 30.0.50; Unusual interpretation of "S-expressions" in c-ts-mode

From: Theodor Thornhill <[email-masked]>
Date: Sat, 18 Mar 2023 14:32:51 +0100

On 18 March 2023 13:11:15 CET, "Daniel Martín" <[email-masked]> wrote:
>Daniel Martín <[email-masked]> writes:
>
>> Yuan Fu <[email-masked]> writes:
>>
>>>
>>> I tested this on my Emacs session and vanilla session, and both marked
>>> to the closing bracket. I believe forward-sexp should just work by the
>>> syntax table. Perhaps it’s your config or something?
>>>
>>
>> You need to enable c-ts-mode first, which redirects
>> forward-sexp-function to treesit-forward-sexp.
>
>I see in treesit.el that we set forward-sexp-function to
>treesit-forward-sexp when treesit-sexp-type-regexp is set by the major
>mode.  For languages with simple grammars, like C, I think that the
>current approach that uses the syntax table is simpler and less prone to
>errors, because the Tree-sitter function is general and should work for
>every language.  I'd suggest we don't define treesit-sexp-type-regexp in
>c-ts-mode, at least for C.
>
>For languages like TypeScript, whose grammar is more complex, perhaps
>forward-sexp does not work very well and using Tree-sitter to implement
>it gives better results with code that is simpler to understand.
>
>Thanks.

I tend to agree. I think it works pretty well with java for instance, but I'm struggling with the compound_statement node in the c grammar.

If too much of an annoyance, I'm ok with not defining this for c, but maybe someone that writes more c than me can have a go at defining nodes that makes sense?

Theo