GNU bug report logs - #58711
Treesit hangs when calling treesit-search-forward

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Wilhelm Kirschbaum <wkirschbaum@HIDDEN>; Keywords: moreinfo; dated Sat, 22 Oct 2022 09:55:01 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
Added tag(s) moreinfo. Request was from Stefan Kangas <stefankangas@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 58711 <at> debbugs.gnu.org:


Received: (at 58711) by debbugs.gnu.org; 11 Nov 2022 06:31:17 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Nov 11 01:31:17 2022
Received: from localhost ([127.0.0.1]:44943 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1otNZN-0005Mf-9G
	for submit <at> debbugs.gnu.org; Fri, 11 Nov 2022 01:31:17 -0500
Received: from mail-lf1-f53.google.com ([209.85.167.53]:38449)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <wilhelm@HIDDEN>) id 1otNZJ-0005MR-OT
 for 58711 <at> debbugs.gnu.org; Fri, 11 Nov 2022 01:31:15 -0500
Received: by mail-lf1-f53.google.com with SMTP id g7so6978431lfv.5
 for <58711 <at> debbugs.gnu.org>; Thu, 10 Nov 2022 22:31:13 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=floatpays.co.za; s=google;
 h=cc:to:subject:message-id:date:from:in-reply-to:references
 :mime-version:from:to:cc:subject:date:message-id:reply-to;
 bh=URWaqSitUXhl/wUUCi6nScXYxRt6+e2sQ7liJV3hfto=;
 b=UnnMI577isgrOG9lnhxki2hpIELEyzzv/TWeUwN2BKNLre8/3wr4M94sjFVhmSLEz6
 rMCYmsgrO2XizVlZk3+OyrZ46i1LJSJTULgu5vV+a0RsD3yXcpjUU9Ug9Zo4imty3T2x
 bi9cg5bfI04sgYcCbz/FIY5eE5IDjkbdO+/Uo=
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=URWaqSitUXhl/wUUCi6nScXYxRt6+e2sQ7liJV3hfto=;
 b=3tH8sM12ED+X32uMo4m+vwCtBErCaanhrSchak3VKi39haSuKZ2zjkH2HlsysY2Dyh
 Pj5KtGpOXZiWfkU9G8G9gXGh4Xxk74LG7bUwqrE+3qQsZr5j7YOQgkHmD6zjBZAS1GMj
 QetLmWUduwqLcUj4/t+Rih3xfk3T1kkK5rP4PnG1FEy03wCtvDj58SPJpAXM0WAtlsWd
 YCxWB8X/RGT1cCydcrrI3+AmTXXd+XWzWsv93+y8cV6VLfF14g4C9N31Cx7PFvhkJPoR
 RrwyDXx33qZbkjciRUr2NJ7TgiUhWFeFgEbWrCUA/0tAnEvhxKGgUaR8QiuVH2EVqP2n
 DTXg==
X-Gm-Message-State: ANoB5pmlrRxM3l8pdP/Y9dT+rnBqnghjjwscuVIo17RE4gXbMt8DxzCH
 wSB4H63VY2EHvKcHR9RKXv8XqSotT4qzYzumc+euwg==
X-Google-Smtp-Source: AA0mqf6KdBILf45NAFrzR6soBoI3vjqXn7Ui0Oub/oRNmKBwUdfaBaLxIXugeXkksoinWXrcOat286VdOXo1NvNzGU4=
X-Received: by 2002:a19:f811:0:b0:4a2:3ca7:3a44 with SMTP id
 a17-20020a19f811000000b004a23ca73a44mr277180lff.23.1668148267644; Thu, 10 Nov
 2022 22:31:07 -0800 (PST)
MIME-Version: 1.0
References: <CAOS0-348zPFJEFNao2Ay06RKygsXv0WMFeLqquWBCJp5VgWbbw@HIDDEN>
 <895A3C87-507A-4FC5-8BAE-B138B35CD40C@HIDDEN>
 <46B629C0-1413-41CE-BDA8-CE14C12B4449@HIDDEN>
 <3054006.Zh9iicr411@HIDDEN>
 <106B8822-FE37-4590-BC77-5FB24FB0758C@HIDDEN>
 <CAJbepr8aYrWRLQ8TTKU=97z+yqhVa=Fsw_Vxthu6EbYidvPNhQ@HIDDEN>
 <82A013FB-9A94-4E57-9FD2-AF8E892241A9@HIDDEN>
 <CAJbepr8Abfdd0RMHoyadoo3+UHjAFFKqQC9FTnk7_YKbVr12Ng@HIDDEN>
 <CAJbepr-3k83dvXjvzJ+fHVsFt=DKhMu08sGmxUGQp=UBu-B9Cw@HIDDEN>
 <CAJbepr8ac81yzpBWpanuehFHrR6W_sUQEU_KXuyeEhkBkbwFqg@HIDDEN>
 <CAJbepr8Zk+X_Trx-46vnqR3UTF2nkkeMDmdmOnNa0g9UyRwCUA@HIDDEN>
 <7B22DC5E-CCC6-4981-AC61-7774FE2846AA@HIDDEN>
In-Reply-To: <7B22DC5E-CCC6-4981-AC61-7774FE2846AA@HIDDEN>
From: Wilhelm Kirschbaum <wilhelm@HIDDEN>
Date: Fri, 11 Nov 2022 08:30:56 +0200
Message-ID: <CAJbepr-SBuNO4mqwOsTiy91dvJ_sqycMzGqatgcj9v9G=3AjXg@HIDDEN>
Subject: Re: bug#58711: Treesit hangs when calling treesit-search-forward
To: Yuan Fu <casouri@HIDDEN>
Content-Type: multipart/alternative; boundary="000000000000ed19cd05ed2c082c"
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 58711
Cc: 58711 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--000000000000ed19cd05ed2c082c
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Thank you. I will spend some time over the weekend to try and have a look.

On Fri, 11 Nov 2022 at 00:07, Yuan Fu <casouri@HIDDEN> wrote:

>
>
> > On Nov 10, 2022, at 12:43 PM, Wilhelm Kirschbaum <
> wilhelm@HIDDEN> wrote:
> >
> > Given the following code
> >
> >  <.foo>  ;; component, start_component
> >  <bar>  ;; tag, start_tag
> >   </bar>;; [cursor here 1)] end_tag
> > </.foo> ;; [cursor here 2] end_component
> >
> > and ast
> >
> > (fragment [0, 0] - [5, 0]
> >   (component [0, 0] - [3, 7]
> >     (start_component [0, 0] - [0, 6]
> >       (component_name [0, 1] - [0, 5]
> >         (function [0, 2] - [0, 5])))
> >     (tag [1, 2] - [2, 8]
> >       (start_tag [1, 2] - [1, 7]
> >         (tag_name [1, 3] - [1, 6]))
> >       (end_tag [2, 2] - [2, 8]
> >         (tag_name [2, 4] - [2, 7])))
> >     (end_component [3, 0] - [3, 7]
> >       (component_name [3, 2] - [3, 6]
> >         (function [3, 3] - [3, 6])))))
> >
> > I do not know how to reliably move from cursor position 1 to start of
> <bar> and from cursor position 2 to start of <.foo>
>
> The snippet below should take you to the corresponding open tag.
>
> (let ((end-node (treesit-search-forward-goto
>                  (treesit-node-at (point))
>                  (rx (or "end_tag" "end_component" "end_slot")) t t)))
>   ;; Go to the corresponding start tag.
>   (goto-char (treesit-node-start (treesit-node-parent end-node))))
>
> >
> > as (treesit-search-forward (treesit-node-at (point)) (rx (or "end_tag"
> "end_component" "end_slot")) t) on position 1 will not look backwards, bu=
t
> find the <./foo> end_component.
> >
> > if i am at the point after the node, how do I find the node before the
> point? once we have the node before the point we can find the correct
> parent and then find the prev sibling to goto.
> >
> > Hope this makes sense.
>
> Yeah, if there is a function that gives you the node right before point,
> treesit-search-forward would work as expected. I=E2=80=99ll see how to ad=
d this
> functionality.
>
> Yuan

--000000000000ed19cd05ed2c082c
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Thank you. I will spend some time over the weekend to try =
and have a look. <br></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" =
class=3D"gmail_attr">On Fri, 11 Nov 2022 at 00:07, Yuan Fu &lt;<a href=3D"m=
ailto:casouri@HIDDEN">casouri@HIDDEN</a>&gt; wrote:<br></div><blockqu=
ote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px=
 solid rgb(204,204,204);padding-left:1ex"><br>
<br>
&gt; On Nov 10, 2022, at 12:43 PM, Wilhelm Kirschbaum &lt;<a href=3D"mailto=
:wilhelm@HIDDEN" target=3D"_blank">wilhelm@HIDDEN</a>&gt;=
 wrote:<br>
&gt; <br>
&gt; Given the following code<br>
&gt; <br>
&gt;=C2=A0 &lt;.foo&gt;=C2=A0 ;; component, start_component<br>
&gt;=C2=A0 &lt;bar&gt;=C2=A0 ;; tag, start_tag<br>
&gt;=C2=A0 =C2=A0&lt;/bar&gt;;; [cursor here 1)] end_tag <br>
&gt; &lt;/.foo&gt; ;; [cursor here 2] end_component<br>
&gt; <br>
&gt; and ast<br>
&gt; <br>
&gt; (fragment [0, 0] - [5, 0]<br>
&gt;=C2=A0 =C2=A0(component [0, 0] - [3, 7]<br>
&gt;=C2=A0 =C2=A0 =C2=A0(start_component [0, 0] - [0, 6]<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0(component_name [0, 1] - [0, 5]<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(function [0, 2] - [0, 5])))<br>
&gt;=C2=A0 =C2=A0 =C2=A0(tag [1, 2] - [2, 8]<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0(start_tag [1, 2] - [1, 7]<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(tag_name [1, 3] - [1, 6]))<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0(end_tag [2, 2] - [2, 8]<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(tag_name [2, 4] - [2, 7])))<br>
&gt;=C2=A0 =C2=A0 =C2=A0(end_component [3, 0] - [3, 7]<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0(component_name [3, 2] - [3, 6]<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(function [3, 3] - [3, 6])))))<br>
&gt; <br>
&gt; I do not know how to reliably move from cursor position 1 to start of =
&lt;bar&gt; and from cursor position 2 to start of &lt;.foo&gt;<br>
<br>
The snippet below should take you to the corresponding open tag.<br>
<br>
(let ((end-node (treesit-search-forward-goto<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(treesit-node=
-at (point))<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(rx (or &quot=
;end_tag&quot; &quot;end_component&quot; &quot;end_slot&quot;)) t t)))<br>
=C2=A0 ;; Go to the corresponding start tag.<br>
=C2=A0 (goto-char (treesit-node-start (treesit-node-parent end-node))))<br>
<br>
&gt; <br>
&gt; as (treesit-search-forward (treesit-node-at (point)) (rx (or &quot;end=
_tag&quot; &quot;end_component&quot; &quot;end_slot&quot;)) t) on position =
1 will not look backwards, but find the &lt;./foo&gt; end_component. <br>
&gt; <br>
&gt; if i am at the point after the node, how do I find the node before the=
 point? once we have the node before the point we can find the correct pare=
nt and then find the prev sibling to goto. <br>
&gt; <br>
&gt; Hope this makes sense. <br>
<br>
Yeah, if there is a function that gives you the node right before point, tr=
eesit-search-forward would work as expected. I=E2=80=99ll see how to add th=
is functionality.<br>
<br>
Yuan</blockquote></div>

--000000000000ed19cd05ed2c082c--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#58711; Package emacs. Full text available.

Message received at 58711 <at> debbugs.gnu.org:


Received: (at 58711) by debbugs.gnu.org; 10 Nov 2022 22:07:52 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Nov 10 17:07:52 2022
Received: from localhost ([127.0.0.1]:44569 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1otFiB-0005IR-OT
	for submit <at> debbugs.gnu.org; Thu, 10 Nov 2022 17:07:52 -0500
Received: from mail-pj1-f48.google.com ([209.85.216.48]:43729)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <casouri@HIDDEN>) id 1otFi8-0005ID-HS
 for 58711 <at> debbugs.gnu.org; Thu, 10 Nov 2022 17:07:50 -0500
Received: by mail-pj1-f48.google.com with SMTP id
 d13-20020a17090a3b0d00b00213519dfe4aso3104375pjc.2
 for <58711 <at> debbugs.gnu.org>; Thu, 10 Nov 2022 14:07:48 -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=WqQ7y9zw8KVyzW9vq+ehuTVMmcPt3decTX1QKNhQOgg=;
 b=f8sTU/LU2G16f3KoSHO/10QFsupkQkmeFDSvGlW7rLIq5lIjSP27kW9ZpU0+FuULld
 oKCmrATC9c84PGJNnsVxreOwxfnXXnGl6ljEJGJW4RWCWcEYWFRVONDGsaGyMXoSSWZc
 UGWyHIo1tNrQmBl6go26gEJilOF/3OFrD/5ngHtvY03r7PXQP6Bn7+N8Sf9ytRl2jnlC
 OlEufz6OTPmWIJQzStiavb7lf5sjjUog4+9iYBfOIZzzItm0RmmV4omU2tWSvietae9P
 e7WDQSKZp0MYkIFn9z+I8FMqt/S63UcWMwz0yE9GCqoaw6s43fBSvSDkfCfcLdys3BoR
 jLwQ==
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=WqQ7y9zw8KVyzW9vq+ehuTVMmcPt3decTX1QKNhQOgg=;
 b=bmfBEUmrq7KTHa4b+Nz/yRWEl7v4pzAq5SSqsM4ZDVNZO8EF0BJHQSvFBg2Sv1olCk
 dRy+/OY4V87kjWVDdMvI82kU3k41Qd4zTFlnBmMnU2q+d6dqNHf4TU3cC39mn/I3mQuS
 aplZxnPa1DZ+VBzRRP63f1fg74aD4E3pCl0tRTFl97iArjrpizsGS6QIQkl7SUcCSHet
 4fHiCtVRrUzU/oCNjP/R4i1oDkQaflSQtLM+Jd+yDG/iGa5IvHQZF9+R1kYtjOczMFT5
 3krq75mwy9C3s2AJP1xCYAOHyc3ZzNXXcALZTCKHF6s4VRBpaJRTbSOerB5r2TAYo1qf
 Ljtg==
X-Gm-Message-State: ACrzQf3NlLH6HBz6/4VDF+ywTOv3a8hVec8PS6fpVA93GzN7aDqGzae1
 oVa+skfAUu39IIN0cC1M4w8=
X-Google-Smtp-Source: AMsMyM6o5kVr5JzCVQmNwJsm3dJNX1Og+6EbryOMvDld2Cz9RAYwGx61ZrKkTXNiKr1hwmvYhRnLTQ==
X-Received: by 2002:a17:90a:f305:b0:214:150f:1d54 with SMTP id
 ca5-20020a17090af30500b00214150f1d54mr2225812pjb.219.1668118062324; 
 Thu, 10 Nov 2022 14:07:42 -0800 (PST)
Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com.
 [172.117.161.177]) by smtp.gmail.com with ESMTPSA id
 b4-20020a1709027e0400b00188a1ae94bbsm187098plm.23.2022.11.10.14.07.41
 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
 Thu, 10 Nov 2022 14:07:41 -0800 (PST)
Content-Type: text/plain;
	charset=utf-8
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\))
Subject: Re: bug#58711: Treesit hangs when calling treesit-search-forward
From: Yuan Fu <casouri@HIDDEN>
In-Reply-To: <CAJbepr8Zk+X_Trx-46vnqR3UTF2nkkeMDmdmOnNa0g9UyRwCUA@HIDDEN>
Date: Thu, 10 Nov 2022 14:07:40 -0800
Content-Transfer-Encoding: quoted-printable
Message-Id: <7B22DC5E-CCC6-4981-AC61-7774FE2846AA@HIDDEN>
References: <CAOS0-348zPFJEFNao2Ay06RKygsXv0WMFeLqquWBCJp5VgWbbw@HIDDEN>
 <895A3C87-507A-4FC5-8BAE-B138B35CD40C@HIDDEN>
 <46B629C0-1413-41CE-BDA8-CE14C12B4449@HIDDEN>
 <3054006.Zh9iicr411@HIDDEN>
 <106B8822-FE37-4590-BC77-5FB24FB0758C@HIDDEN>
 <CAJbepr8aYrWRLQ8TTKU=97z+yqhVa=Fsw_Vxthu6EbYidvPNhQ@HIDDEN>
 <82A013FB-9A94-4E57-9FD2-AF8E892241A9@HIDDEN>
 <CAJbepr8Abfdd0RMHoyadoo3+UHjAFFKqQC9FTnk7_YKbVr12Ng@HIDDEN>
 <CAJbepr-3k83dvXjvzJ+fHVsFt=DKhMu08sGmxUGQp=UBu-B9Cw@HIDDEN>
 <CAJbepr8ac81yzpBWpanuehFHrR6W_sUQEU_KXuyeEhkBkbwFqg@HIDDEN>
 <CAJbepr8Zk+X_Trx-46vnqR3UTF2nkkeMDmdmOnNa0g9UyRwCUA@HIDDEN>
To: Wilhelm Kirschbaum <wilhelm@HIDDEN>
X-Mailer: Apple Mail (2.3696.120.41.1.1)
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 58711
Cc: 58711 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)



> On Nov 10, 2022, at 12:43 PM, Wilhelm Kirschbaum =
<wilhelm@HIDDEN> wrote:
>=20
> Given the following code
>=20
>  <.foo>  ;; component, start_component
>  <bar>  ;; tag, start_tag
>   </bar>;; [cursor here 1)] end_tag=20
> </.foo> ;; [cursor here 2] end_component
>=20
> and ast
>=20
> (fragment [0, 0] - [5, 0]
>   (component [0, 0] - [3, 7]
>     (start_component [0, 0] - [0, 6]
>       (component_name [0, 1] - [0, 5]
>         (function [0, 2] - [0, 5])))
>     (tag [1, 2] - [2, 8]
>       (start_tag [1, 2] - [1, 7]
>         (tag_name [1, 3] - [1, 6]))
>       (end_tag [2, 2] - [2, 8]
>         (tag_name [2, 4] - [2, 7])))
>     (end_component [3, 0] - [3, 7]
>       (component_name [3, 2] - [3, 6]
>         (function [3, 3] - [3, 6])))))
>=20
> I do not know how to reliably move from cursor position 1 to start of =
<bar> and from cursor position 2 to start of <.foo>

