all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 50840@debbugs.gnu.org
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	[thread overview]
Message-ID: <YVSivQuhqgPOmZ56@ACM> (raw)
In-Reply-To: <jwvsfxnvb44.fsf-monnier+emacs@gnu.org>

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).





  reply	other threads:[~2021-09-29 17:30 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-27  7:56 bug#50840: 28.0.50; Support GNU style of multiline comments in C source code Eli Zaretskii
2021-09-27 18:35 ` Alan Mackenzie
2021-09-27 18:51   ` Eli Zaretskii
2021-09-29 11:04     ` Alan Mackenzie
2021-09-29 12:08       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-29 17:30         ` Alan Mackenzie [this message]
2021-10-01 19:42 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-01 19:50   ` Eli Zaretskii
2021-10-01 20:57     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-03 17:02     ` Juri Linkov
2022-09-02 10:59       ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YVSivQuhqgPOmZ56@ACM \
    --to=acm@muc.de \
    --cc=50840@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.