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#59853: 30.0.50; tree-sitter modes have unexpected beginning-of-defun behavior Date: Tue, 20 Dec 2022 21:28:38 -0800 Message-ID: <03F610B9-9B11-4AB8-BE17-A8CB777AE73E@gmail.com> References: <87lenlnjc1.fsf@posteo.net> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) 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="16622"; mail-complaints-to="usenet@ciao.gmane.io" Cc: leungbk@posteo.net, 59853@debbugs.gnu.org To: Theodor Thornhill Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 21 06:29:18 2022 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 1p7rfK-000484-NW for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 21 Dec 2022 06:29:18 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7rf6-0008OK-BF; Wed, 21 Dec 2022 00:29:04 -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 1p7rf5-0008OB-1K for bug-gnu-emacs@gnu.org; Wed, 21 Dec 2022 00:29:03 -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 1p7rf4-00083l-ON for bug-gnu-emacs@gnu.org; Wed, 21 Dec 2022 00:29:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p7rf3-0001ha-Jr for bug-gnu-emacs@gnu.org; Wed, 21 Dec 2022 00:29:01 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <87lenlnjc1.fsf@posteo.net> Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 21 Dec 2022 05:29:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59853 X-GNU-PR-Package: emacs Original-Received: via spool by 59853-submit@debbugs.gnu.org id=B59853.16716005296528 (code B ref 59853); Wed, 21 Dec 2022 05:29:01 +0000 Original-Received: (at 59853) by debbugs.gnu.org; 21 Dec 2022 05:28:49 +0000 Original-Received: from localhost ([127.0.0.1]:49457 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p7req-0001hE-F3 for submit@debbugs.gnu.org; Wed, 21 Dec 2022 00:28:48 -0500 Original-Received: from mail-pf1-f175.google.com ([209.85.210.175]:42808) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p7reo-0001h7-7j for 59853@debbugs.gnu.org; Wed, 21 Dec 2022 00:28:46 -0500 Original-Received: by mail-pf1-f175.google.com with SMTP id 65so9934215pfx.9 for <59853@debbugs.gnu.org>; Tue, 20 Dec 2022 21:28:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:from:to:cc:subject:date:message-id :reply-to; bh=EmQhS2PmRckoar3rrw61mWIVeqmrJM1hpUfvMcvf00U=; b=peaGRko2oo3fg3ykQQWa0uHvcZJSXCftWMc3Y+u165tEJ2SWtiZA+wqWYv+bJckM8w kK8TJTXsBFGXU8X0RY52SoLFvrh4ncbeoVPocInz6hS1/dka4I4ot1vK3DB5sJxzCxpw fBk5Gjj+e2nMhlA2B6ksKdcB2BCJ3aHOX6fH24LqGI7+REjU3jTeEn4D9vvTwuPlp8D6 Drrj8JF8OnFpB/6ceqOQaMV08o70falBb/YmKcJHFDHtlzosWN059FpCKv3WNUt8xo3e uHht06LXCsJMAiKpo1Rjsy4yRsvZfX0p9BoRWu6uHh0ylt/OvDNoY9aOWTBm5kBIsV2L 07Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EmQhS2PmRckoar3rrw61mWIVeqmrJM1hpUfvMcvf00U=; b=PtB9kiopXe15E/2z8stbxw/7Jd/HCTpi3/z9BCAH8eohZkWxkk6vA+8ZLUhAdCcNbW Dwh2dAnjLQ1aaRapyf+3oRLggp+Rh/9gYdw8cAMguszzi0Kp59cPeJ30xKCG45WM1c3V wk/P45kp+CxHTbzfJNluKAYdrLbOCUFypUEFmUAQSrfQan0vDTlDDaoo1gdGQG0hPQ8O k+AHXJptddcp+u+vKgjY3i2JgVcUdO7cggNpi7dZC0CWAJl5fxnVy6rJb2tjqzuFviAF Tu223AhHvjDpl4lF+GnQHagI6/hkz4IGZA1b++jJLscBChUb+c8L1xBAs/eBLG7JYnlI F4gg== X-Gm-Message-State: AFqh2kpc0FhLh3jjrtJ9eigOUsbKrrx3k1V3M7QMpChiDC6tQgwY2Uda Pl5rm5ceiZJBhDOQmLim3/A= X-Google-Smtp-Source: AMrXdXuoh4qND+LvGdSqoOEFkWCuPXrM0PNLp30JgNugXaluMnFEgE637UaVi88rxvF04zuT1o0tjg== X-Received: by 2002:aa7:9e5d:0:b0:57d:c4f3:d4aa with SMTP id z29-20020aa79e5d000000b0057dc4f3d4aamr1125956pfq.23.1671600520061; Tue, 20 Dec 2022 21:28:40 -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 x20-20020aa79574000000b00528a097aeffsm9577939pfq.118.2022.12.20.21.28.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Dec 2022 21:28:39 -0800 (PST) X-Mailer: Apple Mail (2.3696.120.41.1.1) 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:251565 Archived-At: Theodor Thornhill writes: > Brian Leung writes: > >> Theodor Thornhill writes: >> >>>> 2. When point is anywhere in the first line of the class=20 >>>> declaration, mark-defun highlights "void otherMethod()",=20 >>>> instead=20 >>>> of the entire class declaration. >>> >>> Yeah, I think I've fixed this in a patch I just submitted. >> >> Which commit are you referring to? >> > > I believe it was the one I included as a patch here. > >>>> 3a. When point is at the [*] in between someMethod and=20 >>>> otherMethod, narrow-to-defun captures "void otherMethod()". I=20 >>>> feel=20 >>>> that since the methods inside the interface declaration have no=20 >>>> bodies, it makes more sense to capture the entire interface=20 >>>> definition if point is at [*]. >>> >>> Maybe, but I don't believe this is wrong either. >> >> Let me rephrase my request. Consider the following example: >> >>> class Cow implements Animal { >>> public void animalSound() { >>> // The body of animalSound() is provided here >>> System.out.println("The cow says: moo"); >>> } >>> >>> [*] >>> >>> public void sleep() { >>> // The body of sleep() is provided here >>> System.out.println("Zzz"); >>> } >>> } >> >> Both the methods have bodies. If point is at the [*], I would like=20 >> for narrow-to-defun to capture the entire class declaration, since=20 >> point is not really contained in either method. (For this=20 >> particular example, java-mode presently agrees with java-ts-mode.) >> >> Is there a clean way of ensuring that, when point lies between=20 >> (and is not contained in) those two methods, point is not treated=20 >> as if it were in one of those methods' tree-sitter nodes? >> > > I understand. I think that either we need to tweak the > treesit-defun-type-regexp or make use of something like: > > (treesit-node-on (point) (point)) in the code that searches for > beginning/end-of-defun. > > That code should return what you want, right? > >>>> 3b. Arguably, even if point were on the method declarations, we=20 >>>> might still want to (as plain java-mode does) capture the=20 >>>> entire=20 >>>> interface definition, since body-less method declarations don't=20 >>>> feel especially defun-like. >>> >>> Maybe. Can you try applying the below patch and see if this=20 >>> changes >>> anything for you? >> >> It captures the entire interface definition only when I remove=20 >> "method_declaration" (which we probably want to keep) from the=20 >> regexp. > > Yeah. But I believe Yuan is cooking on some code wrt > beginning/end-of-defun, so maybe we should just wait and see what he > comes up with. Oh wait, this report is about narrow-to-defun rather than c-ts-mode-indent-defun, err that=E2=80=99s not fixed yet, because beginning/end-of-defun doens=E2=80=99t use tree-sitter anymore = (headache). I=E2=80=99ll try to address this soon. Yuan