(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.
(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.
(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
(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)
;; `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),
: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 "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))))
;; 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
(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)
(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.
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)
;; 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))
;; 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))
: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"))
: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"))
: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"))
: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))
: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"))
: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))
: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."
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.")
'("\\<:\\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.")
"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.
(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.