emacs-diffs
[Top][All Lists]
Advanced

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

master 25ed447: CC Mode: Fix positioning of point whilst inserting comme


From: Alan Mackenzie
Subject: master 25ed447: CC Mode: Fix positioning of point whilst inserting comments without non-ws
Date: Fri, 25 Oct 2019 16:13:56 -0400 (EDT)

branch: master
commit 25ed447b7bec3af66cf0322239cfabbaf71bef26
Author: Alan Mackenzie <address@hidden>
Commit: Alan Mackenzie <address@hidden>

    CC Mode: Fix positioning of point whilst inserting comments without non-ws
    
    * lisp/progmodes/cc-cmds.el (c-guess-fill-prefix): When determining a new
    block comment prefix (i.e. there isn't one already there to copy), and that
    prefix is hard up against a comment closer, ensure there are at least two
    spaces before the closer.
    (c-indent-new-comment-line): Amend the strategy for ensuring that point 
isn't
    left hard up against the comment closer after M-j.
---
 lisp/progmodes/cc-cmds.el | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el
index 0d9414e..9aa2019 100644
--- a/lisp/progmodes/cc-cmds.el
+++ b/lisp/progmodes/cc-cmds.el
@@ -4083,14 +4083,18 @@ command to conveniently insert and align the necessary 
backslashes."
            ;; `comment-prefix' on a line and indent it to find the
            ;; correct column and the correct mix of tabs and spaces.
            (setq res
-                 (let (tmp-pre tmp-post)
+                 (let (tmp-pre tmp-post at-close)
                    (unwind-protect
                        (progn
 
                          (goto-char (car lit-limits))
                          (if (looking-at comment-start-regexp)
-                             (goto-char (min (match-end 0)
-                                             comment-text-end))
+                             (progn
+                               (goto-char (min (match-end 0)
+                                               comment-text-end))
+                               (setq
+                                at-close
+                                (looking-at c-block-comment-ender-regexp)))
                            (forward-char 2)
                            (skip-chars-forward " \t"))
 
@@ -4106,8 +4110,13 @@ command to conveniently insert and align the necessary 
backslashes."
                                           (save-excursion
                                             (skip-chars-backward " \t")
                                             (point))
-                                          (point)))))
-
+                                          (point))))
+                           ;; If hard up against the comment ender, the
+                           ;; prefix must end in at least two spaces.
+                           (when at-close
+                             (or (string-match "\\s \\s +\\'" comment-prefix)
+                                 (setq comment-prefix
+                                       (concat comment-prefix " ")))))
                          (setq tmp-pre (point-marker))
 
                          ;; We insert an extra non-whitespace character
@@ -4776,7 +4785,6 @@ If a fill prefix is specified, it overrides all the 
above."
                                    (c-collect-line-comments c-lit-limits))
                              c-lit-type)))
                     (pos (point))
-                    (start-col (current-column))
                     (comment-text-end
                      (or (and (eq c-lit-type 'c)
                               (save-excursion
@@ -4821,9 +4829,10 @@ If a fill prefix is specified, it overrides all the 
above."
                          (goto-char (+ (car c-lit-limits) 2))))
                   (funcall do-line-break)
                   (insert-and-inherit (car fill))
-                  (if (> (current-column) start-col)
-                      (move-to-column start-col)))) ; can this hit the
-                                                    ; middle of a TAB?
+                  (if (and (looking-at c-block-comment-ender-regexp)
+                           (memq (char-before) '(?\  ?\t)))
+                      (backward-char)))) ; can this hit the
+                                         ; middle of a TAB?
             ;; Inside a comment that should be broken.
             (let ((comment-start comment-start)
                   (comment-end comment-end)



reply via email to

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