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.
This commit is contained in:
parent
448522201a
commit
9dfece1413
2 changed files with 39 additions and 9 deletions
|
@ -6808,7 +6808,7 @@ comment at the start of cc-engine.el for more info."
|
|||
;; This identifier is bound only in the inner let.
|
||||
'(setq start id-start))))
|
||||
|
||||
(defun c-forward-declarator (&optional limit)
|
||||
(defun c-forward-declarator (&optional limit accept-anon)
|
||||
;; Assuming point is at the start of a declarator, move forward over it,
|
||||
;; leaving point at the next token after it (e.g. a ) or a ; or a ,).
|
||||
;;
|
||||
|
@ -6817,6 +6817,11 @@ comment at the start of cc-engine.el for more info."
|
|||
;; BRACKETS-AFTER-ID is non-nil if a [...] pair is present after the id.
|
||||
;; GOT-INIT is non-nil when the declarator is followed by "=" or "(".
|
||||
;;
|
||||
;; If ACCEPT-ANON is non-nil, move forward over any "anonymous declarator",
|
||||
;; i.e. something like the (*) in int (*), such as might be found in a
|
||||
;; declaration. In such a case ID-START and ID-END in the return value are
|
||||
;; both set to nil. A "null" "anonymous declarator" gives a non-nil result.
|
||||
;;
|
||||
;; If no declarator is found, leave point unmoved and return nil. LIMIT is
|
||||
;; an optional limit for forward searching.
|
||||
;;
|
||||
|
@ -6871,13 +6876,17 @@ comment at the start of cc-engine.el for more info."
|
|||
|
||||
;; If we haven't passed the identifier already, do it now.
|
||||
(unless got-identifier
|
||||
(setq id-start (point))
|
||||
(c-forward-name))
|
||||
(prog1
|
||||
(/= (point) here)
|
||||
(setq id-start (point)))
|
||||
(cond
|
||||
((or got-identifier
|
||||
(c-forward-name))
|
||||
(save-excursion
|
||||
(c-backward-syntactic-ws)
|
||||
(setq id-end (point)))))
|
||||
(setq id-end (point))))
|
||||
(accept-anon
|
||||
(setq id-start nil id-end nil)
|
||||
t)
|
||||
(t (/= (point) here))))
|
||||
|
||||
;; Skip out of the parens surrounding the identifier. If closing
|
||||
;; parens are missing, this form returns nil.
|
||||
|
@ -7266,7 +7275,7 @@ comment at the start of cc-engine.el for more info."
|
|||
(goto-char id-start)
|
||||
|
||||
;; Skip over type decl prefix operators. (Note similar code in
|
||||
;; `c-font-lock-declarators'.)
|
||||
;; `c-forward-declarator'.)
|
||||
(if (and c-recognize-typeless-decls
|
||||
(equal c-type-decl-prefix-key "\\<\\>"))
|
||||
(when (eq (char-after) ?\()
|
||||
|
|
|
@ -1008,7 +1008,7 @@ casts and declarations are fontified. Used on level 2 and higher."
|
|||
((pos (point)) next-pos id-start id-end
|
||||
decl-res
|
||||
paren-depth
|
||||
id-face got-init
|
||||
id-face got-type got-init
|
||||
c-last-identifier-range
|
||||
(separator-prop (if types 'c-decl-type-start 'c-decl-id-start))
|
||||
brackets-after-id)
|
||||
|
@ -1020,7 +1020,28 @@ casts and declarations are fontified. Used on level 2 and higher."
|
|||
(setq next-pos (point)
|
||||
id-start (car decl-res)
|
||||
id-face (if (and (eq (char-after) ?\()
|
||||
(not (car (cddr decl-res)))) ; brackets-after-id
|
||||
(not (car (cddr decl-res))) ; brackets-after-id
|
||||
(or (not (c-major-mode-is 'c++-mode))
|
||||
(save-excursion
|
||||
(let (c-last-identifier-range)
|
||||
(forward-char)
|
||||
(c-forward-syntactic-ws)
|
||||
(catch 'is-function
|
||||
(while
|
||||
(progn
|
||||
(if (eq (char-after) ?\))
|
||||
(throw 'is-function t))
|
||||
(setq got-type (c-forward-type))
|
||||
(cond
|
||||
((null got-type)
|
||||
(throw 'is-function nil))
|
||||
((not (eq got-type 'maybe))
|
||||
(throw 'is-function t)))
|
||||
(c-forward-declarator limit t)
|
||||
(eq (char-after) ?,))
|
||||
(forward-char)
|
||||
(c-forward-syntactic-ws))
|
||||
t)))))
|
||||
'font-lock-function-name-face
|
||||
'font-lock-variable-name-face)
|
||||
got-init (and (cadr (cddr decl-res)) ; got-init
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue