aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2013-09-21 17:21:29 +0000
committerAlan Mackenzie2013-09-21 17:21:29 +0000
commitece15004709aa79faa2e19194c51699c0a86423e (patch)
treed587d703dd3772e2902d09a2319751c59a66a1b5
parentb3f1d1198a0dddc02423f0f766e9e213373fab60 (diff)
downloademacs-ece15004709aa79faa2e19194c51699c0a86423e.tar.gz
emacs-ece15004709aa79faa2e19194c51699c0a86423e.zip
C++: fontify identifier in declaration following "public:" correctly.
* progmodes/cc-langs.el (c-decl-start-colon-kwd-re): New lang var to match "public", etc. (c-decl-prefix-re): Add ":" into the C++ value. * progmodes/cc-engine.el (c-find-decl-prefix-search): Refactor a bit. Add a check for a ":" preceded by "public", etc.
-rw-r--r--lisp/ChangeLog9
-rw-r--r--lisp/progmodes/cc-engine.el72
-rw-r--r--lisp/progmodes/cc-langs.el16
3 files changed, 68 insertions, 29 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 74bcabfb575..cf5e3e1f061 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,12 @@
12013-09-21 Alan Mackenzie <acm@muc.de>
2
3 C++: fontify identifier in declaration following "public:" correctly.
4 * progmodes/cc-langs.el (c-decl-start-colon-kwd-re): New lang var
5 to match "public", etc.
6 (c-decl-prefix-re): Add ":" into the C++ value.
7 * progmodes/cc-engine.el (c-find-decl-prefix-search): Refactor a
8 bit. Add a check for a ":" preceded by "public", etc.
9
12013-09-21 Eli Zaretskii <eliz@gnu.org> 102013-09-21 Eli Zaretskii <eliz@gnu.org>
2 11
3 * files.el (auto-mode-alist): Support OBJFILE-gdb.gdb script files 12 * files.el (auto-mode-alist): Support OBJFILE-gdb.gdb script files
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 582f7ef0a54..ce83efd114b 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -4729,6 +4729,11 @@ comment at the start of cc-engine.el for more info."
4729 ;; inside `c-find-decl-spots'. The point is left at `cfd-match-pos' 4729 ;; inside `c-find-decl-spots'. The point is left at `cfd-match-pos'
4730 ;; if there is a match, otherwise at `cfd-limit'. 4730 ;; if there is a match, otherwise at `cfd-limit'.
4731 ;; 4731 ;;
4732 ;; The macro moves point forward to the next putative start of a declaration
4733 ;; or cfd-limit. This decl start is the next token after a "declaration
4734 ;; prefix". The declaration prefix is the earlier of `cfd-prop-match' and
4735 ;; `cfd-re-match'. `cfd-match-pos' is set to the decl prefix.
4736 ;;
4732 ;; This macro might do hidden buffer changes. 4737 ;; This macro might do hidden buffer changes.
4733 4738
4734 '(progn 4739 '(progn
@@ -4750,34 +4755,47 @@ comment at the start of cc-engine.el for more info."
4750 (if (> cfd-re-match-end (point)) 4755 (if (> cfd-re-match-end (point))
4751 (goto-char cfd-re-match-end)) 4756 (goto-char cfd-re-match-end))
4752 4757
4753 (while (if (setq cfd-re-match-end 4758 ;; Each time round, the next `while' moves forward over a pseudo match
4754 (re-search-forward c-decl-prefix-or-start-re 4759 ;; of `c-decl-prefix-or-start-re' which is either inside a literal, or
4755 cfd-limit 'move)) 4760 ;; is a ":" not preceded by "public", etc.. `cfd-re-match' and
4756 4761 ;; `cfd-re-match-end' get set.
4757 ;; Match. Check if it's inside a comment or string literal. 4762 (while
4758 (c-got-face-at 4763 (progn
4759 (if (setq cfd-re-match (match-end 1)) 4764 (setq cfd-re-match-end (re-search-forward c-decl-prefix-or-start-re
4760 ;; Matched the end of a token preceding a decl spot. 4765 cfd-limit 'move))
4761 (progn 4766 (cond
4762 (goto-char cfd-re-match) 4767 ((null cfd-re-match-end)
4763 (1- cfd-re-match)) 4768 ;; No match. Finish up and exit the loop.
4764 ;; Matched a token that start a decl spot. 4769 (setq cfd-re-match cfd-limit)
4765 (goto-char (match-beginning 0)) 4770 nil)
4766 (point)) 4771 ((c-got-face-at
4767 c-literal-faces) 4772 (if (setq cfd-re-match (match-end 1))
4768 4773 ;; Matched the end of a token preceding a decl spot.
4769 ;; No match. Finish up and exit the loop. 4774 (progn
4770 (setq cfd-re-match cfd-limit) 4775 (goto-char cfd-re-match)
4771 nil) 4776 (1- cfd-re-match))
4772 4777 ;; Matched a token that start a decl spot.
4773 ;; Skip out of comments and string literals. 4778 (goto-char (match-beginning 0))
4774 (while (progn 4779 (point))
4775 (goto-char (next-single-property-change 4780 c-literal-faces)
4776 (point) 'face nil cfd-limit)) 4781 ;; Pseudo match inside a comment or string literal. Skip out
4777 (and (< (point) cfd-limit) 4782 ;; of comments and string literals.
4778 (c-got-face-at (point) c-literal-faces))))) 4783 (while (progn
4784 (goto-char (next-single-property-change
4785 (point) 'face nil cfd-limit))
4786 (and (< (point) cfd-limit)
4787 (c-got-face-at (point) c-literal-faces))))
4788 t) ; Continue the loop over pseudo matches.
4789 ((and (match-string 1)
4790 (string= (match-string 1) ":")
4791 (save-excursion
4792 (or (/= (c-backward-token-2 2) 0) ; no search limit. :-(
4793 (not (looking-at c-decl-start-colon-kwd-re)))))
4794 ;; Found a ":" which isn't part of "public:", etc.
4795 t)
4796 (t nil)))) ;; Found a real match. Exit the pseudo-match loop.
4779 4797
4780 ;; If we matched at the decl start, we have to back up over the 4798 ;; If our match was at the decl start, we have to back up over the
4781 ;; preceding syntactic ws to set `cfd-match-pos' and to catch 4799 ;; preceding syntactic ws to set `cfd-match-pos' and to catch
4782 ;; any decl spots in the syntactic ws. 4800 ;; any decl spots in the syntactic ws.
4783 (unless cfd-re-match 4801 (unless cfd-re-match
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index 80e6189822b..c1e8a1524dc 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -2587,6 +2587,15 @@ Note that Java specific rules are currently applied to tell this from
2587 2587
2588;;; Additional constants for parser-level constructs. 2588;;; Additional constants for parser-level constructs.
2589 2589
2590(c-lang-defconst c-decl-start-colon-kwd-re
2591 "Regexp matching a keyword that is followed by a colon, where
2592 the whole construct can precede a declaration.
2593 E.g. \"public:\" in C++."
2594 t "\\<\\>"
2595 c++ (c-make-keywords-re t (c-lang-const c-protection-kwds)))
2596(c-lang-defvar c-decl-start-colon-kwd-re
2597 (c-lang-const c-decl-start-colon-kwd-re))
2598
2590(c-lang-defconst c-decl-prefix-re 2599(c-lang-defconst c-decl-prefix-re
2591 "Regexp matching something that might precede a declaration, cast or 2600 "Regexp matching something that might precede a declaration, cast or
2592label, such as the last token of a preceding statement or declaration. 2601label, such as the last token of a preceding statement or declaration.
@@ -2626,8 +2635,11 @@ more info."
2626 java "\\([\{\}\(;,<]+\\)" 2635 java "\\([\{\}\(;,<]+\\)"
2627 ;; Match "<" in C++ to get the first argument in a template arglist. 2636 ;; Match "<" in C++ to get the first argument in a template arglist.
2628 ;; In that case there's an additional check in `c-find-decl-spots' 2637 ;; In that case there's an additional check in `c-find-decl-spots'
2629 ;; that it got open paren syntax. 2638 ;; that it got open paren syntax. Match ":" to aid in picking up
2630 c++ "\\([\{\}\(\);,<]+\\)" 2639 ;; "public:", etc. This involves additional checks in
2640 ;; `c-find-decl-prefix-search' to prevent a match of identifiers
2641 ;; or labels.
2642 c++ "\\([\{\}\(\);:,<]+\\)"
2631 ;; Additionally match the protection directives in Objective-C. 2643 ;; Additionally match the protection directives in Objective-C.
2632 ;; Note that this doesn't cope with the longer directives, which we 2644 ;; Note that this doesn't cope with the longer directives, which we
2633 ;; would have to match from start to end since they don't end with 2645 ;; would have to match from start to end since they don't end with