From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yang Yingchao via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#65885: Acknowledgement (29.1.50; wrong behaviour of treesit-beginning-of-defun in c++-ts-mode) Date: Thu, 14 Sep 2023 08:17:56 +0800 Message-ID: References: <871qf4doit.fsf@qq.com> <83h6nzpoeg.fsf@gnu.org> <87wmwv9bhu.fsf@qq.com> <83h6nynued.fsf@gnu.org> Reply-To: yang.yingchao@qq.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30535"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.10.6; emacs 29.1.50 Cc: Yuan Fu , 65885@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Sep 14 02:23: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 1qga8U-0007kb-Kd for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 14 Sep 2023 02:23:11 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qga8J-0005fQ-5A; Wed, 13 Sep 2023 20:22:59 -0400 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 1qga8G-0005ez-Q9 for bug-gnu-emacs@gnu.org; Wed, 13 Sep 2023 20:22:57 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qga8G-0008WB-I0 for bug-gnu-emacs@gnu.org; Wed, 13 Sep 2023 20:22:56 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qga8L-0001nT-U0 for bug-gnu-emacs@gnu.org; Wed, 13 Sep 2023 20:23:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Yang Yingchao Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 14 Sep 2023 00:23:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65885 X-GNU-PR-Package: emacs Original-Received: via spool by 65885-submit@debbugs.gnu.org id=B65885.16946509716890 (code B ref 65885); Thu, 14 Sep 2023 00:23:01 +0000 Original-Received: (at 65885) by debbugs.gnu.org; 14 Sep 2023 00:22:51 +0000 Original-Received: from localhost ([127.0.0.1]:36355 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qga8A-0001n2-Ij for submit@debbugs.gnu.org; Wed, 13 Sep 2023 20:22:51 -0400 Original-Received: from out162-62-57-64.mail.qq.com ([162.62.57.64]:59967) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qga86-0001mk-Qt for 65885@debbugs.gnu.org; Wed, 13 Sep 2023 20:22:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1694650946; bh=CJArjXW6QKw0duLh9m01aOE9SnNGejvbE80l/F9Z+Bs=; h=From:To:Cc:Subject:Date:References:Reply-To:In-reply-to; b=HH3cCUEzSyyTsLVlQXvwSnxmVUieIajQdqMej3y7Q/h5RuERy8lq79Ypt4Nby/0a4 pj8VOYQKPth8KHx/IYtQi/HVSiAvCaJoVINsffTsG375KKa/H1EkGEaG9/HC7axtTA R27khDyhN/3PICpQ5qkp4rl/M6/l5C8YeGnprSys= Original-Received: from tdesk ([60.26.149.220]) by newxmesmtplogicsvrszb9-0.qq.com (NewEsmtp) with SMTP id 5992A2BE; Thu, 14 Sep 2023 08:22:25 +0800 X-QQ-mid: xmsmtpt1694650945t81uonxya X-QQ-XMAILINFO: MzI8mhixeh+ubo5hGtcXPQ48YJE+ecWvlaofF/PmMONxFmw6vmyAYIRYgVuuBC KwG21TbQ3n3CreGxdLap84zHRIr5Yx8Fq4U84TbdUFOfX9rsA6xdl1wMWEZWkPyAKsZr7NbyQ0ww 4BOrAD/HcmORMRK1Mxe6XWgnU/ydjnjbro31eLIdxhlLHqzl41Qx2SAh9AefKYOS/c+1aCB48UpU EA7BQLc9om5aWbigmFdBPh442Fe4Ko/Iskj9TSQkzYG3AGGZ7TcKJEWE2u8NfjIlqz13BpTKzdI9 buKbNFfGDjIrX48ZbySfM0s7ly2y0puYMfjZ1RxK2EMD2uXsnKAbYBkyw7tS2aeVDxpo+7CPJgZS L+z/WX8zza6wokXjJiMXkqsVWuAfmxWxOSrcfVzRQa5Zx4o06+2AJNRn0Gz+TUIWkxNoEC9Icj0x 2IBDgrzM99HQ70EUREye+pIgKHnzUNHJw8BM1egIMLCoxuXlN/sRMJbf99IPUUoHtZ1NEKSW4lsJ wdcE2ZgIVbT1OdDUs+ff6Ui6Ms9+0BfvhrX8ruH5OVX9Fw352uSq0hQoCQ/YmjAlfcsEEqbyOfcr 3k8d796E5iLwpeQ71li++cE+Ol5fiCJhIuUW3hD0a4W6Bt15us8prOd6oR+Whal9kHFLr6Y6dHZs WlqeEsxRJ9iDum2mMFW1vYj6koveJMGehkj4Av2vwCj1+IurRmVk8InVoJExzgXpRDZ5gg2xBQwC RAQPyjsfiS4K1nlSfIhvG8w6A42Jaa4ahGqycYxmAm2p0BPdMTLacblI2Box6XVr8rRCojh/rfyl 4rYLhZ3wFIbuBWXmrkf77xEIWtLvOmS54HgHnNBL X-QQ-XMRINFO: Nq+8W0+stu50PRdwbJxPCL0= In-reply-to: <83h6nynued.fsf@gnu.org> Original-Message-ID: <87led9hadb.fsf@qq.com> 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: , X-ACL-Warn: , Yang Yingchao 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:270380 --=-=-= Content-Type: text/plain Content-Disposition: inline >> From: Yang Yingchao >> Date: Wed, 13 Sep 2023 08:41:27 +0800 >> >> >>> Date: Tue, 12 Sep 2023 12:41:32 +0800 >> >>> From: Yang Yingchao via "Bug reports for GNU Emacs, >> >>> the Swiss army knife of text editors" >> >>> >> >>> It seams that there is an issue with the behavior of `treesit-beginning-of-defun` function in >> >>> `c++-ts-mode` when there are static variables present in the source code. For instance, in the >> >>> provided code snippet, if the cursor is initially placed on the line containing `int b`, and the >> >>> "C-M-a" is pressed, the cursor is positioned on line 4 instead of line 1 where the beginning of >> >>> the function is located. >> >>> >> >>> ,---- >> >>> | void func // c-ts-mode: treesit-beginning-of-defun stops in this line, RIGHT >> >>> | { >> >>> | char * msg; >> >>> | static int a; // c++-ts-mode: treesit-beginning-of-defun stops in this line, WRONG >> >>> | int b; // PUT CUSOR HERE >> >>> | } >> >>> `---- >> >>> >> >>> it works in c-ts-mode works normally. >> >> >> >> If you want c++-ts-mode to work like c-ts-mode, set >> >> treesit-defun-tactic to 'top-level'. By default, we try to support >> >> nested defuns in C++, but not in C. >> > >> > >> > I apologize, but I realized that I have already asked this question before. >> > >> > However, setting 'treesit-defun-tactic' to 'top-level' could cause other >> > issues, as seen in the following snippets: >> > >> > >> > ,---- >> > | class Name { >> > | public: >> > | Name() >> > | { >> > | // cursor here >> > | } >> > | >> > | void func() >> > | { >> > | static int a; >> > | } >> > | >> > | }; >> > `---- >> > >> > Suppose the cursor is in line 5, and "C-M-a" is pressed: >> > >> > - In 'c++-mode', the cursor will be moved to the start of the function 'Name()', which is the expected behavior. >> > - In 'c++-ts-mode': >> > - With 'treesit-defun-tactic' set to 'nested', it behaves the same as in 'c++-mode'. >> > - With 'treesit-defun-tactic' set to 'top-level', the cursor is moved to the beginning of >> > the class, i.e., line 1. >> > >> > Is it possible to make 'c++-ts-mode' behave the same as in 'c++-mode'? >> > >> > Regards. >> >> Maybe I'm wrong, but I would like to suggest reconsidering the solution to the >> 'begging-of-defun' issue related to the static *variable*. It feels strange to me to fix this >> issue by changing the 'treesit-defun-tactic', which is meant to apply to a *function* >> literally... > > Yuan, any ideas or suggestions? Just FYI, I made some modifications to 'treesit--navigate-thing' in my own branch to fix this specific issue: ,---- | 1 file changed, 8 insertions(+) | lisp/treesit.el | 8 ++++++++ | | modified lisp/treesit.el | @@ -2092,6 +2092,14 @@ treesit--navigate-thing | (pcase-let | ((`(,prev ,next ,parent) | (treesit--things-around pos regexp pred))) | + | + ;; YYC: Special handling for static variable inside defun... | + (when (and (equal (treesit-node-type prev) | + "storage_class_specifier") | + (equal (treesit-node-type (treesit-node-parent prev)) | + "declaration")) | + (setq prev nil)) | + | ;; When PARENT is nil, nested and top-level are the same, if | ;; there is a PARENT, make PARENT to be the top-level parent | ;; and pretend there is no nested PREV and NEXT. | `---- --=-=-=--