]> code.delx.au - gnu-emacs/blobdiff - lisp/font-lock.el
(font-lock-keywords): Fix the doc now that regexp-opt-depth is unnecessary.
[gnu-emacs] / lisp / font-lock.el
index b0a29fd7a640683d83ef42d14f4475c6f074599e..91775206f3a07a64c2258e38e95795f639b7ddc2 100644 (file)
@@ -1,8 +1,9 @@
 ;;; font-lock.el --- Electric font lock mode
 
-;; Copyright (C) 1992, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
+;; Copyright (C) 1992, 93, 94, 95, 96, 97, 98, 1999
+;;  Free Software Foundation, Inc.
 
-;; Author: jwz, then rms, then sm <simon@gnu.ai.mit.edu>
+;; Author: jwz, then rms, then sm <simon@gnu.org>
 ;; Maintainer: FSF
 ;; Keywords: languages, faces
 
 ;;
 ;; Efficient regexps for use as MATCHERs for `font-lock-keywords' and
 ;; `font-lock-syntactic-keywords' can be generated via the function
-;; `regexp-opt', and their depth counted via the function `regexp-opt-depth'.
+;; `regexp-opt'.
 
 ;;; Adding patterns for modes that already support Font Lock:
 
 (defgroup font-lock nil
   "Font Lock mode text highlighting package."
   :link '(custom-manual "(emacs)Font Lock")
+  :link '(custom-manual "(elisp)Font Lock Mode")
   :group 'faces)
 
 (defgroup font-lock-highlighting-faces nil
   :link '(custom-manual "(emacs)Support Modes")
   :load 'lazy-lock
   :group 'font-lock)
+
+(defgroup jit-lock nil
+  "Font Lock support mode to fontify just-in-time."
+  :link '(custom-manual "(emacs)Support Modes")
+  :version "21.1"
+  :load 'jit-lock
+  :group 'font-lock)
 \f
 ;; User variables.
 
-(defcustom font-lock-maximum-size (* 250 1024)
+(defcustom font-lock-maximum-size 256000
   "*Maximum size of a buffer for buffer fontification.
 Only buffers less than this can be fontified when Font Lock mode is turned on.
 If nil, means size is irrelevant.
@@ -279,15 +288,15 @@ decoration for buffers in C++ mode, and level 1 decoration otherwise."
                                      (symbol :tag "name"))
                               (radio :tag "Decoration"
                                      (const :tag "default" nil)
-                                     (const :tag "maximum" t) 
+                                     (const :tag "maximum" t)
                                      (integer :tag "level" 1)))))
   :group 'font-lock)
 
-(defcustom font-lock-verbose (* 0 1024)
+(defcustom font-lock-verbose 0
   "*If non-nil, means show status messages for buffer fontification.
 If a number, only buffers greater than this size have fontification messages."
   :type '(choice (const :tag "never" nil)
-                (const :tag "always" t)
+                (other :tag "always" t)
                 (integer :tag "size"))
   :group 'font-lock)
 \f
@@ -295,7 +304,7 @@ If a number, only buffers greater than this size have fontification messages."
 
 (defvar font-lock-keywords nil
   "A list of the keywords to highlight.
-Each element should be of the form:
+Each element should have one of these forms:
 
  MATCHER
  (MATCHER . MATCH)
@@ -310,20 +319,23 @@ FORM is an expression, whose value should be a keyword element, evaluated when
 the keyword is (first) used in a buffer.  This feature can be used to provide a
 keyword that can only be generated when Font Lock mode is actually turned on.
 
-For highlighting single items, typically only MATCH-HIGHLIGHT is required.
+For highlighting single items, for example each instance of the word \"foo\",
+typically only MATCH-HIGHLIGHT is required.
 However, if an item or (typically) items are to be highlighted following the
-instance of another item (the anchor) then MATCH-ANCHORED may be required.
+instance of another item (the anchor), for example each instance of the
+word \"bar\" following the word \"anchor\" then MATCH-ANCHORED may be required.
 
 MATCH-HIGHLIGHT should be of the form:
 
  (MATCH FACENAME OVERRIDE LAXMATCH)
 
-Where MATCHER can be either the regexp to search for, or the function name to
-call to make the search (called with one argument, the limit of the search).
-MATCHER regexps can be generated via the function `regexp-opt'.  MATCH is the
-subexpression of MATCHER to be highlighted.  MATCH can be calculated via the
-function `regexp-opt-depth'.  FACENAME is an expression whose value is the face
-name to use.  Face default attributes can be modified via \\[customize].
+where MATCHER can be either the regexp to search for, or the function name to
+call to make the search (called with one argument, the limit of the search) and
+return non-nil if it succeeds (and set `match-data' appropriately).
+MATCHER regexps can be generated via the function `regexp-opt'.  MATCH is
+the subexpression of MATCHER to be highlighted.  FACENAME is an expression
+whose value is the face name to use.  Face default attributes can be
+modified via \\[customize].
 
 OVERRIDE and LAXMATCH are flags.  If OVERRIDE is t, existing fontification can
 be overwritten.  If `keep', only parts not already fontified are highlighted.
@@ -333,20 +345,25 @@ If LAXMATCH is non-nil, no error is signaled if there is no MATCH in MATCHER.
 
 For example, an element of the form highlights (if not already highlighted):
 
- \"\\\\\\=<foo\\\\\\=>\"               Discrete occurrences of \"foo\" in the value of the
+ \"\\\\\\=<foo\\\\\\=>\"               discrete occurrences of \"foo\" in the value of the
                        variable `font-lock-keyword-face'.
- (\"fu\\\\(bar\\\\)\" . 1)     Substring \"bar\" within all occurrences of \"fubar\" in
+ (\"fu\\\\(bar\\\\)\" . 1)     substring \"bar\" within all occurrences of \"fubar\" in
                        the value of `font-lock-keyword-face'.
  (\"fubar\" . fubar-face)      Occurrences of \"fubar\" in the value of `fubar-face'.
  (\"foo\\\\|bar\" 0 foo-bar-face t)
-                       Occurrences of either \"foo\" or \"bar\" in the value
+                       occurrences of either \"foo\" or \"bar\" in the value
                        of `foo-bar-face', even if already highlighted.
+ (fubar-match 1 fubar-face)
+                       the first subexpression within all occurrences of
+                       whatever the function `fubar-match' finds and matches
+                       in the value of `fubar-face'.
 
 MATCH-ANCHORED should be of the form:
 
  (MATCHER PRE-MATCH-FORM POST-MATCH-FORM MATCH-HIGHLIGHT ...)
 
-Where MATCHER is as for MATCH-HIGHLIGHT with one exception; see below.
+where MATCHER is a regexp to search for or the function name to call to make
+the search, as for MATCH-HIGHLIGHT above, but with one exception; see below.
 PRE-MATCH-FORM and POST-MATCH-FORM are evaluated before the first, and after
 the last, instance MATCH-ANCHORED's MATCHER is used.  Therefore they can be
 used to initialise before, and cleanup after, MATCHER is used.  Typically,
@@ -358,7 +375,7 @@ For example, an element of the form highlights (if not already highlighted):
 
  (\"\\\\\\=<anchor\\\\\\=>\" (0 anchor-face) (\"\\\\\\=<item\\\\\\=>\" nil nil (0 item-face)))
 
Discrete occurrences of \"anchor\" in the value of `anchor-face', and subsequent
discrete occurrences of \"anchor\" in the value of `anchor-face', and subsequent
  discrete occurrences of \"item\" (on the same line) in the value of `item-face'.
  (Here PRE-MATCH-FORM and POST-MATCH-FORM are nil.  Therefore \"item\" is
  initially searched for starting from the end of the match of \"anchor\", and
@@ -372,12 +389,10 @@ PRE-MATCH-FORM is evaluated, that position is used as the limit of the search.
 It is generally a bad idea to return a position greater than the end of the
 line, i.e., cause the MATCHER search to span lines.
 
-Note that the MATCH-ANCHORED feature is experimental; in the future, we may
-replace it with other ways of providing this functionality.
-
-These regular expressions should not match text which spans lines.  While
-\\[font-lock-fontify-buffer] handles multi-line patterns correctly, updating
-when you edit the buffer does not, since it considers text one line at a time.
+These regular expressions can match text which spans lines, although
+it is better to avoid it if possible since updating them while editing
+text is slower, and it is not guaranteed to be always correct when using
+support modes like jit-lock or lazy-lock.
 
 This variable is set by major modes via the variable `font-lock-defaults'.
 Be careful when composing regexps for this list; a poorly written pattern can
@@ -423,7 +438,9 @@ Typical values are `mark-defun' for programming modes or `mark-paragraph' for
 textual modes (i.e., the mode-dependent function is known to put point and mark
 around a text block relevant to that mode).
 
-Other variables include those for buffer-specialised fontification functions,
+Other variables include that for syntactic keyword fontification,
+`font-lock-syntactic-keywords'
+and those for buffer-specialised fontification functions,
 `font-lock-fontify-buffer-function', `font-lock-unfontify-buffer-function',
 `font-lock-fontify-region-function', `font-lock-unfontify-region-function',
 `font-lock-inhibit-thing-lock' and `font-lock-maximum-size'.")
@@ -437,55 +454,36 @@ Other variables include those for buffer-specialised fontification functions,
         '((c-font-lock-keywords c-font-lock-keywords-1
            c-font-lock-keywords-2 c-font-lock-keywords-3)
           nil nil ((?_ . "w")) beginning-of-defun
-          ;; Obsoleted by Emacs 19.35 parse-partial-sexp's COMMENTSTOP.
-          ;(font-lock-comment-start-regexp . "/[*/]")
           (font-lock-mark-block-function . mark-defun)))
        (c++-mode-defaults
-        '((c++-font-lock-keywords c++-font-lock-keywords-1 
+        '((c++-font-lock-keywords c++-font-lock-keywords-1
            c++-font-lock-keywords-2 c++-font-lock-keywords-3)
           nil nil ((?_ . "w")) beginning-of-defun
-          ;; Obsoleted by Emacs 19.35 parse-partial-sexp's COMMENTSTOP.
-          ;(font-lock-comment-start-regexp . "/[*/]")
           (font-lock-mark-block-function . mark-defun)))
        (objc-mode-defaults
         '((objc-font-lock-keywords objc-font-lock-keywords-1
            objc-font-lock-keywords-2 objc-font-lock-keywords-3)
           nil nil ((?_ . "w") (?$ . "w")) nil
-          ;; Obsoleted by Emacs 19.35 parse-partial-sexp's COMMENTSTOP.
-          ;(font-lock-comment-start-regexp . "/[*/]")
           (font-lock-mark-block-function . mark-defun)))
        (java-mode-defaults
         '((java-font-lock-keywords java-font-lock-keywords-1
            java-font-lock-keywords-2 java-font-lock-keywords-3)
-          nil nil ((?_ . "w") (?$ . "w") (?. . "w")) nil
-          ;; Obsoleted by Emacs 19.35 parse-partial-sexp's COMMENTSTOP.
-          ;(font-lock-comment-start-regexp . "/[*/]")
+          nil nil ((?_ . "w") (?$ . "w")) nil
           (font-lock-mark-block-function . mark-defun)))
        (lisp-mode-defaults
         '((lisp-font-lock-keywords
            lisp-font-lock-keywords-1 lisp-font-lock-keywords-2)
           nil nil (("+-*/.<>=!?$%_&~^:" . "w")) beginning-of-defun