The snippet below should take you to the corresponding open tag.

(let ((end-node (treesit-search-forward-goto
                 (treesit-node-at (point))
                 (rx (or "end_tag" "end_component" "end_slot")) t t)))
  ;; Go to the corresponding start tag.
  (goto-char (treesit-node-start (treesit-node-parent end-node))))

>=20
> as (treesit-search-forward (treesit-node-at (point)) (rx (or "end_tag" =
"end_component" "end_slot")) t) on position 1 will not look backwards, =
but find the <./foo> end_component.=20
>=20
> if i am at the point after the node, how do I find the node before the =
point? once we have the node before the point we can find the correct =
parent and then find the prev sibling to goto.=20
>=20
> Hope this makes sense.=20

Yeah, if there is a function that gives you the node right before point, =
treesit-search-forward would work as expected. I=E2=80=99ll see how to =
add this functionality.

Yuan=




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#58711; Package emacs. Full text available.

Message received at 58711 <at> debbugs.gnu.org:


Received: (at 58711) by debbugs.gnu.org; 10 Nov 2022 20:43:56 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Nov 10 15:43:55 2022
Received: from localhost ([127.0.0.1]:44497 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1otEOx-0003Ix-2c
	for submit <at> debbugs.gnu.org; Thu, 10 Nov 2022 15:43:55 -0500
Received: from mail-lf1-f42.google.com ([209.85.167.42]:46990)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <wilhelm@HIDDEN>) id 1otEOr-0003Ig-32
 for 58711 <at> debbugs.gnu.org; Thu, 10 Nov 2022 15:43:53 -0500
Received: by mail-lf1-f42.google.com with SMTP id bp15so5303377lfb.13
 for <58711 <at> debbugs.gnu.org>; Thu, 10 Nov 2022 12:43:49 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=floatpays.co.za; s=google;
 h=cc:to:subject:message-id:date:from:in-reply-to:references
 :mime-version:from:to:cc:subject:date:message-id:reply-to;
 bh=Zs0ol0n/8TuaJtyJTctFMFkSp5mqoYeN9t4GJv8BXMU=;
 b=bDUq6LpN77NqGxYxAWKLOB256vSg2eZnumwY2mtKe/vUbS42H168RLwPe11oC1hIRw
 iDqnIqn1RLDgu22gavgxFysouSoVc8LWJEEwxBkvDSLSY4YwiZ2URGbAtJfwZQ2P6MkL
 X33TCUX9d3ayzMZ1WKj1zF+Eaz5XlP1YK8gUw=
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=Zs0ol0n/8TuaJtyJTctFMFkSp5mqoYeN9t4GJv8BXMU=;
 b=4d1J3+bLrNKVg68hY8a5BYLxzvVF9TccNgS2SlnocwzSBfd1xaxclLzUNAAA2Jzwwc
 s2HSmD+thW6vw8CYSSWDAiP+ig+1cGClwZgK2cnmfym69sK4pGD/O3/QK8FFTHCkIGOO
 j63FTsTydhoj6Kn5bXI3tM4hodSVapvOQ1gaB32yS8K9D2CHDAJjwhQi21g4OQT7IeRx
 cpEx/JEQcaKs3XjgIk/SY+6mZ04+AlGJezi7RkSe2Y2Vd7ymj9GbgVBLpKx2LZRlZltx
 j/kjMivlQlGtanSeNQeaBfyuHjdRX3X5wKcVxC6sAOljS46GwJrKB8rU/tzVm+5zHDK1
 I+hQ==
X-Gm-Message-State: ACrzQf1F1xzjYuC49RWJUqYt/UPOgI7VO9QbRCBFT+jevupvnJZtnL9F
 I0R0L8kylP2dRvDowAZ/gCk4UDHeGJErv3PgmJ2WzA==
X-Google-Smtp-Source: AMsMyM4b2Vj39igZgTXUtsncmivIVHh3i7HtcKOts5c+joxCeebwNkLaWYGY94vJwWtPGUK7vbae4Eh3jrASaTplehg=
X-Received: by 2002:ac2:4ecc:0:b0:4a2:bbdc:1430 with SMTP id
 p12-20020ac24ecc000000b004a2bbdc1430mr1796750lfr.404.1668113022969; Thu, 10
 Nov 2022 12:43:42 -0800 (PST)
MIME-Version: 1.0
References: <CAOS0-348zPFJEFNao2Ay06RKygsXv0WMFeLqquWBCJp5VgWbbw@HIDDEN>
 <895A3C87-507A-4FC5-8BAE-B138B35CD40C@HIDDEN>
 <46B629C0-1413-41CE-BDA8-CE14C12B4449@HIDDEN>
 <3054006.Zh9iicr411@HIDDEN>
 <106B8822-FE37-4590-BC77-5FB24FB0758C@HIDDEN>
 <CAJbepr8aYrWRLQ8TTKU=97z+yqhVa=Fsw_Vxthu6EbYidvPNhQ@HIDDEN>
 <82A013FB-9A94-4E57-9FD2-AF8E892241A9@HIDDEN>
 <CAJbepr8Abfdd0RMHoyadoo3+UHjAFFKqQC9FTnk7_YKbVr12Ng@HIDDEN>
 <CAJbepr-3k83dvXjvzJ+fHVsFt=DKhMu08sGmxUGQp=UBu-B9Cw@HIDDEN>
 <CAJbepr8ac81yzpBWpanuehFHrR6W_sUQEU_KXuyeEhkBkbwFqg@HIDDEN>
In-Reply-To: <CAJbepr8ac81yzpBWpanuehFHrR6W_sUQEU_KXuyeEhkBkbwFqg@HIDDEN>
From: Wilhelm Kirschbaum <wilhelm@HIDDEN>
Date: Thu, 10 Nov 2022 22:43:31 +0200
Message-ID: <CAJbepr8Zk+X_Trx-46vnqR3UTF2nkkeMDmdmOnNa0g9UyRwCUA@HIDDEN>
Subject: Re: bug#58711: Treesit hangs when calling treesit-search-forward
To: Yuan Fu <casouri@HIDDEN>
Content-Type: multipart/alternative; boundary="0000000000002e024d05ed23d4a6"
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 58711
Cc: 58711 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--0000000000002e024d05ed23d4a6
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Given the following code

 <.foo>  ;; component, start_component
 <bar>  ;; tag, start_tag
  </bar>;; [cursor here 1)] end_tag
</.foo> ;; [cursor here 2] end_component

and ast

(fragment [0, 0] - [5, 0]
  (component [0, 0] - [3, 7]
    (start_component [0, 0] - [0, 6]
      (component_name [0, 1] - [0, 5]
        (function [0, 2] - [0, 5])))
    (tag [1, 2] - [2, 8]
      (start_tag [1, 2] - [1, 7]
        (tag_name [1, 3] - [1, 6]))
      (end_tag [2, 2] - [2, 8]
        (tag_name [2, 4] - [2, 7])))
    (end_component [3, 0] - [3, 7]
      (component_name [3, 2] - [3, 6]
        (function [3, 3] - [3, 6])))))

I do not know how to reliably move from cursor position 1 to start of <bar>
and from cursor position 2 to start of <.foo>

as (treesit-search-forward (treesit-node-at (point)) (rx (or "end_tag"
"end_component" "end_slot")) t) on position 1 will not look backwards, but
find the <./foo> end_component.

if i am at the point after the node, how do I find the node before the
point? once we have the node before the point we can find the correct
parent and then find the prev sibling to goto.

Hope this makes sense.


On Thu, 10 Nov 2022 at 21:32, Wilhelm Kirschbaum <wilhelm@HIDDEN>
wrote:

