]> git.eshelyaron.com Git - emacs.git/commitdiff
CC Mode: Fix positioning of point whilst inserting comments without non-ws
authorAlan Mackenzie <acm@muc.de>
Fri, 25 Oct 2019 20:11:48 +0000 (20:11 +0000)
committerAlan Mackenzie <acm@muc.de>
Fri, 25 Oct 2019 20:11:48 +0000 (20:11 +0000)
* 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

index 0d9414e60fbf4f50cde83eef28be40065b964673..9aa2019ae601675e55111b1f7e0760d786e6e56b 100644 (file)
@@ -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)