From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: Code navigation for sh-mode with Tree-sitter Date: Tue, 6 Dec 2022 21:40:34 +0000 Message-ID: References: <1B9F9B3A-A757-4A65-9653-CD0112EB8895@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20775"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Stefan Monnier , =?iso-8859-1?Q?Jo=E3o?= Paulo Labegalini de Carvalho , emacs-devel@gnu.org To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Dec 06 22:41:53 2022 Return-path: Envelope-to: ged-emacs-devel@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 1p2fhI-0005HB-Rx for ged-emacs-devel@m.gmane-mx.org; Tue, 06 Dec 2022 22:41:52 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p2fgW-0008Oc-GG; Tue, 06 Dec 2022 16:41: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 1p2fgP-0008Nn-FH for emacs-devel@gnu.org; Tue, 06 Dec 2022 16:40:57 -0500 Original-Received: from mx3.muc.de ([193.149.48.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p2fgK-0003iC-4O for emacs-devel@gnu.org; Tue, 06 Dec 2022 16:40:55 -0500 Original-Received: (qmail 23091 invoked by uid 3782); 6 Dec 2022 22:40:35 +0100 Original-Received: from acm.muc.de (p4fe157c6.dip0.t-ipconnect.de [79.225.87.198]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Tue, 06 Dec 2022 22:40:34 +0100 Original-Received: (qmail 22113 invoked by uid 1000); 6 Dec 2022 21:40:34 -0000 Content-Disposition: inline In-Reply-To: X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de Received-SPF: pass client-ip=193.149.48.5; envelope-from=acm@muc.de; helo=mx3.muc.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:300984 Archived-At: Hello, Yuan. On Tue, Dec 06, 2022 at 13:08:19 -0800, Yuan Fu wrote: > > On Dec 6, 2022, at 1:04 PM, Yuan Fu wrote: > >> On Dec 6, 2022, at 8:48 AM, Stefan Monnier wrote: > >>>> Calling beginning-of-defun-function followed by > >>>> end-of-defun-function (and comparing the resulting position to the > >>>> start position) should be sufficient to let you know whether or > >>>> not you're inside the function whose definition starts most > >>>> closely before point. > >>> Hmm. In sh-mode `beginning-of-defun-function' is nil and in the > >>> example below, calling `end-of-defun-function' with M-: (funcall > >>> end-of-defun-function) brings point to fi and not the end of the > >>> function. > >> Many major modes do not implement those two functions in a fully > >> reliable way, indeed. > >> `bash-ts-mode` should be able to implement them reliably, OTOH. > >>> In the example above, C-M-a and C-M-e do the right thing. However, > >>> in the presence of nested functions, C-M-a and C-M-e only navigate > >>> over top-level functions. For example: > >> Yes, it's a common limitation when the major mode is unable to do > >> proper parsing of the code. > > It seems there are not convention on whether defun movements should > > move across top-level defun’s or both top-level and nested ones. I’ve > > seen bug report on python-ts-mode complaining about both sides. > > Should we make it configurable, then? A variable that makes > > tree-sitter defun navigation switch between two modes: top-level only > > and not top-level only. 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. I don't remember any complaints about this mechanism. > And for functions nested in a class: if you type C-M-e at the beginning > of a class, should it go to the end of the first function in that > class, or should it go to the end of the class? Right now because of > how end-of-defun works, it will jump to the end of the class if point > is at the beginning of the class (1), and jump to the first function if > point is before the beginning of the class (2). This doesn't seem sensible. > (2) > (1)class class1(): > prop = 0 > def method1(self): > pass > def method2(self): > pass > Yuan -- Alan Mackenzie (Nuremberg, Germany).