Commits

Alan Mackenzie committed 394839a

C++: fontify identifier in declaration following "public:" correctly.
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.
cc-engine.el (c-find-decl-prefix-search): Refactor a bit. Add a check
for a ":" preceded by "public", etc.

Comments (0)

Files changed (2)

   ;; inside `c-find-decl-spots'.  The point is left at `cfd-match-pos'
   ;; if there is a match, otherwise at `cfd-limit'.
   ;;
+  ;; The macro moves point forward to the next putative start of a declaration
+  ;; or cfd-limit.  This decl start is the next token after a "declaration
+  ;; prefix".  The declaration prefix is the earlier of `cfd-prop-match' and
+  ;; `cfd-re-match'.  `cfd-match-pos' is set to the decl prefix.
+  ;; 
   ;; This macro might do hidden buffer changes.
 
   '(progn
        (if (> cfd-re-match-end (point))
 	   (goto-char cfd-re-match-end))
 
-       (while (if (setq cfd-re-match-end
-			(re-search-forward c-decl-prefix-or-start-re
-					   cfd-limit 'move))
-
-		  ;; Match.  Check if it's inside a comment or string literal.
-		  (c-got-face-at
-		   (if (setq cfd-re-match (match-end 1))
-		       ;; Matched the end of a token preceding a decl spot.
-		       (progn
-			 (goto-char cfd-re-match)
-			 (1- cfd-re-match))
-		     ;; Matched a token that start a decl spot.
-		     (goto-char (match-beginning 0))
-		     (point))
-		   c-literal-faces)
-
-		;; No match.  Finish up and exit the loop.
-		(setq cfd-re-match cfd-limit)
-		nil)
-
-	 ;; Skip out of comments and string literals.
-	 (while (progn
-		  (goto-char (c-next-single-property-change
-			      (point) 'face nil cfd-limit))
-		  (and (< (point) cfd-limit)
-		       (c-got-face-at (point) c-literal-faces)))))
-
-       ;; If we matched at the decl start, we have to back up over the
+;;;; NEW STOUGH, 2013-09-21
+       ;; Each time round, the next `while' moves forward over a pseudo match
+       ;; of `c-decl-prefix-or-start-re' which is either inside a literal, or
+       ;; is a ":" not preceded by "public", etc..  `cfd-re-match' and
+       ;; `cfd-re-match-end' get set.
+       (while
+	   (progn
+	     (setq cfd-re-match-end (re-search-forward c-decl-prefix-or-start-re
+						       cfd-limit 'move))
+	     (cond
+	      ((null cfd-re-match-end)
+	       ;; No match.  Finish up and exit the loop.
+	       (setq cfd-re-match cfd-limit)
+	       nil)
+	      ((c-got-face-at
+		(if (setq cfd-re-match (match-end 1))
+		    ;; Matched the end of a token preceding a decl spot.
+		    (progn
+		      (goto-char cfd-re-match)
+		      (1- cfd-re-match))
+		  ;; Matched a token that start a decl spot.
+		  (goto-char (match-beginning 0))
+		  (point))
+		c-literal-faces)
+	       ;; Pseudo match inside a comment or string literal.  Skip out
+	       ;; of comments and string literals.
+	       (while (progn
+			(goto-char (c-next-single-property-change
+				    (point) 'face nil cfd-limit))
+			(and (< (point) cfd-limit)
+			     (c-got-face-at (point) c-literal-faces))))
+	       t)		      ; Continue the loop over pseudo matches.
+	      ((and (match-string 1)
+		    (string= (match-string 1) ":")
+		    (save-excursion
+		      (or (/= (c-backward-token-2 2) 0) ; no search limit.  :-(
+			  (not (looking-at c-decl-start-colon-kwd-re)))))
+	       ;; Found a ":" which isn't part of "public:", etc.
+	       t)
+	      (t nil)))) ;; Found a real match.  Exit the pseudo-match loop.
+;;;; END OF NEW STOUGH
+
+       ;; If our match was at the decl start, we have to back up over the
        ;; preceding syntactic ws to set `cfd-match-pos' and to catch
        ;; any decl spots in the syntactic ws.
        (unless cfd-re-match
 
 ;;; Additional constants for parser-level constructs.
 
+(c-lang-defconst c-decl-start-colon-kwd-re
+  "Regexp matching a keyword that is followed by a colon, where
+  the whole construct can precede a declaration.
+  E.g. \"public:\" in C++."
+  t "\\<\\>"
+  c++ (c-make-keywords-re t (c-lang-const c-protection-kwds)))
+(c-lang-defvar c-decl-start-colon-kwd-re
+  (c-lang-const c-decl-start-colon-kwd-re))
+
 (c-lang-defconst c-decl-prefix-re
   "Regexp matching something that might precede a declaration, cast or
 label, such as the last token of a preceding statement or declaration.
   java "\\([\{\}\(;,<]+\\)"
   ;; Match "<" in C++ to get the first argument in a template arglist.
   ;; In that case there's an additional check in `c-find-decl-spots'
-  ;; that it got open paren syntax.
-  c++ "\\([\{\}\(\);,<]+\\)"
+  ;; that it got open paren syntax.  Match ":" to aid in picking up
+  ;; "public:", etc.  This involves additional checks in
+  ;; `c-find-decl-prefix-search' to prevent a match of identifiers
+  ;; or labels.
+  c++ "\\([\{\}\(\);:,<]+\\)"
   ;; Additionally match the protection directives in Objective-C.
   ;; Note that this doesn't cope with the longer directives, which we
   ;; would have to match from start to end since they don't end with