bug#80837: treesit-forward-comment off-by-one issue: overshoots by one character

Yuan Fu <[email protected]> Wed, 5 Aug 2026 22:53:03 -0700
Newsgroups gmane.emacs.bugs
Message-ID <[email protected]>

> On Aug 5, 2026, at 7:27 AM, Stefan Monnier <[email protected]> wrote:
> 
>>>> Also, I'm not sure we need the whole `treesit--likely-line-comment-p`:
>>>> can we just test if `comment-end` is nil instead?
>>> 
>>> Testing for an empty `comment-end` should work at least
>>> for c-ts-more and lua-ts-mode where the comment thing is set.
>> 
>> I don’t think testing comment-end by itself makes sense. Comment-end being
>> nil doesn’t tell us anything about a comment.
> 
> It tells us that the default comment marker used for this mode is
> that of a "line comment".  It doesn't tell us that *this comment* uses
> the same kind of comment starter, admittedly, but it's likely to give
> the right answer is many cases.
> 
> We're talking about a quickfix that's not intended to fix the problem
> 100% but only to reduce the occurrence of the problem with a minimum
> impact on the code.

It still feels a bit weird to me, since checking comment-start with comment-end is strictly more accurate and isn’t that much more code. And if you think about it, with just comment-end, if it’s set, we assume all comments are block comments, then you’ll get correct behavior for block comments which is already correct without any changes, and still get the wrong behavior for line comments which this change is intended to fix.

If comment-end is not set, we get correct behavior for line comments, and wrong behavior for block comments.

PS Correct behavior means we move to the BOL of the next line when forward-comment on line comment, and stay at the end of the comment for block comments.

Yuan