diff options
| author | Alan Mackenzie | 2018-01-16 21:59:03 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2018-01-16 21:59:03 +0000 |
| commit | b02a06317b04b56d54f73a7d97568a0bc150a18b (patch) | |
| tree | fbb50c28f5d917f4b0e58e8e000b4e93f2437b20 | |
| parent | 743323e570dcb2fdb98a9067073176811fb5428c (diff) | |
| download | emacs-b02a06317b04b56d54f73a7d97568a0bc150a18b.tar.gz emacs-b02a06317b04b56d54f73a7d97568a0bc150a18b.zip | |
C++ Mode: Fontify correctly uniform initialisation with inner parentheses.
E.g.: someStruct x ( (nullptr != y) ? 3 : 4 )
Also fontify declarations of function pointers correctly.
* lisp/progmodes/cc-engine.el (c-forward-decl-or-cast-1): While testing for a
typeless declaration, additionally test the variable `got-prefix' to
recognize a function pointer in parentheses. Allow c-fdoc-shift-type-backward
to be invoked when we have nested parens.
| -rw-r--r-- | lisp/progmodes/cc-engine.el | 57 |
1 files changed, 33 insertions, 24 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index e9972602812..5a0088df500 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el | |||
| @@ -8605,6 +8605,7 @@ comment at the start of cc-engine.el for more info." | |||
| 8605 | ;; construct here in C, since we want to recognize this as a | 8605 | ;; construct here in C, since we want to recognize this as a |
| 8606 | ;; typeless function declaration. | 8606 | ;; typeless function declaration. |
| 8607 | (not (and (c-major-mode-is 'c-mode) | 8607 | (not (and (c-major-mode-is 'c-mode) |
| 8608 | (not got-prefix) | ||
| 8608 | (or (eq context 'top) make-top) | 8609 | (or (eq context 'top) make-top) |
| 8609 | (eq (char-after) ?\))))) | 8610 | (eq (char-after) ?\))))) |
| 8610 | (if (eq (char-after) ?\)) | 8611 | (if (eq (char-after) ?\)) |
| @@ -8634,31 +8635,39 @@ comment at the start of cc-engine.el for more info." | |||
| 8634 | ;; (con|de)structors in C++ and `c-typeless-decl-kwds' | 8635 | ;; (con|de)structors in C++ and `c-typeless-decl-kwds' |
| 8635 | ;; style declarations. That isn't applicable in an | 8636 | ;; style declarations. That isn't applicable in an |
| 8636 | ;; arglist context, though. | 8637 | ;; arglist context, though. |
| 8637 | (when (and (= paren-depth 1) | 8638 | (when (and (> paren-depth 0) |
| 8638 | (not got-prefix-before-parens) | 8639 | (not got-prefix-before-parens) |
| 8639 | (not (eq at-type t)) | 8640 | (not (eq at-type t)) |
| 8640 | (or backup-at-type | 8641 | (or backup-at-type |
| 8641 | maybe-typeless | 8642 | maybe-typeless |
| 8642 | backup-maybe-typeless | 8643 | backup-maybe-typeless |
| 8643 | (when c-recognize-typeless-decls | 8644 | (when c-recognize-typeless-decls |
| 8644 | (and (memq context '(nil top)) | 8645 | (and (memq context '(nil top)) |
| 8645 | ;; Deal with C++11's "copy-initialization" | 8646 | ;; Deal with C++11's "copy-initialization" |
| 8646 | ;; where we have <type>(<constant>), by | 8647 | ;; where we have <type>(<constant>), by |
| 8647 | ;; contrasting with a typeless | 8648 | ;; contrasting with a typeless |
| 8648 | ;; <name>(<type><parameter>, ...). | 8649 | ;; <name>(<type><parameter>, ...). |
| 8649 | (save-excursion | 8650 | (save-excursion |
| 8650 | (goto-char after-paren-pos) | 8651 | (goto-char after-paren-pos) |
| 8651 | (c-forward-syntactic-ws) | 8652 | (c-forward-syntactic-ws) |
| 8652 | (or (c-forward-type) | 8653 | (or (c-forward-type) |
| 8653 | ;; Recognize a top-level typeless | 8654 | ;; Recognize a top-level typeless |
| 8654 | ;; function declaration in C. | 8655 | ;; function declaration in C. |
| 8655 | (and (c-major-mode-is 'c-mode) | 8656 | (and (c-major-mode-is 'c-mode) |
| 8656 | (or (eq context 'top) make-top) | 8657 | (or (eq context 'top) make-top) |
| 8657 | (eq (char-after) ?\)))))))) | 8658 | (eq (char-after) ?\)))))))) |
| 8658 | (setq pos (c-up-list-forward (point))) | 8659 | (let ((pd paren-depth)) |
| 8659 | (eq (char-before pos) ?\))) | 8660 | (setq pos (point)) |
| 8661 | (catch 'pd | ||
| 8662 | (while (> pd 0) | ||
| 8663 | (setq pos (c-up-list-forward pos)) | ||
| 8664 | (when (or (null pos) | ||
| 8665 | (not (eq (char-before pos) ?\)))) | ||
| 8666 | (throw 'pd nil)) | ||
| 8667 | (goto-char pos) | ||
| 8668 | (setq pd (1- pd))) | ||
| 8669 | t))) | ||
| 8660 | (c-fdoc-shift-type-backward) | 8670 | (c-fdoc-shift-type-backward) |
| 8661 | (goto-char pos) | ||
| 8662 | t))) | 8671 | t))) |
| 8663 | 8672 | ||
| 8664 | (c-forward-syntactic-ws)) | 8673 | (c-forward-syntactic-ws)) |