(vc-diff-internal, vc-coding-system-for-diff, vc-default-diff-tree):
[bpt/emacs.git] / lisp / font-lock.el
index bb03507..ef4bf6f 100644 (file)
@@ -1,6 +1,6 @@
 ;;; font-lock.el --- Electric font lock mode
 
-;; Copyright (C) 1992, 93, 94, 95, 96, 97, 98, 1999, 2000
+;; Copyright (C) 1992, 93, 94, 95, 96, 97, 98, 1999, 2000, 2001
 ;;  Free Software Foundation, Inc.
 
 ;; Author: jwz, then rms, then sm
@@ -300,6 +300,46 @@ If a number, only buffers greater than this size have fontification messages."
                 (integer :tag "size"))
   :group 'font-lock)
 \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-doc-face             'font-lock-doc-face
+  "Face name to use for documentation.")
+
+(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'.")
+
 ;; Fontification variables:
 
 (defvar font-lock-keywords nil
@@ -313,12 +353,17 @@ Each element should have one of these forms:
  (MATCHER HIGHLIGHT ...)
  (eval . FORM)
 
-where HIGHLIGHT should be either MATCH-HIGHLIGHT or MATCH-ANCHORED.
+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'.
 
 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.
 
+HIGHLIGHT should be either MATCH-HIGHLIGHT or MATCH-ANCHORED.
+
 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
@@ -329,13 +374,14 @@ 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) 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].
+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].  Instead of a face, FACENAME can
+evaluate to a property list of the form (face VAL1 PROP2 VAL2 PROP3 VAL3 ...)
+in which case all the listed text-properties will be set rather than
+just `face'.  In such a case, you will most likely want to put those
+properties in `font-lock-extra-managed-props' or to override
+`font-lock-unfontify-region-function'.
 
 OVERRIDE and LAXMATCH are flags.  If OVERRIDE is t, existing fontification can
 be overwritten.  If `keep', only parts not already fontified are highlighted.
