GNU bug report logs - #70789
treesit navigate for outlines at bobp

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: Juri Linkov <juri@HIDDEN>; Done: Juri Linkov <juri@HIDDEN>; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
bug marked as fixed in version 30.0.50, send any further explanations to 70789 <at> debbugs.gnu.org and Juri Linkov <juri@HIDDEN> Request was from Juri Linkov <juri@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

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


Received: (at 70789) by debbugs.gnu.org; 9 May 2024 06:31:52 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu May 09 02:31:52 2024
Received: from localhost ([127.0.0.1]:53344 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1s4xJo-0003ld-8n
	for submit <at> debbugs.gnu.org; Thu, 09 May 2024 02:31:52 -0400
Received: from relay1-d.mail.gandi.net ([217.70.183.193]:39207)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>)
 id 1s4xJh-0003l1-8R; Thu, 09 May 2024 02:31:48 -0400
Received: by mail.gandi.net (Postfix) with ESMTPSA id D495D240005;
 Thu,  9 May 2024 06:31:11 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
To: Yuan Fu <casouri@HIDDEN>
Subject: Re: bug#70789: treesit navigate for outlines at bobp
In-Reply-To: <61713C0C-62CA-4FA1-87CA-2E5A4D38AFA1@HIDDEN> (Yuan Fu's
 message of "Wed, 8 May 2024 17:16:22 -0700")
Organization: LINKOV.NET
References: <86seywi4kk.fsf@HIDDEN>
 <37B3FE57-8ABA-4C10-8F75-EC7FF1A64B74@HIDDEN>
 <86jzk7a1pp.fsf@HIDDEN>
 <61713C0C-62CA-4FA1-87CA-2E5A4D38AFA1@HIDDEN>
Date: Thu, 09 May 2024 09:28:59 +0300
Message-ID: <86seyr1ot0.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-GND-Sasl: juri@HIDDEN
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 70789
Cc: 70789 <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.7 (-)

close 70789 30.0.50
thanks

>>  (treesit-navigate-thing (point-min) 1 'beg "\\`\\(?:class\\|method\\)\\'")
>>
>> can't find "class" at the beginning of the buffer,
>> but after inserting an empty line before "class" it can find it.
>
> I see, from treesit-navigate-thing’s point of view, point is already at the
> beginning of a class, therefore the correct behavior is to go to the beg of
> the next class. Using ‘end is probably more appropriate here, but I know
> you must have good reasons to use ‘beg. How about using
> treesit-search-forward? Wait, am I the one that suggested
> treesit-navigate-thing to you, because it returns higher-leveled nodes
> first?

Indeed.

> In that case, maybe you can use treesit-thing-next to test if point is
> at the beginning of an outline header? That feels a bit easier to
> write and understand to me.

I don't see how treesit-thing-next could be used here since
quoting its doc:

  The returned node, if non-nil, must be after POS, i.e., its
  start >= POS.

> If you prefer the current patch I don’t have problem with it either.

Thanks, so now pushed.




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

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


Received: (at 70789) by debbugs.gnu.org; 9 May 2024 00:17:07 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed May 08 20:17:07 2024
Received: from localhost ([127.0.0.1]:51709 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1s4rT9-0005JU-3l
	for submit <at> debbugs.gnu.org; Wed, 08 May 2024 20:17:07 -0400
Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]:54502)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <casouri@HIDDEN>) id 1s4rT6-0005J4-T9
 for 70789 <at> debbugs.gnu.org; Wed, 08 May 2024 20:17:05 -0400
