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: Fri, 09 Dec 2022 16:59:25 +0100 Message-ID: <87tu24in4y.fsf@thornhill.no> References: <87lenlnjc1.fsf@posteo.net> <87k035vsph.fsf@thornhill.no> <87h6y8oq0x.fsf@posteo.net> <875yeox1hs.fsf@thornhill.no> <87mt7zplpf.fsf@posteo.net> <87k033zbw3.fsf@thornhill.no> <87h6y51bgk.fsf@posteo.net> Reply-To: Theodor Thornhill Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27169"; 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 Fri Dec 09 17:00:38 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 1p3fnh-0006iv-7U for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 09 Dec 2022 17:00:37 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p3fnM-0002xL-8E; Fri, 09 Dec 2022 11:00:22 -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 1p3fn9-0002wT-S7 for bug-gnu-emacs@gnu.org; Fri, 09 Dec 2022 11:00:04 -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 1p3fn9-0003Fp-Cv for bug-gnu-emacs@gnu.org; Fri, 09 Dec 2022 11:00:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p3fn8-0006EC-Q2 for bug-gnu-emacs@gnu.org; Fri, 09 Dec 2022 11:00:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Theodor Thornhill Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 09 Dec 2022 16:00: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.167060157023891 (code B ref 59853); Fri, 09 Dec 2022 16:00:02 +0000 Original-Received: (at 59853) by debbugs.gnu.org; 9 Dec 2022 15:59:30 +0000 Original-Received: from localhost ([127.0.0.1]:36968 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p3fmb-0006DH-U9 for submit@debbugs.gnu.org; Fri, 09 Dec 2022 10:59:30 -0500 Original-Received: from out2.migadu.com ([188.165.223.204]:42850) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p3fmZ-0006DB-Cv for 59853@debbugs.gnu.org; Fri, 09 Dec 2022 10:59:28 -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=1670601566; 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=NhKrrxDH5EiPFy5rrUv9ktVbHAu3neGB2z2v4rQYeVI=; b=D06yxJSfAchmjvZMeeYGthcsZJdGAbcNaKuNUSFvnSM8wQMMha2NBcC9g3k6eQ3Y4CEJ0s QLY1HrPLCL+PzGOPu7TMRUmOmoRXXp5ImHPGu/cHqTq/d/mNtb0t8Ghss7N9WtV96Y8DNS EsRK4fx5fHuV43swv4AhEJR7slPqIvO7g/H1AJtJrxeQIZ8MGKiztOzb5fRdygInrFo4gc 8hq0gewvFuoMoJ9et4hh45rjt8o9fmNzfFkaF9OPpboLXTpwGOuovIdYPH2DFmlGvc1V+c E2syfHMH4o8Qr0BcYHq447qat1Int2kOXFbyotffamK1+9sHs2hVPDzlqkN6/A== In-Reply-To: <87h6y51bgk.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:250413 Archived-At: Brian Leung writes: > Theodor Thornhill writes: > >>> 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. > > 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 >>> 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. > > 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 > for narrow-to-defun to capture the entire class declaration, since > point is not really contained in either method. (For this > particular example, java-mode presently agrees with java-ts-mode.) > > Is there a clean way of ensuring that, when point lies between > (and is not contained in) those two methods, point is not treated > 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 >>> 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? > > It captures the entire interface definition only when I remove > "method_declaration" (which we probably want to keep) from the > 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. Theo