@@ -444,6 +490,8 @@ 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'.")
+;;;###autoload
+(make-variable-buffer-local 'font-lock-defaults)
 
 ;; This variable is used where font-lock.el itself supplies the keywords.
 (defvar font-lock-defaults-alist
@@ -474,37 +522,27 @@ and those for buffer-specialised fontification functions,
         '((lisp-font-lock-keywords
            lisp-font-lock-keywords-1 lisp-font-lock-keywords-2)
           nil nil (("+-*/.<>=!?$%_&~^:" . "w")) beginning-of-defun
-          (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.
-       (tex-mode-defaults
-        '((tex-font-lock-keywords
-           tex-font-lock-keywords-1 tex-font-lock-keywords-2)
-          nil nil ((?$ . "\"")) nil
-          (font-lock-mark-block-function . mark-paragraph)))
-       )
+          (font-lock-mark-block-function . mark-defun))))
     (list
      (cons 'c-mode                     c-mode-defaults)
      (cons 'c++-mode                   c++-mode-defaults)
      (cons 'objc-mode                  objc-mode-defaults)
      (cons 'java-mode                  java-mode-defaults)
      (cons 'emacs-lisp-mode            lisp-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 'slitex-mode                        tex-mode-defaults)
-     (cons 'tex-mode                   tex-mode-defaults)))
+     (cons 'lisp-interaction-mode      lisp-mode-defaults)))
   "Alist of fall-back Font Lock defaults for major modes.
+
+This variable should not be used any more.
+Set the buffer-local `font-lock-keywords' in the major mode instead.
+
 Each item should be a list of the form:
 
  (MAJOR-MODE . FONT-LOCK-DEFAULTS)
 
 where MAJOR-MODE is a symbol and FONT-LOCK-DEFAULTS is a list of default
 settings.  See the variable `font-lock-defaults', which takes precedence.")
+(make-obsolete-variable 'font-lock-defaults-alist 'font-lock-defaults)
 
 (defvar font-lock-keywords-alist nil
   "*Alist of `font-lock-keywords' local to a `major-mode'.
@@ -523,6 +561,21 @@ This is normally set via `font-lock-defaults'.")
 (defvar font-lock-keywords-case-fold-search nil
   "*Non-nil means the patterns in `font-lock-keywords' are case-insensitive.
 This is normally set via `font-lock-defaults'.")
+(make-variable-buffer-local 'font-lock-keywords-case-fold-search)
+
+(defvar font-lock-syntactically-fontified 0
+  "Point up to which `font-lock-syntactic-keywords' has been applied.
+If nil, this is ignored, in which case the syntactic fontification may
+sometimes be slightly incorrect.")
+(make-variable-buffer-local 'font-lock-syntactically-fontified)
+
+(defvar font-lock-syntactic-face-function
+  (lambda (state)
+    (if (nth 3 state) font-lock-string-face font-lock-comment-face))
+  "Function to determine which face to use when fontifying syntactically.
+The function is called with a single parameter (the state as returned by
+`parse-partial-sexp' at the beginning of the region to highlight) and
+should return a face.")
 
 (defvar font-lock-syntactic-keywords nil
   "A list of the syntactic keywords to highlight.
@@ -532,28 +585,26 @@ the differences are listed below.  MATCH-HIGHLIGHT should be of the form:
 
  (MATCH SYNTAX OVERRIDE LAXMATCH)
 
-where SYNTAX can be of the form (SYNTAX-CODE . MATCHING-CHAR) (see
-also `string-to-syntax'), 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'.
+where SYNTAX can be a string (as taken by `modify-syntax-entry'), a syntax
+table, a cons cell (as returned by `string-to-syntax') or an expression whose
+value is such a form.  OVERRIDE cannot be `prepend' or `append'.
 
 For example, an element of the form highlights syntactically:
 
- (\"\\\\$\\\\(#\\\\)\" 1 (1 . nil))
+ (\"\\\\$\\\\(#\\\\)\" 1 \".\")
 
- a hash character when following a dollar character, with a SYNTAX-CODE of
1 (meaning punctuation syntax).  Assuming that the buffer syntax table does
+ a hash character when following a dollar character, with a SYNTAX of
\".\" (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 . ?')))
+  (1 \"\\\"\")
+  (2 \"\\\"\"))
 
- 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
+ both single quotes which surround a single character, with a SYNTAX of
+ \"\\\"\" (meaning string quote syntax).  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.
@@ -605,19 +656,14 @@ 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
+(defvar font-lock-multiline nil
   "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.
-
-;;;###autoload
-(defvar font-lock-mode-hook nil
-  "Function or functions to run on entry to Font Lock mode.")
 \f
 ;; Font Lock mode.
 
@@ -633,7 +679,7 @@ Major/minor modes can set this variable if they know which option applies.")
     `(let* ,(append varlist
                    '((modified (buffer-modified-p)) (buffer-undo-list t)
                      (inhibit-read-only t) (inhibit-point-motion-hooks t)
-                     before-change-functions after-change-functions
+                     (inhibit-modification-hooks t)
                      deactivate-mark buffer-file-name buffer-file-truename))
        ,@body
        (when (and (not modified) (buffer-modified-p))
@@ -642,15 +688,15 @@ Major/minor modes can set this variable if they know which option applies.")
   (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))
+  (defvar font-lock-face-attributes))  ; Obsolete but respected if set.
 
 ;;;###autoload
-(defun font-lock-mode (&optional arg)
+(define-minor-mode font-lock-mode
   "Toggle Font Lock mode.
-With arg, turn Font Lock mode on if and only if arg is positive.
+With arg, turn Font Lock mode off if and only if arg is a non-positive
+number; if arg is nil, toggle Font Lock mode; anything else turns Font
+Lock on.
+\(Font Lock is also known as \"syntax highlighting\".)
 
 When Font Lock mode is enabled, text is fontified as you type it:
 
@@ -659,6 +705,9 @@ When Font Lock mode is enabled, text is fontified as you type it:
  - Certain other expressions are displayed in other faces according to the
    value of the variable `font-lock-keywords'.
 
+To customize the faces (colors, fonts, etc.) used by Font Lock for
+fontifying different parts of buffer text, use \\[customize-face].
+
 You can enable Font Lock mode in any major mode automatically by turning on in
 the major mode's hook.  For example, put in your ~/.emacs:
 
@@ -697,43 +746,36 @@ syntactic change on other lines, you can use \\[font-lock-fontify-block].
 See the variable `font-lock-defaults-alist' for the Font Lock mode default
 settings.  You can set your own default settings for some mode, by setting a
 buffer local value for `font-lock-defaults', via its mode hook."
-  (interactive "P")
+  nil nil nil
   ;; Don't turn on Font Lock mode if we don't have a display (we're running a
   ;; batch job) or if the buffer is invisible (the name starts with a space).
-  (let ((on-p (and (not noninteractive)
-                  (not (eq (aref (buffer-name) 0) ?\ ))
-                  (if arg
-                      (> (prefix-numeric-value arg) 0)
-                    (not font-lock-mode)))))
-    (set (make-local-variable 'font-lock-mode) on-p)
-    ;; Turn on Font Lock mode.
-    (when on-p
-      (make-local-hook 'after-change-functions)
-      (add-hook 'after-change-functions 'font-lock-after-change-function nil t)
-      (font-lock-set-defaults)
-      (font-lock-turn-on-thing-lock)
-      (run-hooks 'font-lock-mode-hook)
-      ;; Fontify the buffer if we have to.
-      (let ((max-size (font-lock-value-in-major-mode font-lock-maximum-size)))
-       (cond (font-lock-fontified
-              nil)
-             ((or (null max-size) (> max-size (buffer-size)))
-              (font-lock-fontify-buffer))
-             (font-lock-verbose
-              (message "Fontifying %s...buffer size greater than font-lock-maximum-size"
-                       (buffer-name))))))
-    ;; Turn off Font Lock mode.
-    (unless on-p
-      (remove-hook 'after-change-functions 'font-lock-after-change-function t)
-      (font-lock-unfontify-buffer)
-      (font-lock-turn-off-thing-lock)
-      (font-lock-unset-defaults))
-    (force-mode-line-update)))
+  (when (or noninteractive (eq (aref (buffer-name) 0) ?\ ))
+    (setq font-lock-mode nil))
+
+  ;; Turn on Font Lock mode.
+  (when font-lock-mode
+    (add-hook 'after-change-functions 'font-lock-after-change-function nil t)
+    (font-lock-set-defaults)
+    (font-lock-turn-on-thing-lock)
+    ;; Fontify the buffer if we have to.
+    (let ((max-size (font-lock-value-in-major-mode font-lock-maximum-size)))
+      (cond (font-lock-fontified
+            nil)
+           ((or (null max-size) (> max-size (buffer-size)))
+            (font-lock-fontify-buffer))
+           (font-lock-verbose
+            (message "Fontifying %s...buffer size greater than font-lock-maximum-size"
+                     (buffer-name))))))
+  ;; Turn off Font Lock mode.
+  (unless font-lock-mode
+    (remove-hook 'after-change-functions 'font-lock-after-change-function t)
+    (font-lock-unfontify-buffer)
+    (font-lock-turn-off-thing-lock)
+    (font-lock-unset-defaults)))
 
 ;;;###autoload
 (defun turn-on-font-lock ()
-  "Turn on Font Lock mode conditionally.
-Turn on only if the terminal can display it."
+  "Turn on Font Lock mode (only if the terminal can display it)."
   (unless font-lock-mode
     (font-lock-mode)))
 
@@ -757,6 +799,10 @@ For example:
 adds two fontification patterns for C mode, to fontify `FIXME:' words, even in
 comments, and to fontify `and', `or' and `not' words as keywords.
 
+When used from an elisp package (such as a minor mode), it is recommended
+to use nil for MODE (and place the call in a loop or on a hook) to avoid
+subtle problems due to details of the implementation.
+
 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'."
@@ -834,7 +880,11 @@ see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types',
   "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."
+or nil.  If nil, highlighting keywords are removed for the current buffer.
+
+When used from an elisp package (such as a minor mode), it is recommended
+to use nil for MODE (and place the call in a loop or on a hook) to avoid
+subtle problems due to details of the implementation."
   (cond (mode
         ;; Remove one keyword at the time.
         (dolist (keyword keywords)
@@ -934,53 +984,6 @@ or nil.  If nil, highlighting keywords are removed for the current buffer."
 ;; loading a file tells you nothing about the feature or how to control it.  It
 ;; would also be contrary to the Principle of Least Surprise.  sm.
 
-(defvar font-lock-buffers nil)         ; For remembering buffers.
-
-;;;###autoload
-(defun global-font-lock-mode (&optional arg message)
-  "Toggle Global Font Lock mode.
-With prefix ARG, turn Global Font Lock mode on if and only if ARG is positive.
-Displays a message saying whether the mode is on or off if MESSAGE is non-nil.
-Returns the new status of Global Font Lock mode (non-nil means on).
-
-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'."
-  (interactive "P\np")
-  (let ((on-p (if arg
-                 (> (prefix-numeric-value arg) 0)
-               (not global-font-lock-mode))))
-    (cond (on-p
-          (add-hook 'find-file-hooks 'turn-on-font-lock-if-enabled)
-          (add-hook 'post-command-hook 'turn-on-font-lock-if-enabled)
-          (setq font-lock-buffers (buffer-list)))
-         (t
-          (remove-hook 'find-file-hooks 'turn-on-font-lock-if-enabled)
-          (mapc (function (lambda (buffer)
-                            (with-current-buffer buffer
-                              (when font-lock-mode
-                                (font-lock-mode)))))
-                  (buffer-list))))
-    (when message
-      (message "Global Font Lock mode %s." (if on-p "enabled" "disabled")))
-    (setq global-font-lock-mode on-p)))
-
-;; 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'.
-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 command `global-font-lock-mode'.
@@ -999,38 +1002,20 @@ means that Font Lock mode is turned on for buffers in C and C++ modes only."
                      (repeat :inline t (symbol :tag "mode"))))
   :group 'font-lock)
 
-(defun font-lock-change-major-mode ()
-  ;; Turn off Font Lock mode if it's on.
-  (when font-lock-mode
-    (font-lock-mode))
-  ;; Gross hack warning: Delicate readers should avert eyes now.
-  ;; Something is running `kill-all-local-variables', which generally means the
-  ;; major mode is being changed.  Run `turn-on-font-lock-if-enabled' after the
-  ;; file is visited or the current command has finished.
-  (when global-font-lock-mode
-    (add-hook 'post-command-hook 'turn-on-font-lock-if-enabled)
-    (add-to-list 'font-lock-buffers (current-buffer))))
-
 (defun turn-on-font-lock-if-enabled ()
-  ;; Gross hack warning: Delicate readers should avert eyes now.
-  ;; Turn on Font Lock mode if it's supported by the major mode and enabled by
-  ;; the user.
-  (remove-hook 'post-command-hook 'turn-on-font-lock-if-enabled)
-  (while font-lock-buffers
-    (when (buffer-live-p (car font-lock-buffers))
-      (save-excursion
-       (set-buffer (car font-lock-buffers))
-       (when (and (or font-lock-defaults
-                      (assq major-mode font-lock-defaults-alist))
-                  (or (eq font-lock-global-modes t)
-                      (if (eq (car-safe font-lock-global-modes) 'not)
-                          (not (memq major-mode (cdr font-lock-global-modes)))
-                        (memq major-mode font-lock-global-modes))))
-         (let (inhibit-quit)
-           (turn-on-font-lock)))))
-    (setq font-lock-buffers (cdr font-lock-buffers))))
-
-(add-hook 'change-major-mode-hook 'font-lock-change-major-mode)
+  (when (and (or font-lock-defaults
+                (assq major-mode font-lock-defaults-alist))
+            (or (eq font-lock-global-modes t)
+                (if (eq (car-safe font-lock-global-modes) 'not)
+                    (not (memq major-mode (cdr font-lock-global-modes)))
+                  (memq major-mode font-lock-global-modes))))
+    (let (inhibit-quit)
+      (turn-on-font-lock))))
+
+;;;###autoload
+(easy-mmode-define-global-mode
+ global-font-lock-mode font-lock-mode turn-on-font-lock-if-enabled
+ :extra-args (dummy))
 
 ;;; End of Global Font Lock mode.
 \f
@@ -1062,7 +1047,7 @@ The value of this variable is used when Font Lock mode is turned on."
                 (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))
+                        :value ((t . jit-lock-mode))
                         (cons :tag "Instance"
                               (radio :tag "Mode"
                                      (const :tag "all" t)
@@ -1087,15 +1072,26 @@ The value of this variable is used when Font Lock mode is turned on."
          ((eq thing-mode 'lazy-lock-mode)
           (lazy-lock-mode t))
          ((eq thing-mode 'jit-lock-mode)
-          (jit-lock-mode t)))))
+          ;; Prepare for jit-lock
+          (remove-hook 'after-change-functions
+                       'font-lock-after-change-function t)
+          (set (make-local-variable 'font-lock-fontify-buffer-function)
+               'jit-lock-refontify)
+          ;; Don't fontify eagerly (and don't abort is the buffer is large).
+          (set (make-local-variable 'font-lock-fontified) t)
+          ;; Use jit-lock.
+          (jit-lock-register 'font-lock-fontify-region
+                             (not font-lock-keywords-only))))))
 
 (defun font-lock-turn-off-thing-lock ()
   (cond (fast-lock-mode
-        (fast-lock-mode nil))
+        (fast-lock-mode -1))
        (jit-lock-mode
-        (jit-lock-mode nil))
+        (jit-lock-unregister 'font-lock-fontify-region)
+        ;; Reset local vars to the non-jit-lock case.
+        (kill-local-variable 'font-lock-fontify-buffer-function))
        (lazy-lock-mode
-        (lazy-lock-mode nil))))
+        (lazy-lock-mode -1))))
 
 (defun font-lock-after-fontify-buffer ()
   (cond (fast-lock-mode
@@ -1224,21 +1220,21 @@ The value of this variable is used when Font Lock mode is turned on."
            (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)))
+         (when (and font-lock-multiline
+                    (> beg (point-min))
+                    (get-text-property (1- beg) 'font-lock-multiline))
+           ;; We are just after or in a multiline match.
+           (setq beg (or (previous-single-property-change
+                          beg 'font-lock-multiline)
+                         (point-min)))
+           (goto-char beg)
+           (setq beg (line-beginning-position)))
+         (when font-lock-multiline
+           (setq end (or (text-property-any end (point-max)
+                                            'font-lock-multiline nil)
+                         (point-max))))
+         (goto-char end)
+         (setq end (line-beginning-position 2))
          ;; Now do the fontification.
          (font-lock-unfontify-region beg end)
          (when font-lock-syntactic-keywords
@@ -1401,10 +1397,9 @@ see `font-lock-syntactic-keywords'."
         (start (match-beginning match)) (end (match-end match))
         (value (nth 1 highlight))
         (override (nth 2 highlight)))
-    (cond ((stringp value)
-          (setq value (string-to-syntax value)))
-         ((not (numberp (car-safe value)))
-          (setq value (eval value))))
+    (when (and (consp value) (not (numberp (car value))))
+      (setq value (eval value)))
+    (when (stringp value) (setq value (string-to-syntax value)))
     (cond ((not start)
           ;; No match but we might not signal an error.
           (or (nth 3 highlight)
@@ -1447,6 +1442,11 @@ LIMIT can be modified by the value of its PRE-MATCH-FORM."
 (defun font-lock-fontify-syntactic-keywords-region (start end)
   "Fontify according to `font-lock-syntactic-keywords' between START and END.
 START should be at the beginning of a line."
+  ;; Ensure the beginning of the file is properly syntactic-fontified.
+  (when (and font-lock-syntactically-fontified
+            (< font-lock-syntactically-fontified start))
+    (setq start (max font-lock-syntactically-fontified (point-min)))
+    (setq font-lock-syntactically-fontified end))
   ;; If `font-lock-syntactic-keywords' is a symbol, get the real keywords.
   (when (symbolp font-lock-syntactic-keywords)
     (setq font-lock-syntactic-keywords (font-lock-eval-keywords
@@ -1493,7 +1493,7 @@ START should be at the beginning of a line."
   "Put proper face on each string and comment between START and END.
 START should be at the beginning of a line."
   (let ((cache (marker-position font-lock-cache-position))
-       state string beg)
+       state face beg)
     (if loudly (message "Fontifying %s... (syntactically...)" (buffer-name)))
     (goto-char start)
     ;;
@@ -1518,12 +1518,9 @@ START should be at the beginning of a line."
     ;;
     ;; If the region starts inside a string or comment, show the extent of it.
     (when (or (nth 3 state) (nth 4 state))
-      (setq string (nth 3 state) beg (point))
+      (setq face (funcall font-lock-syntactic-face-function state) beg (point))
       (setq state (parse-partial-sexp (point) end nil nil state 'syntax-table))
-      (put-text-property beg (point) 'face
-                        (if string
-                            font-lock-string-face
-                          font-lock-comment-face)))
+      (put-text-property beg (point) 'face face))
     ;;
     ;; Find each interesting place between here and `end'.
     (while (and (< (point) end)
@@ -1531,12 +1528,10 @@ START should be at the beginning of a line."
                  (setq state (parse-partial-sexp (point) end nil nil state
                                                  'syntax-table))
                  (or (nth 3 state) (nth 4 state))))
-      (setq string (nth 3 state) beg (nth 8 state))
+      (setq face (funcall font-lock-syntactic-face-function 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
-                            font-lock-string-face
-                          font-lock-comment-face)))))
+      (put-text-property beg (point) 'face face))))
 
 ;;; End of Syntactic fontification functions.
 \f
@@ -1581,13 +1576,14 @@ LIMIT can be modified by the value of its PRE-MATCH-FORM."
     (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
-                         (line-beginning-position 2)))
+      (when (and font-lock-multiline (>= limit (line-beginning-position 2)))
        ;; this is a multiline anchored match
-       (setq font-lock-multiline t)
-       (put-text-property (point) limit 'font-lock-multiline t)))
+       ;; (setq font-lock-multiline t)
+       (put-text-property (if (= limit (line-beginning-position 2))
+                              (1- limit)
+                            (min lead-start (point)))
+                          limit
+                          'font-lock-multiline t)))
     (save-match-data
       ;; Find an occurrence of `matcher' before `limit'.
       (while (and (< (point) limit)
@@ -1625,14 +1621,18 @@ START should be at the beginning of a line."
                      (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))))
+                  (>= (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)
+         ;; (setq font-lock-multiline t)
+         (put-text-property (if (= (point)
+                                   (save-excursion
+                                     (goto-char (match-beginning 0))
+                                     (forward-line 1) (point)))
+                                (1- (point))
+                              (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'.
@@ -1694,7 +1694,7 @@ Structure is ((MAJOR-MODE . VALUE) ...) where MAJOR-MODE may be t."
   "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)
+  (cond ((not (and (listp keywords) (symbolp (car keywords))))
         keywords)
        ((numberp level)
         (or (nth level keywords) (car (reverse keywords))))
@@ -1759,13 +1759,11 @@ Sets various variables using `font-lock-defaults' (or, if nil, using
        (set (make-local-variable 'font-lock-beginning-of-syntax-function)
             (nth 4 defaults)))
       ;; Variable alist?
-      (let ((alist (nthcdr 5 defaults)))
-       (while alist
-         (let ((variable (car (car alist))) (value (cdr (car alist))))
-           (unless (boundp variable)
-             (set variable nil))
-           (set (make-local-variable variable) value)
-           (setq alist (cdr alist))))))))
+      (dolist (x (nthcdr 5 defaults))
+       (let ((variable (car x)) (value (cdr x)))
+         (unless (boundp variable)
+           (set variable nil))         ;why ?
+         (set (make-local-variable variable) value))))))
 
 (defun font-lock-unset-defaults ()
   "Unset fontification defaults.  See function `font-lock-set-defaults'."
@@ -1784,42 +1782,6 @@ Sets various variables using `font-lock-defaults' (or, if nil, using
 \f
 ;;; Colour etc. support.
 
-;; 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.
 ;; However, we try and be back-compatible and respect its value if set except
@@ -1852,13 +1814,14 @@ 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
-  '((((type tty) (class color)) (:foreground "red"))
+  '((((type tty pc) (class color) (background light)) (:foreground "red"))
+    (((type tty pc) (class color) (background dark)) (:foreground "red1"))
     (((class grayscale) (background light))
      (:foreground "DimGray" :bold t :italic t))
     (((class grayscale) (background dark))
      (:foreground "LightGray" :bold t :italic t))
     (((class color) (background light)) (:foreground "Firebrick"))
-    (((class color) (background dark)) (:foreground "OrangeRed"))
+    (((class color) (background dark)) (:foreground "chocolate1"))
     (t (:bold t :italic t)))
   "Font Lock mode face used to highlight comments."
   :group 'font-lock-highlighting-faces)
@@ -1873,6 +1836,11 @@ Sets various variables using `font-lock-defaults' (or, if nil, using
   "Font Lock mode face used to highlight strings."
   :group 'font-lock-highlighting-faces)
 
+(defface font-lock-doc-face
+  '((t :inherit font-lock-string-face))
+  "Font Lock mode face used to highlight documentation."
+  :group 'font-lock-highlighting-faces)
+
 (defface font-lock-keyword-face
   '((((type tty) (class color)) (:foreground "cyan" :weight bold))
     (((class grayscale) (background light)) (:foreground "LightGray" :bold t))
@@ -2096,7 +2064,7 @@ This function could be MATCHER in a MATCH-ANCHORED `font-lock-keywords' item."
      ;; Definitions.
      (list (concat "(\\(def\\("
                   ;; Function declarations.
-                  "\\(advice\\|alias\\|generic\\|macro\\*?\\|method\\|"
+                  "\\(advice\\|varalias\\|alias\\|generic\\|macro\\*?\\|method\\|"
                    "setf\\|subst\\*?\\|un\\*?\\|"
                    "ine-\\(condition\\|\\(?:derived\\|minor\\)-mode\\|"
                    "method-combination\\|setf-expander\\|skeleton\\|widget\\|"
@@ -2187,131 +2155,6 @@ This function could be MATCHER in a MATCH-ANCHORED `font-lock-keywords' item."
 (defvar lisp-font-lock-keywords lisp-font-lock-keywords-1
   "Default expressions to highlight in Lisp modes.")
 \f
-;; TeX.
-
-;(defvar tex-font-lock-keywords
-;  ;; Regexps updated with help from Ulrik Dickow <dickow@nbi.dk>.
-;  '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}"
-;     2 font-lock-function-name-face)
-;    ("\\\\\\(cite\\|label\\|pageref\\|ref\\){\\([^} \t\n]+\\)}"
-;     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)
-;    ("{\\\\\\(em\\|it\\|sl\\)\\([^}]+\\)}" 2 'italic keep)
-;    ("\\\\\\([a-zA-Z@]+\\|.\\)" . font-lock-keyword-face)
-;    ("^[ \t\n]*\\\\def[\\\\@]\\(\\w+\\)" 1 font-lock-function-name-face keep))
-;  ;; Rewritten and extended for LaTeX2e by Ulrik Dickow <dickow@nbi.dk>.
-;  '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}"
-;     2 font-lock-function-name-face)
-;    ("\\\\\\(cite\\|label\\|pageref\\|ref\\){\\([^} \t\n]+\\)}"
-;     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
-;    ;; not be able to display those fonts.
-;    ;; LaTeX2e: \emph{This is emphasized}.
-;    ("\\\\emph{\\([^}]+\\)}" 1 'italic keep)
-;    ;; LaTeX2e: \textbf{This is bold}, \textit{...}, \textsl{...}
-;    ("\\\\text\\(\\(bf\\)\\|it\\|sl\\){\\([^}]+\\)}"
-;     3 (if (match-beginning 2) 'bold 'italic) keep)
-;    ;; Old-style bf/em/it/sl.  Stop at `\\' and un-escaped `&', for tables.
-;    ("\\\\\\(\\(bf\\)\\|em\\|it\\|sl\\)\\>\\(\\([^}&\\]\\|\\\\[^\\]\\)+\\)"
-;     3 (if (match-beginning 2) 'bold 'italic) keep))
-
-;; Rewritten with the help of Alexandra Bac <abac@welcome.disi.unige.it>.
-(defconst tex-font-lock-keywords-1
-  (eval-when-compile
-    (let* (;; Names of commands whose arg should be fontified as heading, etc.
-          (headings (regexp-opt
-                     '("title"  "begin" "end" "chapter" "part"
-                       "section" "subsection" "subsubsection"
-                       "paragraph" "subparagraph" "subsubparagraph"
-                       "newcommand" "renewcommand" "newenvironment"
-                       "newtheorem")
-                     t))
-          (variables (regexp-opt
-                      '("newcounter" "newcounter*" "setcounter" "addtocounter"
-                        "setlength" "addtolength" "settowidth")
-                      t))
-          (includes (regexp-opt
-                     '("input" "include" "includeonly" "bibliography"
-                       "epsfig" "psfig" "epsf" "nofiles" "usepackage"
-                       "includegraphics" "includegraphics*")
-                     t))
-          ;; Miscellany.
-          (slash "\\\\")
-          (opt "\\(\\[[^]]*\\]\\)?")
-          (arg "{\\(\\(?:[^{}]+\\(?:{[^}]*}\\)?\\)+\\)"))
-      (list
-       ;; Heading args.
-       (list (concat slash headings "\\*?" opt arg)
-            3 'font-lock-function-name-face 'prepend)
-       ;; Variable args.
-       (list (concat slash variables arg) 2 'font-lock-variable-name-face)
-       ;; Include args.
-       (list (concat slash includes opt arg) 3 'font-lock-builtin-face)
-       ;; Definitions.  I think.
-       '("^[ \t]*\\\\def\\\\\\(\\(\\w\\|@\\)+\\)"
-        1 font-lock-function-name-face)
-       )))
-  "Subdued expressions to highlight in TeX modes.")
-
-(defconst tex-font-lock-keywords-2
-  (append tex-font-lock-keywords-1
-   (eval-when-compile
-     (let* (;;
-           ;; Names of commands whose arg should be fontified with fonts.
-           (bold (regexp-opt '("bf" "textbf" "textsc" "textup"
-                               "boldsymbol" "pmb") t))
-           (italic (regexp-opt '("it" "textit" "textsl" "emph") t))
-           (type (regexp-opt '("texttt" "textmd" "textrm" "textsf") t))
-           ;;
-           ;; Names of commands whose arg should be fontified as a citation.
-           (citations (regexp-opt
-                       '("label" "ref" "pageref" "vref" "eqref"
-                         "cite" "nocite" "caption" "index" "glossary"
-                         "footnote" "footnotemark" "footnotetext")
-                       t))
-           ;;
-           ;; Names of commands that should be fontified.
-           (specials (regexp-opt
-                      '("\\"
-                        "linebreak" "nolinebreak" "pagebreak" "nopagebreak"
-                        "newline" "newpage" "clearpage" "cleardoublepage"
-                        "displaybreak" "allowdisplaybreaks" "enlargethispage")
-                      t))
-           (general "\\([a-zA-Z@]+\\**\\|[^ \t\n]\\)")
-           ;;
-           ;; Miscellany.
-           (slash "\\\\")
-           (opt "\\(\\[[^]]*\\]\\)?")
-           (arg "{\\(\\(?:[^{}]+\\(?:{[^}]*}\\)?\\)+\\)"))
-       (list
-       ;;
-       ;; Citation args.
-       (list (concat slash citations opt arg) 3 'font-lock-constant-face)
-       ;;
-       ;; Command names, special and general.
-       (cons (concat slash specials) 'font-lock-warning-face)
-       (concat slash general)
-       ;;
-       ;; Font environments.  It seems a bit dubious to use `bold' etc. faces
-       ;; since we might not be able to display those fonts.
-       (list (concat slash bold arg) 2 '(quote bold) 'append)
-       (list (concat slash italic arg) 2 '(quote italic) 'append)
-       (list (concat slash type arg) 2 '(quote bold-italic) 'append)
-       ;;
-       ;; Old-style bf/em/it/sl.  Stop at `\\' and un-escaped `&', for tables.
-       (list (concat "\\\\\\(\\(bf\\)\\|em\\|it\\|sl\\)\\>"
-                     "\\(\\([^}&\\]\\|\\\\[^\\]\\)+\\)")
-             3 '(if (match-beginning 2) 'bold 'italic) 'append)
-       ))))
-   "Gaudy expressions to highlight in TeX modes.")
-
-(defvar tex-font-lock-keywords tex-font-lock-keywords-1
-  "Default expressions to highlight in TeX modes.")
-\f
 ;;; User choices.
 
 ;; These provide a means to fontify types not defined by the language.  Those
@@ -2324,7 +2167,7 @@ Members should `:load' the package `font-lock' to use this widget."
   :args '((const :tag "none" nil)
          (repeat :tag "types" regexp)))
 
-(defcustom c-font-lock-extra-types '("FILE" "\\sw+_t")
+(defcustom c-font-lock-extra-types '("FILE" "\\sw+_t" "Lisp_Object")
   "*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 (\"FILE\" \"\\\\sw+_t\") means the word FILE and words
@@ -2412,10 +2255,10 @@ See also `c-font-lock-extra-types'.")
                        "typedef" "extern" "auto" "register" "static"
                        "volatile" "const"
                        ;; Dan Nicolaescu <done@gnu.org> says this is new.
-                       "restrict") t)))
+                       "restrict"))))
        (c-type-specs
        (eval-when-compile
-         (regexp-opt '("enum" "struct" "union") t)))
+         (regexp-opt '("enum" "struct" "union"))))
        (c-type-specs-depth
        (regexp-opt-depth c-type-specs))
        (c-type-names
@@ -2529,7 +2372,11 @@ See also `c-font-lock-extra-types'.")
          (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
+                 nil 
+                 ;; Finish with point after the variable name if
+                 ;; there is one.
+                 `(if (match-end 2) 
+                      (goto-char (match-end 2)))
                  ;; Fontify as a variable or function name.
                  '(1 (if (match-beginning 2)
                          font-lock-function-name-face
@@ -2632,7 +2479,10 @@ See also `c++-font-lock-extra-types'.")
             ;; as keywords not types.
             "typedef" "template"
             "extern" "auto" "register" "const" "volatile" "static"
-            "inline" "friend" "virtual") t)))
+            "inline" "friend" "virtual"
+            ;; Standard C++ operator names.
+            "and" "and_eq" "bitand" "bitor" "compl" "not" "not_eq"
+            "or" "or_eq" "xor" "xor_eq"))))
        (c++-operators
        (eval-when-compile
          (regexp-opt
@@ -2842,7 +2692,7 @@ See also `objc-font-lock-extra-types'.")
          (regexp-opt '("break" "continue" "do" "else" "for" "if" "return"
                        "switch" "while" "sizeof" "self" "super"
                        "typedef" "auto" "extern" "static"
-                       "volatile" "const") t)))
+                       "volatile" "const"))))
        (objc-type-specs
        (eval-when-compile
          (regexp-opt
@@ -3003,7 +2853,7 @@ See also `java-font-lock-extra-types'.")
             ;; "cast" "byvalue" "future" "generic" "operator" "var"
             ;; "inner" "outer" "rest"
             "implements" "extends" "throws" "instanceof" "new"
-            "interface" "return" "switch" "throw" "try" "while") t)))
+            "interface" "return" "switch" "throw" "try" "while"))))
        ;;
        ;; Classes immediately followed by an object name.
        (java-type-names
@@ -3072,7 +2922,8 @@ See also `java-font-lock-extra-types'.")
             "\\|link\\|return\\|see\\|serial\\|serialData\\|serialField"
             "\\|since\\|throws"
             "\\|version"
-            "\\)\\>"))
+            "\\)\\>")
+     '(1 font-lock-constant-face prepend))
     '("@\\(param\\)\\>[ \t]*\\(\\sw+\\)?"
       (1 font-lock-constant-face prepend)
       (2 font-lock-variable-name-face prepend t))
@@ -3127,15 +2978,11 @@ See also `java-font-lock-extra-types'.")
   "Default expressions to highlight in Java mode.
 See also `java-font-lock-extra-types'.")
 \f
-;; Install ourselves:
-
-;; Useful for the popup-menu for mouse-3 on the modeline.
-(unless (assq 'font-lock-mode minor-mode-alist)
-  (push '(font-lock-mode nil) minor-mode-alist))
-
 ;; Provide ourselves:
 
 (provide 'font-lock)
-(require 'jit-lock)
+
+(when (eq font-lock-support-mode 'jit-lock-mode)
+  (require 'jit-lock))
 
 ;;; font-lock.el ends here