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: Wed, 7 Dec 2022 11:34:05 -0800 Message-ID: <5172C572-732C-4F2E-ADFA-F88FD54895CE@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="18018"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Brian Leung , 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 07 20:35:26 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 1p30CU-0004SI-Bf for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 07 Dec 2022 20:35:26 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p30C9-0002yk-EY; Wed, 07 Dec 2022 14:35:05 -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 1p30C7-0002yE-7f for bug-gnu-emacs@gnu.org; Wed, 07 Dec 2022 14:35: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 1p30C6-0002OC-Px for bug-gnu-emacs@gnu.org; Wed, 07 Dec 2022 14:35:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p30C6-0000JJ-6k for bug-gnu-emacs@gnu.org; Wed, 07 Dec 2022 14:35: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, 07 Dec 2022 19:35: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.16704416561180 (code B ref 59853); Wed, 07 Dec 2022 19:35:02 +0000 Original-Received: (at 59853) by debbugs.gnu.org; 7 Dec 2022 19:34:16 +0000 Original-Received: from localhost ([127.0.0.1]:51838 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p30BL-0000Iy-Vu for submit@debbugs.gnu.org; Wed, 07 Dec 2022 14:34:16 -0500 Original-Received: from mail-pg1-f170.google.com ([209.85.215.170]:42530) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p30BI-0000Is-R3 for 59853@debbugs.gnu.org; Wed, 07 Dec 2022 14:34:14 -0500 Original-Received: by mail-pg1-f170.google.com with SMTP id h33so17247531pgm.9 for <59853@debbugs.gnu.org>; Wed, 07 Dec 2022 11:34:12 -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=BJFznxBqcjPmMe0hSH3521GJtLLN8fvuF+RKx3+HEZ0=; b=ZThSGPgZLcqceeG1Lsj6asJWs8u8y2bVp8AeMeX9GuB5QQAobdKoLj6UfNmaEnBZP6 IVEhda6yHysORXBeM3WdUFz5uhC333aYiDGHGQu6GpTQ5bDh4JXdkQdTnCjK4UNRw25K K7bHkx8fPonCR5X44HlB/rihqnUCgfVedJaby78iVJ8mDp2mESWvU1tSI0l5QAJ/hP4+ suyvLAZdndCDWCUmGSwy6ZBtGeOA4cVkNoVhM9308DPV31KWCrP7BakYyKqzFhYiZUGh BSc0nTvyuMBX4D2x739KBwrjFezUl+kHHcyQyOvmF5QbW5t8wDmyIZXAGP+xUASjBZcH /XcA== 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=BJFznxBqcjPmMe0hSH3521GJtLLN8fvuF+RKx3+HEZ0=; b=W/sUphDDvelwK+VcevKgApfL9pC9FU/2bMUDMM9IGqDZtsk1Fp1wOz7l2mAKmgC/jK 9BZdvxOdOIqOb/ZjFxEXgJ9uGPVJw7Kk0IpPdb8i0CR9qRjhUh7wJahCTIdhVmTxbimL RK3JlayhqsCfSud9sQzT0h6VkwVwPzIxNxKTDrrwbTCQ32kjb0OC7yhGbjLXpvWZzlB9 L/oToNLxejL4ncZSQn/0o9Njdg9MXD/Z2uKaMuyUw4riRRgrhmHjsB7gkhy14u4zzaVd I36di7X60oUHUj3cZ7PjsajbPOHEGpncAKf2eBEoVvkhHfu5KoVHodkrR+gcJvbY+R1e LCgw== X-Gm-Message-State: ANoB5plXkkpBi9BOsyxx6PzM2Uc4WjUmGUIxGu5EMPWRJKFcEYqAprXP FeXX6BLE2OgABTbRKkq2l7Q= X-Google-Smtp-Source: AA0mqf4hBBqXrfWABDRi24TU2U3U38IXaE/EGx4em2FpW/bpVGMCD/BLI91adEMSNSY//b2A4DAAyQ== X-Received: by 2002:a63:fc0a:0:b0:434:7885:6ade with SMTP id j10-20020a63fc0a000000b0043478856ademr70226812pgi.243.1670441646648; Wed, 07 Dec 2022 11:34:06 -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 190-20020a6205c7000000b00573eb4a775esm14378147pff.17.2022.12.07.11.34.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Dec 2022 11:34:06 -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:250214 Archived-At: Theodor Thornhill writes: > Brian Leung writes: > >> Theodor Thornhill writes: >> >>> Not sure I can reproduce this. >> >> Sorry, I made a mistake in my description. I additionally noticed=20 >> additional odd results in java-ts-mode. Let me try again: >> >>> p[u]blic abstract class Class { >>> public static interface Interface { >>> void someMethod(); >>> [*] >>> void otherMethod(); >>> [}] >>> } > > Right - thanks! Now I understand what you describe. I'll try to = answer > them case by case. > >> >> 1. When point is at the "u" in "public", narrow-to-defun cuts off=20 >> "pu" and moves point to "b". > > Yes, this definitely looks like a bug. This is probably because the > whole 'public' keyword maps to the declaration, and we don't move to = the > actual beginning. I can look into this. > >> 2. When point is anywhere in the first line of the class=20 >> declaration, mark-defun highlights "void otherMethod()", instead=20 >> of the entire class declaration. > > Yeah, I think I've fixed this in a patch I just submitted. > >> 3a. When point is at the [*] in between someMethod and=20 >> otherMethod, narrow-to-defun captures "void otherMethod()". I 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. > >> 3b. Arguably, even if point were on the method declarations, we=20 >> might still want to (as plain java-mode does) capture the 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 changes > anything for you? > >> 4. When point is on the closing bracket of the interface=20 >> definition, narrow-to-defun captures >> >>> void otherMethod(); >>> } >>> } >> >> which looks quite unusual to me. > > Yes, I agree with this one. My guess is that this is the same as = number > one. > > What do you think? > > Theo There=E2=80=99s a discussion semi-related to this on emacs-devel, where = Alan mentioned this: In CC Mode, it has been configurable via the user option c-defun-tactic for somewhere between ten and fifteen years. When c-defun-tactic is t, C-M-a/e go to the start/end of the top level defuns. When it is the symbol go-outward, C-M-a/e move to the next start/end of defun, if any, at the current level of class/namespace nesting, and move outwards to the next level of class/namespace nesting when a class/namespace = boundary is reached. If we add this option to tree-sitter, user could decide what bahavior they want. I=E2=80=99m planning to work on that. Though there is already something that can more-or-less do this: treesit-defun-prefer-top-level. Yuan