]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/cc-fonts.el
Handle C++ raw strings.
[gnu-emacs] / lisp / progmodes / cc-fonts.el
index a7097b98c9d29328508cdab7b8136bebacaae3e3..f3f369f5f8c99698b7c895749b059d082dfaee20 100644 (file)
@@ -723,6 +723,10 @@ casts and declarations are fontified.  Used on level 2 and higher."
        (concat ".\\(" c-string-limit-regexp "\\)")
        '((c-font-lock-invalid-string)))
 
+      ;; Fontify C++ raw strings.
+      ,@(when (c-major-mode-is 'c++-mode)
+         '(c-font-lock-raw-strings))
+
       ;; Fontify keyword constants.
       ,@(when (c-lang-const c-constant-kwds)
          (let ((re (c-make-keywords-re nil (c-lang-const c-constant-kwds))))
@@ -914,7 +918,7 @@ casts and declarations are fontified.  Used on level 2 and higher."
   ;;
   ;; Fontify types and references in names containing angle bracket
   ;; 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.
 
@@ -976,11 +980,12 @@ casts and declarations are fontified.  Used on level 2 and higher."
                    (when (and c-opt-identifier-concat-key
                               (not (get-text-property id-start 'face)))
                      (c-forward-syntactic-ws)
-                     (if (looking-at c-opt-identifier-concat-key)
-                         (c-put-font-lock-face id-start id-end
-                                               c-reference-face-name)
-                       (c-put-font-lock-face id-start id-end
-                                             'font-lock-type-face)))))
+                     (cond ((looking-at c-opt-identifier-concat-key)
+                            (c-put-font-lock-face id-start id-end
+                                               c-reference-face-name))
+                           ((eq (char-after) ?\())
+                           (t (c-put-font-lock-face id-start id-end
+                                             'font-lock-type-face))))))
 
                (goto-char pos)))
          (goto-char pos)))))
@@ -1335,6 +1340,32 @@ casts and declarations are fontified.  Used on level 2 and higher."
                (when (> (point) max-type-decl-end)
                  (setq max-type-decl-end (point))))
 
+             ;; Do we have an expression as the second or third clause of
+             ;; a "for" paren expression?
+             (if (save-excursion
+                   (and
+                    (car (cddr decl-or-cast)) ; maybe-expression flag.
+                    (goto-char start-pos)
+                    (c-go-up-list-backward)
+                    (eq (char-after) ?\()
+                    (progn (c-backward-syntactic-ws)
+                           (c-simple-skip-symbol-backward))
+                    (looking-at c-paren-stmt-key)
+                    (progn (goto-char match-pos)
+                           (while (and (eq (char-before) ?\))
+                                       (c-go-list-backward))
+                             (c-backward-syntactic-ws))
+                           (eq (char-before) ?\;))))
+                 ;; We've got an expression in "for" parens.  Remove the
+                 ;; "type" that would spuriously get fontified.
+                 (let ((elt (and (consp c-record-type-identifiers)
+                                 (assq (cadr (cddr decl-or-cast))
+                                       c-record-type-identifiers))))
+                   (when elt
+                     (setq c-record-type-identifiers
+                           (c-delq-from-dotted-list
+                            elt c-record-type-identifiers)))
+                   t)
              ;; Back up to the type to fontify the declarator(s).
              (goto-char (car decl-or-cast))
 
@@ -1360,17 +1391,17 @@ casts and declarations are fontified.  Used on level 2 and higher."
                    (c-backward-syntactic-ws)
                    (unless (bobp)
                      (c-put-char-property (1- (point)) 'c-type
-                                          (if (cdr decl-or-cast)
+                                          (if (cadr decl-or-cast)
                                               'c-decl-type-start
                                             'c-decl-id-start)))))
 
                (c-font-lock-declarators
-                (point-max) decl-list (cdr decl-or-cast)))
+                (point-max) decl-list (cadr decl-or-cast)))
 
              ;; A declaration has been successfully identified, so do all the
              ;; fontification of types and refs that've been recorded.
              (c-fontify-recorded-types-and-refs)
-             nil)
+             nil))
 
             ;; Restore point, since at this point in the code it has been
             ;; left undefined by c-forward-decl-or-cast-1 above.
@@ -1544,6 +1575,43 @@ casts and declarations are fontified.  Used on level 2 and higher."
            (c-forward-syntactic-ws)
            (c-font-lock-declarators limit t in-typedef)))))))
 
+(defun c-font-lock-raw-strings (limit)
+  ;; Fontify C++ raw strings.
+  ;;
+  ;; This function will be called from font-lock for a region bounded by POINT
+  ;; and LIMIT, as though it were to identify a keyword for
+  ;; font-lock-keyword-face.  It always returns NIL to inhibit this and
+  ;; prevent a repeat invocation.  See elisp/lispref page "Search-based
+  ;; Fontification".
+  (while (search-forward-regexp
+         "R\\(\"\\)\\([^ ()\\\n\r\t]\\{,16\\}\\)(" limit t)
+    (when
+       (or (and (eobp)
+                (eq (c-get-char-property (1- (point)) 'face)
+                    'font-lock-warning-face))
+           (eq (c-get-char-property (point) 'face) 'font-lock-string-face)
+           (and (equal (c-get-char-property (match-end 2) 'syntax-table) '(1))
+                (equal (c-get-char-property (match-beginning 1) 'syntax-table)
+                       '(1))))
+      (let ((paren-prop (c-get-char-property (1- (point)) 'syntax-table)))
+       (if paren-prop
+           (progn
+             (c-put-font-lock-face (match-beginning 0) (match-end 0)
+                                   'font-lock-warning-face)
+             (when
+                 (and
+                  (equal paren-prop '(15))
+                  (not (c-search-forward-char-property 'syntax-table '(15) limit)))
+               (goto-char limit)))
+         (c-put-font-lock-face (match-beginning 1) (match-end 2) 'default)
+         (when (search-forward-regexp
+                (concat ")\\(" (regexp-quote (match-string-no-properties 2))
+                        "\\)\"")
+                limit t)
+           (c-put-font-lock-face (match-beginning 1) (point)
+                                 'default))))))
+  nil)
+
 (c-lang-defconst c-simple-decl-matchers
   "Simple font lock matchers for types and declarations.  These are used
 on level 2 only and so aren't combined with `c-complex-decl-matchers'."
@@ -1705,7 +1773,9 @@ on level 2 only and so aren't combined with `c-complex-decl-matchers'."
                                              (looking-at "@[A-Za-z0-9]+")))
                                 (c-forward-keyword-clause 1)
                                 t)
-                              (when (looking-at c-noise-macro-with-parens-name-re)
+                              (when (and c-opt-cpp-prefix
+                                         (looking-at
+                                          c-noise-macro-with-parens-name-re))
                                 (c-forward-noise-clause)
                                 t)))
                          ,(if (c-major-mode-is 'c++-mode)