Received: by mail-pl1-x634.google.com with SMTP id
 d9443c01a7336-1ec4dc64c6cso1836625ad.0
 for <70789 <at> debbugs.gnu.org>; Wed, 08 May 2024 17:16:39 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1715213793; x=1715818593; darn=debbugs.gnu.org;
 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=I18hWEBZjVSV+jGP4cfZ/tDEPN8kdHuFtgm/nhKoMMM=;
 b=Hk9ZAuv0K2l2Y47puUkjgK8Vngal6crhi4YfR2TUzcPxeCP7mMKn1oe+Xv5bQms6zz
 ytaURdvgJVIiXn+XyoQUDd85KXJAYXaQGfuJ80LQgbreJYRcZ5ULJ7om41defQxVApNb
 7bmOZwtdR78p8rlxdTlPbD1EAE5DaErQCFH7bdeX/R/lUFrtGkMXJQa+MMrAGWrq3Mu/
 qY5614oMtMAxuk1yipsAGIGRqLKwa/RdVT0uLznCGg+zLOUQybLfQ76mKJVb4uOlcfGy
 yLrHpUQKcrxlYZOVg657fzO7lAbtC5YjUQq6U89TMox3NLMbWc67uS+exE1r/KbjXrJX
 no3w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1715213793; x=1715818593;
 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=I18hWEBZjVSV+jGP4cfZ/tDEPN8kdHuFtgm/nhKoMMM=;
 b=fYZNAZiTMkS9KvZXneIOJBX3N8/bd6Leb9epHdLFxnVwVAOanFBgMfcYRA5/F/JzYw
 15kE1w0ftVgGqP/RfomJiHGMYmkipTGqwAWA0AguvHhLeSckyAu4gkKKgJSopEoHaR5k
 jFvxxuu/rzysVVu/FDtFnkmsduxj8joB5zGutebGaiDKKo6HPw2HQEJZUykKXzSVcX0F
 Q8Ivma9Z0dKgkoGFefcq9y6AjFYOtPtYmXCuzz6p4PIvbJZyYohHNIUJ73+8qyooahWa
 3cB8uZqHv6rcDEJfYS6cU/XJ0nKqVx6DVWc8QYFUmRkGEcAf7pYKgTSPchi138rdjByq
 gEuw==
X-Gm-Message-State: AOJu0YwKOjOPRkvzEknXoiuERmVf9FVXY55GUxa2zO+bIyLUhFFve0yB
 U/n3xO60eNWqB1q/TGsOo9LJQ8GrTYYwQCNeE7SiaYawQARcSFh2
X-Google-Smtp-Source: AGHT+IFtV1p/3MkbzDUJpZi2MP6zVNqzaDqb7oN45fzp55mnl/AysMZHxSslHMtuB9REggDAEglMlw==
X-Received: by 2002:a17:903:41cc:b0:1e3:e093:b5f0 with SMTP id
 d9443c01a7336-1eeb018707dmr50041505ad.8.1715213793246; 
 Wed, 08 May 2024 17:16:33 -0700 (PDT)
Received: from smtpclient.apple ([2601:641:300:4910:38af:f15:5ce3:fab2])
 by smtp.gmail.com with ESMTPSA id
 d9443c01a7336-1ef0b9d4278sm1371095ad.12.2024.05.08.17.16.32
 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
 Wed, 08 May 2024 17:16:32 -0700 (PDT)
Content-Type: text/plain;
	charset=utf-8
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6.1.1\))
Subject: Re: bug#70789: treesit navigate for outlines at bobp
From: Yuan Fu <casouri@HIDDEN>
In-Reply-To: <86jzk7a1pp.fsf@HIDDEN>
Date: Wed, 8 May 2024 17:16:22 -0700
Content-Transfer-Encoding: quoted-printable
Message-Id: <61713C0C-62CA-4FA1-87CA-2E5A4D38AFA1@HIDDEN>
References: <86seywi4kk.fsf@HIDDEN>
 <37B3FE57-8ABA-4C10-8F75-EC7FF1A64B74@HIDDEN>
 <86jzk7a1pp.fsf@HIDDEN>
To: Juri Linkov <juri@HIDDEN>
X-Mailer: Apple Mail (2.3731.700.6.1.1)
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 70789
Cc: 70789 <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 May 5, 2024, at 11:43 PM, Juri Linkov <juri@HIDDEN> wrote:
>=20
>>> 'treesit-outline-search' didn't match outlines at the beginning of
>>> the buffer because unlike 're-search-forward' (used by outline-mode)
>>> that matches the text that immediately follows point,
>>> 'treesit-navigate-thing' misses text at point and stars the search
>>> after point.
>>>=20
>>> So there is a need to handle this difference specially.  Therefore =
this
>>> patch adds such special-handling of bobp to =
'treesit-outline-search=E2=80=99:
>>=20
>> Thanks.  Just for me to understand it better, could you show an
>> example where treesit-navigate-thing misses text at point?
>=20
> Here is an example:
>=20
> 0. emacs -Q
> 1. C-x C-f =
test/lisp/progmodes/ruby-mode-resources/ruby-method-params-indent.rb
> 2. M-x ruby-ts-mode
> 3. M-: (setq outline-minor-mode-use-buttons t)
> 4. M-x outline-minor-mode
>=20
> There are no outline buttons because the top thing "class"
> is at the beginning of the buffer.  Then you can insert
> an empty line before "class", and disable/enable
> outline-minor-mode again, and outline buttons appear
> on "class" and "def" lines.
>=20
> Basically this is because
>=20
>  (treesit-navigate-thing (point-min) 1 'beg =
"\\`\\(?:class\\|method\\)\\'")
>=20
> can't find "class" at the beginning of the buffer,
> but after inserting an empty line before "class" it can find it.

