Subject: Re: bug#61208: 29.0.60; treesit-beginning/end-of-defun problem with macros in c-ts-mode

From: Eli Zaretskii <[email-masked]>
Date: Thu, 02 Feb 2023 09:16:37 +0200

> From: Yang Yingchao <[email-masked]>
> Cc: Eli Zaretskii <[email-masked]>, Yuan Fu <[email-masked]>,
>  [email-masked]
> Date: Thu, 02 Feb 2023 08:48:55 +0800
> 
> But in the following C++ code, is it possible to make treesit-beginning/end-of-defun behaves the same as c++-mode ?
> 
> ,----
> | class Test       // LINE_D
> | {
> | public:
> |     Test(int i)  // LINE_C
> |     {
> |         SWITCH(i)
> |         {
> |             CASE(A)
> |             {
> |                 ;
> |             }
> |             CASE(B) // LINE_B
> |             {
> |                 ; // LINE_A
> |             }
> |         }
> |     }
> | };
> `----
> 
> 
> When cursor is at LINE_A, if in c++-mode, `C-M-a` moves cursor to LINE_C, which is correct.
> But in c++-ts-mode, behaviour of  `C-M-a` is wrong:
> if treesit-defun-tactic is nested, it moves to line_B, and if treesit-defun-tactic is top-level,
> it moves to LINE_D. Both of them are actually wrong...

I don't necessarily agree that c++-mode is right in this case.  I
think it's sheer luck that it goes to where it goes, and small changes
in the cpp macros could easily defeat its logic.

This is all a consequence of the fact that cpp macros that change the
language syntax could have unexpected influence on what the major mode
does with movement by defuns.  It is not a coincidence that such usage
of cpp macros is discouraged by modern coding conventions and
recommendations.

>From my POV, there's no bug here.  There's no requirement that the TS
modes behave the same as their non-TS brethren.  One could argue that
we introduced the TS modes precisely _because_ they behave
differently.  And where cpp macros are involved, all bets are off to
begin with; good support for them is only possible by teaching the
mode about each and every macro.

So I'm okay with closing this bug as wontfix, unless someone has an
easy way of "fixing" it.