From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#59853: 30.0.50; tree-sitter modes have unexpected beginning-of-defun behavior Date: Wed, 07 Dec 2022 12:33:32 +0100 Message-ID: <87k033zbw3.fsf@thornhill.no> References: <87lenlnjc1.fsf@posteo.net> <87k035vsph.fsf@thornhill.no> <87h6y8oq0x.fsf@posteo.net> <875yeox1hs.fsf@thornhill.no> <87mt7zplpf.fsf@posteo.net> Reply-To: Theodor Thornhill 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="35283"; mail-complaints-to="usenet@ciao.gmane.io" Cc: casouri@gmail.com, 59853@debbugs.gnu.org To: Brian Leung Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 07 12:34:40 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 1p2shD-0008up-N8 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 07 Dec 2022 12:34:40 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p2sgv-0003ij-Kr; Wed, 07 Dec 2022 06:34:21 -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 1p2sgk-0003hp-Cu for bug-gnu-emacs@gnu.org; Wed, 07 Dec 2022 06:34:11 -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 1p2sgc-0000ID-2G for bug-gnu-emacs@gnu.org; Wed, 07 Dec 2022 06:34:08 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p2sgb-0003My-Nj for bug-gnu-emacs@gnu.org; Wed, 07 Dec 2022 06:34:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Theodor Thornhill Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 07 Dec 2022 11:34: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.167041282412944 (code B ref 59853); Wed, 07 Dec 2022 11:34:01 +0000 Original-Received: (at 59853) by debbugs.gnu.org; 7 Dec 2022 11:33:44 +0000 Original-Received: from localhost ([127.0.0.1]:49803 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p2sgK-0003Mi-8q for submit@debbugs.gnu.org; Wed, 07 Dec 2022 06:33:44 -0500 Original-Received: from out2.migadu.com ([188.165.223.204]:41440) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p2sgH-0003Mc-OM for 59853@debbugs.gnu.org; Wed, 07 Dec 2022 06:33:43 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1670412819; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=iZm/kYYduV+SMHGWRbOldMvAD6hRK6TyRzNSZVfDYPc=; b=e489cQ6Pd/eKFylmhAVuuiB+UvRfu4C0Jc2X+0ze3Wxev0ENTw/Io9K39SOHZgidfBipAk zLjG+PtqPrIMvzvdVMtmZ7GJMEFfTqdynb+tfBXV2UlT3qCrXYdqvLfMnpnXyLi4mpWlCo AlFKEchc3ujnvg8kP5Y35XR2k11g2kCkQMwppeUIvmzjFDdqM999zhNS/Jce75Ilpm4j27 RUujWOHATN5u4RKCEVFkqJJK8sS3ok4My/iQXPUcugRK4IFonqgmmeKUZ2SjdbYr/9Ar6W 5iTIvTlPUYB+TJaEmKPPtVaaqK9GaXV5q4rVXcEEc6TjbPiw8dlBvK1WfFBtPQ== In-Reply-To: <87mt7zplpf.fsf@posteo.net> X-Migadu-Flow: FLOW_OUT 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:250183 Archived-At: --=-=-= Content-Type: text/plain Brian Leung writes: > Theodor Thornhill writes: > >> Not sure I can reproduce this. > > Sorry, I made a mistake in my description. I additionally noticed > 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 > "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 > declaration, mark-defun highlights "void otherMethod()", instead > 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 > otherMethod, narrow-to-defun captures "void otherMethod()". I feel > that since the methods inside the interface declaration have no > bodies, it makes more sense to capture the entire interface > 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 > might still want to (as plain java-mode does) capture the entire > interface definition, since body-less method declarations don't > 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 > 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 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Make-more-granular-defun-type-regexp.patch >From ef79549e793773b50faea9bad2cd35509e5714e1 Mon Sep 17 00:00:00 2001 From: Theodor Thornhill Date: Wed, 7 Dec 2022 10:07:37 +0100 Subject: [PATCH] Make more granular defun-type-regexp We don't want to match local_variable_declaration and others to hit on beginning-of-defun. The fix is just to make the regexp a bit more granular. * lisp/progmodes/java-ts-mode.el (java-ts-mode): Use regexp-opt to distinguish more granularly. --- lisp/progmodes/java-ts-mode.el | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lisp/progmodes/java-ts-mode.el b/lisp/progmodes/java-ts-mode.el index 2c42505ac9..db2566d655 100644 --- a/lisp/progmodes/java-ts-mode.el +++ b/lisp/progmodes/java-ts-mode.el @@ -317,7 +317,15 @@ java-ts-mode (append "{}():;," electric-indent-chars)) ;; Navigation. - (setq-local treesit-defun-type-regexp "declaration") + (setq-local treesit-defun-type-regexp + (regexp-opt '("method_declaration" + "class_declaration" + "record_declaration" + "interface_declaration" + "enum_declaration" + "import_declaration" + "package_declaration" + "module_declaration"))) ;; Font-lock. (setq-local treesit-font-lock-settings java-ts-mode--font-lock-settings) -- 2.34.1 --=-=-=--