From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.bugs 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 Message-ID: <963AC74E-57EA-4478-AD4C-8210DBA7EC9C@gmail.com> References: <834js51rf8.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.300.101.1.3\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38023"; mail-complaints-to="usenet@ciao.gmane.io" Cc: yingchao.yang@seaboxdata.com, 61208@debbugs.gnu.org, Theodor Thornhill , yang.yingchao@qq.com To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Feb 02 03:33:11 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pNPPS-0009d4-HC for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 02 Feb 2023 03:33:10 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNPPO-00034c-6g; Wed, 01 Feb 2023 21:33:06 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNPPM-00032E-AT for bug-gnu-emacs@gnu.org; Wed, 01 Feb 2023 21:33:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pNPPK-0006CU-32 for bug-gnu-emacs@gnu.org; Wed, 01 Feb 2023 21:33:04 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pNPPJ-0002aU-Ua for bug-gnu-emacs@gnu.org; Wed, 01 Feb 2023 21:33:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 02 Feb 2023 02:33:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61208 X-GNU-PR-Package: emacs Original-Received: via spool by 61208-submit@debbugs.gnu.org id=B61208.16753051669924 (code B ref 61208); Thu, 02 Feb 2023 02:33:01 +0000 Original-Received: (at 61208) by debbugs.gnu.org; 2 Feb 2023 02:32:46 +0000 Original-Received: from localhost ([127.0.0.1]:60259 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pNPP3-0002Zz-Er for submit@debbugs.gnu.org; Wed, 01 Feb 2023 21:32:45 -0500 Original-Received: from mail-pl1-f173.google.com ([209.85.214.173]:41939) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pNPP1-0002Zm-GN for 61208@debbugs.gnu.org; Wed, 01 Feb 2023 21:32:44 -0500 Original-Received: by mail-pl1-f173.google.com with SMTP id jh15so469971plb.8 for <61208@debbugs.gnu.org>; Wed, 01 Feb 2023 18:32:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=yprmDwQyh++haqqqeDO30uFvkJc6OGoT5AVciEW4ZB0=; b=WVv3dfEwemT/SE5krdkgJSlj8dpX9ru1TFe8kuwSLr8Z9MIeSTDtqDj7ULvEbPo3Rm AA4P5yTNmEpJsvyjegmlHsI3mkKsnkuMnqijBBbrFT8mhgwkWE1fwC7xu9/p9DEueUUH GogeSDvhCbImGSm7SuBs2nSEOWedrgGG6XC9B4isJ5y8eJmuMehzEQmj0jZz5K2uh+0K idSFIZU8qt24LaeKQB3EEMf45ArH3kpjy8iCiv1i8vxRNTi23W+HxB3XnlyGzC/5WyT3 QtmosbB0jdAO5mFvLGeEX2xWyUG3NJMGjRJ9ef1y4j70VAcA8VHXWOE5Q5SDo2iOyukn dMuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yprmDwQyh++haqqqeDO30uFvkJc6OGoT5AVciEW4ZB0=; b=kmXOT57XsarlSMKbhX4GqFkIvt049+qCi81M9xT4n/UP7rxH1Nav5p5kauzZNDLOBZ jiw2VNNfiqSpOpIOvv5dSfjQrdlFij2oqBsE/G0RyZpT6YaCmDxsToyR66Igg0cIUz4x oot9K5hD1h0Z+vOuVw1UCXEKJIxThxdxe7Vz7VJtu5k+gj/SXZ15G7JQlnxED4rX0G8c Ltmod9VnTtArL1puCguvhYpP32yjZkjB0DT6/lCEcSoTPUtDeL4DRMdYYlLyUYKkMVZm i6P28hWzcH2HJKhMX/AHoujML4YK2VIruRC72gslET5i1VVwjZLf3UJUJg3EO65CMUos O14w== X-Gm-Message-State: AO0yUKXmtYgMEmFuDBtzocUgb8h/tBJZm0sWds8ykAYxW4BUgLBbzSxu MPcOu60nKzz+qHlfV1kQ0m4= X-Google-Smtp-Source: AK7set+quIckpprQbK32NIjn4JLMoJ00trWJWXFDQM1swb8Z12dDBonBWHBymrmWpzH77GXdUOdMew== X-Received: by 2002:a05:6a20:8b08:b0:b8:5881:5c3b with SMTP id l8-20020a056a208b0800b000b858815c3bmr4491136pzh.58.1675305157546; Wed, 01 Feb 2023 18:32:37 -0800 (PST) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id z28-20020a63b91c000000b004785a63b44bsm11336331pge.43.2023.02.01.18.32.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Feb 2023 18:32:37 -0800 (PST) In-Reply-To: <834js51rf8.fsf@gnu.org> X-Mailer: Apple Mail (2.3731.300.101.1.3) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:254617 Archived-At: > On Feb 1, 2023, at 4:49 AM, Eli Zaretskii wrote: >=20 >> 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" >>=20 >>=20 >> #define SWITCH() >> #define CASE(name) case name: >>=20 >> void func(int i) // LINE_E >> { >> SWITCH(i) // LINE_D >> { >> CASE(A) // LINE_C >> { >> ; >> } >> CASE(B) // LINE_B >> { >> ; // LINE_A >> } >> } >> } >>=20 >> 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... >=20 > Set treesit-defun-tactic to 'top-level, and your problem is solved. >=20 > 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. >=20 > Maybe also in C++ and Java -- AFAIU they don't have nested functions > either. Treesit-defun-tactic being =E2=80=99nested isn=E2=80=99t the problem = here, at least not the direct cause of the problem. c-ts-mode doesn=E2=80=99= 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=E2=80=99t tell what = they are and parses them as function definitions. I don=E2=80=99t object setting treesit-defun-tactic to =E2=80=99top-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=