bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#50840: 28.0.50; Support GNU style of multiline comments in C source


From: Alan Mackenzie
Subject: bug#50840: 28.0.50; Support GNU style of multiline comments in C source code
Date: Wed, 29 Sep 2021 11:04:13 +0000

Hello, Eli.

On Mon, Sep 27, 2021 at 21:51:45 +0300, Eli Zaretskii wrote:
> > Date: Mon, 27 Sep 2021 18:35:50 +0000
> > Cc: 50840@debbugs.gnu.org, Stefan Monnier <monnier@iro.umontreal.ca>,
> >   acm@muc.de
> > From: Alan Mackenzie <acm@muc.de>

> > > Is this true?  If so, a feature request: add a style to support that.
> > > If such a style already exists, please clarify the documentation so that
> > > users could understand which style does that.

> > > And one more nit: Can the 'comment-end' inserted after the end of a
> > > comment please keep _two_ spaces after the period that ends the last
> > > line of a comment?  Or at least heed the setting of
> > > 'sentence-end-double-space'?

> > Are we talking about C-c C-c (aka M-x comment-region) here?

> Yes, my use case, and the context in which I filed the bug report, was
> "C-c C-c".  Not only for the 2 spaces issue, but also for the comment
> style.

> > This command currently inserts comment-end (in C Mode, " */") at the
> > end of each line being commented, which will leave a single space
> > between what was the last "." on the line and the "*/".

> > We could surely check for an end of sentence character at EOL here, and
> > if we've got one, check that at least two spaces are left.  This again
> > would be something for lisp/newcomment.el.

> Probably.  That''s why Stefan was CC'ed as well.

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.



diff --git a/lisp/newcomment.el b/lisp/newcomment.el
index b458f0356d..8865613383 100644
--- a/lisp/newcomment.el
+++ b/lisp/newcomment.el
@@ -1162,7 +1162,8 @@ comment-region-internal
       (unless (or ce-sanitized (eolp)) (insert "\n") 
(indent-according-to-mode))
       (comment-with-narrowing beg end
        (let ((min-indent (point-max))
-             (max-indent 0))
+             (max-indent 0)
+              ceeee extra-spaces eos-col)
          (goto-char (point-min))
          ;; Quote any nested comment marker
          (comment-quote-nested comment-start comment-end nil)
@@ -1174,6 +1175,25 @@ comment-region-internal
                (unless (looking-at "[ \t]*$")
                  (setq min-indent (min min-indent (current-indentation))))
                (end-of-line)
+                ;; Do we need extra spaces at an end of sentence?
+                (setq ceeee (if (eobp) ce cce))
+                (setq extra-spaces
+                      (and ceeee
+                           (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)
+                                   (if ceeee
+                                       (progn
+                                         (string-match "^[  \t]*" ceeee)
+                                         (match-end 0)) ; # spaces in ce/cce.
+                                     0))
+                                0)))
+                (when (and extra-spaces (> extra-spaces 0))
+                  (move-to-column (+ (current-column) extra-spaces) t))
                (setq max-indent (max max-indent (current-column)))
                (not (or (eobp) (progn (forward-line) nil)))))
 

-- 
Alan Mackenzie (Nuremberg, Germany).





reply via email to

[Prev in Thread] Current Thread [Next in Thread]