+;; Define core `font-lock' group.
+(defgroup font-lock nil
+ "Font Lock mode text highlighting package."
+ :link '(custom-manual "(emacs)Font Lock")
+ :group 'faces)
+
+(defgroup font-lock-highlighting-faces nil
+ "Faces for highlighting text."
+ :prefix "font-lock-"
+ :group 'font-lock)
+
+(defgroup font-lock-extra-types nil
+ "Extra mode-specific type names for highlighting declarations."
+ :group 'font-lock)
+
+;; Define support mode groups here to impose `font-lock' group order.
+(defgroup fast-lock nil
+ "Font Lock support mode to cache fontification."
+ :link '(custom-manual "(emacs)Support Modes")
+ :load 'fast-lock
+ :group 'font-lock)
+
+(defgroup lazy-lock nil
+ "Font Lock support mode to fontify lazily."
+ :link '(custom-manual "(emacs)Support Modes")
+ :load 'lazy-lock
+ :group 'font-lock)
+\f
+;; User variables.
+
+(defcustom font-lock-maximum-size (* 250 1024)
+ "*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.
+If a list, each element should be a cons pair of the form (MAJOR-MODE . SIZE),
+where MAJOR-MODE is a symbol or t (meaning the default). For example:
+ ((c-mode . 256000) (c++-mode . 256000) (rmail-mode . 1048576))
+means that the maximum size is 250K for buffers in C or C++ modes, one megabyte
+for buffers in Rmail mode, and size is irrelevant otherwise."
+ :type '(choice (const :tag "none" nil)
+ (integer :tag "size")
+ (repeat :menu-tag "mode specific" :tag "mode specific"
+ :value ((t . nil))
+ (cons :tag "Instance"
+ (radio :tag "Mode"
+ (const :tag "all" t)
+ (symbol :tag "name"))
+ (radio :tag "Size"
+ (const :tag "none" nil)
+ (integer :tag "size")))))
+ :group 'font-lock)
+
+(defcustom font-lock-maximum-decoration t
+ "*Maximum decoration level for fontification.
+If nil, use the default decoration (typically the minimum available).
+If t, use the maximum decoration available.
+If a number, use that level of decoration (or if not available the maximum).
+If a list, each element should be a cons pair of the form (MAJOR-MODE . LEVEL),
+where MAJOR-MODE is a symbol or t (meaning the default). For example:
+ ((c-mode . t) (c++-mode . 2) (t . 1))
+means use the maximum decoration available for buffers in C mode, level 2
+decoration for buffers in C++ mode, and level 1 decoration otherwise."
+ :type '(choice (const :tag "default" nil)
+ (const :tag "maximum" t)
+ (integer :tag "level" 1)
+ (repeat :menu-tag "mode specific" :tag "mode specific"
+ :value ((t . t))
+ (cons :tag "Instance"
+ (radio :tag "Mode"
+ (const :tag "all" t)
+ (symbol :tag "name"))
+ (radio :tag "Decoration"
+ (const :tag "default" nil)
+ (const :tag "maximum" t)
+ (integer :tag "level" 1)))))
+ :group 'font-lock)
+
+(defcustom font-lock-verbose (* 0 1024)
+ "*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)
+ (integer :tag "size")
+ (other :tag "always" t))
+ :group 'font-lock)
+\f
+;; Fontification variables:
+
+(defvar font-lock-keywords nil
+ "A list of the keywords to highlight.
+Each element should have one of these forms:
+
+ MATCHER
+ (MATCHER . MATCH)
+ (MATCHER . FACENAME)
+ (MATCHER . HIGHLIGHT)
+ (MATCHER HIGHLIGHT ...)
+ (eval . FORM)
+
+where HIGHLIGHT should be either MATCH-HIGHLIGHT or MATCH-ANCHORED.
+
+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, 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), 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) 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. 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].
+
+OVERRIDE and LAXMATCH are flags. If OVERRIDE is t, existing fontification can
+be overwritten. If `keep', only parts not already fontified are highlighted.
+If `prepend' or `append', existing fontification is merged with the new, in
+which the new or existing fontification, respectively, takes precedence.
+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
+ variable `font-lock-keyword-face'.
+ (\"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
+ 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 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,
+PRE-MATCH-FORM is used to move to some position relative to the original
+MATCHER, before starting with MATCH-ANCHORED's MATCHER. POST-MATCH-FORM might
+be used to move, before resuming with MATCH-ANCHORED's parent's MATCHER.
+
+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 \"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
+ searching for subsequent instance of \"anchor\" resumes from where searching
+ for \"item\" concluded.)
+
+The above-mentioned exception is as follows. The limit of the MATCHER search
+defaults to the end of the line after PRE-MATCH-FORM is evaluated.
+However, if PRE-MATCH-FORM returns a position greater than the position after
+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.
+
+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.
+
+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
+dramatically slow things down!")
+
+;; This variable is used by mode packages that support Font Lock mode by
+;; defining their own keywords to use for `font-lock-keywords'. (The mode
+;; command should make it buffer-local and set it to provide the set up.)
+(defvar font-lock-defaults nil
+ "Defaults for Font Lock mode specified by the major mode.
+Defaults should be of the form:
+
+ (KEYWORDS KEYWORDS-ONLY CASE-FOLD SYNTAX-ALIST SYNTAX-BEGIN ...)
+
+KEYWORDS may be a symbol (a variable or function whose value is the keywords to
+use for fontification) or a list of symbols. If KEYWORDS-ONLY is non-nil,
+syntactic fontification (strings and comments) is not performed.
+If CASE-FOLD is non-nil, the case of the keywords is ignored when fontifying.
+If SYNTAX-ALIST is non-nil, it should be a list of cons pairs of the form
+\(CHAR-OR-STRING . STRING) used to set the local Font Lock syntax table, for
+keyword and syntactic fontification (see `modify-syntax-entry').
+
+If SYNTAX-BEGIN is non-nil, it should be a function with no args used to move
+backwards outside any enclosing syntactic block, for syntactic fontification.
+Typical values are `beginning-of-line' (i.e., the start of the line is known to
+be outside a syntactic block), or `beginning-of-defun' for programming modes or
+`backward-paragraph' for textual modes (i.e., the mode-dependent function is
+known to move outside a syntactic block). If nil, the beginning of the buffer
+is used as a position outside of a syntactic block, in the worst case.
+
+These item elements are used by Font Lock mode to set the variables
+`font-lock-keywords', `font-lock-keywords-only',
+`font-lock-keywords-case-fold-search', `font-lock-syntax-table' and
+`font-lock-beginning-of-syntax-function', respectively.
+
+Further item elements are alists of the form (VARIABLE . VALUE) and are in no
+particular order. Each VARIABLE is made buffer-local before set to VALUE.
+
+Currently, appropriate variables include `font-lock-mark-block-function'.
+If this is non-nil, it should be a function with no args used to mark any
+enclosing block of text, for fontification via \\[font-lock-fontify-block].
+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,
+`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'.")
+
+;; This variable is used where font-lock.el itself supplies the keywords.
+(defvar font-lock-defaults-alist
+ (let (;; We use `beginning-of-defun', rather than nil, for SYNTAX-BEGIN.
+ ;; Thus the calculation of the cache is usually faster but not
+ ;; infallible, so we risk mis-fontification. sm.
+ (c-mode-defaults
+ '((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 20 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-2 c++-font-lock-keywords-3)
+ nil nil ((?_ . "w")) beginning-of-defun
+ ;; Obsoleted by Emacs 20 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 20 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 20 parse-partial-sexp's COMMENTSTOP.
+ ;(font-lock-comment-start-regexp . "/[*/]")
+ (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 20 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.
+ (tex-mode-defaults
+ '((tex-font-lock-keywords
+ tex-font-lock-keywords-1 tex-font-lock-keywords-2)
+ nil nil ((?$ . "\"")) nil
+ ;; Obsoleted by Emacs 20 parse-partial-sexp's COMMENTSTOP.
+ ;(font-lock-comment-start-regexp . "%")
+ (font-lock-mark-block-function . mark-paragraph)))
+ )
+ (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)))
+ "Alist of fall-back Font Lock defaults for major modes.
+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.")
+
+(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'.")
+
+(defvar font-lock-keywords-only nil
+ "*Non-nil means Font Lock should not fontify comments or strings.
+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'.")
+
+(defvar font-lock-syntactic-keywords nil
+ "A list of the syntactic keywords to highlight.
+Can be the list or the name of a function or variable whose value is the list.
+See `font-lock-keywords' for a description of the form of this list;
+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), 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
+ "Non-nil means use this syntax table for fontifying.
+If this is nil, the major mode's syntax table is used.
+This is normally set via `font-lock-defaults'.")
+
+;; If this is nil, we only use the beginning of the buffer if we can't use
+;; `font-lock-cache-position' and `font-lock-cache-state'.
+(defvar font-lock-beginning-of-syntax-function nil
+ "*Non-nil means use this function to move back outside of a syntactic block.
+When called with no args it should leave point at the beginning of any
+enclosing syntactic block.
+If this is nil, the beginning of the buffer is used (in the worst case).
+This is normally set via `font-lock-defaults'.")
+
+(defvar font-lock-mark-block-function nil
+ "*Non-nil means use this function to mark a block of text.
+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 20 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'.")
+
+(defvar font-lock-unfontify-buffer-function 'font-lock-default-unfontify-buffer
+ "Function to use for unfontifying the buffer.
+This is used when turning off Font Lock mode.
+This is normally set via `font-lock-defaults'.")
+
+(defvar font-lock-fontify-region-function 'font-lock-default-fontify-region
+ "Function to use for fontifying a region.
+It should take two args, the beginning and end of the region, and an optional
+third arg VERBOSE. If non-nil, the function should print status messages.
+This is normally set via `font-lock-defaults'.")
+
+(defvar font-lock-unfontify-region-function 'font-lock-default-unfontify-region
+ "Function to use for unfontifying a region.
+It should take two args, the beginning and end of the region.
+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'.")
+
+(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.
+
+(eval-when-compile
+ ;;
+ ;; We don't do this at the top-level as we only use non-autoloaded macros.
+ (require 'cl)
+ ;;
+ ;; Borrowed from lazy-lock.el.
+ ;; We use this to preserve or protect things when modifying text properties.
+ (defmacro save-buffer-state (varlist &rest body)
+ "Bind variables according to VARLIST and eval BODY restoring buffer state."
+ (` (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
+ deactivate-mark buffer-file-name buffer-file-truename))))
+ (,@ body)
+ (when (and (not modified) (buffer-modified-p))
+ (set-buffer-modified-p nil)))))
+ (put 'save-buffer-state 'lisp-indent-function 1)
+ ;;
+ ;; 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)
+ "Toggle Font Lock mode.
+With arg, turn Font Lock mode on if and only if arg is positive.
+
+When Font Lock mode is enabled, text is fontified as you type it: