aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes
diff options
context:
space:
mode:
authorRichard M. Stallman <[email protected]>1992-09-05 23:19:22 +0000
committerRichard M. Stallman <[email protected]>1992-09-05 23:19:22 +0000
commit6cf420725b8c77321b37c858f7b698bd76224851 (patch)
tree701e83b8670b044393399e490a68898d55592503 /lisp/progmodes
parente5d4f4dc541c0177c62baf13cd75e9c7c83da502 (diff)
*** empty log message ***
Diffstat (limited to 'lisp/progmodes')
-rw-r--r--lisp/progmodes/c-mode.el44
1 files changed, 29 insertions, 15 deletions
diff --git a/lisp/progmodes/c-mode.el b/lisp/progmodes/c-mode.el
index 590efd5fd1..d91e5586ba 100644
--- a/lisp/progmodes/c-mode.el
+++ b/lisp/progmodes/c-mode.el
@@ -239,21 +239,25 @@ If any of the current line is a comment or within a comment,
fill the comment or the paragraph of it that point is in,
preserving the comment indentation or line-starting decorations."
(interactive "P")
- (let ((first-line
- ;; Check for obvious entry to comment.
- (save-excursion
- (beginning-of-line)
- (skip-chars-forward " \t")
- (looking-at comment-start-skip))))
+ (let* (comment-start-place
+ (first-line
+ ;; Check for obvious entry to comment.
+ (save-excursion
+ (beginning-of-line)
+ (skip-chars-forward " \t")
+ (and (looking-at comment-start-skip)
+ (setq comment-start-place (point))))))
(if (or first-line
;; t if we enter a comment between start of function and this line.
(eq (calculate-c-indent) t)
;; t if this line contains a comment starter.
(save-excursion (beginning-of-line)
- (re-search-forward comment-start-skip
- (save-excursion (end-of-line)
- (point))
- t)))
+ (prog1
+ (re-search-forward comment-start-skip
+ (save-excursion (end-of-line)
+ (point))
+ t)
+ (setq comment-start-place (point)))))
;; Inside a comment: fill one comment paragraph.
(let ((fill-prefix
;; The prefix for each line of this paragraph
@@ -280,18 +284,28 @@ preserving the comment indentation or line-starting decorations."
(concat paragraph-separate
"\\|^[ \t]*/\\*[ \t]*$\\|^[ \t]*\\*/[ \t]*$\\|^[^ \t/*]")))
(save-restriction
- (recursive-edit)
;; Don't fill the comment together with the code following it.
- (narrow-to-region (save-excursion
- (search-backward "/*")
- (beginning-of-line)
- (point))
+ ;; So temporarily exclude everything before the comment start,
+ ;; and everything after the line where the comment ends.
+ ;; If comment-start-place is non-nil, the comment starter is there.
+ ;; Otherwise, point is inside the comment.
+ (narrow-to-region (or comment-start-place
+ (save-excursion
+ (search-backward "/*")
+ (beginning-of-line)
+ (point)))
(save-excursion
+ (if comment-start-place
+ (goto-char (+ comment-start-place 2)))
(search-forward "*/" nil 'move)
(forward-line 1)
(point)))
(fill-paragraph arg)
(save-excursion
+ ;; Find the comment ender (should be on last line of buffer,
+ ;; given the narrowing) and don't leave it on its own line.
+ (goto-char (point-max))
+ (forward-line -1)
(search-forward "*/")
(beginning-of-line)
(if (looking-at "[ \t]*\\*/")