Mercurial > emacs
comparison lisp/progmodes/c-mode.el @ 1064:e699ce19609f
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 31 Aug 1992 21:42:28 +0000 |
parents | f6f13367d93c |
children | 4e7d09b779eb |
comparison
equal
deleted
inserted
replaced
1063:25b929c06f83 | 1064:e699ce19609f |
---|---|
238 "Like \\[fill-paragraph] but handle C comments. | 238 "Like \\[fill-paragraph] but handle C comments. |
239 If point is inside a comment, the current paragraph of the comment | 239 If point is inside a comment, the current paragraph of the comment |
240 is filled, preserving the comment indentation or line-starting decorations." | 240 is filled, preserving the comment indentation or line-starting decorations." |
241 (interactive "P") | 241 (interactive "P") |
242 (let ((first-line | 242 (let ((first-line |
243 ;; Check for obvious entry to comment. | |
243 (save-excursion | 244 (save-excursion |
244 (beginning-of-line) | 245 (beginning-of-line) |
245 (skip-chars-forward " \t") | 246 (skip-chars-forward " \t") |
246 (looking-at comment-start-skip)))) | 247 (looking-at comment-start-skip)))) |
247 (if (or first-line | 248 (if (or first-line |
248 (eq (calculate-c-indent) t)) | 249 ;; t if we enter a comment between start of function and this line. |
250 (eq (calculate-c-indent) t) | |
251 ;; See if we enter a comment between beg-of-line and here. | |
252 (nth 4 (parse-partial-sexp (save-excursion (beginning-of-line) (point)) | |
253 (point) 0))) | |
249 ;; Inside a comment: fill one comment paragraph. | 254 ;; Inside a comment: fill one comment paragraph. |
250 (let ((fill-prefix | 255 (let ((fill-prefix |
251 ;; The prefix for each line of this paragraph | 256 ;; The prefix for each line of this paragraph |
252 ;; is the appropriate part of the start of this line, | 257 ;; is the appropriate part of the start of this line, |
253 ;; up to the column at which text should be indented. | 258 ;; up to the column at which text should be indented. |
270 "\\|^[ \t]*/\\*[ \t]*$\\|^[ \t]*\\*/[ \t]*$\\|^[^ \t/*]")) | 275 "\\|^[ \t]*/\\*[ \t]*$\\|^[ \t]*\\*/[ \t]*$\\|^[^ \t/*]")) |
271 (paragraph-separate | 276 (paragraph-separate |
272 (concat paragraph-separate | 277 (concat paragraph-separate |
273 "\\|^[ \t]*/\\*[ \t]*$\\|^[ \t]*\\*/[ \t]*$\\|^[^ \t/*]"))) | 278 "\\|^[ \t]*/\\*[ \t]*$\\|^[ \t]*\\*/[ \t]*$\\|^[^ \t/*]"))) |
274 (save-restriction | 279 (save-restriction |
280 (recursive-edit) | |
275 ;; Don't fill the comment together with the code following it. | 281 ;; Don't fill the comment together with the code following it. |
276 (narrow-to-region (point-min) | 282 (narrow-to-region (save-excursion |
283 (search-backward "/*") | |
284 (beginning-of-line) | |
285 (point)) | |
277 (save-excursion | 286 (save-excursion |
278 (search-forward "*/" nil 'move) | 287 (search-forward "*/" nil 'move) |
279 (forward-line 1) | 288 (forward-line 1) |
280 (point))) | 289 (point))) |
281 (fill-paragraph arg) | 290 (fill-paragraph arg) |
513 ;; or function's arg decls. Set basic-indent accordingly. | 522 ;; or function's arg decls. Set basic-indent accordingly. |
514 (let ((basic-indent | 523 (let ((basic-indent |
515 (save-excursion | 524 (save-excursion |
516 (re-search-backward "^[^ \^L\t\n#]" nil 'move) | 525 (re-search-backward "^[^ \^L\t\n#]" nil 'move) |
517 (let (comment lim) | 526 (let (comment lim) |
518 (if (and (looking-at "\\sw\\|\\s_") | 527 ;; Recognize the DEFUN macro in Emacs. |
519 (looking-at "[^\"\n=]*(") | 528 (if (save-excursion |
520 (progn | 529 ;; Move down to the (putative) argnames line. |
521 (goto-char (1- (match-end 0))) | 530 (while (not (looking-at " *(")) |
522 (setq lim (point)) | 531 (forward-line 1)) |
523 (forward-sexp 1) | 532 ;; Go back to the DEFUN, if it is one. |
524 (skip-chars-forward " \t\f") | 533 (condition-case nil |
525 (and (< (point) indent-point) | 534 (backward-sexp 1) |
526 (not (memq (following-char) | 535 (error)) |
527 '(?\, ?\;))))) | 536 (beginning-of-line) |
528 ;; Make sure the "function decl" we found | 537 (setq tem (point)) |
529 ;; is not inside a comment. | 538 (looking-at "DEFUN\\b")) |
530 (progn | 539 c-argdecl-indent |
531 (beginning-of-line) | 540 (if (and (looking-at "\\sw\\|\\s_") |
532 (while (and (not comment) | 541 (looking-at "[^\"\n=]*(") |
533 (search-forward "/*" lim t)) | 542 (progn |
534 (setq comment | 543 (goto-char (1- (match-end 0))) |
535 (not (search-forward "*/" lim t)))) | 544 (setq lim (point)) |
536 (not comment))) | 545 (condition-case nil |
537 c-argdecl-indent 0))))) | 546 (forward-sexp 1) |
547 (error)) | |
548 (skip-chars-forward " \t\f") | |
549 (and (< (point) indent-point) | |
550 (not (memq (following-char) | |
551 '(?\, ?\;))))) | |
552 ;; Make sure the "function decl" we found | |
553 ;; is not inside a comment. | |
554 (progn | |
555 (beginning-of-line) | |
556 (while (and (not comment) | |
557 (search-forward "/*" lim t)) | |
558 (setq comment | |
559 (not (search-forward "*/" lim t)))) | |
560 (not comment))) | |
561 c-argdecl-indent 0)))))) | |
538 basic-indent))) | 562 basic-indent))) |
539 | 563 |
540 ;; ;; Now add a little if this is a continuation line. | 564 ;; ;; Now add a little if this is a continuation line. |
541 ;; (+ basic-indent (if (or (bobp) | 565 ;; (+ basic-indent (if (or (bobp) |
542 ;; (memq (preceding-char) '(?\) ?\; ?\})) | 566 ;; (memq (preceding-char) '(?\) ?\; ?\})) |