diff options
| author | Richard M. Stallman | 1995-01-12 22:45:24 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1995-01-12 22:45:24 +0000 |
| commit | 1103950c980791dbb0173747fe6792a4edebbb62 (patch) | |
| tree | 7003edfbb468b28c99bef736415a417c28c8198b | |
| parent | eb650569ae9eb775958120be180c0e00f38d46d8 (diff) | |
| download | emacs-1103950c980791dbb0173747fe6792a4edebbb62.tar.gz emacs-1103950c980791dbb0173747fe6792a4edebbb62.zip | |
(indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
| -rw-r--r-- | lisp/progmodes/cplus-md.el | 68 |
1 files changed, 37 insertions, 31 deletions
diff --git a/lisp/progmodes/cplus-md.el b/lisp/progmodes/cplus-md.el index 8d1e8267042..fd7f224969e 100644 --- a/lisp/progmodes/cplus-md.el +++ b/lisp/progmodes/cplus-md.el | |||
| @@ -659,39 +659,45 @@ Returns nil if line starts inside a string, t if in a comment." | |||
| 659 | (>= (car indent-stack) 0)) | 659 | (>= (car indent-stack) 0)) |
| 660 | ;; Line is on an existing nesting level. | 660 | ;; Line is on an existing nesting level. |
| 661 | ;; Lines inside parens are handled specially. | 661 | ;; Lines inside parens are handled specially. |
| 662 | (if (/= (char-after (car contain-stack)) ?\{) | 662 | nil |
| 663 | (setq this-indent (car indent-stack)) | ||
| 664 | ;; Line is at statement level. | ||
| 665 | ;; Is it a new statement? Is it an else? | ||
| 666 | ;; Find last non-comment character before this line | ||
| 667 | (save-excursion | ||
| 668 | (setq at-else (looking-at "else\\W")) | ||
| 669 | (setq at-brace (= (following-char) ?\{)) | ||
| 670 | (c++-backward-to-noncomment opoint) | ||
| 671 | (if (not (memq (preceding-char) '(nil ?\, ?\; ?\} ?: ?\{))) | ||
| 672 | ;; Preceding line did not end in comma or semi; | ||
| 673 | ;; indent this line c-continued-statement-offset | ||
| 674 | ;; more than previous. | ||
| 675 | (progn | ||
| 676 | (c-backward-to-start-of-continued-exp | ||
| 677 | (car contain-stack)) | ||
| 678 | (setq this-indent | ||
| 679 | (+ c-continued-statement-offset | ||
| 680 | (current-column) | ||
| 681 | (if at-brace c-continued-brace-offset 0)))) | ||
| 682 | ;; Preceding line ended in comma or semi; | ||
| 683 | ;; use the standard indent for this level. | ||
| 684 | (if at-else | ||
| 685 | (progn (c-backward-to-start-of-if opoint) | ||
| 686 | (setq this-indent (current-indentation))) | ||
| 687 | (setq this-indent (car indent-stack)))))) | ||
| 688 | ;; Just started a new nesting level. | 663 | ;; Just started a new nesting level. |
| 689 | ;; Compute the standard indent for this level. | 664 | ;; Compute the standard indent for this level. |
| 690 | (let ((val (calculate-c++-indent | 665 | (let (val) |
| 691 | (if (car indent-stack) | 666 | (if (= (char-after (car contain-stack)) ?{) |
| 692 | (- (car indent-stack)))))) | 667 | (save-excursion |
| 693 | (setcar indent-stack | 668 | (goto-char (car contain-stack)) |
| 694 | (setq this-indent val)))) | 669 | (setq val (+ c-indent-level (current-column)))) |
| 670 | (setq val (calculate-c++-indent | ||
| 671 | (if (car indent-stack) | ||
| 672 | (- (car indent-stack)))))) | ||
| 673 | (setcar indent-stack val))) | ||
| 674 | ;; Adjust line indentation according to its predecessor. | ||
| 675 | (if (/= (char-after (car contain-stack)) ?\{) | ||
| 676 | (setq this-indent (car indent-stack)) | ||
| 677 | ;; Line is at statement level. | ||
| 678 | ;; Is it a new statement? Is it an else? | ||
| 679 | ;; Find last non-comment character before this line | ||
| 680 | (save-excursion | ||
| 681 | (setq at-else (looking-at "else\\W")) | ||
| 682 | (setq at-brace (= (following-char) ?\{)) | ||
| 683 | (c++-backward-to-noncomment opoint) | ||
| 684 | (if (not (memq (preceding-char) '(nil ?\, ?\; ?\} ?: ?\{))) | ||
| 685 | ;; Preceding line did not end in comma or semi; | ||
| 686 | ;; indent this line c-continued-statement-offset | ||
| 687 | ;; more than previous. | ||
| 688 | (progn | ||
| 689 | (c-backward-to-start-of-continued-exp | ||
| 690 | (car contain-stack)) | ||
| 691 | (setq this-indent | ||
| 692 | (+ c-continued-statement-offset | ||
| 693 | (current-column) | ||
| 694 | (if at-brace c-continued-brace-offset 0)))) | ||
| 695 | ;; Preceding line ended in comma or semi; | ||
| 696 | ;; use the standard indent for this level. | ||
| 697 | (if at-else | ||
| 698 | (progn (c-backward-to-start-of-if opoint) | ||
| 699 | (setq this-indent (current-indentation))) | ||
| 700 | (setq this-indent (car indent-stack)))))) | ||
| 695 | ;; Adjust line indentation according to its contents | 701 | ;; Adjust line indentation according to its contents |
| 696 | (if (looking-at "\\(public\\|private\\|protected\\):") | 702 | (if (looking-at "\\(public\\|private\\|protected\\):") |
| 697 | (setq this-indent (- this-indent c-indent-level)) | 703 | (setq this-indent (- this-indent c-indent-level)) |