diff options
| author | Alan Mackenzie | 2016-02-04 19:01:50 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2016-02-04 19:01:50 +0000 |
| commit | 9dfece1413846e4df438cd20956c58e12c84dea3 (patch) | |
| tree | b2595ebe194a3e9e2898d3933c2943d560b78f26 | |
| parent | 448522201a12413b6fd4f059202b4d9a79ad3699 (diff) | |
| download | emacs-9dfece1413846e4df438cd20956c58e12c84dea3.tar.gz emacs-9dfece1413846e4df438cd20956c58e12c84dea3.zip | |
Correctly fontify C++ initializations which "look like" functions.
Fixes bug#7579.
lisp/progmodes/cc-engine.el (c-forward-declarator): Add extra optional
parameter to enable handling of "anonymous" declarators in declarations.
lisp/progmodes/cc-fonts.el (c-font-lock-declarators): Check more rigorously
whether a "(" opens a parameter list of a function, or an initialization of a
variable.
| -rw-r--r-- | lisp/progmodes/cc-engine.el | 23 | ||||
| -rw-r--r-- | lisp/progmodes/cc-fonts.el | 25 |
2 files changed, 39 insertions, 9 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index b75d667d318..d30447fe554 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el | |||
| @@ -6808,7 +6808,7 @@ comment at the start of cc-engine.el for more info." | |||
| 6808 | ;; This identifier is bound only in the inner let. | 6808 | ;; This identifier is bound only in the inner let. |
| 6809 | '(setq start id-start)))) | 6809 | '(setq start id-start)))) |
| 6810 | 6810 | ||
| 6811 | (defun c-forward-declarator (&optional limit) | 6811 | (defun c-forward-declarator (&optional limit accept-anon) |
| 6812 | ;; Assuming point is at the start of a declarator, move forward over it, | 6812 | ;; Assuming point is at the start of a declarator, move forward over it, |
| 6813 | ;; leaving point at the next token after it (e.g. a ) or a ; or a ,). | 6813 | ;; leaving point at the next token after it (e.g. a ) or a ; or a ,). |
| 6814 | ;; | 6814 | ;; |
| @@ -6817,6 +6817,11 @@ comment at the start of cc-engine.el for more info." | |||
| 6817 | ;; BRACKETS-AFTER-ID is non-nil if a [...] pair is present after the id. | 6817 | ;; BRACKETS-AFTER-ID is non-nil if a [...] pair is present after the id. |
| 6818 | ;; GOT-INIT is non-nil when the declarator is followed by "=" or "(". | 6818 | ;; GOT-INIT is non-nil when the declarator is followed by "=" or "(". |
| 6819 | ;; | 6819 | ;; |
| 6820 | ;; If ACCEPT-ANON is non-nil, move forward over any "anonymous declarator", | ||
| 6821 | ;; i.e. something like the (*) in int (*), such as might be found in a | ||
| 6822 | ;; declaration. In such a case ID-START and ID-END in the return value are | ||
| 6823 | ;; both set to nil. A "null" "anonymous declarator" gives a non-nil result. | ||
| 6824 | ;; | ||
| 6820 | ;; If no declarator is found, leave point unmoved and return nil. LIMIT is | 6825 | ;; If no declarator is found, leave point unmoved and return nil. LIMIT is |
| 6821 | ;; an optional limit for forward searching. | 6826 | ;; an optional limit for forward searching. |
| 6822 | ;; | 6827 | ;; |
| @@ -6871,13 +6876,17 @@ comment at the start of cc-engine.el for more info." | |||
| 6871 | 6876 | ||
| 6872 | ;; If we haven't passed the identifier already, do it now. | 6877 | ;; If we haven't passed the identifier already, do it now. |
| 6873 | (unless got-identifier | 6878 | (unless got-identifier |
| 6874 | (setq id-start (point)) | 6879 | (setq id-start (point))) |
| 6875 | (c-forward-name)) | 6880 | (cond |
| 6876 | (prog1 | 6881 | ((or got-identifier |
| 6877 | (/= (point) here) | 6882 | (c-forward-name)) |
| 6878 | (save-excursion | 6883 | (save-excursion |
| 6879 | (c-backward-syntactic-ws) | 6884 | (c-backward-syntactic-ws) |
| 6880 | (setq id-end (point))))) | 6885 | (setq id-end (point)))) |
| 6886 | (accept-anon | ||
| 6887 | (setq id-start nil id-end nil) | ||
| 6888 | t) | ||
| 6889 | (t (/= (point) here)))) | ||
| 6881 | 6890 | ||
| 6882 | ;; Skip out of the parens surrounding the identifier. If closing | 6891 | ;; Skip out of the parens surrounding the identifier. If closing |
| 6883 | ;; parens are missing, this form returns nil. | 6892 | ;; parens are missing, this form returns nil. |
| @@ -7266,7 +7275,7 @@ comment at the start of cc-engine.el for more info." | |||
| 7266 | (goto-char id-start) | 7275 | (goto-char id-start) |
| 7267 | 7276 | ||
| 7268 | ;; Skip over type decl prefix operators. (Note similar code in | 7277 | ;; Skip over type decl prefix operators. (Note similar code in |
| 7269 | ;; `c-font-lock-declarators'.) | 7278 | ;; `c-forward-declarator'.) |
| 7270 | (if (and c-recognize-typeless-decls | 7279 | (if (and c-recognize-typeless-decls |
| 7271 | (equal c-type-decl-prefix-key "\\<\\>")) | 7280 | (equal c-type-decl-prefix-key "\\<\\>")) |
| 7272 | (when (eq (char-after) ?\() | 7281 | (when (eq (char-after) ?\() |
diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el index 1e101d12aac..3cc537bba3d 100644 --- a/lisp/progmodes/cc-fonts.el +++ b/lisp/progmodes/cc-fonts.el | |||
| @@ -1008,7 +1008,7 @@ casts and declarations are fontified. Used on level 2 and higher." | |||
| 1008 | ((pos (point)) next-pos id-start id-end | 1008 | ((pos (point)) next-pos id-start id-end |
| 1009 | decl-res | 1009 | decl-res |
| 1010 | paren-depth | 1010 | paren-depth |
| 1011 | id-face got-init | 1011 | id-face got-type got-init |
| 1012 | c-last-identifier-range | 1012 | c-last-identifier-range |
| 1013 | (separator-prop (if types 'c-decl-type-start 'c-decl-id-start)) | 1013 | (separator-prop (if types 'c-decl-type-start 'c-decl-id-start)) |
| 1014 | brackets-after-id) | 1014 | brackets-after-id) |
| @@ -1020,7 +1020,28 @@ casts and declarations are fontified. Used on level 2 and higher." | |||
| 1020 | (setq next-pos (point) | 1020 | (setq next-pos (point) |
| 1021 | id-start (car decl-res) | 1021 | id-start (car decl-res) |
| 1022 | id-face (if (and (eq (char-after) ?\() | 1022 | id-face (if (and (eq (char-after) ?\() |
| 1023 | (not (car (cddr decl-res)))) ; brackets-after-id | 1023 | (not (car (cddr decl-res))) ; brackets-after-id |
| 1024 | (or (not (c-major-mode-is 'c++-mode)) | ||
| 1025 | (save-excursion | ||
| 1026 | (let (c-last-identifier-range) | ||
| 1027 | (forward-char) | ||
| 1028 | (c-forward-syntactic-ws) | ||
| 1029 | (catch 'is-function | ||
| 1030 | (while | ||
| 1031 | (progn | ||
| 1032 | (if (eq (char-after) ?\)) | ||
| 1033 | (throw 'is-function t)) | ||
| 1034 | (setq got-type (c-forward-type)) | ||
| 1035 | (cond | ||
| 1036 | ((null got-type) | ||
| 1037 | (throw 'is-function nil)) | ||
| 1038 | ((not (eq got-type 'maybe)) | ||
| 1039 | (throw 'is-function t))) | ||
| 1040 | (c-forward-declarator limit t) | ||
| 1041 | (eq (char-after) ?,)) | ||
| 1042 | (forward-char) | ||
| 1043 | (c-forward-syntactic-ws)) | ||
| 1044 | t))))) | ||
| 1024 | 'font-lock-function-name-face | 1045 | 'font-lock-function-name-face |
| 1025 | 'font-lock-variable-name-face) | 1046 | 'font-lock-variable-name-face) |
| 1026 | got-init (and (cadr (cddr decl-res)) ; got-init | 1047 | got-init (and (cadr (cddr decl-res)) ; got-init |