diff options
| author | Alan Mackenzie | 2013-04-30 16:19:14 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2013-04-30 16:19:14 +0000 |
| commit | 3d1c39faa4744f87838ecd07fdf01787d5235186 (patch) | |
| tree | 1495bb55a5fd47b4a80e57b7e356d1b9220396cb /lisp | |
| parent | 5147fc177367a3d41a98bc651b02af3660aeafbd (diff) | |
| download | emacs-3d1c39faa4744f87838ecd07fdf01787d5235186.tar.gz emacs-3d1c39faa4744f87838ecd07fdf01787d5235186.zip | |
Handle arbitrarily long C++ member initialisation lists.
* progmodes/cc-engine.el (c-back-over-member-initializers): new
function.
(c-guess-basic-syntax): New CASE 5R (extracted from 5B) to handle
(most) member init lists.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 8 | ||||
| -rw-r--r-- | lisp/progmodes/cc-engine.el | 78 |
2 files changed, 76 insertions, 10 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 00cfe320701..0513d69d0fc 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2013-04-30 Alan Mackenzie <acm@muc.de> | ||
| 2 | |||
| 3 | Handle arbitrarily long C++ member initialisation lists. | ||
| 4 | * progmodes/cc-engine.el (c-back-over-member-initializers): new | ||
| 5 | function. | ||
| 6 | (c-guess-basic-syntax): New CASE 5R (extracted from 5B) to handle | ||
| 7 | (most) member init lists. | ||
| 8 | |||
| 1 | 2013-04-30 RĂ¼diger Sonderfeld <ruediger@c-plusplus.de> | 9 | 2013-04-30 RĂ¼diger Sonderfeld <ruediger@c-plusplus.de> |
| 2 | 10 | ||
| 3 | * progmodes/octave.el (inferior-octave-prompt-read-only): New user | 11 | * progmodes/octave.el (inferior-octave-prompt-read-only): New user |
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 4fc270792fc..6a23da1f2cd 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el | |||
| @@ -6475,6 +6475,52 @@ comment at the start of cc-engine.el for more info." | |||
| 6475 | (c-go-list-forward) | 6475 | (c-go-list-forward) |
| 6476 | t))) | 6476 | t))) |
| 6477 | 6477 | ||
| 6478 | (defun c-back-over-member-initializers () | ||
| 6479 | ;; Test whether we are in a C++ member initializer list, and if so, go back | ||
| 6480 | ;; to the introducing ":", returning the position of the opening paren of | ||
| 6481 | ;; the function's arglist. Otherwise return nil, leaving point unchanged. | ||
| 6482 | (let ((here (point)) | ||
| 6483 | (paren-state (c-parse-state)) | ||
| 6484 | res) | ||
| 6485 | |||
| 6486 | (setq res | ||
| 6487 | (catch 'done | ||
| 6488 | (if (not (c-at-toplevel-p)) | ||
| 6489 | (progn | ||
| 6490 | (while (not (c-at-toplevel-p)) | ||
| 6491 | (goto-char (c-pull-open-brace paren-state))) | ||
| 6492 | (c-backward-syntactic-ws) | ||
| 6493 | (when (not (c-simple-skip-symbol-backward)) | ||
| 6494 | (throw 'done nil)) | ||
| 6495 | (c-backward-syntactic-ws)) | ||
| 6496 | (c-backward-syntactic-ws) | ||
| 6497 | (when (memq (char-before) '(?\) ?})) | ||
| 6498 | (when (not (c-go-list-backward)) | ||
| 6499 | (throw 'done nil)) | ||
| 6500 | (c-backward-syntactic-ws)) | ||
| 6501 | (when (c-simple-skip-symbol-backward) | ||
| 6502 | (c-backward-syntactic-ws))) | ||
| 6503 | |||
| 6504 | (while (eq (char-before) ?,) | ||
| 6505 | (backward-char) | ||
| 6506 | (c-backward-syntactic-ws) | ||
| 6507 | |||
| 6508 | (when (not (memq (char-before) '(?\) ?}))) | ||
| 6509 | (throw 'done nil)) | ||
| 6510 | (when (not (c-go-list-backward)) | ||
| 6511 | (throw 'done nil)) | ||
| 6512 | (c-backward-syntactic-ws) | ||
| 6513 | (when (not (c-simple-skip-symbol-backward)) | ||
| 6514 | (throw 'done nil)) | ||
| 6515 | (c-backward-syntactic-ws)) | ||
| 6516 | |||
| 6517 | (and | ||
| 6518 | (eq (char-before) ?:) | ||
| 6519 | (c-just-after-func-arglist-p)))) | ||
| 6520 | |||
| 6521 | (or res (goto-char here)) | ||
| 6522 | res)) | ||
| 6523 | |||
| 6478 | 6524 | ||
| 6479 | ;; Handling of large scale constructs like statements and declarations. | 6525 | ;; Handling of large scale constructs like statements and declarations. |
| 6480 | 6526 | ||
| @@ -9677,18 +9723,13 @@ comment at the start of cc-engine.el for more info." | |||
| 9677 | ;; 2007-11-09) | 9723 | ;; 2007-11-09) |
| 9678 | )))) | 9724 | )))) |
| 9679 | 9725 | ||
| 9680 | ;; CASE 5B: After a function header but before the body (or | 9726 | ;; CASE 5R: Member init list. (Used to be part of CASE 5B.1) |
| 9681 | ;; the ending semicolon if there's no body). | 9727 | ;; Note there is no limit on the backward search here, since member |
| 9728 | ;; init lists can, in practice, be very large. | ||
| 9682 | ((save-excursion | 9729 | ((save-excursion |
| 9683 | (when (setq placeholder (c-just-after-func-arglist-p | 9730 | (when (setq placeholder (c-back-over-member-initializers)) |
| 9684 | (max lim (c-determine-limit 500)))) | ||
| 9685 | (setq tmp-pos (point)))) | 9731 | (setq tmp-pos (point)))) |
| 9686 | (cond | 9732 | (if (= (c-point 'bosws) (1+ tmp-pos)) |
| 9687 | |||
| 9688 | ;; CASE 5B.1: Member init list. | ||
| 9689 | ((eq (char-after tmp-pos) ?:) | ||
| 9690 | (if (or (>= tmp-pos indent-point) | ||
| 9691 | (= (c-point 'bosws) (1+ tmp-pos))) | ||
| 9692 | (progn | 9733 | (progn |
| 9693 | ;; There is no preceding member init clause. | 9734 | ;; There is no preceding member init clause. |
| 9694 | ;; Indent relative to the beginning of indentation | 9735 | ;; Indent relative to the beginning of indentation |
| @@ -9701,6 +9742,23 @@ comment at the start of cc-engine.el for more info." | |||
| 9701 | (c-forward-syntactic-ws) | 9742 | (c-forward-syntactic-ws) |
| 9702 | (c-add-syntax 'member-init-cont (point)))) | 9743 | (c-add-syntax 'member-init-cont (point)))) |
| 9703 | 9744 | ||
| 9745 | ;; CASE 5B: After a function header but before the body (or | ||
| 9746 | ;; the ending semicolon if there's no body). | ||
| 9747 | ((save-excursion | ||
| 9748 | (when (setq placeholder (c-just-after-func-arglist-p | ||
| 9749 | (max lim (c-determine-limit 500)))) | ||
| 9750 | (setq tmp-pos (point)))) | ||
| 9751 | (cond | ||
| 9752 | |||
| 9753 | ;; CASE 5B.1: Member init list. | ||
| 9754 | ((eq (char-after tmp-pos) ?:) | ||
| 9755 | ;; There is no preceding member init clause. | ||
| 9756 | ;; Indent relative to the beginning of indentation | ||
| 9757 | ;; for the topmost-intro line that contains the | ||
| 9758 | ;; prototype's open paren. | ||
| 9759 | (goto-char placeholder) | ||
| 9760 | (c-add-syntax 'member-init-intro (c-point 'boi))) | ||
| 9761 | |||
| 9704 | ;; CASE 5B.2: K&R arg decl intro | 9762 | ;; CASE 5B.2: K&R arg decl intro |
| 9705 | ((and c-recognize-knr-p | 9763 | ((and c-recognize-knr-p |
| 9706 | (c-in-knr-argdecl lim)) | 9764 | (c-in-knr-argdecl lim)) |