GNU bug report logs -
#78003
31.0.50; comment-indent misbehaves in multiline comments
Previous Next
Reported by: Sean Whitton <spwhitton <at> spwhitton.name>
Date: Wed, 23 Apr 2025 03:19:01 UTC
Severity: normal
Found in version 31.0.50
Fixed in version 31.1
Done: Sean Whitton <spwhitton <at> spwhitton.name>
Bug is archived. No further changes may be made.
Full log
Message #11 received at 78003 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
> 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".
> However, I propose instead to change comment-indent (or possibly
> comment-search-forward).
+1
> - (let* ((eolpos (line-end-position))
> - (begpos (comment-search-forward eolpos t))
> + (let* ((startpos (comment-search-forward (line-end-position) t))
> + (begpos (or startpos
> + ;; If we couldn't find a comment *starting* on
> + ;; this line, see if we are already within a
> + ;; multiline comment at BOL (bug#78003).
> + (and (not continue)
> + comment-use-syntax comment-use-global-state
> + (let ((st (syntax-ppss (line-beginning-position))))
> + (and (nth 4 st) (< (nth 8 st) (point))
> + (point))))))
> + (multilinep (and (not startpos) begpos))
AFAICT we don't need to check (< (nth 8 st) (point)).
Am I missing something?
Also, I think the bug will still bite when
`comment-insert-comment-function` is set.
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?
Stefan
[comment-indent.patch (text/x-diff, inline)]
diff --git a/lisp/newcomment.el b/lisp/newcomment.el
index 23fcbc05372..d04090c0a75 100644
--- a/lisp/newcomment.el
+++ b/lisp/newcomment.el
@@ -713,18 +713,28 @@
If CONTINUE is non-nil, use the `comment-continue' markers if any."
(interactive "*")
(comment-normalize-vars)
- (let ((starter (or (and continue comment-continue)
- comment-start))
- (ender (or (and continue comment-continue "")
- comment-end)))
- (unless starter (error "No comment syntax defined"))
(beginning-of-line)
- (let* ((eolpos (line-end-position))
+ (let* ((starter (or (and continue comment-continue)
+ comment-start
+ (error "No comment syntax defined")))
+ (ender (or (and continue comment-continue "")
+ comment-end))
+ (eolpos (line-end-position))
(begpos (comment-search-forward eolpos t))
cpos indent)
- (if (and comment-insert-comment-function (not begpos))
+ (cond
+ ;; If we couldn't find a comment *starting* on this line, see
+ ;; if we are already within a multiline comment at BOL (bug#78003).
+ ((and (not begpos) (not continue)
+ comment-use-syntax comment-use-global-state
+ (nth 4 (syntax-ppss (line-beginning-position))))
+ ;; We don't know anything about the nature of the multiline
+ ;; construct, so immediately delegate to the mode.
+ (indent-according-to-mode))
+ ((and comment-insert-comment-function (not begpos))
;; If no comment and c-i-c-f is set, let it do everything.
- (funcall comment-insert-comment-function)
+ (funcall comment-insert-comment-function))
+ (t
;; An existing comment?
(if begpos
(progn
This bug report was last modified 27 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.