(vc-diff-internal, vc-coding-system-for-diff, vc-default-diff-tree):
[bpt/emacs.git] / lisp / font-lock.el
index 9c7b58a..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
@@ -353,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
@@ -369,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.
@@ -555,6 +561,7 @@ 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.
@@ -649,7 +656,7 @@ 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.
@@ -672,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))
@@ -686,7 +693,9 @@ Major/minor modes can set this variable if they know which option applies.")
 ;;;###autoload
 (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:
@@ -790,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'."
@@ -867,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)
@@ -1203,7 +1220,8 @@ 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
-         (when (and (> beg (point-min))
+         (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
@@ -1211,11 +1229,12 @@ The value of this variable is used when Font Lock mode is turned on."
                          (point-min)))
            (goto-char beg)
            (setq beg (line-beginning-position)))
-         (setq end (or (text-property-any end (point-max)
-                                          'font-lock-multiline nil)
-                       (point-max)))
+         (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-end-position))
+         (setq end (line-beginning-position 2))
          ;; Now do the fontification.
          (font-lock-unfontify-region beg end)
          (when font-lock-syntactic-keywords
@@ -1602,7 +1621,6 @@ 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)
                   (>= (point)
                       (save-excursion (goto-char (match-beginning 0))
                                       (forward-line 1) (point))))
@@ -1741,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'."
@@ -1799,7 +1815,7 @@ Sets various variables using `font-lock-defaults' (or, if nil, using
 ;; faces declared above via `custom-declare-face'.
 (defface font-lock-comment-face
   '((((type tty pc) (class color) (background light)) (:foreground "red"))
-    (((type tty pc) (class color) (background dark)) (:foreground "lightred"))
+    (((type tty pc) (class color) (background dark)) (:foreground "red1"))
     (((class grayscale) (background light))
      (:foreground "DimGray" :bold t :italic t))
     (((class grayscale) (background dark))
@@ -2048,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\\|"
@@ -2151,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
@@ -2356,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
@@ -2459,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"))))
+            "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
@@ -2958,6 +2981,8 @@ See also `java-font-lock-extra-types'.")
 ;; 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