Package: emacs;
Reported by: Eli Zaretskii <eliz <at> gnu.org>
Date: Mon, 27 Sep 2021 07:57:02 UTC
Severity: wishlist
Found in version 28.0.50
Fixed in version 29.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
View this message in rfc822 format
From: Stefan Monnier <monnier <at> iro.umontreal.ca> To: Eli Zaretskii <eliz <at> gnu.org> Cc: Alan Mackenzie <acm <at> muc.de>, 50840 <at> debbugs.gnu.org Subject: bug#50840: 28.0.50; Support GNU style of multiline comments in C source code Date: Fri, 01 Oct 2021 15:42:32 -0400
> It sounds like none of the comment styles in 'comment-styles' can > produce the style of C code comments that we use in Emacs, i.e. > > /* This is the first line of a multi-line comment. > This is the final line of a multi-line comment. */ > > And I don't see anything in the CC Mode manual to augment that, > either. I'm not sure exactly what that would mean in practice. `comment-style` is used to comment out code rather than to write the text of a comment. I think what you're asking for is what you get by setting `comment-multi-line` and then writing your text (e.g. starting with M-; and then typing the text in there, maybe with auto-fill set). If you want comment-region to produce something like the above, then maybe a patch like the following would make sense? The idea is to add a new value nil to `comment-style` which would instruct `comment-region` to refrain from adding `comment-continue` on eachline of a multiline comment. Stefan diff --git a/lisp/newcomment.el b/lisp/newcomment.el index 52e7f09b693..619353d72fd 100644 --- a/lisp/newcomment.el +++ b/lisp/newcomment.el @@ -279,13 +277,13 @@ comment-style See `comment-styles' for a list of available styles." :type (if (boundp 'comment-styles) `(choice + (cons :tag "nil: Minimal" nil) ,@(mapcar (lambda (s) `(const :tag ,(format "%s: %s" (car s) (nth 5 s)) ,(car s))) comment-styles)) 'symbol) - :version "23.1" - :group 'comment) + :version "23.1") ;;;###autoload (defcustom comment-padding (purecopy " ") @@ -345,9 +339,7 @@ comment-string-strip "\\'") str) (match-string 1 str)) -(defun comment-string-reverse (s) - "Return the mirror image of string S, without any trailing space." - (comment-string-strip (concat (nreverse (string-to-list s))) nil t)) +(define-obsolete-function-alias 'comment-string-reverse #'reverse "29.1") ;;;###autoload (defun comment-normalize-vars (&optional noerror) @@ -933,7 +925,10 @@ uncomment-region-default-1 (let* ((numarg (prefix-numeric-value arg)) (ccs comment-continue) (srei (or (comment-padright ccs 're) - (and (stringp comment-continue) comment-continue))) + ;; `comment-padright' returns nil for whitespace-only + ;; strings. + (and (stringp comment-continue) + comment-continue))) (csre (comment-padright comment-start 're)) (sre (and srei (concat "^\\s-*?\\(" srei "\\)"))) spt) @@ -1005,8 +1000,8 @@ uncomment-region-default-1 ;; Eliminate continuation markers as well. (when sre - (let* ((cce (comment-string-reverse (or comment-continue - comment-start))) + (let* ((cce (reverse (or comment-continue + comment-start))) (erei (and box (comment-padleft cce 're))) (ere (and erei (concat "\\(" erei "\\)\\s-*$")))) (goto-char (point-min)) @@ -1149,7 +1144,7 @@ comment-region-internal ;; Should we mark empty lines as well ? (if (or ccs block lines) (setq no-empty nil)) ;; Make sure we have end-markers for BLOCK mode. - (when block (unless ce (setq ce (comment-string-reverse cs)))) + (when block (unless ce (setq ce (reverse cs)))) ;; If BLOCK is not requested, we don't need CCE. (unless block (setq cce nil)) ;; Continuation defaults to the same as CS and CE. @@ -1244,7 +1239,7 @@ comment-region-default-1 (style (cdr (assoc comment-style comment-styles))) (lines (nth 2 style)) (block (nth 1 style)) - (multi (nth 0 style))) + (multi (if style (nth 0 style) t))) (if noadjust (when (bolp) @@ -1297,10 +1292,9 @@ comment-region-default-1 ;; In Lisp and similar modes with one-character comment starters, ;; double it by default if `comment-add' says so. ;; If it isn't indented, triple it. - (if (and (null arg) (not multi-char)) - (setq numarg (* comment-add (if triple 2 1))) - (setq numarg (1- (prefix-numeric-value arg)))) - + (setq numarg (if (and (null arg) (not multi-char)) + (* comment-add (if triple 2 1)) + (1- (prefix-numeric-value arg)))) (comment-region-internal beg end (let ((s (comment-padright comment-start numarg))) @@ -1309,13 +1303,17 @@ 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 - (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)) + (cond + ((not style) (make-string (string-width cs) "")) + (multi + (or (comment-padright comment-continue numarg) + ;; `comment-padright' returns nil when + ;; `comment-continue' contains only whitespace + (and (stringp comment-continue) comment-continue)))) + (cond + ((not style) "") + (multi + (comment-padleft (reverse comment-continue) numarg))) block lines indent)))))) @@ -1360,7 +1358,7 @@ comment-or-uncomment-region (interactive "*r\nP") (comment-normalize-vars) (funcall (if (comment-only-p beg end) - 'uncomment-region 'comment-region) + #'uncomment-region #'comment-region) beg end arg)) ;;;###autoload @@ -1545,8 +1542,9 @@ comment-indent-new-line (comment-start comstart) (comment-end comend) (continuep (or comment-multi-line - (cadr (assoc comment-style - comment-styles)))) + (null comment-style) + (cadr (assq comment-style + comment-styles)))) ;; Recreate comment-continue from comment-start. ;; FIXME: wrong if comment-continue was set explicitly! ;; FIXME: use prev line's continuation if available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.