From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#50840: 28.0.50; Support GNU style of multiline comments in C source code Date: Wed, 29 Sep 2021 17:30:37 +0000 Message-ID: References: <837df2moym.fsf@gnu.org> <83ee99lum6.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30526"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 50840@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Sep 29 19:31:28 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 1mVdQW-0007qI-5s for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 29 Sep 2021 19:31:28 +0200 Original-Received: from localhost ([::1]:47532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVdQV-0002OY-84 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 29 Sep 2021 13:31:27 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48774) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVdQ6-0002Mx-Pr for bug-gnu-emacs@gnu.org; Wed, 29 Sep 2021 13:31:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:38560) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mVdQ6-0005PH-H8 for bug-gnu-emacs@gnu.org; Wed, 29 Sep 2021 13:31:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mVdQ6-0006OW-C1 for bug-gnu-emacs@gnu.org; Wed, 29 Sep 2021 13:31:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 29 Sep 2021 17:31: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.163293664723662 (code B ref 50840); Wed, 29 Sep 2021 17:31:02 +0000 Original-Received: (at 50840) by debbugs.gnu.org; 29 Sep 2021 17:30:47 +0000 Original-Received: from localhost ([127.0.0.1]:50106 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mVdPq-00069J-MR for submit@debbugs.gnu.org; Wed, 29 Sep 2021 13:30:47 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:51416 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1mVdPo-000615-DL for 50840@debbugs.gnu.org; Wed, 29 Sep 2021 13:30:45 -0400 Original-Received: (qmail 47827 invoked by uid 3782); 29 Sep 2021 17:30:37 -0000 Original-Received: from acm.muc.de (p4fe15c83.dip0.t-ipconnect.de [79.225.92.131]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Wed, 29 Sep 2021 19:30:37 +0200 Original-Received: (qmail 20858 invoked by uid 1000); 29 Sep 2021 17:30:37 -0000 Content-Disposition: inline In-Reply-To: X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de 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:215881 Archived-At: Hello, Stefan. On Wed, Sep 29, 2021 at 08:08:43 -0400, Stefan Monnier wrote: > > OK. Here's a provisional patch to lisp/newcomment.el that tries to fix > > the two spaces at the end of a sentence issue. I haven't got anywhere > > with the main bug, yet. > Thanks, Alan. This looks good. > Only one request: could you put the bulk of the new code into a separate function? > I'll see about the "main bug" ASAP, How about the patch below? It's not perfect - the move-to-column might insert a tab at EOL, which will then be the Wrong Thing after the function inserts the comment opener at the left margin. Or something like that. Maybe we should bind indent-tabs-mode to nil around the move-to-column. I'll leave the "main bug" to you, then. diff --git a/lisp/newcomment.el b/lisp/newcomment.el index b458f0356d..5e8691890d 100644 --- a/lisp/newcomment.el +++ b/lisp/newcomment.el @@ -1124,6 +1124,27 @@ comment-add (* comment-add 1) (1- (prefix-numeric-value arg)))) +(defun comment--sentence-spaces (c-end) + "Add spaces at EOL in a comment if needed for an end of sentence. +C-END, a string, is the comment ender for the current line. When +called, point must be at the end of the line, and will be left +at the possibly changed EOL at the end of this function." + (let (extra-spaces eos-col) + (setq extra-spaces + (and (save-excursion + (skip-chars-backward "  \t") + (setq eos-col (current-column)) + (or (bolp) (backward-char)) + (looking-at (sentence-end))) + (max (- (if sentence-end-double-space 2 1) + (- (current-column) eos-col) + (progn + (string-match "^[  \t]*" c-end) + (match-end 0))) ; # spaces in ce/cce. + 0))) + (when (and extra-spaces (> extra-spaces 0)) + (move-to-column (+ (current-column) extra-spaces) t)))) + (defun comment-region-internal (beg end cs ce &optional ccs cce block lines indent) "Comment region BEG .. END. @@ -1174,6 +1195,8 @@ comment-region-internal (unless (looking-at "[ \t]*$") (setq min-indent (min min-indent (current-indentation)))) (end-of-line) + (let ((c-end (if (eobp) ce cce))) + (if c-end (comment--sentence-spaces c-end))) (setq max-indent (max max-indent (current-column))) (not (or (eobp) (progn (forward-line) nil))))) > Stefan -- Alan Mackenzie (Nuremberg, Germany).