GNU bug report logs -
#61208
29.0.60; treesit-beginning/end-of-defun problem with macros in c-ts-mode
Previous Next
Full log
View this message in rfc822 format
> From: Yang Yingchao <yang.yingchao <at> qq.com>
> Cc: Eli Zaretskii <eliz <at> gnu.org>, Yuan Fu <casouri <at> gmail.com>,
> 61208 <at> debbugs.gnu.org
> 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.
This bug report was last modified 1 year and 283 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.