I see, from treesit-navigate-thing=E2=80=99s point of view, point is =
already at the beginning of a class, therefore the correct behavior is =
to go to the beg of the next class. Using =E2=80=98end is probably more =
appropriate here, but I know you must have good reasons to use =E2=80=98be=
g. How about using treesit-search-forward? Wait, am I the one that =
suggested treesit-navigate-thing to you, because it returns =
higher-leveled nodes first?

In that case, maybe you can use treesit-thing-next to test if point is =
at the beginning of an outline header? That feels a bit easier to write =
and understand to me. If you prefer the current patch I don=E2=80=99t =
have problem with it either.

Yuan






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

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


Received: (at 70789) by debbugs.gnu.org; 6 May 2024 07:08:16 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon May 06 03:08:16 2024
Received: from localhost ([127.0.0.1]:36159 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1s3sSL-0005Ti-0p
	for submit <at> debbugs.gnu.org; Mon, 06 May 2024 03:08:16 -0400
Received: from relay2-d.mail.gandi.net ([2001:4b98:dc4:8::222]:50527)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1s3sSE-0005TG-K3
 for 70789 <at> debbugs.gnu.org; Mon, 06 May 2024 03:08:11 -0400
Received: by mail.gandi.net (Postfix) with ESMTPSA id 48EAF4000C;
 Mon,  6 May 2024 07:07:34 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
To: Yuan Fu <casouri@HIDDEN>
Subject: Re: bug#70789: treesit navigate for outlines at bobp
In-Reply-To: <37B3FE57-8ABA-4C10-8F75-EC7FF1A64B74@HIDDEN> (Yuan Fu's
 message of "Sun, 5 May 2024 20:11:56 -0700")
Organization: LINKOV.NET
References: <86seywi4kk.fsf@HIDDEN>
 <37B3FE57-8ABA-4C10-8F75-EC7FF1A64B74@HIDDEN>
Date: Mon, 06 May 2024 09:43:54 +0300
Message-ID: <86jzk7a1pp.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-GND-Sasl: juri@HIDDEN
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 70789
Cc: 70789 <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.7 (-)

>> 'treesit-outline-search' didn't match outlines at the beginning of
>> the buffer because unlike 're-search-forward' (used by outline-mode)
>> that matches the text that immediately follows point,
>> 'treesit-navigate-thing' misses text at point and stars the search
>> after point.
>>
>> So there is a need to handle this difference specially.  Therefore this
>> patch adds such special-handling of bobp to 'treesit-outline-search’:
>
> Thanks.  Just for me to understand it better, could you show an
> example where treesit-navigate-thing misses text at point?

Here is an example:

0. emacs -Q
1. C-x C-f test/lisp/progmodes/ruby-mode-resources/ruby-method-params-indent.rb
2. M-x ruby-ts-mode
3. M-: (setq outline-minor-mode-use-buttons t)
4. M-x outline-minor-mode

There are no outline buttons because the top thing "class"
is at the beginning of the buffer.  Then you can insert
an empty line before "class", and disable/enable
outline-minor-mode again, and outline buttons appear
on "class" and "def" lines.

Basically this is because

  (treesit-navigate-thing (point-min) 1 'beg "\\`\\(?:class\\|method\\)\\'")

can't find "class" at the beginning of the buffer,
but after inserting an empty line before "class" it can find it.

> If it does, that should be a bug that treesit-navigate-thing should
> fix, right?

I'm not sure if this is a bug.  Maybe it can be described just as
a difference between re-search-forward and treesit-navigate-thing.




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

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


Received: (at 70789) by debbugs.gnu.org; 6 May 2024 03:12:41 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun May 05 23:12:41 2024
Received: from localhost ([127.0.0.1]:35178 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1s3omO-0002re-My
	for submit <at> debbugs.gnu.org; Sun, 05 May 2024 23:12:40 -0400
Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]:59738)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <casouri@HIDDEN>) id 1s3omL-0002rW-U7
 for 70789 <at> debbugs.gnu.org; Sun, 05 May 2024 23:12:39 -0400
