Prevent C++ Mode wrongly fontifying some identifiers near templates as types
This fixes debbugs #7917. * lisp/progmodes/cc-engine.el (c-forward-keyword-prefixed-id): Accept 'maybe (from c-forward-type) as sufficient to record an id. Record type id as well as ref ids. (c-forward-name): Bind c-last-identifier-range around the call to c-forward-<>-arglist to prevent it getting corrupted. Don't automatically assume an identifier is a type when a template ">" is followed by a "(". (c-forward-type): Don't automatically assume an identifier is a type when a template ">" is followed by a "(". * lisp/progmodes/cc-fonts.el (c-font-lock-<>-arglists): Don't fontify an identifier as a type when its associated ">" is followed by a "(".
This commit is contained in:
parent
b3b523cdd6
commit
9151f16e81
2 changed files with 31 additions and 17 deletions
|
@ -5812,10 +5812,11 @@ comment at the start of cc-engine.el for more info."
|
||||||
nil
|
nil
|
||||||
(and (looking-at c-keywords-regexp)
|
(and (looking-at c-keywords-regexp)
|
||||||
(c-forward-keyword-clause 1))))
|
(c-forward-keyword-clause 1))))
|
||||||
(when (memq res '(t known found prefix))
|
(when (memq res '(t known found prefix maybe))
|
||||||
,(when (eq type 'ref)
|
(when c-record-type-identifiers
|
||||||
`(when c-record-type-identifiers
|
,(if (eq type 'type)
|
||||||
(c-record-ref-id c-last-identifier-range)))
|
`(c-record-type-id c-last-identifier-range)
|
||||||
|
`(c-record-ref-id c-last-identifier-range)))
|
||||||
t)))
|
t)))
|
||||||
|
|
||||||
(defmacro c-forward-id-comma-list (type update-safe-pos)
|
(defmacro c-forward-id-comma-list (type update-safe-pos)
|
||||||
|
@ -6371,13 +6372,15 @@ comment at the start of cc-engine.el for more info."
|
||||||
(eq (char-after) ?<))
|
(eq (char-after) ?<))
|
||||||
;; Maybe an angle bracket arglist.
|
;; Maybe an angle bracket arglist.
|
||||||
(when (let ((c-record-type-identifiers t)
|
(when (let ((c-record-type-identifiers t)
|
||||||
(c-record-found-types t))
|
(c-record-found-types t)
|
||||||
|
(c-last-identifier-range))
|
||||||
(c-forward-<>-arglist nil))
|
(c-forward-<>-arglist nil))
|
||||||
|
|
||||||
(c-add-type start (1+ pos))
|
|
||||||
(c-forward-syntactic-ws)
|
(c-forward-syntactic-ws)
|
||||||
(setq pos (point)
|
(unless (eq (char-after) ?\()
|
||||||
c-last-identifier-range nil)
|
(setq c-last-identifier-range nil)
|
||||||
|
(c-add-type start (1+ pos)))
|
||||||
|
(setq pos (point))
|
||||||
|
|
||||||
(if (and c-opt-identifier-concat-key
|
(if (and c-opt-identifier-concat-key
|
||||||
(looking-at c-opt-identifier-concat-key))
|
(looking-at c-opt-identifier-concat-key))
|
||||||
|
@ -6391,7 +6394,8 @@ comment at the start of cc-engine.el for more info."
|
||||||
(c-forward-syntactic-ws)
|
(c-forward-syntactic-ws)
|
||||||
t)
|
t)
|
||||||
|
|
||||||
(when (and c-record-type-identifiers id-start)
|
(when (and c-record-type-identifiers id-start
|
||||||
|
(not (eq (char-after) ?\()))
|
||||||
(c-record-type-id (cons id-start id-end)))
|
(c-record-type-id (cons id-start id-end)))
|
||||||
(setq res 'template)
|
(setq res 'template)
|
||||||
nil)))
|
nil)))
|
||||||
|
@ -6565,9 +6569,18 @@ comment at the start of cc-engine.el for more info."
|
||||||
;; It's an identifier that might be a type.
|
;; It's an identifier that might be a type.
|
||||||
'maybe))))
|
'maybe))))
|
||||||
((eq name-res 'template)
|
((eq name-res 'template)
|
||||||
;; A template is a type.
|
;; A template is sometimes a type.
|
||||||
(goto-char id-end)
|
(goto-char id-end)
|
||||||
(setq res t))
|
(c-forward-syntactic-ws)
|
||||||
|
(setq res
|
||||||
|
(if (eq (char-after) ?\()
|
||||||
|
(if (c-check-type id-start id-end)
|
||||||
|
;; It's an identifier that has been used as
|
||||||
|
;; a type somewhere else.
|
||||||
|
'found
|
||||||
|
;; It's an identifier that might be a type.
|
||||||
|
'maybe)
|
||||||
|
t)))
|
||||||
(t
|
(t
|
||||||
;; Otherwise it's an operator identifier, which is not a type.
|
;; Otherwise it's an operator identifier, which is not a type.
|
||||||
(goto-char start)
|
(goto-char start)
|
||||||
|
|
|
@ -914,7 +914,7 @@ casts and declarations are fontified. Used on level 2 and higher."
|
||||||
;;
|
;;
|
||||||
;; Fontify types and references in names containing angle bracket
|
;; Fontify types and references in names containing angle bracket
|
||||||
;; arglists from the point to LIMIT. Note that
|
;; arglists from the point to LIMIT. Note that
|
||||||
;; `c-font-lock-declarations' already has handled many of them.
|
;; `c-font-lock-declarations' has already handled many of them.
|
||||||
;;
|
;;
|
||||||
;; This function might do hidden buffer changes.
|
;; This function might do hidden buffer changes.
|
||||||
|
|
||||||
|
@ -976,11 +976,12 @@ casts and declarations are fontified. Used on level 2 and higher."
|
||||||
(when (and c-opt-identifier-concat-key
|
(when (and c-opt-identifier-concat-key
|
||||||
(not (get-text-property id-start 'face)))
|
(not (get-text-property id-start 'face)))
|
||||||
(c-forward-syntactic-ws)
|
(c-forward-syntactic-ws)
|
||||||
(if (looking-at c-opt-identifier-concat-key)
|
(cond ((looking-at c-opt-identifier-concat-key)
|
||||||
(c-put-font-lock-face id-start id-end
|
(c-put-font-lock-face id-start id-end
|
||||||
c-reference-face-name)
|
c-reference-face-name))
|
||||||
(c-put-font-lock-face id-start id-end
|
((eq (char-after) ?\())
|
||||||
'font-lock-type-face)))))
|
(t (c-put-font-lock-face id-start id-end
|
||||||
|
'font-lock-type-face))))))
|
||||||
|
|
||||||
(goto-char pos)))
|
(goto-char pos)))
|
||||||
(goto-char pos)))))
|
(goto-char pos)))))
|
||||||
|
|
Loading…
Add table
Reference in a new issue