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.devel Subject: Re: Code navigation for sh-mode with Tree-sitter Date: Tue, 6 Dec 2022 13:08:19 -0800 Message-ID: References: <1B9F9B3A-A757-4A65-9653-CD0112EB8895@gmail.com> 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="19060"; mail-complaints-to="usenet@ciao.gmane.io" Cc: =?utf-8?Q?Jo=C3=A3o_Paulo_Labegalini_de_Carvalho?= , Alan Mackenzie , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Dec 06 22:09:05 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 1p2fBZ-0004k5-A5 for ged-emacs-devel@m.gmane-mx.org; Tue, 06 Dec 2022 22:09:05 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p2fB4-0001Yz-Sp; Tue, 06 Dec 2022 16:08:34 -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 1p2fAu-0001UP-RX for emacs-devel@gnu.org; Tue, 06 Dec 2022 16:08:28 -0500 Original-Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p2fAs-0006nw-Qn for emacs-devel@gnu.org; Tue, 06 Dec 2022 16:08:24 -0500 Original-Received: by mail-pl1-x629.google.com with SMTP id d3so15162114plr.10 for ; Tue, 06 Dec 2022 13:08:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=HX9pVXYUp84uF5qAE9z6HkLk/0CQxc3oAXkxR8YPs4o=; b=M/jTeshz+dSfRMLjSXTxVFz/6h9oaNycDo+X7anKylD+vfqKj2guWQvV0js9PpC24P S7aJiPBqy8qcqwbCG51w5JLrWH2ef90R6nYVPrJpNyr3oUpYhwUeAbKRUQ8t1OTyh3GH svh+Doi+9+aJDxAc+Q1kGH/ZI0pAF4sYd6EglNFwHm0DW4XCafIWmC4apZgei//v1trg 540Th8O+dpF4sQnsgDgTDelkOHGwXFeUNWCrgv88Sc3Na4ZhMw9BiGS2futd9DB8oXwr CbwQPRpKOpPJE00Q5SQkahiq7mts5+EqHYtHX8TVyRLM1U6eqrgy7W8/WPEg31XYIVlJ Fy+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HX9pVXYUp84uF5qAE9z6HkLk/0CQxc3oAXkxR8YPs4o=; b=y6P7RR7xCUXw8MBgLhkmtJFF0yIRkPWjkiQtrZ059ScMYHeYpBMx8p02xKz2/+gIF0 MeNFTqoyIf8LKF2mJf9LgyYSBs6clBwHy1HBHNOOlRv12hsyqpRSd+vMOFnkOUHZhehC yJ3sEUZrXgFt9Ucw4JY2ArVi/Au6Ox0y0WLDhhnJyRCz0jC2u6KHa3Qv8741X5MDW94b hztp7UXdGZB0ig+ytL9VfR06GdTvbF3lE+CUoFE5kS6PsYgkXRf/WcNxXSKtp95efRFJ zuD2BnvTWOVqrU0ERcjuGiT4heSNlLWFqLIAt/V+m/MLpzFiwdHgwSBlSfJwHCTn9YTX PkYQ== X-Gm-Message-State: ANoB5plNsjApnqQcFyFuK+0jHfdS6ZE8e966zm9gh9MDQ16AIxOE7QdW caBvw8ME/ItQrAIR9ZmEvSw= X-Google-Smtp-Source: AA0mqf5BcEDtry7O4g+okabA4Bgzhn21yAWt89DbajdLpzv4hypeSziVJYWKOLOKVMuEm2oq7vFHTg== X-Received: by 2002:a17:90a:9e5:b0:219:5139:7fa8 with SMTP id 92-20020a17090a09e500b0021951397fa8mr38721967pjo.15.1670360901342; Tue, 06 Dec 2022 13:08:21 -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 l22-20020a63f316000000b00478d947ed5esm1864406pgh.27.2022.12.06.13.08.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Dec 2022 13:08:20 -0800 (PST) In-Reply-To: <1B9F9B3A-A757-4A65-9653-CD0112EB8895@gmail.com> X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=casouri@gmail.com; helo=mail-pl1-x629.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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:300983 Archived-At: > On Dec 6, 2022, at 1:04 PM, Yuan Fu wrote: >=20 >=20 >=20 >> On Dec 6, 2022, at 8:48 AM, Stefan Monnier = wrote: >>=20 >>>> 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. >>>>=20 >>>=20 >>> 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. >>=20 >> Many major modes do not implement those two functions in a fully >> reliable way, indeed. >>=20 >> `bash-ts-mode` should be able to implement them reliably, OTOH. >>=20 >>> 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: >>=20 >> Yes, it's a common limitation when the major mode is unable to do >> proper parsing of the code. >=20 > It seems there are not convention on whether defun movements should = move across top-level defun=E2=80=99s or both top-level and nested ones. = I=E2=80=99ve seen bug report on python-ts-mode complaining about both = sides. >=20 > 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.=20 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). (2) (1)class class1(): prop =3D 0 def method1(self): pass def method2(self): pass Yuan=