From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Wilhelm Kirschbaum Newsgroups: gmane.emacs.bugs Subject: bug#58711: Treesit hangs when calling treesit-search-forward Date: Fri, 11 Nov 2022 08:30:56 +0200 Message-ID: References: <895A3C87-507A-4FC5-8BAE-B138B35CD40C@gmail.com> <46B629C0-1413-41CE-BDA8-CE14C12B4449@gmail.com> <3054006.Zh9iicr411@melissa.local> <106B8822-FE37-4590-BC77-5FB24FB0758C@gmail.com> <82A013FB-9A94-4E57-9FD2-AF8E892241A9@gmail.com> <7B22DC5E-CCC6-4981-AC61-7774FE2846AA@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000ed19cd05ed2c082c" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31584"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 58711@debbugs.gnu.org To: Yuan Fu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Nov 11 07:32:28 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1otNaV-00084j-QR for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 11 Nov 2022 07:32:28 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1otNa9-0001gx-4j; Fri, 11 Nov 2022 01:32:05 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1otNa7-0001dN-1d for bug-gnu-emacs@gnu.org; Fri, 11 Nov 2022 01:32:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1otNa6-0002OX-PM for bug-gnu-emacs@gnu.org; Fri, 11 Nov 2022 01:32:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1otNa6-0005Ne-J4 for bug-gnu-emacs@gnu.org; Fri, 11 Nov 2022 01:32:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Wilhelm Kirschbaum Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 11 Nov 2022 06:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58711 X-GNU-PR-Package: emacs Original-Received: via spool by 58711-submit@debbugs.gnu.org id=B58711.166814827720630 (code B ref 58711); Fri, 11 Nov 2022 06:32:02 +0000 Original-Received: (at 58711) by debbugs.gnu.org; 11 Nov 2022 06:31:17 +0000 Original-Received: from localhost ([127.0.0.1]:44943 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1otNZN-0005Mf-9G for submit@debbugs.gnu.org; Fri, 11 Nov 2022 01:31:17 -0500 Original-Received: from mail-lf1-f53.google.com ([209.85.167.53]:38449) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1otNZJ-0005MR-OT for 58711@debbugs.gnu.org; Fri, 11 Nov 2022 01:31:15 -0500 Original-Received: by mail-lf1-f53.google.com with SMTP id g7so6978431lfv.5 for <58711@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) In-Reply-To: <7B22DC5E-CCC6-4981-AC61-7774FE2846AA@gmail.com> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:247569 Archived-At: --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 wrote: > > > > On Nov 10, 2022, at 12:43 PM, Wilhelm Kirschbaum < > wilhelm@floatpays.co.za> wrote: > > > > Given the following code > > > > <.foo> ;; component, start_component > > ;; tag, start_tag > > ;; [cursor here 1)] end_tag > > ;; [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 > 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
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@gmail.com> wrote:


> On Nov 10, 2022, at 12:43 PM, Wilhelm Kirschbaum <wilhelm@floatpays.co.za>= wrote:
>
> Given the following code
>
>=C2=A0 <.foo>=C2=A0 ;; component, start_component
>=C2=A0 <bar>=C2=A0 ;; tag, start_tag
>=C2=A0 =C2=A0</bar>;; [cursor here 1)] end_tag
> </.foo> ;; [cursor here 2] end_component
>
> and ast
>
> (fragment [0, 0] - [5, 0]
>=C2=A0 =C2=A0(component [0, 0] - [3, 7]
>=C2=A0 =C2=A0 =C2=A0(start_component [0, 0] - [0, 6]
>=C2=A0 =C2=A0 =C2=A0 =C2=A0(component_name [0, 1] - [0, 5]
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(function [0, 2] - [0, 5])))
>=C2=A0 =C2=A0 =C2=A0(tag [1, 2] - [2, 8]
>=C2=A0 =C2=A0 =C2=A0 =C2=A0(start_tag [1, 2] - [1, 7]
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(tag_name [1, 3] - [1, 6]))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0(end_tag [2, 2] - [2, 8]
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(tag_name [2, 4] - [2, 7])))
>=C2=A0 =C2=A0 =C2=A0(end_component [3, 0] - [3, 7]
>=C2=A0 =C2=A0 =C2=A0 =C2=A0(component_name [3, 2] - [3, 6]
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(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
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(treesit-node= -at (point))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(rx (or "= ;end_tag" "end_component" "end_slot")) t t)))
=C2=A0 ;; Go to the corresponding start tag.
=C2=A0 (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, 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 pare= nt 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, tr= eesit-search-forward would work as expected. I=E2=80=99ll see how to add th= is functionality.

Yuan
--000000000000ed19cd05ed2c082c--