Received: by mail-pf1-x435.google.com with SMTP id
 d2e1a72fcca58-6f449ea8e37so1317378b3a.3
 for <70789 <at> debbugs.gnu.org>; Sun, 05 May 2024 20:12:13 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1714965128; x=1715569928; darn=debbugs.gnu.org;
 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=y9kA5yQAWjNjq5r0jiL98aOOG+ynjy6TpIOPjJEFBjE=;
 b=CvdkA/EzrFSuhtuP9uCZqQXKfD3eXtEJb5ybGQZc8WtZsHyqvSNTE8c5RF2l5uAHqy
 f5rPEkG5P8IGd1FyETzMcUSJybS2dzLE+fAoknSltxTgUIBjcjfUb9Ccd+tvfQcqoi+4
 cnY4PiqxD66sjst6A2CRnZCtEL5s2JNiZXU9s6S8Q3BLJ28IjcfbS8LJ7iKrNjLsTV2I
 rQasgGf1mYlQ7M7eYTX5Ku8AYvDsvD/5f/mi9Lxz07Tys7mWjMlwRqqwRmpku8U1nImu
 qn17QFt5K8Q6JDZe/p4QswoXWMRgdIQt1NfgzG7FDyUqobUAJIt7EyYmoNLW2lk7v6Y5
 1kiw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1714965128; x=1715569928;
 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=y9kA5yQAWjNjq5r0jiL98aOOG+ynjy6TpIOPjJEFBjE=;
 b=hlTDeBZVWwhHVJpjo3xKh131cec14dQXEwlG6L6tAYJ83c5rXM8rZHEIrwBJL7wptJ
 y6ZIaIEhSET0otGF19sQ9pnb87q7S/PEg6IIMhPPqInHILJGW7KLxPpdoQr//xeE8CTN
 ejGCdF/fEZ+Lt3yrZeEBIwKIO2I6N8NtQrGJpqgjJ30ezvqPZFa2lu8qm2KepOhL6GhQ
 rPbGcWCx9AcsIGznKrmMwGir+Imyjtb5DL0aRInKnUEuCn+JNAQkp6DF3xuU3GJMfEVM
 4TMZ0mzDO7bBZQ3W+az3Awsg8gIpEpwV+/QOjfaOjP2KIcDMA5nR7fs6GfloMZ8A4qal
 +jYg==
X-Gm-Message-State: AOJu0YwytQ08xekkheAwGVH7Dei0xlRiuNf6D5uLiU7hsF/dnzYvJdxr
 wVs1B6uNzikXJehXAg1tAG8jXhnzymBw2XafHBOqznXglu2YSoMF
X-Google-Smtp-Source: AGHT+IEzYqtYXzfgzgXGCV8CEck1ribeVwNMbXC8BTBhNVhJAswIl8gp6CHsLeV3uAeuvW9Kqi9cqw==
X-Received: by 2002:a05:6a20:7295:b0:1a7:5fbf:3774 with SMTP id
 o21-20020a056a20729500b001a75fbf3774mr13595673pzk.55.1714965127781; 
 Sun, 05 May 2024 20:12:07 -0700 (PDT)
Received: from smtpclient.apple ([2601:641:300:4910:8c94:1882:61e7:40ed])
 by smtp.gmail.com with ESMTPSA id
 nc15-20020a17090b37cf00b002b115be650bsm8920220pjb.10.2024.05.05.20.12.06
 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
 Sun, 05 May 2024 20:12:07 -0700 (PDT)
Content-Type: text/plain;
	charset=utf-8
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6.1.1\))
Subject: Re: bug#70789: treesit navigate for outlines at bobp
From: Yuan Fu <casouri@HIDDEN>
In-Reply-To: <86seywi4kk.fsf@HIDDEN>
Date: Sun, 5 May 2024 20:11:56 -0700
Content-Transfer-Encoding: quoted-printable
Message-Id: <37B3FE57-8ABA-4C10-8F75-EC7FF1A64B74@HIDDEN>
References: <86seywi4kk.fsf@HIDDEN>
To: Juri Linkov <juri@HIDDEN>
X-Mailer: Apple Mail (2.3731.700.6.1.1)
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 70789
Cc: 70789 <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 May 5, 2024, at 9:52 AM, Juri Linkov <juri@HIDDEN> wrote:
>=20
> 'treesit-outline-search' didn't match outlines at the beginning of
> the buffer because unlike 're-search-forward' (used by outline-mode)
> that matches the text that immediately follows point,
> 'treesit-navigate-thing' misses text at point and stars the search
> after point.
>=20
> So there is a need to handle this difference specially.  Therefore =
this
> patch adds such special-handling of bobp to =
'treesit-outline-search=E2=80=99:

