aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes
diff options
context:
space:
mode:
authorJim Blandy <[email protected]>1992-12-24 05:59:00 +0000
committerJim Blandy <[email protected]>1992-12-24 05:59:00 +0000
commit8931ecc02814ee43ef9f3f69755acd1441370f93 (patch)
tree68f0b567b0c87684559124629126020ac493e007 /lisp/progmodes
parentc87b230fa2e4216f21d135250d155c61b71bb54b (diff)
* c-mode.el (c-fill-paragraph): Calculating the proper fill-prefix
shouldn't change the buffer text. Make it not. If we're in the blank space before another comment, fill that one as a comment, not as normal text. * c-mode.el (c-fill-paragraph): When guessing the fill prefix, don't ever grab any actual text.
Diffstat (limited to 'lisp/progmodes')
-rw-r--r--lisp/progmodes/c-mode.el66
1 files changed, 52 insertions, 14 deletions
diff --git a/lisp/progmodes/c-mode.el b/lisp/progmodes/c-mode.el
index aa76614874..56db49bc5c 100644
--- a/lisp/progmodes/c-mode.el
+++ b/lisp/progmodes/c-mode.el
@@ -244,7 +244,7 @@ preserving the comment indentation or line-starting decorations."
;; Check for obvious entry to comment.
(save-excursion
(beginning-of-line)
- (skip-chars-forward " \t")
+ (skip-chars-forward " \t\n")
(and (looking-at comment-start-skip)
(setq comment-start-place (point))))))
(if (or first-line
@@ -252,13 +252,14 @@ preserving the comment indentation or line-starting decorations."
(eq (calculate-c-indent) t)
;; t if this line contains a comment starter.
(setq first-line
- (save-excursion (beginning-of-line)
- (prog1
- (re-search-forward comment-start-skip
- (save-excursion (end-of-line)
- (point))
- t)
- (setq comment-start-place (point))))))
+ (save-excursion
+ (beginning-of-line)
+ (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
@@ -270,12 +271,49 @@ preserving the comment indentation or line-starting decorations."
(progn (re-search-forward comment-start-skip)
(make-string (current-column) ?\ ))
(if first-line (forward-line 1))
- (buffer-substring (point)
- (progn
- (move-to-column
- (calculate-c-indent-within-comment t)
- t)
- (point))))))
+
+ (let ((line-width (progn (end-of-line) (current-column))))
+ (beginning-of-line)
+ (prog1
+ (buffer-substring
+ (point)
+
+ ;; How shall we decide where the end of the
+ ;; fill-prefix is?
+ ;; calculate-c-indent-within-comment bases its value
+ ;; on the indentation of previous lines; if they're
+ ;; indented specially, it could return a column
+ ;; that's well into the current line's text. So
+ ;; we'll take at most that many space, tab, or *
+ ;; characters, and use that as our fill prefix.
+ (let ((max-prefix-end
+ (progn
+ (move-to-column
+ (calculate-c-indent-within-comment t)
+ t)
+ (point))))
+ (beginning-of-line)
+ (skip-chars-forward " \t*" max-prefix-end)
+ (point)))
+
+ ;; If the comment is only one line followed by a blank
+ ;; line, calling move-to-column above may have added
+ ;; some spaces and tabs to the end of the line; the
+ ;; fill-paragraph function will then delete it and the
+ ;; newline following it, so we'll lose a blank line
+ ;; when we shouldn't. So delete anything
+ ;; move-to-column added to the end of the line. We
+ ;; record the line width instead of the position of the
+ ;; old line end because move-to-column might break a
+ ;; tab into spaces, and the new characters introduced
+ ;; there shouldn't be deleted.
+
+ ;; If you can see a better way to do this, please make
+ ;; the change. This seems very messy to me.
+ (delete-region (progn (move-to-column line-width)
+ (point))
+ (progn (end-of-line) (point))))))))
+
(paragraph-start
;; Lines containing just a comment start or just an end
;; should not be filled into paragraphs they are next to.