Juri Linkov <juri@HIDDEN>
to control <at> debbugs.gnu.org.
Full text available.
Received: (at 80837) by debbugs.gnu.org; 30 Apr 2026 15:41:40 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Apr 30 11:41:40 2026
Received: from localhost ([127.0.0.1]:56233 helo=debbugs.gnu.org)
by debbugs.gnu.org with esmtp (Exim 4.84_2)
(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
id 1wITWF-0001DA-W8
for submit <at> debbugs.gnu.org; Thu, 30 Apr 2026 11:41:40 -0400
Received: from mout-p-101.mailbox.org ([2001:67c:2050:0:465::101]:57604)
by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
(Exim 4.84_2) (envelope-from <juri@HIDDEN>) id 1wITVz-00018z-QI
for 80837 <at> debbugs.gnu.org; Thu, 30 Apr 2026 11:41:25 -0400
Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
(No client certificate requested)
by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4g5z0n1CzQz9tsV;
Thu, 30 Apr 2026 17:41:13 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linkov.net; s=MBO0001;
t=1777563673;
h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
to:to:cc:cc:mime-version:mime-version:content-type:content-type:
content-transfer-encoding:content-transfer-encoding:
in-reply-to:in-reply-to:references:references;
bh=5p5NWe9UYyftyTfiee9a1sjuIZR42sDWAdyxmqRfJWA=;
b=g8vSRjjn6+TyOxr+biK+25paaIzLgS03PyltuFjP2je0esIjuNtc2r9/0cxgnws6BFeF8N
mg/YfSkhH9ukH55oYj6ln8/l+bPmhZvU/XSZYKqV6cDEEoAUejZbUtHdbbFYqrD7OpSJqD
19Qo1Bin0jL3fcw+j8hy6HhrxszLRY4RBFoKcFnHid0Ehtw+OlkORSAi9BQ+BYTAU3gR3u
fvrVxtB8TAjac8cnKrhxWKC55rv2dbfYSvH43wwH1VtWSVrj3J3nyCNPFhJ/kMOn2vaGRF
AsPeHpQdVc5vVzAWFyajXM3HZUpUAQa8TYoNRBxv3JLtrXrk5fdyGcWoLFziKA==
From: Juri Linkov <juri@HIDDEN>
To: Yuan Fu <casouri@HIDDEN>
Subject: Re: bug#80837: treesit-forward-comment off-by-one issue: overshoots
by one character
In-Reply-To: <678B0681-921F-4A07-8432-C6C716B84F46@HIDDEN>
Organization: LINKOV.NET
References: <ee8e55cc-d3fb-4ef9-9868-b8da4f3362ff@HIDDEN>
<87mrz2uchs.fsf@HIDDEN>
<A2D955D2-AB1A-45E5-9C8B-A13C82FEA734@HIDDEN>
<87zf31ek6k.fsf@HIDDEN> <87a4ux7kjj.fsf@HIDDEN>
<875x5ks4fa.fsf@HIDDEN>
<0777647F-0B38-4473-A76B-BA777629D31A@HIDDEN>
<871pg758em.fsf@HIDDEN>
<678B0681-921F-4A07-8432-C6C716B84F46@HIDDEN>
Date: Thu, 30 Apr 2026 18:24:10 +0300
Message-ID: <87a4ukeeap.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 80837
Cc: 80837 <at> debbugs.gnu.org, Bozhidar Batsov <bozhidar@HIDDEN>
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 (-)
>> Could you find an example of a ts-mode that uses both line and block
>> comments at the same time? I can find only 'c-ts-mode-toggle-comment-style'
>> and 'php-ts-mode-set-comment-style' that switch between them.
>
> Maybe we’re not on the same page. Most C-like languages support both line
> and block comments. So major mode for these languages will set comment-end,
> so checking comment-end == “” isn’t a good check for whether the comment at
> point is line or block comment.
I know, but I can't find where block and line comments are used
simultaneously. For example, 'c-ts-mode-toggle-comment-style'
toggles between block and line comments.
>>> Better to strip the whitespace and do a string match, I think.
>>
>> Please clarify, do you mean something like
>> (string-empty-p (string-trim comment-end))
>
> I’m thinking of
>
> (save-excursion
> (goto-char (treesit-node-end node))
> (looking-back (regexp-quote
> (string-trim comment-end))
> (length (string-trim comment-end))))
How this could detect a line comment
when 'comment-end' is e.g. " */"?
> But anyway, comment-end probably isn’t a great heuristic since I found
> that some major modes that supports block comment syntax doesn’t set
> it, presumably because line comment is the “default” comment syntax.
bug#77424 briefly added dedicated variables 'block-comment-start'
and 'block-comment-end' that were reverted in bug#77823.
> Ok, what do you think about this heuristic? Since we already know the node
> is a comment node verified by the parser, this heuristics should be pretty
> reliable.
> +(defvar treesit--block-comment-heuristic
> + (let* ((pairs
> + '(("/*" . "*/") ; C, C++, Java, JS, Rust, Go, CSS, SQL, PHP
> + ("(*" . "*)") ; Pascal, Clojure, OCaml, SML, F#, AppleScript
> + ("{-" . "-}") ; Haskell, Elm, Agda
> + ("#|" . "|#") ; Common Lisp, Racket, Scheme
> + ("<#" . "#>") ; PowerShell
> + ("--[[" . "]]") ; Lua
> + ("<!--" . "-->") ; HTML, XML, Markdown
> + ("%{" . "%}") ; MATLAB, Octave
> + ("\"" . "\"") ; Smalltalk
> + ("###" . "###") ; CoffeeScript
> + ("{" . "}") ; Delphi, Pascal
> + ("(" . ")")) ; Forth
I think maintaining a database of many different comment
styles in treesit.el is not the right thing to do.
For example, why there is no comments <%!-- --%> and <%# %>
for heex-ts-mode existing in Emacs core, etc.
bug-gnu-emacs@HIDDEN:bug#80837; Package emacs.
Full text available.
Received: (at 80837) by debbugs.gnu.org; 30 Apr 2026 07:16:28 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Apr 30 03:16:28 2026
Received: from localhost ([127.0.0.1]:52044 helo=debbugs.gnu.org)
by debbugs.gnu.org with esmtp (Exim 4.84_2)
(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
id 1wILdL-0000ne-Gu
for submit <at> debbugs.gnu.org; Thu, 30 Apr 2026 03:16:28 -0400
Received: from mail-dy1-x1336.google.com ([2607:f8b0:4864:20::1336]:50222)
by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
(Exim 4.84_2) (envelope-from <casouri@HIDDEN>) id 1wILdI-0000n6-IF
for 80837 <at> debbugs.gnu.org; Thu, 30 Apr 2026 03:16:25 -0400
Received: by mail-dy1-x1336.google.com with SMTP id
5a478bee46e88-2e221a71e19so862005eec.0
for <80837 <at> debbugs.gnu.org>; Thu, 30 Apr 2026 00:16:24 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1777533383; x=1778138183; darn=debbugs.gnu.org;
h=references:to:cc:in-reply-to:date:subject:mime-version:message-id
:from:from:to:cc:subject:date:message-id:reply-to;
bh=QsP5CqMPRGfPmAxRmw1GHC3mzL/bzpsrsf1qmxy3eKA=;
b=ZIm6jSWbQW9YujBcIw2SPyxT3F4saoNjIoGle1DkV1G2b2zfAIt9Z4WDqyH1cHUrVk
826RxZlLHEvSnhPokPlGO3LUn8ppPQnFkYakVMy+3e5Ys/XV8FnajXIu//mN6VRDcy/I
Px+xFr673QaMqrjeLVcqmZAVZ1Cm7y4U2TWcce4plfIH/3m8PMTzcBF95+8jMBGDkypa
fKFKHhs/F4t52fACDukpXFZZb2hjZQVk0gl4ceB2xc0+H9eAAgZfkXVs8mTUBe3EBawV
fMLwvbgn+NSuHU0rbtqopXrqkk7SVYZrsYcZEzk3QY/BY1unb1G6VsbBsAH19Jq/gLAq
fxQA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20251104; t=1777533383; x=1778138183;
h=references:to:cc:in-reply-to:date:subject:mime-version:message-id
:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id
:reply-to;
bh=QsP5CqMPRGfPmAxRmw1GHC3mzL/bzpsrsf1qmxy3eKA=;
b=Fo/Lhis94TZPuMzQXGySBHH8s77+kjO1iuAy+GjOsQrDQPIxVWM0FIxf72y8AswF7I
lR56lSRUQJeXr4oCt1qjRCrvvc2MkJWUjicBiRVQgrgl7jLXxVfxup1oTtm39KUhWvz/
80U76bjbuJHNSWiPYb0IazkaQgvgg8jfzvxL0cvFEgBm2CqEr5a+bpwq3psEb1bkOAWR
8QrBfyIPvv+e0FPevPhMFG+LhX2o90RXi2jHEELP7dpq2HMW46zAN7kVdDsNvnlCv99/
HnkNjpLhmdcV0IynP3LOJBQxX1OP1lv1FxQasw7t3j9o9t31wWjdye4BzSUtQN2gl/uG
axbw==
X-Gm-Message-State: AOJu0YyZTqVnIwSG35PXTgXBfQ3Ne5G/axuSrKzLAzq3Q9hA8Bepb6do
EBvvc3pTuFKFuCEoHmNkUA+NuhJ9Nx+HysIWFkW3FMiO7BT9NFuRhvtA
X-Gm-Gg: AeBDiet/MBKN8HZpupQusa01umT99MOKVJzJ4V5J0fWiXM0l+bU271lkeNcA+o11DTP
s1uoVPjvGUS5xKWECrbGt0Gh/06ItK4HrmQ/dxBbAYEA1BUoVKOWG2ymcYmnR1c9gvlEsac5WdN
P0NEcmOPeSK9awGIo1t1rh2qrXH0uuKGlAeqcMlPMrlDPWIRKek+ymRAxubEznRbvA1JvipS8ET
HA0jRG9pdxfy+TYhbWTVaF7kt2VfsVHPkWN4mRcGcgu17umARqbqMjDhZm7zD8F42E0KTW+psL0
oIZ3bSNP2KFbNa7TwCEr+mklaBPqihm6XVhv37oX20vwRdoRej9LQUNlCJ8udXerKGsamvMOyjM
Lc4nU15jF6co8UhZFo5z3IeljipVnQKVQk2zyHfNNy+JL1ggAHb64RV6GHk+IZih6eEoOSnkiAf
UmSpk/3EuD9vqHlMAliPJKybytmQRJ4eA0iCTFKeBtyYa2D+K66GwDHqSY
X-Received: by 2002:a05:7300:e614:b0:2dd:c066:c02 with SMTP id
5a478bee46e88-2ed3dbc07a9mr775844eec.22.1777533382885;
Thu, 30 Apr 2026 00:16:22 -0700 (PDT)
Received: from smtpclient.apple ([2601:645:c686:b320:19b1:e3f2:b31a:17cb])
by smtp.gmail.com with ESMTPSA id
5a478bee46e88-2ed1bf8e281sm5669438eec.9.2026.04.30.00.16.22
(version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
Thu, 30 Apr 2026 00:16:22 -0700 (PDT)
From: Yuan Fu <casouri@HIDDEN>
Message-Id: <678B0681-921F-4A07-8432-C6C716B84F46@HIDDEN>
Content-Type: multipart/mixed;
boundary="Apple-Mail=_AD9468CE-7A4A-4F5F-AB60-965CF7348CAF"
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\))
Subject: Re: bug#80837: treesit-forward-comment off-by-one issue: overshoots
by one character
Date: Thu, 30 Apr 2026 00:16:11 -0700
In-Reply-To: <871pg758em.fsf@HIDDEN>
To: Juri Linkov <juri@HIDDEN>
References: <ee8e55cc-d3fb-4ef9-9868-b8da4f3362ff@HIDDEN>
<87mrz2uchs.fsf@HIDDEN>
<A2D955D2-AB1A-45E5-9C8B-A13C82FEA734@HIDDEN>
<87zf31ek6k.fsf@HIDDEN> <87a4ux7kjj.fsf@HIDDEN>
<875x5ks4fa.fsf@HIDDEN>
<0777647F-0B38-4473-A76B-BA777629D31A@HIDDEN>
<871pg758em.fsf@HIDDEN>
X-Mailer: Apple Mail (2.3826.700.81)
X-Spam-Score: 1.0 (+)
X-Debbugs-Envelope-To: 80837
Cc: 80837 <at> debbugs.gnu.org, Bozhidar Batsov <bozhidar@HIDDEN>
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.0 (/)
--Apple-Mail=_AD9468CE-7A4A-4F5F-AB60-965CF7348CAF
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=utf-8
> On Apr 22, 2026, at 8:30=E2=80=AFAM, Juri Linkov <juri@HIDDEN> =
wrote:
>=20
>> I was thinking more like a heuristic that checks for */ *) etc, since
>> there=E2=80=99s only that many block comments in the world (right? =
right?) But
>> I admit it=E2=80=99s clearly not a 100% solution.
>=20
> For example, HTML comments: (setq-local comment-end " -->")
>=20
>> Comment end could be a nice solution too, since major modes _ought =
to_
>> define them. But I don=E2=80=99t think comparing it to empty string =
is that useful,
>> languages that has both line and block comments will define that
>> variable.
>=20
> Could you find an example of a ts-mode that uses both line and block
> comments at the same time? I can find only =
'c-ts-mode-toggle-comment-style'
> and 'php-ts-mode-set-comment-style' that switch between them.
Maybe we=E2=80=99re not on the same page. Most C-like languages support =
both line and block comments. So major mode for these languages will set =
comment-end, so checking comment-end =3D=3D =E2=80=9C=E2=80=9D isn=E2=80=99=
t a good check for whether the comment at point is line or block =
comment.
>=20
>> Better to strip the whitespace and do a string match, I think.
>=20
> Please clarify, do you mean something like
> (string-empty-p (string-trim comment-end))
I=E2=80=99m thinking of
(save-excursion
(goto-char (treesit-node-end node))
(looking-back (regexp-quote
(string-trim comment-end))
(length (string-trim comment-end))))
But anyway, comment-end probably isn=E2=80=99t a great heuristic since I =
found that some major modes that supports block comment syntax doesn=E2=80=
=99t set it, presumably because line comment is the =E2=80=9Cdefault=E2=80=
=9D comment syntax.
>=20
>> IMHO we should do both: use a dedicate function for uncomment region, =
since
>=20
> Any ts-mode can already override 'uncomment-region-function'
> to use specifics of its grammar. But I think no general treesit
> function is possible that would cover all grammars.
Actually, yeah, this seems to be a rare case where a tree-sitter version =
wouldn=E2=80=99t be better than the default implementation.
>> that=E2=80=99s usually how we deal with these kind of functions. But =
it=E2=80=99s probably
>> good to make tree-sitter=E2=80=99s forward-comment behave exactly =
like the old one
>> as much as possible, for a) ergonomics (it=E2=80=99s definitely more =
convenient to
>> go directly to the next line rather than EOL when the comment is a =
line
>> comment), and b) there might be other functions that rely on that =
behavior
>> out in the wilds.
>=20
> Agreed.
Ok, what do you think about this heuristic? Since we already know the =
node is a comment node verified by the parser, this heuristics should be =
pretty reliable.
Yuan
--Apple-Mail=_AD9468CE-7A4A-4F5F-AB60-965CF7348CAF
Content-Disposition: attachment;
filename=block-comment-heuristic.patch
Content-Type: application/octet-stream;
x-unix-mode=0644;
name="block-comment-heuristic.patch"
Content-Transfer-Encoding: quoted-printable
=46rom=206f2e350df2fd4a03e68e75c79a53d3f34f47bac3=20Mon=20Sep=2017=20=
00:00:00=202001=0AFrom:=20Yuan=20Fu=20<casouri@HIDDEN>=0ADate:=20Thu,=20=
30=20Apr=202026=2000:12:28=20-0700=0ASubject:=20[PATCH]=20Use=20a=20=
heuristic=20to=20imitate=20forward-comment=20in=20tree-sitter=0A=20=
(bug#80837)=0A=0ALine=20comment:=20go=20to=20next=20line=0ABlock=20=
comment:=20go=20to=20end=20of=20comment=0A=0A*=20lisp/treesit.el=20=
(treesit--block-comment-heuristic):=20New=20variable.=0A=
(treesit--probably-block-comment-p):=20new=20function.=0A=
(treesit-forward-comment):=20Use=20the=20heuristic.=0A---=0A=20=
lisp/treesit.el=20|=2056=20=
++++++++++++++++++++++++++++++++++++++++++++++---=0A=201=20file=20=
changed,=2053=20insertions(+),=203=20deletions(-)=0A=0Adiff=20--git=20=
a/lisp/treesit.el=20b/lisp/treesit.el=0Aindex=204579d416f34..7065c310434=20=
100644=0A---=20a/lisp/treesit.el=0A+++=20b/lisp/treesit.el=0A@@=20=
-3747,22=20+3747,72=20@@=20treesit-forward-sentence=0A=20=20=20=20=20=20=20=
=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(max=20(point-min)=20=
(previous-single-char-property-change=0A=20=20=20=20=20=20=20=20=20=20=20=
=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=
=20=20=20=20(point)=20'treesit-parser)))))))=0A=20=0A-(defun=20=
treesit-forward-comment=20(&optional=20count)=0A+(defvar=20=
treesit--block-comment-heuristic=0A+=20=20(let*=20((pairs=0A+=20=20=20=20=
=20=20=20=20=20=20'(("/*"=20.=20"*/")=20=20=20=20=20=20;=20C,=20C++,=20=
Java,=20JS,=20Rust,=20Go,=20CSS,=20SQL,=20PHP=0A+=20=20=20=20=20=20=20=20=
=20=20=20=20("(*"=20.=20"*)")=20=20=20=20=20=20;=20Pascal,=20Clojure,=20=
OCaml,=20SML,=20F#,=20AppleScript=0A+=20=20=20=20=20=20=20=20=20=20=20=20=
("{-"=20.=20"-}")=20=20=20=20=20=20;=20Haskell,=20Elm,=20Agda=0A+=20=20=20=
=20=20=20=20=20=20=20=20=20("#|"=20.=20"|#")=20=20=20=20=20=20;=20Common=20=
Lisp,=20Racket,=20Scheme=0A+=20=20=20=20=20=20=20=20=20=20=20=20("<#"=20=
.=20"#>")=20=20=20=20=20=20;=20PowerShell=0A+=20=20=20=20=20=20=20=20=20=20=
=20=20("--[["=20.=20"]]")=20=20=20=20;=20Lua=0A+=20=20=20=20=20=20=20=20=20=
=20=20=20("<!--"=20.=20"-->")=20=20=20;=20HTML,=20XML,=20Markdown=0A+=20=20=
=20=20=20=20=20=20=20=20=20=20("%{"=20.=20"%}")=20=20=20=20=20=20;=20=
MATLAB,=20Octave=0A+=20=20=20=20=20=20=20=20=20=20=20=20("\""=20.=20=
"\"")=20=20=20=20=20=20;=20Smalltalk=0A+=20=20=20=20=20=20=20=20=20=20=20=
=20("###"=20.=20"###")=20=20=20=20;=20CoffeeScript=0A+=20=20=20=20=20=20=20=
=20=20=20=20=20("{"=20.=20"}")=20=20=20=20=20=20=20=20;=20Delphi,=20=
Pascal=0A+=20=20=20=20=20=20=20=20=20=20=20=20("("=20.=20")"))=20=20=20=20=
=20=20=20;=20Forth=0A+=20=20=20=20=20=20=20=20=20=20)=0A+=20=20=20=20=20=20=
=20=20=20(beg-list=0A+=20=20=20=20=20=20=20=20=20=20(mapcar=20#'car=20=
pairs))=0A+=20=20=20=20=20=20=20=20=20(end-list=0A+=20=20=20=20=20=20=20=20=
=20=20(mapcar=20#'cdr=20pairs)))=0A+=20=20=20=20(cons=20(regexp-opt=20=
beg-list)=0A+=20=20=20=20=20=20=20=20=20=20(regexp-opt=20end-list)))=0A+=20=
=20"Heuristic=20regexp=20of=20beginning=20and=20end=20of=20block=20=
comments.=0A+=0A+The=20car=20is=20regexp=20matching=20beginning=20of=20=
block=20comments,=20the=20cdr=20is=0A+regexp=20mathcing=20the=20end.")=0A=
+=0A+;;=20We=20don't=20verify=20if=20the=20beginning=20and=20end=20comes=20=
from=20the=20same=20pair,=0A+;;=20but=20this=20should=20suffice:=20=
afterall,=20the=20parser=20has=20done=20the=20hard=20work=0A+;;=20and=20=
we=20already=20know=20the=20node=20must=20be=20a=20comment=20node.=20=20=
This=20is=20just=20a=0A+;;=20fallback=20when=20major=20mode=20doesn't=20=
provide=20their=20own=20check.=0A+(defun=20=
treesit--probably-block-comment-p=20(node)=0A+=20=20"Return=20non-nil=20=
if=20NODE=20is=20probably=20a=20block=20comment."=0A+=20=20=
(save-excursion=0A+=20=20=20=20(catch=20'return=0A+=20=20=20=20=20=20=
(let=20(beg-match=20end-match)=0A+=20=20=20=20=20=20=20=20(goto-char=20=
(treesit-node-start=20node))=0A+=20=20=20=20=20=20=20=20(when=20(not=20=
(looking-at=20(car=20treesit--block-comment-heuristic)))=0A+=20=20=20=20=20=
=20=20=20=20=20(throw=20'return=20nil))=0A+=20=20=20=20=20=20=20=20=
(goto-char=20(treesit-node-end=20node))=0A+=20=20=20=20=20=20=20=20(when=20=
(not=20(looking-back=20(cdr=20treesit--block-comment-heuristic)=203))=0A=
+=20=20=20=20=20=20=20=20=20=20(throw=20'return=20nil))=0A+=20=20=20=20=20=
=20=20=20t))))=0A+=0A+(defun=20treesit-forward-comment=20(count)=0A=20=20=
=20"Tree-sitter=20`forward-comment-function'=20implementation.=0A=20=0A=20=
COUNT=20is=20the=20same=20as=20in=20`forward-comment'."=0A-=20=20(let=20=
((res=20t)=20thing)=0A+=20=20(let=20((res=20t)=20thing=20=
block-comment-p)=0A=20=20=20=20=20(while=20(>=20count=200)=0A=20=20=20=20=
=20=20=20(skip-chars-forward=20"=20\t\n")=0A=20=20=20=20=20=20=20(setq=20=
thing=20(treesit-thing-at=20(point)=20'comment))=0A+=20=20=20=20=20=20=
(setq=20block-comment-p=20(and=20thing=20=
(treesit--probably-block-comment-p=20thing)))=0A=20=20=20=20=20=20=20(if=20=
(and=20thing=20(eq=20(point)=20(treesit-node-start=20thing)))=0A=20=20=20=
=20=20=20=20=20=20=20=20(progn=0A-=20=20=20=20=20=20=20=20=20=20=20=20=
(goto-char=20(min=20(1+=20(treesit-node-end=20thing))=20(point-max)))=0A=
+=20=20=20=20=20=20=20=20=20=20=20=20(goto-char=20(min=20=
(treesit-node-end=20thing)=20(point-max)))=0A+=20=20=20=20=20=20=20=20=20=
=20=20=20;;=20For=20line=20comments,=20go=20to=20the=20next=20line.=0A+=20=
=20=20=20=20=20=20=20=20=20=20=20(when=20(not=20block-comment-p)=0A+=20=20=
=20=20=20=20=20=20=20=20=20=20=20=20(skip-chars-forward=20"=20\t")=0A+=20=
=20=20=20=20=20=20=20=20=20=20=20=20=20(when=20(looking-at=20"\n")=0A+=20=
=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(forward-char)))=0A=20=20=20=
=20=20=20=20=20=20=20=20=20=20(setq=20count=20(1-=20count)))=0A=20=20=20=20=
=20=20=20=20=20(setq=20count=200=20res=20nil)))=0A=20=20=20=20=20(while=20=
(<=20count=200)=0A=20=20=20=20=20=20=20(skip-chars-backward=20"=20\t\n")=0A=
=20=20=20=20=20=20=20(setq=20thing=20(treesit-thing-at=20(max=20(1-=20=
(point))=20(point-min))=20'comment))=0A+=20=20=20=20=20=20(setq=20=
block-comment-p=20(and=20thing=20(treesit--probably-block-comment-p=20=
thing)))=0A=20=20=20=20=20=20=20(if=20(and=20thing=20(eq=20(point)=20=
(treesit-node-end=20thing)))=0A=20=20=20=20=20=20=20=20=20=20=20(progn=0A=
=20=20=20=20=20=20=20=20=20=20=20=20=20(goto-char=20(treesit-node-start=20=
thing))=0A--=20=0A2.39.5=20(Apple=20Git-154)=0A=0A=
--Apple-Mail=_AD9468CE-7A4A-4F5F-AB60-965CF7348CAF
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=us-ascii
--Apple-Mail=_AD9468CE-7A4A-4F5F-AB60-965CF7348CAF--
bug-gnu-emacs@HIDDEN:bug#80837; Package emacs.
Full text available.Received: (at 80837) by debbugs.gnu.org; 22 Apr 2026 15:30:56 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Wed Apr 22 11:30:56 2026 Received: from localhost ([127.0.0.1]:38506 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1wFZXT-0006Lx-UX for submit <at> debbugs.gnu.org; Wed, 22 Apr 2026 11:30:56 -0400 Received: from mout-p-201.mailbox.org ([80.241.56.171]:39556) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <juri@HIDDEN>) id 1wFZXS-0006Lb-DL for 80837 <at> debbugs.gnu.org; Wed, 22 Apr 2026 11:30:55 -0400 Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4g138Q2Xcsz9v0h; Wed, 22 Apr 2026 17:30:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linkov.net; s=MBO0001; t=1776871846; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W5kkQpR6Y7JXkT1w9GshV2n0XlmRq5GaZfKKl1qkZ+w=; b=oG2H4GcGYYq8bAaS465LEUW+j+l5R/0HoYcotQPOvgK/J5PaZVSoPw3zYG06tn1e198lv6 nkodgfnDGsaZMFSdLelQGzfkjtuDoqwzqQHJL5Yn1QtHg7rcyAMtABbqlPIGFa9Hv6IJQB PCmrxIzasOvyllBp5Loyn/ggSCo7JgrM+9GbGvqeKx4Zzlr5dUPAe8psJZ5J8g316CDqTE juyeeY+rAaZ8XM274yy2Hul35Y9jdLOVKidnXV7InfGaV5F3xSBcrw5iPyAlRfAOKoUoXe f/5gHHBreWsh3vyknDo9E7AbNG0VXmjEytd4AHmQnABIf+SISebhF1OMYxAT2Q== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of juri@HIDDEN designates 2001:67c:2050:b231:465::102 as permitted sender) smtp.mailfrom=juri@HIDDEN From: Juri Linkov <juri@HIDDEN> To: Yuan Fu <casouri@HIDDEN> Subject: Re: bug#80837: treesit-forward-comment off-by-one issue: overshoots by one character In-Reply-To: <0777647F-0B38-4473-A76B-BA777629D31A@HIDDEN> Organization: LINKOV.NET References: <ee8e55cc-d3fb-4ef9-9868-b8da4f3362ff@HIDDEN> <87mrz2uchs.fsf@HIDDEN> <A2D955D2-AB1A-45E5-9C8B-A13C82FEA734@HIDDEN> <87zf31ek6k.fsf@HIDDEN> <87a4ux7kjj.fsf@HIDDEN> <875x5ks4fa.fsf@HIDDEN> <0777647F-0B38-4473-A76B-BA777629D31A@HIDDEN> Date: Wed, 22 Apr 2026 18:30:17 +0300 Message-ID: <871pg758em.fsf@HIDDEN> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4g138Q2Xcsz9v0h X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 80837 Cc: 80837 <at> debbugs.gnu.org, Bozhidar Batsov <bozhidar@HIDDEN> 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 (-) > I was thinking more like a heuristic that checks for */ *) etc, since > there’s only that many block comments in the world (right? right?) But > I admit it’s clearly not a 100% solution. For example, HTML comments: (setq-local comment-end " -->") > Comment end could be a nice solution too, since major modes _ought to_ > define them. But I don’t think comparing it to empty string is that useful, > languages that has both line and block comments will define that > variable. Could you find an example of a ts-mode that uses both line and block comments at the same time? I can find only 'c-ts-mode-toggle-comment-style' and 'php-ts-mode-set-comment-style' that switch between them. > Better to strip the whitespace and do a string match, I think. Please clarify, do you mean something like (string-empty-p (string-trim comment-end)) > IMHO we should do both: use a dedicate function for uncomment region, since Any ts-mode can already override 'uncomment-region-function' to use specifics of its grammar. But I think no general treesit function is possible that would cover all grammars. > that’s usually how we deal with these kind of functions. But it’s probably > good to make tree-sitter’s forward-comment behave exactly like the old one > as much as possible, for a) ergonomics (it’s definitely more convenient to > go directly to the next line rather than EOL when the comment is a line > comment), and b) there might be other functions that rely on that behavior > out in the wilds. Agreed.
bug-gnu-emacs@HIDDEN:bug#80837; Package emacs.
Full text available.Received: (at 80837) by debbugs.gnu.org; 22 Apr 2026 03:38:28 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Tue Apr 21 23:38:28 2026 Received: from localhost ([127.0.0.1]:57221 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1wFOPz-0004dR-UG for submit <at> debbugs.gnu.org; Tue, 21 Apr 2026 23:38:28 -0400 Received: from mail-dy1-x132a.google.com ([2607:f8b0:4864:20::132a]:60512) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from <casouri@HIDDEN>) id 1wFOPx-0004dC-JM for 80837 <at> debbugs.gnu.org; Tue, 21 Apr 2026 23:38:26 -0400 Received: by mail-dy1-x132a.google.com with SMTP id 5a478bee46e88-2b4520f6b32so6446798eec.0 for <80837 <at> debbugs.gnu.org>; Tue, 21 Apr 2026 20:38:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776829104; x=1777433904; 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=r7ormtK1o904bItW5Y2t+aDzlnrumA4Uf85LthOOPL8=; b=kQL+Ts0EfjQDYTTQeHc4WlkUFhyWR+EmCAbqyUxlS2Gfqt1HV/aFrKnBAYsiaKsfXQ m4/mFSh/HT1bcVSlIiu0OccTyqO+yCVeUb+TwXlyBQg565+wgf0Sc6D8aFJtOa1gXLSw tPrP4VbVuNXCbx/cUj3LPZgDiENk+nmMEM8tNHOSb1XpwatM4CwwfqPqCEam7qL+ND1Y blQYMUu07zdhs/9jcNU0SzFYbi2oZzp36jiyn/0zpOWv6800bGPhSHO0q5l4Et3epKdt NnOkO4iAcOmBbWNXEyg+tTd/lVcvho/0QLQka3vKVVHkeLHi//yh67uWEobCruLT/k2v RDKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776829104; x=1777433904; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=r7ormtK1o904bItW5Y2t+aDzlnrumA4Uf85LthOOPL8=; b=KivhvXs/pJkCv0Qoc3gFim1q+bL9kljjomuP1Rnod/OfrNTTrAcy2KaflQjuJxZ1XM nlKD0fO1VVMR8DcI7lp2liv/2U1IZYaq9dnUy59+T4TcB6j/SP5tyFlWCpRFwRhAqT4U E5ihm3e1BlzB9TpsgBlmPhLKoVdC6yVaq82cnWBNorDRjfCtJficC+fXGCcPJEhI8Z7I pRhBM9/5gm75QsI+maRe5mSJFnm0eJnuCVICv41cvkva1BBZ/zYtNfHGcZXlMIQeN9W7 mv1yi0ODO4qz8XC0AYvJom6BsAErX4vj89vn7fDGeaB+z1RFHLGHYbn5gQC95MBr3LMV COCg== X-Gm-Message-State: AOJu0YyySY26EjUWK28ApjtqA2cEd7K4ZrT40UztIM+mC+nJuBIF4qDM qkMuV53rHFCggk4WUcF3JdW4AhdK4QJMMdqqHY07De3s9lbDUxAmSDsL X-Gm-Gg: AeBDievURqVHtkIDHwh0Ja9d6O+SfC6RNLaNLOrQM+DbgJYo7dZvIbrDx+zAviJGtIp bo8c2UFvyp0utU1cf0SOevH1pupLRfM8VFyfkkkViyrA9WcQDgxGZs0bdh78BxG9HnEs0VAmTl9 Da2y8Zsd75KIkUqvBR8D9gSg7ZON2ll7Q81i4Lj7Cpt4BmUocFDcFeVgNEDQuxx6yN0k+rOxmtt 1A5rvMEy+zE4klOzBJbUzfMqJsCxjWDcPz9x+AgGv8QpPeLonyxDf57+YtHH+WUOoWjbjUqBDP8 e2y6xEh1jco6gcjyMwnpUyOuMg1MPZvoDVIlz+3DaaUMv/WZbbSHUw82RkjW7gvHCLhL6iqPoU7 78ZZPG6x+VALtL/EidElU3cheXJpS9VUUCMEO5onrLgdltB9dAzh2lU/u8JkINfuVD0P8GrOe/i MootKkv60tABe6tSuyqhAALbEcRtYpKPIptjhpVi/XZmPKLYqj+dAg5YdJkmj0XI/efrs= X-Received: by 2002:a05:7301:1e97:b0:2d9:77e1:57d4 with SMTP id 5a478bee46e88-2e47930c509mr11117336eec.29.1776829104057; Tue, 21 Apr 2026 20:38:24 -0700 (PDT) Received: from smtpclient.apple ([2601:645:c686:b320:58c4:b11e:e51e:f62b]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2e53ccce0f5sm21449906eec.17.2026.04.21.20.38.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Apr 2026 20:38:23 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: bug#80837: treesit-forward-comment off-by-one issue: overshoots by one character From: Yuan Fu <casouri@HIDDEN> In-Reply-To: <875x5ks4fa.fsf@HIDDEN> Date: Tue, 21 Apr 2026 20:38:12 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: <0777647F-0B38-4473-A76B-BA777629D31A@HIDDEN> References: <ee8e55cc-d3fb-4ef9-9868-b8da4f3362ff@HIDDEN> <87mrz2uchs.fsf@HIDDEN> <A2D955D2-AB1A-45E5-9C8B-A13C82FEA734@HIDDEN> <87zf31ek6k.fsf@HIDDEN> <87a4ux7kjj.fsf@HIDDEN> <875x5ks4fa.fsf@HIDDEN> To: Juri Linkov <juri@HIDDEN> X-Mailer: Apple Mail (2.3826.700.81) X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: 80837 Cc: 80837 <at> debbugs.gnu.org, Bozhidar Batsov <bozhidar@HIDDEN> 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.0 (/) > On Apr 21, 2026, at 8:45=E2=80=AFAM, Juri Linkov <juri@HIDDEN> = wrote: >=20 >>>> I think the TRT to do for treesit-forward-comment is to mimic what >>>> forward-comment does: go to the next line for line comment, and go = to the >>>> end of the comment for block comment. Unfortunately there=E2=80=99s = currently no >>>> proper way to distinguish between the two in the tree-sitter thing >>>> system. Maybe we can add line-comment and block comment thing? Or = use som >>>> heuristic to distinguish between the two. >=20 > The only heuristic that we can use is to rely on non-ts variables > because in modes with line comments the value of 'comment-end' is "": >=20 > diff --git a/lisp/treesit.el b/lisp/treesit.el > index b4f148e8972..c2a8e49130b 100644 > --- a/lisp/treesit.el > +++ b/lisp/treesit.el > @@ -3637,13 +3637,16 @@ treesit-forward-comment > "Tree-sitter `forward-comment-function' implementation. >=20 > COUNT is the same as in `forward-comment'." > - (let ((res t) thing) > + (let ((res t) > + (line-comment (equal comment-end "")) > + thing) > (while (> count 0) > (skip-chars-forward " \t\n") > (setq thing (treesit-thing-at (point) 'comment)) > (if (and thing (eq (point) (treesit-node-start thing))) > (progn > - (goto-char (min (1+ (treesit-node-end thing)) = (point-max))) > + (goto-char (treesit-node-end thing)) > + (when line-comment (skip-chars-forward "\n" (1+ = (point)))) > (setq count (1- count))) > (setq count 0 res nil))) > (while (< count 0) I was thinking more like a heuristic that checks for */ *) etc, since = there=E2=80=99s only that many block comments in the world (right? = right?) But I admit it=E2=80=99s clearly not a 100% solution. Comment end could be a nice solution too, since major modes _ought to_ = define them. But I don=E2=80=99t think comparing it to empty string is = that useful, languages that has both line and block comments will define = that variable. Better to strip the whitespace and do a string match, I = think. IMHO we should do both: use a dedicate function for uncomment region, = since that=E2=80=99s usually how we deal with these kind of functions. = But it=E2=80=99s probably good to make tree-sitter=E2=80=99s = forward-comment behave exactly like the old one as much as possible, for = a) ergonomics (it=E2=80=99s definitely more convenient to go directly to = the next line rather than EOL when the comment is a line comment), and = b) there might be other functions that rely on that behavior out in the = wilds. Yuan=
bug-gnu-emacs@HIDDEN:bug#80837; Package emacs.
Full text available.
Received: (at 80837) by debbugs.gnu.org; 21 Apr 2026 15:49:44 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Apr 21 11:49:43 2026
Received: from localhost ([127.0.0.1]:48734 helo=debbugs.gnu.org)
by debbugs.gnu.org with esmtp (Exim 4.84_2)
(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
id 1wFDM5-0000hp-6p
for submit <at> debbugs.gnu.org; Tue, 21 Apr 2026 11:49:43 -0400
Received: from mout-p-201.mailbox.org ([2001:67c:2050:0:465::201]:34214)
by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
(Exim 4.84_2) (envelope-from <juri@HIDDEN>) id 1wFDM0-0000h3-G3
for 80837 <at> debbugs.gnu.org; Tue, 21 Apr 2026 11:49:38 -0400
Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
(No client certificate requested)
by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4g0RcR4pfXz9tkD;
Tue, 21 Apr 2026 17:49:27 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linkov.net; s=MBO0001;
t=1776786567;
h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
to:to:cc:cc:mime-version:mime-version:content-type:content-type:
in-reply-to:in-reply-to:references:references;
bh=RvgMkWFD0NJRIXBCP5LqGXEoANLOYSSf7Y8vOrHFeIo=;
b=WI/zFls8oTq9jokCTiWQTOwGQwv+so1rwhLkj4BD+2LaTIiS4BExG7s3DilmH5LGMluyrI
yJUKSKNRLXoYYLt0C1Tmnfq8YntlvI21W64bsnFKzYE7QfGYDVBB5ZSn0Bg5dJrYz62vr+
eml3iJDbl05EfuXM+EZmCGNBwepyHKY9GhygrxEpD69nr1cTNWeBprj51Aep5WXncB9L1/
rn6zfJde6QFeiGgd0ra53UB4tOFxdhXIs39W5+Jre4RC7e6DmUXVBHzLSPsMcLGGS7MJHn
C0/dv7T92yD3YNgDNDdqtfNmf9GxjqlMVRNnI7uGfXrPiTzC7nMfNxNniM7pRQ==
From: Juri Linkov <juri@HIDDEN>
To: Yuan Fu <casouri@HIDDEN>
Subject: Re: bug#80837: treesit-forward-comment off-by-one issue: overshoots
by one character
In-Reply-To: <87a4ux7kjj.fsf@HIDDEN>
Organization: LINKOV.NET
References: <ee8e55cc-d3fb-4ef9-9868-b8da4f3362ff@HIDDEN>
<87mrz2uchs.fsf@HIDDEN>
<A2D955D2-AB1A-45E5-9C8B-A13C82FEA734@HIDDEN>
<87zf31ek6k.fsf@HIDDEN> <87a4ux7kjj.fsf@HIDDEN>
Date: Tue, 21 Apr 2026 18:45:29 +0300
Message-ID: <875x5ks4fa.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 80837
Cc: 80837 <at> debbugs.gnu.org, Bozhidar Batsov <bozhidar@HIDDEN>
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 (-)
--=-=-=
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
>>> I think the TRT to do for treesit-forward-comment is to mimic what
>>> forward-comment does: go to the next line for line comment, and go to the
>>> end of the comment for block comment. Unfortunately there’s currently no
>>> proper way to distinguish between the two in the tree-sitter thing
>>> system. Maybe we can add line-comment and block comment thing? Or use som
>>> heuristic to distinguish between the two.
The only heuristic that we can use is to rely on non-ts variables
because in modes with line comments the value of 'comment-end' is "":
--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline;
filename=treesit-forward-comment-line-comment.patch
diff --git a/lisp/treesit.el b/lisp/treesit.el
index b4f148e8972..c2a8e49130b 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -3637,13 +3637,16 @@ treesit-forward-comment
"Tree-sitter `forward-comment-function' implementation.
COUNT is the same as in `forward-comment'."
- (let ((res t) thing)
+ (let ((res t)
+ (line-comment (equal comment-end ""))
+ thing)
(while (> count 0)
(skip-chars-forward " \t\n")
(setq thing (treesit-thing-at (point) 'comment))
(if (and thing (eq (point) (treesit-node-start thing)))
(progn
- (goto-char (min (1+ (treesit-node-end thing)) (point-max)))
+ (goto-char (treesit-node-end thing))
+ (when line-comment (skip-chars-forward "\n" (1+ (point))))
(setq count (1- count)))
(setq count 0 res nil)))
(while (< count 0)
--=-=-=--
bug-gnu-emacs@HIDDEN:bug#80837; Package emacs.
Full text available.Received: (at 80837) by debbugs.gnu.org; 20 Apr 2026 15:19:28 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Mon Apr 20 11:19:27 2026 Received: from localhost ([127.0.0.1]:57983 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1wEqPH-0008DA-7E for submit <at> debbugs.gnu.org; Mon, 20 Apr 2026 11:19:27 -0400 Received: from mout-p-201.mailbox.org ([80.241.56.171]:50816) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <juri@HIDDEN>) id 1wEqPE-0008Cm-OR for 80837 <at> debbugs.gnu.org; Mon, 20 Apr 2026 11:19:25 -0400 Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4fzq035xdJz9stk; Mon, 20 Apr 2026 17:19:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linkov.net; s=MBO0001; t=1776698355; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zfd3vkj0cIQgAlWZuxHWkH9D643GPl31078QSBQ4ko0=; b=FaCvh+SQuE93diQocN3VRCot1Q0DeYyVGInIMav/S2asjiMhdb7KlaMbGf2Mg3adUE4tp5 kq7IFxZkv4ABwgvquvka6kB88QUXD8KBO0w/PqTome1o3p5TLp4snaLZmm4ONHnAgRtxlf CnEf2BEQiXxBjjlam6RzTDg72B1t15aItkiXwceee13TkMUw7lb15dlyj4l4nsGjJ+LQlV cFlKD1zviX/zkci9uvJXN8GMsQnJZ3BTVEFFSCP0uGiQpAKYHbcpw3lCyY5cuwoixdleq4 F+OGvzAWSfUDq978K6IWkQRf9YcRiD3jMN+onyJeQQ6RnqQKqKYQoT2fxIbfPA== From: Juri Linkov <juri@HIDDEN> To: Yuan Fu <casouri@HIDDEN> Subject: Re: bug#80837: treesit-forward-comment off-by-one issue: overshoots by one character In-Reply-To: <87zf31ek6k.fsf@HIDDEN> Organization: LINKOV.NET References: <ee8e55cc-d3fb-4ef9-9868-b8da4f3362ff@HIDDEN> <87mrz2uchs.fsf@HIDDEN> <A2D955D2-AB1A-45E5-9C8B-A13C82FEA734@HIDDEN> <87zf31ek6k.fsf@HIDDEN> Date: Mon, 20 Apr 2026 18:10:04 +0300 Message-ID: <87a4ux7kjj.fsf@HIDDEN> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 80837 Cc: 80837 <at> debbugs.gnu.org, Bozhidar Batsov <bozhidar@HIDDEN> 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 (-) >> I think the TRT to do for treesit-forward-comment is to mimic what >> forward-comment does: go to the next line for line comment, and go to the >> end of the comment for block comment. Unfortunately there’s currently no >> proper way to distinguish between the two in the tree-sitter thing >> system. Maybe we can add line-comment and block comment thing? Or use som >> heuristic to distinguish between the two. > > Unfortunately, there is no distinction between line and block > comments in most grammars, including tree-sitter-ocaml. > And I can't imagine a heuristic since both line and block > comments can end in a newline. > > Does this problem exists only for uncomment-region? > If yes, then we can redefine uncomment-region-function. > The default implementation in uncomment-region-default-1 > is over-complicated. But a new treesit-uncomment-region > would be very simple: it will just delete the text between > the node 'comment' and its children node 'comment_content'. Ah, no way, because 'comment_content' is specific only to Lua grammar. So we can't use 'comment_content' neither for uncomment-region-function, nor for a heuristic to distinguish between line/block comments. And distinction between "line_comment" and "block_comment" exists only in Java and Rust grammars. It would be sad to require every ts-mode to override treesit-forward-comment with own implementation.
bug-gnu-emacs@HIDDEN:bug#80837; Package emacs.
Full text available.Received: (at 80837) by debbugs.gnu.org; 17 Apr 2026 15:38:18 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Fri Apr 17 11:38:18 2026 Received: from localhost ([127.0.0.1]:36957 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1wDlGs-0002h0-3y for submit <at> debbugs.gnu.org; Fri, 17 Apr 2026 11:38:18 -0400 Received: from mout-p-102.mailbox.org ([2001:67c:2050:0:465::102]:35732) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <juri@HIDDEN>) id 1wDlGp-0002gh-P4 for 80837 <at> debbugs.gnu.org; Fri, 17 Apr 2026 11:38:16 -0400 Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4fxzYC1q9Qz9vYd; Fri, 17 Apr 2026 17:38:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linkov.net; s=MBO0001; t=1776440287; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sVsATmisNs73CfYZ+2RVW+iQk8rHisO8NU3xIC/rwSc=; b=Gn0/0k8wS3hnVMMkK/xJ41U8DucQ3uBVtJH6QdAtmpJadr84xYd89O9my75Az/4G2HhQAP AJYH28kgjhr45pUyyCQjaAw8+ADmmvfjKOjSA97xa2CyY7s6kc1Lfysq5i2kO3PslQ+pMX Cq2K0ybdAEhEBpdcQVnPUE5jG3mhzbvrsqs28EaBL8E0VNt7g40B1YJj3GEeyEJ/TvQcMW wiFJslPBMb+VrmqLU09wlBIx1hrkbd0nlE9NkvMW+WATqp1B6ibei42UbUWKtrNfwqD6Zp myeHfT9xpW9Tn6yqHw0oT3vCGIGFAajNqBbnSrcNeKTy8EP6Ny0aeGo+7wprWQ== From: Juri Linkov <juri@HIDDEN> To: Yuan Fu <casouri@HIDDEN> Subject: Re: bug#80837: treesit-forward-comment off-by-one issue: overshoots by one character In-Reply-To: <A2D955D2-AB1A-45E5-9C8B-A13C82FEA734@HIDDEN> Organization: LINKOV.NET References: <ee8e55cc-d3fb-4ef9-9868-b8da4f3362ff@HIDDEN> <87mrz2uchs.fsf@HIDDEN> <A2D955D2-AB1A-45E5-9C8B-A13C82FEA734@HIDDEN> Date: Fri, 17 Apr 2026 18:27:31 +0300 Message-ID: <87zf31ek6k.fsf@HIDDEN> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 80837 Cc: 80837 <at> debbugs.gnu.org, Bozhidar Batsov <bozhidar@HIDDEN> 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 (-) > I think the TRT to do for treesit-forward-comment is to mimic what > forward-comment does: go to the next line for line comment, and go to the > end of the comment for block comment. Unfortunately there’s currently no > proper way to distinguish between the two in the tree-sitter thing > system. Maybe we can add line-comment and block comment thing? Or use som > heuristic to distinguish between the two. Unfortunately, there is no distinction between line and block comments in most grammars, including tree-sitter-ocaml. And I can't imagine a heuristic since both line and block comments can end in a newline. Does this problem exists only for uncomment-region? If yes, then we can redefine uncomment-region-function. The default implementation in uncomment-region-default-1 is over-complicated. But a new treesit-uncomment-region would be very simple: it will just delete the text between the node 'comment' and its children node 'comment_content'.
bug-gnu-emacs@HIDDEN:bug#80837; Package emacs.
Full text available.Received: (at 80837) by debbugs.gnu.org; 17 Apr 2026 06:56:08 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Fri Apr 17 02:56:07 2026 Received: from localhost ([127.0.0.1]:60625 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1wDd7X-0004Wh-CJ for submit <at> debbugs.gnu.org; Fri, 17 Apr 2026 02:56:07 -0400 Received: from mail-dl1-x122f.google.com ([2607:f8b0:4864:20::122f]:50382) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from <casouri@HIDDEN>) id 1wDd7R-0004UD-FV for 80837 <at> debbugs.gnu.org; Fri, 17 Apr 2026 02:56:04 -0400 Received: by mail-dl1-x122f.google.com with SMTP id a92af1059eb24-1279eced0b9so470548c88.0 for <80837 <at> debbugs.gnu.org>; Thu, 16 Apr 2026 23:56:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776408958; x=1777013758; 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=edzAKTbZYNaeJzyFwefaQ1QTnkA1QorWfCtIz0ujQPU=; b=Dm7dLoJkrEouAUoDRJBHYBxFkPYnGWV2U/UMOkq1YspGkMDj9gAJwMH4Df0PCNTowq BSqxZzFjBIaxNlTetWus76Z+tdEzQkbr1Vlw58NkyV7FI26D3TJRJ9XcPhx4CsFKlqlk azV16AyD/U63AIk7ro2XHOttd+xzwQi7poUjyJbfamdt4/lQGOZCTmz35LC3FyvRaTx4 mYKtrC4gf5O0ODqT8Z1zdaCznzMo/sJ6yjUBESzvWpo+ppQeMf1dHM2Pl8KPg7Qe6Wkm PNnTrQQm7uF35u8mPqg04w+MU7j/nOJA01ugUz5EqL1gX4pETwqrDw63aqalE1r63lFf tUVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776408958; x=1777013758; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=edzAKTbZYNaeJzyFwefaQ1QTnkA1QorWfCtIz0ujQPU=; b=akbF8dNqgR45Bm0XcswFzEJPwFEj9dz1t56f/oL+5ZQqmgj5h8zhQ4hL7zJWpdi5eI q+RsL3q2is9rq2e8kfVw+6DE4+rH6QXo4D94mAf1qeLkxvIF8gUdcOtH2WQnqG9qBWuU vpx/vYhbquWbIgjmqWOfgWUntK/5I3Zfs/oVxsMR1eb3gakNwS9EF3xhZi49EgBSRPwd XgrTlLyz1YeQgk4Fc8gZf9CXL1VQ5dI3f0ANbiDrXKyLaJ+xtgHVqyOZq2WlfTPXDHiS NQOgGwxi6iYeYRqZN8aUc6xd8ATe54B/EVUeNxk5r0LKB5TpsXN8Vxt9B6pU1u039ecO sewg== X-Forwarded-Encrypted: i=1; AFNElJ9pp5NBEn2xs4ouzd6Rg15ZYJJhy32We8BQ/Cjewx1PSgs+qQw8E6Vt73hIVMYdPYwhNaXYmA==@debbugs.gnu.org X-Gm-Message-State: AOJu0YxPCffFuQmX2qb1Noqc9FmsW0mZEX358KcpczxVjNt8MkCDhLww zAKmYy7JlNaxN6Saa0WnpSa0vwK0LDODJqi/mqseio/HLqvWG6QyK6ji X-Gm-Gg: AeBDieuYdyip3X4naJ7LOxfsBrcme/e67emSg1d7N4bhNwm09kstJx+FeTK14Ap3f5c CrYZKac+rrRTZgcjB/eDSKoIIR/2a+u3rpx4Ok1ytaw9e/3GFyxVIh0LGjMJfon3OVxvUPKRmUm qhdLrvO83cPB6wOhAtGJFDHsdQ+tfsM7gR5ZjJJDZ8cB94AIaFojVo3Prmtx5QUfXNcsyXaCc09 UVBRzQlMfyUWOSSzNrHnZa4vZzUDAN8UifA1R3UAMBB6IDjCaz3OyGec4kskO8j/vSRajcinN/I sD7gdvgbK26/Jv3F8ucNgRAivYh4koxq12wxgtxJfn5fkIhH5ANXXGX66m1uO33TavAXr0VsxrC xTsDOOngF2OEflGLelPOTOLGNMolDIENk6rSSDkeBaCa4iA1y8vcl4EtyKdnLCruZTvKm68IRoP FNMyJd2wPhs0KWvq4MI9PRjOC4e5BktgFT9pwyqggAoyMM5pP6QdzD/7K2 X-Received: by 2002:a05:7301:168a:b0:2d1:815f:19c1 with SMTP id 5a478bee46e88-2e479c0427dmr615129eec.15.1776408957842; Thu, 16 Apr 2026 23:55:57 -0700 (PDT) Received: from smtpclient.apple ([2601:645:c686:b320:e5b4:ad68:f329:dbbc]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2e53a4a8bd2sm1000955eec.11.2026.04.16.23.55.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Apr 2026 23:55:57 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: bug#80837: treesit-forward-comment off-by-one issue: overshoots by one character From: Yuan Fu <casouri@HIDDEN> In-Reply-To: <87mrz2uchs.fsf@HIDDEN> Date: Thu, 16 Apr 2026 23:55:46 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: <A2D955D2-AB1A-45E5-9C8B-A13C82FEA734@HIDDEN> References: <ee8e55cc-d3fb-4ef9-9868-b8da4f3362ff@HIDDEN> <87mrz2uchs.fsf@HIDDEN> To: Juri Linkov <juri@HIDDEN> X-Mailer: Apple Mail (2.3826.700.81) X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: 80837 Cc: 80837 <at> debbugs.gnu.org, Bozhidar Batsov <bozhidar@HIDDEN> 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.0 (/) > On Apr 16, 2026, at 9:34=E2=80=AFAM, Juri Linkov <juri@HIDDEN> = wrote: >=20 >> The fix is to remove the `1+`: >>=20 >> (goto-char (min (treesit-node-end thing) (point-max))) >>=20 >> Reproducible with any tree-sitter major mode that defines the = `comment` >> thing and uses block comments. Tested on Emacs 31.0.50. >=20 > I called this "off-by-one curse" in > https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D76791#8 >=20 > When we removed `1+`, navigation failed in some modes. > When we added `1+` back, it failed in other modes. >=20 > So I'm 100% sure that removing the `1+` here > will break other modes. >=20 > I see only one mode in Emacs core that uses the `comment` thing: > it's `lua-ts-mode`. And there is an example of Lua block comments > in test/lisp/progmodes/lua-ts-mode-resources/hide-show.lua: >=20 > --[[ > This is a > comment block. > ]] >=20 > I see no difference with or without `1+`, so this is ok. >=20 > However, there is a problem for non-block comments. > Removing the `1+` breaks test/manual/etags/lua-src/allegro.lua: >=20 > -- > -- Read "LEGAL.txt" for more information. >=20 > where `uncomment-region` doesn't uncomment the second line. >=20 > In any case, we need more tests in test/src/treesit-tests.el > to have an overview of ts-modes affected by differences of `1+`. I think the TRT to do for treesit-forward-comment is to mimic what = forward-comment does: go to the next line for line comment, and go to = the end of the comment for block comment. Unfortunately there=E2=80=99s = currently no proper way to distinguish between the two in the = tree-sitter thing system. Maybe we can add line-comment and block = comment thing? Or use som heuristic to distinguish between the two. Yuan=
bug-gnu-emacs@HIDDEN:bug#80837; Package emacs.
Full text available.Received: (at 80837) by debbugs.gnu.org; 16 Apr 2026 16:37:28 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Thu Apr 16 12:37:28 2026 Received: from localhost ([127.0.0.1]:53758 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1wDPiZ-0001tf-U0 for submit <at> debbugs.gnu.org; Thu, 16 Apr 2026 12:37:28 -0400 Received: from mout-p-101.mailbox.org ([80.241.56.151]:57062) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <juri@HIDDEN>) id 1wDPiX-0001st-21 for 80837 <at> debbugs.gnu.org; Thu, 16 Apr 2026 12:37:26 -0400 Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4fxNvs6y2sz9t9t; Thu, 16 Apr 2026 18:37:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linkov.net; s=MBO0001; t=1776357434; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=96YWx3Nl4GB6hhiSK/XtyIwcPHppl2ecHvZ/wPXYocU=; b=RfmXidHq1LU5ZGn3ptJMD1lyuZS5Fqj57i4UxirxqXdsh9IV+3Qe6/WOcvzAZams1okhGt enrUUm+1Qk1JgHN0BVmhu9h9gTEm6ej5NlqVRbwqXl1maqXRDpJVh5DzL+KHbXQ/o9fInO cxtTIQFc3kRimMG7EMujddD+DNh1u1fctaozRNs10ShyKMaNeh4BJiHeUl33xDH5HLAyDk FcszuOnLrU9JoCQRWjDxF1qyb0vMrHjw5dNIIzr1J36ShuvNcYwW9I9/IR6bGEEQgdNuAF /AVeP9FHLrTSGcInjSvJ6bo5fgILsnb2hNqQvDtIL3UhkOG4amZehTwwY9mzEw== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of juri@HIDDEN designates 2001:67c:2050:b231:465::202 as permitted sender) smtp.mailfrom=juri@HIDDEN From: Juri Linkov <juri@HIDDEN> To: "Bozhidar Batsov" <bozhidar@HIDDEN> Subject: Re: bug#80837: treesit-forward-comment off-by-one issue: overshoots by one character In-Reply-To: <ee8e55cc-d3fb-4ef9-9868-b8da4f3362ff@HIDDEN> Organization: LINKOV.NET References: <ee8e55cc-d3fb-4ef9-9868-b8da4f3362ff@HIDDEN> Date: Thu, 16 Apr 2026 19:34:39 +0300 Message-ID: <87mrz2uchs.fsf@HIDDEN> MIME-Version: 1.0 Content-Type: text/plain X-Rspamd-Queue-Id: 4fxNvs6y2sz9t9t X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 80837 Cc: 80837 <at> debbugs.gnu.org, Yuan Fu <casouri@HIDDEN> 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 (-) > The fix is to remove the `1+`: > > (goto-char (min (treesit-node-end thing) (point-max))) > > Reproducible with any tree-sitter major mode that defines the `comment` > thing and uses block comments. Tested on Emacs 31.0.50. I called this "off-by-one curse" in https://debbugs.gnu.org/cgi/bugreport.cgi?bug=76791#8 When we removed `1+`, navigation failed in some modes. When we added `1+` back, it failed in other modes. So I'm 100% sure that removing the `1+` here will break other modes. I see only one mode in Emacs core that uses the `comment` thing: it's `lua-ts-mode`. And there is an example of Lua block comments in test/lisp/progmodes/lua-ts-mode-resources/hide-show.lua: --[[ This is a comment block. ]] I see no difference with or without `1+`, so this is ok. However, there is a problem for non-block comments. Removing the `1+` breaks test/manual/etags/lua-src/allegro.lua: -- -- Read "LEGAL.txt" for more information. where `uncomment-region` doesn't uncomment the second line. In any case, we need more tests in test/src/treesit-tests.el to have an overview of ts-modes affected by differences of `1+`.
bug-gnu-emacs@HIDDEN:bug#80837; Package emacs.
Full text available.Received: (at 80837) by debbugs.gnu.org; 16 Apr 2026 08:09:23 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Thu Apr 16 04:09:22 2026 Received: from localhost ([127.0.0.1]:50597 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1wDHmo-0004eO-EZ for submit <at> debbugs.gnu.org; Thu, 16 Apr 2026 04:09:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40310) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1wDHmi-0004ck-Ci for 80837 <at> debbugs.gnu.org; Thu, 16 Apr 2026 04:09:15 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <eliz@HIDDEN>) id 1wDHmc-00087h-H9; Thu, 16 Apr 2026 04:09:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=Rdr0TCYtMVcJ+co2yQG1oenZ9VTqm9amuTzOQi74Ags=; b=XmBgSp9uZCc7 r9vllZobJsdjzofkBgVHso6jVcYktVmhECr+fFYhNri8TrrcFqI57PntmMMjUsDcBZigd+AwGzDck ptuOC99uJ+pDNXxpyU2XjfNLoJmYajkafQCjBn2f2VcC9J5WHZNLJuIkfZ9EQt51w8XQk9BiEZzA/ zONP5rZdz1VREg6nvx3DmiqiMuaT7dpfBB8tdq1uTqqFCxukjZ8hlf1i3TBY8mQXw3u59bCuLLP9e O7gnN558FVioaIUbxCtEkcnhQEznBw/HPo66Kv1HY4O/lXhRVQfbXxch1V0uWmTv8j11jniZL4wSS sygQ2c9f75ZzltjR2Zuf6A==; Date: Thu, 16 Apr 2026 11:09:00 +0300 Message-Id: <86ldenl42r.fsf@HIDDEN> From: Eli Zaretskii <eliz@HIDDEN> To: "Bozhidar Batsov" <bozhidar@HIDDEN>, Yuan Fu <casouri@HIDDEN> In-Reply-To: <ee8e55cc-d3fb-4ef9-9868-b8da4f3362ff@HIDDEN> (bozhidar@HIDDEN) Subject: Re: bug#80837: treesit-forward-comment off-by-one issue: overshoots by one character References: <ee8e55cc-d3fb-4ef9-9868-b8da4f3362ff@HIDDEN> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 80837 Cc: 80837 <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: -3.3 (---) > Date: Thu, 16 Apr 2026 09:37:01 +0300 > From: "Bozhidar Batsov" <bozhidar@HIDDEN> > > `treesit-forward-comment` (introduced in commit 63df216490 for bug#75609) has an off-by-one error in the > forward branch. The line: > > (goto-char (min (1+ (treesit-node-end thing)) (point-max))) > > adds 1 to `treesit-node-end`, but `treesit-node-end` already returns an exclusive position (one past the last > character of the node). This causes point to overshoot by one character after skipping a comment. > > The practical impact is that `uncomment-region` breaks for languages with block comments (e.g., OCaml's (* ... > *)). When uncommenting a multi-line region where each line is individually commented: > > (* let () = *) > (* let a = 3 in *) > (* Format.eprintf "%d@." a *) > > The leading (* is removed but the trailing *) is left behind: > > let () = *) > let a = 3 in *) > Format.eprintf "%d@." a *) > > This happens because `uncomment-region-default-1` calls `comment-forward`, which calls `forward-comment 1 > `. The overshoot places point on the next line, where `comment-enter-backward` sees `(bolp)` as true and > takes the branch meant for line-comment modes, skipping removal of the closing delimiter. > > The fix is to remove the `1+`: > > (goto-char (min (treesit-node-end thing) (point-max))) > > Reproducible with any tree-sitter major mode that defines the `comment` thing and uses block comments. > Tested on Emacs 31.0.50. > > I came across this when a user of neocaml (a tree-sitter OCaml major mode) reported the problem: > https://github.com/bbatsov/neocaml/issues/25 > > I haven't reported any bugs here in ages, so I hope I got the report right. Thanks, I add Yuan to the discussion.
bug-gnu-emacs@HIDDEN:bug#80837; Package emacs.
Full text available.
Received: (at submit) by debbugs.gnu.org; 16 Apr 2026 06:37:47 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Apr 16 02:37:46 2026
Received: from localhost ([127.0.0.1]:50397 helo=debbugs.gnu.org)
by debbugs.gnu.org with esmtp (Exim 4.84_2)
(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
id 1wDGM9-00068Z-5n
for submit <at> debbugs.gnu.org; Thu, 16 Apr 2026 02:37:45 -0400
Received: from lists1p.gnu.org ([2001:470:142::17]:58800)
by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
(Exim 4.84_2) (envelope-from <bozhidar@HIDDEN>)
id 1wDGM2-00063V-IQ
for submit <at> debbugs.gnu.org; Thu, 16 Apr 2026 02:37:38 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10])
by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
(Exim 4.90_1) (envelope-from <bozhidar@HIDDEN>)
id 1wDGLw-000887-Ty
for bug-gnu-emacs@HIDDEN; Thu, 16 Apr 2026 02:37:28 -0400
Received: from fout-b8-smtp.messagingengine.com ([202.12.124.151])
by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
(Exim 4.90_1) (envelope-from <bozhidar@HIDDEN>)
id 1wDGLu-0000pU-Ee
for bug-gnu-emacs@HIDDEN; Thu, 16 Apr 2026 02:37:28 -0400
Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43])
by mailfout.stl.internal (Postfix) with ESMTP id 1A9671D0012B
for <bug-gnu-emacs@HIDDEN>; Thu, 16 Apr 2026 02:37:22 -0400 (EDT)
Received: from phl-imap-01 ([10.202.2.91])
by phl-compute-03.internal (MEProxy); Thu, 16 Apr 2026 02:37:22 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=batsov.dev; h=cc
:content-type:content-type:date:date:from:from:in-reply-to
:message-id:mime-version:reply-to:subject:subject:to:to; s=fm1;
t=1776321441; x=1776407841; bh=thZnr4DBlcQ24MxsLb2jwkBEK1IgMidk
d42cLmyOuaE=; b=H5Ye//rDKf/XYbCkJ/+2MLxjTjqaNPKwRlRWdqu+giyXytpq
CmQzKcShWp1MIIq80w53+Kz5/b8dx7/AYhBxXKZITOtV0Uc5aSVyA5qbMziikS+n
gnniGyb8o8rI6tE5CHCZ2r0xwrKjJo9qJfdUgvKhxxncUWY4X0xpNZdOXn7ax3Y9
pg0qGGmwOkSI93SrVtPdbxtR/+IvKr5dYQEVj+2yJiz+ib/L30FAaLcse9rFfk6u
R92yHVWsgfBKUT1G2+2D+nqiw8Q2Dc7wrKNQb8+IHP8nP9kZTNcGVsGjtp2ZXI/s
bA8aYj9EYu2AENocBjJvMQFu0infyRrn7OJF2Q==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
messagingengine.com; h=cc:content-type:content-type:date:date
:feedback-id:feedback-id:from:from:in-reply-to:message-id
:mime-version:reply-to:subject:subject:to:to:x-me-proxy
:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1776321441; x=
1776407841; bh=thZnr4DBlcQ24MxsLb2jwkBEK1IgMidkd42cLmyOuaE=; b=G
B6o3MQPvEhAMUX78+u5Lff8F6a45YILrsc4gh2+PFjhQZmW9ZAwl7vyYJPbpA7By
TkjAENB2M8NrWcpWarDwsRQYKXVmJDqZmx1NmPMqaeexHnTB/sW2TuCuGUQt5t3g
Qn9S56jkv/36sD6XJ6oIVC/AMhGqmz9QSw3XYiBmnQ/9tSSTuYP7LpoJkEvjfqHj
ClusEgPIPbEctUnws7opV78Adm/CGgEaeotNDbv0eo056LAanINeGJK8P84mPr1C
Fii6IaYiOD9UIOFiqkM97MTB27+UaUOAw+bSAZCpS0nzNqS4diPyLJYpqm70A32G
zWfCF2Qu7RfoCFHrKoTBQ==
X-ME-Sender: <xms:oYPgaZjcG303KQMZVpF00TRwPXps6yCmQgn52sVZy83nTOJ6BBkwGg>
<xme:oYPgaY1QvFR9VX0_4sGQfw7LDyhr59jO3P1d1R8YUivf3SL5wpPrJZURnd8RB4J2-
b8hpNMYnfleB2MYZDTaoJSv-8dD88_DMQD-cEQjt0q9_ujFGqcsrA>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdegieeftdcutefuodetggdotefrod
ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr
ihhlohhuthemuceftddtnecunecujfgurhepofggfffhvffkufgtsegrtderreertddtne
cuhfhrohhmpedfuehoiihhihgurghruceurghtshhovhdfuceosghoiihhihgurghrsegs
rghtshhovhdruggvvheqnecuggftrfgrthhtvghrnhepueehleffiedugedugeevffduke
ehleejgfefteegjeevudegiedtkeejgeduteegnecuffhomhgrihhnpehgihhthhhusgdr
tghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe
gsohiihhhiuggrrhessggrthhsohhvrdguvghvpdhnsggprhgtphhtthhopedupdhmohgu
vgepshhmthhpohhuthdprhgtphhtthhopegsuhhgqdhgnhhuqdgvmhgrtghssehgnhhurd
horhhg
X-ME-Proxy: <xmx:oYPgabGi76Tvr2Wx_uNs5ZlhDKRg265MgLqav0jbwKtY81msxzhF5A>
<xmx:oYPgafRf_6VeR5v0VtQAykxXfVn0Ifx3y3Rh3RUQNorPZf2p1QkgFA>
<xmx:oYPgaSx-A6fxoXwRFP1F2VWGgJdz_kPv6zpy9Iy9k2UZN1VfWP5Ncg>
<xmx:oYPgaePB3SCRx_a936jT1UzZBGTX6bg4Vhpdw11Krh6fvKK_E9_SQw>
<xmx:oYPgaS_LOot-x1ZFcKkUc-aAUlH1Yom-tzEd5lM1JyrAtBUc9FwYay03>
Feedback-ID: i025946a9:Fastmail
Received: by mailuser.phl.internal (Postfix, from userid 501)
id A139918C0067; Thu, 16 Apr 2026 02:37:21 -0400 (EDT)
X-Mailer: MessagingEngine.com Webmail Interface
MIME-Version: 1.0
X-ThreadId: AmdKaEwoFgMo
Date: Thu, 16 Apr 2026 09:37:01 +0300
From: "Bozhidar Batsov" <bozhidar@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Message-Id: <ee8e55cc-d3fb-4ef9-9868-b8da4f3362ff@HIDDEN>
Subject: treesit-forward-comment off-by-one issue: overshoots by one character
Content-Type: multipart/alternative;
boundary=46f7486897f8e7b83709658aff9220e1adc25a78
Received-SPF: pass client-ip=202.12.124.151; envelope-from=bozhidar@HIDDEN;
helo=fout-b8-smtp.messagingengine.com
X-Spam_score_int: -17
X-Spam_score: -1.8
X-Spam_bar: -
X-Spam_report: (-1.8 / 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, HEXHASH_WORD=1,
HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7,
RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001,
SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 1.7 (+)
X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org",
has NOT identified this incoming email as spam. The original
message has been attached to this so you can view it or label
similar future email. If you have any questions, see
the administrator of that system for details.
Content preview: Hey there! `treesit-forward-comment` (introduced in commit
63df216490 for bug#75609) has an off-by-one error in the forward branch.
The line: (goto-char (min (1+ (treesit-node-end thing)) (point-max)))
Content analysis details: (1.7 points, 10.0 required)
pts rule name description
---- ---------------------- --------------------------------------------------
-0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/,
no trust [2001:470:142:0:0:0:0:17 listed in] [list.dnswl.org]
0.7 SPF_NEUTRAL SPF: sender does not match SPF record (neutral)
-0.0 SPF_HELO_PASS SPF: HELO matches SPF record
0.0 HTML_MESSAGE BODY: HTML included in message
1.0 HEXHASH_WORD Multiple instances of word + hexadecimal hash
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 (/)
--46f7486897f8e7b83709658aff9220e1adc25a78
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Hey there!
`treesit-forward-comment` (introduced in commit 63df216490 for bug#75609) has an off-by-one error in the forward branch. The line:
(goto-char (min (1+ (treesit-node-end thing)) (point-max)))
adds 1 to `treesit-node-end`, but `treesit-node-end` already returns an exclusive position (one past the last character of the node). This causes point to overshoot by one character after skipping a comment.
The practical impact is that `uncomment-region` breaks for languages with block comments (e.g., OCaml's (* ... *)). When uncommenting a multi-line region where each line is individually commented:
(* let () = *)
(* let a = 3 in *)
(* Format.eprintf "%d@." a *)
The leading (* is removed but the trailing *) is left behind:
let () = *)
let a = 3 in *)
Format.eprintf "%d@." a *)
This happens because `uncomment-region-default-1` calls `comment-forward`, which calls `forward-comment 1`. The overshoot places point on the next line, where `comment-enter-backward` sees `(bolp)` as true and takes the branch meant for line-comment modes, skipping removal of the closing delimiter.
The fix is to remove the `1+`:
(goto-char (min (treesit-node-end thing) (point-max)))
Reproducible with any tree-sitter major mode that defines the `comment` thing and uses block comments. Tested on Emacs 31.0.50.
I came across this when a user of neocaml (a tree-sitter OCaml major mode) reported the problem: https://github.com/bbatsov/neocaml/issues/25
I haven't reported any bugs here in ages, so I hope I got the report right.
--46f7486897f8e7b83709658aff9220e1adc25a78
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE html><html><head><title></title></head><body><div>Hey there!</=
div><div><br></div><div>`treesit-forward-comment` (introduced in commit =
63df216490 for bug#75609) has an off-by-one error in the forward branch.=
The line:</div><div><br></div><div> (goto-char (min (1+ (treesit-=
node-end thing)) (point-max)))</div><div><br></div><div>adds 1 to `trees=
it-node-end`, but `treesit-node-end` already returns an exclusive positi=
on (one past the last character of the node). This causes point to overs=
hoot by one character after skipping a comment.</div><div><br></div><div=
>The practical impact is that `uncomment-region` breaks for languages wi=
th block comments (e.g., OCaml's (* ... *)). When uncommenting a multi-l=
ine region where each line is individually commented:</div><div><br></di=
v><div> (* let () =3D *)</div><div> (* let=
a =3D 3 in *)</div><div> (* Format.eprintf "%d@=
." a *)</div><div><br></div><div>The leading (* is removed but the=
trailing *) is left behind:</div><div><br></div><div> let () =3D&=
nbsp; *)</div><div> let a =3D 3 in *)</div><div>=
Format.eprintf "%d@." a *)</div><div><br></div>=
<div>This happens because `uncomment-region-default-1` calls `comment-fo=
rward`, which calls `forward-comment 1`. The overshoot places point on t=
he next line, where `comment-enter-backward` sees `(bolp)` as true and t=
akes the branch meant for line-comment modes, skipping removal of the cl=
osing delimiter.</div><div><br></div><div>The fix is to remove the `1+`:=
</div><div><br></div><div> (goto-char (min (treesit-node-end thing=
) (point-max)))</div><div><br></div><div>Reproducible with any tree-sitt=
er major mode that defines the `comment` thing and uses block comments. =
Tested on Emacs 31.0.50.</div><div><br></div><div>I came across this whe=
n a user of neocaml (a tree-sitter OCaml major mode) reported the proble=
m: <a href=3D"https://github.com/bbatsov/neocaml/issues/25">https://gith=
ub.com/bbatsov/neocaml/issues/25</a></div><div><br></div><div>I haven't =
reported any bugs here in ages, so I hope I got the report right.</div><=
div><br></div></body></html>
--46f7486897f8e7b83709658aff9220e1adc25a78--
"Bozhidar Batsov" <bozhidar@HIDDEN>:bug-gnu-emacs@HIDDEN.
Full text available.bug-gnu-emacs@HIDDEN:bug#80837; Package emacs.
Full text available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997 nCipher Corporation Ltd,
1994-97 Ian Jackson.