From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Jo=C3=A3o_Paulo_Labegalini_de_Carvalho?= Newsgroups: gmane.emacs.devel Subject: Re: Code navigation for sh-mode with Tree-sitter Date: Tue, 6 Dec 2022 08:51:07 -0700 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000005c8f8705ef2ac6fa" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25572"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 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 16:51:56 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 1p2aEc-0006Qv-Ou for ged-emacs-devel@m.gmane-mx.org; Tue, 06 Dec 2022 16:51:54 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p2aE8-0003Wv-HA; Tue, 06 Dec 2022 10:51:24 -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 1p2aE7-0003Wi-2F for emacs-devel@gnu.org; Tue, 06 Dec 2022 10:51:23 -0500 Original-Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p2aE5-0005Cn-Cm for emacs-devel@gnu.org; Tue, 06 Dec 2022 10:51:22 -0500 Original-Received: by mail-ej1-x632.google.com with SMTP id t17so7300649eju.1 for ; Tue, 06 Dec 2022 07:51:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ARL2BMRRQSnI7bi4vtfUrtm0PDyj7rLyYFFwiU/GUXY=; b=MolvgFjCCFPlMDrtK5OZfvdX7T/O/zsImDc9xApyyRglH35AB1BMMGsvK3FQLtjmnk xrVj+G8FKYQQN5DsxoBE73aYlQkLrr2Cifkj+mLK1G/itc7nA2Q6cUkI9sDUY6+6vCJW ozRBZBlrvoEaBc2mba/YjL0pq5s9Kwx9jypaq8E56CLigSofWJjqfJMlVHMUpQZEEzli GnUye4HKAIkHr9E+GozReZm6i2S9PK0A56WCm+5Q5IQjno6z0ycxUAmlBkTQ5VDtSx+N VPDFfbzI4QqDuZGBPM9v4qg/3w7eH2VFFhKKOXgZbfVNZvVvanXIdiIje3bAlk/9gcsz zDJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ARL2BMRRQSnI7bi4vtfUrtm0PDyj7rLyYFFwiU/GUXY=; b=VIOOiTbn5onJgjhWPTMqDNcKSm9DTcBWxLzxjoDTIdZoMS0xjQCVS7URm0MA7Rmfz7 z6wAGCd3li5lwZF272KGbU3QcTSJUKlLFKGjMzgIa46gbLgMp9sFqgSUu89PNyGlUxp0 B8AOeeahMD3513QbhwEfhR23J8wSWrV296m/x74NYrvGlExGDTCmRkkbxWY8CmYmseZL bNSqpYIetpAeCWFrWBQ1Q8AMe7eemCtr3kbBI4EyWg/qJuQux2p0HtwCmhb0nCUc89+9 Cl0/yXu0RYxYchkfX80X2DMUfXrn5z3mwKEeKTaN6lUiOOjuTFoQSHX5Uq2v/af4QnlN tQuw== X-Gm-Message-State: ANoB5pmb4aF8000BzcXXl6wQ8iHHsh/yLQvfljSqwlrO3H2awqa1qspZ wc8eEWzN2XQ7c+0qgrJpOH1nTCrnN7YHRKLMBEM= X-Google-Smtp-Source: AA0mqf5H1YFhbxgLVgMbLqB0FhQIA74eFqKPAQFt/ImHrX1XLnqirpZ5UQZ85UL6+d+Q2WiqJWUvaYhBbyfp1aSCxho= X-Received: by 2002:a17:906:5784:b0:7c0:e987:cd6d with SMTP id k4-20020a170906578400b007c0e987cd6dmr9337069ejq.429.1670341879171; Tue, 06 Dec 2022 07:51:19 -0800 (PST) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::632; envelope-from=jaopaulolc@gmail.com; helo=mail-ej1-x632.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, HTML_MESSAGE=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:300972 Archived-At: --0000000000005c8f8705ef2ac6fa Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > > > I think for now I will use the same workaround. > > I'd urge you to try and find a way to make it work without such > a workaround. > I definitely will. I am just using the work around for testing. >> Yes. I suggest you submit a bug report for this bug. > > I will put some time into this and see if I can come up with a patch > > before flagging it as a bug. > > Once you get it to work without the above workaround, you'll be able to > write a much better bug report. > Yes, and hopefully I can come up with a patch to improve the behavior as well. > >> To work properly, beginning/end-of-defun need to know whether the > >> starting point is inside a defun or between defuns. > > 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. function foo { if [[ $1 > 0 ]]; then return 24 else return 42 echo "Hello from foo" } 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: function foo { function bar { echo "Hello from bar" } if [[ $1 > 0 ]]; then return 24 else return 42 echo "Hello from foo" } C-M-a/e brings point to beginning/end of foo even when point was inside bar and M-: (funcall end-of-defun-function) brings point to after o in echo. If I define beginning/end-of-defun-function with the functions I wrote, the behavior I intended happens (bringing point to bar in the example above if point was inside bar). --=20 Jo=C3=A3o Paulo L. de Carvalho Ph.D Computer Science | IC-UNICAMP | Campinas , SP - Brazil Postdoctoral Research Fellow | University of Alberta | Edmonton, AB - Canad= a joao.carvalho@ic.unicamp.br joao.carvalho@ualberta.ca --0000000000005c8f8705ef2ac6fa Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
> I think for now I will use the same workaround.

I'd urge you to try and find a way to make it work without such
a workaround.

I definitely will. I am just using t= he work around for testing.=C2=A0

>> Yes.=C2=A0 I suggest you submit a bug report= for this bug.
> I will put some time into this and see if I can come up with a patch > before flagging it as a bug.

Once you get it to work without the above workaround, you'll be able to=
write a much better bug report.

Yes, an= d hopefully I can come up with a patch to improve the behavior as well.
=C2=A0
>> To work properly, beginning/end-of-defun need to know whether the<= br> >> starting point is inside a defun or between defuns.

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 exampl= e below, calling `end-of-defun-function' with M-: (funcall end-of-defun= -function) brings point to fi and not the e= nd of the function.

function foo=C2=A0 {=C2=A0 if [[ $1 > 0 ]]; then
= =C2=A0 =C2=A0 return 24
=C2=A0 el= se
=C2=A0 =C2=A0 return 42=
=C2=A0 echo "Hello from foo"<= br>}

In the example above, C-M-a and C-M-e do the rig= ht thing. However, in the presence of nested functions, C-M-a and C-M-e onl= y navigate over top-level functions.=C2=A0 For example:

function foo=C2=A0 {
=C2=A0 function bar {
=C2=A0 =C2=A0 echo "Hello from bar"= ;
=C2=A0 }
=C2=A0 if [[ $1 >= ; 0 ]]; then
=C2=A0 =C2=A0 return= 24
=C2=A0 else
= =C2=A0 =C2=A0 return 42
=C2=A0 echo "Hello from foo"
}

C-M-a/e bri= ngs point to beginning/end of foo even when point was inside bar and M-: (f= uncall end-of-defun-function) brings point to after o in echo.

If I define= beginning/end-of-defun-function with the functions I wrote, the behavior I= intended happens (bringing point to bar in the example above if point was = inside bar).

--
Jo=C3=A3o Paul= o L. de Carvalho
Ph.D Computer Science | =C2=A0IC-UNICAMP | Campinas , S= P - Brazil
Postdoctoral Research Fellow | University of Alberta | Edmont= on, AB - Canada
--0000000000005c8f8705ef2ac6fa--