[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#47167: Multi-line comment-region with empty comment-continue
From: |
Juri Linkov |
Subject: |
bug#47167: Multi-line comment-region with empty comment-continue |
Date: |
Mon, 15 Mar 2021 19:03:22 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu) |
Tags: patch
Tried to customize 'comment-region' to use multi-line comments,
so when commenting out such region in html-mode:
line 1
line 2
line 3
instead of adding comments to each line:
<!-- line 1 -->
<!-- line 2 -->
<!-- line 3 -->
to add comments only at the beginning/end:
<!--
line 1
line 2
line 3
-->
According to the documentation, a legitimate way to do this is
to use such customization:
(setq-local comment-style 'extra-line
comment-continue "")
But currently it has no effect. So needed to fix newcomment.el.
One possible fix is to return the original string from 'comment-padright'
even when the string contains only whitespace. Maybe this would be
the right fix, but still not sure about other calls of 'comment-padright'.
So a safer fix would be to do this in the caller:
diff --git a/lisp/newcomment.el b/lisp/newcomment.el
index ea47eec4fd..a5bfb06795 100644
--- a/lisp/newcomment.el
+++ b/lisp/newcomment.el
@@ -1300,7 +1300,11 @@ comment-region-default-1
(let ((s (comment-padleft comment-end numarg)))
(and s (if (string-match comment-end-skip s) s
(comment-padright comment-end))))
- (if multi (comment-padright comment-continue numarg))
+ (if multi
+ (or (comment-padright comment-continue numarg)
+ ;; `comment-padright' returns nil when
+ ;; `comment-continue' contains only whitespace
+ (and (stringp comment-continue) comment-continue)))
(if multi
(comment-padleft (comment-string-reverse comment-continue) numarg))
block