diff options
| author | Richard M. Stallman | 1998-02-17 07:04:48 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-02-17 07:04:48 +0000 |
| commit | 28c236dee385e1101cfaba57bbf92a25180f7be7 (patch) | |
| tree | b4ddaccae88cc612507fd100ea9caf788420a07d | |
| parent | eae86618133fd47f48b0d41d6f9eac1b54c74933 (diff) | |
| download | emacs-28c236dee385e1101cfaba57bbf92a25180f7be7.tar.gz emacs-28c236dee385e1101cfaba57bbf92a25180f7be7.zip | |
(c-beginning-of-statement)
(c-end-of-statement): Do not move by sentence in strings.
(c-beginning-of-statement): Major rewrite.
(c-beginning-of-defun, c-indent-defun):
Use (c-point 'bod) instead of beginning-of-defun directly.
(c-beginning-of-defun, c-end-of-defun): New commands.
(c-beginning-of-statement): When moving forward by sentences, because
we're either inside or at the start of a comment, be sure to limit
movement to only within the extent of the comment.
(c-electric-colon): Don't insert newlines before or after scope
operators, regardless of the value of c-hanging-colons.
(c-electric-brace): namespace-open and namespace-close braces can hang.
(c-comment-line-break-function): When breaking a
line-oriented comment, copy the comment leader from the previous
line instead of hardcoding it to "// ". This ensures that
whitespace between the slashes and the text is preserved.
(c-electric-pound, c-electric-brace)
(c-electric-slash, c-electric-star, c-electric-semi&comma)
(c-electric-colon, c-electric-lt-gt, c-scope-operator)
(c-electric-backspace, c-electric-delete)
(c-indent-command, c-indent-exp, c-indent-defun)
(c-backslash-region, c-fill-paragraph): Add "*" to interactive spec.
(c-fill-paragraph): regexp-quote the
fill-prefix when search forward for the end of line oriented comments.
(c-backslash-region): Do not preserve the zmacs region (XEmacs).
| -rw-r--r-- | lisp/progmodes/cc-cmds.el | 332 |
1 files changed, 258 insertions, 74 deletions
diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el index 1e5db017389..31adde4f908 100644 --- a/lisp/progmodes/cc-cmds.el +++ b/lisp/progmodes/cc-cmds.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; cc-cmds.el --- user level commands for CC Mode | 1 | ;;; cc-cmds.el --- user level commands for CC Mode |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1985,87,92,93,94,95,96,97 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Authors: 1992-1997 Barry A. Warsaw | 5 | ;; Authors: 1992-1997 Barry A. Warsaw |
| 6 | ;; 1987 Dave Detlefs and Stewart Clamen | 6 | ;; 1987 Dave Detlefs and Stewart Clamen |
| @@ -102,7 +102,7 @@ nil, or point is inside a literal then the function in the variable | |||
| 102 | `c-backspace-function' is called. | 102 | `c-backspace-function' is called. |
| 103 | 103 | ||
| 104 | See also \\[c-electric-delete]." | 104 | See also \\[c-electric-delete]." |
| 105 | (interactive "P") | 105 | (interactive "*P") |
| 106 | (if (or (not c-hungry-delete-key) | 106 | (if (or (not c-hungry-delete-key) |
| 107 | arg | 107 | arg |
| 108 | (c-in-literal)) | 108 | (c-in-literal)) |
| @@ -122,13 +122,14 @@ The behavior of this function depends on the variable | |||
| 122 | exist, as in older Emacsen), then this function behaves identical to | 122 | exist, as in older Emacsen), then this function behaves identical to |
| 123 | \\[c-electric-backspace]. | 123 | \\[c-electric-backspace]. |
| 124 | 124 | ||
| 125 | If `delete-key-deletes-forward' is non-nil, then deletion occurs in | 125 | If `delete-key-deletes-forward' is non-nil and is supported in your |
| 126 | the forward direction. So if `c-hungry-delete-key' is non-nil, as | 126 | Emacs, then deletion occurs in the forward direction. So if |
| 127 | evidenced by the \"/h\" or \"/ah\" string on the mode line, then all | 127 | `c-hungry-delete-key' is non-nil, as evidenced by the \"/h\" or |
| 128 | following whitespace is consumed. If however an ARG is supplied, or | 128 | \"/ah\" string on the mode line, then all following whitespace is |
| 129 | `c-hungry-delete-key' is nil, or point is inside a literal then the | 129 | consumed. If however an ARG is supplied, or `c-hungry-delete-key' is |
| 130 | function in the variable `c-delete-function' is called." | 130 | nil, or point is inside a literal then the function in the variable |
| 131 | (interactive "P") | 131 | `c-delete-function' is called." |
| 132 | (interactive "*P") | ||
| 132 | (if (and (boundp 'delete-key-deletes-forward) | 133 | (if (and (boundp 'delete-key-deletes-forward) |
| 133 | delete-key-deletes-forward) | 134 | delete-key-deletes-forward) |
| 134 | (if (or (not c-hungry-delete-key) | 135 | (if (or (not c-hungry-delete-key) |
| @@ -148,7 +149,7 @@ function in the variable `c-delete-function' is called." | |||
| 148 | Inserts a `#' character specially depending on the variable | 149 | Inserts a `#' character specially depending on the variable |
| 149 | `c-electric-pound-behavior'. If a numeric ARG is supplied, or if | 150 | `c-electric-pound-behavior'. If a numeric ARG is supplied, or if |
| 150 | point is inside a literal, nothing special happens." | 151 | point is inside a literal, nothing special happens." |
| 151 | (interactive "P") | 152 | (interactive "*P") |
| 152 | (if (or (c-in-literal) | 153 | (if (or (c-in-literal) |
| 153 | arg | 154 | arg |
| 154 | (not (memq 'alignleft c-electric-pound-behavior))) | 155 | (not (memq 'alignleft c-electric-pound-behavior))) |
| @@ -174,7 +175,7 @@ after braces based on the value of `c-hanging-braces-alist'. | |||
| 174 | Also, the line is re-indented unless a numeric ARG is supplied, there | 175 | Also, the line is re-indented unless a numeric ARG is supplied, there |
| 175 | are non-whitespace characters present on the line after the brace, or | 176 | are non-whitespace characters present on the line after the brace, or |
| 176 | the brace is inserted inside a literal." | 177 | the brace is inserted inside a literal." |
| 177 | (interactive "P") | 178 | (interactive "*P") |
| 178 | (let* ((c-state-cache (c-parse-state)) | 179 | (let* ((c-state-cache (c-parse-state)) |
| 179 | (safepos (c-safe-position (point) c-state-cache)) | 180 | (safepos (c-safe-position (point) c-state-cache)) |
| 180 | (literal (c-in-literal safepos))) | 181 | (literal (c-in-literal safepos))) |
| @@ -185,11 +186,19 @@ the brace is inserted inside a literal." | |||
| 185 | ; (not c-auto-newline) | 186 | ; (not c-auto-newline) |
| 186 | (not (looking-at "[ \t]*$"))) | 187 | (not (looking-at "[ \t]*$"))) |
| 187 | (self-insert-command (prefix-numeric-value arg)) | 188 | (self-insert-command (prefix-numeric-value arg)) |
| 188 | (let* ((syms '(class-open class-close defun-open defun-close | 189 | (let* ((syms |
| 189 | inline-open inline-close brace-list-open brace-list-close | 190 | ;; This is the list of brace syntactic symbols that can |
| 190 | brace-list-intro brace-list-entry block-open block-close | 191 | ;; hang. If any new ones are added to c-offsets-alist, |
| 191 | substatement-open statement-case-open | 192 | ;; they should be added here as well. |
| 192 | extern-lang-open extern-lang-close)) | 193 | '(class-open class-close defun-open defun-close |
| 194 | inline-open inline-close | ||
| 195 | brace-list-open brace-list-close | ||
| 196 | brace-list-intro brace-list-entry | ||
| 197 | block-open block-close | ||
| 198 | substatement-open statement-case-open | ||
| 199 | extern-lang-open extern-lang-close | ||
| 200 | namespace-open namespace-close | ||
| 201 | )) | ||
| 193 | ;; we want to inhibit blinking the paren since this will | 202 | ;; we want to inhibit blinking the paren since this will |
| 194 | ;; be most disruptive. we'll blink it ourselves later on | 203 | ;; be most disruptive. we'll blink it ourselves later on |
| 195 | (old-blink-paren blink-paren-function) | 204 | (old-blink-paren blink-paren-function) |
| @@ -366,7 +375,7 @@ Indent the line as a comment, if: | |||
| 366 | 375 | ||
| 367 | If numeric ARG is supplied or point is inside a literal, indentation | 376 | If numeric ARG is supplied or point is inside a literal, indentation |
| 368 | is inhibited." | 377 | is inhibited." |
| 369 | (interactive "P") | 378 | (interactive "*P") |
| 370 | (let* ((ch (char-before)) | 379 | (let* ((ch (char-before)) |
| 371 | (indentp (and (not arg) | 380 | (indentp (and (not arg) |
| 372 | (eq last-command-char ?/) | 381 | (eq last-command-char ?/) |
| @@ -387,7 +396,7 @@ If the star is the second character of a C style comment introducing | |||
| 387 | construct, and we are on a comment-only-line, indent line as comment. | 396 | construct, and we are on a comment-only-line, indent line as comment. |
| 388 | If numeric ARG is supplied or point is inside a literal, indentation | 397 | If numeric ARG is supplied or point is inside a literal, indentation |
| 389 | is inhibited." | 398 | is inhibited." |
| 390 | (interactive "P") | 399 | (interactive "*P") |
| 391 | (self-insert-command (prefix-numeric-value arg)) | 400 | (self-insert-command (prefix-numeric-value arg)) |
| 392 | ;; if we are in a literal, or if arg is given do not re-indent the | 401 | ;; if we are in a literal, or if arg is given do not re-indent the |
| 393 | ;; current line, unless this star introduces a comment-only line. | 402 | ;; current line, unless this star introduces a comment-only line. |
| @@ -416,7 +425,7 @@ is determined. | |||
| 416 | When semicolon is inserted, the line is re-indented unless a numeric | 425 | When semicolon is inserted, the line is re-indented unless a numeric |
| 417 | arg is supplied, point is inside a literal, or there are | 426 | arg is supplied, point is inside a literal, or there are |
| 418 | non-whitespace characters on the line following the semicolon." | 427 | non-whitespace characters on the line following the semicolon." |
| 419 | (interactive "P") | 428 | (interactive "*P") |
| 420 | (let* ((lim (c-most-enclosing-brace (c-parse-state))) | 429 | (let* ((lim (c-most-enclosing-brace (c-parse-state))) |
| 421 | (literal (c-in-literal lim)) | 430 | (literal (c-in-literal lim)) |
| 422 | (here (point)) | 431 | (here (point)) |
| @@ -479,10 +488,10 @@ the colon is inserted inside a literal. | |||
| 479 | 488 | ||
| 480 | This function cleans up double colon scope operators based on the | 489 | This function cleans up double colon scope operators based on the |
| 481 | value of `c-cleanup-list'." | 490 | value of `c-cleanup-list'." |
| 482 | (interactive "P") | 491 | (interactive "*P") |
| 483 | (let* ((bod (c-point 'bod)) | 492 | (let* ((bod (c-point 'bod)) |
| 484 | (literal (c-in-literal bod)) | 493 | (literal (c-in-literal bod)) |
| 485 | syntax newlines | 494 | syntax newlines is-scope-op |
| 486 | ;; shut this up | 495 | ;; shut this up |
| 487 | (c-echo-syntactic-information-p nil)) | 496 | (c-echo-syntactic-information-p nil)) |
| 488 | (if (or literal | 497 | (if (or literal |
| @@ -502,7 +511,9 @@ value of `c-cleanup-list'." | |||
| 502 | (eq (char-before) ?:)) | 511 | (eq (char-before) ?:)) |
| 503 | (not (c-in-literal)) | 512 | (not (c-in-literal)) |
| 504 | (not (eq (char-after (- (point) 2)) ?:))) | 513 | (not (eq (char-after (- (point) 2)) ?:))) |
| 505 | (delete-region (point) (1- here))) | 514 | (progn |
| 515 | (delete-region (point) (1- here)) | ||
| 516 | (setq is-scope-op t))) | ||
| 506 | (goto-char (- (point-max) pos))) | 517 | (goto-char (- (point-max) pos))) |
| 507 | ;; lets do some special stuff with the colon character | 518 | ;; lets do some special stuff with the colon character |
| 508 | (setq syntax (c-guess-basic-syntax) | 519 | (setq syntax (c-guess-basic-syntax) |
| @@ -526,6 +537,7 @@ value of `c-cleanup-list'." | |||
| 526 | ;; non-hung colons. However, we don't unhang them because that | 537 | ;; non-hung colons. However, we don't unhang them because that |
| 527 | ;; would be a cleanup (and anti-social). | 538 | ;; would be a cleanup (and anti-social). |
| 528 | (if (and (memq 'before newlines) | 539 | (if (and (memq 'before newlines) |
| 540 | (not is-scope-op) | ||
| 529 | (save-excursion | 541 | (save-excursion |
| 530 | (skip-chars-backward ": \t") | 542 | (skip-chars-backward ": \t") |
| 531 | (not (bolp)))) | 543 | (not (bolp)))) |
| @@ -535,7 +547,8 @@ value of `c-cleanup-list'." | |||
| 535 | (c-indent-line) | 547 | (c-indent-line) |
| 536 | (goto-char (- (point-max) pos)))) | 548 | (goto-char (- (point-max) pos)))) |
| 537 | ;; does a newline go after the colon? | 549 | ;; does a newline go after the colon? |
| 538 | (if (memq 'after (cdr-safe newlines)) | 550 | (if (and (memq 'after (cdr-safe newlines)) |
| 551 | (not is-scope-op)) | ||
| 539 | (progn | 552 | (progn |
| 540 | (newline) | 553 | (newline) |
| 541 | (c-indent-line))) | 554 | (c-indent-line))) |
| @@ -550,7 +563,7 @@ and the buffer is in C++ mode. | |||
| 550 | 563 | ||
| 551 | The line will also not be re-indented if a numeric argument is | 564 | The line will also not be re-indented if a numeric argument is |
| 552 | supplied, or point is inside a literal." | 565 | supplied, or point is inside a literal." |
| 553 | (interactive "P") | 566 | (interactive "*P") |
| 554 | (let ((indentp (and (not arg) | 567 | (let ((indentp (and (not arg) |
| 555 | (eq (char-before) last-command-char) | 568 | (eq (char-before) last-command-char) |
| 556 | (not (c-in-literal)))) | 569 | (not (c-in-literal)))) |
| @@ -590,16 +603,67 @@ forward." | |||
| 590 | (defun c-scope-operator () | 603 | (defun c-scope-operator () |
| 591 | "Insert a double colon scope operator at point. | 604 | "Insert a double colon scope operator at point. |
| 592 | No indentation or other \"electric\" behavior is performed." | 605 | No indentation or other \"electric\" behavior is performed." |
| 593 | (interactive) | 606 | (interactive "*") |
| 594 | (insert "::")) | 607 | (insert "::")) |
| 595 | 608 | ||
| 609 | (defun c-beginning-of-defun (&optional arg) | ||
| 610 | "Move backward to the beginning of a defun. | ||
| 611 | With argument, do it that many times. Negative arg -N | ||
| 612 | means move forward to Nth following beginning of defun. | ||
| 613 | Returns t unless search stops due to beginning or end of buffer. | ||
| 614 | |||
| 615 | Unlike the built-in `beginning-of-defun' this tries to be smarter | ||
| 616 | about finding the char with open-parenthesis syntax that starts the | ||
| 617 | defun." | ||
| 618 | (interactive "p") | ||
| 619 | (if (< arg 0) | ||
| 620 | (c-end-of-defun (- arg)) | ||
| 621 | (while (> arg 0) | ||
| 622 | (let ((state (nreverse (c-parse-state))) | ||
| 623 | prevbod bod) | ||
| 624 | (while (and state (not bod)) | ||
| 625 | (setq bod (car state) | ||
| 626 | state (cdr state)) | ||
| 627 | (if (consp bod) | ||
| 628 | (setq prevbod (car bod) | ||
| 629 | bod nil))) | ||
| 630 | (cond | ||
| 631 | (bod (goto-char bod)) | ||
| 632 | (prevbod (goto-char prevbod)) | ||
| 633 | (t (goto-char (c-point 'bod))))) | ||
| 634 | (setq arg (1- arg)))) | ||
| 635 | (c-keep-region-active)) | ||
| 636 | |||
| 637 | (defun c-end-of-defun (&optional arg) | ||
| 638 | "Move forward to next end of defun. With argument, do it that many times. | ||
| 639 | Negative argument -N means move back to Nth preceding end of defun. | ||
| 640 | |||
| 641 | An end of a defun occurs right after the close-parenthesis that matches | ||
| 642 | the open-parenthesis that starts a defun; see `beginning-of-defun'." | ||
| 643 | (interactive "p") | ||
| 644 | (if (< arg 0) | ||
| 645 | (c-beginning-of-defun (- arg)) | ||
| 646 | (while (> arg 0) | ||
| 647 | ;; skip down into the next defun-block | ||
| 648 | (while (and (c-safe (down-list 1) t) | ||
| 649 | (not (eq (char-before) ?{))) | ||
| 650 | (forward-char -1) | ||
| 651 | (forward-sexp)) | ||
| 652 | (c-beginning-of-defun 1) | ||
| 653 | (forward-sexp 1) | ||
| 654 | (setq arg (1- arg))) | ||
| 655 | (forward-line 1)) | ||
| 656 | (c-keep-region-active)) | ||
| 657 | |||
| 596 | 658 | ||
| 597 | (defun c-beginning-of-statement (&optional count lim sentence-flag) | 659 | (defun c-beginning-of-statement (&optional count lim sentence-flag) |
| 598 | "Go to the beginning of the innermost C statement. | 660 | "Go to the beginning of the innermost C statement. |
| 599 | With prefix arg, go back N - 1 statements. If already at the | 661 | With prefix arg, go back N - 1 statements. If already at the |
| 600 | beginning of a statement then go to the beginning of the preceding | 662 | beginning of a statement then go to the beginning of the closest |
| 601 | one. If within a string or comment, or next to a comment (only | 663 | preceding one, moving into nested blocks if necessary (use |
| 602 | whitespace between), move by sentences instead of statements. | 664 | \\[backward-sexp] to skip over a block). If within a comment, or next |
| 665 | to a comment (only whitespace between), move by sentences instead of | ||
| 666 | statements. | ||
| 603 | 667 | ||
| 604 | When called from a program, this function takes 3 optional args: the | 668 | When called from a program, this function takes 3 optional args: the |
| 605 | repetition count, a buffer position limit which is the farthest back | 669 | repetition count, a buffer position limit which is the farthest back |
| @@ -607,45 +671,167 @@ to search, and a flag saying whether to do sentence motion when in a | |||
| 607 | comment." | 671 | comment." |
| 608 | (interactive (list (prefix-numeric-value current-prefix-arg) | 672 | (interactive (list (prefix-numeric-value current-prefix-arg) |
| 609 | nil t)) | 673 | nil t)) |
| 610 | (let ((here (point)) | 674 | (let* ((count (or count 1)) |
| 611 | (count (or count 1)) | 675 | here |
| 612 | (lim (or lim (c-point 'bod))) | 676 | (range (c-collect-line-comments (c-literal-limits lim)))) |
| 613 | state) | 677 | (while (and (/= count 0) |
| 614 | (save-excursion | 678 | (or (not lim) (> (point) lim))) |
| 615 | (goto-char lim) | 679 | (setq here (point)) |
| 616 | (setq state (parse-partial-sexp (point) here nil nil))) | 680 | (if (and (not range) sentence-flag) |
| 617 | (if (and sentence-flag | 681 | (save-excursion |
| 618 | (or (nth 3 state) | 682 | ;; Find the comment next to point if we're not in one. |
| 619 | (nth 4 state) | 683 | (if (> count 0) |
| 620 | ;; skipping forward into a comment? | 684 | ;; Finding a comment backwards is a bit cumbersome |
| 621 | (and (> 0 count) | 685 | ;; because `forward-comment' regards every newline as |
| 622 | (save-excursion | 686 | ;; a comment when searching backwards (Emacs 19.34). |
| 623 | (skip-chars-forward " \t\n") | 687 | (while (and (progn (skip-chars-backward " \t") |
| 624 | (or (eobp) | 688 | (setq range (point)) |
| 625 | (looking-at comment-start-skip)))) | 689 | (setq range (if (forward-comment -1) |
| 626 | (and (< 0 count) | 690 | (cons (point) range) |
| 627 | (save-excursion | 691 | nil))) |
| 628 | (skip-chars-backward " \t\n") | 692 | (= (char-after) ?\n))) |
| 629 | (goto-char (- (point) 2)) | 693 | (skip-chars-forward " \t\n") |
| 630 | (looking-at "\\*/"))))) | 694 | (setq range (point)) |
| 631 | (forward-sentence (- count)) | 695 | (setq range (if (forward-comment 1) |
| 632 | (while (> count 0) | 696 | (cons range (point)) |
| 633 | (c-beginning-of-statement-1 lim) | 697 | nil))) |
| 634 | (setq count (1- count))) | 698 | (setq range (c-collect-line-comments range)))) |
| 635 | (while (< count 0) | 699 | (if (and (< count 0) (= here (point-max))) |
| 636 | (c-end-of-statement-1) | 700 | ;; Special case because eob might be in a literal. |
| 637 | (setq count (1+ count)))) | 701 | (setq range nil)) |
| 702 | (if range | ||
| 703 | (if (and sentence-flag | ||
| 704 | (/= (char-syntax (char-after (car range))) ?\")) | ||
| 705 | (progn | ||
| 706 | ;; move by sentence, but not past the limit of the literal | ||
| 707 | (save-restriction | ||
| 708 | (narrow-to-region (save-excursion | ||
| 709 | (goto-char (car range)) | ||
| 710 | (looking-at comment-start-skip) | ||
| 711 | (goto-char (match-end 0)) | ||
| 712 | (point)) | ||
| 713 | (save-excursion | ||
| 714 | (goto-char (cdr range)) | ||
| 715 | (if (save-excursion | ||
| 716 | (goto-char (car range)) | ||
| 717 | (looking-at "/\\*")) | ||
| 718 | (backward-char 2)) | ||
| 719 | (skip-chars-backward " \t\n") | ||
| 720 | (point))) | ||
| 721 | (c-safe (forward-sentence (if (> count 0) -1 1)))) | ||
| 722 | ;; See if we should escape the literal. | ||
| 723 | (if (> count 0) | ||
| 724 | (if (< (point) here) | ||
| 725 | (setq count (1- count)) | ||
| 726 | (goto-char (car range)) | ||
| 727 | (setq range nil)) | ||
| 728 | (if (> (point) here) | ||
| 729 | (setq count (1+ count)) | ||
| 730 | (goto-char (cdr range)) | ||
| 731 | (setq range nil)))) | ||
| 732 | (goto-char (if (> count 0) (car range) (cdr range))) | ||
| 733 | (setq range nil)) | ||
| 734 | ;; Below we do approximately the same as | ||
| 735 | ;; c-beginning-of-statement-1 and c-end-of-statement-1 and | ||
| 736 | ;; perhaps they should be changed, but that'd likely break a | ||
| 737 | ;; lot in cc-engine. | ||
| 738 | (goto-char here) | ||
| 739 | ;; Move out of any enclosing non-`{ }' parens. | ||
| 740 | (let ((last (point))) | ||
| 741 | (while (and (c-safe (progn (up-list 1) t)) | ||
| 742 | (/= (char-before) ?\})) | ||
| 743 | (setq last (point))) | ||
| 744 | (goto-char last)) | ||
| 745 | (if (> count 0) | ||
| 746 | (if (condition-case nil | ||
| 747 | ;; Stop before `{' and after `;', `{', `}' and | ||
| 748 | ;; `};' when not followed by `}', but on the other | ||
| 749 | ;; side of the syntactic ws. Also stop before | ||
| 750 | ;; `}', but only to catch comments. Move by sexps | ||
| 751 | ;; and move into `{ }', but not into any other | ||
| 752 | ;; other type of paren. | ||
| 753 | (catch 'done | ||
| 754 | (let (last) | ||
| 755 | (while t | ||
| 756 | (setq last (point)) | ||
| 757 | (if (and (looking-at "[{}]") | ||
| 758 | (/= here last)) | ||
| 759 | (throw 'done (= (char-after) ?{))) | ||
| 760 | (c-backward-syntactic-ws) | ||
| 761 | (cond ((bobp) ; Must handle bob specially. | ||
| 762 | (if (= here last) | ||
| 763 | (if (= last (point-min)) | ||
| 764 | (throw 'done t) | ||
| 765 | (goto-char last) | ||
| 766 | (throw 'done nil)) | ||
| 767 | (goto-char last) | ||
| 768 | (throw 'done t))) | ||
| 769 | ((progn (backward-char) | ||
| 770 | (looking-at "[;{}]")) | ||
| 771 | (if (or (= here last) | ||
| 772 | (= (char-after last) ?})) | ||
| 773 | (if (and (= (char-before) ?}) | ||
| 774 | (= (char-after) ?\;)) | ||
| 775 | (backward-char)) | ||
| 776 | (goto-char last) | ||
| 777 | (throw 'done t))) | ||
| 778 | ((or (= (char-syntax (char-after)) ?\)) | ||
| 779 | (= (char-syntax (char-after)) ?\")) | ||
| 780 | (forward-char) | ||
| 781 | (backward-sexp)) | ||
| 782 | )))) | ||
| 783 | (error | ||
| 784 | (goto-char (point-min)) | ||
| 785 | t)) | ||
| 786 | (setq count (1- count))) | ||
| 787 | (if (condition-case nil | ||
| 788 | ;; Stop before `{' and `}' and after `;', `}' and | ||
| 789 | ;; `};'. Also stop after `{', but only to catch | ||
| 790 | ;; comments. Move by sexps and move into `{ }', but | ||
| 791 | ;; not into any other other type of paren. | ||
| 792 | (catch 'done | ||
| 793 | (let (last) | ||
| 794 | (while t | ||
| 795 | (setq last (point)) | ||
| 796 | (c-forward-syntactic-ws) | ||
| 797 | (cond ((= (char-after) ?{) | ||
| 798 | (if (= here last) | ||
| 799 | (progn (forward-char) | ||
| 800 | (throw 'done nil)) | ||
| 801 | (goto-char last) | ||
| 802 | (throw 'done t))) | ||
| 803 | ((and (= (char-after) ?}) | ||
| 804 | (/= here last)) | ||
| 805 | (goto-char last) | ||
| 806 | (throw 'done t)) | ||
| 807 | ((looking-at ";\\|};?") | ||
| 808 | (goto-char (match-end 0)) | ||
| 809 | (throw 'done t)) | ||
| 810 | ((or (= (char-syntax (char-after)) ?\() | ||
| 811 | (= (char-syntax (char-after)) ?\")) | ||
| 812 | (forward-sexp)) | ||
| 813 | (t | ||
| 814 | (forward-char)) | ||
| 815 | )))) | ||
| 816 | (error | ||
| 817 | (goto-char (point-max)) | ||
| 818 | t)) | ||
| 819 | (setq count (1+ count))))) | ||
| 820 | ;; If we haven't moved we're near a buffer limit. | ||
| 821 | (when (= (point) here) | ||
| 822 | (goto-char (if (> count 0) (point-min) (point-max))) | ||
| 823 | (setq count 0))) | ||
| 638 | ;; its possible we've been left up-buf of lim | 824 | ;; its possible we've been left up-buf of lim |
| 639 | (goto-char (max (point) lim)) | 825 | (if lim (goto-char (max (point) lim)))) |
| 640 | ) | ||
| 641 | (c-keep-region-active)) | 826 | (c-keep-region-active)) |
| 642 | 827 | ||
| 643 | (defun c-end-of-statement (&optional count lim sentence-flag) | 828 | (defun c-end-of-statement (&optional count lim sentence-flag) |
| 644 | "Go to the end of the innermost C statement. | 829 | "Go to the end of the innermost C statement. |
| 645 | 830 | With prefix arg, go forward N - 1 statements. Move forward to the end | |
| 646 | With prefix arg, go forward N - 1 statements. Move forward to end of | 831 | of the next statement if already at end, and move into nested blocks |
| 647 | the next statement if already at end. If within a string or comment, | 832 | \(use \\[forward-sexp] to skip over a block). If within a comment, or |
| 648 | move by sentences instead of statements. | 833 | next to a comment (only whitespace between), move by sentences instead |
| 834 | of statements. | ||
| 649 | 835 | ||
| 650 | When called from a program, this function takes 3 optional args: the | 836 | When called from a program, this function takes 3 optional args: the |
| 651 | repetition count, a buffer position limit which is the farthest back | 837 | repetition count, a buffer position limit which is the farthest back |
| @@ -778,7 +964,7 @@ comment." | |||
| 778 | "\\)[ \t]+")) | 964 | "\\)[ \t]+")) |
| 779 | (string-equal (match-string 1) "//")) | 965 | (string-equal (match-string 1) "//")) |
| 780 | ;; line style | 966 | ;; line style |
| 781 | (setq leader "// ")) | 967 | (setq leader (match-string 0))) |
| 782 | (goto-char here) | 968 | (goto-char here) |
| 783 | (delete-region (progn (skip-chars-backward " \t") (point)) | 969 | (delete-region (progn (skip-chars-backward " \t") (point)) |
| 784 | (progn (skip-chars-forward " \t") (point))) | 970 | (progn (skip-chars-forward " \t") (point))) |
| @@ -909,7 +1095,7 @@ of the expression are preserved. | |||
| 909 | just inserts a tab character, or the equivalent number of spaces, | 1095 | just inserts a tab character, or the equivalent number of spaces, |
| 910 | depending on the variable `indent-tabs-mode'." | 1096 | depending on the variable `indent-tabs-mode'." |
| 911 | 1097 | ||
| 912 | (interactive "P") | 1098 | (interactive "*P") |
| 913 | (let ((bod (c-point 'bod))) | 1099 | (let ((bod (c-point 'bod))) |
| 914 | (if whole-exp | 1100 | (if whole-exp |
| 915 | ;; If arg, always indent this line as C | 1101 | ;; If arg, always indent this line as C |
| @@ -952,7 +1138,7 @@ of the expression are preserved. | |||
| 952 | (defun c-indent-exp (&optional shutup-p) | 1138 | (defun c-indent-exp (&optional shutup-p) |
| 953 | "Indent each line in balanced expression following point. | 1139 | "Indent each line in balanced expression following point. |
| 954 | Optional SHUTUP-P if non-nil, inhibits message printing and error checking." | 1140 | Optional SHUTUP-P if non-nil, inhibits message printing and error checking." |
| 955 | (interactive "P") | 1141 | (interactive "*P") |
| 956 | (let ((here (point)) | 1142 | (let ((here (point)) |
| 957 | end progress-p) | 1143 | end progress-p) |
| 958 | (unwind-protect | 1144 | (unwind-protect |
| @@ -999,13 +1185,11 @@ Optional SHUTUP-P if non-nil, inhibits message printing and error checking." | |||
| 999 | 1185 | ||
| 1000 | (defun c-indent-defun () | 1186 | (defun c-indent-defun () |
| 1001 | "Re-indents the current top-level function def, struct or class declaration." | 1187 | "Re-indents the current top-level function def, struct or class declaration." |
| 1002 | (interactive) | 1188 | (interactive "*") |
| 1003 | (let ((here (point-marker)) | 1189 | (let ((here (point-marker)) |
| 1004 | (c-echo-syntactic-information-p nil) | 1190 | (c-echo-syntactic-information-p nil) |
| 1005 | (brace (c-least-enclosing-brace (c-parse-state)))) | 1191 | (brace (c-least-enclosing-brace (c-parse-state)))) |
| 1006 | (if brace | 1192 | (goto-char (or brace (c-point 'bod))) |
| 1007 | (goto-char brace) | ||
| 1008 | (beginning-of-defun)) | ||
| 1009 | ;; if we're sitting at b-o-b, it might be because there was no | 1193 | ;; if we're sitting at b-o-b, it might be because there was no |
| 1010 | ;; least enclosing brace and we were sitting on the defun's open | 1194 | ;; least enclosing brace and we were sitting on the defun's open |
| 1011 | ;; brace. | 1195 | ;; brace. |
| @@ -1205,7 +1389,7 @@ backslash (if any) at the end of the previous line. | |||
| 1205 | 1389 | ||
| 1206 | You can put the region around an entire macro definition and use this | 1390 | You can put the region around an entire macro definition and use this |
| 1207 | command to conveniently insert and align the necessary backslashes." | 1391 | command to conveniently insert and align the necessary backslashes." |
| 1208 | (interactive "r\nP") | 1392 | (interactive "*r\nP") |
| 1209 | (save-excursion | 1393 | (save-excursion |
| 1210 | (goto-char from) | 1394 | (goto-char from) |
| 1211 | (let ((column c-backslash-column) | 1395 | (let ((column c-backslash-column) |
| @@ -1240,8 +1424,7 @@ command to conveniently insert and align the necessary backslashes." | |||
| 1240 | (c-append-backslash column) | 1424 | (c-append-backslash column) |
| 1241 | (c-delete-backslash)) | 1425 | (c-delete-backslash)) |
| 1242 | (forward-line 1)) | 1426 | (forward-line 1)) |
| 1243 | (move-marker endmark nil))) | 1427 | (move-marker endmark nil)))) |
| 1244 | (c-keep-region-active)) | ||
| 1245 | 1428 | ||
| 1246 | (defun c-append-backslash (column) | 1429 | (defun c-append-backslash (column) |
| 1247 | (end-of-line) | 1430 | (end-of-line) |
| @@ -1269,7 +1452,7 @@ fill the comment or the paragraph of it that point is in, | |||
| 1269 | preserving the comment indentation or line-starting decorations. | 1452 | preserving the comment indentation or line-starting decorations. |
| 1270 | 1453 | ||
| 1271 | Optional prefix ARG means justify paragraph as well." | 1454 | Optional prefix ARG means justify paragraph as well." |
| 1272 | (interactive "P") | 1455 | (interactive "*P") |
| 1273 | (let* (comment-start-place | 1456 | (let* (comment-start-place |
| 1274 | (first-line | 1457 | (first-line |
| 1275 | ;; Check for obvious entry to comment. | 1458 | ;; Check for obvious entry to comment. |
| @@ -1308,7 +1491,8 @@ Optional prefix ARG means justify paragraph as well." | |||
| 1308 | (narrow-to-region (c-point 'bol) | 1491 | (narrow-to-region (c-point 'bol) |
| 1309 | (save-excursion | 1492 | (save-excursion |
| 1310 | (forward-line 1) | 1493 | (forward-line 1) |
| 1311 | (while (looking-at fill-prefix) | 1494 | (while |
| 1495 | (looking-at (regexp-quote fill-prefix)) | ||
| 1312 | (forward-line 1)) | 1496 | (forward-line 1)) |
| 1313 | (point))) | 1497 | (point))) |
| 1314 | (fill-paragraph arg) | 1498 | (fill-paragraph arg) |