aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes
diff options
context:
space:
mode:
authorAlan Mackenzie2019-10-25 20:11:48 +0000
committerAlan Mackenzie2019-10-25 20:11:48 +0000
commit25ed447b7bec3af66cf0322239cfabbaf71bef26 (patch)
tree090654a61cacd0d7605ebdd5628a6fe6a525a25c /lisp/progmodes
parent4e271a6c36c73cbf3b45ced26493aa6589669815 (diff)
downloademacs-25ed447b7bec3af66cf0322239cfabbaf71bef26.tar.gz
emacs-25ed447b7bec3af66cf0322239cfabbaf71bef26.zip
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.
Diffstat (limited to 'lisp/progmodes')
-rw-r--r--lisp/progmodes/cc-cmds.el27
1 files changed, 18 insertions, 9 deletions
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."
4083 ;; `comment-prefix' on a line and indent it to find the 4083 ;; `comment-prefix' on a line and indent it to find the
4084 ;; correct column and the correct mix of tabs and spaces. 4084 ;; correct column and the correct mix of tabs and spaces.
4085 (setq res 4085 (setq res
4086 (let (tmp-pre tmp-post) 4086 (let (tmp-pre tmp-post at-close)
4087 (unwind-protect 4087 (unwind-protect
4088 (progn 4088 (progn
4089 4089
4090 (goto-char (car lit-limits)) 4090 (goto-char (car lit-limits))
4091 (if (looking-at comment-start-regexp) 4091 (if (looking-at comment-start-regexp)
4092 (goto-char (min (match-end 0) 4092 (progn
4093 comment-text-end)) 4093 (goto-char (min (match-end 0)
4094 comment-text-end))
4095 (setq
4096 at-close
4097 (looking-at c-block-comment-ender-regexp)))
4094 (forward-char 2) 4098 (forward-char 2)
4095 (skip-chars-forward " \t")) 4099 (skip-chars-forward " \t"))
4096 4100
@@ -4106,8 +4110,13 @@ command to conveniently insert and align the necessary backslashes."
4106 (save-excursion 4110 (save-excursion
4107 (skip-chars-backward " \t") 4111 (skip-chars-backward " \t")
4108 (point)) 4112 (point))
4109 (point))))) 4113 (point))))
4110 4114 ;; If hard up against the comment ender, the
4115 ;; prefix must end in at least two spaces.
4116 (when at-close
4117 (or (string-match "\\s \\s +\\'" comment-prefix)
4118 (setq comment-prefix
4119 (concat comment-prefix " ")))))
4111 (setq tmp-pre (point-marker)) 4120 (setq tmp-pre (point-marker))
4112 4121
4113 ;; We insert an extra non-whitespace character 4122 ;; We insert an extra non-whitespace character
@@ -4776,7 +4785,6 @@ If a fill prefix is specified, it overrides all the above."
4776 (c-collect-line-comments c-lit-limits)) 4785 (c-collect-line-comments c-lit-limits))
4777 c-lit-type))) 4786 c-lit-type)))
4778 (pos (point)) 4787 (pos (point))
4779 (start-col (current-column))
4780 (comment-text-end 4788 (comment-text-end
4781 (or (and (eq c-lit-type 'c) 4789 (or (and (eq c-lit-type 'c)
4782 (save-excursion 4790 (save-excursion
@@ -4821,9 +4829,10 @@ If a fill prefix is specified, it overrides all the above."
4821 (goto-char (+ (car c-lit-limits) 2)))) 4829 (goto-char (+ (car c-lit-limits) 2))))
4822 (funcall do-line-break) 4830 (funcall do-line-break)
4823 (insert-and-inherit (car fill)) 4831 (insert-and-inherit (car fill))
4824 (if (> (current-column) start-col) 4832 (if (and (looking-at c-block-comment-ender-regexp)
4825 (move-to-column start-col)))) ; can this hit the 4833 (memq (char-before) '(?\ ?\t)))
4826 ; middle of a TAB? 4834 (backward-char)))) ; can this hit the
4835 ; middle of a TAB?
4827 ;; Inside a comment that should be broken. 4836 ;; Inside a comment that should be broken.
4828 (let ((comment-start comment-start) 4837 (let ((comment-start comment-start)
4829 (comment-end comment-end) 4838 (comment-end comment-end)