Subject: bug#78003: closed (Re: bug#78003: 31.0.50; comment-indent misbehaves in multiline comments)

From: [email-masked] (GNU bug Tracking System)
Date: Fri, 25 Apr 2025 01:16:02 +0000

Your bug report

#78003: 31.0.50; comment-indent misbehaves in multiline comments

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
78003: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=78003
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#78003: 31.0.50; comment-indent misbehaves in multiline comments
From: Sean Whitton <[email-masked]>
To: Stefan Monnier <[email-masked]>
Cc: [email-masked]
Date: Fri, 25 Apr 2025 09:15:23 +0800
List-Id: <debbugs-submit.debbugs.gnu.org>

Version: 31.1

Hello,

On Thu 24 Apr 2025 at 02:58pm -04, Stefan Monnier wrote:

>> We could fix this within comment-dwim.
>
> I don't think we could because `comment-indent` is also a command.
> Maybe we could make `comment-dwim` do something more useful than calling
> `comment-indent` in that case, but that's "another problem".

Right.

> AFAICT we don't need to check (< (nth 8 st) (point)).
> Am I missing something?

I think you are correct that it does not need to be checked because this
call to `<' could only return nil in the case that
comment-search-forward returned non-nil, in which case we would not be
calling syntax-ppss at all.

> Also, I think the bug will still bite when
> `comment-insert-comment-function` is set.

Yes, I was thinking that handling it in that case is going to have to be
the responsibility of whatever function is set.  But it ought to know
what's going on better than comment-indent does.

> BTW, the patch looks simple in terms of the diff, but it makes the
> control flow (which is already not great) even more complicated.
>
> How 'bout the one below?

Thanks for reviewing, and for reworking it.  Installed the change.

There are other bugs nearby that I hope to fix soon but nothing
actionable remaining here, so closing the bug.

-- 
Sean Whitton

Subject: 31.0.50; comment-indent misbehaves in multiline comments
From: Sean Whitton <[email-masked]>
To: [email-masked]
Date: Wed, 23 Apr 2025 11:17:59 +0800
List-Id: <debbugs-submit.debbugs.gnu.org>

X-debbugs-cc: [email-masked]

1. emacs -q
2. C-x b foo RET
3. M-x lisp-mode RET
4. Enter this content:
--8<---------------cut here---------------start------------->8---
#|
foo
#|
--8<---------------cut here---------------end--------------->8---
5. Put point after "foo".
6. M-;

The result is an insertion of trailing single-semicolon comment.
As we are already within a comment, this makes no sense.  M-; should
either do nothing, or possibly perform some form of indentation.

We could fix this within comment-dwim.  However, I propose instead to
change comment-indent (or possibly comment-search-forward).
This is because I first encountered this problem not via comment-dwim,
but via how indent-sexp calls comment-indent.

The above recipe with M-; is just the simplest reproducer I found.
Making comment-indent behave better within multiline comments would make
it a more useful function in general and also fix these various
misbehaviours at once.

Other background:

- Possibly indent-sexp needs some adjustment too, but any change to
  comment-indent should come first.

- A similar problem shows up with syntax-propertize-function values
  which set comment-fence syntax-table text properties, which are
  another kind of multiline comment.
  (Came up for me in consfigurator.el's syntax-propertize-function.)

- A similar problem shows up with the literate-scratch library
  Stefan M. and I were discussing over the past few days, where the
  problem is that the library adds a whitespace syntax-table property to
  some trailing newlines such that it is only the second of the two
  newlines following a paragraph which ends the comment.  With point
  between the two newlines, we're still in a comment, but comment-indent
  doesn't think so.

-- 
Sean Whitton