From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs 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 Message-ID: References: <837df2moym.fsf@gnu.org> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30960"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Alan Mackenzie , 50840@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Oct 01 21:43:10 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mWOR4-0007si-8e for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 01 Oct 2021 21:43:10 +0200 Original-Received: from localhost ([::1]:32986 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mWOR3-0002bG-0U for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 01 Oct 2021 15:43:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59990) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mWOQw-0002b8-IF for bug-gnu-emacs@gnu.org; Fri, 01 Oct 2021 15:43:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45847) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mWOQw-0003zC-A3 for bug-gnu-emacs@gnu.org; Fri, 01 Oct 2021 15:43:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mWOQw-0007wu-3f for bug-gnu-emacs@gnu.org; Fri, 01 Oct 2021 15:43:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 01 Oct 2021 19:43:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50840 X-GNU-PR-Package: emacs Original-Received: via spool by 50840-submit@debbugs.gnu.org id=B50840.163311736430532 (code B ref 50840); Fri, 01 Oct 2021 19:43:02 +0000 Original-Received: (at 50840) by debbugs.gnu.org; 1 Oct 2021 19:42:44 +0000 Original-Received: from localhost ([127.0.0.1]:57393 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mWOQd-0007wN-SA for submit@debbugs.gnu.org; Fri, 01 Oct 2021 15:42:44 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:33444) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mWOQb-0007w9-Nw for 50840@debbugs.gnu.org; Fri, 01 Oct 2021 15:42:43 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id DA9338084E; Fri, 1 Oct 2021 15:42:35 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id EE3AB80161; Fri, 1 Oct 2021 15:42:33 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1633117353; bh=16knGHyMCyZ0l0y8K/ywnI8MrKXwpt12jraymefzwnE=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=YSfabKY768H5RnQCR4C3nMb5ocUJQJbMQ36a4seb6oGs612g9mNEFB+obDU0+pJGH nLPq8R46Pijkr/3J/oDnD79jVJYjuzeRIPnGZROqLu1e1cq6RJTzJxPgP0kQaVCYbc c+kNvZ1pIT7/Y4W9fNrPHlPDbDkPPCZK3hkjd0sycn5sdQtBhFzVbTqV5zv+esyUP9 iwutT+VzIa5g3qzIalUBThDPli7QmYMBjGgupeDGlV2oU/zGngoPR7M6dicf2w2Ut8 ltLe0XFHBeng67WLYZ5FF1eV2gLMWgNxgATXoxRCkNqBu8l19W2bLXzjdmYi4CZWg8 ODpPiY42c34+A== Original-Received: from ceviche (modemcable004.216-203-24.mc.videotron.ca [24.203.216.4]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id AB8D81202A1; Fri, 1 Oct 2021 15:42:33 -0400 (EDT) In-Reply-To: <837df2moym.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 27 Sep 2021 10:56:17 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:216080 Archived-At: > 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.