From: Alan Mackenzie Date: Fri, 25 Oct 2019 20:11:48 +0000 (+0000) Subject: CC Mode: Fix positioning of point whilst inserting comments without non-ws X-Git-Tag: emacs-27.0.90~893 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=25ed447b7bec3af66cf0322239cfabbaf71bef26;p=emacs.git 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. --- diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el index 0d9414e60fb..9aa2019ae60 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)