]> code.delx.au - gnu-emacs/blobdiff - lisp/font-lock.el
(Finternal_show_cursor_p): Fix doc string.
[gnu-emacs] / lisp / font-lock.el
index 48c69183ee1853fbb8b765cbb03e718717262fb7..9dcb8a3facb41dc019df962be783407ff912074a 100644 (file)
 (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.
 
@@ -585,8 +593,8 @@ 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 as `fast-lock-mode', `jit-lock-mode' and
+`lazy-lock-mode'.  This is normally set via `font-lock-defaults'.")
 
 (defvar font-lock-mode nil)            ; Whether we are turned on/modeline.
 (defvar font-lock-fontified nil)       ; Whether we have fontified the buffer.
@@ -708,7 +716,7 @@ 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)
+  (when (and (not font-lock-mode) (or window-system (tty-display-color-p)))
     (font-lock-mode)))
 
 ;;;###autoload
@@ -835,17 +843,19 @@ turned on in a buffer if its major mode is one of `font-lock-global-modes'."
       (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'.
-This variable should be set only with \\[customize], which is equivalent
-to using the function `global-font-lock-mode'."
+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)
@@ -911,11 +921,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),
@@ -928,6 +939,7 @@ 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"
@@ -937,35 +949,45 @@ The value of this variable is used when Font Lock mode is turned on."
                               (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))))
 
@@ -1071,6 +1093,16 @@ 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)
+                       (or (previous-single-property-change
+                            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
@@ -1091,9 +1123,10 @@ The value of this variable is used when Font Lock mode is turned on."
 
 (defun font-lock-default-unfontify-region (beg end)
   (save-buffer-state nil
-    (if font-lock-syntactic-keywords
-       (remove-text-properties beg end '(face nil syntax-table nil))
-      (remove-text-properties beg end '(face 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)
@@ -1232,7 +1265,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.
@@ -1403,12 +1436,16 @@ 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))))
+       (save-excursion (end-of-line) (setq limit (point)))
+      (setq limit pre-match-value)
+      (when (>= pre-match-value (save-excursion (forward-line 1) (point)))
+       ;; this is a multiline anchored match
+       (put-text-property (point) limit 'font-lock-multiline t)))
     (save-match-data
       ;; Find an occurrence of `matcher' before `limit'.
       (while (if (stringp matcher)
@@ -1440,9 +1477,17 @@ 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 (match-beginning 0)
+                  (>= (point)
+                      (save-excursion (goto-char (match-beginning 0))
+                                      (forward-line 1) (point))))
+         ;; this is a multiline regexp match
+         (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))
@@ -1655,7 +1700,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))
@@ -1666,7 +1712,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"))
@@ -1675,7 +1722,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"))
@@ -1684,7 +1732,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"))
@@ -1693,14 +1742,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))
@@ -1711,7 +1762,8 @@ 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"))
@@ -1720,7 +1772,8 @@ Sets various variables using `font-lock-defaults' (or, if nil, using
   :group 'font-lock-highlighting-faces)
 
 (defface font-lock-constant-face
-  '((((class grayscale) (background light))
+  '((((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))
@@ -1731,7 +1784,8 @@ Sets various variables using `font-lock-defaults' (or, if nil, using
   :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."
@@ -1910,7 +1964,7 @@ This function could be MATCHER in a MATCH-ANCHORED `font-lock-keywords' item."
               nil t))
      ;;
      ;; Emacs Lisp autoload cookies.
-     '("^;;;###\\(autoload\\)\\>" 1 font-lock-warning-face prepend)
+     '("^;;;###\\(autoload\\)" 1 font-lock-warning-face prepend)
      ))
   "Subdued level highlighting for Lisp modes.")
 
@@ -1971,7 +2025,7 @@ This function could be MATCHER in a MATCH-ANCHORED `font-lock-keywords' item."
       '("\\<:\\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.")
 
@@ -2179,6 +2233,7 @@ The value of this variable is used when Font Lock mode is turned on."
     "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.
@@ -2425,6 +2480,7 @@ See also `c++-font-lock-extra-types'.")
          (regexp-opt
           '("break" "continue" "do" "else" "for" "if" "return" "switch"
             "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.