-          ;; Obsoleted by Emacs 19.35 parse-partial-sexp's COMMENTSTOP.
-          ;(font-lock-comment-start-regexp . ";")
-          (font-lock-mark-block-function . mark-defun)))
-       (scheme-mode-defaults
-        '((scheme-font-lock-keywords
-           scheme-font-lock-keywords-1 scheme-font-lock-keywords-2)
-          nil t (("+-*/.<>=!?$%_&~^:" . "w")) beginning-of-defun
-          ;; Obsoleted by Emacs 19.35 parse-partial-sexp's COMMENTSTOP.
-          ;(font-lock-comment-start-regexp . ";")
           (font-lock-mark-block-function . mark-defun)))
        ;; For TeX modes we could use `backward-paragraph' for the same reason.
        ;; But we don't, because paragraph breaks are arguably likely enough to
        ;; occur within a genuine syntactic block to make it too risky.
        ;; However, we do specify a MARK-BLOCK function as that cannot result
-       ;; in a mis-fontification even if it might not fontify enough.  --sm.
+       ;; in a mis-fontification even if it might not fontify enough.  sm.
        (tex-mode-defaults
         '((tex-font-lock-keywords
            tex-font-lock-keywords-1 tex-font-lock-keywords-2)
           nil nil ((?$ . "\"")) nil
-          ;; Obsoleted by Emacs 19.35 parse-partial-sexp's COMMENTSTOP.
-          ;(font-lock-comment-start-regexp . "%")
           (font-lock-mark-block-function . mark-paragraph)))
        )
     (list
@@ -494,13 +492,10 @@ Other variables include those for buffer-specialised fontification functions,
      (cons 'objc-mode                  objc-mode-defaults)
      (cons 'java-mode                  java-mode-defaults)
      (cons 'emacs-lisp-mode            lisp-mode-defaults)
-     (cons 'inferior-scheme-mode       scheme-mode-defaults)
      (cons 'latex-mode                 tex-mode-defaults)
      (cons 'lisp-mode                  lisp-mode-defaults)
      (cons 'lisp-interaction-mode      lisp-mode-defaults)
      (cons 'plain-tex-mode             tex-mode-defaults)
-     (cons 'scheme-mode                        scheme-mode-defaults)
-     (cons 'scheme-interaction-mode    scheme-mode-defaults)
      (cons 'slitex-mode                        tex-mode-defaults)
      (cons 'tex-mode                   tex-mode-defaults)))
   "Alist of fall-back Font Lock defaults for major modes.
@@ -513,7 +508,13 @@ settings.  See the variable `font-lock-defaults', which takes precedence.")
 
 (defvar font-lock-keywords-alist nil
   "*Alist of `font-lock-keywords' local to a `major-mode'.
-This is normally set via `font-lock-add-keywords'.")
+This is normally set via `font-lock-add-keywords' and
+`font-lock-remove-keywords'.")
+
+(defvar font-lock-removed-keywords-alist nil
+  "*Alist of `font-lock-keywords' removed from `major-mode'.
+This is normally set via `font-lock-add-keywords' and
+`font-lock-remove-keywords'.")
 
 (defvar font-lock-keywords-only nil
   "*Non-nil means Font Lock should not fontify comments or strings.
@@ -535,6 +536,27 @@ where SYNTAX can be of the form (SYNTAX-CODE . MATCHING-CHAR), the name of a
 syntax table, or an expression whose value is such a form or a syntax table.
 OVERRIDE cannot be `prepend' or `append'.
 
+For example, an element of the form highlights syntactically:
+
+ (\"\\\\$\\\\(#\\\\)\" 1 (1 . nil))
+
+ a hash character when following a dollar character, with a SYNTAX-CODE of
+ 1 (meaning punctuation syntax).  Assuming that the buffer syntax table does
+ specify hash characters to have comment start syntax, the element will only
+ highlight hash characters that do not follow dollar characters as comments
+ syntactically.
+
+ (\"\\\\('\\\\).\\\\('\\\\)\"
+  (1 (7 . ?'))
+  (2 (7 . ?')))
+
+ both single quotes which surround a single character, with a SYNTAX-CODE of
+ 7 (meaning string quote syntax) and a MATCHING-CHAR of a single quote (meaning
+ a single quote matches a single quote).  Assuming that the buffer syntax table
+ does not specify single quotes to have quote syntax, the element will only
+ highlight single quotes of the form 'c' as strings syntactically.
+ Other forms, such as foo'bar or 'fubar', will not be highlighted as strings.
+
 This is normally set via `font-lock-defaults'.")
 
 (defvar font-lock-syntax-table nil
@@ -557,14 +579,6 @@ When called with no args it should leave point at the beginning of any
 enclosing textual block and mark at the end.
 This is normally set via `font-lock-defaults'.")
 
-;; Obsoleted by Emacs 19.35 parse-partial-sexp's COMMENTSTOP.
-;(defvar font-lock-comment-start-regexp nil
-;  "*Regexp to match the start of a comment.
-;This need not discriminate between genuine comments and quoted comment
-;characters or comment characters within strings.
-;If nil, `comment-start-skip' is used instead; see that variable for more info.
-;This is normally set via `font-lock-defaults'.")
-
 (defvar font-lock-fontify-buffer-function 'font-lock-default-fontify-buffer
   "Function to use for fontifying the buffer.
 This is normally set via `font-lock-defaults'.")
@@ -587,8 +601,15 @@ This is normally set via `font-lock-defaults'.")
 
 (defvar font-lock-inhibit-thing-lock nil
   "List of Font Lock mode related modes that should not be turned on.
-Currently, valid mode names as `fast-lock-mode' and `lazy-lock-mode'.
-This is normally set via `font-lock-defaults'.")
+Currently, valid mode names are `fast-lock-mode', `jit-lock-mode' and
+`lazy-lock-mode'.  This is normally set via `font-lock-defaults'.")
+
+(defvar font-lock-multiline 'undecided
+  "Whether font-lock should cater to multiline keywords.
+If nil, don't try to handle multiline patterns.
+If t, always handle multiline patterns.
+If `undecided', don't try to handle multiline patterns until you see one.
+Major/minor modes can set this variable if they know which option applies.")
 
 (defvar font-lock-mode nil)            ; Whether we are turned on/modeline.
 (defvar font-lock-fontified nil)       ; Whether we have fontified the buffer.
@@ -597,39 +618,6 @@ This is normally set via `font-lock-defaults'.")
 (defvar font-lock-mode-hook nil
   "Function or functions to run on entry to Font Lock mode.")
 \f
-;; Originally these variable values were face names such as `bold' etc.
-;; Now we create our own faces, but we keep these variables for compatibility
-;; and they give users another mechanism for changing face appearance.
-;; We now allow a FACENAME in `font-lock-keywords' to be any expression that
-;; returns a face.  So the easiest thing is to continue using these variables,
-;; rather than sometimes evaling FACENAME and sometimes not.  sm.
-(defvar font-lock-comment-face         'font-lock-comment-face
-  "Face name to use for comments.")
-
-(defvar font-lock-string-face          'font-lock-string-face
-  "Face name to use for strings.")
-
-(defvar font-lock-keyword-face         'font-lock-keyword-face
-  "Face name to use for keywords.")
-
-(defvar font-lock-builtin-face         'font-lock-builtin-face
-  "Face name to use for builtins.")
-
-(defvar font-lock-function-name-face   'font-lock-function-name-face
-  "Face name to use for function names.")
-
-(defvar font-lock-variable-name-face   'font-lock-variable-name-face
-  "Face name to use for variable names.")
-
-(defvar font-lock-type-face            'font-lock-type-face
-  "Face name to use for type names.")
-
-(defvar font-lock-reference-face       'font-lock-reference-face
-  "Face name to use for reference names.")
-
-(defvar font-lock-warning-face         'font-lock-warning-face
-  "Face name to use for things that should stand out.")
-\f
 ;; Font Lock mode.
 
 (eval-when-compile
@@ -649,7 +637,14 @@ This is normally set via `font-lock-defaults'.")
         (,@ body)
         (when (and (not modified) (buffer-modified-p))
           (set-buffer-modified-p nil)))))
-  (put 'save-buffer-state 'lisp-indent-function 1))
+  (put 'save-buffer-state 'lisp-indent-function 1)
+  (def-edebug-spec save-buffer-state let)
+  ;;
+  ;; Shut up the byte compiler.
+  (defvar global-font-lock-mode)       ; Now a defcustom.
+  (defvar font-lock-face-attributes)   ; Obsolete but respected if set.
+  (defvar font-lock-string-face)       ; Used in syntactic fontification.
+  (defvar font-lock-comment-face))
 
 ;;;###autoload
 (defun font-lock-mode (&optional arg)
@@ -737,13 +732,13 @@ buffer local value for `font-lock-defaults', via its mode hook."
 (defun turn-on-font-lock ()
   "Turn on Font Lock mode conditionally.
 Turn on only if the terminal can display it."
-  (when (and (not font-lock-mode) window-system)
+  (unless font-lock-mode
     (font-lock-mode)))
 
 ;;;###autoload
-(defun font-lock-add-keywords (major-mode keywords &optional append)
-  "Add highlighting KEYWORDS for MAJOR-MODE.
-MAJOR-MODE should be a symbol, the major mode command name, such as `c-mode'
+(defun font-lock-add-keywords (mode keywords &optional append)
+  "Add highlighting KEYWORDS for MODE.
+MODE should be a symbol, the major mode command name, such as `c-mode'
 or nil.  If nil, highlighting keywords are added for the current buffer.
 KEYWORDS should be a list; see the variable `font-lock-keywords'.
 By default they are added at the beginning of the current highlighting list.
@@ -763,23 +758,126 @@ comments, and to fontify `and', `or' and `not' words as keywords.
 Note that some modes have specialised support for additional patterns, e.g.,
 see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types',
 `objc-font-lock-extra-types' and `java-font-lock-extra-types'."
-  (cond (major-mode
-        ;; If MAJOR-MODE is non-nil, add the KEYWORDS and APPEND spec to
+  (cond (mode
+        ;; If MODE is non-nil, add the KEYWORDS and APPEND spec to
         ;; `font-lock-keywords-alist' so `font-lock-set-defaults' uses them.
         (let ((spec (cons keywords append)) cell)
-          (if (setq cell (assq major-mode font-lock-keywords-alist))
-              (setcdr cell (append (cdr cell) (list spec)))
-            (push (list major-mode spec) font-lock-keywords-alist))))
-       (font-lock-mode
-        ;; Otherwise if Font Lock mode is on, set or add the keywords now.
-        (if (eq append 'set)
-            (setq font-lock-keywords keywords)
+          (if (setq cell (assq mode font-lock-keywords-alist))
+              (if (eq append 'set)
+                  (setcdr cell (list spec))
+                (setcdr cell (append (cdr cell) (list spec))))
+            (push (list mode spec) font-lock-keywords-alist)))
+        ;; Make sure that `font-lock-removed-keywords-alist' does not
+        ;; contain the new keywords.
+        (font-lock-update-removed-keyword-alist mode keywords append))
+       (t
+        ;; Otherwise set or add the keywords now.
+        (font-lock-set-defaults)
+        (if (eq append 'set)
+            (setq font-lock-keywords keywords)
+          (font-lock-remove-keywords nil keywords) ;to avoid duplicates
           (let ((old (if (eq (car-safe font-lock-keywords) t)
                          (cdr font-lock-keywords)
                        font-lock-keywords)))
             (setq font-lock-keywords (if append
                                          (append old keywords)
                                        (append keywords old))))))))
+
+(defun font-lock-update-removed-keyword-alist (mode keywords append)
+  ;; Update `font-lock-removed-keywords-alist' when adding new
+  ;; KEYWORDS to MODE.
+  ;;
+  ;; When font-lock is enabled first all keywords in the list
+  ;; `font-lock-keywords-alist' are added, then all keywords in the
+  ;; list `font-lock-removed-keywords-alist' are removed.  If a
+  ;; keyword was once added, removed, and then added again it must be
+  ;; removed from the removed-keywords list.  Otherwise the second add
+  ;; will not take effect.
+  (let ((cell (assq mode font-lock-removed-keywords-alist)))
+    (if cell
+       (if (eq append 'set)
+           ;; A new set of keywords is defined.  Forget all about
+           ;; our old keywords that should be removed.
+           (setq font-lock-removed-keywords-alist
+                 (delq cell font-lock-removed-keywords-alist))
+         ;; Delete all previously removed keywords.
+         (dolist (kword keywords)
+           (setcdr cell (delete kword (cdr cell))))
+         ;; Delete the mode cell if empty.
+         (if (null (cdr cell))
+             (setq font-lock-removed-keywords-alist
+                   (delq cell font-lock-removed-keywords-alist)))))))
+
+;; Written by Anders Lindgren <andersl@andersl.com>.
+;;
+;; Case study:
+;; (I)  The keywords are removed from a major mode.
+;;      In this case the keyword could be local (i.e. added earlier by
+;;      `font-lock-add-keywords'), global, or both.
+;;
+;;      (a) In the local case we remove the keywords from the variable
+;;          `font-lock-keywords-alist'.
+;;
+;;      (b) The actual global keywords are not known at this time.
+;;          All keywords are added to `font-lock-removed-keywords-alist',
+;;          when font-lock is enabled those keywords are removed.
+;;
+;;      Note that added keywords are taken out of the list of removed
+;;      keywords.  This ensure correct operation when the same keyword
+;;      is added and removed several times.
+;;
+;; (II) The keywords are removed from the current buffer.
+;;;###autoload
+(defun font-lock-remove-keywords (mode keywords)
+  "Remove highlighting KEYWORDS for MODE.
+
+MODE should be a symbol, the major mode command name, such as `c-mode'
+or nil.  If nil, highlighting keywords are removed for the current buffer."
+  (cond (mode
+        ;; Remove one keyword at the time.
+        (dolist (keyword keywords)
+          (let ((top-cell (assq mode font-lock-keywords-alist)))
+            ;; If MODE is non-nil, remove the KEYWORD from
+            ;; `font-lock-keywords-alist'.
+            (when top-cell
+              (dolist (keyword-list-append-pair (cdr top-cell))
+                ;; `keywords-list-append-pair' is a cons with a list of
+                ;; keywords in the car top-cell and the original append
+                ;; argument in the cdr top-cell.
+                (setcar keyword-list-append-pair
+                        (delete keyword (car keyword-list-append-pair))))
+              ;; Remove keyword list/append pair when the keyword list
+              ;; is empty and append doesn't specify `set'.  (If it
+              ;; should be deleted then previously deleted keywords
+              ;; would appear again.)
+              (let ((cell top-cell))
+                (while (cdr cell)
+                  (if (and (null (car (car (cdr cell))))
+                           (not (eq (cdr (car (cdr cell))) 'set)))
+                      (setcdr cell (cdr (cdr cell)))
+                    (setq cell (cdr cell)))))
+              ;; Final cleanup, remove major mode cell if last keyword
+              ;; was deleted.
+              (if (null (cdr top-cell))
+                  (setq font-lock-keywords-alist
+                        (delq top-cell font-lock-keywords-alist))))
+            ;; Remember the keyword in case it is not local.
+            (let ((cell (assq mode font-lock-removed-keywords-alist)))
+              (if cell
+                  (unless (member keyword (cdr cell))
+                    (nconc cell (list keyword)))
+                (push (cons mode (list keyword))
+                      font-lock-removed-keywords-alist))))))
+       (t
+        ;; Otherwise remove it immediately.
+        (font-lock-set-defaults)
+        (setq font-lock-keywords (copy-sequence font-lock-keywords))
+        (dolist (keyword keywords)
+          (setq font-lock-keywords
+                (delete keyword
+                        ;; The keywords might be compiled.
+                        (delete (font-lock-compile-keyword keyword)
+                                font-lock-keywords)))))))
 \f
 ;;; Global Font Lock mode.
 
@@ -836,8 +934,6 @@ see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types',
 
 (defvar font-lock-buffers nil)         ; For remembering buffers.
 
-(defvar global-font-lock-mode)         ;Prevent warnings in defun below.
-
 ;;;###autoload
 (defun global-font-lock-mode (&optional arg message)
   "Toggle Global Font Lock mode.
@@ -863,26 +959,29 @@ turned on in a buffer if its major mode is one of `font-lock-global-modes'."
                                   (font-lock-mode)))))
                   (buffer-list))))
     (when message
-      (message "Global Font Lock mode %s" (if on-p "enabled" "disabled")))
+      (message "Global Font Lock mode %s." (if on-p "enabled" "disabled")))
     (setq global-font-lock-mode on-p)))
 
-;; Naughty hack.  This variable was originally a `defvar' to keep track of
+;; This variable was originally a `defvar' to keep track of
 ;; whether Global Font Lock mode was turned on or not.  As a `defcustom' with
 ;; special `:set' and `:require' forms, we can provide custom mode control.
+;;;###autoload
 (defcustom global-font-lock-mode nil
   "Toggle Global Font Lock mode.
 When Global Font Lock mode is enabled, Font Lock mode is automagically
 turned on in a buffer if its major mode is one of `font-lock-global-modes'.
-You must modify via \\[customize] for this variable to have an effect."
+Setting this variable directly does not take effect;
+use either \\[customize] or the function `global-font-lock-mode'."
   :set (lambda (symbol value)
         (global-font-lock-mode (or value 0)))
+  :initialize 'custom-initialize-default
   :type 'boolean
   :group 'font-lock
   :require 'font-lock)
 
 (defcustom font-lock-global-modes t
   "*Modes for which Font Lock mode is automagically turned on.
-Global Font Lock mode is controlled by the `global-font-lock-mode' command.
+Global Font Lock mode is controlled by the command `global-font-lock-mode'.
 If nil, means no modes have Font Lock mode automatically turned on.
 If t, all modes that support Font Lock mode have it automatically turned on.
 If a list, it should be a list of `major-mode' symbol names for which Font Lock
@@ -941,11 +1040,12 @@ means that Font Lock mode is turned on for buffers in C and C++ modes only."
 ;; `font-lock-after-fontify-buffer' and/or `font-lock-after-unfontify-buffer'
 ;; themselves.
 
-(defcustom font-lock-support-mode nil
+(defcustom font-lock-support-mode 'jit-lock-mode
   "*Support mode for Font Lock mode.
 Support modes speed up Font Lock mode by being choosy about when fontification
-occurs.  Known support modes are Fast Lock mode (symbol `fast-lock-mode') and
-Lazy Lock mode (symbol `lazy-lock-mode').  See those modes for more info.
+occurs.  Known support modes are Fast Lock mode (symbol `fast-lock-mode'),
+Lazy Lock mode (symbol `lazy-lock-mode'), and Just-in-time Lock mode (symbol
+`jit-lock-mode'.  See those modes for more info.
 If nil, means support for Font Lock mode is never performed.
 If a symbol, use that support mode.
 If a list, each element should be of the form (MAJOR-MODE . SUPPORT-MODE),
@@ -958,43 +1058,55 @@ The value of this variable is used when Font Lock mode is turned on."
   :type '(choice (const :tag "none" nil)
                 (const :tag "fast lock" fast-lock-mode)
                 (const :tag "lazy lock" lazy-lock-mode)
+                (const :tag "jit lock" jit-lock-mode)
                 (repeat :menu-tag "mode specific" :tag "mode specific"
                         :value ((t . lazy-lock-mode))
                         (cons :tag "Instance"
                               (radio :tag "Mode"
                                      (const :tag "all" t)
                                      (symbol :tag "name"))
-                              (radio :tag "Decoration"
+                              (radio :tag "Support"
+                                     (const :tag "none" nil)
                                      (const :tag "fast lock" fast-lock-mode)
-                                     (const :tag "lazy lock" lazy-lock-mode)))
+                                     (const :tag "lazy lock" lazy-lock-mode)
+                                     (const :tag "JIT lock" jit-lock-mode)))
                         ))
   :group 'font-lock)
 
 (defvar fast-lock-mode nil)
 (defvar lazy-lock-mode nil)
+(defvar jit-lock-mode nil)
 
 (defun font-lock-turn-on-thing-lock ()
   (let ((thing-mode (font-lock-value-in-major-mode font-lock-support-mode)))
     (cond ((eq thing-mode 'fast-lock-mode)
           (fast-lock-mode t))
          ((eq thing-mode 'lazy-lock-mode)
-          (lazy-lock-mode t)))))
+          (lazy-lock-mode t))
+         ((eq thing-mode 'jit-lock-mode)
+          (jit-lock-mode t)))))
 
 (defun font-lock-turn-off-thing-lock ()
   (cond (fast-lock-mode
         (fast-lock-mode nil))
+       (jit-lock-mode
+        (jit-lock-mode nil))
        (lazy-lock-mode
         (lazy-lock-mode nil))))
 
 (defun font-lock-after-fontify-buffer ()
   (cond (fast-lock-mode
         (fast-lock-after-fontify-buffer))
+       (jit-lock-mode
+        (jit-lock-after-fontify-buffer))
        (lazy-lock-mode
         (lazy-lock-after-fontify-buffer))))
 
 (defun font-lock-after-unfontify-buffer ()
   (cond (fast-lock-mode
         (fast-lock-after-unfontify-buffer))
+       (jit-lock-mode
+        (jit-lock-after-unfontify-buffer))
        (lazy-lock-mode
         (lazy-lock-after-unfontify-buffer))))
 
@@ -1043,7 +1155,7 @@ The value of this variable is used when Font Lock mode is turned on."
 
 ;;;###autoload
 (defun font-lock-fontify-buffer ()
-  "Fontify the current buffer the way `font-lock-mode' would."
+  "Fontify the current buffer the way the function `font-lock-mode' would."
   (interactive)
   (let ((font-lock-verbose (or font-lock-verbose (interactive-p))))
     (funcall font-lock-fontify-buffer-function)))
@@ -1061,27 +1173,26 @@ The value of this variable is used when Font Lock mode is turned on."
   (let ((verbose (if (numberp font-lock-verbose)
                     (> (buffer-size) font-lock-verbose)
                   font-lock-verbose)))
-    (when verbose
-      (message "Fontifying %s..." (buffer-name)))
-    ;; Make sure we have the right `font-lock-keywords' etc.
-    (unless font-lock-mode
-      (font-lock-set-defaults))
-    ;; Make sure we fontify etc. in the whole buffer.
-    (save-restriction
-      (widen)
-      (condition-case nil
-         (save-excursion
-           (save-match-data
-             (font-lock-fontify-region (point-min) (point-max) verbose)
-             (font-lock-after-fontify-buffer)
-             (setq font-lock-fontified t)))
-       ;; We don't restore the old fontification, so it's best to unfontify.
-       (quit (font-lock-unfontify-buffer))))
-    ;; Make sure we undo `font-lock-keywords' etc.
-    (unless font-lock-mode
-      (font-lock-unset-defaults))
-    (if verbose (message "Fontifying %s...%s" (buffer-name)
-                        (if font-lock-fontified "done" "quit")))))
+    (with-temp-message
+       (when verbose
+         (format "Fontifying %s..." (buffer-name)))
+      ;; Make sure we have the right `font-lock-keywords' etc.
+      (unless font-lock-mode
+       (font-lock-set-defaults))
+      ;; Make sure we fontify etc. in the whole buffer.
+      (save-restriction
+       (widen)
+       (condition-case nil
+           (save-excursion
+             (save-match-data
+               (font-lock-fontify-region (point-min) (point-max) verbose)
+               (font-lock-after-fontify-buffer)
+               (setq font-lock-fontified t)))
+         ;; We don't restore the old fontification, so it's best to unfontify.
+         (quit (font-lock-unfontify-buffer))))
+      ;; Make sure we undo `font-lock-keywords' etc.
+      (unless font-lock-mode
+       (font-lock-unset-defaults)))))
 
 (defun font-lock-default-unfontify-buffer ()
   ;; Make sure we unfontify etc. in the whole buffer.
@@ -1101,6 +1212,23 @@ The value of this variable is used when Font Lock mode is turned on."
          ;; Use the fontification syntax table, if any.
          (when font-lock-syntax-table
            (set-syntax-table font-lock-syntax-table))
+         ;; check to see if we should expand the beg/end area for
+         ;; proper multiline matches
+         (setq beg (if (get-text-property beg 'font-lock-multiline)
+                       ;; if the text-property is non-nil, (1+ beg)
+                       ;; is valid.  We need to use (1+ beg) for the
+                       ;; case where (get-text-property (1- beg)) is nil
+                       ;; in which case we want to keep BEG but
+                       ;; previous-single-property-change will return
+                       ;; the previous change (if any) rather than
+                       ;; the one at BEG.
+                       (or (previous-single-property-change
+                            (1+ beg) 'font-lock-multiline)
+                           (point-min))
+                     beg))
+         (setq end (or (text-property-any end (point-max)
+                                          'font-lock-multiline nil)
+                       (point-max)))
          ;; Now do the fontification.
          (font-lock-unfontify-region beg end)
          (when font-lock-syntactic-keywords
@@ -1114,14 +1242,17 @@ The value of this variable is used when Font Lock mode is turned on."
 ;; The following must be rethought, since keywords can override fontification.
 ;      ;; Now scan for keywords, but not if we are inside a comment now.
 ;      (or (and (not font-lock-keywords-only)
-;             (let ((state (parse-partial-sexp beg end nil nil 
+;             (let ((state (parse-partial-sexp beg end nil nil
 ;                                              font-lock-cache-state)))
 ;               (or (nth 4 state) (nth 7 state))))
 ;        (font-lock-fontify-keywords-region beg end))
 
 (defun font-lock-default-unfontify-region (beg end)
   (save-buffer-state nil
-    (remove-text-properties beg end '(face nil syntax-table nil))))
+    (remove-text-properties beg end
+                           (if font-lock-syntactic-keywords
+                               '(face nil syntax-table nil font-lock-multiline nil)
+                             '(face nil font-lock-multiline nil)))))
 
 ;; Called when any modification is made to buffer text.
 (defun font-lock-after-change-function (beg end old-len)
@@ -1260,7 +1391,7 @@ see `font-lock-syntactic-keywords'."
         (start (match-beginning match)) (end (match-end match))
         (value (nth 1 highlight))
         (override (nth 2 highlight)))
-    (unless (numberp (car value))
+    (unless (numberp (car-safe value))
       (setq value (eval value)))
     (cond ((not start)
           ;; No match but we might not signal an error.
@@ -1287,7 +1418,7 @@ LIMIT can be modified by the value of its PRE-MATCH-FORM."
     ;; Set LIMIT to value of PRE-MATCH-FORM or the end of line.
     (if (and (numberp pre-match-value) (> pre-match-value (point)))
        (setq limit pre-match-value)
-      (save-excursion (end-of-line) (setq limit (point))))
+      (setq limit (line-end-position)))
     (save-match-data
       ;; Find an occurrence of `matcher' before `limit'.
       (while (if (stringp matcher)
@@ -1377,8 +1508,8 @@ START should be at the beginning of a line."
     (when (or (nth 3 state) (nth 4 state))
       (setq string (nth 3 state) beg (point))
       (setq state (parse-partial-sexp (point) end nil nil state 'syntax-table))
-      (put-text-property beg (point) 'face 
-                        (if string 
+      (put-text-property beg (point) 'face
+                        (if string
                             font-lock-string-face
                           font-lock-comment-face)))
     ;;
@@ -1390,8 +1521,8 @@ START should be at the beginning of a line."
                  (or (nth 3 state) (nth 4 state))))
       (setq string (nth 3 state) beg (nth 8 state))
       (setq state (parse-partial-sexp (point) end nil nil state 'syntax-table))
-      (put-text-property beg (point) 'face 
-                        (if string 
+      (put-text-property beg (point) 'face
+                        (if string
                             font-lock-string-face
                           font-lock-comment-face)))))
 
@@ -1431,17 +1562,26 @@ HIGHLIGHT should be of the form MATCH-HIGHLIGHT, see `font-lock-keywords'."
 KEYWORDS should be of the form MATCH-ANCHORED, see `font-lock-keywords',
 LIMIT can be modified by the value of its PRE-MATCH-FORM."
   (let ((matcher (nth 0 keywords)) (lowdarks (nthcdr 3 keywords)) highlights
+       (lead-start (match-beginning 0))
        ;; Evaluate PRE-MATCH-FORM.
        (pre-match-value (eval (nth 1 keywords))))
     ;; Set LIMIT to value of PRE-MATCH-FORM or the end of line.
-    (if (and (numberp pre-match-value) (> pre-match-value (point)))
-       (setq limit pre-match-value)
-      (save-excursion (end-of-line) (setq limit (point))))
+    (if (not (and (numberp pre-match-value) (> pre-match-value (point))))
+       (setq limit (line-end-position))
+      (setq limit pre-match-value)
+      (when (and font-lock-multiline
+                (funcall (if (eq font-lock-multiline t) '>= '>)
+                         pre-match-value
+                         (save-excursion (forward-line 1) (point))))
+       ;; this is a multiline anchored match
+       (setq font-lock-multiline t)
+       (put-text-property (point) limit 'font-lock-multiline t)))
     (save-match-data
       ;; Find an occurrence of `matcher' before `limit'.
-      (while (if (stringp matcher)
-                (re-search-forward matcher limit t)
-              (funcall matcher limit))
+      (while (and (< (point) limit)
+                 (if (stringp matcher)
+                     (re-search-forward matcher limit t)
+                   (funcall matcher limit)))
        ;; Apply each highlight to this instance of `matcher'.
        (setq highlights lowdarks)
        (while highlights
@@ -1468,9 +1608,20 @@ START should be at the beginning of a line."
       ;; Find an occurrence of `matcher' from `start' to `end'.
       (setq keyword (car keywords) matcher (car keyword))
       (goto-char start)
-      (while (if (stringp matcher)
-                (re-search-forward matcher end t)
-              (funcall matcher end))
+      (while (and (< (point) end)
+                 (if (stringp matcher)
+                     (re-search-forward matcher end t)
+                   (funcall matcher end)))
+       (when (and font-lock-multiline
+                  (match-beginning 0)
+                  (funcall (if (eq font-lock-multiline t) '>= '>)
+                           (point)
+                           (save-excursion (goto-char (match-beginning 0))
+                                           (forward-line 1) (point))))
+         ;; this is a multiline regexp match
+         (setq font-lock-multiline t)
+         (put-text-property (match-beginning 0) (point)
+                            'font-lock-multiline t))
        ;; Apply each highlight to this instance of `matcher', which may be
        ;; specific highlights or more keywords anchored to `matcher'.
        (setq highlights (cdr keyword))
@@ -1486,8 +1637,9 @@ START should be at the beginning of a line."
 ;; Various functions.
 
 (defun font-lock-compile-keywords (keywords)
-  ;; Compile KEYWORDS into the form (t KEYWORD ...) where KEYWORD is of the
-  ;; form (MATCHER HIGHLIGHT ...) as shown in `font-lock-keywords' doc string.
+  "Compile KEYWORDS into the form (t KEYWORD ...).
+Here KEYWORD is of the form (MATCHER HIGHLIGHT ...) as shown in the
+`font-lock-keywords' doc string."
   (if (eq (car-safe keywords) t)
       keywords
     (cons t (mapcar 'font-lock-compile-keyword keywords))))
@@ -1512,7 +1664,7 @@ START should be at the beginning of a line."
         keyword)))
 
 (defun font-lock-eval-keywords (keywords)
-  ;; Evalulate KEYWORDS if a function (funcall) or variable (eval) name.
+  "Evalulate KEYWORDS if a function (funcall) or variable (eval) name."
   (if (listp keywords)
       keywords
     (font-lock-eval-keywords (if (fboundp keywords)
@@ -1520,15 +1672,16 @@ START should be at the beginning of a line."
                               (eval keywords)))))
 
 (defun font-lock-value-in-major-mode (alist)
-  ;; Return value in ALIST for `major-mode', or ALIST if it is not an alist.
-  ;; Structure is ((MAJOR-MODE . VALUE) ...) where MAJOR-MODE may be t.
+  "Return value in ALIST for `major-mode', or ALIST if it is not an alist.
+Structure is ((MAJOR-MODE . VALUE) ...) where MAJOR-MODE may be t."
   (if (consp alist)
       (cdr (or (assq major-mode alist) (assq t alist)))
     alist))
 
 (defun font-lock-choose-keywords (keywords level)
-  ;; Return LEVELth element of KEYWORDS.  A LEVEL of nil is equal to a
-  ;; LEVEL of 0, a LEVEL of t is equal to (1- (length KEYWORDS)).
+  "Return LEVELth element of KEYWORDS.
+A LEVEL of nil is equal to a LEVEL of 0, a LEVEL of t is equal to
+\(1- (length KEYWORDS))."
   (cond ((symbolp keywords)
         keywords)
        ((numberp level)
@@ -1544,19 +1697,21 @@ START should be at the beginning of a line."
   "Set fontification defaults appropriately for this mode.
 Sets various variables using `font-lock-defaults' (or, if nil, using
 `font-lock-defaults-alist') and `font-lock-maximum-decoration'."
-  ;; Set fontification defaults.
-  (make-local-variable 'font-lock-fontified)
-  ;; Set iff not previously set.
+  ;; Set fontification defaults iff not previously set.
   (unless font-lock-set-defaults
     (set (make-local-variable 'font-lock-set-defaults)         t)
     (set (make-local-variable 'font-lock-cache-state)          nil)
     (set (make-local-variable 'font-lock-cache-position)       (make-marker))
+    (make-local-variable 'font-lock-fontified)
+    (make-local-variable 'font-lock-multiline)
     (let* ((defaults (or font-lock-defaults
                         (cdr (assq major-mode font-lock-defaults-alist))))
           (keywords
            (font-lock-choose-keywords (nth 0 defaults)
             (font-lock-value-in-major-mode font-lock-maximum-decoration)))
-          (local (cdr (assq major-mode font-lock-keywords-alist))))
+          (local (cdr (assq major-mode font-lock-keywords-alist)))
+          (removed-keywords
+           (cdr-safe (assq major-mode font-lock-removed-keywords-alist))))
       ;; Regexp fontification?
       (set (make-local-variable 'font-lock-keywords)
           (font-lock-compile-keywords (font-lock-eval-keywords keywords)))
@@ -1564,6 +1719,8 @@ Sets various variables using `font-lock-defaults' (or, if nil, using
       (while local
        (font-lock-add-keywords nil (car (car local)) (cdr (car local)))
        (setq local (cdr local)))
+      (when removed-keywords
+       (font-lock-remove-keywords nil removed-keywords))
       ;; Syntactic fontification?
       (when (nth 1 defaults)
        (set (make-local-variable 'font-lock-keywords-only) t))
@@ -1582,8 +1739,7 @@ Sets various variables using `font-lock-defaults' (or, if nil, using
                           (mapcar 'identity (car (car slist)))))
                  (syntax (cdr (car slist))))
              (while chars
-               (modify-syntax-entry (car chars) syntax
-                                    font-lock-syntax-table)
+               (modify-syntax-entry (car chars) syntax font-lock-syntax-table)
                (setq chars (cdr chars)))
              (setq slist (cdr slist))))))
       ;; Syntax function for syntactic fontification?
@@ -1600,7 +1756,7 @@ Sets various variables using `font-lock-defaults' (or, if nil, using
            (setq alist (cdr alist))))))))
 
 (defun font-lock-unset-defaults ()
-  "Unset fontification defaults.  See `font-lock-set-defaults'."
+  "Unset fontification defaults.  See function `font-lock-set-defaults'."
   (setq font-lock-set-defaults                 nil
        font-lock-keywords                      nil
        font-lock-keywords-only                 nil
@@ -1616,7 +1772,41 @@ Sets various variables using `font-lock-defaults' (or, if nil, using
 \f
 ;;; Colour etc. support.
 
-(defvar font-lock-face-attributes)     ;Avoid compiler warnings below.
+;; Originally these variable values were face names such as `bold' etc.
+;; Now we create our own faces, but we keep these variables for compatibility
+;; and they give users another mechanism for changing face appearance.
+;; We now allow a FACENAME in `font-lock-keywords' to be any expression that
+;; returns a face.  So the easiest thing is to continue using these variables,
+;; rather than sometimes evaling FACENAME and sometimes not.  sm.
+(defvar font-lock-comment-face         'font-lock-comment-face
+  "Face name to use for comments.")
+
+(defvar font-lock-string-face          'font-lock-string-face
+  "Face name to use for strings.")
+
+(defvar font-lock-keyword-face         'font-lock-keyword-face
+  "Face name to use for keywords.")
+
+(defvar font-lock-builtin-face         'font-lock-builtin-face
+  "Face name to use for builtins.")
+
+(defvar font-lock-function-name-face   'font-lock-function-name-face
+  "Face name to use for function names.")
+
+(defvar font-lock-variable-name-face   'font-lock-variable-name-face
+  "Face name to use for variable names.")
+
+(defvar font-lock-type-face            'font-lock-type-face
+  "Face name to use for type and class names.")
+
+(defvar font-lock-constant-face                'font-lock-constant-face
+  "Face name to use for constant and label names.")
+
+(defvar font-lock-warning-face         'font-lock-warning-face
+  "Face name to use for things that should stand out.")
+
+(defvar font-lock-reference-face       'font-lock-constant-face
+  "This variable is obsolete.  Use `font-lock-constant-face'.")
 
 ;; Originally face attributes were specified via `font-lock-face-attributes'.
 ;; Users then changed the default face attributes by setting that variable.
@@ -1650,7 +1840,8 @@ Sets various variables using `font-lock-defaults' (or, if nil, using
 ;; But now we do it the custom way.  Note that `defface' will not overwrite any
 ;; faces declared above via `custom-declare-face'.
 (defface font-lock-comment-face
-  '((((class grayscale) (background light))
+  '((((type tty) (class color)) (:foreground "red"))
+    (((class grayscale) (background light))
      (:foreground "DimGray" :bold t :italic t))
     (((class grayscale) (background dark))
      (:foreground "LightGray" :bold t :italic t))
@@ -1661,7 +1852,8 @@ Sets various variables using `font-lock-defaults' (or, if nil, using
   :group 'font-lock-highlighting-faces)
 
 (defface font-lock-string-face
-  '((((class grayscale) (background light)) (:foreground "DimGray" :italic t))
+  '((((type tty) (class color)) (:foreground "green"))
+    (((class grayscale) (background light)) (:foreground "DimGray" :italic t))
     (((class grayscale) (background dark)) (:foreground "LightGray" :italic t))
     (((class color) (background light)) (:foreground "RosyBrown"))
     (((class color) (background dark)) (:foreground "LightSalmon"))
@@ -1670,7 +1862,8 @@ Sets various variables using `font-lock-defaults' (or, if nil, using
   :group 'font-lock-highlighting-faces)
 
 (defface font-lock-keyword-face
-  '((((class grayscale) (background light)) (:foreground "LightGray" :bold t))
+  '((((type tty) (class color)) (:foreground "cyan" :weight bold))
+    (((class grayscale) (background light)) (:foreground "LightGray" :bold t))
     (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
     (((class color) (background light)) (:foreground "Purple"))
     (((class color) (background dark)) (:foreground "Cyan"))
@@ -1679,7 +1872,8 @@ Sets various variables using `font-lock-defaults' (or, if nil, using
   :group 'font-lock-highlighting-faces)
 
 (defface font-lock-builtin-face
-  '((((class grayscale) (background light)) (:foreground "LightGray" :bold t))
+  '((((type tty) (class color)) (:foreground "blue" :weight light))
+    (((class grayscale) (background light)) (:foreground "LightGray" :bold t))
     (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
     (((class color) (background light)) (:foreground "Orchid"))
     (((class color) (background dark)) (:foreground "LightSteelBlue"))
@@ -1688,14 +1882,16 @@ Sets various variables using `font-lock-defaults' (or, if nil, using
   :group 'font-lock-highlighting-faces)
 
 (defface font-lock-function-name-face
-  '((((class color) (background light)) (:foreground "Blue"))
+  '((((type tty) (class color)) (:foreground "blue" :weight bold))
+    (((class color) (background light)) (:foreground "Blue"))
     (((class color) (background dark)) (:foreground "LightSkyBlue"))
     (t (:inverse-video t :bold t)))
   "Font Lock mode face used to highlight function names."
   :group 'font-lock-highlighting-faces)
 
 (defface font-lock-variable-name-face
-  '((((class grayscale) (background light))
+  '((((type tty) (class color)) (:foreground "yellow" :weight light))
+    (((class grayscale) (background light))
      (:foreground "Gray90" :bold t :italic t))
     (((class grayscale) (background dark))
      (:foreground "DimGray" :bold t :italic t))
@@ -1706,27 +1902,30 @@ Sets various variables using `font-lock-defaults' (or, if nil, using
   :group 'font-lock-highlighting-faces)
 
 (defface font-lock-type-face
-  '((((class grayscale) (background light)) (:foreground "Gray90" :bold t))
+  '((((type tty) (class color)) (:foreground "green"))
+    (((class grayscale) (background light)) (:foreground "Gray90" :bold t))
     (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
     (((class color) (background light)) (:foreground "ForestGreen"))
     (((class color) (background dark)) (:foreground "PaleGreen"))
     (t (:bold t :underline t)))
-  "Font Lock mode face used to highlight types."
+  "Font Lock mode face used to highlight type and classes."
   :group 'font-lock-highlighting-faces)
 
-(defface font-lock-reference-face
-  '((((class grayscale) (background light))
+(defface font-lock-constant-face
+  '((((type tty) (class color)) (:foreground "magenta"))
+    (((class grayscale) (background light))
      (:foreground "LightGray" :bold t :underline t))
     (((class grayscale) (background dark))
      (:foreground "Gray50" :bold t :underline t))
     (((class color) (background light)) (:foreground "CadetBlue"))
     (((class color) (background dark)) (:foreground "Aquamarine"))
     (t (:bold t :underline t)))
-  "Font Lock mode face used to highlight references."
+  "Font Lock mode face used to highlight constants and labels."
   :group 'font-lock-highlighting-faces)
 
 (defface font-lock-warning-face
-  '((((class color) (background light)) (:foreground "Red" :bold t))
+  '((((type tty) (class color)) (:foreground "red"))
+    (((class color) (background light)) (:foreground "Red" :bold t))
     (((class color) (background dark)) (:foreground "Pink" :bold t))
     (t (:inverse-video t :bold t)))
   "Font Lock mode face used to highlight warnings."
@@ -1743,7 +1942,7 @@ Sets various variables using `font-lock-defaults' (or, if nil, using
 ;; the entry for "Text Properties" something like:
 ;;
 ;; (define-key menu-bar-edit-menu [font-lock]
-;;   '("Syntax Highlighting" . font-lock-menu))
+;;   (cons "Syntax Highlighting" font-lock-menu))
 ;;
 ;; and remove a single ";" from the beginning of each line in the rest of this
 ;; section.  Probably the mechanism for telling the menu code what are menu
@@ -1776,7 +1975,7 @@ Sets various variables using `font-lock-defaults' (or, if nil, using
 ;  (put 'font-lock-fontify-less 'menu-enable '(identity)))
 ;
 ;;; Put the appropriate symbol property values on now.  See above.
-;(put 'global-font-lock-mode 'menu-selected 'global-font-lock-mode))
+;(put 'global-font-lock-mode 'menu-selected 'global-font-lock-mode)
 ;(put 'font-lock-mode 'menu-selected 'font-lock-mode)
 ;(put 'font-lock-fontify-more 'menu-enable '(nth 2 font-lock-fontify-level))
 ;(put 'font-lock-fontify-less 'menu-enable '(nth 1 font-lock-fontify-level))
@@ -1885,27 +2084,27 @@ This function could be MATCHER in a MATCH-ANCHORED `font-lock-keywords' item."
      ;; Definitions.
      (list (concat "(\\(def\\("
                   ;; Function declarations.
-                  "\\(advice\\|alias\\|"
-                  "ine-\\(derived-mode\\|function\\|skeleton\\|widget\\)\\|"
-                  "macro\\|subst\\|un\\)\\|"
+                  "\\(advice\\|alias\\|generic\\|macro\\*?\\|method\\|"
+                   "setf\\|subst\\*?\\|un\\*?\\|"
+                   "ine-\\(condition\\|derived-mode\\|function\\|"
+                   "method-combination\\|setf-expander\\|skeleton\\|widget\\|"
+                   "\\(compiler\\|modify\\|symbol\\)-macro\\)\\)\\|"
                   ;; Variable declarations.
-                  "\\(const\\|custom\\|face\\|var\\)\\|"
+                  "\\(const\\(ant\\)?\\|custom\\|face\\|parameter\\|var\\)\\|"
                   ;; Structure declarations.
-                  "\\(class\\|group\\|struct\\|type\\)"
+                  "\\(class\\|group\\|package\\|struct\\|type\\)"
                   "\\)\\)\\>"
                   ;; Any whitespace and defined object.
                   "[ \t'\(]*"
-                  "\\(\\sw+\\)?")
+                  "\\(setf[ \t]+\\sw+)\\|\\sw+\\)?")
           '(1 font-lock-keyword-face)
-          '(7 (cond ((match-beginning 3) font-lock-function-name-face)
-                    ((match-beginning 5) font-lock-variable-name-face)
+          '(9 (cond ((match-beginning 3) font-lock-function-name-face)
+                    ((match-beginning 6) font-lock-variable-name-face)
                     (t font-lock-type-face))
               nil t))
      ;;
      ;; Emacs Lisp autoload cookies.
-     '("^;;;\\(###\\)\\(autoload\\)\\>"
-       (1 font-lock-reference-face prepend)
-       (2 font-lock-warning-face prepend))
+     '("^;;;###\\(autoload\\)" 1 font-lock-warning-face prepend)
      ))
   "Subdued level highlighting for Lisp modes.")
 
@@ -1917,17 +2116,18 @@ This function could be MATCHER in a MATCH-ANCHORED `font-lock-keywords' item."
       ;; Control structures.  Emacs Lisp forms.
       (cons (concat
             "(" (regexp-opt
-                 '("cond" "if" "while" "catch" "throw" "let" "let*"
+                 '("cond" "if" "while" "let" "let*"
                    "prog" "progn" "progv" "prog1" "prog2" "prog*"
-                   "closure" "preparse-closure" "make-closure"
-                   "inline" "save-restriction" "save-excursion"
+                   "inline" "lambda" "save-restriction" "save-excursion"
                    "save-window-excursion" "save-selected-window"
                    "save-match-data" "save-current-buffer" "unwind-protect"
-                   "condition-case" "track-mouse" "dont-compile"
+                   "condition-case" "track-mouse"
                    "eval-after-load" "eval-and-compile" "eval-when-compile"
-                   "eval-when" "with-output-to-temp-buffer" "with-timeout"
-                   "with-current-buffer" "with-temp-buffer"
-                   "with-temp-file") t)
+                   "eval-when"
+                   "with-current-buffer" "with-electric-help"
+                   "with-output-to-string" "with-output-to-temp-buffer"
+                   "with-temp-buffer" "with-temp-file" "with-temp-message"
+                   "with-timeout") t)
             "\\>")
            1)
       ;;
@@ -1935,92 +2135,43 @@ This function could be MATCHER in a MATCH-ANCHORED `font-lock-keywords' item."
       (cons (concat
             "(" (regexp-opt
                  '("when" "unless" "case" "ecase" "typecase" "etypecase"
-                   "loop" "do" "do*" "dotimes" "dolist"
-                   "proclaim" "declaim" "declare"
-                   "lexical-let" "lexical-let*" "flet" "labels"
+                   "ccase" "ctypecase" "handler-case" "handler-bind"
+                   "restart-bind" "restart-case" "in-package"
+                   "cerror" "break" "ignore-errors"
+                   "loop" "do" "do*" "dotimes" "dolist" "the" "locally"
+                   "proclaim" "declaim" "declare" "symbol-macrolet"
+                   "lexical-let" "lexical-let*" "flet" "labels" "compiler-let"
+                   "destructuring-bind" "macrolet" "tagbody" "block"
                    "return" "return-from") t)
             "\\>")
            1)
       ;;
-      ;; Feature symbols as references.
-      '("(\\(featurep\\|provide\\|require\\)\\>[ \t']*\\(\\sw+\\)?"
-       (1 font-lock-keyword-face) (2 font-lock-reference-face nil t))
+      ;; Exit/Feature symbols as constants.
+      (list (concat "(\\(catch\\|throw\\|featurep\\|provide\\|require\\)\\>"
+                   "[ \t']*\\(\\sw+\\)?")
+           '(1 font-lock-keyword-face)
+           '(2 font-lock-constant-face nil t))
+      ;;
+      ;; Erroneous structures.
+      '("(\\(abort\\|assert\\|error\\|signal\\)\\>" 1 font-lock-warning-face)
       ;;
       ;; Words inside \\[] tend to be for `substitute-command-keys'.
-      '("\\\\\\\\\\[\\(\\sw+\\)]" 1 font-lock-reference-face prepend)
+      '("\\\\\\\\\\[\\(\\sw+\\)]" 1 font-lock-constant-face prepend)
       ;;
       ;; Words inside `' tend to be symbol names.
-      '("`\\(\\sw\\sw+\\)'" 1 font-lock-reference-face prepend)
+      '("`\\(\\sw\\sw+\\)'" 1 font-lock-constant-face prepend)
       ;;
-      ;; CLisp `:' keywords as builtins.
+      ;; Constant values.
       '("\\<:\\sw\\sw+\\>" 0 font-lock-builtin-face)
       ;;
       ;; ELisp and CLisp `&' keywords as types.
-      '("\\<\\&\\sw+\\>" . font-lock-type-face)
+      '("\\&\\sw+\\>" . font-lock-type-face)
       )))
   "Gaudy level highlighting for Lisp modes.")
 
 (defvar lisp-font-lock-keywords lisp-font-lock-keywords-1
   "Default expressions to highlight in Lisp modes.")
 \f
-;; Scheme.
-
-(defconst scheme-font-lock-keywords-1
-  (eval-when-compile
-    (list
-     ;;
-     ;; Declarations.  Hannes Haug <hannes.haug@student.uni-tuebingen.de> says
-     ;; this works for SOS, STklos, SCOOPS, Meroon and Tiny CLOS.
-     (list (concat "(\\(define\\("
-                  ;; Function names.
-                  "\\(\\|-\\(generic\\(\\|-procedure\\)\\|method\\)\\)\\|"
-                  ;; Macro names, as variable names.  A bit dubious, this.
-                  "\\(-syntax\\)\\|"
-                  ;; Class names.
-                  "-class"
-                  "\\)\\)\\>"
-                  ;; Any whitespace and declared object.
-                  "[ \t]*(?"
-                  "\\(\\sw+\\)?")
-          '(1 font-lock-keyword-face)
-          '(7 (cond ((match-beginning 3) font-lock-function-name-face)
-                    ((match-beginning 6) font-lock-variable-name-face)
-                    (t font-lock-type-face))
-              nil t))
-     ))
-  "Subdued expressions to highlight in Scheme modes.")
-
-(defconst scheme-font-lock-keywords-2
-  (append scheme-font-lock-keywords-1
-   (eval-when-compile
-     (list
-      ;;
-      ;; Control structures.
-      (cons
-       (concat
-       "(" (regexp-opt
-            '("begin" "call-with-current-continuation" "call/cc"
-              "call-with-input-file" "call-with-output-file" "case" "cond"
-              "do" "else" "for-each" "if" "lambda"
-              "let" "let*" "let-syntax" "letrec" "letrec-syntax"
-              ;; Hannes Haug <hannes.haug@student.uni-tuebingen.de> wants:
-              "and" "or" "delay"
-              ;; Stefan Monnier <stefan.monnier@epfl.ch> says don't bother:
-              ;;"quasiquote" "quote" "unquote" "unquote-splicing"
-              "map" "syntax" "syntax-rules") t)
-       "\\>") 1)
-      ;;
-      ;; David Fox <fox@graphics.cs.nyu.edu> for SOS/STklos class specifiers.
-      '("\\<<\\sw+>\\>" . font-lock-type-face)
-      ;;
-      ;; Scheme `:' keywords as references.
-      '("\\<:\\sw+\\>" . font-lock-reference-face)
-      )))
-  "Gaudy expressions to highlight in Scheme modes.")
-
-(defvar scheme-font-lock-keywords scheme-font-lock-keywords-1
-  "Default expressions to highlight in Scheme modes.")
-\f
 ;; TeX.
 
 ;(defvar tex-font-lock-keywords
@@ -2028,7 +2179,7 @@ This function could be MATCHER in a MATCH-ANCHORED `font-lock-keywords' item."
 ;  '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}"
 ;     2 font-lock-function-name-face)
 ;    ("\\\\\\(cite\\|label\\|pageref\\|ref\\){\\([^} \t\n]+\\)}"
-;     2 font-lock-reference-face)
+;     2 font-lock-constant-face)
 ;    ;; It seems a bit dubious to use `bold' and `italic' faces since we might
 ;    ;; not be able to display those fonts.
 ;    ("{\\\\bf\\([^}]+\\)}" 1 'bold keep)
@@ -2039,7 +2190,7 @@ This function could be MATCHER in a MATCH-ANCHORED `font-lock-keywords' item."
 ;  '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}"
 ;     2 font-lock-function-name-face)
 ;    ("\\\\\\(cite\\|label\\|pageref\\|ref\\){\\([^} \t\n]+\\)}"
-;     2 font-lock-reference-face)
+;     2 font-lock-constant-face)
 ;    ("^[ \t]*\\\\def\\\\\\(\\(\\w\\|@\\)+\\)" 1 font-lock-function-name-face)
 ;    "\\\\\\([a-zA-Z@]+\\|.\\)"
 ;    ;; It seems a bit dubious to use `bold' and `italic' faces since we might
@@ -2134,9 +2285,9 @@ This function could be MATCHER in a MATCH-ANCHORED `font-lock-keywords' item."
                        '("label" "ref" "pageref" "vref" "eqref")
                        t))
            (citations-opt (regexp-opt
-                           '("cite" "caption" "index" "glossary"
+                           '("cite" "nocite" "caption" "index" "glossary"
                              "footnote" "footnotemark" "footnotetext")
-                       t))
+                           t))
            ;;
            ;; Names of commands that should be fontified.
            (specials (regexp-opt
@@ -2159,10 +2310,10 @@ This function could be MATCHER in a MATCH-ANCHORED `font-lock-keywords' item."
        ;; Citation args.
        (list (concat slash citations arg)
              (+ (regexp-opt-depth citations) arg-depth)
-             'font-lock-reference-face)
+             'font-lock-constant-face)
        (list (concat slash citations-opt opt arg)
              (+ (regexp-opt-depth citations-opt) opt-depth arg-depth)
-             'font-lock-reference-face)
+             'font-lock-constant-face)
        ;;
        ;; Command names, special and general.
        (cons (concat slash specials) 'font-lock-warning-face)
@@ -2181,9 +2332,9 @@ This function could be MATCHER in a MATCH-ANCHORED `font-lock-keywords' item."
              '(quote bold-italic) 'keep)
        ;;
        ;; Old-style bf/em/it/sl.  Stop at `\\' and un-escaped `&', for tables.
-       (list (concat "\\\\\\(\\(bf\\)\\|em\\|it\\(em\\)?\\|sl\\)\\>"
+       (list (concat "\\\\\\(\\(bf\\)\\|em\\|it\\|sl\\)\\>"
                      "\\(\\([^}&\\]\\|\\\\[^\\]\\)+\\)")
-             4 '(if (match-beginning 2) 'bold 'italic) 'keep)
+             3 '(if (match-beginning 2) 'bold 'italic) 'keep)
        ))))
    "Gaudy expressions to highlight in TeX modes.")
 
@@ -2212,11 +2363,23 @@ The value of this variable is used when Font Lock mode is turned on."
   :type 'font-lock-extra-types-widget
   :group 'font-lock-extra-types)
 
-(defcustom c++-font-lock-extra-types '("string" "wchar_t")
+(defcustom c++-font-lock-extra-types
+  '("\\sw+_t"
+    "\\([iof]\\|str\\)+stream\\(buf\\)?" "ios"
+    "string" "rope"
+    "list" "slist"
+    "deque" "vector" "bit_vector"
+    "set" "multiset"
+    "map" "multimap"
+    "hash\\(_\\(m\\(ap\\|ulti\\(map\\|set\\)\\)\\|set\\)\\)?"
+    "stack" "queue" "priority_queue"
+    "type_info"
+    "iterator" "const_iterator" "reverse_iterator" "const_reverse_iterator"
+    "reference" "const_reference")
   "*List of extra types to fontify in C++ mode.
 Each list item should be a regexp not containing word-delimiters.
-For example, a value of (\"string\" \"wchar_t\") means the words string and
-wchar_t are treated as type names.
+For example, a value of (\"string\") means the word string is treated as a type
+name.
 
 The value of this variable is used when Font Lock mode is turned on."
   :type 'font-lock-extra-types-widget
@@ -2232,10 +2395,11 @@ The value of this variable is used when Font Lock mode is turned on."
   :type 'font-lock-extra-types-widget
   :group 'font-lock-extra-types)
 
-(defcustom java-font-lock-extra-types '("[A-Z\300-\326\330-\337]\\sw+")
+(defcustom java-font-lock-extra-types
+  '("[A-Z\300-\326\330-\337]\\sw*[a-z]\\sw*")
   "*List of extra types to fontify in Java mode.
 Each list item should be a regexp not containing word-delimiters.
-For example, a value of (\"[A-Z\300-\326\330-\337]\\\\sw+\") means capitalised
+For example, a value of (\"[A-Z\300-\326\330-\337]\\\\sw*[a-z]\\\\sw*\") means capitalised
 words (and words conforming to the Java id spec) are treated as type names.
 
 The value of this variable is used when Font Lock mode is turned on."
@@ -2272,18 +2436,35 @@ See also `c-font-lock-extra-types'.")
 (let* ((c-keywords
        (eval-when-compile
          (regexp-opt '("break" "continue" "do" "else" "for" "if" "return"
-                       "switch" "while") t)))
-       (c-type-types
+                       "switch" "while" "sizeof"
+                       ;; Type related, but we don't do anything special.
+                       "typedef" "extern" "auto" "register" "static"
+                       "volatile" "const"
+                       ;; Dan Nicolaescu <done@gnu.org> says this is new.
+                       "restrict") t)))
+       (c-type-specs
+       (eval-when-compile
+         (regexp-opt '("enum" "struct" "union") t)))
+       (c-type-specs-depth
+       (regexp-opt-depth c-type-specs))
+       (c-type-names
        `(mapconcat 'identity
-         (cons 
+         (cons
           (,@ (eval-when-compile
                 (regexp-opt
-                 '("auto" "extern" "register" "static" "typedef" "struct"
-                   "union" "enum" "signed" "unsigned" "short" "long"
-                   "int" "char" "float" "double" "void" "volatile" "const"))))
+                 '("char" "short" "int" "long" "signed" "unsigned"
+                   "float" "double" "void" "complex"))))
           c-font-lock-extra-types)
          "\\|"))
-       (c-type-depth `(regexp-opt-depth (,@ c-type-types)))
+       (c-type-names-depth
+       `(regexp-opt-depth (,@ c-type-names)))
+       (c-preprocessor-directives
+       (eval-when-compile
+         (regexp-opt
+          '("define"  "elif" "else" "endif" "error" "file" "if" "ifdef"
+            "ifndef" "include" "line" "pragma" "undef"))))
+       (c-preprocessor-directives-depth
+       (regexp-opt-depth c-preprocessor-directives))
        )
  (setq c-font-lock-keywords-1
   (list
@@ -2298,7 +2479,7 @@ See also `c-font-lock-extra-types'.")
    '("^#[ \t]*error[ \t]+\\(.+\\)" 1 font-lock-warning-face prepend)
    ;;
    ;; Fontify filenames in #include <...> preprocessor directives as strings.
-   '("^#[ \t]*\\(import\\|include\\)[ \t]+\\(<[^>\"\n]*>?\\)"
+   '("^#[ \t]*\\(import\\|include\\)[ \t]*\\(<[^>\"\n]*>?\\)"
      2 font-lock-string-face)
    ;;
    ;; Fontify function macro names.
@@ -2307,11 +2488,15 @@ See also `c-font-lock-extra-types'.")
    ;; Fontify symbol names in #elif or #if ... defined preprocessor directives.
    '("^#[ \t]*\\(elif\\|if\\)\\>"
      ("\\<\\(defined\\)\\>[ \t]*(?\\(\\sw+\\)?" nil nil
-      (1 font-lock-reference-face) (2 font-lock-variable-name-face nil t)))
+      (1 font-lock-builtin-face) (2 font-lock-variable-name-face nil t)))
    ;;
    ;; Fontify otherwise as symbol names, and the preprocessor directive names.
-   '("^#[ \t]*\\(\\sw+\\)\\>[ \t]*\\(\\sw+\\)?"
-     (1 font-lock-reference-face) (2 font-lock-variable-name-face nil t))
+   (list
+    (concat "^#[ \t]*\\(" c-preprocessor-directives
+           "\\)\\>[ \t!]*\\(\\sw+\\)?")
+    '(1 font-lock-builtin-face)
+    (list (+ 2 c-preprocessor-directives-depth)
+         'font-lock-variable-name-face nil t))
    ))
 
  (setq c-font-lock-keywords-2
@@ -2320,21 +2505,27 @@ See also `c-font-lock-extra-types'.")
     ;;
     ;; Simple regexps for speed.
     ;;
-    ;; Fontify all type specifiers.
+    ;; Fontify all type names.
     `(eval .
-      (cons (concat "\\<\\(" (,@ c-type-types) "\\)\\>") 'font-lock-type-face))
+      (cons (concat "\\<\\(" (,@ c-type-names) "\\)\\>") 'font-lock-type-face))
     ;;
     ;; Fontify all builtin keywords (except case, default and goto; see below).
-    (concat "\\<" c-keywords "\\>")
+    (concat "\\<\\(" c-keywords "\\|" c-type-specs "\\)\\>")
     ;;
     ;; Fontify case/goto keywords and targets, and case default/goto tags.
-    '("\\<\\(case\\|goto\\)\\>[ \t]*\\(-?\\sw+\\)?"
-      (1 font-lock-keyword-face) (2 font-lock-reference-face nil t))
-    ;; Anders Lindgren <andersl@csd.uu.se> points out that it is quicker to use
-    ;; MATCH-ANCHORED to effectively anchor the regexp on the left.
-    '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:"
+    '("\\<\\(case\\|goto\\)\\>"
+      (1 font-lock-keyword-face)
+      ("\\(-[0-9]+\\|\\sw+\\)"
+       ;; Return limit of search.
+       (save-excursion (skip-chars-forward "^:\n") (point))
+       nil
+       (1 font-lock-constant-face nil t)))
+    ;; Anders Lindgren <andersl@andersl.com> points out that it is quicker to
+    ;; use MATCH-ANCHORED to effectively anchor the regexp on the left.
+    ;; This must come after the one for keywords and targets.
+    '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:[ \t]*$"
           (beginning-of-line) (end-of-line)
-          (1 font-lock-reference-face)))
+          (1 font-lock-constant-face)))
     )))
 
  (setq c-font-lock-keywords-3
@@ -2344,15 +2535,16 @@ See also `c-font-lock-extra-types'.")
    ;; We still have to fontify type specifiers individually, as C is so hairy.
    (list
     ;;
-    ;; Fontify all storage classes and type specifiers, plus their items.
+    ;; Fontify all storage types, plus their items.
     `(eval .
-      (list (concat "\\<\\(" (,@ c-type-types) "\\)\\>"
+      (list (concat "\\<\\(" (,@ c-type-names) "\\)\\>"
                    "\\([ \t*&]+\\sw+\\>\\)*")
            ;; Fontify each declaration item.
            (list 'font-lock-match-c-style-declaration-item-and-skip-to-next
                  ;; Start with point after all type specifiers.
-                 (list 'goto-char (list 'or (list 'match-beginning
-                                                  (+ (,@ c-type-depth) 2))
+                 (list 'goto-char (list 'or
+                                        (list 'match-beginning
+                                              (+ (,@ c-type-names-depth) 2))
                                         '(match-end 1)))
                  ;; Finish with point after first type specifier.
                  '(goto-char (match-end 1))
@@ -2361,13 +2553,24 @@ See also `c-font-lock-extra-types'.")
                          font-lock-function-name-face
                        font-lock-variable-name-face)))))
     ;;
+    ;; Fontify all storage specs and types, plus their items.
+    `(eval .
+      (list (concat "\\<\\(" (,@ c-type-specs) "\\)\\>"
+                   "[ \t]*\\(\\sw+\\)?")
+         (list 1 'font-lock-keyword-face)
+         (list (+ (,@ c-type-specs-depth) 2) 'font-lock-type-face nil t)
+         (list 'font-lock-match-c-style-declaration-item-and-skip-to-next
+                 nil nil
+                 ;; Fontify as a variable or function name.
+                 '(1 (if (match-beginning 2)
+                         font-lock-function-name-face
+                       font-lock-variable-name-face) nil t))))
+    ;;
     ;; Fontify structures, or typedef names, plus their items.
     '("\\(}\\)[ \t*]*\\sw"
       (font-lock-match-c-style-declaration-item-and-skip-to-next
        (goto-char (match-end 1)) nil
-       (1 (if (match-beginning 2)
-             font-lock-function-name-face
-           font-lock-variable-name-face))))
+       (1 font-lock-type-face)))
     ;;
     ;; Fontify anything at beginning of line as a declaration or definition.
     '("^\\(\\sw+\\)\\>\\([ \t*]+\\sw+\\>\\)*"
@@ -2413,7 +2616,7 @@ See also `c++-font-lock-extra-types'.")
                       ;; This is `c++-type-spec' from below.  (Hint hint!)
                       "\\(\\sw+\\)"                            ; The instance?
                       "\\([ \t]*<\\([^>\n]+\\)[ \t*&]*>\\)?"   ; Or template?
-                      "\\([ \t]*::[ \t*~]*\\(\\sw+\\)\\)?"     ; Or member?
+                      "\\([ \t]*::[ \t*~]*\\(\\sw+\\)\\)*"     ; Or member?
                       ;; Match any trailing parenthesis.
                       "[ \t]*\\((\\)?")))
     (save-match-data
@@ -2428,14 +2631,39 @@ See also `c++-font-lock-extra-types'.")
            (goto-char (match-end 2)))
        (error t)))))
 
+(defun font-lock-match-c++-structor-declaration (limit)
+  ;; Match C++ constructors and destructors inside class declarations.
+  (let ((res nil)
+       (regexp (concat "^\\s-+\\(\\(virtual\\|explicit\\)\\s-+\\)*~?\\(\\<"
+                       (mapconcat 'identity
+                                  c++-font-lock-extra-types "\\|")
+                       "\\>\\)\\s-*("
+                       ;; Don't match function pointer declarations, e.g.:
+                       ;;    Foo (*fptr)();
+                       "\\s-*[^*( \t]")))
+    (while (progn (setq res (re-search-forward regexp limit t))
+                 (and res
+                      (save-excursion
+                        (beginning-of-line)
+                        (save-match-data
+                          (not (vectorp (c-at-toplevel-p))))))))
+    res))
+
 (let* ((c++-keywords
        (eval-when-compile
          (regexp-opt
           '("break" "continue" "do" "else" "for" "if" "return" "switch"
-            "while" "asm" "catch" "delete" "new" "operator" "sizeof" "this"
-            "throw" "try"
-            ;; Eric Hopper <hopper@omnifarious.mn.org> says these are new.
-            "static_cast" "dynamic_cast" "const_cast" "reinterpret_cast") t)))
+            "while" "asm" "catch" "delete" "new" "sizeof" "this" "throw" "try"
+            "typeid"
+            ;; Branko Cibej <branko.cibej@hermes.si> says this is new.
+            "export"
+            ;; Mark Mitchell <mmitchell@usa.net> says these are new.
+            "mutable" "explicit"
+            ;; Alain Picard <ap@abelard.apana.org.au> suggests treating these
+            ;; as keywords not types.
+            "typedef" "template"
+            "extern" "auto" "register" "const" "volatile" "static"
+            "inline" "friend" "virtual") t)))
        (c++-operators
        (eval-when-compile
          (regexp-opt
@@ -2443,32 +2671,40 @@ See also `c++-font-lock-extra-types'.")
           '("+" "-" "*" "/" "%" "^" "&" "|" "~" "!" "=" "<" ">" "+=" "-="
             "*=" "/=" "%=" "^=" "&=" "|=" "<<" ">>" ">>=" "<<=" "==" "!="
             "<=" ">=" "&&" "||" "++" "--" "->*" "," "->" "[]" "()"))))
-       (c++-type-types
+       (c++-type-specs
+       (eval-when-compile
+         (regexp-opt
+          '("class" "public" "private" "protected" "typename"
+            "struct" "union" "enum" "namespace" "using"
+            ;; Eric Hopper <hopper@omnifarious.mn.org> says these are new.
+            "static_cast" "dynamic_cast" "const_cast" "reinterpret_cast") t)))
+       (c++-type-specs-depth
+       (regexp-opt-depth c++-type-specs))
+       (c++-type-names
        `(mapconcat 'identity
-         (cons 
+         (cons
           (,@ (eval-when-compile
                 (regexp-opt
-                 '("auto" "extern" "register" "static" "typedef" "struct"
-                   "union" "enum" "signed" "unsigned" "short" "long"
-                   "int" "char" "float" "double" "void" "volatile" "const"
-                   "inline" "friend" "bool" "virtual" "complex" "template"
-                   "namespace" "using"
-                   ;; Mark Mitchell <mmitchell@usa.net> says these are new.
-                   "explicit" "mutable"))))
+                 '("signed" "unsigned" "short" "long"
+                   "int" "char" "float" "double" "void"
+                   "bool" "complex"))))
           c++-font-lock-extra-types)
          "\\|"))
+       (c++-type-names-depth `(regexp-opt-depth (,@ c++-type-names)))
        ;;
        ;; A brave attempt to match templates following a type and/or match
        ;; class membership.  See and sync the above function
        ;; `font-lock-match-c++-style-declaration-item-and-skip-to-next'.
        (c++-type-suffix (concat "\\([ \t]*<\\([^>\n]+\\)[ \t*&]*>\\)?"
-                               "\\([ \t]*::[ \t*~]*\\(\\sw+\\)\\)?"))
+                               "\\([ \t]*::[ \t*~]*\\(\\sw+\\)\\)*"))
+       (c++-type-suffix-depth (regexp-opt-depth c++-type-suffix))
        ;; If the string is a type, it may be followed by the cruft above.
        (c++-type-spec (concat "\\(\\sw+\\)\\>" c++-type-suffix))
+       (c++-type-spec-depth (regexp-opt-depth c++-type-spec))
        ;;
        ;; Parenthesis depth of user-defined types not forgetting their cruft.
        (c++-type-depth `(regexp-opt-depth
-                        (concat (,@ c++-type-types) (,@ c++-type-suffix))))
+                        (concat (,@ c++-type-names) (,@ c++-type-suffix))))
        )
  (setq c++-font-lock-keywords-1
   (append
@@ -2477,22 +2713,12 @@ See also `c++-font-lock-extra-types'.")
    (cdr c-font-lock-keywords-1)
    (list
     ;;
-    ;; Class names etc.
-    (list (concat "\\<\\(class\\|public\\|private\\|protected\\)\\>[ \t]*"
-                 "\\(" c++-type-spec "\\)?")
-         '(1 font-lock-type-face)
-         '(3 (if (match-beginning 6)
-                 font-lock-type-face
-               font-lock-function-name-face) nil t)
-         '(5 font-lock-function-name-face nil t)
-         '(7 font-lock-function-name-face nil t))
-    ;;
     ;; Fontify function name definitions, possibly incorporating class names.
     (list (concat "^" c++-type-spec "[ \t]*(")
          '(1 (if (or (match-beginning 2) (match-beginning 4))
                  font-lock-type-face
                font-lock-function-name-face))
-         '(3 font-lock-function-name-face nil t)
+         '(3 font-lock-type-face nil t)
          '(5 font-lock-function-name-face nil t))
     )))
 
@@ -2502,7 +2728,7 @@ See also `c++-font-lock-extra-types'.")
     ;;
     ;; The list `c-font-lock-keywords-2' for C++ plus operator overloading.
     `(eval .
-      (cons (concat "\\<\\(" (,@ c++-type-types) "\\)\\>")
+      (cons (concat "\\<\\(" (,@ c++-type-names) "\\)\\>")
            'font-lock-type-face))
     ;;
     ;; Fontify operator overloading.
@@ -2511,17 +2737,30 @@ See also `c++-font-lock-extra-types'.")
          '(2 font-lock-builtin-face nil t))
     ;;
     ;; Fontify case/goto keywords and targets, and case default/goto tags.
-    '("\\<\\(case\\|goto\\)\\>[ \t]*\\(-?\\sw+\\)?"
-      (1 font-lock-keyword-face) (2 font-lock-reference-face nil t))
+    '("\\<\\(case\\|goto\\)\\>"
+      (1 font-lock-keyword-face)
+      ("\\(-[0-9]+\\|\\sw+\\)[ \t]*\\(::\\)?"
+       ;; Return limit of search.
+       (save-excursion
+        (while (progn
+                 (skip-chars-forward "^:\n")
+                 (looking-at "::"))
+          (forward-char 2))
+        (point))
+       nil
+       (1 (if (match-beginning 2)
+             font-lock-type-face
+           font-lock-constant-face) nil t)))
+    ;; This must come after the one for keywords and targets.
     '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:\\($\\|[^:]\\)"
           (beginning-of-line) (end-of-line)
-          (1 font-lock-reference-face)))
+          (1 font-lock-constant-face)))
     ;;
     ;; Fontify other builtin keywords.
-    (concat "\\<" c++-keywords "\\>")
+    (concat "\\<\\(" c++-keywords "\\|" c++-type-specs "\\)\\>")
     ;;
     ;; Eric Hopper <hopper@omnifarious.mn.org> says `true' and `false' are new.
-    '("\\<\\(false\\|true\\)\\>" . font-lock-reference-face)
+    '("\\<\\(false\\|true\\)\\>" . font-lock-constant-face)
     )))
 
  (setq c++-font-lock-keywords-3
@@ -2532,8 +2771,10 @@ See also `c++-font-lock-extra-types'.")
     ;;
     ;; Fontify all storage classes and type specifiers, plus their items.
     `(eval .
-      (list (concat "\\<\\(" (,@ c++-type-types) "\\)\\>" (,@ c++-type-suffix)
+      (list (concat "\\<\\(" (,@ c++-type-names) "\\)\\>" (,@ c++-type-suffix)
                    "\\([ \t*&]+" (,@ c++-type-spec) "\\)*")
+           ;; The name of any template type.
+           (list (+ (,@ c++-type-names-depth) 3) 'font-lock-type-face nil t)
            ;; Fontify each declaration item.
            (list 'font-lock-match-c++-style-declaration-item-and-skip-to-next
                  ;; Start with point after all type specifiers.
@@ -2545,20 +2786,48 @@ See also `c++-font-lock-extra-types'.")
                  ;; Fontify as a variable or function name.
                  '(1 (cond ((or (match-beginning 2) (match-beginning 4))
                             font-lock-type-face)
-                           ((match-beginning 6) font-lock-function-name-face)
-                           (t font-lock-variable-name-face)))
-                 '(3 font-lock-function-name-face nil t)
+                           ((and (match-beginning 6) (c-at-toplevel-p))
+                            font-lock-function-name-face)
+                           (t
+                            font-lock-variable-name-face)))
+                 '(3 font-lock-type-face nil t)
                  '(5 (if (match-beginning 6)
                          font-lock-function-name-face
                        font-lock-variable-name-face) nil t))))
     ;;
+    ;; Fontify all storage specs and types, plus their items.
+    `(eval .
+      (list (concat "\\<" (,@ c++-type-specs) "\\>" (,@ c++-type-suffix)
+                   "[ \t]*\\(" (,@ c++-type-spec) "\\)?")
+           ;; The name of any template type.
+           (list (+ (,@ c++-type-specs-depth) 2) 'font-lock-type-face nil t)
+           ;; The name of any type.
+           (list (+ (,@ c++-type-specs-depth) (,@ c++-type-suffix-depth) 2)
+                 'font-lock-type-face nil t)
+           ;; Fontify each declaration item.
+           (list 'font-lock-match-c++-style-declaration-item-and-skip-to-next
+                 ;; Start with point after all type specifiers.
+                 nil
+                 ;; Finish with point after first type specifier.
+                 nil
+                 ;; Fontify as a variable or function name.
+                 '(1 (cond ((or (match-beginning 2) (match-beginning 4))
+                            font-lock-type-face)
+                           ((and (match-beginning 6) (c-at-toplevel-p))
+                            font-lock-function-name-face)
+                           (t
+                            font-lock-variable-name-face)))
+                 '(3 font-lock-type-face nil t)
+                 '(5 (if (match-beginning 6)
+                         font-lock-function-name-face
+                       font-lock-variable-name-face) nil t))
+           ))
+    ;;
     ;; Fontify structures, or typedef names, plus their items.
     '("\\(}\\)[ \t*]*\\sw"
       (font-lock-match-c++-style-declaration-item-and-skip-to-next
        (goto-char (match-end 1)) nil
-       (1 (if (match-beginning 6)
-             font-lock-function-name-face
-           font-lock-variable-name-face))))
+       (1 font-lock-type-face)))
     ;;
     ;; Fontify anything at beginning of line as a declaration or definition.
     (list (concat "^\\(" c++-type-spec "[ \t*&]*\\)+")
@@ -2569,10 +2838,14 @@ See also `c++-font-lock-extra-types'.")
                      font-lock-type-face)
                     ((match-beginning 6) font-lock-function-name-face)
                     (t font-lock-variable-name-face)))
-           (3 font-lock-function-name-face nil t)
+           (3 font-lock-type-face nil t)
            (5 (if (match-beginning 6)
                   font-lock-function-name-face
                 font-lock-variable-name-face) nil t)))
+    ;;
+    ;; Fontify constructors and destructors inside class declarations.
+    '(font-lock-match-c++-structor-declaration
+      (3 font-lock-function-name-face t))
     )))
  )
 
@@ -2598,19 +2871,28 @@ See also `objc-font-lock-extra-types'.")
 (let* ((objc-keywords
        (eval-when-compile
          (regexp-opt '("break" "continue" "do" "else" "for" "if" "return"
-                       "switch" "while" "sizeof" "self" "super") t)))
-       (objc-type-types
+                       "switch" "while" "sizeof" "self" "super"
+                       "typedef" "auto" "extern" "static"
+                       "volatile" "const") t)))
+       (objc-type-specs
+       (eval-when-compile
+         (regexp-opt
+          '("register" "struct" "union" "enum"
+            "oneway" "in" "out" "inout" "bycopy" "byref") t)))
+       (objc-type-specs-depth
+       (regexp-opt-depth objc-type-specs))
+       (objc-type-names
        `(mapconcat 'identity
          (cons
           (,@ (eval-when-compile
                 (regexp-opt
-                 '("auto" "extern" "register" "static" "typedef" "struct"
-                   "union" "enum" "signed" "unsigned" "short" "long"
-                   "int" "char" "float" "double" "void" "volatile" "const"
-                   "id" "oneway" "in" "out" "inout" "bycopy" "byref"))))
+                 '("signed" "unsigned" "short" "long"
+                   "int" "char" "float" "double" "void"
+                   "id"))))
           objc-font-lock-extra-types)
          "\\|"))
-       (objc-type-depth `(regexp-opt-depth (,@ objc-type-types)))
+       (objc-type-names-depth
+       `(regexp-opt-depth (,@ objc-type-names)))
        )
  (setq objc-font-lock-keywords-1
   (append
@@ -2622,26 +2904,23 @@ See also `objc-font-lock-extra-types'.")
     ;; Fontify compiler directives.
     '("@\\(\\sw+\\)\\>"
       (1 font-lock-keyword-face)
-      ("\\=[ \t:<(,]*\\(\\sw+\\)" nil nil
-       (1 font-lock-function-name-face)))
+      ("\\=[ \t:<,]*\\(\\sw+\\)" nil nil
+       (1 font-lock-type-face)))
     ;;
     ;; Fontify method names and arguments.  Oh Lordy!
     ;; First, on the same line as the function declaration.
-    '("^[+-][ \t]*\\(PRIVATE\\)?[ \t]*\\((\\([^)\n]+\\))\\)?[ \t]*\\(\\sw+\\)"
-      (1 font-lock-type-face nil t)
-      (3 font-lock-type-face nil t)
-      (4 font-lock-function-name-face)
-      ("\\=[ \t]*\\(\\sw+\\)?:[ \t]*\\((\\([^)\n]+\\))\\)?[ \t]*\\(\\sw+\\)"
+    '("^[+-][ \t]*\\(PRIVATE\\>\\)?[ \t]*\\(([^)\n]+)\\)?[ \t]*\\(\\sw+\\)"
+      (1 font-lock-keyword-face nil t)
+      (3 font-lock-function-name-face)
+      ("\\=[ \t]*\\(\\sw+\\)?:[ \t]*\\(([^)\n]+)\\)?[ \t]*\\(\\sw+\\)"
        nil nil
        (1 font-lock-function-name-face nil t)
-       (3 font-lock-type-face nil t)
-       (4 font-lock-variable-name-face)))
+       (3 font-lock-variable-name-face)))
     ;; Second, on lines following the function declaration.
-    '(":" ("^[ \t]*\\(\\sw+\\)?:[ \t]*\\((\\([^)\n]+\\))\\)?[ \t]*\\(\\sw+\\)"
+    '(":" ("^[ \t]*\\(\\sw+\\)?:[ \t]*\\(([^)\n]+)\\)?[ \t]*\\(\\sw+\\)"
           (beginning-of-line) (end-of-line)
           (1 font-lock-function-name-face nil t)
-          (3 font-lock-type-face nil t)
-          (4 font-lock-variable-name-face)))
+          (3 font-lock-variable-name-face)))
     )))
 
  (setq objc-font-lock-keywords-2
@@ -2652,22 +2931,23 @@ See also `objc-font-lock-extra-types'.")
     ;;
     ;; Fontify all type specifiers.
     `(eval .
-      (cons (concat "\\<\\(" (,@ objc-type-types) "\\)\\>")
+      (cons (concat "\\<\\(" (,@ objc-type-names) "\\)\\>")
            'font-lock-type-face))
     ;;
     ;; Fontify all builtin keywords (except case, default and goto; see below).
-    (concat "\\<" objc-keywords "\\>")
+    (concat "\\<\\(" objc-keywords "\\|" objc-type-specs "\\)\\>")
     ;;
     ;; Fontify case/goto keywords and targets, and case default/goto tags.
     '("\\<\\(case\\|goto\\)\\>[ \t]*\\(-?\\sw+\\)?"
-      (1 font-lock-keyword-face) (2 font-lock-reference-face nil t))
+      (1 font-lock-keyword-face) (2 font-lock-constant-face nil t))
     ;; Fontify tags iff sole statement on line, otherwise we detect selectors.
+    ;; This must come after the one for keywords and targets.
     '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:[ \t]*$"
           (beginning-of-line) (end-of-line)
-          (1 font-lock-reference-face)))
+          (1 font-lock-constant-face)))
     ;;
     ;; Fontify null object pointers.
-    '("\\<\\(Nil\\|nil\\)\\>" 1 font-lock-reference-face)
+    '("\\<[Nn]il\\>" . font-lock-constant-face)
     )))
 
  (setq objc-font-lock-keywords-3
@@ -2679,14 +2959,15 @@ See also `objc-font-lock-extra-types'.")
     ;;
     ;; Fontify all storage classes and type specifiers, plus their items.
     `(eval .
-      (list (concat "\\<\\(" (,@ objc-type-types) "\\)\\>"
+      (list (concat "\\<\\(" (,@ objc-type-names) "\\)\\>"
                    "\\([ \t*&]+\\sw+\\>\\)*")
            ;; Fontify each declaration item.
            (list 'font-lock-match-c-style-declaration-item-and-skip-to-next
                  ;; Start with point after all type specifiers.
-                 (list 'goto-char (list 'or (list 'match-beginning
-                                                  (+ (,@ objc-type-depth) 2))
-                                        '(match-end 1)))
+                 (list 'goto-char
+                       (list 'or (list 'match-beginning
+                                       (+ (,@ objc-type-names-depth) 2))
+                             '(match-end 1)))
                  ;; Finish with point after first type specifier.
                  '(goto-char (match-end 1))
                  ;; Fontify as a variable or function name.
@@ -2694,13 +2975,26 @@ See also `objc-font-lock-extra-types'.")
                          font-lock-function-name-face
                        font-lock-variable-name-face)))))
     ;;
+    ;; Fontify all storage specs and types, plus their items.
+    `(eval .
+      (list (concat "\\<\\(" (,@ objc-type-specs) "[ \t]*\\)+\\>"
+                   "[ \t]*\\(\\sw+\\)?")
+           ;; The name of any type.
+           (list (+ (,@ objc-type-specs-depth) 2) 'font-lock-type-face nil t)
+           ;; Fontify each declaration item.
+           (list 'font-lock-match-c++-style-declaration-item-and-skip-to-next
+                 nil nil
+                 ;; Fontify as a variable or function name.
+                 '(1 (if (match-beginning 2)
+                         font-lock-function-name-face
+                       font-lock-variable-name-face)))
+           ))
+    ;;
     ;; Fontify structures, or typedef names, plus their items.
     '("\\(}\\)[ \t*]*\\sw"
       (font-lock-match-c-style-declaration-item-and-skip-to-next
        (goto-char (match-end 1)) nil
-       (1 (if (match-beginning 2)
-             font-lock-function-name-face
-           font-lock-variable-name-face))))
+       (1 font-lock-type-face)))
     ;;
     ;; Fontify anything at beginning of line as a declaration or definition.
     '("^\\(\\sw+\\)\\>\\([ \t*]+\\sw+\\>\\)*"
@@ -2730,87 +3024,92 @@ See also `java-font-lock-extra-types'.")
   "Gaudy level highlighting for Java mode.
 See also `java-font-lock-extra-types'.")
 
-;; Regexps written with help from Fred White <fwhite@bbn.com> and
-;; Anders Lindgren <andersl@csd.uu.se>.
+;; Regexps written with help from Fred White <fwhite@bbn.com>,
+;; Anders Lindgren <andersl@andersl.com> and Carl Manning <caroma@ai.mit.edu>.
 (let* ((java-keywords
        (eval-when-compile
          (regexp-opt
           '("catch" "do" "else" "super" "this" "finally" "for" "if"
-            ;; Anders Lindgren <andersl@csd.uu.se> says these have gone.
+            ;; Anders Lindgren <andersl@andersl.com> says these have gone.
             ;; "cast" "byvalue" "future" "generic" "operator" "var"
             ;; "inner" "outer" "rest"
+            "implements" "extends" "throws" "instanceof" "new"
             "interface" "return" "switch" "throw" "try" "while") t)))
        ;;
-       ;; These are immediately followed by an object name.
-       (java-minor-types
-       (eval-when-compile
-         (regexp-opt '("boolean" "char" "byte" "short" "int" "long"
-                       "float" "double" "void"))))
+       ;; Classes immediately followed by an object name.
+       (java-type-names
+       `(mapconcat 'identity
+         (cons
+          (,@ (eval-when-compile
+                (regexp-opt '("boolean" "char" "byte" "short" "int" "long"
+                              "float" "double" "void"))))
+          java-font-lock-extra-types)
+         "\\|"))
+       (java-type-names-depth `(regexp-opt-depth (,@ java-type-names)))
        ;;
        ;; These are eventually followed by an object name.
-       (java-major-types
+       (java-type-specs
        (eval-when-compile
          (regexp-opt
           '("abstract" "const" "final" "synchronized" "transient" "static"
-            ;; Anders Lindgren <andersl@csd.uu.se> says this has gone.
+            ;; Anders Lindgren <andersl@andersl.com> says this has gone.
             ;; "threadsafe"
-            "volatile" "public" "private" "protected" "native"))))
-       ;;
-       ;; Random types immediately followed by an object name.
-       (java-other-types
-       '(mapconcat 'identity (cons "\\sw+\\.\\sw+" java-font-lock-extra-types)
-                   "\\|"))
-       (java-other-depth `(regexp-opt-depth (,@ java-other-types)))
+            "volatile" "public" "private" "protected" "native"
+            ;; Carl Manning <caroma@ai.mit.edu> says this is new.
+            "strictfp"))))
        )
  (setq java-font-lock-keywords-1
   (list
    ;;
    ;; Fontify class names.
    '("\\<\\(class\\)\\>[ \t]*\\(\\sw+\\)?"
-     (1 font-lock-type-face) (2 font-lock-function-name-face nil t))
+     (1 font-lock-keyword-face) (2 font-lock-type-face nil t))
    ;;
    ;; Fontify package names in import directives.
    '("\\<\\(import\\|package\\)\\>[ \t]*\\(\\sw+\\)?"
-     (1 font-lock-keyword-face) (2 font-lock-reference-face nil t))
+     (1 font-lock-keyword-face)
+     (2 font-lock-constant-face nil t)
+     ("\\=\\.\\(\\*\\|\\sw+\\)" nil nil
+      (1 font-lock-constant-face nil t)))
    ))
 
  (setq java-font-lock-keywords-2
   (append java-font-lock-keywords-1
    (list
     ;;
-    ;; Fontify all builtin type specifiers.
-    (cons (concat "\\<\\(" java-minor-types "\\|" java-major-types "\\)\\>")
-         'font-lock-type-face)
+    ;; Fontify class names.
+    `(eval .
+      (cons (concat "\\<\\(" (,@ java-type-names) "\\)\\>[^.]")
+           '(1 font-lock-type-face)))
     ;;
     ;; Fontify all builtin keywords (except below).
-    (concat "\\<" java-keywords "\\>")
+    (concat "\\<\\(" java-keywords "\\|" java-type-specs "\\)\\>")
     ;;
     ;; Fontify keywords and targets, and case default/goto tags.
     (list "\\<\\(break\\|case\\|continue\\|goto\\)\\>[ \t]*\\(-?\\sw+\\)?"
-         '(1 font-lock-keyword-face) '(2 font-lock-reference-face nil t))
-    '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:"
+         '(1 font-lock-keyword-face) '(2 font-lock-constant-face nil t))
+    ;; This must come after the one for keywords and targets.
+    '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:[ \t]*$"
           (beginning-of-line) (end-of-line)
-          (1 font-lock-reference-face)))
-    ;;
-    ;; Fontify keywords and types; the first can be followed by a type list.
-    (list (concat "\\<\\("
-                 "implements\\|throws\\|"
-                 "\\(extends\\|instanceof\\|new\\)"
-                 "\\)\\>[ \t]*\\(\\sw+\\)?")
-         '(1 font-lock-keyword-face) '(3 font-lock-type-face nil t)
-         '("\\=[ \t]*,[ \t]*\\(\\sw+\\)"
-           (if (match-beginning 2) (goto-char (match-end 2))) nil
-           (1 font-lock-type-face)))
+          (1 font-lock-constant-face)))
     ;;
     ;; Fontify all constants.
-    '("\\<\\(false\\|null\\|true\\)\\>" . font-lock-reference-face)
+    '("\\<\\(false\\|null\\|true\\)\\>" . font-lock-constant-face)
     ;;
     ;; Javadoc tags within comments.
-    '("@\\(author\\|exception\\|return\\|see\\|version\\)\\>"
-      (1 font-lock-reference-face prepend))
+    (list
+     (concat "@\\("
+            "author\\|deprecated\\|exception"
+            "\\|link\\|return\\|see\\|serial\\|serialData\\|serialField"
+            "\\|since\\|throws"
+            "\\|version"
+            "\\)\\>"))
     '("@\\(param\\)\\>[ \t]*\\(\\sw+\\)?"
-      (1 font-lock-reference-face prepend)
+      (1 font-lock-constant-face prepend)
       (2 font-lock-variable-name-face prepend t))
+    '("@\\(exception\\|throws\\)\\>[ \t]*\\(\\S-+\\)?"
+      (1 font-lock-constant-face prepend)
+      (2 font-lock-type-face prepend t))
     )))
 
  (setq java-font-lock-keywords-3
@@ -2820,50 +3119,25 @@ See also `java-font-lock-extra-types'.")
    ;; We still have to fontify type specifiers individually, as Java is hairy.
    (list
     ;;
-    ;; Fontify random types in casts.
-    `(eval .
-      (list (concat "(\\(" (,@ java-other-types) "\\))"
-                   "[ \t]*\\(\\sw\\|[\"\(]\\)")
-           ;; Fontify the type name.
-           '(1 font-lock-type-face)))
-    ;;
     ;; Fontify random types immediately followed by an item or items.
     `(eval .
-      (list (concat "\\<\\(" (,@ java-other-types) "\\)\\>"
-                   "\\([ \t]*\\[[ \t]*\\]\\)*"
-                   "[ \t]*\\sw")
-           ;; Fontify the type name.
-           '(1 font-lock-type-face)))
-    `(eval .
-      (list (concat "\\<\\(" (,@ java-other-types) "\\)\\>"
+      (list (concat "\\<\\(" (,@ java-type-names) "\\)\\>"
                    "\\([ \t]*\\[[ \t]*\\]\\)*"
                    "\\([ \t]*\\sw\\)")
            ;; Fontify each declaration item.
            (list 'font-lock-match-c-style-declaration-item-and-skip-to-next
                  ;; Start and finish with point after the type specifier.
                  (list 'goto-char (list 'match-beginning
-                                        (+ (,@ java-other-depth) 3)))
+                                        (+ (,@ java-type-names-depth) 3)))
                  (list 'goto-char (list 'match-beginning
-                                        (+ (,@ java-other-depth) 3)))
+                                        (+ (,@ java-type-names-depth) 3)))
                  ;; Fontify as a variable or function name.
                  '(1 (if (match-beginning 2)
                          font-lock-function-name-face
                        font-lock-variable-name-face)))))
     ;;
-    ;; Fontify those that are immediately followed by an item or items.
-    (list (concat "\\<\\(" java-minor-types "\\)\\>"
-                 "\\([ \t]*\\[[ \t]*\\]\\)*")
-         ;; Fontify each declaration item.
-         '(font-lock-match-c-style-declaration-item-and-skip-to-next
-           ;; Start and finish with point after the type specifier.
-           nil (goto-char (match-end 0))
-           ;; Fontify as a variable or function name.
-           (1 (if (match-beginning 2)
-                  font-lock-function-name-face
-                font-lock-variable-name-face))))
-    ;;
     ;; Fontify those that are eventually followed by an item or items.
-    (list (concat "\\<\\(" java-major-types "\\)\\>"
+    (list (concat "\\<\\(" java-type-specs "\\)\\>"
                  "\\([ \t]+\\sw+\\>"
                  "\\([ \t]*\\[[ \t]*\\]\\)*"
                  "\\)*")