aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2017-09-16 11:31:38 +0000
committerAlan Mackenzie2017-09-16 11:31:38 +0000
commit4ea37c2b8b0c5a68fde59770c3536195e0972217 (patch)
tree4d961e699f3379139974cef30e8b7d26e0e7b4a1
parent2d53f8783ff8e48d91809741adab6a2402587fad (diff)
downloademacs-4ea37c2b8b0c5a68fde59770c3536195e0972217.tar.gz
emacs-4ea37c2b8b0c5a68fde59770c3536195e0972217.zip
Cope better with C++ and Objective-C protection keywords in class declarations
This fix fixes the fontification of a method inside a class at the time it is typed, when there is a protection keyword clause preceding it. * lisp/progmodes/cc-engine.el (c-forward-keyword-clause): Handle protection keywords. (c-looking-at-decl-block): Avoid scanning forward over protection keyword clauses too eagerly. * lisp/progmodes/cc-langs.el (c-protection-key c-post-protection-token): New lang defconsts and defvars. * lisp/progmodes/cc-mode.el (c-fl-decl-start): When we encounter a protection keyword following a semicolon or brace, move forward over it before attempting to parse a type.
-rw-r--r--lisp/progmodes/cc-engine.el25
-rw-r--r--lisp/progmodes/cc-langs.el12
-rw-r--r--lisp/progmodes/cc-mode.el19
3 files changed, 45 insertions, 11 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index d5083ed2481..05b391a3d38 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -6924,7 +6924,7 @@ comment at the start of cc-engine.el for more info."
6924 ;; recognized are those specified by `c-type-list-kwds', 6924 ;; recognized are those specified by `c-type-list-kwds',
6925 ;; `c-ref-list-kwds', `c-colon-type-list-kwds', 6925 ;; `c-ref-list-kwds', `c-colon-type-list-kwds',
6926 ;; `c-paren-nontype-kwds', `c-paren-type-kwds', `c-<>-type-kwds', 6926 ;; `c-paren-nontype-kwds', `c-paren-type-kwds', `c-<>-type-kwds',
6927 ;; and `c-<>-arglist-kwds'. 6927 ;; `c-<>-arglist-kwds', and `c-protection-kwds'.
6928 ;; 6928 ;;
6929 ;; This function records identifier ranges on 6929 ;; This function records identifier ranges on
6930 ;; `c-record-type-identifiers' and `c-record-ref-identifiers' if 6930 ;; `c-record-type-identifiers' and `c-record-ref-identifiers' if
@@ -6994,6 +6994,17 @@ comment at the start of cc-engine.el for more info."
6994 (not (looking-at c-symbol-start)) 6994 (not (looking-at c-symbol-start))
6995 (c-safe (c-forward-sexp) t)) 6995 (c-safe (c-forward-sexp) t))
6996 (c-forward-syntactic-ws) 6996 (c-forward-syntactic-ws)
6997 (setq safe-pos (point)))
6998
6999 ((and (c-keyword-member kwd-sym 'c-protection-kwds)
7000 (or (null c-post-protection-token)
7001 (and (looking-at c-post-protection-token)
7002 (save-excursion
7003 (goto-char (match-end 0))
7004 (not (c-end-of-current-token))))))
7005 (if c-post-protection-token
7006 (goto-char (match-end 0)))
7007 (c-forward-syntactic-ws)
6997 (setq safe-pos (point)))) 7008 (setq safe-pos (point))))
6998 7009
6999 (when (c-keyword-member kwd-sym 'c-colon-type-list-kwds) 7010 (when (c-keyword-member kwd-sym 'c-colon-type-list-kwds)
@@ -10169,8 +10180,16 @@ comment at the start of cc-engine.el for more info."
10169 ;; Could be more restrictive wrt invalid keywords, 10180 ;; Could be more restrictive wrt invalid keywords,
10170 ;; but that'd only occur in invalid code so there's 10181 ;; but that'd only occur in invalid code so there's
10171 ;; no use spending effort on it. 10182 ;; no use spending effort on it.
10172 (let ((end (match-end 0))) 10183 (let ((end (match-end 0))
10173 (unless (c-forward-keyword-clause 0) 10184 (kwd-sym (c-keyword-sym (match-string 0))))
10185 (unless
10186 (and kwd-sym
10187 ;; Moving over a protection kwd and the following
10188 ;; ":" (in C++ Mode) to the next token could take
10189 ;; us all the way up to `kwd-start', leaving us
10190 ;; no chance to update `first-specifier-pos'.
10191 (not (c-keyword-member kwd-sym 'c-protection-kwds))
10192 (c-forward-keyword-clause 0))
10174 (goto-char end) 10193 (goto-char end)
10175 (c-forward-syntactic-ws))) 10194 (c-forward-syntactic-ws)))
10176 10195
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index ef6b88c3727..7a285f93d34 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -2284,6 +2284,18 @@ one of `c-type-list-kwds', `c-ref-list-kwds',
2284 c++ '("private" "protected" "public") 2284 c++ '("private" "protected" "public")
2285 objc '("@private" "@protected" "@public")) 2285 objc '("@private" "@protected" "@public"))
2286 2286
2287(c-lang-defconst c-protection-key
2288 ;; A regexp match an element of `c-protection-kwds' cleanly.
2289 t (c-make-keywords-re t (c-lang-const c-protection-kwds)))
2290(c-lang-defvar c-protection-key (c-lang-const c-protection-key))
2291
2292(c-lang-defconst c-post-protection-token
2293 "The token which (may) follow a protection keyword,
2294e.g. the \":\" in C++ Mode's \"public:\". nil if there is no such token."
2295 t nil
2296 c++ ":")
2297(c-lang-defvar c-post-protection-token (c-lang-const c-post-protection-token))
2298
2287(c-lang-defconst c-block-decls-with-vars 2299(c-lang-defconst c-block-decls-with-vars
2288 "Keywords introducing declarations that can contain a block which 2300 "Keywords introducing declarations that can contain a block which
2289might be followed by variable declarations, e.g. like \"foo\" in 2301might be followed by variable declarations, e.g. like \"foo\" in
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index 354dee82df9..8867453e85c 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -1526,14 +1526,17 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".")
1526 (> (point) bod-lim) 1526 (> (point) bod-lim)
1527 (progn (c-forward-syntactic-ws) 1527 (progn (c-forward-syntactic-ws)
1528 (setq bo-decl (point)) 1528 (setq bo-decl (point))
1529 ;; Are we looking at a keyword such as "template" or 1529 (or (not (looking-at c-protection-key))
1530 ;; "typedef" which can decorate a type, or the type itself? 1530 (c-forward-keyword-clause 1)))
1531 (when (or (looking-at c-prefix-spec-kwds-re) 1531 (progn
1532 (c-forward-type t)) 1532 ;; Are we looking at a keyword such as "template" or
1533 ;; We've found another candidate position. 1533 ;; "typedef" which can decorate a type, or the type itself?
1534 (setq new-pos (min new-pos bo-decl)) 1534 (when (or (looking-at c-prefix-spec-kwds-re)
1535 (goto-char bo-decl)) 1535 (c-forward-type t))
1536 t) 1536 ;; We've found another candidate position.
1537 (setq new-pos (min new-pos bo-decl))
1538 (goto-char bo-decl))
1539 t)
1537 ;; Try and go out a level to search again. 1540 ;; Try and go out a level to search again.
1538 (progn 1541 (progn
1539 (c-backward-syntactic-ws bod-lim) 1542 (c-backward-syntactic-ws bod-lim)