GNU bug report logs - #61208
29.0.60; treesit-beginning/end-of-defun problem with macros in c-ts-mode

Previous Next

Package: emacs;

Reported by: yingchao.yang <at> seaboxdata.com

Date: Wed, 1 Feb 2023 09:14:02 UTC

Severity: normal

Merged with 61209

Found in version 29.0.60

Full log


View this message in rfc822 format

From: Yang Yingchao <yang.yingchao <at> qq.com>
To: Theodor Thornhill <theo <at> thornhill.no>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 61208 <at> debbugs.gnu.org, Yuan Fu <casouri <at> gmail.com>
Subject: bug#61208: 29.0.60; treesit-beginning/end-of-defun problem with macros in c-ts-mode
Date: Thu, 02 Feb 2023 08:48:55 +0800
[Message part 1 (text/plain, inline)]
On Wed, Feb 01 2023, Theodor Thornhill <theo <at> thornhill.no> wrote:

> Eli Zaretskii <eliz <at> gnu.org> writes:
>
>>> Cc: yang.yingchao <at> qq.com
>>> Date: Wed, 01 Feb 2023 14:33:24 +0800
>>> From:  Yang Yingchao via "Bug reports for GNU Emacs,
>>>  the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
>>>
>>>
>>> #define SWITCH()
>>> #define CASE(name)		case name:
>>>
>>> void func(int i)        // LINE_E
>>> {
>>>     SWITCH(i)           // LINE_D
>>>     {
>>>         CASE(A)         // LINE_C
>>>         {
>>>             ;
>>>         }
>>>         CASE(B)         // LINE_B
>>>         {
>>>             ;           // LINE_A
>>>         }
>>>     }
>>> }
>>>
>>> When cursor is at LINE_A, and stoke `C-M-a`, cursor will go to LINE_B;
>>> then `C-M-a` again, cursor goes to LINE_C, then `C-M-a` again, LINE_D,
>>> and `C-M-a` again, finally to LINE_E...
>>
>> Set treesit-defun-tactic to 'top-level, and your problem is solved.
>>
>> Yuan, Theo: do we want to have that set by default in ts-c-mode?  C
>> doesn't have nested functions, so it should be a better default, what
>> with all the cpp madness that the C grammar doesn't grok.
>>
>> Maybe also in C++ and Java -- AFAIU they don't have nested functions
>> either.
>>
>> WDYT?
>
> I'm fine with that change, I think.  Other, "smaller" constructs can be
> found as sentences or sexps anyway, I think.
>
> Theo

Thanks for the help.

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...


-- 
Yang Yingchao
Yang Yingchao

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.