> Sorry, I see something like this makes sense and is not the prev-sibling
> issue.
>
> (defun heex--treesit-backward-sexp ()
>   "Forward sexp for Heex using treesit."
>   (let* ((node (treesit-search-forward
>                 (treesit-node-at (point))
>                 (rx (or "end_tag" "end_component" "end_slot"))
>                 t))
>          (sibling (treesit-node-prev-sibling node)))
>     (when sibling
>       (goto-char (treesit-node-start sibling)))))
>
> Just need to handle the outermost (fragment peace and should work then.
>
> Thanks for the help.
>
> On Thu, 10 Nov 2022 at 21:05, Wilhelm Kirschbaum <wilhelm@HIDDEN=
>
> wrote:
>
>> Full implementation here:
>> https://github.com/wkirschbaum/elixir-mode/blob/main/heex-mode.el
>>
>> On Thu, 10 Nov 2022 at 21:03, Wilhelm Kirschbaum <wilhelm@HIDDEN=
a>
>> wrote:
>>
>>> forward-sexp works well with the below code, but when calling
>>> treesit-node-prev-sibling it will traverse up the list, which is then
>>> breaking backward-up-list when defining forward-sexp in the major mode.
>>>
>>> (defun heex--treesit-largest-node-at-point ()
>>>   "Find the largest node at point."
>>>   (save-excursion
>>>     (forward-comment (point-max))
>>>     (let ((node-list
>>>            (cl-loop for node =3D (treesit-node-at (point))
>>>                     then (treesit-node-parent node)
>>>                     while node
>>>                     if (eq (treesit-node-start node)
>>>                            (point))
>>>                     collect node)))
>>>       (car (last node-list)))))
>>>
>>> (defun heex--treesit-backward-sexp ()
>>>   "Forward sexp for Heex using treesit."
>>>   (let* ((largest-node (heex--treesit-largest-node-at-point))
>>>          (sibling (treesit-node-prev-sibling largest-node)))
>>>     (when sibling
>>>       (goto-char (treesit-node-start sibling)))))
>>>
>>> (defun heex--treesit-forward-sexp ()
>>>   "Forward sexp for Heex using treesit."
>>>   (let* ((largest-node (heex--treesit-largest-node-at-point))
>>>          (sibling (treesit-node-next-sibling largest-node)))
>>>     (when sibling
>>>       (goto-char (treesit-node-start sibling))
>>>       (forward-comment (- (point-max))))))
>>>
>>> On Thu, 10 Nov 2022 at 10:14, Yuan Fu <casouri@HIDDEN> wrote:
>>>
>>>>
>>>>
>>>> > On Nov 9, 2022, at 10:44 PM, Wilhelm Kirschbaum <
>>>> wilhelm@HIDDEN> wrote:
>>>> >
>>>> > I finally had some time to have a look. I don't see any more issues,
>>>> thank you for the fantastic work on this. The defun-type-regexp is not
>>>> enough to identify a defun in elixir this is the query I am using curr=
ently:
>>>> >
>>>> > (defvar elixir--treesit-query-defun
>>>> >   (let ((query `((call
>>>> >      target: (identifier) @type
>>>> >      (arguments
>>>> >       [
>>>> >        (alias) @name
>>>> >        (identifier) @name
>>>> >        (call target: (identifier)) @name
>>>> >        (binary_operator
>>>> >         left: (call target: (identifier)) @name
>>>> >         operator: "when")
>>>> >        ])
>>>> >      (:match ,elixir--definition-keywords-re @type)
>>>> >      ))))
>>>> >     (treesit-query-compile 'elixir query)))
>>>> >
>>>> > Regex will work in most cases I guess, but does not really deal with
>>>> more complex queries for more complex cases like in elixir as there is=
 not
>>>> one type which is always the defun. elixir relies heavily on macros an=
d
>>>> different defun macros can be defined on the fly.
>>>>
>>>> You can try the following procedure: use a regex to find the
>>>> next/previous call, then perform some check on whether it=E2=80=99s in=
deed a defun,
>>>> if not, keep searching for the next/previous call.
>>>>
>>>>
>>>> > Maybe if there is an option for using either a regex or a function?
>>>>
>>>> Yes, instead of a regex you can pass a predicate function.
>>>>
>>>> >
>>>> > I am also not sure how forward-sexp can work with the current
>>>> treesit-search-forward-goto function as it does not take into consider=
ation
>>>> the level. Is there perhaps a way to move forward/backward, but do not=
 jump
>>>> to parents or children?
>>>>
>>>> If you want to move in the same level, perhaps you can use
>>>> treesit-next/prev/sibling?
>>>>
>>>> Yuan
>>>
>>>

--0000000000002e024d05ed23d4a6
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Given the following code</div><div><br></div><div>=C2=
=A0&lt;.foo&gt;=C2=A0 ;; component, start_component<br>=C2=A0&lt;bar&gt;=C2=
=A0 ;; tag, start_tag<br>=C2=A0 &lt;/bar&gt;;; [cursor here 1)] end_tag <br=
>&lt;/.foo&gt; ;; [cursor here 2] end_component<br></div><div><br></div><di=
v>and ast</div><div><br>(fragment [0, 0] - [5, 0]<br>=C2=A0 (component [0, =
0] - [3, 7]<br>=C2=A0 =C2=A0 (start_component [0, 0] - [0, 6]<br>=C2=A0 =C2=
=A0 =C2=A0 (component_name [0, 1] - [0, 5]<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 (=
function [0, 2] - [0, 5])))<br>=C2=A0 =C2=A0 (tag [1, 2] - [2, 8]<br>=C2=A0=
 =C2=A0 =C2=A0 (start_tag [1, 2] - [1, 7]<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 (t=
ag_name [1, 3] - [1, 6]))<br>=C2=A0 =C2=A0 =C2=A0 (end_tag [2, 2] - [2, 8]<=
br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 (tag_name [2, 4] - [2, 7])))<br>=C2=A0 =C2=
=A0 (end_component [3, 0] - [3, 7]<br>=C2=A0 =C2=A0 =C2=A0 (component_name =
[3, 2] - [3, 6]<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 (function [3, 3] - [3, 6])))=
))<br><br></div><div>I do not know how to reliably move from cursor positio=
n 1 to start of &lt;bar&gt; and from cursor position 2 to start of &lt;.foo=
&gt;</div><div><br></div><div>as (treesit-search-forward (treesit-node-at (=
point)) (rx (or &quot;end_tag&quot; &quot;end_component&quot; &quot;end_slo=
t&quot;)) t) on position 1 will not look backwards, but find the &lt;./foo&=
gt; end_component. <br><br></div><div>if i am at the point after the node, =
how do I find the node before the point? once we have the node before the p=
oint we can find the correct parent and then find the prev sibling to goto.=
 <br></div><div><br></div><div>Hope this makes sense. <br></div><div><br></=
div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_at=
tr">On Thu, 10 Nov 2022 at 21:32, Wilhelm Kirschbaum &lt;<a href=3D"mailto:=
wilhelm@HIDDEN">wilhelm@HIDDEN</a>&gt; wrote:<br></div><b=
lockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-le=
ft:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr"><div>Sorry=
, I see something like this makes sense and is not the prev-sibling issue. =
<br></div><div><br></div><div>(defun heex--treesit-backward-sexp ()<br>=C2=
=A0 &quot;Forward sexp for Heex using treesit.&quot;<br>=C2=A0 (let* ((node=
 (treesit-search-forward<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 (treesit-node-at (point))<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 (rx (or &quot;end_tag&quot; &quot;end_component&quot; =
&quot;end_slot&quot;))<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 t))<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sibling (treesit-node-prev=
-sibling node)))<br>=C2=A0 =C2=A0 (when sibling<br>=C2=A0 =C2=A0 =C2=A0 (go=
to-char (treesit-node-start sibling)))))</div><div><br></div><div>Just need=
 to handle the outermost (fragment peace and should work then. <br></div><d=
iv><br></div><div>Thanks for the help. <br></div></div><br><div class=3D"gm=
ail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Thu, 10 Nov 2022 at 21:=
05, Wilhelm Kirschbaum &lt;<a href=3D"mailto:wilhelm@HIDDEN" targe=
t=3D"_blank">wilhelm@HIDDEN</a>&gt; wrote:<br></div><blockquote cl=
ass=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid=
 rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr">Full implementation he=
re: <a href=3D"https://github.com/wkirschbaum/elixir-mode/blob/main/heex-mo=
de.el" target=3D"_blank">https://github.com/wkirschbaum/elixir-mode/blob/ma=
in/heex-mode.el</a></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" cl=
ass=3D"gmail_attr">On Thu, 10 Nov 2022 at 21:03, Wilhelm Kirschbaum &lt;<a =
href=3D"mailto:wilhelm@HIDDEN" target=3D"_blank">wilhelm@floatpays=
.co.za</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"m=
argin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left=
:1ex"><div dir=3D"ltr"><div>forward-sexp works well with the below code, bu=
t when calling treesit-node-prev-sibling it will traverse up the list, whic=
h is then breaking backward-up-list when defining forward-sexp in the major=
 mode. <br></div><div><br></div><div>(defun heex--treesit-largest-node-at-p=
oint ()<br>=C2=A0 &quot;Find the largest node at point.&quot;<br>=C2=A0 (sa=
ve-excursion<br>=C2=A0 =C2=A0 (forward-comment (point-max))<br>=C2=A0 =C2=
=A0 (let ((node-list<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(cl-loop f=
or node =3D (treesit-node-at (point))<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 then (treesit-node-parent node)<br>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 while no=
de<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 if (eq (treesit-node-start node)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(point))<br>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 collect =
node)))<br>=C2=A0 =C2=A0 =C2=A0 (car (last node-list)))))<br><br>(defun hee=
x--treesit-backward-sexp ()<br>=C2=A0 &quot;Forward sexp for Heex using tre=
esit.&quot;<br>=C2=A0 (let* ((largest-node (heex--treesit-largest-node-at-p=
oint))<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sibling (treesit-node-prev-sib=
ling largest-node)))<br>=C2=A0 =C2=A0 (when sibling<br>=C2=A0 =C2=A0 =C2=A0=
 (goto-char (treesit-node-start sibling)))))<br><br>(defun heex--treesit-fo=
rward-sexp ()<br>=C2=A0 &quot;Forward sexp for Heex using treesit.&quot;<br=
>=C2=A0 (let* ((largest-node (heex--treesit-largest-node-at-point))<br>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sibling (treesit-node-next-sibling largest-=
node)))<br>=C2=A0 =C2=A0 (when sibling<br>=C2=A0 =C2=A0 =C2=A0 (goto-char (=
treesit-node-start sibling))<br>=C2=A0 =C2=A0 =C2=A0 (forward-comment (- (p=
oint-max))))))</div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" c=
lass=3D"gmail_attr">On Thu, 10 Nov 2022 at 10:14, Yuan Fu &lt;<a href=3D"ma=
ilto:casouri@HIDDEN" target=3D"_blank">casouri@HIDDEN</a>&gt; wrote:<=
br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8e=
x;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
&gt; On Nov 9, 2022, at 10:44 PM, Wilhelm Kirschbaum &lt;<a href=3D"mailto:=
wilhelm@HIDDEN" target=3D"_blank">wilhelm@HIDDEN</a>&gt; =
wrote:<br>
&gt; <br>
&gt; I finally had some time to have a look. I don&#39;t see any more issue=
s, thank you for the fantastic work on this. The defun-type-regexp is not e=
nough to identify a defun in elixir this is the query I am using currently:=
<br>
&gt; <br>
&gt; (defvar elixir--treesit-query-defun<br>
&gt;=C2=A0 =C2=A0(let ((query `((call<br>
&gt;=C2=A0 =C2=A0 =C2=A0 target: (identifier) @type<br>
&gt;=C2=A0 =C2=A0 =C2=A0 (arguments<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0[<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 (alias) @name<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 (identifier) @name<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 (call target: (identifier)) @name<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 (binary_operator<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0left: (call target: (identifier)) @na=
me<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0operator: &quot;when&quot;)<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 ])<br>
&gt;=C2=A0 =C2=A0 =C2=A0 (:match ,elixir--definition-keywords-re @type)<br>
&gt;=C2=A0 =C2=A0 =C2=A0 ))))<br>
&gt;=C2=A0 =C2=A0 =C2=A0(treesit-query-compile &#39;elixir query)))<br>
&gt; <br>
&gt; Regex will work in most cases I guess, but does not really deal with m=
ore complex queries for more complex cases like in elixir as there is not o=
ne type which is always the defun. elixir relies heavily on macros and diff=
erent defun macros can be defined on the fly.<br>
<br>
You can try the following procedure: use a regex to find the next/previous =
call, then perform some check on whether it=E2=80=99s indeed a defun, if no=
t, keep searching for the next/previous call.<br>
<br>
<br>
&gt; Maybe if there is an option for using either a regex or a function? <b=
r>
<br>
Yes, instead of a regex you can pass a predicate function.<br>
<br>
&gt; <br>
&gt; I am also not sure how forward-sexp can work with the current treesit-=
search-forward-goto function as it does not take into consideration the lev=
el. Is there perhaps a way to move forward/backward, but do not jump to par=
ents or children? <br>
<br>
If you want to move in the same level, perhaps you can use treesit-next/pre=
v/sibling?<br>
<br>
Yuan</blockquote></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>

--0000000000002e024d05ed23d4a6--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#58711; Package emacs. Full text available.

Message received at 58711 <at> debbugs.gnu.org:


Received: (at 58711) by debbugs.gnu.org; 10 Nov 2022 19:33:17 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Nov 10 14:33:17 2022
Received: from localhost ([127.0.0.1]:44419 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1otDIb-0001f9-42
	for submit <at> debbugs.gnu.org; Thu, 10 Nov 2022 14:33:17 -0500
Received: from mail-lf1-f50.google.com ([209.85.167.50]:38618)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <wilhelm@HIDDEN>) id 1otDIX-0001et-57
 for 58711 <at> debbugs.gnu.org; Thu, 10 Nov 2022 14:33:16 -0500
Received: by mail-lf1-f50.google.com with SMTP id g7so5098487lfv.5
 for <58711 <at> debbugs.gnu.org>; Thu, 10 Nov 2022 11:33:13 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=floatpays.co.za; s=google;
 h=cc:to:subject:message-id:date:from:in-reply-to:references
 :mime-version:from:to:cc:subject:date:message-id:reply-to;
 bh=YZw301uNZkCNjbr85xf8rKkNBuxQAuvc7TqiKgx5LZo=;
 b=fuDhXhVXJ0ENa3LWns/ET1tRFnhiNU1uEc0+4lJFDNM6C6bI40dyu0BIbXwor+P8xF
 /nygdLF1NxGuqkyjfdXGNiANym0SkqGCCsFjIPXs6HYEXarJ0OUPvMP//9qTMU8jL3e4
 ilMx1XPbU+cTfu+Qi0A+eeIhK6kCqWjuxkfag=
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=YZw301uNZkCNjbr85xf8rKkNBuxQAuvc7TqiKgx5LZo=;
 b=aWYbBXtvZcEaffXv+jjAFXurX7wKgQ69Dv8IgLspzh58XZOocB/OLEPGAXmr8ZdC6w
 gC1kcLCJvAP344OKUGmoHmuUuyEo+izWQIEdfCmllcanprjiWhT+q6jUjt2CEpfXLH3+
 kUHEgw4EeKQRyeMGDK7AoD//fhPc4VwCHPJrTqt9uFX0lRor4QcHX2JwYL5SPBcMwnS8
 XnSbiptNJ92tMTlBxzu3ghFdRPIutHMknl+o9BOOfcN8NMXFXZzESMEnjrHbZvBq1Nl1
 udSrww/l1zsStV7s3PlVkW5Iaqo7I04s163jkBfLSZrHKGAMbR/R9P1Z2oc+Zu5xAkRK
 GVQg==
X-Gm-Message-State: ANoB5plJpPM8wLTs4PqTI0dsY36tOON3Pwqdvk7PUnlj1+dpCHeudr+d
 gAeHvqADrctVAk/U+VimbfILF2YkbTyVSvQR9LpIBg==
X-Google-Smtp-Source: AA0mqf6Lmr227gFWFETKzLQ9MW1U6zuijbo0LSvppEqRLJ6tQ7bdln+oihntHArWilCoTjUnW0zCac0B36wmIO52tTY=
X-Received: by 2002:ac2:560b:0:b0:4b3:abaf:b7c1 with SMTP id
 v11-20020ac2560b000000b004b3abafb7c1mr1722283lfd.39.1668108787149; Thu, 10
 Nov 2022 11:33:07 -0800 (PST)
MIME-Version: 1.0
References: <CAOS0-348zPFJEFNao2Ay06RKygsXv0WMFeLqquWBCJp5VgWbbw@HIDDEN>
 <895A3C87-507A-4FC5-8BAE-B138B35CD40C@HIDDEN>
 <46B629C0-1413-41CE-BDA8-CE14C12B4449@HIDDEN>
 <3054006.Zh9iicr411@HIDDEN>
 <106B8822-FE37-4590-BC77-5FB24FB0758C@HIDDEN>
 <CAJbepr8aYrWRLQ8TTKU=97z+yqhVa=Fsw_Vxthu6EbYidvPNhQ@HIDDEN>
 <82A013FB-9A94-4E57-9FD2-AF8E892241A9@HIDDEN>
 <CAJbepr8Abfdd0RMHoyadoo3+UHjAFFKqQC9FTnk7_YKbVr12Ng@HIDDEN>
 <CAJbepr-3k83dvXjvzJ+fHVsFt=DKhMu08sGmxUGQp=UBu-B9Cw@HIDDEN>
In-Reply-To: <CAJbepr-3k83dvXjvzJ+fHVsFt=DKhMu08sGmxUGQp=UBu-B9Cw@HIDDEN>
From: Wilhelm Kirschbaum <wilhelm@HIDDEN>
Date: Thu, 10 Nov 2022 21:32:56 +0200
Message-ID: <CAJbepr8ac81yzpBWpanuehFHrR6W_sUQEU_KXuyeEhkBkbwFqg@HIDDEN>
Subject: Re: bug#58711: Treesit hangs when calling treesit-search-forward
To: Yuan Fu <casouri@HIDDEN>
Content-Type: multipart/alternative; boundary="000000000000b4833805ed22d7f9"
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 58711
Cc: 58711 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--000000000000b4833805ed22d7f9
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Sorry, I see something like this makes sense and is not the prev-sibling
issue.

(defun heex--treesit-backward-sexp ()
  "Forward sexp for Heex using treesit."
  (let* ((node (treesit-search-forward
                (treesit-node-at (point))
                (rx (or "end_tag" "end_component" "end_slot"))
                t))
         (sibling (treesit-node-prev-sibling node)))
    (when sibling
      (goto-char (treesit-node-start sibling)))))

Just need to handle the outermost (fragment peace and should work then.

Thanks for the help.

On Thu, 10 Nov 2022 at 21:05, Wilhelm Kirschbaum <wilhelm@HIDDEN>
wrote:

> Full implementation here:
> https://github.com/wkirschbaum/elixir-mode/blob/main/heex-mode.el
>
> On Thu, 10 Nov 2022 at 21:03, Wilhelm Kirschbaum <wilhelm@HIDDEN=
>
> wrote:
>
>> forward-sexp works well with the below code, but when calling
>> treesit-node-prev-sibling it will traverse up the list, which is then
>> breaking backward-up-list when defining forward-sexp in the major mode.
>>
>> (defun heex--treesit-largest-node-at-point ()
>>   "Find the largest node at point."
>>   (save-excursion
>>     (forward-comment (point-max))
>>     (let ((node-list
>>            (cl-loop for node =3D (treesit-node-at (point))
>>                     then (treesit-node-parent node)
>>                     while node
>>                     if (eq (treesit-node-start node)
>>                            (point))
>>                     collect node)))
>>       (car (last node-list)))))
>>
>> (defun heex--treesit-backward-sexp ()
>>   "Forward sexp for Heex using treesit."
>>   (let* ((largest-node (heex--treesit-largest-node-at-point))
>>          (sibling (treesit-node-prev-sibling largest-node)))
>>     (when sibling
>>       (goto-char (treesit-node-start sibling)))))
>>
>> (defun heex--treesit-forward-sexp ()
>>   "Forward sexp for Heex using treesit."
>>   (let* ((largest-node (heex--treesit-largest-node-at-point))
>>          (sibling (treesit-node-next-sibling largest-node)))
>>     (when sibling
>>       (goto-char (treesit-node-start sibling))
>>       (forward-comment (- (point-max))))))
>>
>> On Thu, 10 Nov 2022 at 10:14, Yuan Fu <casouri@HIDDEN> wrote:
>>
>>>
>>>
>>> > On Nov 9, 2022, at 10:44 PM, Wilhelm Kirschbaum <
>>> wilhelm@HIDDEN> wrote:
>>> >
>>> > I finally had some time to have a look. I don't see any more issues,
>>> thank you for the fantastic work on this. The defun-type-regexp is not
>>> enough to identify a defun in elixir this is the query I am using curre=
ntly:
>>> >
>>> > (defvar elixir--treesit-query-defun
>>> >   (let ((query `((call
>>> >      target: (identifier) @type
>>> >      (arguments
>>> >       [
>>> >        (alias) @name
>>> >        (identifier) @name
>>> >        (call target: (identifier)) @name
>>> >        (binary_operator
>>> >         left: (call target: (identifier)) @name
>>> >         operator: "when")
>>> >        ])
>>> >      (:match ,elixir--definition-keywords-re @type)
>>> >      ))))
>>> >     (treesit-query-compile 'elixir query)))
>>> >
>>> > Regex will work in most cases I guess, but does not really deal with
>>> more complex queries for more complex cases like in elixir as there is =
not
>>> one type which is always the defun. elixir relies heavily on macros and
>>> different defun macros can be defined on the fly.
>>>
>>> You can try the following procedure: use a regex to find the
>>> next/previous call, then perform some check on whether it=E2=80=99s ind=
eed a defun,
>>> if not, keep searching for the next/previous call.
>>>
>>>
>>> > Maybe if there is an option for using either a regex or a function?
>>>
>>> Yes, instead of a regex you can pass a predicate function.
>>>
>>> >
>>> > I am also not sure how forward-sexp can work with the current
>>> treesit-search-forward-goto function as it does not take into considera=
tion
>>> the level. Is there perhaps a way to move forward/backward, but do not =
jump
>>> to parents or children?
>>>
>>> If you want to move in the same level, perhaps you can use
>>> treesit-next/prev/sibling?
>>>
>>> Yuan
>>
>>

--000000000000b4833805ed22d7f9
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Sorry, I see something like this makes sense and is n=
ot the prev-sibling issue. <br></div><div><br></div><div>(defun heex--trees=
it-backward-sexp ()<br>=C2=A0 &quot;Forward sexp for Heex using treesit.&qu=
ot;<br>=C2=A0 (let* ((node (treesit-search-forward<br>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (treesit-node-at (point))<br>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (rx (or &quot;end_tag&quot; &=
quot;end_component&quot; &quot;end_slot&quot;))<br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 t))<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(s=
ibling (treesit-node-prev-sibling node)))<br>=C2=A0 =C2=A0 (when sibling<br=
>=C2=A0 =C2=A0 =C2=A0 (goto-char (treesit-node-start sibling)))))</div><div=
><br></div><div>Just need to handle the outermost (fragment peace and shoul=
d work then. <br></div><div><br></div><div>Thanks for the help. <br></div><=
/div><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">O=
n Thu, 10 Nov 2022 at 21:05, Wilhelm Kirschbaum &lt;<a href=3D"mailto:wilhe=
lm@HIDDEN">wilhelm@HIDDEN</a>&gt; wrote:<br></div><blockq=
uote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1p=
x solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr">Full implementa=
tion here: <a href=3D"https://github.com/wkirschbaum/elixir-mode/blob/main/=
heex-mode.el" target=3D"_blank">https://github.com/wkirschbaum/elixir-mode/=
blob/main/heex-mode.el</a></div><br><div class=3D"gmail_quote"><div dir=3D"=
ltr" class=3D"gmail_attr">On Thu, 10 Nov 2022 at 21:03, Wilhelm Kirschbaum =
&lt;<a href=3D"mailto:wilhelm@HIDDEN" target=3D"_blank">wilhelm@fl=
oatpays.co.za</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" sty=
le=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);paddi=
ng-left:1ex"><div dir=3D"ltr"><div>forward-sexp works well with the below c=
ode, but when calling treesit-node-prev-sibling it will traverse up the lis=
t, which is then breaking backward-up-list when defining forward-sexp in th=
e major mode. <br></div><div><br></div><div>(defun heex--treesit-largest-no=
de-at-point ()<br>=C2=A0 &quot;Find the largest node at point.&quot;<br>=C2=
=A0 (save-excursion<br>=C2=A0 =C2=A0 (forward-comment (point-max))<br>=C2=
=A0 =C2=A0 (let ((node-list<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(cl=
-loop for node =3D (treesit-node-at (point))<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 then (treesit-node-parent node)<=
br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 wh=
ile node<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 if (eq (treesit-node-start node)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(point))<=
br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 co=
llect node)))<br>=C2=A0 =C2=A0 =C2=A0 (car (last node-list)))))<br><br>(def=
un heex--treesit-backward-sexp ()<br>=C2=A0 &quot;Forward sexp for Heex usi=
ng treesit.&quot;<br>=C2=A0 (let* ((largest-node (heex--treesit-largest-nod=
e-at-point))<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sibling (treesit-node-pr=
ev-sibling largest-node)))<br>=C2=A0 =C2=A0 (when sibling<br>=C2=A0 =C2=A0 =
=C2=A0 (goto-char (treesit-node-start sibling)))))<br><br>(defun heex--tree=
sit-forward-sexp ()<br>=C2=A0 &quot;Forward sexp for Heex using treesit.&qu=
ot;<br>=C2=A0 (let* ((largest-node (heex--treesit-largest-node-at-point))<b=
r>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sibling (treesit-node-next-sibling lar=
gest-node)))<br>=C2=A0 =C2=A0 (when sibling<br>=C2=A0 =C2=A0 =C2=A0 (goto-c=
har (treesit-node-start sibling))<br>=C2=A0 =C2=A0 =C2=A0 (forward-comment =
(- (point-max))))))</div></div><br><div class=3D"gmail_quote"><div dir=3D"l=
tr" class=3D"gmail_attr">On Thu, 10 Nov 2022 at 10:14, Yuan Fu &lt;<a href=
=3D"mailto:casouri@HIDDEN" target=3D"_blank">casouri@HIDDEN</a>&gt; w=
rote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0p=
x 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
&gt; On Nov 9, 2022, at 10:44 PM, Wilhelm Kirschbaum &lt;<a href=3D"mailto:=
wilhelm@HIDDEN" target=3D"_blank">wilhelm@HIDDEN</a>&gt; =
wrote:<br>
&gt; <br>
&gt; I finally had some time to have a look. I don&#39;t see any more issue=
s, thank you for the fantastic work on this. The defun-type-regexp is not e=
nough to identify a defun in elixir this is the query I am using currently:=
<br>
&gt; <br>
&gt; (defvar elixir--treesit-query-defun<br>
&gt;=C2=A0 =C2=A0(let ((query `((call<br>
&gt;=C2=A0 =C2=A0 =C2=A0 target: (identifier) @type<br>
&gt;=C2=A0 =C2=A0 =C2=A0 (arguments<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0[<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 (alias) @name<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 (identifier) @name<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 (call target: (identifier)) @name<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 (binary_operator<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0left: (call target: (identifier)) @na=
me<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0operator: &quot;when&quot;)<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 ])<br>
&gt;=C2=A0 =C2=A0 =C2=A0 (:match ,elixir--definition-keywords-re @type)<br>
&gt;=C2=A0 =C2=A0 =C2=A0 ))))<br>
&gt;=C2=A0 =C2=A0 =C2=A0(treesit-query-compile &#39;elixir query)))<br>
&gt; <br>
&gt; Regex will work in most cases I guess, but does not really deal with m=
ore complex queries for more complex cases like in elixir as there is not o=
ne type which is always the defun. elixir relies heavily on macros and diff=
erent defun macros can be defined on the fly.<br>
<br>
You can try the following procedure: use a regex to find the next/previous =
call, then perform some check on whether it=E2=80=99s indeed a defun, if no=
t, keep searching for the next/previous call.<br>
<br>
<br>
&gt; Maybe if there is an option for using either a regex or a function? <b=
r>
<br>
Yes, instead of a regex you can pass a predicate function.<br>
<br>
&gt; <br>
&gt; I am also not sure how forward-sexp can work with the current treesit-=
search-forward-goto function as it does not take into consideration the lev=
el. Is there perhaps a way to move forward/backward, but do not jump to par=
ents or children? <br>
<br>
If you want to move in the same level, perhaps you can use treesit-next/pre=
v/sibling?<br>
<br>
Yuan</blockquote></div>
</blockquote></div>
</blockquote></div>

--000000000000b4833805ed22d7f9--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#58711; Package emacs. Full text available.

Message received at 58711 <at> debbugs.gnu.org:


Received: (at 58711) by debbugs.gnu.org; 10 Nov 2022 19:05:26 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Nov 10 14:05:26 2022
Received: from localhost ([127.0.0.1]:44402 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1otCre-00012C-37
	for submit <at> debbugs.gnu.org; Thu, 10 Nov 2022 14:05:26 -0500
Received: from mail-lj1-f180.google.com ([209.85.208.180]:46867)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <wilhelm@HIDDEN>) id 1otCrc-00011y-2v
 for 58711 <at> debbugs.gnu.org; Thu, 10 Nov 2022 14:05:24 -0500
Received: by mail-lj1-f180.google.com with SMTP id l8so1995533ljh.13
 for <58711 <at> debbugs.gnu.org>; Thu, 10 Nov 2022 11:05:24 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=floatpays.co.za; s=google;
 h=cc:to:subject:message-id:date:from:in-reply-to:references
 :mime-version:from:to:cc:subject:date:message-id:reply-to;
 bh=84Ra6BECLrVwom9uGsI4aBwCLeVgl+1BWgbJ13R8taM=;
 b=brno2d5gW3sgPKiByJqxfkdAgmaMc1EGt8lImH5MnPY0fRlGSEs2ucnVbDoWX/VCiC
 o2C1YAi7z5YBSMLd4/9e3AHwjK34sRvfcvZAzFjbQWwnDoisfXPChvgceEC9qLShzG1H
 hud/MnccuNWhLTZkUwlCIJqYUb0n+Puwqc2F0=
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=84Ra6BECLrVwom9uGsI4aBwCLeVgl+1BWgbJ13R8taM=;
 b=Z5W4PTkay1s8YhkurEgVuQen57kWgPxxsCW7BVhUsnCRIQDSp3//dSAM8LCC7IguiA
 hiRxmPu3TbWDJCkKS9KUvoLuooFIwOZkXnOQ8Xts7OOtfQlJrUA+XRoMNvWAPIKDoo/T
 +IjWMXAiagBqYvjcjoHERwny0ZnV9OoVxSbzlOebjnFWADWyDYudwNzdfSn717L2xu8Y
 ANYBoI7j6HoYjfD5VfDuiReCm/otc6mbcUbjdEeQ6xBCPraHp/cNil/04E3pu7bv6TQr
 fS2h5AfQdQmSmVWcKSgeFKOyhgR1W0RqJROr4shDcHnxE77cADvbE+qD/LMt8iL7Vl8o
 94/A==
X-Gm-Message-State: ACrzQf1vYeqsQi0lIO94SmiQAvePHdOmbmG1vS8WPLGdUppAf4CZU9Zj
 0Z+J2Y+aKqIZ9OoWwiHs52XDQQSjRt344IuqhFqbaTTJALuj470v
X-Google-Smtp-Source: AMsMyM4rtSDkps2o1O9KItbQ3HlYEpLwPM1km9YFAZc4va89KalEWyWsg4bwAc6As5E8cUqR9Ylf5oz3eu52BMiXTFU=
X-Received: by 2002:a05:651c:b1e:b0:26e:33e:4513 with SMTP id
 b30-20020a05651c0b1e00b0026e033e4513mr9156253ljr.253.1668107118073; Thu, 10
 Nov 2022 11:05:18 -0800 (PST)
MIME-Version: 1.0
References: <CAOS0-348zPFJEFNao2Ay06RKygsXv0WMFeLqquWBCJp5VgWbbw@HIDDEN>
 <895A3C87-507A-4FC5-8BAE-B138B35CD40C@HIDDEN>
 <46B629C0-1413-41CE-BDA8-CE14C12B4449@HIDDEN>
 <3054006.Zh9iicr411@HIDDEN>
 <106B8822-FE37-4590-BC77-5FB24FB0758C@HIDDEN>
 <CAJbepr8aYrWRLQ8TTKU=97z+yqhVa=Fsw_Vxthu6EbYidvPNhQ@HIDDEN>
 <82A013FB-9A94-4E57-9FD2-AF8E892241A9@HIDDEN>
 <CAJbepr8Abfdd0RMHoyadoo3+UHjAFFKqQC9FTnk7_YKbVr12Ng@HIDDEN>
In-Reply-To: <CAJbepr8Abfdd0RMHoyadoo3+UHjAFFKqQC9FTnk7_YKbVr12Ng@HIDDEN>
From: Wilhelm Kirschbaum <wilhelm@HIDDEN>
Date: Thu, 10 Nov 2022 21:05:07 +0200
Message-ID: <CAJbepr-3k83dvXjvzJ+fHVsFt=DKhMu08sGmxUGQp=UBu-B9Cw@HIDDEN>
Subject: Re: bug#58711: Treesit hangs when calling treesit-search-forward
To: Yuan Fu <casouri@HIDDEN>
Content-Type: multipart/alternative; boundary="00000000000038755f05ed2274b6"
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 58711
Cc: 58711 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--00000000000038755f05ed2274b6
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Full implementation here:
https://github.com/wkirschbaum/elixir-mode/blob/main/heex-mode.el

On Thu, 10 Nov 2022 at 21:03, Wilhelm Kirschbaum <wilhelm@HIDDEN>
wrote:

> forward-sexp works well with the below code, but when calling
> treesit-node-prev-sibling it will traverse up the list, which is then
> breaking backward-up-list when defining forward-sexp in the major mode.
>
> (defun heex--treesit-largest-node-at-point ()
>   "Find the largest node at point."
>   (save-excursion
>     (forward-comment (point-max))
>     (let ((node-list
>            (cl-loop for node =3D (treesit-node-at (point))
>                     then (treesit-node-parent node)
>                     while node
>                     if (eq (treesit-node-start node)
>                            (point))
>                     collect node)))
>       (car (last node-list)))))
>
> (defun heex--treesit-backward-sexp ()
>   "Forward sexp for Heex using treesit."
>   (let* ((largest-node (heex--treesit-largest-node-at-point))
>          (sibling (treesit-node-prev-sibling largest-node)))
>     (when sibling
>       (goto-char (treesit-node-start sibling)))))
>
> (defun heex--treesit-forward-sexp ()
>   "Forward sexp for Heex using treesit."
>   (let* ((largest-node (heex--treesit-largest-node-at-point))
>          (sibling (treesit-node-next-sibling largest-node)))
>     (when sibling
>       (goto-char (treesit-node-start sibling))
>       (forward-comment (- (point-max))))))
>
> On Thu, 10 Nov 2022 at 10:14, Yuan Fu <casouri@HIDDEN> wrote:
>
>>
>>
>> > On Nov 9, 2022, at 10:44 PM, Wilhelm Kirschbaum <
>> wilhelm@HIDDEN> wrote:
>> >
>> > I finally had some time to have a look. I don't see any more issues,
>> thank you for the fantastic work on this. The defun-type-regexp is not
>> enough to identify a defun in elixir this is the query I am using curren=
tly:
>> >
>> > (defvar elixir--treesit-query-defun
>> >   (let ((query `((call
>> >      target: (identifier) @type
>> >      (arguments
>> >       [
>> >        (alias) @name
>> >        (identifier) @name
>> >        (call target: (identifier)) @name
>> >        (binary_operator
>> >         left: (call target: (identifier)) @name
>> >         operator: "when")
>> >        ])
>> >      (:match ,elixir--definition-keywords-re @type)
>> >      ))))
>> >     (treesit-query-compile 'elixir query)))
>> >
>> > Regex will work in most cases I guess, but does not really deal with
>> more complex queries for more complex cases like in elixir as there is n=
ot
>> one type which is always the defun. elixir relies heavily on macros and
>> different defun macros can be defined on the fly.
>>
>> You can try the following procedure: use a regex to find the
>> next/previous call, then perform some check on whether it=E2=80=99s inde=
ed a defun,
>> if not, keep searching for the next/previous call.
>>
>>
>> > Maybe if there is an option for using either a regex or a function?
>>
>> Yes, instead of a regex you can pass a predicate function.
>>
>> >
>> > I am also not sure how forward-sexp can work with the current
>> treesit-search-forward-goto function as it does not take into considerat=
ion
>> the level. Is there perhaps a way to move forward/backward, but do not j=
ump
>> to parents or children?
>>
>> If you want to move in the same level, perhaps you can use
>> treesit-next/prev/sibling?
>>
>> Yuan
>
>

--00000000000038755f05ed2274b6
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Full implementation here: <a href=3D"https://github.com/wk=
irschbaum/elixir-mode/blob/main/heex-mode.el">https://github.com/wkirschbau=
m/elixir-mode/blob/main/heex-mode.el</a></div><br><div class=3D"gmail_quote=
"><div dir=3D"ltr" class=3D"gmail_attr">On Thu, 10 Nov 2022 at 21:03, Wilhe=
lm Kirschbaum &lt;<a href=3D"mailto:wilhelm@HIDDEN">wilhelm@floatp=
ays.co.za</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=
=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding=
-left:1ex"><div dir=3D"ltr"><div>forward-sexp works well with the below cod=
e, but when calling treesit-node-prev-sibling it will traverse up the list,=
 which is then breaking backward-up-list when defining forward-sexp in the =
major mode. <br></div><div><br></div><div>(defun heex--treesit-largest-node=
-at-point ()<br>=C2=A0 &quot;Find the largest node at point.&quot;<br>=C2=
=A0 (save-excursion<br>=C2=A0 =C2=A0 (forward-comment (point-max))<br>=C2=
=A0 =C2=A0 (let ((node-list<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(cl=
-loop for node =3D (treesit-node-at (point))<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 then (treesit-node-parent node)<=
br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 wh=
ile node<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 if (eq (treesit-node-start node)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(point))<=
br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 co=
llect node)))<br>=C2=A0 =C2=A0 =C2=A0 (car (last node-list)))))<br><br>(def=
un heex--treesit-backward-sexp ()<br>=C2=A0 &quot;Forward sexp for Heex usi=
ng treesit.&quot;<br>=C2=A0 (let* ((largest-node (heex--treesit-largest-nod=
e-at-point))<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sibling (treesit-node-pr=
ev-sibling largest-node)))<br>=C2=A0 =C2=A0 (when sibling<br>=C2=A0 =C2=A0 =
=C2=A0 (goto-char (treesit-node-start sibling)))))<br><br>(defun heex--tree=
sit-forward-sexp ()<br>=C2=A0 &quot;Forward sexp for Heex using treesit.&qu=
ot;<br>=C2=A0 (let* ((largest-node (heex--treesit-largest-node-at-point))<b=
r>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sibling (treesit-node-next-sibling lar=
gest-node)))<br>=C2=A0 =C2=A0 (when sibling<br>=C2=A0 =C2=A0 =C2=A0 (goto-c=
har (treesit-node-start sibling))<br>=C2=A0 =C2=A0 =C2=A0 (forward-comment =
(- (point-max))))))</div></div><br><div class=3D"gmail_quote"><div dir=3D"l=
tr" class=3D"gmail_attr">On Thu, 10 Nov 2022 at 10:14, Yuan Fu &lt;<a href=
=3D"mailto:casouri@HIDDEN" target=3D"_blank">casouri@HIDDEN</a>&gt; w=
rote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0p=
x 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
&gt; On Nov 9, 2022, at 10:44 PM, Wilhelm Kirschbaum &lt;<a href=3D"mailto:=
wilhelm@HIDDEN" target=3D"_blank">wilhelm@HIDDEN</a>&gt; =
wrote:<br>
&gt; <br>
&gt; I finally had some time to have a look. I don&#39;t see any more issue=
s, thank you for the fantastic work on this. The defun-type-regexp is not e=
nough to identify a defun in elixir this is the query I am using currently:=
<br>
&gt; <br>
&gt; (defvar elixir--treesit-query-defun<br>
&gt;=C2=A0 =C2=A0(let ((query `((call<br>
&gt;=C2=A0 =C2=A0 =C2=A0 target: (identifier) @type<br>
&gt;=C2=A0 =C2=A0 =C2=A0 (arguments<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0[<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 (alias) @name<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 (identifier) @name<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 (call target: (identifier)) @name<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 (binary_operator<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0left: (call target: (identifier)) @na=
me<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0operator: &quot;when&quot;)<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 ])<br>
&gt;=C2=A0 =C2=A0 =C2=A0 (:match ,elixir--definition-keywords-re @type)<br>
&gt;=C2=A0 =C2=A0 =C2=A0 ))))<br>
&gt;=C2=A0 =C2=A0 =C2=A0(treesit-query-compile &#39;elixir query)))<br>
&gt; <br>
&gt; Regex will work in most cases I guess, but does not really deal with m=
ore complex queries for more complex cases like in elixir as there is not o=
ne type which is always the defun. elixir relies heavily on macros and diff=
erent defun macros can be defined on the fly.<br>
<br>
You can try the following procedure: use a regex to find the next/previous =
call, then perform some check on whether it=E2=80=99s indeed a defun, if no=
t, keep searching for the next/previous call.<br>
<br>
<br>
&gt; Maybe if there is an option for using either a regex or a function? <b=
r>
<br>
Yes, instead of a regex you can pass a predicate function.<br>
<br>
&gt; <br>
&gt; I am also not sure how forward-sexp can work with the current treesit-=
search-forward-goto function as it does not take into consideration the lev=
el. Is there perhaps a way to move forward/backward, but do not jump to par=
ents or children? <br>
<br>
If you want to move in the same level, perhaps you can use treesit-next/pre=
v/sibling?<br>
<br>
Yuan</blockquote></div>
</blockquote></div>

--00000000000038755f05ed2274b6--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#58711; Package emacs. Full text available.

Message received at 58711 <at> debbugs.gnu.org:


Received: (at 58711) by debbugs.gnu.org; 10 Nov 2022 19:03:29 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Nov 10 14:03:28 2022
Received: from localhost ([127.0.0.1]:44398 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1otCpk-0000zJ-Bx
	for submit <at> debbugs.gnu.org; Thu, 10 Nov 2022 14:03:28 -0500
Received: from mail-lf1-f42.google.com ([209.85.167.42]:41737)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <wilhelm@HIDDEN>) id 1otCpf-0000z4-TY
 for 58711 <at> debbugs.gnu.org; Thu, 10 Nov 2022 14:03:26 -0500
Received: by mail-lf1-f42.google.com with SMTP id f37so4945977lfv.8
 for <58711 <at> debbugs.gnu.org>; Thu, 10 Nov 2022 11:03:23 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=floatpays.co.za; s=google;
 h=cc:to:subject:message-id:date:from:in-reply-to:references
 :mime-version:from:to:cc:subject:date:message-id:reply-to;
 bh=WukTo/F8ThmY6SVGCg/AhwnXhgpJY65zqkFnHYfimJ8=;
 b=ViV3iPthz/IgTZtJtYpbbxoyJmDZUtP+6TH6/Kz/rdJ3BoAJ2rnuL2eAp9OqrS1AMA
 fkr1ZHtVnGJmPwMnnscJKiY0UWSWXgROwtUXWPtNAWhVrV7F+j8ZNmd70xLJNLxRaJjg
 3GrYlkdef6RcmYzWeuhbqCQT44MfgdegI8hCs=
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=WukTo/F8ThmY6SVGCg/AhwnXhgpJY65zqkFnHYfimJ8=;
 b=1NGd148Ax058kVXULgtsKES2dWOBBgAT2x7OtNaAod7Spw5Pgy9MJhF74MUfgB2FbV
 vjUIbcwVUmEAaq7dNz8hBJoWbUXb7MjX4AfRVuqiFspMeDf51hWzdkbpxGCf658pYpzc
 tKLbCRvQ4G27fH46Phhn3FUeNzt3frM/xFyrbtrmfOixnrUvOhj+i6pvfGrDFQnzEg+x
 jzuHcL1q4lJoSSWsFQrLowoCbV3Xq8EQKlnYmkc/aQyvA9wU3DzG0/jgUEQUHbQmI5VV
 tW4Izt2FXg1GA+4OT0ushSLwecH3IywKNrWF23FYGOju9niOpbXQFOl14l4gdj5WVigv
 423w==
X-Gm-Message-State: ACrzQf16LowoA/X8uJUg/peu4I+A9i76A7z1DuHTP0yX2dx7jxKxmXDJ
 pj46fZduyETlw/gx+dP+PV0TLJm5rvpJ1816urQAsw==
X-Google-Smtp-Source: AMsMyM6xdv1sNh0W+cctWqnAPZGHfmL6dp54K/mUGbHAwuSP5g8V90E05ppvWewM95ak4iyOPCm4mrFvuLht9m+D6j0=
X-Received: by 2002:ac2:4ecc:0:b0:4a2:bbdc:1430 with SMTP id
 p12-20020ac24ecc000000b004a2bbdc1430mr1699552lfr.404.1668106997752; Thu, 10
 Nov 2022 11:03:17 -0800 (PST)
MIME-Version: 1.0
References: <CAOS0-348zPFJEFNao2Ay06RKygsXv0WMFeLqquWBCJp5VgWbbw@HIDDEN>
 <895A3C87-507A-4FC5-8BAE-B138B35CD40C@HIDDEN>
 <46B629C0-1413-41CE-BDA8-CE14C12B4449@HIDDEN>
 <3054006.Zh9iicr411@HIDDEN>
 <106B8822-FE37-4590-BC77-5FB24FB0758C@HIDDEN>
 <CAJbepr8aYrWRLQ8TTKU=97z+yqhVa=Fsw_Vxthu6EbYidvPNhQ@HIDDEN>
 <82A013FB-9A94-4E57-9FD2-AF8E892241A9@HIDDEN>
In-Reply-To: <82A013FB-9A94-4E57-9FD2-AF8E892241A9@HIDDEN>
From: Wilhelm Kirschbaum <wilhelm@HIDDEN>
Date: Thu, 10 Nov 2022 21:03:06 +0200
Message-ID: <CAJbepr8Abfdd0RMHoyadoo3+UHjAFFKqQC9FTnk7_YKbVr12Ng@HIDDEN>
Subject: Re: bug#58711: Treesit hangs when calling treesit-search-forward
To: Yuan Fu <casouri@HIDDEN>
Content-Type: multipart/alternative; boundary="0000000000000c813b05ed226dfb"
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 58711
Cc: 58711 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--0000000000000c813b05ed226dfb
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

forward-sexp works well with the below code, but when calling
treesit-node-prev-sibling it will traverse up the list, which is then
breaking backward-up-list when defining forward-sexp in the major mode.

(defun heex--treesit-largest-node-at-point ()
  "Find the largest node at point."
  (save-excursion
    (forward-comment (point-max))
    (let ((node-list
           (cl-loop for node =3D (treesit-node-at (point))
                    then (treesit-node-parent node)
                    while node
                    if (eq (treesit-node-start node)
                           (point))
                    collect node)))
      (car (last node-list)))))

(defun heex--treesit-backward-sexp ()
  "Forward sexp for Heex using treesit."
  (let* ((largest-node (heex--treesit-largest-node-at-point))
         (sibling (treesit-node-prev-sibling largest-node)))
    (when sibling
      (goto-char (treesit-node-start sibling)))))

(defun heex--treesit-forward-sexp ()
  "Forward sexp for Heex using treesit."
  (let* ((largest-node (heex--treesit-largest-node-at-point))
         (sibling (treesit-node-next-sibling largest-node)))
    (when sibling
      (goto-char (treesit-node-start sibling))
      (forward-comment (- (point-max))))))

On Thu, 10 Nov 2022 at 10:14, Yuan Fu <casouri@HIDDEN> wrote:

>
>
> > On Nov 9, 2022, at 10:44 PM, Wilhelm Kirschbaum <wilhelm@HIDDEN=
a>
> wrote:
> >
> > I finally had some time to have a look. I don't see any more issues,
> thank you for the fantastic work on this. The defun-type-regexp is not
> enough to identify a defun in elixir this is the query I am using current=
ly:
> >
> > (defvar elixir--treesit-query-defun
> >   (let ((query `((call
> >      target: (identifier) @type
> >      (arguments
> >       [
> >        (alias) @name
> >        (identifier) @name
> >        (call target: (identifier)) @name
> >        (binary_operator
> >         left: (call target: (identifier)) @name
> >         operator: "when")
> >        ])
> >      (:match ,elixir--definition-keywords-re @type)
> >      ))))
> >     (treesit-query-compile 'elixir query)))
> >
> > Regex will work in most cases I guess, but does not really deal with
> more complex queries for more complex cases like in elixir as there is no=
t
> one type which is always the defun. elixir relies heavily on macros and
> different defun macros can be defined on the fly.
>
> You can try the following procedure: use a regex to find the next/previou=
s
> call, then perform some check on whether it=E2=80=99s indeed a defun, if =
not, keep
> searching for the next/previous call.
>
>
> > Maybe if there is an option for using either a regex or a function?
>
> Yes, instead of a regex you can pass a predicate function.
>
> >
> > I am also not sure how forward-sexp can work with the current
> treesit-search-forward-goto function as it does not take into considerati=
on
> the level. Is there perhaps a way to move forward/backward, but do not ju=
mp
> to parents or children?
>
> If you want to move in the same level, perhaps you can use
> treesit-next/prev/sibling?
>
> Yuan

--0000000000000c813b05ed226dfb
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>forward-sexp works well with the below code, but when=
 calling treesit-node-prev-sibling it will traverse up the list, which is t=
hen breaking backward-up-list when defining forward-sexp in the major mode.=
 <br></div><div><br></div><div>(defun heex--treesit-largest-node-at-point (=
)<br>=C2=A0 &quot;Find the largest node at point.&quot;<br>=C2=A0 (save-exc=
ursion<br>=C2=A0 =C2=A0 (forward-comment (point-max))<br>=C2=A0 =C2=A0 (let=
 ((node-list<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(cl-loop for node =
=3D (treesit-node-at (point))<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 then (treesit-node-parent node)<br>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 while node<br>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (e=
q (treesit-node-start node)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(point))<br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 collect node=
)))<br>=C2=A0 =C2=A0 =C2=A0 (car (last node-list)))))<br><br>(defun heex--t=
reesit-backward-sexp ()<br>=C2=A0 &quot;Forward sexp for Heex using treesit=
.&quot;<br>=C2=A0 (let* ((largest-node (heex--treesit-largest-node-at-point=
))<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sibling (treesit-node-prev-sibling=
 largest-node)))<br>=C2=A0 =C2=A0 (when sibling<br>=C2=A0 =C2=A0 =C2=A0 (go=
to-char (treesit-node-start sibling)))))<br><br>(defun heex--treesit-forwar=
d-sexp ()<br>=C2=A0 &quot;Forward sexp for Heex using treesit.&quot;<br>=C2=
=A0 (let* ((largest-node (heex--treesit-largest-node-at-point))<br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0(sibling (treesit-node-next-sibling largest-node=
)))<br>=C2=A0 =C2=A0 (when sibling<br>=C2=A0 =C2=A0 =C2=A0 (goto-char (tree=
sit-node-start sibling))<br>=C2=A0 =C2=A0 =C2=A0 (forward-comment (- (point=
-max))))))</div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=
=3D"gmail_attr">On Thu, 10 Nov 2022 at 10:14, Yuan Fu &lt;<a href=3D"mailto=
:casouri@HIDDEN">casouri@HIDDEN</a>&gt; wrote:<br></div><blockquote c=
lass=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px soli=
d rgb(204,204,204);padding-left:1ex"><br>
<br>
&gt; On Nov 9, 2022, at 10:44 PM, Wilhelm Kirschbaum &lt;<a href=3D"mailto:=
wilhelm@HIDDEN" target=3D"_blank">wilhelm@HIDDEN</a>&gt; =
wrote:<br>
&gt; <br>
&gt; I finally had some time to have a look. I don&#39;t see any more issue=
s, thank you for the fantastic work on this. The defun-type-regexp is not e=
nough to identify a defun in elixir this is the query I am using currently:=
<br>
&gt; <br>
&gt; (defvar elixir--treesit-query-defun<br>
&gt;=C2=A0 =C2=A0(let ((query `((call<br>
&gt;=C2=A0 =C2=A0 =C2=A0 target: (identifier) @type<br>
&gt;=C2=A0 =C2=A0 =C2=A0 (arguments<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0[<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 (alias) @name<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 (identifier) @name<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 (call target: (identifier)) @name<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 (binary_operator<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0left: (call target: (identifier)) @na=
me<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0operator: &quot;when&quot;)<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 ])<br>
&gt;=C2=A0 =C2=A0 =C2=A0 (:match ,elixir--definition-keywords-re @type)<br>
&gt;=C2=A0 =C2=A0 =C2=A0 ))))<br>
&gt;=C2=A0 =C2=A0 =C2=A0(treesit-query-compile &#39;elixir query)))<br>
&gt; <br>
&gt; Regex will work in most cases I guess, but does not really deal with m=
ore complex queries for more complex cases like in elixir as there is not o=
ne type which is always the defun. elixir relies heavily on macros and diff=
erent defun macros can be defined on the fly.<br>
<br>
You can try the following procedure: use a regex to find the next/previous =
call, then perform some check on whether it=E2=80=99s indeed a defun, if no=
t, keep searching for the next/previous call.<br>
<br>
<br>
&gt; Maybe if there is an option for using either a regex or a function? <b=
r>
<br>
Yes, instead of a regex you can pass a predicate function.<br>
<br>
&gt; <br>
&gt; I am also not sure how forward-sexp can work with the current treesit-=
search-forward-goto function as it does not take into consideration the lev=
el. Is there perhaps a way to move forward/backward, but do not jump to par=
ents or children? <br>
<br>
If you want to move in the same level, perhaps you can use treesit-next/pre=
v/sibling?<br>
<br>
Yuan</blockquote></div>

--0000000000000c813b05ed226dfb--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#58711; Package emacs. Full text available.

Message received at 58711 <at> debbugs.gnu.org:


Received: (at 58711) by debbugs.gnu.org; 10 Nov 2022 08:14:38 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Nov 10 03:14:38 2022
Received: from localhost ([127.0.0.1]:41807 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1ot2hq-0002KP-AA
	for submit <at> debbugs.gnu.org; Thu, 10 Nov 2022 03:14:38 -0500
Received: from mail-pf1-f176.google.com ([209.85.210.176]:35573)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <casouri@HIDDEN>) id 1ot2hn-0002KC-QN
 for 58711 <at> debbugs.gnu.org; Thu, 10 Nov 2022 03:14:36 -0500
Received: by mail-pf1-f176.google.com with SMTP id k15so1286009pfg.2
 for <58711 <at> debbugs.gnu.org>; Thu, 10 Nov 2022 00:14:35 -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=IcGCtn0tR9k8kZq9kEkiPONjfMG/G2gaI4+kmDvI3AY=;
 b=M0sjuVCpwc1NLD+uU0I2f6Ohnt5CsW3ArfJSjE7CKrLWuJaiZJ2wgACJPdUJHjmqRR
 pPvpNssQ1f08fvWoFYN8OoHcVzl27nXvVoYYEaU+94eiwIIrzKKjCcKFzQo3JYKvb4Ol
 1kGzZDDiQk1JLq47BwZQDWhZg91d7hge7mD7hQwvHe8fGrlwvWe9GOnqpdIay60MPplQ
 Pkxrcq8WldSB1/R203mtIieiHpZ2E/soFNS30qhEO1Q5ZjiLx+T9z1mx5G0XujnPzbE6
 nbJ1zjXqzBB/NCW071odIxf1SEKgbhnqZrCg2uUuEDSvar8htTqZkZOOcQRY+tlVXSX9
 2mXA==
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=IcGCtn0tR9k8kZq9kEkiPONjfMG/G2gaI4+kmDvI3AY=;
 b=rqo1CRcG2+Nw8s0rsDUhd/Yezgh5uSaxJL6qe+y9ntIUq7xcIneA2NcI0R8er+FdDC
 KGhRxtHgkUCxJ4cZWhhBsrhsEuD5f4Bw8+Gom+HFccLeHbXx9XYmAVhtKlExxmCzAscB
 2Y2KPiUskBifCs4a2NEq4NOBGPhxaYX3IKzJGYFvmh/2Y1fHRe7Nrs3lkAokjRzcyxen
 izwfG2yMOQOXGwd1l2ZA5feAXZQjYNodyONmlKGqA4t1DzlWQHa/WFLhMKK4cn2GLK0g
 tC+E933mtUnlCJP+IsSvSGimml5T5MgTIDvks16UeYZGfoJtG+UbTzJZZVL+11nyexcf
 ExSQ==
X-Gm-Message-State: ACrzQf2iwQmZjfyCZPDA7VnTTr5gHME9mo9+0kl3FovGbKzdAo91BPEH
 vp2mnnyFvVKh4NJQkcfBdfQ=
X-Google-Smtp-Source: AMsMyM7Vj2AjQyvyKhRtMe8vXu7TydB/TkZA9adOlbNoCTe8ngz+PYSrepdelNs3gb3CXTEaymiBZA==
X-Received: by 2002:a05:6a00:1950:b0:56e:1092:1272 with SMTP id
 s16-20020a056a00195000b0056e10921272mr1887560pfk.31.1668068069600; 
 Thu, 10 Nov 2022 00:14:29 -0800 (PST)
Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com.
 [172.117.161.177]) by smtp.gmail.com with ESMTPSA id
 c3-20020a17090a020300b00205d85cfb30sm2493791pjc.20.2022.11.10.00.14.28
 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
 Thu, 10 Nov 2022 00:14:29 -0800 (PST)
Content-Type: text/plain;
	charset=utf-8
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\))
Subject: Re: bug#58711: Treesit hangs when calling treesit-search-forward
From: Yuan Fu <casouri@HIDDEN>
In-Reply-To: <CAJbepr8aYrWRLQ8TTKU=97z+yqhVa=Fsw_Vxthu6EbYidvPNhQ@HIDDEN>
Date: Thu, 10 Nov 2022 00:14:27 -0800
Content-Transfer-Encoding: quoted-printable
Message-Id: <82A013FB-9A94-4E57-9FD2-AF8E892241A9@HIDDEN>
References: <CAOS0-348zPFJEFNao2Ay06RKygsXv0WMFeLqquWBCJp5VgWbbw@HIDDEN>
 <895A3C87-507A-4FC5-8BAE-B138B35CD40C@HIDDEN>
 <46B629C0-1413-41CE-BDA8-CE14C12B4449@HIDDEN>
 <3054006.Zh9iicr411@HIDDEN>
 <106B8822-FE37-4590-BC77-5FB24FB0758C@HIDDEN>
 <CAJbepr8aYrWRLQ8TTKU=97z+yqhVa=Fsw_Vxthu6EbYidvPNhQ@HIDDEN>
To: Wilhelm Kirschbaum <wilhelm@HIDDEN>
X-Mailer: Apple Mail (2.3696.120.41.1.1)
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 58711
Cc: 58711 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)



> On Nov 9, 2022, at 10:44 PM, Wilhelm Kirschbaum =
<wilhelm@HIDDEN> wrote:
>=20
> I finally had some time to have a look. I don't see any more issues, =
thank you for the fantastic work on this. The defun-type-regexp is not =
enough to identify a defun in elixir this is the query I am using =
currently:
>=20
> (defvar elixir--treesit-query-defun
>   (let ((query `((call
>      target: (identifier) @type
>      (arguments
>       [
>        (alias) @name
>        (identifier) @name
>        (call target: (identifier)) @name
>        (binary_operator
>         left: (call target: (identifier)) @name
>         operator: "when")
>        ])
>      (:match ,elixir--definition-keywords-re @type)
>      ))))
>     (treesit-query-compile 'elixir query)))
>=20
> Regex will work in most cases I guess, but does not really deal with =
more complex queries for more complex cases like in elixir as there is =
not one type which is always the defun. elixir relies heavily on macros =
and different defun macros can be defined on the fly.

You can try the following procedure: use a regex to find the =
next/previous call, then perform some check on whether it=E2=80=99s =
indeed a defun, if not, keep searching for the next/previous call.


> Maybe if there is an option for using either a regex or a function?=20

Yes, instead of a regex you can pass a predicate function.

>=20
> I am also not sure how forward-sexp can work with the current =
treesit-search-forward-goto function as it does not take into =
consideration the level. Is there perhaps a way to move =
forward/backward, but do not jump to parents or children?=20

If you want to move in the same level, perhaps you can use =
treesit-next/prev/sibling?

Yuan=




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#58711; Package emacs. Full text available.

Message received at 58711 <at> debbugs.gnu.org:


Received: (at 58711) by debbugs.gnu.org; 10 Nov 2022 06:45:10 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Nov 10 01:45:10 2022
Received: from localhost ([127.0.0.1]:41668 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1ot1JG-00008g-AW
	for submit <at> debbugs.gnu.org; Thu, 10 Nov 2022 01:45:10 -0500
Received: from mail-lf1-f49.google.com ([209.85.167.49]:45847)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <wilhelm@HIDDEN>) id 1ot1JD-00008A-UO
 for 58711 <at> debbugs.gnu.org; Thu, 10 Nov 2022 01:45:09 -0500
Received: by mail-lf1-f49.google.com with SMTP id j16so1357713lfe.12
 for <58711 <at> debbugs.gnu.org>; Wed, 09 Nov 2022 22:45:07 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=floatpays.co.za; s=google;
 h=cc:to:subject:message-id:date:from:in-reply-to:references
 :mime-version:from:to:cc:subject:date:message-id:reply-to;
 bh=9eJBByvkwX4UIVdqDY4BBaoV8kCXjB7j7hv58tVh7RA=;
 b=TmI2s35ycVnUV2Fiix3Z4Xl47aa2L7EyWCidsoh/GHfPx+3MSy5MxnXXIBkH5LYu/J
 an5v7noXUVgbsNdQ0e+jTorSEdjBq3ZlfHS1Ev1A2WTYOSkr7IXIhXOElNKOJpv/0odR
 rIMTl1PL9XHcjx5kO9j614OlA38JJXxfvYIz0=
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=9eJBByvkwX4UIVdqDY4BBaoV8kCXjB7j7hv58tVh7RA=;
 b=SEja1XXwQ84FIDN6R5DUSRrKlwJqfzbPvcr854kld7Sp4uIDobR2QxaASPplfq3V+n
 1bYv7wUV0JW8IwWeImfSyvBf1daWMefkcKYP7BSjpx1nJnLLOvgePDZaK82tK2SYMozN
 JUXK5GoVSHIRrsG1ewM4YHCMJL7XAxBDQluiJtf55dcGhLBnFjLM8hxGJEdItRRVLRQM
 e+KYq545c8F12pXRHO3rjVDV+1R2ltO9WNijvSFEkz8yMt4+1j6TA/8+M+DFB2Bg4xVF
 q+xyTthi1GFu/x5bCKHM3yJmPidmTIh20IefeJfUFIKSnFA75/3OPPcE5glJbwm4I7/7
 jdzQ==
X-Gm-Message-State: ACrzQf3RLJ4S/kABB+63TYSyXD06QbJyQO/sts7QQI4phncFFrCCVhLe
 9ofiupiBbUIsDwovHCFdXjltYTWXRYS++5kcqyfxkg==
X-Google-Smtp-Source: AMsMyM7THkTRaRyj2sg59JylIqlX/8u/zip8nYJhHTpaYmNVjdKnP5op7xkKDYxb5Sppxu5lSqL6mZnC7qTUOpswxzs=
X-Received: by 2002:a05:6512:3241:b0:4a2:4f95:c02e with SMTP id
 c1-20020a056512324100b004a24f95c02emr20312626lfr.23.1668062701531; Wed, 09
 Nov 2022 22:45:01 -0800 (PST)
MIME-Version: 1.0
References: <CAOS0-348zPFJEFNao2Ay06RKygsXv0WMFeLqquWBCJp5VgWbbw@HIDDEN>
 <895A3C87-507A-4FC5-8BAE-B138B35CD40C@HIDDEN>
 <46B629C0-1413-41CE-BDA8-CE14C12B4449@HIDDEN>
 <3054006.Zh9iicr411@HIDDEN>
 <106B8822-FE37-4590-BC77-5FB24FB0758C@HIDDEN>
In-Reply-To: <106B8822-FE37-4590-BC77-5FB24FB0758C@HIDDEN>
From: Wilhelm Kirschbaum <wilhelm@HIDDEN>
Date: Thu, 10 Nov 2022 08:44:50 +0200
Message-ID: <CAJbepr8aYrWRLQ8TTKU=97z+yqhVa=Fsw_Vxthu6EbYidvPNhQ@HIDDEN>
Subject: Re: bug#58711: Treesit hangs when calling treesit-search-forward
To: Yuan Fu <casouri@HIDDEN>
Content-Type: multipart/alternative; boundary="000000000000c9d11905ed181ce4"
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 58711
Cc: 58711 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--000000000000c9d11905ed181ce4
Content-Type: text/plain; charset="UTF-8"

I finally had some time to have a look. I don't see any more issues, thank
you for the fantastic work on this. The defun-type-regexp is not enough to
identify a defun in elixir this is the query I am using currently:

(defvar elixir--treesit-query-defun
  (let ((query `((call
     target: (identifier) @type
     (arguments
      [
       (alias) @name
       (identifier) @name
       (call target: (identifier)) @name
       (binary_operator
        left: (call target: (identifier)) @name
        operator: "when")
       ])
     (:match ,elixir--definition-keywords-re @type)
     ))))
    (treesit-query-compile 'elixir query)))

Regex will work in most cases I guess, but does not really deal with more
complex queries for more complex cases like in elixir as there is not one
type which is always the defun. elixir relies heavily on macros and
different defun macros can be defined on the fly. Maybe if there is an
option for using either a regex or a function?

I am also not sure how forward-sexp can work with the current
treesit-search-forward-goto function as it does not take into consideration
the level. Is there perhaps a way to move forward/backward, but do not jump
to parents or children?


On Mon, 24 Oct 2022 at 22:19, Yuan Fu <casouri@HIDDEN> wrote:

> >
> > Thanks, I would need some time to have a proper look. The reporting
> issue
> > seems to have been fixed. There are some complications to identify the
> > appropriate node for defun in elixir as a "call" node might, or might
> not be
> > defun, depending on its child identifier ( i currently have to do a
> query on
> > cycling up the parent ), but will try the respond in more detail in
> another
> > thread.
>
> While fixing the hanging issue, I also improved
> treesit-beginning-of-defun, which now first goes backward to find a node
> that matches tresit-defun-type-regexp, then goes upward and finds the
> top-most parent matching treesit-defun-type-regexp, IOW, it now only stops
> at top-level defun matches. Does that help with your case?
>
> Yuan

--000000000000c9d11905ed181ce4
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><div>I finally had some time to have a look. I don&#3=
9;t see any more issues, thank you for the fantastic work on this. The defu=
n-type-regexp is not enough to identify a defun in elixir this is the query=
 I am using currently:<br><br>(defvar elixir--treesit-query-defun<br>=C2=A0=
 (let ((query `((call<br>=C2=A0 =C2=A0 =C2=A0target: (identifier) @type<br>=
=C2=A0 =C2=A0 =C2=A0(arguments<br>=C2=A0 =C2=A0 =C2=A0 [<br>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0(alias) @name<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0(identifier) @name=
<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0(call target: (identifier)) @name<br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0(binary_operator<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 left: (=
call target: (identifier)) @name<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 operator: &=
quot;when&quot;)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0])<br>=C2=A0 =C2=A0 =C2=A0(:=
match ,elixir--definition-keywords-re @type)<br>=C2=A0 =C2=A0 =C2=A0))))<br=
>=C2=A0 =C2=A0 (treesit-query-compile &#39;elixir query)))<br><br></div>Reg=
ex will work in most cases I guess, but does not really deal with more comp=
lex queries for more complex cases like in elixir as there is not one type =
which is always the defun. elixir relies heavily on macros and different de=
fun macros can be defined on the fly. Maybe if there is an option for using=
 either a regex or a function? <br></div><div><br></div>I am also not sure =
how forward-sexp can work with the current treesit-search-forward-goto func=
tion as it does not take into consideration the level. Is there perhaps a w=
ay to move forward/backward, but do not jump to parents or children? <br><d=
iv><div><div><div><div><div><div><div dir=3D"ltr"><br></div><br><div class=
=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Mon, 24 Oct 2022 =
at 22:19, Yuan Fu &lt;<a href=3D"mailto:casouri@HIDDEN" target=3D"_blank=
">casouri@HIDDEN</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quot=
e" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204)=
;padding-left:1ex">&gt; <br>
&gt; Thanks, I would need some time to have a proper look. The reporting is=
sue <br>
&gt; seems to have been fixed. There are some complications to identify the=
 <br>
&gt; appropriate node for defun in elixir as a &quot;call&quot; node might,=
 or might not be <br>
&gt; defun, depending on its child identifier ( i currently have to do a qu=
ery on <br>
&gt; cycling up the parent ), but will try the respond in more detail in an=
other <br>
&gt; thread.=C2=A0 <br>
<br>
While fixing the hanging issue, I also improved treesit-beginning-of-defun,=
 which now first goes backward to find a node that matches tresit-defun-typ=
e-regexp, then goes upward and finds the top-most parent matching treesit-d=
efun-type-regexp, IOW, it now only stops at top-level defun matches. Does t=
hat help with your case?<br>
<br>
Yuan</blockquote></div></div></div></div></div></div></div></div></div>

--000000000000c9d11905ed181ce4--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#58711; Package emacs. Full text available.

Message received at 58711 <at> debbugs.gnu.org:


Received: (at 58711) by debbugs.gnu.org; 24 Oct 2022 20:19:37 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Oct 24 16:19:37 2022
Received: from localhost ([127.0.0.1]:49625 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1on3v7-0000lp-5x
	for submit <at> debbugs.gnu.org; Mon, 24 Oct 2022 16:19:37 -0400
Received: from mail-pf1-f179.google.com ([209.85.210.179]:42663)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <casouri@HIDDEN>) id 1on3v4-0000lY-2U
 for 58711 <at> debbugs.gnu.org; Mon, 24 Oct 2022 16:19:35 -0400
Received: by mail-pf1-f179.google.com with SMTP id b185so3719309pfb.9
 for <58711 <at> debbugs.gnu.org>; Mon, 24 Oct 2022 13:19:34 -0700 (PDT)
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=ZRaN1NKmrbpqAYCvkE0MvWqaizwvwsB7Fb8mjk9a4CQ=;
 b=TAWfej5kzoyXZQ/gbNTuaz+ravV1QFbN5OJ9jhCYxXOV0GICCf1yPuuVSFPvc1lsOB
 WdzOW1u9ZWF9xDbUh+5VTvKV3x8goYq2SqTsRuvh3taoKJLFKmw2nMxFjAmVGNXTXJ1a
 IkR1L0FTXxKge600ecYVJcSyvHYky+tFz1R0CLSYCmY4BKs1nxFJd4iLVd9jlDiom6dQ
 5tY59EcMfgRaFaUNGtI4XTxAP5XKV1tEOKJ+t19T3Uzq0N6JE0Sp8uUci4YH6xIhRavu
 bKk43cJ4piXsqoGeFDe1gVygLFvut8qza53/QqUEGyP8cH0jJkVYm7L9i13nco4Kfn2m
 482A==
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=ZRaN1NKmrbpqAYCvkE0MvWqaizwvwsB7Fb8mjk9a4CQ=;
 b=CIWu+/L0mtfuuEMiLJoXaSk+kBoHt2ZxBKQYuShHGrr4JF1k2CLrgzo9sSoRWggWU/
 C6DkUKs2DFRBDTxoztWKprnUf8IatJ/WmQjRRpgr6Tfjz5tADjiQmxpgjgrqhQut/J7o
 A6X6EP0KdqHDm0JhTHbor91pHqt9ATHBjl7NgJmeOvosDyxqnNulz3DxbndrgIBmjzdF
 BdS9w8Sxp0FSKDPFh5bNBPLQ002Hy3uqL4lABVovK1sX+Dyg8RQI17iiwIOm0//YD1aB
 OqFNPg/NhijDgtFZyLA27MAuBUIxt8cXHmGy16EVnen9+GFRYNg+5JzfDtmsJcxsZzC2
 RHiQ==
X-Gm-Message-State: ACrzQf3wz4GA053Wd/VHuzIQdGyVJcA/SFSP40rRoepqfVzNhefCJB0M
 snNqDlP4ssrz1Ax1zX9MDmi0dCVkra4=
X-Google-Smtp-Source: AMsMyM56dIYs9f6BrYlJ2Gjr2BDY/MUyDReHGA9jvn6SVCSgukTkKwKN+UX/FpJRlHyFwUVGm4cQMA==
X-Received: by 2002:a05:6a00:1912:b0:564:f6be:11fd with SMTP id
 y18-20020a056a00191200b00564f6be11fdmr34406757pfi.32.1666642768456; 
 Mon, 24 Oct 2022 13:19:28 -0700 (PDT)
Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com.
 [172.117.161.177]) by smtp.gmail.com with ESMTPSA id
 z15-20020a1709027e8f00b001868ed86a95sm119498pla.174.2022.10.24.13.19.27
 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
 Mon, 24 Oct 2022 13:19:27 -0700 (PDT)
Content-Type: text/plain;
	charset=us-ascii
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\))
Subject: Re: bug#58711: Treesit hangs when calling treesit-search-forward
From: Yuan Fu <casouri@HIDDEN>
In-Reply-To: <3054006.Zh9iicr411@HIDDEN>
Date: Mon, 24 Oct 2022 13:19:25 -0700
Content-Transfer-Encoding: quoted-printable
Message-Id: <106B8822-FE37-4590-BC77-5FB24FB0758C@HIDDEN>
References: <CAOS0-348zPFJEFNao2Ay06RKygsXv0WMFeLqquWBCJp5VgWbbw@HIDDEN>
 <895A3C87-507A-4FC5-8BAE-B138B35CD40C@HIDDEN>
 <46B629C0-1413-41CE-BDA8-CE14C12B4449@HIDDEN>
 <3054006.Zh9iicr411@HIDDEN>
To: Wilhelm Hugo Kirschbaum <wilhelm@HIDDEN>
X-Mailer: Apple Mail (2.3696.120.41.1.1)
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 58711
Cc: 58711 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

>=20
> Thanks, I would need some time to have a proper look. The reporting =
issue=20
> seems to have been fixed. There are some complications to identify the=20=

> appropriate node for defun in elixir as a "call" node might, or might =
not be=20
> defun, depending on its child identifier ( i currently have to do a =
query on=20
> cycling up the parent ), but will try the respond in more detail in =
another=20
> thread. =20

While fixing the hanging issue, I also improved =
treesit-beginning-of-defun, which now first goes backward to find a node =
that matches tresit-defun-type-regexp, then goes upward and finds the =
top-most parent matching treesit-defun-type-regexp, IOW, it now only =
stops at top-level defun matches. Does that help with your case?

Yuan=




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#58711; Package emacs. Full text available.

Message received at 58711 <at> debbugs.gnu.org:


Received: (at 58711) by debbugs.gnu.org; 24 Oct 2022 18:20:16 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Oct 24 14:20:16 2022
Received: from localhost ([127.0.0.1]:49526 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1on23b-0006DM-NZ
	for submit <at> debbugs.gnu.org; Mon, 24 Oct 2022 14:20:16 -0400
Received: from mail-wm1-f50.google.com ([209.85.128.50]:52142)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <wilhelm@HIDDEN>) id 1on0uq-0004NY-PQ
 for 58711 <at> debbugs.gnu.org; Mon, 24 Oct 2022 13:07:10 -0400
Received: by mail-wm1-f50.google.com with SMTP id v11so6954635wmd.1
 for <58711 <at> debbugs.gnu.org>; Mon, 24 Oct 2022 10:07:08 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=floatpays.co.za; s=google;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=zu8DoA7ENLGKOaa84h4iclAzB+EgAQ0ADNcFN+tToPc=;
 b=Yr9QLH3tObR/veAkrI91zvBCtwzVAT3klkiDextTCv6bs1ZWcfVhcY6JW27cDfCx5c
 r7XEdBNMpcZ/wqVuVSBTJyhOay9lNGR44Blk8Ra0jewo10ecveW+qSy6CIlwAR7OUF11
 JvGHMw0K7axrDyt7aQapoyebLLrVeaubALt8k=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20210112;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=zu8DoA7ENLGKOaa84h4iclAzB+EgAQ0ADNcFN+tToPc=;
 b=TtDaxoOUie63GuTGTtH8i3gOT+ukckMWyh9BKAHpzG7ip0SznO+vwNDXNrVu/NWd8v
 JFPAJv7UEE6S9zybzepciwG02M5EpCrsCDgdPCTeVhfnyGDrJ11kPXLwmYZvmwNw4sR9
 Ps4IG7KdIX74zaFGzpN6lBXK0rjbqORWrRn5Sil9NngG71MBrj0jTjFbaBfIEN2TOCy2
 ktbAQ3U9Eyg1fj43LNrA7MiJKAF4V0nE+IIz2yDMZlxWTBHM+7OKCWcD1ijcaQ191/hQ
 NoAhYTHvjTxrd0YN7rn9nbgR3bTwjZ4g+vXHRJR/POejD8wQkiDana3cWNKzHd0iKfpl
 c26g==
X-Gm-Message-State: ACrzQf3Jt5STwyk6Boiy5BKOi7StmC6Fk0Ju09W1sk7v+IHuSmt7wUx/
 yCQqSfvp6eetmR7ZcP9d+cTZUA==
X-Google-Smtp-Source: AMsMyM5A4jgnKgC0TWeinKBIbveb6286OrcdOC9J9PIaWMhu4MQP1E0VOs9VchliYhdkkWdz68oOKg==
X-Received: by 2002:a05:600c:35c8:b0:3c8:33dc:c262 with SMTP id
 r8-20020a05600c35c800b003c833dcc262mr10949602wmq.206.1666631222681; 
 Mon, 24 Oct 2022 10:07:02 -0700 (PDT)
Received: from melissa.local ([2c0f:ef18:1431:0:b09:9616:db04:c248])
 by smtp.gmail.com with ESMTPSA id
 k11-20020a056000004b00b0023657e1b97esm183848wrx.11.2022.10.24.10.07.01
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Mon, 24 Oct 2022 10:07:02 -0700 (PDT)
From: Wilhelm Hugo Kirschbaum <wilhelm@HIDDEN>
X-Google-Original-From: Wilhelm Hugo Kirschbaum <wkirschbaum@HIDDEN>
To: Yuan Fu <casouri@HIDDEN>
Subject: Re: bug#58711: Treesit hangs when calling treesit-search-forward
Date: Mon, 24 Oct 2022 19:06:58 +0200
Message-ID: <3054006.Zh9iicr411@HIDDEN>
In-Reply-To: <46B629C0-1413-41CE-BDA8-CE14C12B4449@HIDDEN>
References: <CAOS0-348zPFJEFNao2Ay06RKygsXv0WMFeLqquWBCJp5VgWbbw@HIDDEN>
 <895A3C87-507A-4FC5-8BAE-B138B35CD40C@HIDDEN>
 <46B629C0-1413-41CE-BDA8-CE14C12B4449@HIDDEN>
MIME-Version: 1.0
Content-Transfer-Encoding: 7Bit
Content-Type: text/plain; charset="us-ascii"
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 58711
X-Mailman-Approved-At: Mon, 24 Oct 2022 14:20:15 -0400
Cc: 58711 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

On Monday, 24 October 2022 01:20:01 SAST Yuan Fu wrote:
> > On Oct 22, 2022, at 11:42 PM, Yuan Fu <casouri@HIDDEN> wrote:
> >> On Oct 22, 2022, at 2:53 AM, Wilhelm Kirschbaum <wkirschbaum@HIDDEN>
> >> wrote:
> >> 
> >> I am attempting to implement treesit for the current elixir-mode using
> >> the branch feature/trees-sitter. For implementing
> >> beginning-of-defun-function using treesit I am running into an issue
> >> where the Emacs will hang indefinitely. Using (setq-local
> >> treesit-defun-type-regexp (rx (or "call"))) yields the same result.
> >> 
> >> For the following node-at-point output
> >> 
> >> (do_block (call target: (identifier)))
> >> 
> >> with Elixir code
> >> 
> >> # foo.ex
> >> defmodule Foo do
> >> 
> >>  <<point/cursor here>>def bar(), do: "bar"
> >> 
> >> end
> >> 
> >> When I call `(treesit-search-forward-goto (rx (or "call")) 'start nil t)`
> >> the function `treesit-search-forward` seems to get stuck.
> >> 
> >> Elixir does not strictly have a begin function, but can be determined as
> >> one of the following: ; * modules and protocols
> >> (call
> >> 
> >>  target: (identifier) @ignore
> >>  (arguments (alias) @name)
> >>  (#match? @ignore "^(defmodule|defprotocol)$")) @definition.module
> >> 
> >> ; * functions/macros
> >> (call
> >> 
> >>  target: (identifier) @ignore
> >>  (arguments
> >>  
> >>    [
> >>    
> >>      ; zero-arity functions with no parentheses
> >>      (identifier) @name
> >>      ; regular function clause
> >>      (call target: (identifier) @name)
> >>      ; function clause with a guard clause
> >>      (binary_operator
> >>      
> >>        left: (call target: (identifier) @name)
> >>        operator: "when")
> >>    
> >>    ])
> >>  
> >>  (#match? @ignore
> >>  "^(def|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defn
> >>  p)$")) @definition.function>> 
> >> The elixir tree sitter implementation is here:
> >> https://github.com/elixir-lang/tree-sitter-elixir
> >> 
> >> I lack the knowledge to further debug this or find a clean workaround,
> >> but I'm almost sure that treesit-search-forward should never hang.> 
> > Thanks for reporting this. The way treesit-search-forward-goto works makes
> > it very to have infinite loops. I revised the way it traverses the tree
> > and now it should be impossible to fall into infinite loops.
> > 
> > Yuan
> 
> Just a heads up: I changed the function signature of
> treesit-search-forward-goto in the latest commit.
> 
> Yuan

Thanks, I would need some time to have a proper look. The reporting issue 
seems to have been fixed. There are some complications to identify the 
appropriate node for defun in elixir as a "call" node might, or might not be 
defun, depending on its child identifier ( i currently have to do a query on 
cycling up the parent ), but will try the respond in more detail in another 
thread.  







Information forwarded to bug-gnu-emacs@HIDDEN:
bug#58711; Package emacs. Full text available.

Message received at 58711 <at> debbugs.gnu.org:


Received: (at 58711) by debbugs.gnu.org; 23 Oct 2022 23:20:12 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Oct 23 19:20:12 2022
Received: from localhost ([127.0.0.1]:46653 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1omkGJ-0001VB-O6
	for submit <at> debbugs.gnu.org; Sun, 23 Oct 2022 19:20:12 -0400
Received: from mail-pl1-f169.google.com ([209.85.214.169]:34719)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <casouri@HIDDEN>) id 1omkGH-0001Uv-D1
 for 58711 <at> debbugs.gnu.org; Sun, 23 Oct 2022 19:20:10 -0400
Received: by mail-pl1-f169.google.com with SMTP id n7so7129933plp.1
 for <58711 <at> debbugs.gnu.org>; Sun, 23 Oct 2022 16:20:09 -0700 (PDT)
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=s014aqWaGM4G4ZfToYWFeurVWzGqHeapX3xCPvUQdOA=;
 b=F9zSgfb4hFBuHppdEI0amc1kPYZSZMas6FLLMtWnRAjgyAvhmDhh0kOe21lKtlBI47
 KmFGAEtr5sfo19k+VFYaEtxq3j+9Uf4Z9T5Be24xyEmt/A61DVsFDuh5+nX12h+hMLET
 tLpRK2K19HHzxWECg8rDL41twA8+okU/ohAUYNOEDKvc5Kx/Gu4RmLqu93FJZ/Map9h+
 yWcR/PN3ll0nfMon8zpTJw8w8sUxXWjQZaEz8dXAOagIe4m+9mnFvFjwYh5fx1TWJffO
 fHujoZ7TofUp/s+BubZJAAEUegclwqHDsSaZQ4wM/vfIEEANPwxcNkw5vcpV2OD79Hj/
 0/VA==
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=s014aqWaGM4G4ZfToYWFeurVWzGqHeapX3xCPvUQdOA=;
 b=75FPolwZptkIs4id87MDLSPhbUmtf16eExUVH8gnyrLiQhlGrEeVgtGbb5XKhS7Pp+
 bnpOWL/ux30XNHX0UvLA2jdDpgrV/1LTZjT3oK70qcpLgGusM4DY63VjXXQI/jpXJMPE
 1JODLvA5uU41CZLzbinhtZpOkxi3zEi8HjgdTBcIcB8c7p1rPFAGT6l8GRgOWoDss1gf
 iwTs9GBRvsI8HLGvIv2PJbkO1TlXwMfkL8NiQgJBuk7vlwIv/+J3t4M7oCrbYOnLSa33
 WuIUaq0RfXVvNzXdxobDq0Gd96wPKw+IM0Hq4gxN0JFUY/+Cw5MAH57UMneb6jdt9ROn
 dgSA==
X-Gm-Message-State: ACrzQf2pHszwoqntiWh2cZUPh0oEIV3VCmdf80sSdhQX+w0f9JhzJnfB
 f0jL72khsJbtUWlNiytzMGM=
X-Google-Smtp-Source: AMsMyM4s/ke3FzTKXiJAUY7ENh9fAu6AWoLjbPeR0EsOyi9AKyrRTUSM7yuE/d4gIwacej/bTch8EQ==
X-Received: by 2002:a17:902:e852:b0:186:96fe:56d9 with SMTP id
 t18-20020a170902e85200b0018696fe56d9mr7026526plg.69.1666567203449; 
 Sun, 23 Oct 2022 16:20:03 -0700 (PDT)
Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com.
 [172.117.161.177]) by smtp.gmail.com with ESMTPSA id
 k17-20020a170902d59100b00186a8085382sm764742plh.43.2022.10.23.16.20.02
 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
 Sun, 23 Oct 2022 16:20:03 -0700 (PDT)
Content-Type: text/plain;
	charset=us-ascii
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\))
Subject: Re: bug#58711: Treesit hangs when calling treesit-search-forward
From: Yuan Fu <casouri@HIDDEN>
In-Reply-To: <895A3C87-507A-4FC5-8BAE-B138B35CD40C@HIDDEN>
Date: Sun, 23 Oct 2022 16:20:01 -0700
Content-Transfer-Encoding: quoted-printable
Message-Id: <46B629C0-1413-41CE-BDA8-CE14C12B4449@HIDDEN>
References: <CAOS0-348zPFJEFNao2Ay06RKygsXv0WMFeLqquWBCJp5VgWbbw@HIDDEN>
 <895A3C87-507A-4FC5-8BAE-B138B35CD40C@HIDDEN>
To: Wilhelm Kirschbaum <wkirschbaum@HIDDEN>
X-Mailer: Apple Mail (2.3696.120.41.1.1)
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 58711
Cc: 58711 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)



> On Oct 22, 2022, at 11:42 PM, Yuan Fu <casouri@HIDDEN> wrote:
>=20
>=20
>=20
>> On Oct 22, 2022, at 2:53 AM, Wilhelm Kirschbaum =
<wkirschbaum@HIDDEN> wrote:
>>=20
>> I am attempting to implement treesit for the current elixir-mode =
using the branch feature/trees-sitter. For implementing =
beginning-of-defun-function using treesit I am running into an issue =
where the Emacs will hang indefinitely. Using (setq-local =
treesit-defun-type-regexp (rx (or "call"))) yields the same result.
>>=20
>> For the following node-at-point output
>>=20
>> (do_block (call target: (identifier)))
>>=20
>> with Elixir code
>>=20
>> # foo.ex
>> defmodule Foo do
>>  <<point/cursor here>>def bar(), do: "bar"
>> end
>>=20
>> When I call `(treesit-search-forward-goto (rx (or "call")) 'start nil =
t)` the function `treesit-search-forward` seems to get stuck.=20
>>=20
>> Elixir does not strictly have a begin function, but can be determined =
as one of the following:
>> ; * modules and protocols
>> (call
>>  target: (identifier) @ignore
>>  (arguments (alias) @name)
>>  (#match? @ignore "^(defmodule|defprotocol)$")) @definition.module
>>=20
>> ; * functions/macros
>> (call
>>  target: (identifier) @ignore
>>  (arguments
>>    [
>>      ; zero-arity functions with no parentheses
>>      (identifier) @name
>>      ; regular function clause
>>      (call target: (identifier) @name)
>>      ; function clause with a guard clause
>>      (binary_operator
>>        left: (call target: (identifier) @name)
>>        operator: "when")
>>    ])
>>  (#match? @ignore =
"^(def|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp)$=
")) @definition.function
>>=20
>> The elixir tree sitter implementation is here: =
https://github.com/elixir-lang/tree-sitter-elixir
>>=20
>> I lack the knowledge to further debug this or find a clean =
workaround, but I'm almost sure that treesit-search-forward should never =
hang.=20
>=20
> Thanks for reporting this. The way treesit-search-forward-goto works =
makes it very to have infinite loops. I revised the way it traverses the =
tree and now it should be impossible to fall into infinite loops.
>=20
> Yuan

Just a heads up: I changed the function signature of =
treesit-search-forward-goto in the latest commit.

Yuan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#58711; Package emacs. Full text available.

Message received at 58711 <at> debbugs.gnu.org:


Received: (at 58711) by debbugs.gnu.org; 23 Oct 2022 06:42:33 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Oct 23 02:42:33 2022
Received: from localhost ([127.0.0.1]:42791 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1omUgr-0006Mn-DT
	for submit <at> debbugs.gnu.org; Sun, 23 Oct 2022 02:42:33 -0400
Received: from mail-pj1-f42.google.com ([209.85.216.42]:37788)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <casouri@HIDDEN>) id 1omUgp-0006MW-9k
 for 58711 <at> debbugs.gnu.org; Sun, 23 Oct 2022 02:42:31 -0400
Received: by mail-pj1-f42.google.com with SMTP id
 f9-20020a17090a654900b00210928389f8so10362245pjs.2
 for <58711 <at> debbugs.gnu.org>; Sat, 22 Oct 2022 23:42:31 -0700 (PDT)
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=CcZ/3jMzxd314xd1qLRSVqSuXL6/zEVUg+LEKnnD4WE=;
 b=lG5mpGfvwYzC0F5I5ArsK0YlAcZqhG0RRlqZgC2G3X2ueudBLEnnBh0dUK8zXrFUeX
 mc+06qVe+AeOg9KxrHmMCW4NO5oSe52OCVQm2kF7Grj7supQU6Mmi+TDSB94V2Dx49JX
 IQ/x6fidoGlclnj6o2FYYBDry+6lXou/Cwd1ebkpTO4YZEVaVOEeiWUKFRiUh5AlMxGA
 Yt/pT+svWKQJc8FdoDoC7po22grtNd4TuxyLlxzyAg90XdEPsIJooqr+awLkm1pUYO0e
 8IdoHVF6RC9nx1tzZIlqHtwQH53QnJFGEjDPkjZD6JkyIGtkPM6V2gcXsWanwdsSXl1r
 zs/g==
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=CcZ/3jMzxd314xd1qLRSVqSuXL6/zEVUg+LEKnnD4WE=;
 b=ayEUeWCJZ1nl/C4n/Ym8grdJpePjUpjWtlLN16ds32FlKAUDhubdPMbb7+3dfn0fMo
 MlSUB9t16lAzqgzmUWvWXhqmOhxw0JMQF8e2Hkw9jn6BqDdYz+Tt2gS61MGqcA7aUBPd
 poDtELkaLKVIJG9Qiqh/twwVXp6gtJYEV1VVIconU1UJoJ8l0wpMVQuRrT4vCA+L4VTD
 mRhxuW5qNLI6It13Exhx/eO6kDx1Ln4OwQAdclcELXzEXQqreGZHri0uBPVmPJ0LOUBF
 S6vkFeWGIaC7PwVDs7s7pTvgYHxNKBR9WvIvrOSnMUmoWL6PQZFdjNaMLjvjs+v/Eb3L
 mNLw==
X-Gm-Message-State: ACrzQf1wgJf6KLBPg23yqyXUyLpD/hsGsU+BfMeFYtF1CFBXhi/DE5iW
 XHgj5pnHNBTWutFj8TEkc3Y=
X-Google-Smtp-Source: AMsMyM5Of5ANGtmj/hU+WH7iKgifmN8FCyTsTY80O7PDcq1DkWkQbp6Lakr90qt5KB0fYUr/ANgtFg==
X-Received: by 2002:a17:90b:2242:b0:20d:a2be:95a4 with SMTP id
 hk2-20020a17090b224200b0020da2be95a4mr32040299pjb.159.1666507345352; 
 Sat, 22 Oct 2022 23:42:25 -0700 (PDT)
Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com.
 [172.117.161.177]) by smtp.gmail.com with ESMTPSA id
 x1-20020a17090a8a8100b00203917403ccsm4006139pjn.1.2022.10.22.23.42.24
 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
 Sat, 22 Oct 2022 23:42:24 -0700 (PDT)
Content-Type: text/plain;
	charset=us-ascii
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\))
Subject: Re: bug#58711: Treesit hangs when calling treesit-search-forward
From: Yuan Fu <casouri@HIDDEN>
In-Reply-To: <CAOS0-348zPFJEFNao2Ay06RKygsXv0WMFeLqquWBCJp5VgWbbw@HIDDEN>
Date: Sat, 22 Oct 2022 23:42:23 -0700
Content-Transfer-Encoding: quoted-printable
Message-Id: <895A3C87-507A-4FC5-8BAE-B138B35CD40C@HIDDEN>
References: <CAOS0-348zPFJEFNao2Ay06RKygsXv0WMFeLqquWBCJp5VgWbbw@HIDDEN>
To: Wilhelm Kirschbaum <wkirschbaum@HIDDEN>
X-Mailer: Apple Mail (2.3696.120.41.1.1)
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 58711
Cc: 58711 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)



> On Oct 22, 2022, at 2:53 AM, Wilhelm Kirschbaum =
<wkirschbaum@HIDDEN> wrote:
>=20
> I am attempting to implement treesit for the current elixir-mode using =
the branch feature/trees-sitter. For implementing =
beginning-of-defun-function using treesit I am running into an issue =
where the Emacs will hang indefinitely. Using (setq-local =
treesit-defun-type-regexp (rx (or "call"))) yields the same result.
>=20
> For the following node-at-point output
>=20
> (do_block (call target: (identifier)))
>=20
> with Elixir code
>=20
> # foo.ex
> defmodule Foo do
>   <<point/cursor here>>def bar(), do: "bar"
> end
>=20
> When I call `(treesit-search-forward-goto (rx (or "call")) 'start nil =
t)` the function `treesit-search-forward` seems to get stuck.=20
>=20
> Elixir does not strictly have a begin function, but can be determined =
as one of the following:
> ; * modules and protocols
> (call
>   target: (identifier) @ignore
>   (arguments (alias) @name)
>   (#match? @ignore "^(defmodule|defprotocol)$")) @definition.module
>=20
> ; * functions/macros
> (call
>   target: (identifier) @ignore
>   (arguments
>     [
>       ; zero-arity functions with no parentheses
>       (identifier) @name
>       ; regular function clause
>       (call target: (identifier) @name)
>       ; function clause with a guard clause
>       (binary_operator
>         left: (call target: (identifier) @name)
>         operator: "when")
>     ])
>   (#match? @ignore =
"^(def|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp)$=
")) @definition.function
>=20
> The elixir tree sitter implementation is here: =
https://github.com/elixir-lang/tree-sitter-elixir
>=20
> I lack the knowledge to further debug this or find a clean workaround, =
but I'm almost sure that treesit-search-forward should never hang.=20

Thanks for reporting this. The way treesit-search-forward-goto works =
makes it very to have infinite loops. I revised the way it traverses the =
tree and now it should be impossible to fall into infinite loops.

Yuan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#58711; Package emacs. Full text available.

Message received at 58711 <at> debbugs.gnu.org:


Received: (at 58711) by debbugs.gnu.org; 22 Oct 2022 10:26:22 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Oct 22 06:26:22 2022
Received: from localhost ([127.0.0.1]:39750 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1omBht-0008RR-QM
	for submit <at> debbugs.gnu.org; Sat, 22 Oct 2022 06:26:22 -0400
Received: from mail-io1-f54.google.com ([209.85.166.54]:36435)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <wkirschbaum@HIDDEN>) id 1omBhs-0008R6-AV
 for 58711 <at> debbugs.gnu.org; Sat, 22 Oct 2022 06:26:20 -0400
Received: by mail-io1-f54.google.com with SMTP id y80so4238015iof.3
 for <58711 <at> debbugs.gnu.org>; Sat, 22 Oct 2022 03:26:20 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
 h=to:subject:message-id:date:from:mime-version:from:to:cc:subject
 :date:message-id:reply-to;
 bh=JOARRI/wHS6jN2a7bjtwMxL7SFLzhFDujsAGGOEDb2g=;
 b=PSTzoq6PjJILbb5M976hMgB5biacaqXsX93kqJ77TCgxq9u4k4G/+UmvMLIMBm8BTL
 k5d+2xyFKNbtm3yB8ZxUJC4SxAgGaCL+TDK4aWU2jOnRVfHaLre4uOp42S5wi77k5NZW
 RbNdSTpdKr797L00vDHakrc8PjW1iOLITqQN6q7NDF7ucuQAzFIIDWGN1cnjugCNA5bR
 osq96fC9oTAOFTtEA6o2/pk25BDcvTC770V3QrlNJAml4eUsodJdOqQzhKbP4agKQyHI
 jFWd39EdRPhbENUJBx+Gge/cNUv41toLwkjHz+CV4SodKkUhDThPk8axsFSWlphvP2J8
 0kkg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20210112;
 h=to:subject:message-id:date:from:mime-version:x-gm-message-state
 :from:to:cc:subject:date:message-id:reply-to;
 bh=JOARRI/wHS6jN2a7bjtwMxL7SFLzhFDujsAGGOEDb2g=;
 b=iHcUzGWnezFP7GaukQ4+R0QmUU2EyD2MO3VbXeFNKAjEYLP6jGpI3nZ6l52IiWMK/V
 /u+6b05FO61FkgmKm9kHxddX/2S37eEFIiAbO3PvkCAFgseX3cuCaxfhxPdDbvc3A2EW
 iH3oenMLtOozcnzyFbzul2hcml6NqIp43C9KWPgEZ9ow2GK9/kKH9+O0dSV36n4O8iOR
 Zd6odsqFokuJa7BKIrymdEBIwADcnT7WFv0WvWNQJcA5PNnYNWLNXsyFnjrQmNxfQFST
 t+mkL7Gfx8hgPjJ/mPMvGoHDb2sy3W0GgLKUOit1/RCy5nVqV9gT3D5WSqncNzxrki9O
 n63w==
X-Gm-Message-State: ACrzQf1lGhLeseqc27MOgF7xXLWl0jq6CsOy/5zNmMquvzvykxWpWVaV
 TDyakEDjAy0TojoIH6a3PJFqhLinLU8amMxB6sF7jYWVNAg=
X-Google-Smtp-Source: AMsMyM5OmX74mXALF6nrWWaCCDmV5IYw5EcSzqFkyP6bwp84cpKFCJmnlSJcIg33bWE+zNfivZrqNs/QDo614a4TPi0=
X-Received: by 2002:a05:6638:438b:b0:363:abe9:2179 with SMTP id
 bo11-20020a056638438b00b00363abe92179mr17251981jab.16.1666434374251; Sat, 22
 Oct 2022 03:26:14 -0700 (PDT)
MIME-Version: 1.0
From: Wilhelm Kirschbaum <wkirschbaum@HIDDEN>
Date: Sat, 22 Oct 2022 12:26:02 +0200
Message-ID: <CAOS0-34vShyTODvLg_X7g5zPuUt3wbG=O1ZdU_b6gjqpAKHfog@HIDDEN>
Subject: The full tree-sitter parse output
To: 58711 <at> debbugs.gnu.org
Content-Type: multipart/alternative; boundary="000000000000eb401e05eb9cfc55"
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 58711
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--000000000000eb401e05eb9cfc55
Content-Type: text/plain; charset="UTF-8"

This is the full tree-sitter parse output for the use case mentioned:

(source [0, 0] - [4, 3]
  (call [0, 0] - [4, 3]
    target: (identifier [0, 0] - [0, 9])
    (arguments [0, 10] - [0, 13]
      (alias [0, 10] - [0, 13]))
    (do_block [0, 14] - [4, 3]
      (call [1, 2] - [3, 5]
        target: (identifier [1, 2] - [1, 5])
        (arguments [1, 6] - [1, 11]
          (call [1, 6] - [1, 11]
            target: (identifier [1, 6] - [1, 9])
            (arguments [1, 9] - [1, 11])))
        (do_block [1, 12] - [3, 5]
          (string [2, 4] - [2, 9]
            (quoted_content [2, 5] - [2, 8])))))))

--000000000000eb401e05eb9cfc55
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">This is the full tree-sitter parse output for the use case=
 mentioned:<br><br>(source [0, 0] - [4, 3]<br>=C2=A0 (call [0, 0] - [4, 3]<=
br>=C2=A0 =C2=A0 target: (identifier [0, 0] - [0, 9])<br>=C2=A0 =C2=A0 (arg=
uments [0, 10] - [0, 13]<br>=C2=A0 =C2=A0 =C2=A0 (alias [0, 10] - [0, 13]))=
<br>=C2=A0 =C2=A0 (do_block [0, 14] - [4, 3]<br>=C2=A0 =C2=A0 =C2=A0 (call =
[1, 2] - [3, 5]<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 target: (identifier [1, 2] -=
 [1, 5])<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 (arguments [1, 6] - [1, 11]<br>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (call [1, 6] - [1, 11]<br>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 target: (identifier [1, 6] - [1, 9])<br>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (arguments [1, 9] - [1, 11])))<br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 (do_block [1, 12] - [3, 5]<br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 (string [2, 4] - [2, 9]<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 (quoted_content [2, 5] - [2, 8])))))))</div>

--000000000000eb401e05eb9cfc55--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#58711; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 22 Oct 2022 09:54:13 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Oct 22 05:54:13 2022
Received: from localhost ([127.0.0.1]:39720 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1omBCm-0007TO-CB
	for submit <at> debbugs.gnu.org; Sat, 22 Oct 2022 05:54:13 -0400
Received: from lists.gnu.org ([209.51.188.17]:46450)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <wkirschbaum@HIDDEN>) id 1omBCk-0007TH-J5
 for submit <at> debbugs.gnu.org; Sat, 22 Oct 2022 05:54:11 -0400
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 <wkirschbaum@HIDDEN>)
 id 1omBCi-00040C-Ac
 for bug-gnu-emacs@HIDDEN; Sat, 22 Oct 2022 05:54:10 -0400
Received: from mail-io1-xd2a.google.com ([2607:f8b0:4864:20::d2a])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <wkirschbaum@HIDDEN>)
 id 1omBCd-0007XR-TL
 for bug-gnu-emacs@HIDDEN; Sat, 22 Oct 2022 05:54:06 -0400
Received: by mail-io1-xd2a.google.com with SMTP id b79so4196514iof.5
 for <bug-gnu-emacs@HIDDEN>; Sat, 22 Oct 2022 02:54:02 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
 h=to:subject:message-id:date:from:mime-version:from:to:cc:subject
 :date:message-id:reply-to;
 bh=VfP69udyw1q3fnjYes0KvSRY7utqyYMfDmIhyBeU9ds=;
 b=j+o8tVeHFd0BuLFZcJgdziiFMVcKpivJYIJC+xMxcDDwYFCLvtg5kdsqUb371vJa/R
 u1ee1c7O0PDondphRsfU6DkTyCXu4NLLQSuilbvZjARG3x3rq574Bx8H7VOiskgeulRG
 dF7t1SAjV6ReP1es7sqxmwsN/A5aON1D8NVF/Ia271NkQXIFXNfUnIBDCecj/K1DNPAt
 TURrUFlH49GAXMYfJj3LHxa1zxi/OSGiM0lhthJ9wx+GFSm6aVpX06zKHzwBQI27RsCs
 ZgQxY9OGXbxj4YavILCSYiQtkCpthrzeQX2afGfQl9dXaRLC7WXkuQry16XjMAD+dVZu
 FQ/g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20210112;
 h=to:subject:message-id:date:from:mime-version:x-gm-message-state
 :from:to:cc:subject:date:message-id:reply-to;
 bh=VfP69udyw1q3fnjYes0KvSRY7utqyYMfDmIhyBeU9ds=;
 b=leBWjyF1T1VdeVVFdWSLD2h7FjB1gYF1xO9ymcvKv4ps0BiyNE/rk8Y1Tmpc4kOHpz
 QKLT5toNbJGCOLbn19dr5efoBhIeguUnFOY+XmUO7v/D8qOJK4hLSGMcJIeNdJr7iabl
 ImUCD8WiA4dBoISaskZzvG8dCuUN4n399C672vbc6VhuB60LMKvTYON32k0dM1Dwgjk1
 wG4ZdwLFcmmlKOrgLs1Ri2Tgj5ft6bK7e9VmpoGCBXnYOup5g6BVls5nWrqBshPhPCSJ
 rr06/z+FOcg8VPC9Py+E7ijjVPl4Qr0cDpe08qV8CyGVwwrX6wsmtgCi+zPe9Jsis0Yv
 oYdg==
X-Gm-Message-State: ACrzQf13NEnRzyQ8U57Z+xX7jMhip5Kpv/6vUNF3/UDxL8P1xK9MHjBm
 ZPJ2QVqj8/lRzhd7GcYT9KaKpJEFBayP3uF64kQcjZeFlds=
X-Google-Smtp-Source: AMsMyM6gaIEuk4ykcL3bmAV5CmT7GkCPeoQ76Chv+jMrLJ4Or/o2JEPRlqMgu9dlGx6h1gkUAayFjqaMXq6m7PAnwWI=
X-Received: by 2002:a05:6602:1551:b0:6bc:dfba:33f9 with SMTP id
 h17-20020a056602155100b006bcdfba33f9mr15086195iow.76.1666432441928; Sat, 22
 Oct 2022 02:54:01 -0700 (PDT)
MIME-Version: 1.0
From: Wilhelm Kirschbaum <wkirschbaum@HIDDEN>
Date: Sat, 22 Oct 2022 11:53:50 +0200
Message-ID: <CAOS0-348zPFJEFNao2Ay06RKygsXv0WMFeLqquWBCJp5VgWbbw@HIDDEN>
Subject: Treesit hangs when calling treesit-search-forward
To: bug-gnu-emacs@HIDDEN
Content-Type: multipart/alternative; boundary="000000000000be52c705eb9c89de"
Received-SPF: pass client-ip=2607:f8b0:4864:20::d2a;
 envelope-from=wkirschbaum@HIDDEN; helo=mail-io1-xd2a.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-Spam-Score: -1.3 (-)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.3 (--)

--000000000000be52c705eb9c89de
Content-Type: text/plain; charset="UTF-8"

I am attempting to implement treesit for the current elixir-mode using the
branch feature/trees-sitter. For implementing beginning-of-defun-function
using treesit I am running into an issue where the Emacs will hang
indefinitely. Using (setq-local treesit-defun-type-regexp (rx (or "call")))
yields the same result.

For the following node-at-point output

(do_block (call target: (identifier)))

with Elixir code

# foo.ex
defmodule Foo do
  <<point/cursor here>>def bar(), do: "bar"
end

When I call `(treesit-search-forward-goto (rx (or "call")) 'start nil t)`
the function `treesit-search-forward` seems to get stuck.

Elixir does not strictly have a begin function, but can be determined as
one of the following:
; * modules and protocols
(call
  target: (identifier) @ignore
  (arguments (alias) @name)
  (#match? @ignore "^(defmodule|defprotocol)$")) @definition.module

; * functions/macros
(call
  target: (identifier) @ignore
  (arguments
    [
      ; zero-arity functions with no parentheses
      (identifier) @name
      ; regular function clause
      (call target: (identifier) @name)
      ; function clause with a guard clause
      (binary_operator
        left: (call target: (identifier) @name)
        operator: "when")
    ])
  (#match? @ignore
"^(def|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp)$"))
@definition.function

The elixir tree sitter implementation is here:
https://github.com/elixir-lang/tree-sitter-elixir

I lack the knowledge to further debug this or find a clean workaround, but
I'm almost sure that treesit-search-forward should never hang.

In GNU Emacs 29.0.50 (build 3, x86_64-pc-linux-gnu, GTK+ Version
 3.24.34, cairo version 1.17.6) of 2022-10-22 built on melissa.local
Repository revision: 7c750343be6309a78d3fd289959bca241d9daf5d
Repository branch: feature/tree-sitter
Windowing system distributor 'The X.Org Foundation', version 11.0.12101004
System Description: Arch Linux

Configured using:
 'configure --with-tree-sitter --with-native-compilation'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON TREE-SITTER LCMS2 LIBSYSTEMD LIBXML2 MODULES NATIVE_COMP NOTIFY
INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS WEBP X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB

Important settings:
  value of $LANG: en_ZA.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message mailcap yank-media puny dired
dired-loaddefs rfc822 mml mml-sec password-cache epa epg rfc6068
epg-config gnus-util text-property-search mm-decode mm-bodies mm-encode
mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047
rfc2045 ietf-drums mm-util mail-prsvr mail-utils time-date comp
comp-cstr warnings icons subr-x cl-extra help-mode bytecomp byte-compile
cconv elixir-mode derived rx pcase cl-macs gv treesit cl-seq cl-loaddefs
cl-lib rmc iso-transl tooltip eldoc paren electric uniquify ediff-hook
vc-hooks lisp-float-type elisp-mode mwheel term/x-win x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode lisp-mode prog-mode register
page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer nadvice seq simple cl-generic indonesian philippine
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite emoji-zwj charscript
charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure
cl-preloaded button loaddefs faces cus-face macroexp files window
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget keymap hashtable-print-readable backquote threads dbusbind
inotify lcms2 dynamic-setting system-font-setting font-render-setting
cairo move-toolbar gtk x-toolkit xinput2 x multi-tty
make-network-process native-compile emacs)

Memory information:
((conses 16 81171 6071)
 (symbols 48 7449 0)
 (strings 32 20132 1351)
 (string-bytes 1 613689)
 (vectors 16 15685)
 (vector-slots 8 324392 11268)
 (floats 8 27 29)
 (intervals 56 211 0)
 (buffers 1008 11))

--000000000000be52c705eb9c89de
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>I am attempting to implement treesit for the current =
elixir-mode using the branch feature/trees-sitter. For implementing beginni=
ng-of-defun-function using treesit I am running into an issue where the Ema=
cs will hang indefinitely. Using (setq-local treesit-defun-type-regexp (rx =
(or &quot;call&quot;))) yields the same result.<br></div><div><br></div><di=
v>For the following node-at-point output<br></div><div><br></div><div>(do_b=
lock (call target: (identifier)))</div><div><br></div><div>with Elixir code=
</div><div><br></div><div># foo.ex<br></div><div>defmodule Foo do<br>=C2=A0=
 &lt;&lt;point/cursor here&gt;&gt;def bar(), do: &quot;bar&quot;<br>end</di=
v><div><br></div><div>When I call `(treesit-search-forward-goto (rx (or &qu=
ot;call&quot;)) &#39;start nil t)` the function `treesit-search-forward` se=
ems to get stuck. <br></div><div><br></div><div>Elixir does not strictly ha=
ve a begin function, but can be determined as one of the following:</div><d=
iv>; * modules and protocols<br>(call<br>=C2=A0 target: (identifier) @ignor=
e<br>=C2=A0 (arguments (alias) @name)<br>=C2=A0 (#match? @ignore &quot;^(de=
fmodule|defprotocol)$&quot;)) @definition.module<br><br>; * functions/macro=
s<br>(call<br>=C2=A0 target: (identifier) @ignore<br>=C2=A0 (arguments<br>=
=C2=A0 =C2=A0 [<br>=C2=A0 =C2=A0 =C2=A0 ; zero-arity functions with no pare=
ntheses<br>=C2=A0 =C2=A0 =C2=A0 (identifier) @name<br>=C2=A0 =C2=A0 =C2=A0 =
; regular function clause<br>=C2=A0 =C2=A0 =C2=A0 (call target: (identifier=
) @name)<br>=C2=A0 =C2=A0 =C2=A0 ; function clause with a guard clause<br>=
=C2=A0 =C2=A0 =C2=A0 (binary_operator<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 left: =
(call target: (identifier) @name)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 operator: =
&quot;when&quot;)<br>=C2=A0 =C2=A0 ])<br>=C2=A0 (#match? @ignore &quot;^(de=
f|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp)$&quot;=
)) @definition.function<br></div><div><br></div><div>The elixir tree sitter=
 implementation is here: <a href=3D"https://github.com/elixir-lang/tree-sit=
ter-elixir">https://github.com/elixir-lang/tree-sitter-elixir</a></div><div=
><br></div><div>I lack the knowledge to further debug this or find a clean =
workaround, but I&#39;m almost sure that treesit-search-forward should neve=
r hang. <br></div><div><br></div><div>In GNU Emacs 29.0.50 (build 3, x86_64=
-pc-linux-gnu, GTK+ Version<br>=C2=A03.24.34, cairo version 1.17.6) of 2022=
-10-22 built on melissa.local<br>Repository revision: 7c750343be6309a78d3fd=
289959bca241d9daf5d<br>Repository branch: feature/tree-sitter<br>Windowing =
system distributor &#39;The X.Org Foundation&#39;, version 11.0.12101004<br=
>System Description: Arch Linux<br><br>Configured using:<br>=C2=A0&#39;conf=
igure --with-tree-sitter --with-native-compilation&#39;<br><br>Configured f=
eatures:<br>ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFB=
UZZ JPEG<br>JSON TREE-SITTER LCMS2 LIBSYSTEMD LIBXML2 MODULES NATIVE_COMP N=
OTIFY<br>INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF<br>TOO=
LKIT_SCROLL_BARS WEBP X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB<br><br>Important s=
ettings:<br>=C2=A0 value of $LANG: en_ZA.UTF-8<br>=C2=A0 locale-coding-syst=
em: utf-8-unix<br><br>Major mode: Lisp Interaction<br><br>Minor modes in ef=
fect:<br>=C2=A0 tooltip-mode: t<br>=C2=A0 global-eldoc-mode: t<br>=C2=A0 el=
doc-mode: t<br>=C2=A0 show-paren-mode: t<br>=C2=A0 electric-indent-mode: t<=
br>=C2=A0 mouse-wheel-mode: t<br>=C2=A0 tool-bar-mode: t<br>=C2=A0 menu-bar=
-mode: t<br>=C2=A0 file-name-shadow-mode: t<br>=C2=A0 global-font-lock-mode=
: t<br>=C2=A0 font-lock-mode: t<br>=C2=A0 blink-cursor-mode: t<br>=C2=A0 li=
ne-number-mode: t<br>=C2=A0 indent-tabs-mode: t<br>=C2=A0 transient-mark-mo=
de: t<br>=C2=A0 auto-composition-mode: t<br>=C2=A0 auto-encryption-mode: t<=
br>=C2=A0 auto-compression-mode: t<br><br>Load-path shadows:<br>None found.=
<br><br>Features:<br>(shadow sort mail-extr emacsbug message mailcap yank-m=
edia puny dired<br>dired-loaddefs rfc822 mml mml-sec password-cache epa epg=
 rfc6068<br>epg-config gnus-util text-property-search mm-decode mm-bodies m=
m-encode<br>mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc=
2047<br>rfc2045 ietf-drums mm-util mail-prsvr mail-utils time-date comp<br>=
comp-cstr warnings icons subr-x cl-extra help-mode bytecomp byte-compile<br=
>cconv elixir-mode derived rx pcase cl-macs gv treesit cl-seq cl-loaddefs<b=
r>cl-lib rmc iso-transl tooltip eldoc paren electric uniquify ediff-hook<br=
>vc-hooks lisp-float-type elisp-mode mwheel term/x-win x-win<br>term/common=
-win x-dnd tool-bar dnd fontset image regexp-opt fringe<br>tabulated-list r=
eplace newcomment text-mode lisp-mode prog-mode register<br>page tab-bar me=
nu-bar rfn-eshadow isearch easymenu timer select<br>scroll-bar mouse jit-lo=
ck font-lock syntax font-core term/tty-colors<br>frame minibuffer nadvice s=
eq simple cl-generic indonesian philippine<br>cham georgian utf-8-lang misc=
-lang vietnamese tibetan thai tai-viet lao<br>korean japanese eucjp-ms cp51=
932 hebrew greek romanian slovak czech<br>european ethiopic indian cyrillic=
 chinese composite emoji-zwj charscript<br>charprop case-table epa-hook jka=
-cmpr-hook help abbrev obarray oclosure<br>cl-preloaded button loaddefs fac=
es cus-face macroexp files window<br>text-properties overlay sha1 md5 base6=
4 format env code-pages mule<br>custom widget keymap hashtable-print-readab=
le backquote threads dbusbind<br>inotify lcms2 dynamic-setting system-font-=
setting font-render-setting<br>cairo move-toolbar gtk x-toolkit xinput2 x m=
ulti-tty<br>make-network-process native-compile emacs)<br><br>Memory inform=
ation:<br>((conses 16 81171 6071)<br>=C2=A0(symbols 48 7449 0)<br>=C2=A0(st=
rings 32 20132 1351)<br>=C2=A0(string-bytes 1 613689)<br>=C2=A0(vectors 16 =
15685)<br>=C2=A0(vector-slots 8 324392 11268)<br>=C2=A0(floats 8 27 29)<br>=
=C2=A0(intervals 56 211 0)<br>=C2=A0(buffers 1008 11))</div></div>

--000000000000be52c705eb9c89de--




Acknowledgement sent to Wilhelm Kirschbaum <wkirschbaum@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#58711; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sun, 13 Nov 2022 04:15:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.