From: Yuan Fu <casouri@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: yingchao.yang@seaboxdata.com, 61208@debbugs.gnu.org,
Theodor Thornhill <theo@thornhill.no>,
yang.yingchao@qq.com
Subject: bug#61208: 29.0.60; treesit-beginning/end-of-defun problem with macros in c-ts-mode
Date: Wed, 1 Feb 2023 18:32:26 -0800 [thread overview]
Message-ID: <963AC74E-57EA-4478-AD4C-8210DBA7EC9C@gmail.com> (raw)
In-Reply-To: <834js51rf8.fsf@gnu.org>
> On Feb 1, 2023, at 4:49 AM, Eli Zaretskii <eliz@gnu.org> wrote:
>
>> Cc: yang.yingchao@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@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.
Treesit-defun-tactic being ’nested isn’t the problem here, at least not the direct cause of the problem. c-ts-mode doesn’t consider switch cases or if-else statements as defuns. It only considers function, struct, enum, union, as defun. So in a preprocessed C source file, C-M-a will move point to the beginning of the function, line E. It does not in this particular file because tree-sitter is thrown off by the SWITCH() and CASE() macro: it can’t tell what they are and parses them as function definitions.
I don’t object setting treesit-defun-tactic to ’top-level in c-ts-mode, though. It can hide problems like this. Just be aware that it merely hides the problem.
C++ and Java has classes, and when point is in a class, I think people expect to move to the prev/next method rather than the beginning/end of the class. So nested is still a better default IMO.
Yuan
next prev parent reply other threads:[~2023-02-02 2:32 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <fc907ec5049baaaff04d38dd4ed5ab996500a50b6d723604fff453aad543dc86@mu.id>
2023-02-01 6:33 ` bug#61208: 29.0.60; treesit-beginning/end-of-defun problem with macros in c-ts-mode Yang Yingchao via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-01 12:49 ` Eli Zaretskii
2023-02-01 13:10 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-02 0:48 ` Yang Yingchao via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-02 7:16 ` Eli Zaretskii
[not found] ` <875yckubqb.fsf@qq.com>
2023-02-02 1:48 ` Yang Yingchao via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-02 2:32 ` Yuan Fu [this message]
2023-02-02 7:41 ` Eli Zaretskii
2023-02-02 18:22 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=963AC74E-57EA-4478-AD4C-8210DBA7EC9C@gmail.com \
--to=casouri@gmail.com \
--cc=61208@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=theo@thornhill.no \
--cc=yang.yingchao@qq.com \
--cc=yingchao.yang@seaboxdata.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).