Mercurial > emacs
comparison lisp/progmodes/c-mode.el @ 1701:e0463f021e2f
* 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.
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Thu, 24 Dec 1992 05:59:00 +0000 |
parents | ee7f627ef26e |
children | fe2bebf150c7 |
comparison
equal
deleted
inserted
replaced
1700:4be274918c90 | 1701:e0463f021e2f |
---|---|
242 (let* (comment-start-place | 242 (let* (comment-start-place |
243 (first-line | 243 (first-line |
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 |
251 ;; t if we enter a comment between start of function and this line. | 251 ;; t if we enter a comment between start of function and this line. |
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 |
265 ;; is the appropriate part of the start of this line, | 266 ;; is the appropriate part of the start of this line, |
266 ;; up to the column at which text should be indented. | 267 ;; up to the column at which text should be indented. |
268 (beginning-of-line) | 269 (beginning-of-line) |
269 (if (looking-at "[ \t]*/\\*.*\\*/") | 270 (if (looking-at "[ \t]*/\\*.*\\*/") |
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. |
282 (concat paragraph-start | 320 (concat paragraph-start |
283 "\\|^[ \t]*/\\*[ \t]*$\\|^[ \t]*\\*/[ \t]*$\\|^[^ \t/*]")) | 321 "\\|^[ \t]*/\\*[ \t]*$\\|^[ \t]*\\*/[ \t]*$\\|^[^ \t/*]")) |