diff options
| author | Jim Blandy | 1992-12-24 05:59:00 +0000 |
|---|---|---|
| committer | Jim Blandy | 1992-12-24 05:59:00 +0000 |
| commit | 8931ecc02814ee43ef9f3f69755acd1441370f93 (patch) | |
| tree | 68f0b567b0c87684559124629126020ac493e007 | |
| parent | c87b230fa2e4216f21d135250d155c61b71bb54b (diff) | |
| download | emacs-8931ecc02814ee43ef9f3f69755acd1441370f93.tar.gz emacs-8931ecc02814ee43ef9f3f69755acd1441370f93.zip | |
* 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.
| -rw-r--r-- | lisp/progmodes/c-mode.el | 66 |
1 files changed, 52 insertions, 14 deletions
diff --git a/lisp/progmodes/c-mode.el b/lisp/progmodes/c-mode.el index aa766148743..56db49bc5c5 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." | |||
| 244 | ;; Check for obvious entry to comment. | 244 | ;; Check for obvious entry to comment. |
| 245 | (save-excursion | 245 | (save-excursion |
| 246 | (beginning-of-line) | 246 | (beginning-of-line) |
| 247 | (skip-chars-forward " \t") | 247 | (skip-chars-forward " \t\n") |
| 248 | (and (looking-at comment-start-skip) | 248 | (and (looking-at comment-start-skip) |
| 249 | (setq comment-start-place (point)))))) | 249 | (setq comment-start-place (point)))))) |
| 250 | (if (or first-line | 250 | (if (or first-line |
| @@ -252,13 +252,14 @@ preserving the comment indentation or line-starting decorations." | |||
| 252 | (eq (calculate-c-indent) t) | 252 | (eq (calculate-c-indent) t) |
| 253 | ;; t if this line contains a comment starter. | 253 | ;; t if this line contains a comment starter. |
| 254 | (setq first-line | 254 | (setq first-line |
| 255 | (save-excursion (beginning-of-line) | 255 | (save-excursion |
| 256 | (prog1 | 256 | (beginning-of-line) |
| 257 | (re-search-forward comment-start-skip | 257 | (prog1 |
| 258 | (save-excursion (end-of-line) | 258 | (re-search-forward comment-start-skip |
| 259 | (point)) | 259 | (save-excursion (end-of-line) |
| 260 | t) | 260 | (point)) |
| 261 | (setq comment-start-place (point)))))) | 261 | t) |
| 262 | (setq comment-start-place (point)))))) | ||
| 262 | ;; Inside a comment: fill one comment paragraph. | 263 | ;; Inside a comment: fill one comment paragraph. |
| 263 | (let ((fill-prefix | 264 | (let ((fill-prefix |
| 264 | ;; The prefix for each line of this paragraph | 265 | ;; The prefix for each line of this paragraph |
| @@ -270,12 +271,49 @@ preserving the comment indentation or line-starting decorations." | |||
| 270 | (progn (re-search-forward comment-start-skip) | 271 | (progn (re-search-forward comment-start-skip) |
| 271 | (make-string (current-column) ?\ )) | 272 | (make-string (current-column) ?\ )) |
| 272 | (if first-line (forward-line 1)) | 273 | (if first-line (forward-line 1)) |
| 273 | (buffer-substring (point) | 274 | |
| 274 | (progn | 275 | (let ((line-width (progn (end-of-line) (current-column)))) |
| 275 | (move-to-column | 276 | (beginning-of-line) |
| 276 | (calculate-c-indent-within-comment t) | 277 | (prog1 |
| 277 | t) | 278 | (buffer-substring |
| 278 | (point)))))) | 279 | (point) |
| 280 | |||
| 281 | ;; How shall we decide where the end of the | ||
| 282 | ;; fill-prefix is? | ||
| 283 | ;; calculate-c-indent-within-comment bases its value | ||
| 284 | ;; on the indentation of previous lines; if they're | ||
| 285 | ;; indented specially, it could return a column | ||
| 286 | ;; that's well into the current line's text. So | ||
| 287 | ;; we'll take at most that many space, tab, or * | ||
| 288 | ;; characters, and use that as our fill prefix. | ||
| 289 | (let ((max-prefix-end | ||
| 290 | (progn | ||
| 291 | (move-to-column | ||
| 292 | (calculate-c-indent-within-comment t) | ||
| 293 | t) | ||
| 294 | (point)))) | ||
| 295 | (beginning-of-line) | ||
| 296 | (skip-chars-forward " \t*" max-prefix-end) | ||
| 297 | (point))) | ||
| 298 | |||
| 299 | ;; If the comment is only one line followed by a blank | ||
| 300 | ;; line, calling move-to-column above may have added | ||
| 301 | ;; some spaces and tabs to the end of the line; the | ||
| 302 | ;; fill-paragraph function will then delete it and the | ||
| 303 | ;; newline following it, so we'll lose a blank line | ||
| 304 | ;; when we shouldn't. So delete anything | ||
| 305 | ;; move-to-column added to the end of the line. We | ||
| 306 | ;; record the line width instead of the position of the | ||
| 307 | ;; old line end because move-to-column might break a | ||
| 308 | ;; tab into spaces, and the new characters introduced | ||
| 309 | ;; there shouldn't be deleted. | ||
| 310 | |||
| 311 | ;; If you can see a better way to do this, please make | ||
| 312 | ;; the change. This seems very messy to me. | ||
| 313 | (delete-region (progn (move-to-column line-width) | ||
| 314 | (point)) | ||
| 315 | (progn (end-of-line) (point)))))))) | ||
| 316 | |||
| 279 | (paragraph-start | 317 | (paragraph-start |
| 280 | ;; Lines containing just a comment start or just an end | 318 | ;; Lines containing just a comment start or just an end |
| 281 | ;; should not be filled into paragraphs they are next to. | 319 | ;; should not be filled into paragraphs they are next to. |