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:24:32 -0800 Message-ID: <59CB3DA5-FC95-4604-893B-2697114BD445@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="40114"; 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:25:25 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 1p7rbZ-000AHG-NI for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 21 Dec 2022 06:25:25 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7rbE-0007ry-3A; Wed, 21 Dec 2022 00:25: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 1p7rbC-0007rq-UB for bug-gnu-emacs@gnu.org; Wed, 21 Dec 2022 00:25: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 1p7rbC-0007L8-F1 for bug-gnu-emacs@gnu.org; Wed, 21 Dec 2022 00:25:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p7rbC-0001eB-7l for bug-gnu-emacs@gnu.org; Wed, 21 Dec 2022 00:25:02 -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:25:02 +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.16716002826320 (code B ref 59853); Wed, 21 Dec 2022 05:25:02 +0000 Original-Received: (at 59853) by debbugs.gnu.org; 21 Dec 2022 05:24:42 +0000 Original-Received: from localhost ([127.0.0.1]:49430 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p7rar-0001dq-VF for submit@debbugs.gnu.org; Wed, 21 Dec 2022 00:24:42 -0500 Original-Received: from mail-pj1-f54.google.com ([209.85.216.54]:52161) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p7raq-0001df-Eb for 59853@debbugs.gnu.org; Wed, 21 Dec 2022 00:24:41 -0500 Original-Received: by mail-pj1-f54.google.com with SMTP id gt4so14650518pjb.1 for <59853@debbugs.gnu.org>; Tue, 20 Dec 2022 21:24:40 -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=tBZI1/sEXscJGxg6RjMGQJPlc7xCBMi59zOGTRGsKhw=; b=c09mxWIKp3iCLLecLIrVuMFGBzBttV+o9raR6y/9xPJQ17/HMbYg2GNQq9LdXjDBGS fIgMXtMREgwGlDW7B7el+lpQ7+YhI/9bzUVeqktPpmIomkkWFM18LaKbP9s/BRe0QrzP JpBs40TFPUJjgVwyg24Sfs1ZeUaXpB1MkDdjvnB8IZ6xoD5N73dMzzyFd8NFcbIZ2dzb BfGtn0/Gk07DgZ7CaBm9LLbPmpv2nb+n8g+fVnJuNjBtK957N+jsCIMHPPcEFn1bwMAD ZmWGziGh6rExrQ+aq0QBR2nyy9QL64KS4lm2whG+wfAARRxpRwhoVoyOrI9UFzJaVBgn 5heQ== 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=tBZI1/sEXscJGxg6RjMGQJPlc7xCBMi59zOGTRGsKhw=; b=K5dSlt9qGxAQBblyP+lyHhoHXIJPORo7m5MPpm1S1axR2ZBjfKmhJr5H+XrTdhM5Sf zOW+Pt5Ssvj2VqYSQK7zS5RB1Q6DI5gLZ3+R2NWkVBnqu6RUrOQ9xS6yLdAKx5inuGCx SyAYUp+YXxZywIFN9Om3snaIm90RprXa+ZJCQLm35pQ2vX9CwtEVGzkWi6u70l1dGDTc 4Mn3v1kHhyT8RjRleFMqYVLCE6DZ3kSpF994LTxys1S4XI5YhI8cxPaIohlm6sK11iqB 6kBjJcxNKFxBP8+w1m4Oni7pvVH+j6Z0NKmOnEIF89MuRk82ue7+rGlyiJtyno4aZd/r w9FA== X-Gm-Message-State: AFqh2kp765JbUQle6vlG8zSugTi2ZQRLOt7rJxjLdcmtQ7cNhSv2fW79 s5H4upleNmiCjTlhWA7tvYM= X-Google-Smtp-Source: AMrXdXuOX9sCOxM8cJ6XdqNaRMlj2KiT2VWqhwT/a81IKRKl3q73LygCdE2QQ836zQf81uR4S7xo0Q== X-Received: by 2002:a17:90a:e50d:b0:20d:bd60:ada4 with SMTP id t13-20020a17090ae50d00b0020dbd60ada4mr18328830pjy.32.1671600274494; Tue, 20 Dec 2022 21:24:34 -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 z15-20020a17090a66cf00b00223ed94759csm440086pjl.39.2022.12.20.21.24.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Dec 2022 21:24:34 -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:251564 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. I=E2=80=99ve cooked and served said code. Now beginning/end-of-defun = should work reliably, and you can configure its behavior with treesit-defun-tactic. I also fixed c-ts-mode-indent-defun with the new defun functions. Yuan