Thanks. Just for me to understand it better, could you show an example =
where treesit-navigate-thing misses text at point? If it does, that =
should be a bug that treesit-navigate-thing should fix, right?

Yuan






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

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


Received: (at submit) by debbugs.gnu.org; 5 May 2024 16:56:11 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun May 05 12:56:11 2024
Received: from localhost ([127.0.0.1]:60681 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1s3f9m-0001i5-Uu
	for submit <at> debbugs.gnu.org; Sun, 05 May 2024 12:56:11 -0400
Received: from lists.gnu.org ([2001:470:142::17]:53256)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1s3f9j-0001hX-VC
 for submit <at> debbugs.gnu.org; Sun, 05 May 2024 12:56:09 -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 <juri@HIDDEN>) id 1s3f98-0004VA-6n
 for bug-gnu-emacs@HIDDEN; Sun, 05 May 2024 12:55:30 -0400
Received: from relay5-d.mail.gandi.net ([217.70.183.197])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <juri@HIDDEN>) id 1s3f95-0003WA-6T
 for bug-gnu-emacs@HIDDEN; Sun, 05 May 2024 12:55:29 -0400
Received: by mail.gandi.net (Postfix) with ESMTPSA id 1BC741C0004
 for <bug-gnu-emacs@HIDDEN>; Sun,  5 May 2024 16:55:23 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: treesit navigate for outlines at bobp
Organization: LINKOV.NET
X-Debbugs-Cc: Yuan Fu <casouri@HIDDEN>
Date: Sun, 05 May 2024 19:52:43 +0300
Message-ID: <86seywi4kk.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-GND-Sasl: juri@HIDDEN
Received-SPF: pass client-ip=217.70.183.197; envelope-from=juri@HIDDEN;
 helo=relay5-d.mail.gandi.net
X-Spam_score_int: -25
X-Spam_score: -2.6
X-Spam_bar: --
X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7,
 RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 0.7 (/)
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: -0.3 (/)

--=-=-=
Content-Type: text/plain

'treesit-outline-search' didn't match outlines at the beginning of
the buffer because unlike 're-search-forward' (used by outline-mode)
that matches the text that immediately follows point,
'treesit-navigate-thing' misses text at point and stars the search
after point.

So there is a need to handle this difference specially.  Therefore this
patch adds such special-handling of bobp to 'treesit-outline-search':


--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline; filename=treesit-outline-search-bobp.patch

diff --git a/lisp/treesit.el b/lisp/treesit.el
index e55e04e53b3..86ed1bbae33 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -2884,15 +2884,21 @@ treesit-outline-search
                   (start (treesit-node-start node)))
         (eq (pos-bol) (save-excursion (goto-char start) (pos-bol))))
 
-    (let* ((pos
+    (let* ((bob-pos
+            ;; `treesit-navigate-thing' can't find a thing at bobp,
+            ;; so use `looking-at' to match at bobp.
+            (and (bobp) (treesit-outline-search bound move backward t) (point)))
+           (pos
             ;; When function wants to find the current outline, point
             ;; is at the beginning of the current line.  When it wants
             ;; to find the next outline, point is at the second column.
-            (if (eq (point) (pos-bol))
-                (if (bobp) (point) (1- (point)))
-              (pos-eol)))
-           (found (treesit-navigate-thing pos (if backward -1 1) 'beg
-                                          treesit-outline-predicate)))
+            (unless bob-pos
+              (if (eq (point) (pos-bol))
+                  (if (bobp) (point) (1- (point)))
+                (pos-eol))))
+           (found (or bob-pos
+                      (treesit-navigate-thing pos (if backward -1 1) 'beg
+                                              treesit-outline-predicate))))
       (if found
           (if (or (not bound) (if backward (>= found bound) (<= found bound)))
               (progn

--=-=-=--




Acknowledgement sent to Juri Linkov <juri@HIDDEN>:
New bug report received and forwarded. Copy sent to casouri@HIDDEN, bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to casouri@HIDDEN, bug-gnu-emacs@HIDDEN:
bug#70789; 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: Thu, 9 May 2024 06:45:02 UTC

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