428
+ − 1 ;;; font-lock.el --- decorating source files with fonts/colors based on syntax
+ − 2
+ − 3 ;; Copyright (C) 1992-1995, 1997 Free Software Foundation, Inc.
+ − 4 ;; Copyright (C) 1995 Amdahl Corporation.
442
+ − 5 ;; Copyright (C) 1996, 2000 Ben Wing.
428
+ − 6
+ − 7 ;; Author: Jamie Zawinski <jwz@jwz.org>, for the LISPM Preservation Society.
+ − 8 ;; Minimally merged with FSF 19.34 by Barry Warsaw <bwarsaw@python.org>
+ − 9 ;; Then (partially) synched with FSF 19.30, leading to:
+ − 10 ;; Next Author: RMS
+ − 11 ;; Next Author: Simon Marshall <simon@gnu.ai.mit.edu>
+ − 12 ;; Latest XEmacs Author: Ben Wing
+ − 13 ;; Maintainer: XEmacs Development Team
+ − 14 ;; Keywords: languages, faces
+ − 15
+ − 16 ;; This file is part of XEmacs.
+ − 17
+ − 18 ;; XEmacs is free software; you can redistribute it and/or modify it
+ − 19 ;; under the terms of the GNU General Public License as published by
+ − 20 ;; the Free Software Foundation; either version 2, or (at your option)
+ − 21 ;; any later version.
+ − 22
+ − 23 ;; XEmacs is distributed in the hope that it will be useful, but
+ − 24 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
+ − 25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ − 26 ;; General Public License for more details.
+ − 27
+ − 28 ;; You should have received a copy of the GNU General Public License
+ − 29 ;; along with XEmacs; see the file COPYING. If not, write to the
+ − 30 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ − 31 ;; Boston, MA 02111-1307, USA.
+ − 32
+ − 33 ;;; Synched up with: FSF 19.30 except for the code to initialize the faces.
+ − 34
+ − 35 ;;; Commentary:
+ − 36
+ − 37 ;; Font-lock-mode is a minor mode that causes your comments to be
+ − 38 ;; displayed in one face, strings in another, reserved words in another,
+ − 39 ;; documentation strings in another, and so on.
+ − 40 ;;
+ − 41 ;; Comments will be displayed in `font-lock-comment-face'.
+ − 42 ;; Strings will be displayed in `font-lock-string-face'.
+ − 43 ;; Doc strings will be displayed in `font-lock-doc-string-face'.
+ − 44 ;; Function and variable names (in their defining forms) will be
+ − 45 ;; displayed in `font-lock-function-name-face'.
+ − 46 ;; Reserved words will be displayed in `font-lock-keyword-face'.
+ − 47 ;;
+ − 48 ;; Don't let the name fool you: you can highlight things using different
+ − 49 ;; colors or background stipples instead of fonts, though that is not the
+ − 50 ;; default. See the variables `font-lock-use-colors' and
+ − 51 ;; `font-lock-use-fonts' for broad control over this, or see the
+ − 52 ;; documentation on faces and how to change their attributes for
+ − 53 ;; fine-grained control.
+ − 54 ;;
+ − 55 ;; To make the text you type be fontified, use M-x font-lock-mode. When
+ − 56 ;; this minor mode is on, the fonts of the current line will be updated
+ − 57 ;; with every insertion or deletion.
+ − 58 ;;
+ − 59 ;; By default, font-lock will automatically put newly loaded files
+ − 60 ;; into font-lock-mode if it knows about the file's mode. See the
+ − 61 ;; variables `font-lock-auto-fontify', `font-lock-mode-enable-list',
+ − 62 ;; and `font-lock-mode-disable-list' for control over this.
+ − 63 ;;
+ − 64 ;; The `font-lock-keywords' variable defines other patterns to highlight.
+ − 65 ;; The default font-lock-mode-hook sets it to the value of the variables
+ − 66 ;; lisp-font-lock-keywords, c-font-lock-keywords, etc, as appropriate.
+ − 67 ;; The easiest way to change the highlighting patterns is to change the
+ − 68 ;; values of c-font-lock-keywords and related variables. See the doc
+ − 69 ;; string of the variable `font-lock-keywords' for the appropriate syntax.
+ − 70 ;;
+ − 71 ;; The default value for `lisp-font-lock-keywords' is the value of the variable
+ − 72 ;; `lisp-font-lock-keywords-1'. You may like `lisp-font-lock-keywords-2'
+ − 73 ;; better; it highlights many more words, but is slower and makes your buffers
+ − 74 ;; be very visually noisy.
+ − 75 ;;
+ − 76 ;; The same is true of `c-font-lock-keywords-1' and `c-font-lock-keywords-2';
+ − 77 ;; the former is subdued, the latter is loud.
+ − 78 ;;
+ − 79 ;; You can make font-lock default to the gaudier variety of keyword
+ − 80 ;; highlighting by setting the variable `font-lock-maximum-decoration'
+ − 81 ;; before loading font-lock, or by calling the functions
+ − 82 ;; `font-lock-use-default-maximal-decoration' or
+ − 83 ;; `font-lock-use-default-minimal-decoration'.
+ − 84 ;;
+ − 85 ;; On a Sparc10, the initial fontification takes about 6 seconds for a typical
+ − 86 ;; 140k file of C code, using the default configuration. The actual speed
+ − 87 ;; depends heavily on the type of code in the file, and how many non-syntactic
+ − 88 ;; patterns match; for example, Xlib.h takes 23 seconds for 101k, because many
+ − 89 ;; patterns match in it. You can speed this up substantially by removing some
+ − 90 ;; of the patterns that are highlighted by default. Fontifying lisp code is
+ − 91 ;; significantly faster, because lisp has a more regular syntax than C, so the
+ − 92 ;; regular expressions don't have to be as complicated.
+ − 93 ;;
+ − 94 ;; It's called font-lock-mode here because on the Lispms it was called
+ − 95 ;; "Electric Font Lock Mode." It was called that because there was an older
+ − 96 ;; mode called "Electric Caps Lock Mode" which had the function of causing all
+ − 97 ;; of your source code to be in upper case except for strings and comments,
+ − 98 ;; without you having to blip the caps lock key by hand all the time (thus the
+ − 99 ;; "electric", as in `electric-c-brace'.)
+ − 100
+ − 101 ;; See also the related packages `fast-lock' and `lazy-lock'. Both
+ − 102 ;; attempt to speed up the initial fontification. `fast-lock' saves
+ − 103 ;; the fontification info when you exit Emacs and reloads it next time
+ − 104 ;; you load the file, so that the file doesn't have to be fontified
+ − 105 ;; again. `lazy-lock' does "lazy" fontification -- i.e. it only
+ − 106 ;; fontifies the text as it becomes visible rather than fontifying
+ − 107 ;; the whole file when it's first loaded in.
+ − 108
+ − 109 ;; Further comments from the FSF:
+ − 110
+ − 111 ;; Nasty regexps of the form "bar\\(\\|lo\\)\\|f\\(oo\\|u\\(\\|bar\\)\\)\\|lo"
+ − 112 ;; are made thusly: (regexp-opt '("foo" "fu" "fubar" "bar" "barlo" "lo")) for
+ − 113 ;; efficiency.
+ − 114
+ − 115 ;; What is fontification for? You might say, "It's to make my code look nice."
+ − 116 ;; I think it should be for adding information in the form of cues. These cues
+ − 117 ;; should provide you with enough information to both (a) distinguish between
+ − 118 ;; different items, and (b) identify the item meanings, without having to read
+ − 119 ;; the items and think about it. Therefore, fontification allows you to think
+ − 120 ;; less about, say, the structure of code, and more about, say, why the code
+ − 121 ;; doesn't work. Or maybe it allows you to think less and drift off to sleep.
+ − 122 ;;
+ − 123 ;; So, here are my opinions/advice/guidelines:
+ − 124 ;;
+ − 125 ;; - Use the same face for the same conceptual object, across all modes.
+ − 126 ;; i.e., (b) above, all modes that have items that can be thought of as, say,
+ − 127 ;; keywords, should be highlighted with the same face, etc.
+ − 128 ;; - Keep the faces distinct from each other as far as possible.
+ − 129 ;; i.e., (a) above.
+ − 130 ;; - Make the face attributes fit the concept as far as possible.
+ − 131 ;; i.e., function names might be a bold color such as blue, comments might
+ − 132 ;; be a bright color such as red, character strings might be brown, because,
+ − 133 ;; err, strings are brown (that was not the reason, please believe me).
+ − 134 ;; - Don't use a non-nil OVERRIDE unless you have a good reason.
+ − 135 ;; Only use OVERRIDE for special things that are easy to define, such as the
+ − 136 ;; way `...' quotes are treated in strings and comments in Emacs Lisp mode.
+ − 137 ;; Don't use it to, say, highlight keywords in commented out code or strings.
+ − 138 ;; - Err, that's it.
+ − 139
+ − 140
+ − 141 ;;; Code:
+ − 142
+ − 143 (require 'fontl-hooks)
+ − 144
+ − 145 ;;;;;;;;;;;;;;;;;;;;;; user variables ;;;;;;;;;;;;;;;;;;;;;;
+ − 146
+ − 147 (defgroup font-lock nil
+ − 148 "Decorate source files with fonts/colors based on syntax.
+ − 149 Font-lock-mode is a minor mode that causes your comments to be
+ − 150 displayed in one face, strings in another, reserved words in another,
+ − 151 documentation strings in another, and so on.
+ − 152
+ − 153 Comments will be displayed in `font-lock-comment-face'.
+ − 154 Strings will be displayed in `font-lock-string-face'.
+ − 155 Doc strings will be displayed in `font-lock-doc-string-face'.
+ − 156 Function and variable names (in their defining forms) will be displayed
+ − 157 in `font-lock-function-name-face'.
+ − 158 Reserved words will be displayed in `font-lock-keyword-face'.
+ − 159 Preprocessor conditionals will be displayed in `font-lock-preprocessor-face'."
+ − 160 :group 'languages)
+ − 161
+ − 162 (defgroup font-lock-faces nil
+ − 163 "Faces used by the font-lock package."
+ − 164 :group 'font-lock
+ − 165 :group 'faces)
+ − 166
+ − 167
+ − 168 (defcustom font-lock-verbose t
+ − 169 "*If non-nil, means show status messages when fontifying.
+ − 170 See also `font-lock-message-threshold'."
+ − 171 :type 'boolean
+ − 172 :group 'font-lock)
+ − 173
+ − 174 (defcustom font-lock-message-threshold 6000
+ − 175 "*Minimum size of region being fontified for status messages to appear.
+ − 176
+ − 177 The size is measured in characters. This affects `font-lock-fontify-region'
+ − 178 but not `font-lock-fontify-buffer'. (In other words, when you first visit
+ − 179 a file and it gets fontified, you will see status messages no matter what
+ − 180 size the file is. However, if you do something else like paste a
442
+ − 181 chunk of text, you will see status messages only if the changed region is
+ − 182 large enough.)
428
+ − 183
+ − 184 Note that setting `font-lock-verbose' to nil disables the status
+ − 185 messages entirely."
+ − 186 :type 'integer
+ − 187 :group 'font-lock)
+ − 188
+ − 189 ;;;###autoload
+ − 190 (defcustom font-lock-auto-fontify t
+ − 191 "*Whether font-lock should automatically fontify files as they're loaded.
+ − 192 This will only happen if font-lock has fontifying keywords for the major
+ − 193 mode of the file. You can get finer-grained control over auto-fontification
+ − 194 by using this variable in combination with `font-lock-mode-enable-list' or
+ − 195 `font-lock-mode-disable-list'."
+ − 196 :type 'boolean
+ − 197 :group 'font-lock)
+ − 198
+ − 199 ;;;###autoload
+ − 200 (defcustom font-lock-mode-enable-list nil
+ − 201 "*List of modes to auto-fontify, if `font-lock-auto-fontify' is nil."
+ − 202 :type '(repeat (symbol :tag "Mode"))
+ − 203 :group 'font-lock)
+ − 204
+ − 205 ;;;###autoload
+ − 206 (defcustom font-lock-mode-disable-list nil
+ − 207 "*List of modes not to auto-fontify, if `font-lock-auto-fontify' is t."
+ − 208 :type '(repeat (symbol :tag "Mode"))
+ − 209 :group 'font-lock)
+ − 210
+ − 211 ;;;###autoload
+ − 212 (defcustom font-lock-use-colors '(color)
+ − 213 "*Specification for when Font Lock will set up color defaults.
+ − 214 Normally this should be '(color), meaning that Font Lock will set up
+ − 215 color defaults that are only used on color displays. Set this to nil
+ − 216 if you don't want Font Lock to set up color defaults at all. This
+ − 217 should be one of
+ − 218
+ − 219 -- a list of valid tags, meaning that the color defaults will be used
+ − 220 when all of the tags apply. (e.g. '(color x))
+ − 221 -- a list whose first element is 'or and whose remaining elements are
+ − 222 lists of valid tags, meaning that the defaults will be used when
+ − 223 any of the tag lists apply.
+ − 224 -- nil, meaning that the defaults should not be set up at all.
+ − 225
+ − 226 \(If you specify face values in your init file, they will override any
+ − 227 that Font Lock specifies, regardless of whether you specify the face
+ − 228 values before or after loading Font Lock.)
+ − 229
+ − 230 See also `font-lock-use-fonts'. If you want more control over the faces
+ − 231 used for fontification, see the documentation of `font-lock-mode' for
+ − 232 how to do it."
+ − 233 ;; Hard to do right.
+ − 234 :type 'sexp
+ − 235 :group 'font-lock)
+ − 236
+ − 237 ;;;###autoload
+ − 238 (defcustom font-lock-use-fonts '(or (mono) (grayscale))
+ − 239 "*Specification for when Font Lock will set up non-color defaults.
+ − 240
+ − 241 Normally this should be '(or (mono) (grayscale)), meaning that Font
+ − 242 Lock will set up non-color defaults that are only used on either mono
+ − 243 or grayscale displays. Set this to nil if you don't want Font Lock to
+ − 244 set up non-color defaults at all. This should be one of
+ − 245
+ − 246 -- a list of valid tags, meaning that the non-color defaults will be used
+ − 247 when all of the tags apply. (e.g. '(grayscale x))
+ − 248 -- a list whose first element is 'or and whose remaining elements are
+ − 249 lists of valid tags, meaning that the defaults will be used when
+ − 250 any of the tag lists apply.
+ − 251 -- nil, meaning that the defaults should not be set up at all.
+ − 252
+ − 253 \(If you specify face values in your init file, they will override any
+ − 254 that Font Lock specifies, regardless of whether you specify the face
+ − 255 values before or after loading Font Lock.)
+ − 256
+ − 257 See also `font-lock-use-colors'. If you want more control over the faces
+ − 258 used for fontification, see the documentation of `font-lock-mode' for
+ − 259 how to do it."
+ − 260 :type 'sexp
+ − 261 :group 'font-lock)
+ − 262
+ − 263 ;;;###autoload
+ − 264 (defcustom font-lock-maximum-decoration t
+ − 265 "*If non-nil, the maximum decoration level for fontifying.
+ − 266 If nil, use the minimum decoration (equivalent to level 0).
+ − 267 If t, use the maximum decoration available.
+ − 268 If a number, use that level of decoration (or if not available the maximum).
+ − 269 If a list, each element should be a cons pair of the form (MAJOR-MODE . LEVEL),
+ − 270 where MAJOR-MODE is a symbol or t (meaning the default). For example:
+ − 271 ((c++-mode . 2) (c-mode . t) (t . 1))
+ − 272 means use level 2 decoration for buffers in `c++-mode', the maximum decoration
+ − 273 available for buffers in `c-mode', and level 1 decoration otherwise."
+ − 274 :type '(choice (const :tag "default" nil)
+ − 275 (const :tag "maximum" t)
+ − 276 (integer :tag "level" 1)
+ − 277 (repeat :menu-tag "mode specific" :tag "mode specific"
+ − 278 :value ((t . t))
+ − 279 (cons :tag "Instance"
+ − 280 (radio :tag "Mode"
+ − 281 (const :tag "all" t)
+ − 282 (symbol :tag "name"))
+ − 283 (radio :tag "Decoration"
+ − 284 (const :tag "default" nil)
+ − 285 (const :tag "maximum" t)
+ − 286 (integer :tag "level" 1)))))
+ − 287 :group 'font-lock)
+ − 288
+ − 289 ;;;###autoload
+ − 290 (define-obsolete-variable-alias 'font-lock-use-maximal-decoration
+ − 291 'font-lock-maximum-decoration)
+ − 292
+ − 293 ;;;###autoload
+ − 294 (defcustom font-lock-maximum-size (* 250 1024)
+ − 295 "*If non-nil, the maximum size for buffers for fontifying.
+ − 296 Only buffers less than this can be fontified when Font Lock mode is turned on.
+ − 297 If nil, means size is irrelevant.
+ − 298 If a list, each element should be a cons pair of the form (MAJOR-MODE . SIZE),
+ − 299 where MAJOR-MODE is a symbol or t (meaning the default). For example:
+ − 300 ((c++-mode . 256000) (c-mode . 256000) (rmail-mode . 1048576))
+ − 301 means that the maximum size is 250K for buffers in `c++-mode' or `c-mode', one
+ − 302 megabyte for buffers in `rmail-mode', and size is irrelevant otherwise."
+ − 303 :type '(choice (const :tag "none" nil)
+ − 304 (integer :tag "size")
+ − 305 (repeat :menu-tag "mode specific" :tag "mode specific"
+ − 306 :value ((t . nil))
+ − 307 (cons :tag "Instance"
+ − 308 (radio :tag "Mode"
+ − 309 (const :tag "all" t)
+ − 310 (symbol :tag "name"))
+ − 311 (radio :tag "Size"
+ − 312 (const :tag "none" nil)
+ − 313 (integer :tag "size")))))
+ − 314 :group 'font-lock)
+ − 315
460
+ − 316 ;;;###autoload
+ − 317 (defcustom font-lock-fontify-string-delimiters nil
+ − 318 "*If non-nil, apply font-lock-string-face to string delimiters as well as
+ − 319 string text when fontifying."
+ − 320 :type 'boolean
+ − 321 :group 'font-lock)
428
+ − 322
+ − 323 ;; Fontification variables:
+ − 324
+ − 325 ;;;###autoload
+ − 326 (defvar font-lock-keywords nil
442
+ − 327 "A list defining the keywords for `font-lock-mode' to highlight.
+ − 328
+ − 329 FONT-LOCK-KEYWORDS := List of FONT-LOCK-FORM's.
+ − 330
+ − 331 FONT-LOCK-FORM :== MATCHER
+ − 332 | (MATCHER . MATCH)
+ − 333 | (MATCHER . FACE-FORM)
+ − 334 | (MATCHER . HIGHLIGHT)
+ − 335 | (MATCHER HIGHLIGHT ...)
+ − 336 | (eval . FORM)
+ − 337
+ − 338 MATCHER :== A string containing a regexp.
+ − 339 | A variable containing a regexp to search for.
+ − 340 | A function to call to make the search.
+ − 341 It is called with one arg, the limit of the search,
+ − 342 and should leave MATCH results in the XEmacs global
+ − 343 match data.
+ − 344
+ − 345 MATCH :== An integer match subexpression number from MATCHER.
+ − 346
+ − 347 FACE-FORM :== The symbol naming a defined face.
+ − 348 | Expression whos value is the face name to use. If you
+ − 349 want FACE-FORM to be a symbol that evaluates to a face,
+ − 350 use a form like \"(progn sym)\".
+ − 351
+ − 352 HIGHLIGHT :== MATCH-HIGHLIGHT
+ − 353 | MATCH-ANCHORED
+ − 354
+ − 355 FORM :== Expression returning a FONT-LOCK-FORM, evaluated when
+ − 356 the FONT-LOCK-FORM is first used in a buffer. This
+ − 357 feature can be used to provide a FONT-LOCK-FORM that
+ − 358 can only be generated when Font Lock mode is actually
+ − 359 turned on.
+ − 360
+ − 361 MATCH-HIGHLIGHT :== (MATCH FACE-FORM OVERRIDE LAXMATCH)
+ − 362
+ − 363 OVERRIDE :== t - overwrite existing fontification
+ − 364 | 'keep - only parts not already fontified are
+ − 365 highlighted.
+ − 366 | 'prepend - merge faces, this fontification has
+ − 367 precedence over existing
+ − 368 | 'append - merge faces, existing fontification has
+ − 369 precedence over
+ − 370 this face.
+ − 371
+ − 372 LAXMATCH :== If non-nil, no error is signalled if there is no MATCH
+ − 373 in MATCHER.
+ − 374
+ − 375 MATCH-ANCHORED :== (ANCHOR-MATCHER PRE-MATCH-FORM \\
+ − 376 POST-MATCH-FORM MATCH-HIGHLIGHT ...)
428
+ − 377
442
+ − 378 ANCHOR-MATCHER :== Like a MATCHER, except that the limit of the search
+ − 379 defaults to the end of the line after PRE-MATCH-FORM
+ − 380 is evaluated. However, if PRE-MATCH-FORM returns a
+ − 381 position greater than the end of the line, that
+ − 382 position is used as the limit of the search. It is
+ − 383 generally a bad idea to return a position greater than
+ − 384 the end of the line, i.e., cause the ANCHOR-MATCHER
+ − 385 search to span lines.
+ − 386
+ − 387 PRE-MATCH-FORM :== Evaluated before the ANCHOR-MATCHER is used, therefore
+ − 388 can be used to initialize before, ANCHOR-MATCHER is
+ − 389 used. Typically, PRE-MATCH-FORM is used to move to
+ − 390 some position relative to the original MATCHER, before
+ − 391 starting with the ANCHOR-MATCHER.
+ − 392
+ − 393 POST-MATCH-FORM :== Like PRE-MATCH-FORM, but used to clean up after the
+ − 394 ANCHOR-MATCHER. It might be used to move, before
+ − 395 resuming with MATCH-ANCHORED's parent's MATCHER.
+ − 396
+ − 397 For example, an element of the first form highlights (if not already highlighted):
+ − 398
444
+ − 399 \"\\\\\\=<foo\\\\\\=>\" Discrete occurrences of \"foo\" in the value
442
+ − 400 of the variable `font-lock-keyword-face'.
428
+ − 401
442
+ − 402 (\"fu\\\\(bar\\\\)\" . 1) Substring \"bar\" within all occurrences of
+ − 403 \"fubar\" in the value of
+ − 404 `font-lock-keyword-face'.
+ − 405
+ − 406 (\"fubar\" . fubar-face) Occurrences of \"fubar\" in the value of
+ − 407 `fubar-face'.
+ − 408
+ − 409 (\"foo\\\\|bar\" 0 foo-bar-face t) Occurrences of either \"foo\" or \"bar\" in the
+ − 410 value of `foo-bar-face', even if already
+ − 411 highlighted.
428
+ − 412
442
+ − 413 (fubar-match 1 fubar-face) The first subexpression within all
+ − 414 occurrences of whatever the function
+ − 415 `fubar-match' finds and matches in the value
+ − 416 of `fubar-face'.
+ − 417
444
+ − 418 (\"\\\\\\=<anchor\\\\\\=>\" (0 anchor-face) (\"\\\\\\=<item\\\\\\=>\" nil nil (0 item-face)))
442
+ − 419 -------------- --------------- ------------ --- --- -------------
+ − 420 | | | | | |
+ − 421 MATCHER | ANCHOR-MATCHER | +------+ MATCH-HIGHLIGHT
+ − 422 MATCH-HIGHLIGHT PRE-MATCH-FORM |
+ − 423 POST-MATCH-FORM
+ − 424
+ − 425 Discrete occurrences of \"anchor\" in the value of `anchor-face', and
+ − 426 subsequent discrete occurrences of \"item\" (on the same line) in the value
+ − 427 of `item-face'. (Here PRE-MATCH-FORM and POST-MATCH-FORM are nil.
+ − 428 Therefore \"item\" is initially searched for starting from the end of the
+ − 429 match of \"anchor\", and searching for subsequent instance of \"anchor\"
+ − 430 resumes from where searching for \"item\" concluded.)
428
+ − 431
+ − 432 For highlighting single items, typically only MATCH-HIGHLIGHT is required.
442
+ − 433 However, if an item or (typically) several items are to be highlighted
+ − 434 following the instance of another item (the anchor) then MATCH-ANCHORED may be
+ − 435 required.
428
+ − 436
+ − 437 These regular expressions should not match text which spans lines. While
442
+ − 438 \\[font-lock-fontify-buffer] handles multi-line patterns correctly, updating when you
+ − 439 edit the buffer does not, since it considers text one line at a time.
428
+ − 440
442
+ − 441 Be very careful composing regexps for this list; the wrong pattern can
+ − 442 dramatically slow things down!
+ − 443 ")
428
+ − 444 ;;;###autoload
+ − 445 (make-variable-buffer-local 'font-lock-keywords)
+ − 446
460
+ − 447 ;;;###autoload
+ − 448 (defvar font-lock-syntactic-keywords nil
+ − 449 "A list of the syntactic keywords to highlight.
+ − 450 Can be the list or the name of a function or variable whose value is the list.
+ − 451 See `font-lock-keywords' for a description of the form of this list;
+ − 452 the differences are listed below. MATCH-HIGHLIGHT should be of the form:
+ − 453
+ − 454 (MATCH SYNTAX OVERRIDE LAXMATCH)
+ − 455
+ − 456 where SYNTAX can be of the form (SYNTAX-CODE . MATCHING-CHAR), the name of a
+ − 457 syntax table, or an expression whose value is such a form or a syntax table.
+ − 458 OVERRIDE cannot be `prepend' or `append'.
+ − 459
+ − 460 For example, an element of the form highlights syntactically:
+ − 461
+ − 462 (\"\\\\$\\\\(#\\\\)\" 1 (1 . nil))
+ − 463
+ − 464 a hash character when following a dollar character, with a SYNTAX-CODE of
+ − 465 1 (meaning punctuation syntax). Assuming that the buffer syntax table does
+ − 466 specify hash characters to have comment start syntax, the element will only
+ − 467 highlight hash characters that do not follow dollar characters as comments
+ − 468 syntactically.
+ − 469
+ − 470 (\"\\\\('\\\\).\\\\('\\\\)\"
+ − 471 (1 (7 . ?'))
+ − 472 (2 (7 . ?')))
+ − 473
+ − 474 both single quotes which surround a single character, with a SYNTAX-CODE of
+ − 475 7 (meaning string quote syntax) and a MATCHING-CHAR of a single quote (meaning
+ − 476 a single quote matches a single quote). Assuming that the buffer syntax table
+ − 477 does not specify single quotes to have quote syntax, the element will only
+ − 478 highlight single quotes of the form 'c' as strings syntactically.
+ − 479 Other forms, such as foo'bar or 'fubar', will not be highlighted as strings.
+ − 480
+ − 481 This is normally set via `font-lock-defaults'."
+ − 482 )
+ − 483 ;;;###autoload
+ − 484 (make-variable-buffer-local 'font-lock-syntactic-keywords)
+ − 485
428
+ − 486 (defvar font-lock-defaults nil
+ − 487 "The defaults font Font Lock mode for the current buffer.
+ − 488 Normally, do not set this directly. If you are writing a major mode,
+ − 489 put a property of `font-lock-defaults' on the major-mode symbol with
+ − 490 the desired value.
+ − 491
+ − 492 It should be a list
+ − 493
+ − 494 \(KEYWORDS KEYWORDS-ONLY CASE-FOLD SYNTAX-ALIST SYNTAX-BEGIN)
+ − 495
+ − 496 KEYWORDS may be a symbol (a variable or function whose value is the keywords
+ − 497 to use for fontification) or a list of symbols. If KEYWORDS-ONLY is non-nil,
+ − 498 syntactic fontification (strings and comments) is not performed. If CASE-FOLD
+ − 499 is non-nil, the case of the keywords is ignored when fontifying. If
+ − 500 SYNTAX-ALIST is non-nil, it should be a list of cons pairs of the form (CHAR
+ − 501 . STRING) used to set the local Font Lock syntax table, for keyword and
+ − 502 syntactic fontification (see `modify-syntax-entry').
+ − 503
+ − 504 If SYNTAX-BEGIN is non-nil, it should be a function with no args used to move
+ − 505 backwards outside any enclosing syntactic block, for syntactic fontification.
+ − 506 Typical values are `beginning-of-line' (i.e., the start of the line is known to
+ − 507 be outside a syntactic block), or `beginning-of-defun' for programming modes or
+ − 508 `backward-paragraph' for textual modes (i.e., the mode-dependent function is
+ − 509 known to move outside a syntactic block). If nil, the beginning of the buffer
+ − 510 is used as a position outside of a syntactic block, in the worst case.
+ − 511
+ − 512 These item elements are used by Font Lock mode to set the variables
+ − 513 `font-lock-keywords', `font-lock-keywords-only',
+ − 514 `font-lock-keywords-case-fold-search', `font-lock-syntax-table' and
+ − 515 `font-lock-beginning-of-syntax-function', respectively.
+ − 516
+ − 517 Alternatively, if the value is a symbol, it should name a major mode,
+ − 518 and the defaults for that mode will apply.")
+ − 519 (make-variable-buffer-local 'font-lock-defaults)
+ − 520
+ − 521 ;; FSF uses `font-lock-defaults-alist' and expects the major mode to
+ − 522 ;; set a value for `font-lock-defaults', but I don't like either of
+ − 523 ;; these -- requiring the mode to set `font-lock-defaults' makes it
+ − 524 ;; impossible to have defaults for a minor mode, and using an alist is
+ − 525 ;; generally a bad idea for information that really should be
+ − 526 ;; decentralized. (Who knows what strange modes might want
+ − 527 ;; font-locking?)
+ − 528
+ − 529 (defvar font-lock-keywords-only nil
+ − 530 "Non-nil means Font Lock should not do syntactic fontification.
+ − 531 This is normally set via `font-lock-defaults'.
+ − 532
+ − 533 This should be nil for all ``language'' modes, but other modes, like
+ − 534 dired, do not have anything useful in the syntax tables (no comment
+ − 535 or string delimiters, etc) and so there is no need to use them and
+ − 536 this variable should have a value of t.
+ − 537
+ − 538 You should not set this variable directly; its value is computed
+ − 539 from `font-lock-defaults', or (if that does not specify anything)
+ − 540 by examining the syntax table to see whether it appears to contain
+ − 541 anything useful.")
+ − 542 (make-variable-buffer-local 'font-lock-keywords-only)
+ − 543
+ − 544 (defvar font-lock-keywords-case-fold-search nil
+ − 545 "Whether the strings in `font-lock-keywords' should be case-folded.
+ − 546 This variable is automatically buffer-local, as the correct value depends
+ − 547 on the language in use.")
+ − 548 (make-variable-buffer-local 'font-lock-keywords-case-fold-search)
+ − 549
+ − 550 (defvar font-lock-after-fontify-buffer-hook nil
+ − 551 "Function or functions to run after completion of font-lock-fontify-buffer.")
+ − 552
+ − 553 (defvar font-lock-syntax-table nil
+ − 554 "Non-nil means use this syntax table for fontifying.
+ − 555 If this is nil, the major mode's syntax table is used.
+ − 556 This is normally set via `font-lock-defaults'.")
+ − 557 (make-variable-buffer-local 'font-lock-syntax-table)
+ − 558
460
+ − 559 ;; These record the parse state at a particular position, always the start of a
+ − 560 ;; line. Used to make `font-lock-fontify-syntactically-region' faster.
+ − 561 ;; Previously, `font-lock-cache-position' was just a buffer position. However,
+ − 562 ;; under certain situations, this occasionally resulted in mis-fontification.
+ − 563 ;; I think the "situations" were deletion with Lazy Lock mode's deferral. sm.
+ − 564 (defvar font-lock-cache-state nil)
+ − 565 (defvar font-lock-cache-position nil)
+ − 566 (make-variable-buffer-local 'font-lock-cache-state)
+ − 567 (make-variable-buffer-local 'font-lock-cache-position)
428
+ − 568
+ − 569 ;; If this is nil, we only use the beginning of the buffer if we can't use
+ − 570 ;; `font-lock-cache-position' and `font-lock-cache-state'.
+ − 571 (defvar font-lock-beginning-of-syntax-function nil
+ − 572 "Non-nil means use this function to move back outside of a syntactic block.
+ − 573 If this is nil, the beginning of the buffer is used (in the worst case).
+ − 574 This is normally set via `font-lock-defaults'.")
+ − 575 (make-variable-buffer-local 'font-lock-beginning-of-syntax-function)
+ − 576
+ − 577 (defvar font-lock-fontify-buffer-function 'font-lock-default-fontify-buffer
+ − 578 "Function to use for fontifying the buffer.
+ − 579 This is normally set via `font-lock-defaults'.")
+ − 580
+ − 581 (defvar font-lock-unfontify-buffer-function 'font-lock-default-unfontify-buffer
+ − 582 "Function to use for unfontifying the buffer.
+ − 583 This is used when turning off Font Lock mode.
+ − 584 This is normally set via `font-lock-defaults'.")
+ − 585
+ − 586 (defvar font-lock-fontify-region-function 'font-lock-default-fontify-region
+ − 587 "Function to use for fontifying a region.
+ − 588 It should take two args, the beginning and end of the region, and an optional
+ − 589 third arg VERBOSE. If non-nil, the function should print status messages.
+ − 590 This is normally set via `font-lock-defaults'.")
+ − 591
+ − 592 (defvar font-lock-unfontify-region-function 'font-lock-default-unfontify-region
+ − 593 "Function to use for unfontifying a region.
+ − 594 It should take two args, the beginning and end of the region.
+ − 595 This is normally set via `font-lock-defaults'.")
+ − 596
+ − 597 (defvar font-lock-inhibit-thing-lock nil
+ − 598 "List of Font Lock mode related modes that should not be turned on.
+ − 599 Currently, valid mode names as `fast-lock-mode' and `lazy-lock-mode'.
+ − 600 This is normally set via `font-lock-defaults'.")
+ − 601
+ − 602 ;;;###autoload
+ − 603 (defcustom font-lock-mode nil ;; customized for the option menu. dverna
+ − 604 "Non nil means `font-lock-mode' is on"
+ − 605 :group 'font-lock
+ − 606 :type 'boolean
+ − 607 :initialize 'custom-initialize-default
+ − 608 :require 'font-lock
+ − 609 :set #'(lambda (var val) (font-lock-mode (or val 0)))
+ − 610 )
+ − 611
+ − 612 (defvar font-lock-fontified nil) ; whether we have hacked this buffer
+ − 613 (put 'font-lock-fontified 'permanent-local t)
+ − 614
+ − 615 ;;;###autoload
+ − 616 (defvar font-lock-mode-hook nil
+ − 617 "Function or functions to run on entry to font-lock-mode.")
+ − 618
+ − 619 ; whether font-lock-set-defaults has already been run.
+ − 620 (defvar font-lock-defaults-computed nil)
+ − 621 (make-variable-buffer-local 'font-lock-defaults-computed)
+ − 622
+ − 623
+ − 624 ;;; Initialization of faces.
+ − 625
+ − 626 ;; #### barf gag retch. Horrid FSF lossage that we need to
+ − 627 ;; keep around for compatibility with font-lock-keywords that
442
+ − 628 ;; forget to properly quote their faces. I tried just let-binding
+ − 629 ;; them when we eval the face expression, but that failes because
+ − 630 ;; some files actually use the variables directly in their init code
+ − 631 ;; without quoting them. --ben
428
+ − 632 (defvar font-lock-comment-face 'font-lock-comment-face
442
+ − 633 "This variable should not be set.
+ − 634 It is present only for horrid FSF compatibility reasons.
+ − 635 The corresponding face should be set using `edit-faces' or the
+ − 636 `set-face-*' functions.")
428
+ − 637 (defvar font-lock-doc-string-face 'font-lock-doc-string-face
442
+ − 638 "This variable should not be set.
+ − 639 It is present only for horrid FSF compatibility reasons.
+ − 640 The corresponding face should be set using `edit-faces' or the
+ − 641 `set-face-*' functions.")
428
+ − 642 (defvar font-lock-string-face 'font-lock-string-face
442
+ − 643 "This variable should not be set.
+ − 644 It is present only for horrid FSF compatibility reasons.
+ − 645 The corresponding face should be set using `edit-faces' or the
+ − 646 `set-face-*' functions.")
428
+ − 647 (defvar font-lock-keyword-face 'font-lock-keyword-face
442
+ − 648 "This variable should not be set.
+ − 649 It is present only for horrid FSF compatibility reasons.
+ − 650 The corresponding face should be set using `edit-faces' or the
+ − 651 `set-face-*' functions.")
428
+ − 652 (defvar font-lock-function-name-face 'font-lock-function-name-face
442
+ − 653 "This variable should not be set.
+ − 654 It is present only for horrid FSF compatibility reasons.
+ − 655 The corresponding face should be set using `edit-faces' or the
+ − 656 `set-face-*' functions.")
428
+ − 657 (defvar font-lock-variable-name-face 'font-lock-variable-name-face
442
+ − 658 "This variable should not be set.
+ − 659 It is present only for horrid FSF compatibility reasons.
+ − 660 The corresponding face should be set using `edit-faces' or the
+ − 661 `set-face-*' functions.")
428
+ − 662 (defvar font-lock-type-face 'font-lock-type-face
442
+ − 663 "This variable should not be set.
+ − 664 It is present only for horrid FSF compatibility reasons.
+ − 665 The corresponding face should be set using `edit-faces' or the
+ − 666 `set-face-*' functions.")
428
+ − 667 (defvar font-lock-reference-face 'font-lock-reference-face
442
+ − 668 "This variable should not be set.
+ − 669 It is present only for horrid FSF compatibility reasons.
+ − 670 The corresponding face should be set using `edit-faces' or the
+ − 671 `set-face-*' functions.")
428
+ − 672 (defvar font-lock-preprocessor-face 'font-lock-preprocessor-face
442
+ − 673 "This variable should not be set.
+ − 674 It is present only for horrid FSF compatibility reasons.
+ − 675 The corresponding face should be set using `edit-faces' or the
+ − 676 `set-face-*' functions.")
428
+ − 677
+ − 678 (defconst font-lock-face-list
+ − 679 '(font-lock-comment-face
+ − 680 font-lock-string-face
+ − 681 font-lock-doc-string-face
+ − 682 font-lock-keyword-face
+ − 683 font-lock-function-name-face
+ − 684 font-lock-variable-name-face
+ − 685 font-lock-type-face
+ − 686 font-lock-reference-face
+ − 687 font-lock-preprocessor-face
+ − 688 font-lock-warning-face))
+ − 689
+ − 690 (defface font-lock-comment-face
+ − 691 '((((class color) (background dark)) (:foreground "gray80"))
442
+ − 692 ;; blue4 is hardly different from black on windows.
+ − 693 (((class color) (background light) (type mswindows)) (:foreground "blue"))
428
+ − 694 (((class color) (background light)) (:foreground "blue4"))
+ − 695 (((class grayscale) (background light))
+ − 696 (:foreground "DimGray" :bold t :italic t))
+ − 697 (((class grayscale) (background dark))
+ − 698 (:foreground "LightGray" :bold t :italic t))
+ − 699 (t (:bold t)))
+ − 700 "Font Lock mode face used to highlight comments."
+ − 701 :group 'font-lock-faces)
+ − 702
+ − 703 (defface font-lock-string-face
+ − 704 '((((class color) (background dark)) (:foreground "tan"))
+ − 705 (((class color) (background light)) (:foreground "green4"))
+ − 706 (((class grayscale) (background light)) (:foreground "DimGray" :italic t))
+ − 707 (((class grayscale) (background dark)) (:foreground "LightGray" :italic t))
+ − 708 (t (:bold t)))
+ − 709 "Font Lock mode face used to highlight strings."
+ − 710 :group 'font-lock-faces)
+ − 711
+ − 712 (defface font-lock-doc-string-face
+ − 713 '((((class color) (background dark)) (:foreground "light coral"))
+ − 714 (((class color) (background light)) (:foreground "green4"))
+ − 715 (t (:bold t)))
432
+ − 716 "Font Lock mode face used to highlight documentation strings.
+ − 717 This is currently supported only in Lisp-like modes, which are those
+ − 718 with \"lisp\" or \"scheme\" in their name. You can explicitly make
+ − 719 a mode Lisp-like by putting a non-nil `font-lock-lisp-like' property
+ − 720 on the major mode's symbol."
428
+ − 721 :group 'font-lock-faces)
+ − 722
+ − 723 (defface font-lock-keyword-face
+ − 724 '((((class color) (background dark)) (:foreground "cyan"))
442
+ − 725 ;; red4 is hardly different from black on windows.
+ − 726 (((class color) (background light) (type mswindows)) (:foreground "red"))
428
+ − 727 (((class color) (background light)) (:foreground "red4"))
+ − 728 (((class grayscale) (background light)) (:foreground "LightGray" :bold t))
+ − 729 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
+ − 730 (t (:bold t)))
+ − 731 "Font Lock mode face used to highlight keywords."
+ − 732 :group 'font-lock-faces)
+ − 733
+ − 734 (defface font-lock-function-name-face
+ − 735 '((((class color) (background dark)) (:foreground "aquamarine"))
442
+ − 736 ;; brown4 is hardly different from black on windows.
+ − 737 ;; I changed it to red because IMO it's pointless and ugly to
+ − 738 ;; use a million slightly different colors for niggly syntactic
+ − 739 ;; differences. --ben
+ − 740 (((class color) (background light) (type mswindows)) (:foreground "red"))
428
+ − 741 (((class color) (background light)) (:foreground "brown4"))
+ − 742 (t (:bold t :underline t)))
+ − 743 "Font Lock mode face used to highlight function names."
+ − 744 :group 'font-lock-faces)
+ − 745
+ − 746 (defface font-lock-variable-name-face
+ − 747 '((((class color) (background dark)) (:foreground "cyan3"))
+ − 748 (((class color) (background light)) (:foreground "magenta4"))
+ − 749 (((class grayscale) (background light))
+ − 750 (:foreground "Gray90" :bold t :italic t))
+ − 751 (((class grayscale) (background dark))
+ − 752 (:foreground "DimGray" :bold t :italic t))
+ − 753 (t (:underline t)))
+ − 754 "Font Lock mode face used to highlight variable names."
+ − 755 :group 'font-lock-faces)
+ − 756
+ − 757 (defface font-lock-type-face
+ − 758 '((((class color) (background dark)) (:foreground "wheat"))
+ − 759 (((class color) (background light)) (:foreground "steelblue"))
+ − 760 (((class grayscale) (background light)) (:foreground "Gray90" :bold t))
+ − 761 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
+ − 762 (t (:bold t)))
+ − 763 "Font Lock mode face used to highlight types."
+ − 764 :group 'font-lock-faces)
+ − 765
+ − 766 (defface font-lock-reference-face
+ − 767 '((((class color) (background dark)) (:foreground "cadetblue2"))
+ − 768 (((class color) (background light)) (:foreground "red3"))
+ − 769 (((class grayscale) (background light))
+ − 770 (:foreground "LightGray" :bold t :underline t))
+ − 771 (((class grayscale) (background dark))
+ − 772 (:foreground "Gray50" :bold t :underline t)))
+ − 773 "Font Lock mode face used to highlight references."
+ − 774 :group 'font-lock-faces)
+ − 775
+ − 776 ;; #### FSF has font-lock-builtin-face.
+ − 777
+ − 778 (defface font-lock-preprocessor-face
+ − 779 '((((class color) (background dark)) (:foreground "steelblue1"))
+ − 780 (((class color) (background light)) (:foreground "blue3"))
+ − 781 (t (:underline t)))
+ − 782 "Font Lock Mode face used to highlight preprocessor conditionals."
+ − 783 :group 'font-lock-faces)
+ − 784
+ − 785 ;; #### Currently unused
+ − 786 (defface font-lock-warning-face
+ − 787 '((((class color) (background light)) (:foreground "Red" :bold t))
+ − 788 (((class color) (background dark)) (:foreground "Pink" :bold t))
+ − 789 (t (:inverse-video t :bold t)))
+ − 790 "Font Lock mode face used to highlight warnings."
+ − 791 :group 'font-lock-faces)
+ − 792
+ − 793 (defun font-lock-recompute-variables ()
+ − 794 ;; Is this a Draconian thing to do?
+ − 795 (mapc #'(lambda (buffer)
+ − 796 (with-current-buffer buffer
+ − 797 (font-lock-mode 0)
+ − 798 (font-lock-set-defaults t)))
+ − 799 (buffer-list)))
+ − 800
+ − 801 ;; Backwards-compatible crud.
+ − 802
+ − 803 (defun font-lock-reset-all-faces ()
+ − 804 (dolist (face font-lock-face-list)
+ − 805 (face-spec-set face (get face 'face-defface-spec))))
+ − 806
+ − 807 (defun font-lock-use-default-fonts ()
+ − 808 "Reset the font-lock faces to a default set of fonts."
+ − 809 (interactive)
+ − 810 ;; #### !!!!
+ − 811 (font-lock-reset-all-faces))
+ − 812
+ − 813 (defun font-lock-use-default-colors ()
+ − 814 "Reset the font-lock faces to a default set of colors."
+ − 815 (interactive)
+ − 816 ;; #### !!!!
+ − 817 (font-lock-reset-all-faces))
+ − 818
+ − 819 (defun font-lock-use-default-minimal-decoration ()
+ − 820 "Reset the font-lock patterns to a fast, minimal set of decorations."
+ − 821 (and font-lock-maximum-decoration
+ − 822 (setq font-lock-maximum-decoration nil)
+ − 823 (font-lock-recompute-variables)))
+ − 824
+ − 825 (defun font-lock-use-default-maximal-decoration ()
+ − 826 "Reset the font-lock patterns to a larger set of decorations."
+ − 827 (and (not (eq t font-lock-maximum-decoration))
+ − 828 (setq font-lock-maximum-decoration t)
+ − 829 (font-lock-recompute-variables)))
+ − 830
+ − 831
+ − 832 ;;;;;;;;;;;;;;;;;;;;;; actual code ;;;;;;;;;;;;;;;;;;;;;;
+ − 833
+ − 834 ;;; To fontify the whole buffer by language syntax, we go through it a
+ − 835 ;;; character at a time, creating extents on the boundary of each syntactic
+ − 836 ;;; unit (that is, one extent for each block comment, one for each line
+ − 837 ;;; comment, one for each string, etc.) This is done with the C function
+ − 838 ;;; syntactically-sectionize. It's in C for speed (the speed of lisp function
+ − 839 ;;; calls was a real bottleneck for this task since it involves examining each
+ − 840 ;;; character in turn.)
+ − 841 ;;;
+ − 842 ;;; Then we make a second pass, to fontify the buffer based on other patterns
+ − 843 ;;; specified by regexp. When we find a match for a region of text, we need
+ − 844 ;;; to change the fonts on those characters. This is done with the
+ − 845 ;;; put-text-property function, which knows how to efficiently share extents.
+ − 846 ;;; Conceptually, we are attaching some particular face to each of the
+ − 847 ;;; characters in a range, but the implementation of this involves creating
+ − 848 ;;; extents, or resizing existing ones.
+ − 849 ;;;
+ − 850 ;;; Each time a modification happens to a line, we re-fontify the entire line.
+ − 851 ;;; We do this by first removing the extents (text properties) on the line,
+ − 852 ;;; and then doing the syntactic and keyword passes again on that line. (More
+ − 853 ;;; generally, each modified region is extended to include the preceding and
+ − 854 ;;; following BOL or EOL.)
+ − 855 ;;;
+ − 856 ;;; This means that, as the user types, we repeatedly go back to the beginning
+ − 857 ;;; of the line, doing more work the longer the line gets. This doesn't cost
+ − 858 ;;; much in practice, and if we don't, then we incorrectly fontify things when,
+ − 859 ;;; for example, inserting spaces into `intfoo () {}'.
+ − 860 ;;;
+ − 861
+ − 862
+ − 863 ;; The user level functions
+ − 864
+ − 865 ;;;###autoload
+ − 866 (defun font-lock-mode (&optional arg)
+ − 867 "Toggle Font Lock Mode.
+ − 868 With arg, turn font-lock mode on if and only if arg is positive.
+ − 869
+ − 870 When Font Lock mode is enabled, text is fontified as you type it:
+ − 871
+ − 872 - Comments are displayed in `font-lock-comment-face';
+ − 873 - Strings are displayed in `font-lock-string-face';
+ − 874 - Documentation strings (in Lisp-like languages) are displayed in
+ − 875 `font-lock-doc-string-face';
+ − 876 - Language keywords (\"reserved words\") are displayed in
+ − 877 `font-lock-keyword-face';
+ − 878 - Function names in their defining form are displayed in
+ − 879 `font-lock-function-name-face';
+ − 880 - Variable names in their defining form are displayed in
+ − 881 `font-lock-variable-name-face';
+ − 882 - Type names are displayed in `font-lock-type-face';
+ − 883 - References appearing in help files and the like are displayed
+ − 884 in `font-lock-reference-face';
+ − 885 - Preprocessor declarations are displayed in
+ − 886 `font-lock-preprocessor-face';
+ − 887
+ − 888 and
+ − 889
+ − 890 - Certain other expressions are displayed in other faces according
+ − 891 to the value of the variable `font-lock-keywords'.
+ − 892
+ − 893 Where modes support different levels of fontification, you can use the variable
+ − 894 `font-lock-maximum-decoration' to specify which level you generally prefer.
+ − 895 When you turn Font Lock mode on/off the buffer is fontified/defontified, though
+ − 896 fontification occurs only if the buffer is less than `font-lock-maximum-size'.
+ − 897 To fontify a buffer without turning on Font Lock mode, and regardless of buffer
+ − 898 size, you can use \\[font-lock-fontify-buffer].
+ − 899
+ − 900 See the variable `font-lock-keywords' for customization."
+ − 901 (interactive "P")
+ − 902 (let ((on-p (if arg (> (prefix-numeric-value arg) 0) (not font-lock-mode)))
+ − 903 (maximum-size (if (not (consp font-lock-maximum-size))
+ − 904 font-lock-maximum-size
+ − 905 (cdr (or (assq major-mode font-lock-maximum-size)
+ − 906 (assq t font-lock-maximum-size))))))
531
+ − 907 ;; Font-lock mode will refuse to turn itself on if in batch mode
+ − 908 ;; to avoid potential (probably not actual, though) slowdown. We
+ − 909 ;; used to try to "be nice" by avoiding doing this in temporary
+ − 910 ;; buffers. But with the deferral code we don't need this, and it
+ − 911 ;; definitely screws some things up.
+ − 912 (if (noninteractive)
428
+ − 913 (setq on-p nil))
+ − 914 (cond (on-p
+ − 915 (make-local-hook 'after-change-functions)
+ − 916 (add-hook 'after-change-functions
+ − 917 'font-lock-after-change-function nil t)
+ − 918 (add-hook 'pre-idle-hook 'font-lock-pre-idle-hook))
+ − 919 (t
+ − 920 (remove-hook 'after-change-functions
+ − 921 'font-lock-after-change-function t)
+ − 922 (setq font-lock-defaults-computed nil
+ − 923 font-lock-keywords nil)
+ − 924 ;; We have no business doing this here, since
+ − 925 ;; pre-idle-hook is global. Other buffers may
+ − 926 ;; still be in font-lock mode. -dkindred@cs.cmu.edu
+ − 927 ;; (remove-hook 'pre-idle-hook 'font-lock-pre-idle-hook)
+ − 928 ))
+ − 929 (set (make-local-variable 'font-lock-mode) on-p)
+ − 930 (cond (on-p
+ − 931 (font-lock-set-defaults-1)
+ − 932 (run-hooks 'font-lock-mode-hook)
+ − 933 (cond (font-lock-fontified
+ − 934 nil)
+ − 935 ((or (null maximum-size) (<= (buffer-size) maximum-size))
+ − 936 (font-lock-fontify-buffer))
+ − 937 (font-lock-verbose
442
+ − 938 (progress-feedback-with-label
+ − 939 'font-lock
+ − 940 "Fontifying %s... buffer too big." 'abort
+ − 941 (buffer-name)))))
428
+ − 942 (font-lock-fontified
+ − 943 (setq font-lock-fontified nil)
+ − 944 (font-lock-unfontify-region (point-min) (point-max))
+ − 945 (font-lock-thing-lock-cleanup))
+ − 946 (t
+ − 947 (font-lock-thing-lock-cleanup)))
+ − 948 (redraw-modeline)))
+ − 949
+ − 950 ;; For init-file hooks
+ − 951 ;;;###autoload
+ − 952 (defun turn-on-font-lock ()
+ − 953 "Unconditionally turn on Font Lock mode."
444
+ − 954 (interactive)
428
+ − 955 (font-lock-mode 1))
+ − 956
+ − 957 ;;;###autoload
+ − 958 (defun turn-off-font-lock ()
+ − 959 "Unconditionally turn off Font Lock mode."
444
+ − 960 (interactive)
428
+ − 961 (font-lock-mode 0))
+ − 962
+ − 963 ;;; FSF has here:
+ − 964
+ − 965 ;; support for add-keywords, global-font-lock-mode and
+ − 966 ;; font-lock-support-mode (unified support for various *-lock modes).
+ − 967
+ − 968
+ − 969 ;; Fontification functions.
+ − 970
+ − 971 ;; We first define some defsubsts to encapsulate the way we add
+ − 972 ;; faces to a region of text. I am planning on modifying the
+ − 973 ;; text-property mechanism so that multiple independent classes
+ − 974 ;; of text properties can exist. That way, for example, ediff's
+ − 975 ;; face text properties don't interfere with font lock's face
+ − 976 ;; text properties. Due to the XEmacs implementation of text
+ − 977 ;; properties in terms of extents, doing this is fairly trivial:
+ − 978 ;; instead of using the `text-prop' property, you just use a
+ − 979 ;; specified property.
+ − 980
+ − 981 (defsubst font-lock-set-face (start end face)
+ − 982 ;; Set the face on the characters in the range.
+ − 983 (put-nonduplicable-text-property start end 'face face)
+ − 984 (put-nonduplicable-text-property start end 'font-lock t))
+ − 985
+ − 986 (defsubst font-lock-remove-face (start end)
+ − 987 ;; Remove any syntax highlighting on the characters in the range.
+ − 988 (put-nonduplicable-text-property start end 'face nil)
460
+ − 989 (put-nonduplicable-text-property start end 'font-lock nil)
+ − 990 (if lookup-syntax-properties
+ − 991 (put-nonduplicable-text-property start end 'syntax-table nil)))
+ − 992
+ − 993 (defsubst font-lock-set-syntax (start end syntax)
+ − 994 ;; Set the face on the characters in the range.
+ − 995 (put-nonduplicable-text-property start end 'syntax-table syntax)
+ − 996 (put-nonduplicable-text-property start end 'font-lock t))
428
+ − 997
+ − 998 (defsubst font-lock-any-faces-p (start end)
+ − 999 ;; Return non-nil if we've put any syntax highlighting on
+ − 1000 ;; the characters in the range.
+ − 1001 ;;
+ − 1002 ;; used to look for 'text-prop property, but this has problems if
+ − 1003 ;; you put any other text properties in the vicinity. Simon
+ − 1004 ;; Marshall suggested looking for the 'face property (this is what
+ − 1005 ;; FSF Emacs does) but that's equally bogus. Only reliable way is
+ − 1006 ;; for font-lock to specially mark its extents.
+ − 1007 ;;
+ − 1008 ;; FSF's (equivalent) definition of this defsubst would be
+ − 1009 ;; (text-property-not-all start end 'font-lock nil)
+ − 1010 ;;
+ − 1011 ;; Perhaps our `map-extents' is faster than our definition
+ − 1012 ;; of `text-property-not-all'. #### If so, `text-property-not-all'
+ − 1013 ;; should be fixed ...
+ − 1014 ;;
+ − 1015 (map-extents 'extent-property (current-buffer) start (1- end) 'font-lock))
+ − 1016
+ − 1017
+ − 1018 ;; Fontification functions.
+ − 1019
+ − 1020 ;; Rather than the function, e.g., `font-lock-fontify-region' containing the
+ − 1021 ;; code to fontify a region, the function runs the function whose name is the
+ − 1022 ;; value of the variable, e.g., `font-lock-fontify-region-function'. Normally,
+ − 1023 ;; the value of this variable is, e.g., `font-lock-default-fontify-region'
+ − 1024 ;; which does contain the code to fontify a region. However, the value of the
+ − 1025 ;; variable could be anything and thus, e.g., `font-lock-fontify-region' could
+ − 1026 ;; do anything. The indirection of the fontification functions gives major
+ − 1027 ;; modes the capability of modifying the way font-lock.el fontifies. Major
+ − 1028 ;; modes can modify the values of, e.g., `font-lock-fontify-region-function',
+ − 1029 ;; via the variable `font-lock-defaults'.
+ − 1030 ;;
+ − 1031 ;; For example, Rmail mode sets the variable `font-lock-defaults' so that
+ − 1032 ;; font-lock.el uses its own function for buffer fontification. This function
+ − 1033 ;; makes fontification be on a message-by-message basis and so visiting an
+ − 1034 ;; RMAIL file is much faster. A clever implementation of the function might
+ − 1035 ;; fontify the headers differently than the message body. (It should, and
+ − 1036 ;; correspondingly for Mail mode, but I can't be bothered to do the work. Can
+ − 1037 ;; you?) This hints at a more interesting use...
+ − 1038 ;;
+ − 1039 ;; Languages that contain text normally contained in different major modes
+ − 1040 ;; could define their own fontification functions that treat text differently
+ − 1041 ;; depending on its context. For example, Perl mode could arrange that here
+ − 1042 ;; docs are fontified differently than Perl code. Or Yacc mode could fontify
+ − 1043 ;; rules one way and C code another. Neat!
+ − 1044 ;;
+ − 1045 ;; A further reason to use the fontification indirection feature is when the
+ − 1046 ;; default syntactual fontification, or the default fontification in general,
+ − 1047 ;; is not flexible enough for a particular major mode. For example, perhaps
+ − 1048 ;; comments are just too hairy for `font-lock-fontify-syntactically-region' to
+ − 1049 ;; cope with. You need to write your own version of that function, e.g.,
+ − 1050 ;; `hairy-fontify-syntactically-region', and make your own version of
+ − 1051 ;; `hairy-fontify-region' call that function before calling
+ − 1052 ;; `font-lock-fontify-keywords-region' for the normal regexp fontification
+ − 1053 ;; pass. And Hairy mode would set `font-lock-defaults' so that font-lock.el
+ − 1054 ;; would call your region fontification function instead of its own. For
+ − 1055 ;; example, TeX modes could fontify {\foo ...} and \bar{...} etc. multi-line
+ − 1056 ;; directives correctly and cleanly. (It is the same problem as fontifying
+ − 1057 ;; multi-line strings and comments; regexps are not appropriate for the job.)
+ − 1058
+ − 1059 ;;;###autoload
+ − 1060 (defun font-lock-fontify-buffer ()
+ − 1061 "Fontify the current buffer the way `font-lock-mode' would.
+ − 1062 See `font-lock-mode' for details.
+ − 1063
+ − 1064 This can take a while for large buffers."
+ − 1065 (interactive)
+ − 1066 (let ((font-lock-verbose (or font-lock-verbose (interactive-p))))
+ − 1067 (funcall font-lock-fontify-buffer-function)))
+ − 1068
+ − 1069 (defun font-lock-unfontify-buffer ()
+ − 1070 (funcall font-lock-unfontify-buffer-function))
+ − 1071
+ − 1072 (defun font-lock-fontify-region (beg end &optional loudly)
+ − 1073 (funcall font-lock-fontify-region-function beg end loudly))
+ − 1074
+ − 1075 (defun font-lock-unfontify-region (beg end &optional loudly)
+ − 1076 (funcall font-lock-unfontify-region-function beg end loudly))
+ − 1077
+ − 1078 (defun font-lock-default-fontify-buffer ()
+ − 1079 (interactive)
442
+ − 1080 ;; if we don't widen, then the C code will fail to
+ − 1081 ;; realize that we're inside a comment.
+ − 1082 (save-restriction
+ − 1083 (widen)
+ − 1084 (let ((was-on font-lock-mode)
+ − 1085 (font-lock-verbose (or font-lock-verbose (interactive-p)))
+ − 1086 (font-lock-message-threshold 0)
+ − 1087 (aborted nil))
+ − 1088 ;; Turn it on to run hooks and get the right font-lock-keywords.
+ − 1089 (or was-on (font-lock-mode 1))
+ − 1090 (font-lock-unfontify-region (point-min) (point-max) t)
+ − 1091 ;; (buffer-syntactic-context-flush-cache)
428
+ − 1092
442
+ − 1093 ;; If a ^G is typed during fontification, abort the fontification, but
+ − 1094 ;; return normally (do not signal.) This is to make it easy to abort
+ − 1095 ;; fontification if it's taking a long time, without also causing the
+ − 1096 ;; buffer not to pop up. If a real abort is desired, the user can ^G
+ − 1097 ;; again.
+ − 1098 ;;
+ − 1099 ;; Possibly this should happen down in font-lock-fontify-region instead
+ − 1100 ;; of here, but since that happens from the after-change-hook (meaning
+ − 1101 ;; much more frequently) I'm afraid of the bad consequences of stealing
+ − 1102 ;; the interrupt character at inopportune times.
+ − 1103 ;;
+ − 1104 (condition-case nil
+ − 1105 (save-excursion
+ − 1106 (font-lock-fontify-region (point-min) (point-max)))
+ − 1107 (t
+ − 1108 (setq aborted t)))
428
+ − 1109
442
+ − 1110 (or was-on ; turn it off if it was off.
+ − 1111 (let ((font-lock-fontified nil)) ; kludge to prevent defontification
+ − 1112 (font-lock-mode 0)))
+ − 1113 (set (make-local-variable 'font-lock-fontified) t)
+ − 1114 (when (and aborted font-lock-verbose)
+ − 1115 (progress-feedback-with-label 'font-lock "Fontifying %s... aborted."
+ − 1116 'abort (buffer-name))))
+ − 1117 (run-hooks 'font-lock-after-fontify-buffer-hook)))
428
+ − 1118
+ − 1119 (defun font-lock-default-unfontify-buffer ()
+ − 1120 (font-lock-unfontify-region (point-min) (point-max))
+ − 1121 (set (make-local-variable 'font-lock-fontified) nil))
+ − 1122
+ − 1123 ;; This used to be `font-lock-fontify-region', and before that,
+ − 1124 ;; `font-lock-fontify-region' used to be the name used for what is now
+ − 1125 ;; `font-lock-fontify-syntactically-region'.
+ − 1126 (defun font-lock-default-fontify-region (beg end &optional loudly)
+ − 1127 (let ((modified (buffer-modified-p))
+ − 1128 (buffer-undo-list t) (inhibit-read-only t)
+ − 1129 (old-syntax-table (syntax-table))
+ − 1130 buffer-file-name buffer-file-truename)
+ − 1131 (unwind-protect
+ − 1132 (progn
+ − 1133 ;; Use the fontification syntax table, if any.
+ − 1134 (if font-lock-syntax-table (set-syntax-table font-lock-syntax-table))
+ − 1135 ;; Now do the fontification.
460
+ − 1136 (font-lock-unfontify-region beg end)
+ − 1137 (when font-lock-syntactic-keywords
+ − 1138 (font-lock-fontify-syntactic-keywords-region beg end))
+ − 1139 (unless font-lock-keywords-only
428
+ − 1140 (font-lock-fontify-syntactically-region beg end loudly))
+ − 1141 (font-lock-fontify-keywords-region beg end loudly))
+ − 1142 ;; Clean up.
+ − 1143 (set-syntax-table old-syntax-table)
+ − 1144 (and (not modified) (buffer-modified-p) (set-buffer-modified-p nil)))))
+ − 1145
+ − 1146 ;; The following must be rethought, since keywords can override fontification.
+ − 1147 ; ;; Now scan for keywords, but not if we are inside a comment now.
+ − 1148 ; (or (and (not font-lock-keywords-only)
+ − 1149 ; (let ((state (parse-partial-sexp beg end nil nil
+ − 1150 ; font-lock-cache-state)))
+ − 1151 ; (or (nth 4 state) (nth 7 state))))
+ − 1152 ; (font-lock-fontify-keywords-region beg end))
+ − 1153
+ − 1154 (defun font-lock-default-unfontify-region (beg end &optional maybe-loudly)
+ − 1155 (when (and maybe-loudly font-lock-verbose
+ − 1156 (>= (- end beg) font-lock-message-threshold))
442
+ − 1157 (progress-feedback-with-label 'font-lock "Fontifying %s..." 0
+ − 1158 (buffer-name)))
428
+ − 1159 (let ((modified (buffer-modified-p))
+ − 1160 (buffer-undo-list t) (inhibit-read-only t)
+ − 1161 buffer-file-name buffer-file-truename)
+ − 1162 (font-lock-remove-face beg end)
+ − 1163 (and (not modified) (buffer-modified-p) (set-buffer-modified-p nil))))
+ − 1164
+ − 1165 ;; Following is the original FSF version (similar to our original
442
+ − 1166 ;; version, before the deferred stuff was added).
428
+ − 1167 ;;
+ − 1168 ;; I think that lazy-lock v2 tries to do something similar.
+ − 1169 ;; Those efforts should be merged.
+ − 1170
+ − 1171 ;; Called when any modification is made to buffer text.
+ − 1172 ;(defun font-lock-after-change-function (beg end old-len)
+ − 1173 ; (save-excursion
+ − 1174 ; (save-match-data
+ − 1175 ; ;; Rescan between start of line from `beg' and start of line after `end'.
+ − 1176 ; (font-lock-fontify-region
+ − 1177 ; (progn (goto-char beg) (beginning-of-line) (point))
+ − 1178 ; (progn (goto-char end) (forward-line 1) (point))))))
+ − 1179
442
+ − 1180 (defvar font-lock-always-fontify-immediately nil
+ − 1181 "Set this to non-nil to disable font-lock deferral.
+ − 1182 Otherwise, changes to existing text will not be processed until the
+ − 1183 next redisplay cycle, avoiding excessive fontification when many
+ − 1184 buffer modifications are performed or a buffer is reverted.")
428
+ − 1185
462
+ − 1186 ;; list of buffers in which there is a pending change.
+ − 1187 (defvar font-lock-pending-buffer-table (make-hash-table :weakness 'key))
+ − 1188 ;; table used to keep track of ranges needing fontification.
442
+ − 1189 (defvar font-lock-range-table (make-range-table))
428
+ − 1190
+ − 1191 (defun font-lock-pre-idle-hook ()
442
+ − 1192 (condition-case font-lock-error
462
+ − 1193 (if (> (hash-table-count font-lock-pending-buffer-table) 0)
442
+ − 1194 (font-lock-fontify-pending-extents))
+ − 1195 (error (warn "Error caught in `font-lock-pre-idle-hook': %s"
+ − 1196 font-lock-error))))
428
+ − 1197
+ − 1198 ;;; called when any modification is made to buffer text. This function
442
+ − 1199 ;;; remembers the changed ranges until the next redisplay, at which point
+ − 1200 ;;; the extents are merged and pruned, and the resulting ranges fontified.
+ − 1201 ;;; This function could easily be adapted to other after-change-functions.
428
+ − 1202
+ − 1203 (defun font-lock-after-change-function (beg end old-len)
442
+ − 1204 (when font-lock-mode
462
+ − 1205 ;; treat deletions as if the following character (or previous, if
664
+ − 1206 ;; there is no following) were inserted. (also use the previous
+ − 1207 ;; character at end of line. this avoids a problem when you
+ − 1208 ;; insert a comment on the line before a line of code: if we use
+ − 1209 ;; the following char, then when you hit backspace, the following
+ − 1210 ;; line of code turns the comment color.) this is a bit of a hack
462
+ − 1211 ;; but allows us to use text properties for everything.
+ − 1212 (if (= beg end)
664
+ − 1213 (cond ((not (eolp)) (setq end (1+ end)))
462
+ − 1214 ((/= beg (point-min)) (setq beg (1- beg)))
+ − 1215 (t nil)))
+ − 1216 (put-text-property beg end 'font-lock-pending t)
+ − 1217 (puthash (current-buffer) t font-lock-pending-buffer-table)
442
+ − 1218 (if font-lock-always-fontify-immediately
+ − 1219 (font-lock-fontify-pending-extents))))
428
+ − 1220
442
+ − 1221 (defun font-lock-fontify-pending-extents ()
+ − 1222 ;; ah, the beauty of mapping functions.
+ − 1223 ;; this function is actually shorter than the old version, which handled
+ − 1224 ;; only one buffer and one contiguous region!
+ − 1225 (save-match-data
+ − 1226 (maphash
462
+ − 1227 #'(lambda (buffer dummy)
442
+ − 1228 ;; remove first, to avoid infinite reprocessing if error
462
+ − 1229 (remhash buffer font-lock-pending-buffer-table)
442
+ − 1230 (when (buffer-live-p buffer)
+ − 1231 (clear-range-table font-lock-range-table)
+ − 1232 (with-current-buffer buffer
+ − 1233 (save-excursion
+ − 1234 (save-restriction
462
+ − 1235 ;; if we don't widen, then the C code in
+ − 1236 ;; syntactically-sectionize will fail to realize that
+ − 1237 ;; we're inside a comment. #### We don't actually use
+ − 1238 ;; syntactically-sectionize any more. Do we still
+ − 1239 ;; need the widen?
442
+ − 1240 (widen)
502
+ − 1241 (map-extents
+ − 1242 #'(lambda (ex dummy-maparg)
+ − 1243 ;; first expand the ranges to full lines,
+ − 1244 ;; because that is what will be fontified;
+ − 1245 ;; then use a range table to merge the
+ − 1246 ;; ranges. (we could also do this simply using
+ − 1247 ;; text properties. the range table code was
+ − 1248 ;; here from a previous version of this code
+ − 1249 ;; and works just as well.)
+ − 1250 (let* ((beg (extent-start-position ex))
+ − 1251 (end (extent-end-position ex))
+ − 1252 (beg (progn (goto-char beg)
+ − 1253 (beginning-of-line)
+ − 1254 (point)))
+ − 1255 (end (progn (goto-char end)
+ − 1256 (forward-line 1)
+ − 1257 (point))))
+ − 1258 (put-range-table beg end t
+ − 1259 font-lock-range-table)))
+ − 1260 nil nil nil nil nil 'font-lock-pending t)
+ − 1261 ;; clear all pending extents first in case of error below.
+ − 1262 (put-text-property (point-min) (point-max)
+ − 1263 'font-lock-pending nil)
+ − 1264 (map-range-table
+ − 1265 #'(lambda (beg end val)
462
+ − 1266 ;; This creates some unnecessary progress gauges.
442
+ − 1267 ;; (if (and (= beg (point-min))
+ − 1268 ;; (= end (point-max)))
+ − 1269 ;; (font-lock-fontify-buffer)
+ − 1270 ;; (font-lock-fontify-region beg end)))
502
+ − 1271 (font-lock-fontify-region beg end))
+ − 1272 font-lock-range-table))))))
462
+ − 1273 font-lock-pending-buffer-table)))
428
+ − 1274
+ − 1275 ;; Syntactic fontification functions.
+ − 1276
430
+ − 1277 (defun font-lock-lisp-like (mode)
+ − 1278 ;; Note: (or (get mode 'font-lock-lisp-like) (string-match ...)) is
+ − 1279 ;; not enough because the property needs to be able to specify a nil
+ − 1280 ;; value.
+ − 1281 (if (plist-member (symbol-plist mode) 'font-lock-lisp-like)
+ − 1282 (get mode 'font-lock-lisp-like)
+ − 1283 ;; If the property is not specified, guess. Similar logic exists
+ − 1284 ;; in add-log, but I think this encompasses more modes.
+ − 1285 (string-match "lisp\\|scheme" (symbol-name mode))))
+ − 1286
460
+ − 1287 ;; fontify-syntactically-region used to use syntactically-sectionize, which
+ − 1288 ;; was supposedly much faster than the FSF version because it was written in
+ − 1289 ;; C. However, the FSF version uses parse-partial-sexp, which is also
+ − 1290 ;; written in C, and the benchmarking I did showed the
+ − 1291 ;; syntactically-sectionize code to be slower overall. So here's the FSF
+ − 1292 ;; version, modified to support font-lock-doc-string-face.
+ − 1293 ;; -- mct 2000-12-29
428
+ − 1294 (defun font-lock-fontify-syntactically-region (start end &optional loudly)
+ − 1295 "Put proper face on each string and comment between START and END.
+ − 1296 START should be at the beginning of a line."
+ − 1297 (if font-lock-keywords-only
+ − 1298 nil
460
+ − 1299
+ − 1300 ;; #### Shouldn't this just be using 'loudly??
428
+ − 1301 (when (and font-lock-verbose
+ − 1302 (>= (- end start) font-lock-message-threshold))
442
+ − 1303 (progress-feedback-with-label 'font-lock
+ − 1304 "Fontifying %s... (syntactically)" 5
+ − 1305 (buffer-name)))
428
+ − 1306 (goto-char start)
460
+ − 1307
+ − 1308 (let ((lisp-like (font-lock-lisp-like major-mode))
+ − 1309 (cache (marker-position font-lock-cache-position))
+ − 1310 state string beg depth)
+ − 1311 ;;
+ − 1312 ;; Find the state at the `beginning-of-line' before `start'.
+ − 1313 (if (eq start cache)
+ − 1314 ;; Use the cache for the state of `start'.
+ − 1315 (setq state font-lock-cache-state)
+ − 1316 ;; Find the state of `start'.
+ − 1317 (if (null font-lock-beginning-of-syntax-function)
+ − 1318 ;; Use the state at the previous cache position, if any, or
+ − 1319 ;; otherwise calculate from `point-min'.
+ − 1320 (if (or (null cache) (< start cache))
+ − 1321 (setq state (parse-partial-sexp (point-min) start))
+ − 1322 (setq state (parse-partial-sexp cache start nil nil
+ − 1323 font-lock-cache-state)))
+ − 1324 ;; Call the function to move outside any syntactic block.
+ − 1325 (funcall font-lock-beginning-of-syntax-function)
+ − 1326 (setq state (parse-partial-sexp (point) start)))
+ − 1327 ;; Cache the state and position of `start'.
+ − 1328 (setq font-lock-cache-state state)
+ − 1329 (set-marker font-lock-cache-position start))
+ − 1330 ;;
+ − 1331 ;; If the region starts inside a string or comment, show the extent of it.
+ − 1332 (when (or (nth 3 state) (nth 4 state))
+ − 1333 (setq string (nth 3 state) beg (point))
+ − 1334 (setq state (parse-partial-sexp (point) end nil nil state 'syntax-table))
+ − 1335 (font-lock-set-face beg (point) (if string
+ − 1336 font-lock-string-face
+ − 1337 font-lock-comment-face)))
+ − 1338 ;;
+ − 1339 ;; Find each interesting place between here and `end'.
+ − 1340 (while (and (< (point) end)
+ − 1341 (progn
+ − 1342 (setq state (parse-partial-sexp (point) end nil nil state
+ − 1343 'syntax-table))
+ − 1344 (or (nth 3 state) (nth 4 state))))
+ − 1345 (setq depth (nth 0 state) string (nth 3 state) beg (nth 8 state))
+ − 1346 (setq state (parse-partial-sexp (point) end nil nil state 'syntax-table))
+ − 1347 (if string
+ − 1348 ;; #### It would be nice if we handled Python and other
+ − 1349 ;; non-Lisp languages with docstrings correctly.
+ − 1350 (let ((face (if (and lisp-like (= depth 1))
+ − 1351 'font-lock-doc-string-face
+ − 1352 'font-lock-string-face)))
+ − 1353 (if font-lock-fontify-string-delimiters
+ − 1354 (font-lock-set-face beg (point) face)
+ − 1355 (font-lock-set-face (+ beg 1) (- (point) 1) face)))
+ − 1356 (font-lock-set-face beg (point)
+ − 1357 font-lock-comment-face))))))
428
+ − 1358
+ − 1359 ;;; Additional text property functions.
+ − 1360
+ − 1361 ;; The following three text property functions are not generally available (and
+ − 1362 ;; it's not certain that they should be) so they are inlined for speed.
+ − 1363 ;; The case for `fillin-text-property' is simple; it may or not be generally
+ − 1364 ;; useful. (Since it is used here, it is useful in at least one place.;-)
+ − 1365 ;; However, the case for `append-text-property' and `prepend-text-property' is
+ − 1366 ;; more complicated. Should they remove duplicate property values or not? If
+ − 1367 ;; so, should the first or last duplicate item remain? Or the one that was
+ − 1368 ;; added? In our implementation, the first duplicate remains.
+ − 1369
+ − 1370 ;; XEmacs: modified all these functions to use
+ − 1371 ;; `put-nonduplicable-text-property' instead of `put-text-property', and
+ − 1372 ;; the first one to take both SETPROP and MARKPROP, in accordance with the
+ − 1373 ;; changed definitions of `font-lock-any-faces-p' and `font-lock-set-face'.
+ − 1374
+ − 1375 (defsubst font-lock-fillin-text-property (start end setprop markprop value &optional object)
+ − 1376 "Fill in one property of the text from START to END.
+ − 1377 Arguments PROP and VALUE specify the property and value to put where none are
+ − 1378 already in place. Therefore existing property values are not overwritten.
+ − 1379 Optional argument OBJECT is the string or buffer containing the text."
+ − 1380 (let ((start (text-property-any start end markprop nil object)) next)
+ − 1381 (while start
+ − 1382 (setq next (next-single-property-change start markprop object end))
+ − 1383 (put-nonduplicable-text-property start next setprop value object)
+ − 1384 (put-nonduplicable-text-property start next markprop value object)
+ − 1385 (setq start (text-property-any next end markprop nil object)))))
+ − 1386
+ − 1387 ;; This function (from simon's unique.el) is rewritten and inlined for speed.
+ − 1388 ;(defun unique (list function)
+ − 1389 ; "Uniquify LIST, deleting elements using FUNCTION.
+ − 1390 ;Return the list with subsequent duplicate items removed by side effects.
+ − 1391 ;FUNCTION is called with an element of LIST and a list of elements from LIST,
+ − 1392 ;and should return the list of elements with occurrences of the element removed,
+ − 1393 ;i.e., a function such as `delete' or `delq'.
+ − 1394 ;This function will work even if LIST is unsorted. See also `uniq'."
+ − 1395 ; (let ((list list))
+ − 1396 ; (while list
+ − 1397 ; (setq list (setcdr list (funcall function (car list) (cdr list))))))
+ − 1398 ; list)
+ − 1399
+ − 1400 (defsubst font-lock-unique (list)
+ − 1401 "Uniquify LIST, deleting elements using `delq'.
+ − 1402 Return the list with subsequent duplicate items removed by side effects."
+ − 1403 (let ((list list))
+ − 1404 (while list
+ − 1405 (setq list (setcdr list (delq (car list) (cdr list))))))
+ − 1406 list)
+ − 1407
+ − 1408 ;; A generalisation of `facemenu-add-face' for any property, but without the
+ − 1409 ;; removal of inactive faces via `facemenu-discard-redundant-faces' and special
+ − 1410 ;; treatment of `default'. Uses `unique' to remove duplicate property values.
+ − 1411 (defsubst font-lock-prepend-text-property (start end prop value &optional object)
+ − 1412 "Prepend to one property of the text from START to END.
+ − 1413 Arguments PROP and VALUE specify the property and value to prepend to the value
+ − 1414 already in place. The resulting property values are always lists, and unique.
+ − 1415 Optional argument OBJECT is the string or buffer containing the text."
+ − 1416 (let ((val (if (listp value) value (list value))) next prev)
+ − 1417 (while (/= start end)
+ − 1418 (setq next (next-single-property-change start prop object end)
+ − 1419 prev (get-text-property start prop object))
+ − 1420 (put-text-property
+ − 1421 start next prop
+ − 1422 (font-lock-unique (append val (if (listp prev) prev (list prev))))
+ − 1423 object)
+ − 1424 (setq start next))))
+ − 1425
+ − 1426 (defsubst font-lock-append-text-property (start end prop value &optional object)
+ − 1427 "Append to one property of the text from START to END.
+ − 1428 Arguments PROP and VALUE specify the property and value to append to the value
+ − 1429 already in place. The resulting property values are always lists, and unique.
+ − 1430 Optional argument OBJECT is the string or buffer containing the text."
+ − 1431 (let ((val (if (listp value) value (list value))) next prev)
+ − 1432 (while (/= start end)
+ − 1433 (setq next (next-single-property-change start prop object end)
+ − 1434 prev (get-text-property start prop object))
+ − 1435 (put-text-property
+ − 1436 start next prop
+ − 1437 (font-lock-unique (append (if (listp prev) prev (list prev)) val))
+ − 1438 object)
+ − 1439 (setq start next))))
+ − 1440
460
+ − 1441 ;;; Syntactic regexp fontification functions (taken from FSF Emacs 20.7.1)
+ − 1442
+ − 1443 ;; These syntactic keyword pass functions are identical to those keyword pass
+ − 1444 ;; functions below, with the following exceptions; (a) they operate on
+ − 1445 ;; `font-lock-syntactic-keywords' of course, (b) they are all `defun' as speed
+ − 1446 ;; is less of an issue, (c) eval of property value does not occur JIT as speed
+ − 1447 ;; is less of an issue, (d) OVERRIDE cannot be `prepend' or `append' as it
+ − 1448 ;; makes no sense for `syntax-table' property values, (e) they do not do it
+ − 1449 ;; LOUDLY as it is not likely to be intensive.
+ − 1450
+ − 1451 (defun font-lock-apply-syntactic-highlight (highlight)
+ − 1452 "Apply HIGHLIGHT following a match.
+ − 1453 HIGHLIGHT should be of the form MATCH-HIGHLIGHT,
+ − 1454 see `font-lock-syntactic-keywords'."
+ − 1455 (let* ((match (nth 0 highlight))
+ − 1456 (start (match-beginning match)) (end (match-end match))
+ − 1457 (value (nth 1 highlight))
+ − 1458 (override (nth 2 highlight)))
+ − 1459 (unless (numberp (car-safe value))
+ − 1460 (setq value (eval value)))
+ − 1461 (cond ((not start)
+ − 1462 ;; No match but we might not signal an error.
+ − 1463 (or (nth 3 highlight)
+ − 1464 (error "No match %d in highlight %S" match highlight)))
+ − 1465 ((not override)
+ − 1466 ;; Cannot override existing fontification.
+ − 1467 (or (map-extents 'extent-property (current-buffer)
+ − 1468 start end 'syntax-table)
+ − 1469 (font-lock-set-syntax start end value)))
+ − 1470 ((eq override t)
+ − 1471 ;; Override existing fontification.
+ − 1472 (font-lock-set-syntax start end value))
+ − 1473 ((eq override 'keep)
+ − 1474 ;; Keep existing fontification.
+ − 1475 (font-lock-fillin-text-property start end
+ − 1476 'syntax-table 'font-lock value)))))
+ − 1477
+ − 1478 (defun font-lock-fontify-syntactic-anchored-keywords (keywords limit)
+ − 1479 "Fontify according to KEYWORDS until LIMIT.
+ − 1480 KEYWORDS should be of the form MATCH-ANCHORED, see `font-lock-keywords',
+ − 1481 LIMIT can be modified by the value of its PRE-MATCH-FORM."
+ − 1482 (let ((matcher (nth 0 keywords)) (lowdarks (nthcdr 3 keywords)) highlights
+ − 1483 ;; Evaluate PRE-MATCH-FORM.
+ − 1484 (pre-match-value (eval (nth 1 keywords))))
+ − 1485 ;; Set LIMIT to value of PRE-MATCH-FORM or the end of line.
+ − 1486 (if (and (numberp pre-match-value) (> pre-match-value (point)))
+ − 1487 (setq limit pre-match-value)
+ − 1488 (save-excursion (end-of-line) (setq limit (point))))
+ − 1489 (save-match-data
+ − 1490 ;; Find an occurrence of `matcher' before `limit'.
+ − 1491 (while (if (stringp matcher)
+ − 1492 (re-search-forward matcher limit t)
+ − 1493 (funcall matcher limit))
+ − 1494 ;; Apply each highlight to this instance of `matcher'.
+ − 1495 (setq highlights lowdarks)
+ − 1496 (while highlights
+ − 1497 (font-lock-apply-syntactic-highlight (car highlights))
+ − 1498 (setq highlights (cdr highlights)))))
+ − 1499 ;; Evaluate POST-MATCH-FORM.
+ − 1500 (eval (nth 2 keywords))))
+ − 1501
+ − 1502 (defun font-lock-fontify-syntactic-keywords-region (start end)
+ − 1503 "Fontify according to `font-lock-syntactic-keywords' between START and END.
+ − 1504 START should be at the beginning of a line."
+ − 1505 ;; ;; If `font-lock-syntactic-keywords' is a symbol, get the real keywords.
+ − 1506 (when (symbolp font-lock-syntactic-keywords)
+ − 1507 (setq font-lock-syntactic-keywords (font-lock-eval-keywords
+ − 1508 font-lock-syntactic-keywords)))
+ − 1509 ;; If `font-lock-syntactic-keywords' is not compiled, compile it.
+ − 1510 (unless (eq (car font-lock-syntactic-keywords) t)
+ − 1511 (setq font-lock-syntactic-keywords (font-lock-compile-keywords
+ − 1512 font-lock-syntactic-keywords)))
+ − 1513 ;; Get down to business.
+ − 1514 (let ((case-fold-search font-lock-keywords-case-fold-search)
+ − 1515 (keywords (cdr font-lock-syntactic-keywords))
+ − 1516 keyword matcher highlights)
+ − 1517 (while keywords
+ − 1518 ;; Find an occurrence of `matcher' from `start' to `end'.
+ − 1519 (setq keyword (car keywords) matcher (car keyword))
+ − 1520 (goto-char start)
+ − 1521 (while (if (stringp matcher)
+ − 1522 (re-search-forward matcher end t)
+ − 1523 (funcall matcher end))
+ − 1524 ;; Apply each highlight to this instance of `matcher', which may be
+ − 1525 ;; specific highlights or more keywords anchored to `matcher'.
+ − 1526 (setq highlights (cdr keyword))
+ − 1527 (while highlights
+ − 1528 (if (numberp (car (car highlights)))
+ − 1529 (font-lock-apply-syntactic-highlight (car highlights))
+ − 1530 (font-lock-fontify-syntactic-anchored-keywords (car highlights)
+ − 1531 end))
+ − 1532 (setq highlights (cdr highlights)))
+ − 1533 )
+ − 1534 (setq keywords (cdr keywords)))))
+ − 1535
428
+ − 1536 ;;; Regexp fontification functions.
+ − 1537
+ − 1538 (defsubst font-lock-apply-highlight (highlight)
+ − 1539 "Apply HIGHLIGHT following a match.
+ − 1540 HIGHLIGHT should be of the form MATCH-HIGHLIGHT, see `font-lock-keywords'."
+ − 1541 (let* ((match (nth 0 highlight))
+ − 1542 (start (match-beginning match)) (end (match-end match))
+ − 1543 (override (nth 2 highlight)))
+ − 1544 (let ((newface (nth 1 highlight)))
+ − 1545 (or (symbolp newface)
+ − 1546 (setq newface (eval newface)))
+ − 1547 (cond ((not start)
+ − 1548 ;; No match but we might not signal an error.
+ − 1549 (or (nth 3 highlight)
+ − 1550 (error "No match %d in highlight %S" match highlight)))
+ − 1551 ((= start end) nil)
+ − 1552 ((not override)
+ − 1553 ;; Cannot override existing fontification.
+ − 1554 (or (font-lock-any-faces-p start end)
+ − 1555 (font-lock-set-face start end newface)))
+ − 1556 ((eq override t)
+ − 1557 ;; Override existing fontification.
+ − 1558 (font-lock-set-face start end newface))
+ − 1559 ((eq override 'keep)
+ − 1560 ;; Keep existing fontification.
+ − 1561 (font-lock-fillin-text-property start end 'face 'font-lock
+ − 1562 newface))
+ − 1563 ((eq override 'prepend)
+ − 1564 ;; Prepend to existing fontification.
+ − 1565 (font-lock-prepend-text-property start end 'face newface))
+ − 1566 ((eq override 'append)
+ − 1567 ;; Append to existing fontification.
+ − 1568 (font-lock-append-text-property start end 'face newface))))))
+ − 1569
+ − 1570 (defsubst font-lock-fontify-anchored-keywords (keywords limit)
+ − 1571 "Fontify according to KEYWORDS until LIMIT.
+ − 1572 KEYWORDS should be of the form MATCH-ANCHORED, see `font-lock-keywords',
+ − 1573 LIMIT can be modified by the value of its PRE-MATCH-FORM."
+ − 1574 (let ((matcher (nth 0 keywords)) (lowdarks (nthcdr 3 keywords)) highlights
+ − 1575 ;; Evaluate PRE-MATCH-FORM.
+ − 1576 (pre-match-value (eval (nth 1 keywords))))
+ − 1577 ;; Set LIMIT to value of PRE-MATCH-FORM or the end of line.
+ − 1578 (if (and (numberp pre-match-value) (> pre-match-value (point)))
+ − 1579 (setq limit pre-match-value)
+ − 1580 (save-excursion (end-of-line) (setq limit (point))))
+ − 1581 (save-match-data
+ − 1582 ;; Find an occurrence of `matcher' before `limit'.
+ − 1583 (while (if (stringp matcher)
+ − 1584 (re-search-forward matcher limit t)
+ − 1585 (funcall matcher limit))
+ − 1586 ;; Apply each highlight to this instance of `matcher'.
+ − 1587 (setq highlights lowdarks)
+ − 1588 (while highlights
+ − 1589 (font-lock-apply-highlight (car highlights))
+ − 1590 (setq highlights (cdr highlights)))))
+ − 1591 ;; Evaluate POST-MATCH-FORM.
+ − 1592 (eval (nth 2 keywords))))
+ − 1593
+ − 1594 (defun font-lock-fontify-keywords-region (start end &optional loudvar)
+ − 1595 "Fontify according to `font-lock-keywords' between START and END.
+ − 1596 START should be at the beginning of a line."
+ − 1597 (let ((loudly (and font-lock-verbose
+ − 1598 (>= (- end start) font-lock-message-threshold))))
566
+ − 1599 ;; If `font-lock-keywords' is not compiled, compile it.
+ − 1600 (unless (eq (car-safe font-lock-keywords) t)
+ − 1601 (setq font-lock-keywords (font-lock-compile-keywords
+ − 1602 font-lock-keywords)))
442
+ − 1603 (let* ((case-fold-search font-lock-keywords-case-fold-search)
566
+ − 1604 (keywords (cdr font-lock-keywords))
442
+ − 1605 (bufname (buffer-name))
+ − 1606 (progress 5) (old-progress 5)
+ − 1607 (iter 0)
+ − 1608 (nkeywords (length keywords))
+ − 1609 keyword matcher highlights)
428
+ − 1610 ;;
+ − 1611 ;; Fontify each item in `font-lock-keywords' from `start' to `end'.
442
+ − 1612 ;; In order to measure progress accurately we need to know how
+ − 1613 ;; many keywords we have and how big the region is. Then progress
+ − 1614 ;; is ((pos - start)/ (end - start) * nkeywords
+ − 1615 ;; + iteration / nkeywords) * 100
428
+ − 1616 (while keywords
+ − 1617 ;;
+ − 1618 ;; Find an occurrence of `matcher' from `start' to `end'.
+ − 1619 (setq keyword (car keywords) matcher (car keyword))
+ − 1620 (goto-char start)
+ − 1621 (while (and (< (point) end)
+ − 1622 (if (stringp matcher)
+ − 1623 (re-search-forward matcher end t)
+ − 1624 (funcall matcher end)))
442
+ − 1625 ;; calculate progress
+ − 1626 (setq progress
+ − 1627 (+ (/ (* (- (point) start) 95) (* (- end start) nkeywords))
+ − 1628 (/ (* iter 95) nkeywords) 5))
+ − 1629 (when (and loudly (> progress old-progress))
+ − 1630 (progress-feedback-with-label 'font-lock
+ − 1631 "Fontifying %s... (regexps)"
+ − 1632 progress bufname))
+ − 1633 (setq old-progress progress)
428
+ − 1634 ;; Apply each highlight to this instance of `matcher', which may be
+ − 1635 ;; specific highlights or more keywords anchored to `matcher'.
+ − 1636 (setq highlights (cdr keyword))
+ − 1637 (while highlights
+ − 1638 (if (numberp (car (car highlights)))
+ − 1639 (let ((end (match-end (car (car highlights)))))
+ − 1640 (font-lock-apply-highlight (car highlights))
+ − 1641 ;; restart search just after the end of the
+ − 1642 ;; keyword so keywords can share bracketing
+ − 1643 ;; expressions.
+ − 1644 (and end (goto-char end)))
+ − 1645 (font-lock-fontify-anchored-keywords (car highlights) end))
+ − 1646 (setq highlights (cdr highlights))))
442
+ − 1647 (setq iter (1+ iter))
428
+ − 1648 (setq keywords (cdr keywords))))
442
+ − 1649 (if loudly
+ − 1650 (progress-feedback-with-label 'font-lock "Fontifying %s... " 100
+ − 1651 (buffer-name)))))
428
+ − 1652
+ − 1653
+ − 1654 ;; Various functions.
+ − 1655
+ − 1656 ;; Turn off other related packages if they're on. I prefer a hook. --sm.
+ − 1657 ;; These explicit calls are easier to understand
+ − 1658 ;; because people know what they will do.
+ − 1659 ;; A hook is a mystery because it might do anything whatever. --rms.
+ − 1660 (defun font-lock-thing-lock-cleanup ()
+ − 1661 (cond ((and (boundp 'fast-lock-mode) fast-lock-mode)
+ − 1662 (fast-lock-mode -1))
+ − 1663 ((and (boundp 'lazy-lock-mode) lazy-lock-mode)
+ − 1664 (lazy-lock-mode -1))
+ − 1665 ((and (boundp 'lazy-shot-mode) lazy-shot-mode)
+ − 1666 (lazy-shot-mode -1))))
+ − 1667
502
+ − 1668 ; Do something special for these packages after fontifying. I prefer a hook.
428
+ − 1669 (defun font-lock-after-fontify-buffer ()
+ − 1670 (cond ((and (boundp 'fast-lock-mode) fast-lock-mode)
502
+ − 1671 (declare-fboundp (fast-lock-after-fontify-buffer)))
428
+ − 1672 ((and (boundp 'lazy-lock-mode) lazy-lock-mode)
502
+ − 1673 (declare-fboundp (lazy-lock-after-fontify-buffer)))))
428
+ − 1674
+ − 1675
+ − 1676 ;; Various functions.
+ − 1677
566
+ − 1678 (defun font-lock-compile-keywords (keywords)
428
+ − 1679 ;; Compile `font-lock-keywords' into the form (t KEYWORD ...) where KEYWORD
+ − 1680 ;; is the (MATCHER HIGHLIGHT ...) shown in the variable's doc string.
566
+ − 1681 (if (eq (car-safe keywords) t)
+ − 1682 keywords
+ − 1683 (cons t (mapcar 'font-lock-compile-keyword keywords))))
428
+ − 1684
+ − 1685 (defun font-lock-compile-keyword (keyword)
+ − 1686 (cond ((nlistp keyword) ; Just MATCHER
+ − 1687 (list keyword '(0 font-lock-keyword-face)))
+ − 1688 ((eq (car keyword) 'eval) ; Specified (eval . FORM)
+ − 1689 (font-lock-compile-keyword (eval (cdr keyword))))
+ − 1690 ((numberp (cdr keyword)) ; Specified (MATCHER . MATCH)
+ − 1691 (list (car keyword) (list (cdr keyword) 'font-lock-keyword-face)))
+ − 1692 ((symbolp (cdr keyword)) ; Specified (MATCHER . FACENAME)
+ − 1693 (list (car keyword) (list 0 (cdr keyword))))
+ − 1694 ((nlistp (nth 1 keyword)) ; Specified (MATCHER . HIGHLIGHT)
+ − 1695 (list (car keyword) (cdr keyword)))
+ − 1696 (t ; Hopefully (MATCHER HIGHLIGHT ...)
+ − 1697 keyword)))
+ − 1698
460
+ − 1699 (defun font-lock-eval-keywords (keywords)
+ − 1700 ;; Evalulate KEYWORDS if a function (funcall) or variable (eval) name.
+ − 1701 (if (listp keywords)
+ − 1702 keywords
+ − 1703 (font-lock-eval-keywords (if (fboundp keywords)
+ − 1704 (funcall keywords)
+ − 1705 (eval keywords)))))
+ − 1706
428
+ − 1707 (defun font-lock-choose-keywords (keywords level)
+ − 1708 ;; Return LEVELth element of KEYWORDS. A LEVEL of nil is equal to a
+ − 1709 ;; LEVEL of 0, a LEVEL of t is equal to (1- (length KEYWORDS)).
+ − 1710 (let ((level (if (not (consp level))
+ − 1711 level
+ − 1712 (cdr (or (assq major-mode level) (assq t level))))))
+ − 1713 (cond ((symbolp keywords)
+ − 1714 keywords)
+ − 1715 ((numberp level)
+ − 1716 (or (nth level keywords) (car (reverse keywords))))
+ − 1717 ((eq level t)
+ − 1718 (car (reverse keywords)))
+ − 1719 (t
+ − 1720 (car keywords)))))
+ − 1721
+ − 1722
+ − 1723 ;;; Determining which set of font-lock keywords to use.
+ − 1724
+ − 1725 (defun font-lock-find-font-lock-defaults (modesym)
+ − 1726 ;; Get the defaults based on the major mode.
+ − 1727 (let (raw-defaults)
+ − 1728 ;; I want a do-while loop!
+ − 1729 (while (progn
+ − 1730 (setq raw-defaults (get modesym 'font-lock-defaults))
+ − 1731 (and raw-defaults (symbolp raw-defaults)
+ − 1732 (setq modesym raw-defaults)))
+ − 1733 )
+ − 1734 raw-defaults))
+ − 1735
+ − 1736 (defun font-lock-examine-syntax-table ()
+ − 1737 ; Computes the value of font-lock-keywords-only for this buffer.
+ − 1738 (if (eq (syntax-table) (standard-syntax-table))
+ − 1739 ;; Assume that modes which haven't bothered to install their own
+ − 1740 ;; syntax table don't do anything syntactically interesting.
+ − 1741 ;; Really, the standard-syntax-table shouldn't have comments and
+ − 1742 ;; strings in it, but changing that now might break things.
+ − 1743 nil
+ − 1744 ;; else map over the syntax table looking for strings or comments.
+ − 1745 (let (got-one)
+ − 1746 ;; XEmacs 20.0 ...
+ − 1747 (if (fboundp 'map-syntax-table)
+ − 1748 (setq got-one
+ − 1749 (map-syntax-table
+ − 1750 #'(lambda (key value)
+ − 1751 (memq (char-syntax-from-code value)
+ − 1752 '(?\" ?\< ?\> ?\$)))
+ − 1753 (syntax-table)))
+ − 1754 ;; older Emacsen.
+ − 1755 (let ((i (1- (length (syntax-table)))))
+ − 1756 (while (>= i 0)
+ − 1757 (if (memq (char-syntax i) '(?\" ?\< ?\> ?\$))
+ − 1758 (setq got-one t i 0))
+ − 1759 (setq i (1- i)))))
+ − 1760 (set (make-local-variable 'font-lock-keywords-only) (not got-one)))))
+ − 1761
+ − 1762 ;; font-lock-set-defaults is in fontl-hooks.el.
+ − 1763
+ − 1764 ;;;###autoload
+ − 1765 (defun font-lock-set-defaults-1 (&optional explicit-defaults)
+ − 1766 ;; does everything that font-lock-set-defaults does except
+ − 1767 ;; enable font-lock-mode. This is called by `font-lock-mode'.
+ − 1768 ;; Note that the return value is used!
+ − 1769
+ − 1770 (if (and font-lock-defaults-computed (not explicit-defaults))
+ − 1771 ;; nothing to do.
+ − 1772 nil
+ − 1773
+ − 1774 (or font-lock-keywords
+ − 1775 (let* ((defaults (or (and (not (eq t explicit-defaults))
+ − 1776 explicit-defaults)
+ − 1777 ;; in case modes decide to set
+ − 1778 ;; `font-lock-defaults' themselves,
+ − 1779 ;; as in FSF Emacs.
+ − 1780 font-lock-defaults
+ − 1781 (font-lock-find-font-lock-defaults major-mode)))
+ − 1782 (keywords (font-lock-choose-keywords
+ − 1783 (nth 0 defaults) font-lock-maximum-decoration)))
460
+ − 1784
428
+ − 1785 ;; Keywords?
+ − 1786 (setq font-lock-keywords (if (fboundp keywords)
+ − 1787 (funcall keywords)
+ − 1788 (eval keywords)))
+ − 1789 (or font-lock-keywords
+ − 1790 ;; older way:
+ − 1791 ;; try to look for a variable `foo-mode-font-lock-keywords',
+ − 1792 ;; or similar.
+ − 1793 (let ((major (symbol-name major-mode))
+ − 1794 (try #'(lambda (n)
+ − 1795 (if (stringp n) (setq n (intern-soft n)))
+ − 1796 (if (and n
+ − 1797 (boundp n))
+ − 1798 n
+ − 1799 nil))))
+ − 1800 (setq font-lock-keywords
+ − 1801 (symbol-value
+ − 1802 (or (funcall try (get major-mode 'font-lock-keywords))
+ − 1803 (funcall try (concat major "-font-lock-keywords"))
+ − 1804 (funcall try (and (string-match "-mode\\'" major)
+ − 1805 (concat (substring
+ − 1806 major 0
+ − 1807 (match-beginning 0))
+ − 1808 "-font-lock-keywords")))
+ − 1809 'font-lock-keywords)))))
+ − 1810
+ − 1811 ;; Case fold?
+ − 1812 (if (>= (length defaults) 3)
+ − 1813 (setq font-lock-keywords-case-fold-search (nth 2 defaults))
+ − 1814 ;; older way:
+ − 1815 ;; look for a property 'font-lock-keywords-case-fold-search on
+ − 1816 ;; the major-mode symbol.
+ − 1817 (let* ((nonexist (make-symbol ""))
+ − 1818 (value (get major-mode 'font-lock-keywords-case-fold-search
+ − 1819 nonexist)))
+ − 1820 (if (not (eq nonexist value))
+ − 1821 (setq font-lock-keywords-case-fold-search value))))
+ − 1822
+ − 1823 ;; Syntactic?
+ − 1824 (if (>= (length defaults) 2)
+ − 1825 (setq font-lock-keywords-only (nth 1 defaults))
+ − 1826 ;; older way:
+ − 1827 ;; cleverly examine the syntax table.
+ − 1828 (font-lock-examine-syntax-table))
+ − 1829
+ − 1830 ;; Syntax table?
+ − 1831 (if (nth 3 defaults)
+ − 1832 (let ((slist (nth 3 defaults)))
+ − 1833 (setq font-lock-syntax-table
+ − 1834 (copy-syntax-table (syntax-table)))
+ − 1835 (while slist
+ − 1836 (modify-syntax-entry (car (car slist)) (cdr (car slist))
+ − 1837 font-lock-syntax-table)
+ − 1838 (setq slist (cdr slist)))))
+ − 1839
+ − 1840 ;; Syntax function?
+ − 1841 (cond (defaults
+ − 1842 (setq font-lock-beginning-of-syntax-function
+ − 1843 (nth 4 defaults)))
+ − 1844 (t
+ − 1845 ;; older way:
+ − 1846 ;; defaults not specified at all, so use `beginning-of-defun'.
+ − 1847 (setq font-lock-beginning-of-syntax-function
+ − 1848 'beginning-of-defun)))))
+ − 1849
460
+ − 1850 (setq font-lock-cache-position (make-marker))
428
+ − 1851 (setq font-lock-defaults-computed t)))
+ − 1852
+ − 1853
+ − 1854 ;;;;;;;;;;;;;;;;;;;;;; keywords ;;;;;;;;;;;;;;;;;;;;;;
+ − 1855
+ − 1856 ;;; Various major-mode interfaces.
+ − 1857 ;;; Probably these should go in with the source of the respective major modes.
+ − 1858
+ − 1859 ;; The defaults and keywords listed here should perhaps be moved into
+ − 1860 ;; mode-specific files.
+ − 1861
+ − 1862 ;; For C and Lisp modes we use `beginning-of-defun', rather than nil,
+ − 1863 ;; for SYNTAX-BEGIN. Thus the calculation of the cache is usually
+ − 1864 ;; faster but not infallible, so we risk mis-fontification. --sm.
+ − 1865
+ − 1866 (put 'c-mode 'font-lock-defaults
+ − 1867 '((c-font-lock-keywords
+ − 1868 c-font-lock-keywords-1 c-font-lock-keywords-2 c-font-lock-keywords-3)
+ − 1869 nil nil ((?_ . "w")) beginning-of-defun))
+ − 1870 (put 'c++-c-mode 'font-lock-defaults 'c-mode)
+ − 1871 (put 'elec-c-mode 'font-lock-defaults 'c-mode)
+ − 1872
+ − 1873 (put 'c++-mode 'font-lock-defaults
+ − 1874 '((c++-font-lock-keywords
+ − 1875 c++-font-lock-keywords-1 c++-font-lock-keywords-2
+ − 1876 c++-font-lock-keywords-3)
+ − 1877 nil nil ((?_ . "w") (?~ . "w")) beginning-of-defun))
+ − 1878
+ − 1879 (put 'java-mode 'font-lock-defaults
+ − 1880 '((java-font-lock-keywords
+ − 1881 java-font-lock-keywords-1 java-font-lock-keywords-2
+ − 1882 java-font-lock-keywords-3)
+ − 1883 nil nil ((?_ . "w")) beginning-of-defun
+ − 1884 (font-lock-mark-block-function . mark-defun)))
+ − 1885
+ − 1886 (put 'lisp-mode 'font-lock-defaults
+ − 1887 '((lisp-font-lock-keywords
+ − 1888 lisp-font-lock-keywords-1 lisp-font-lock-keywords-2)
+ − 1889 nil nil
+ − 1890 ((?: . "w") (?- . "w") (?* . "w") (?+ . "w") (?. . "w") (?< . "w")
+ − 1891 (?> . "w") (?= . "w") (?! . "w") (?? . "w") (?$ . "w") (?% . "w")
+ − 1892 (?_ . "w") (?& . "w") (?~ . "w") (?^ . "w") (?/ . "w"))
+ − 1893 beginning-of-defun))
+ − 1894 (put 'emacs-lisp-mode 'font-lock-defaults 'lisp-mode)
+ − 1895 (put 'lisp-interaction-mode 'font-lock-defaults 'lisp-mode)
+ − 1896
+ − 1897 (put 'scheme-mode 'font-lock-defaults
+ − 1898 '(scheme-font-lock-keywords
+ − 1899 nil t
+ − 1900 ((?: . "w") (?- . "w") (?* . "w") (?+ . "w") (?. . "w") (?< . "w")
+ − 1901 (?> . "w") (?= . "w") (?! . "w") (?? . "w") (?$ . "w") (?% . "w")
+ − 1902 (?_ . "w") (?& . "w") (?~ . "w") (?^ . "w") (?/ . "w"))
+ − 1903 beginning-of-defun))
+ − 1904 (put 'inferior-scheme-mode 'font-lock-defaults 'scheme-mode)
+ − 1905 (put 'scheme-interaction-mode 'font-lock-defaults 'scheme-mode)
+ − 1906
+ − 1907 (put 'tex-mode 'font-lock-defaults
+ − 1908 ;; For TeX modes we could use `backward-paragraph' for the same reason.
+ − 1909 '(tex-font-lock-keywords nil nil ((?$ . "\""))))
+ − 1910 ;; the nine billion names of TeX mode...
+ − 1911 (put 'bibtex-mode 'font-lock-defaults 'tex-mode)
+ − 1912 (put 'plain-tex-mode 'font-lock-defaults 'tex-mode)
+ − 1913 (put 'slitex-tex-mode 'font-lock-defaults 'tex-mode)
+ − 1914 (put 'SliTeX-mode 'font-lock-defaults 'tex-mode)
+ − 1915 (put 'slitex-mode 'font-lock-defaults 'tex-mode)
+ − 1916 (put 'latex-tex-mode 'font-lock-defaults 'tex-mode)
+ − 1917 (put 'LaTex-tex-mode 'font-lock-defaults 'tex-mode)
+ − 1918 (put 'latex-mode 'font-lock-defaults 'tex-mode)
+ − 1919 (put 'LaTeX-mode 'font-lock-defaults 'tex-mode)
+ − 1920 (put 'japanese-LaTeX-mode 'font-lock-defaults 'tex-mode)
+ − 1921 (put 'japanese-SliTeX-mode 'font-lock-defaults 'tex-mode)
+ − 1922 (put 'FoilTeX-mode 'font-lock-defaults 'tex-mode)
+ − 1923 (put 'LATeX-MoDe 'font-lock-defaults 'tex-mode)
+ − 1924 (put 'lATEx-mODe 'font-lock-defaults 'tex-mode)
+ − 1925 ;; ok, this is getting a bit silly ...
+ − 1926 (put 'eDOm-xETAl 'font-lock-defaults 'tex-mode)
+ − 1927
+ − 1928 ;;; Various regexp information shared by several modes.
+ − 1929 ;;; Information specific to a single mode should go in its load library.
+ − 1930
+ − 1931 (defconst lisp-font-lock-keywords-1
+ − 1932 (list
+ − 1933 ;; Anything not a variable or type declaration is fontified as a function.
+ − 1934 ;; It would be cleaner to allow preceding whitespace, but it would also be
+ − 1935 ;; about five times slower.
+ − 1936 (list (concat "^(\\(def\\("
+ − 1937 ;; Variable declarations.
+ − 1938 "\\(const\\(\\|ant\\)\\|ine-key\\(\\|-after\\)\\|var\\|custom\\)\\|"
+ − 1939 ;; Structure declarations.
+ − 1940 "\\(class\\|struct\\|type\\)\\|"
+ − 1941 ;; Everything else is a function declaration.
+ − 1942 "\\([^ \t\n\(\)]+\\)"
+ − 1943 "\\)\\)\\>"
+ − 1944 ;; Any whitespace and declared object.
+ − 1945 "[ \t'\(]*"
+ − 1946 "\\([^ \t\n\)]+\\)?")
+ − 1947 '(1 font-lock-keyword-face)
+ − 1948 '(8 (cond ((match-beginning 3) 'font-lock-variable-name-face)
+ − 1949 ((match-beginning 6) 'font-lock-type-face)
+ − 1950 (t 'font-lock-function-name-face))
+ − 1951 nil t))
+ − 1952 )
+ − 1953 "Subdued level highlighting Lisp modes.")
+ − 1954
+ − 1955 (defconst lisp-font-lock-keywords-2
+ − 1956 (append lisp-font-lock-keywords-1
+ − 1957 (list
+ − 1958 ;;
+ − 1959 ;; Control structures. ELisp and CLisp combined.
+ − 1960 ;;
+ − 1961 (cons
+ − 1962 (concat
+ − 1963 "(\\("
442
+ − 1964 ;; beginning of generated stuff
+ − 1965 ;; to regenerate, use the regexp-opt below, then delete the outermost
+ − 1966 ;; grouping, then use the macro below to break up the string.
+ − 1967 ;; (regexp-opt
+ − 1968 ;; '("cond" "if" "while" "let" "let*" "prog" "progn" "prog1"
+ − 1969 ;; "prog2" "progv" "catch" "throw" "save-restriction"
+ − 1970 ;; "save-excursion" "save-window-excursion"
+ − 1971 ;; "save-current-buffer" "with-current-buffer"
+ − 1972 ;; "save-selected-window" "with-selected-window"
+ − 1973 ;; "save-selected-frame" "with-selected-frame"
+ − 1974 ;; "with-temp-file" "with-temp-buffer" "with-output-to-string"
+ − 1975 ;; "with-string-as-buffer-contents"
+ − 1976 ;; "save-match-data" "unwind-protect" "call-with-condition-handler"
+ − 1977 ;; "condition-case" "track-mouse" "autoload"
+ − 1978 ;; "eval-after-load" "eval-and-compile" "eval-when-compile"
+ − 1979 ;; "when" "unless" "do" "dolist" "dotimes" "flet" "labels"
+ − 1980 ;; "lambda" "block" "return" "return-from" "loop") t)
+ − 1981 ;; (setq last-kbd-macro
+ − 1982 ;; (read-kbd-macro "\" C-7 C-1 <right> C-r \\\\| 3*<right> \" RET"))
+ − 1983 "autoload\\|block\\|c\\(?:a\\(?:ll-with-condition-handler\\|tch\\)\\|"
+ − 1984 "ond\\(?:ition-case\\)?\\)\\|do\\(?:list\\|times\\)?\\|"
+ − 1985 "eval-\\(?:a\\(?:fter-load\\|nd-compile\\)\\|when-compile\\)\\|flet\\|"
+ − 1986 "if\\|l\\(?:a\\(?:bels\\|mbda\\)\\|et\\*?\\|oop\\)\\|prog[12nv]?\\|"
+ − 1987 "return\\(?:-from\\)?\\|save-\\(?:current-buffer\\|excursion\\|"
+ − 1988 "match-data\\|restriction\\|selected-\\(?:frame\\|window\\)\\|"
+ − 1989 "window-excursion\\)\\|t\\(?:hrow\\|rack-mouse\\)\\|un\\(?:less\\|"
+ − 1990 "wind-protect\\)\\|w\\(?:h\\(?:en\\|ile\\)\\|ith-\\(?:current-buffer\\|"
+ − 1991 "output-to-string\\|s\\(?:elected-\\(?:frame\\|window\\)\\|"
+ − 1992 "tring-as-buffer-contents\\)\\|temp-\\(?:buffer\\|file\\)\\)\\)"
+ − 1993 ;; end of generated stuff
428
+ − 1994 "\\)\\>") 1)
+ − 1995 ;;
+ − 1996 ;; Feature symbols as references.
+ − 1997 '("(\\(featurep\\|provide\\|require\\)\\>[ \t']*\\(\\sw+\\)?"
+ − 1998 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t))
+ − 1999 ;;
+ − 2000 ;; Words inside \\[] tend to be for `substitute-command-keys'.
+ − 2001 '("\\\\\\\\\\[\\(\\sw+\\)]" 1 font-lock-reference-face prepend)
+ − 2002 ;;
+ − 2003 ;; Words inside `' tend to be symbol names.
+ − 2004 '("`\\(\\sw\\sw+\\)'" 1 font-lock-reference-face prepend)
+ − 2005 ;;
+ − 2006 ;; CLisp `:' keywords as references.
+ − 2007 '("\\<:\\sw+\\>" 0 font-lock-reference-face prepend)
+ − 2008 ;;
+ − 2009 ;; ELisp and CLisp `&' keywords as types.
+ − 2010 '("\\<\\&\\(optional\\|rest\\|whole\\)\\>" . font-lock-type-face)
+ − 2011 ))
+ − 2012 "Gaudy level highlighting for Lisp modes.")
+ − 2013
+ − 2014 (defvar lisp-font-lock-keywords lisp-font-lock-keywords-1
+ − 2015 "Default expressions to highlight in Lisp modes.")
+ − 2016
+ − 2017 ;; The previous version, before replacing it with the FSF version.
+ − 2018 ;(defconst lisp-font-lock-keywords-1 (purecopy
+ − 2019 ; '(;;
+ − 2020 ; ;; highlight defining forms. This doesn't work too nicely for
+ − 2021 ; ;; (defun (setf foo) ...) but it does work for (defvar foo) which
+ − 2022 ; ;; is more important.
+ − 2023 ; ("^(def[-a-z]+\\s +\\([^ \t\n\)]+\\)" 1 font-lock-function-name-face)
+ − 2024 ; ;;
+ − 2025 ; ;; highlight CL keywords (three clauses seems faster than one)
+ − 2026 ; ("\\s :\\(\\(\\sw\\|\\s_\\)+\\)\\>" . 1)
+ − 2027 ; ("(:\\(\\(\\sw\\|\\s_\\)+\\)\\>" . 1)
+ − 2028 ; ("':\\(\\(\\sw\\|\\s_\\)+\\)\\>" . 1)
+ − 2029 ; ;;
+ − 2030 ; ;; this is highlights things like (def* (setf foo) (bar baz)), but may
+ − 2031 ; ;; be slower (I haven't really thought about it)
+ − 2032 ;; ("^(def[-a-z]+\\s +\\(\\s(\\S)*\\s)\\|\\S(\\S *\\)"
+ − 2033 ;; 1 font-lock-function-name-face)
+ − 2034 ; ))
+ − 2035 ; "For consideration as a value of `lisp-font-lock-keywords'.
+ − 2036 ;This does fairly subdued highlighting.")
+ − 2037 ;
+ − 2038 ;(defconst lisp-font-lock-keywords-2 (purecopy
+ − 2039 ; (append lisp-font-lock-keywords-1
+ − 2040 ; '(;;
+ − 2041 ; ;; Highlight control structures
+ − 2042 ; ("(\\(cond\\|if\\|when\\|unless\\|[ec]?\\(type\\)?case\\)[ \t\n]" . 1)
+ − 2043 ; ("(\\(while\\|do\\|let\\*?\\|flet\\|labels\\|prog[nv12*]?\\)[ \t\n]" . 1)
+ − 2044 ; ("(\\(do\\*\\|dotimes\\|dolist\\|loop\\)[ \t\n]" . 1)
+ − 2045 ; ("(\\(catch\\|\\throw\\|block\\|return\\|return-from\\)[ \t\n]" . 1)
+ − 2046 ; ("(\\(save-restriction\\|save-window-restriction\\)[ \t\n]" . 1)
+ − 2047 ; ("(\\(save-excursion\\|unwind-protect\\|condition-case\\)[ \t\n]" . 1)
+ − 2048 ; ;;
+ − 2049 ; ;; highlight function names in emacs-lisp docstrings (in the syntax
+ − 2050 ; ;; that substitute-command-keys understands.)
+ − 2051 ; ("\\\\\\\\\\[\\([^]\\\n]+\\)]" 1 font-lock-keyword-face t)
+ − 2052 ; ;;
+ − 2053 ; ;; highlight words inside `' which tend to be function names
+ − 2054 ; ("`\\([-a-zA-Z0-9_][-a-zA-Z0-9_][-a-zA-Z0-9_.]+\\)'"
+ − 2055 ; 1 font-lock-keyword-face t)
+ − 2056 ; )))
+ − 2057 ; "For consideration as a value of `lisp-font-lock-keywords'.
+ − 2058 ;
+ − 2059 ;This does a lot more highlighting.")
+ − 2060
+ − 2061 (defvar scheme-font-lock-keywords
+ − 2062 (eval-when-compile
+ − 2063 (list
+ − 2064 ;;
+ − 2065 ;; Declarations. Hannes Haug <hannes.haug@student.uni-tuebingen.de> says
+ − 2066 ;; this works for SOS, STklos, SCOOPS, Meroon and Tiny CLOS.
+ − 2067 (list (concat "(\\(define\\("
+ − 2068 ;; Function names.
+ − 2069 "\\(\\|-\\(generic\\(\\|-procedure\\)\\|method\\)\\)\\|"
+ − 2070 ;; Macro names, as variable names. A bit dubious, this.
+ − 2071 "\\(-syntax\\)\\|"
+ − 2072 ;; Class names.
+ − 2073 "\\(-class\\)"
+ − 2074 "\\)\\)\\>"
+ − 2075 ;; Any whitespace and declared object.
+ − 2076 "[ \t]*(?"
+ − 2077 "\\(\\sw+\\)?")
+ − 2078 '(1 font-lock-keyword-face)
+ − 2079 '(8 (cond ((match-beginning 3) 'font-lock-function-name-face)
+ − 2080 ((match-beginning 6) 'font-lock-variable-name-face)
+ − 2081 (t 'font-lock-type-face))
+ − 2082 nil t))
+ − 2083 ;;
+ − 2084 ;; Control structures.
+ − 2085 ;(regexp-opt '("begin" "call-with-current-continuation" "call/cc"
+ − 2086 ; "call-with-input-file" "call-with-output-file" "case" "cond"
+ − 2087 ; "do" "else" "for-each" "if" "lambda"
+ − 2088 ; "let\\*?" "let-syntax" "letrec" "letrec-syntax"
+ − 2089 ; ;; Hannes Haug <hannes.haug@student.uni-tuebingen.de> wants:
+ − 2090 ; "and" "or" "delay"
+ − 2091 ; ;; Stefan Monnier <stefan.monnier@epfl.ch> says don't bother:
+ − 2092 ; ;;"quasiquote" "quote" "unquote" "unquote-splicing"
+ − 2093 ; "map" "syntax" "syntax-rules"))
+ − 2094 (cons
+ − 2095 (concat "(\\("
+ − 2096 "and\\|begin\\|c\\(a\\(ll\\(-with-\\(current-continuation\\|"
+ − 2097 "input-file\\|output-file\\)\\|/cc\\)\\|se\\)\\|ond\\)\\|"
+ − 2098 "d\\(elay\\|o\\)\\|else\\|for-each\\|if\\|"
+ − 2099 "l\\(ambda\\|et\\(-syntax\\|\\*?\\|rec\\(\\|-syntax\\)\\)\\)\\|"
+ − 2100 "map\\|or\\|syntax\\(\\|-rules\\)"
+ − 2101 "\\)\\>") 1)
+ − 2102 ;;
+ − 2103 ;; David Fox <fox@graphics.cs.nyu.edu> for SOS/STklos class specifiers.
+ − 2104 '("\\<<\\sw+>\\>" . font-lock-type-face)
+ − 2105 ;;
+ − 2106 ;; Scheme `:' keywords as references.
+ − 2107 '("\\<:\\sw+\\>" . font-lock-reference-face)
+ − 2108 ))
+ − 2109 "Default expressions to highlight in Scheme modes.")
+ − 2110
+ − 2111 ;; The previous version, before replacing it with the FSF version.
+ − 2112 ;(defconst scheme-font-lock-keywords (purecopy
+ − 2113 ; '(("(define[ \t]+(?\\([^ \t\n\)]+\\)" 1 font-lock-function-name-face)
+ − 2114 ; ("(\\(cond\\|lambda\\|begin\\|if\\|else\\|case\\|do\\)[ \t\n]" . 1)
+ − 2115 ; ("(\\(\\|letrec\\|let\\*?\\|set!\\|and\\|or\\)[ \t\n]" . 1)
+ − 2116 ; ("(\\(quote\\|unquote\\|quasiquote\\|unquote-splicing\\)[ \t\n]" . 1)
+ − 2117 ; ("(\\(syntax\\|syntax-rules\\|define-syntax\\|let-syntax\\|letrec-syntax\\)[ \t\n]" . 1)))
+ − 2118 ; "Expressions to highlight in Scheme buffers.")
+ − 2119
+ − 2120 (defconst c-font-lock-keywords-1 nil
+ − 2121 "Subdued level highlighting for C modes.")
+ − 2122
+ − 2123 (defconst c-font-lock-keywords-2 nil
+ − 2124 "Medium level highlighting for C modes.")
+ − 2125
+ − 2126 (defconst c-font-lock-keywords-3 nil
+ − 2127 "Gaudy level highlighting for C modes.")
+ − 2128
+ − 2129 (defconst c++-font-lock-keywords-1 nil
+ − 2130 "Subdued level highlighting for C++ modes.")
+ − 2131
+ − 2132 (defconst c++-font-lock-keywords-2 nil
+ − 2133 "Medium level highlighting for C++ modes.")
+ − 2134
+ − 2135 (defconst c++-font-lock-keywords-3 nil
+ − 2136 "Gaudy level highlighting for C++ modes.")
+ − 2137
+ − 2138 (defun font-lock-match-c++-style-declaration-item-and-skip-to-next (limit)
+ − 2139 ;; Match, and move over, any declaration/definition item after point.
+ − 2140 ;; The expect syntax of an item is "word" or "word::word", possibly ending
+ − 2141 ;; with optional whitespace and a "(". Everything following the item (but
+ − 2142 ;; belonging to it) is expected to by skip-able by `forward-sexp', and items
+ − 2143 ;; are expected to be separated with a "," or ";".
+ − 2144 (if (looking-at "[ \t*&]*\\(\\(?:\\sw\\|\\s_\\)+\\)\\(::\\(\\(?:\\sw\\|\\s_\\)+\\)\\)?[ \t]*\\((\\)?")
+ − 2145 (save-match-data
+ − 2146 (condition-case nil
+ − 2147 (save-restriction
+ − 2148 ;; Restrict to the end of line, currently guaranteed to be LIMIT.
+ − 2149 (narrow-to-region (point-min) limit)
+ − 2150 (goto-char (match-end 1))
+ − 2151 ;; Move over any item value, etc., to the next item.
+ − 2152 (while (not (looking-at "[ \t]*\\([,;]\\|$\\)"))
+ − 2153 (goto-char (or (scan-sexps (point) 1) (point-max))))
+ − 2154 (goto-char (match-end 0)))
+ − 2155 (error t)))))
+ − 2156
+ − 2157 (let ((c-keywords
+ − 2158 ; ("break" "continue" "do" "else" "for" "if" "return" "switch" "while")
+ − 2159 "break\\|continue\\|do\\|else\\|for\\|if\\|return\\|switch\\|while")
+ − 2160 (c-type-types
+ − 2161 ; ("auto" "extern" "register" "static" "typedef" "struct" "union" "enum"
+ − 2162 ; "signed" "unsigned" "short" "long" "int" "char" "float" "double"
+ − 2163 ; "void" "volatile" "const")
+ − 2164 (concat "auto\\|c\\(har\\|onst\\)\\|double\\|e\\(num\\|xtern\\)\\|"
+ − 2165 "float\\|int\\|long\\|register\\|"
+ − 2166 "s\\(hort\\|igned\\|t\\(atic\\|ruct\\)\\)\\|typedef\\|"
+ − 2167 "un\\(ion\\|signed\\)\\|vo\\(id\\|latile\\)")) ; 6 ()s deep.
+ − 2168 (c++-keywords
+ − 2169 ; ("break" "continue" "do" "else" "for" "if" "return" "switch" "while"
+ − 2170 ; "asm" "catch" "delete" "new" "operator" "sizeof" "this" "throw" "try"
448
+ − 2171 ; "protected" "private" "public" "const_cast" "dynamic_cast" "reinterpret_cast"
+ − 2172 ; "static_cast" "and" "bitor" "or" "xor" "compl" "bitand" "and_eq"
+ − 2173 ; "or_eq" "xor_eq" "not" "not_eq" "typeid" "false" "true")
+ − 2174 (concat "a\\(nd\\(\\|_eq\\)\\|sm\\)\\|"
+ − 2175 "b\\(it\\(or\\|and\\)\\|reak\\)\\|"
+ − 2176 "c\\(atch\\|o\\(mpl\\|n\\(tinue\\|st_cast\\)\\)\\)\\|"
+ − 2177 "d\\(elete\\|o\\|ynamic_cast\\)\\|"
+ − 2178 "else\\|"
+ − 2179 "f\\(alse\\|or\\)\\|if\\|"
+ − 2180 "n\\(ew\\|ot\\(\\|_eq\\)\\)\\|"
+ − 2181 "p\\(r\\(ivate\\|otected\\)\\|ublic\\)\\|"
+ − 2182 "or\\(\\|_eq\\)\\|"
+ − 2183 "re\\(interpret_cast\\|turn\\)\\|"
+ − 2184 "s\\(izeof\\|tatic_cast\\|witch\\)\\|"
+ − 2185 "t\\(h\\(is\\|row\\)\\|r\\(ue\\|y\\)\\|ypeid\\)\\|"
+ − 2186 "xor\\(\\|_eq\\)\\|while"))
428
+ − 2187 (c++-type-types
+ − 2188 ; ("auto" "extern" "register" "static" "typedef" "struct" "union" "enum"
+ − 2189 ; "signed" "unsigned" "short" "long" "int" "char" "float" "double"
+ − 2190 ; "void" "volatile" "const" "class" "inline" "friend" "bool"
448
+ − 2191 ; "virtual" "complex" "template" "explicit" "mutable" "export" "namespace"
+ − 2192 ; "using" "typename" "wchar_t")
428
+ − 2193 (concat "auto\\|bool\\|c\\(har\\|lass\\|o\\(mplex\\|nst\\)\\)\\|"
448
+ − 2194 "double\\|"
+ − 2195 "e\\(num\\|x\\(p\\(licit\\|ort\\)\\|tern\\)\\)\\|"
+ − 2196 "f\\(loat\\|riend\\)\\|"
+ − 2197 "in\\(line\\|t\\)\\|long\\|mutable\\|namespace\\|register\\|"
428
+ − 2198 "s\\(hort\\|igned\\|t\\(atic\\|ruct\\)\\)\\|"
448
+ − 2199 "t\\(emplate\\|ype\\(def\\|name\\)\\)\\|"
+ − 2200 "u\\(\\(n\\(ion\\|signed\\)\\|sing\\)\\)\\|"
+ − 2201 "v\\(irtual\\|o\\(id\\|latile\\)\\)\\|"
+ − 2202 "wchar_t")) ; 11 ()s deep.
428
+ − 2203 (ctoken "\\(\\sw\\|\\s_\\|[:~*&]\\)+")
+ − 2204 )
+ − 2205 (setq c-font-lock-keywords-1
+ − 2206 (list
+ − 2207 ;;
+ − 2208 ;; These are all anchored at the beginning of line for speed.
+ − 2209 ;;
+ − 2210 ;; Fontify function name definitions (GNU style; without type on line).
+ − 2211
+ − 2212 ;; In FSF this has the simpler definition of "\\sw+" for ctoken.
+ − 2213 ;; I'm not sure if ours is more correct.
+ − 2214 ;; This is a subset of the next rule, and is slower when present. --dmoore
+ − 2215 ;; (list (concat "^\\(" ctoken "\\)[ \t]*(") 1 'font-lock-function-name-face)
+ − 2216 ;;
+ − 2217 ;; fontify the names of functions being defined.
+ − 2218 ;; FSF doesn't have this but I think it should be fast for us because
+ − 2219 ;; our regexp routines are more intelligent than FSF's about handling
+ − 2220 ;; anchored-at-newline. (When I added this hack in regex.c, it halved
+ − 2221 ;; the time to do the regexp phase of font-lock for a C file!) Not
+ − 2222 ;; including this discriminates against those who don't follow the
+ − 2223 ;; GNU coding style. --ben
+ − 2224 ;; x?x?x?y?z should always be: (x(xx?)?)?y?z --dmoore
+ − 2225 (list (concat
+ − 2226 "^\\("
+ − 2227 "\\(" ctoken "[ \t]+\\)" ; type specs; there can be no
+ − 2228 "\\("
+ − 2229 "\\(" ctoken "[ \t]+\\)" ; more than 3 tokens, right?
+ − 2230 "\\(" ctoken "[ \t]+\\)"
+ − 2231 "?\\)?\\)?"
+ − 2232 "\\([*&]+[ \t]*\\)?" ; pointer
+ − 2233 "\\(" ctoken "\\)[ \t]*(") ; name
+ − 2234 10 'font-lock-function-name-face)
+ − 2235 ;;
+ − 2236 ;; This is faster but not by much. I don't see why not.
+ − 2237 ;(list (concat "^\\(" ctoken "\\)[ \t]*(") 1 'font-lock-function-name-face)
+ − 2238 ;;
+ − 2239 ;; Added next two; they're both jolly-good fastmatch candidates so
+ − 2240 ;; should be fast. --ben
+ − 2241 ;;
+ − 2242 ;; Fontify structure names (in structure definition form).
+ − 2243 (list (concat "^\\(typedef[ \t]+struct\\|struct\\|static[ \t]+struct\\)"
+ − 2244 "[ \t]+\\(" ctoken "\\)[ \t]*\\(\{\\|$\\)")
+ − 2245 2 'font-lock-function-name-face)
+ − 2246 ;;
+ − 2247 ;; Fontify case clauses. This is fast because its anchored on the left.
+ − 2248 '("case[ \t]+\\(\\(\\sw\\|\\s_\\)+\\)[ \t]+:". 1)
+ − 2249 ;;
+ − 2250 '("\\<\\(default\\):". 1)
+ − 2251 ;; Fontify filenames in #include <...> preprocessor directives as strings.
+ − 2252 '("^#[ \t]*include[ \t]+\\(<[^>\"\n]+>\\)" 1 font-lock-string-face)
+ − 2253 ;;
+ − 2254 ;; Fontify function macro names.
+ − 2255 '("^#[ \t]*define[ \t]+\\(\\(\\sw+\\)(\\)" 2 font-lock-function-name-face)
+ − 2256 ;;
+ − 2257 ;; Fontify symbol names in #if ... defined preprocessor directives.
+ − 2258 '("^#[ \t]*if\\>"
+ − 2259 ("\\<\\(defined\\)\\>[ \t]*(?\\(\\sw+\\)?" nil nil
+ − 2260 (1 font-lock-preprocessor-face) (2 font-lock-variable-name-face nil t)))
+ − 2261 ;;
+ − 2262 ;; Fontify symbol names in #elif ... defined preprocessor directives.
+ − 2263 '("^#[ \t]*elif\\>"
+ − 2264 ("\\<\\(defined\\)\\>[ \t]*(?\\(\\sw+\\)?" nil nil
+ − 2265 (1 font-lock-preprocessor-face) (2 font-lock-variable-name-face nil t)))
+ − 2266 ;;
+ − 2267 ;; Fontify otherwise as symbol names, and the preprocessor directive names.
+ − 2268 '("^\\(#[ \t]*[a-z]+\\)\\>[ \t]*\\(\\sw+\\)?"
+ − 2269 (1 font-lock-preprocessor-face) (2 font-lock-variable-name-face nil t))
+ − 2270 ))
+ − 2271
+ − 2272 (setq c-font-lock-keywords-2
+ − 2273 (append c-font-lock-keywords-1
+ − 2274 (list
+ − 2275 ;;
+ − 2276 ;; Simple regexps for speed.
+ − 2277 ;;
+ − 2278 ;; Fontify all type specifiers.
+ − 2279 (cons (concat "\\<\\(" c-type-types "\\)\\>") 'font-lock-type-face)
+ − 2280 ;;
+ − 2281 ;; Fontify all builtin keywords (except case, default and goto; see below).
+ − 2282 (cons (concat "\\<\\(" c-keywords "\\)\\>") 'font-lock-keyword-face)
+ − 2283 ;;
+ − 2284 ;; Fontify case/goto keywords and targets, and case default/goto tags.
+ − 2285 '("\\<\\(case\\|goto\\)\\>[ \t]*\\([^ \t\n:;]+\\)?"
+ − 2286 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t))
+ − 2287 '("^[ \t]*\\(\\sw+\\)[ \t]*:" 1 font-lock-reference-face)
+ − 2288 )))
+ − 2289
+ − 2290 (setq c-font-lock-keywords-3
+ − 2291 (append c-font-lock-keywords-2
+ − 2292 ;;
+ − 2293 ;; More complicated regexps for more complete highlighting for types.
+ − 2294 ;; We still have to fontify type specifiers individually, as C is so hairy.
+ − 2295 (list
+ − 2296 ;;
+ − 2297 ;; Fontify all storage classes and type specifiers, plus their items.
+ − 2298 (list (concat "\\<\\(" c-type-types "\\)\\>"
+ − 2299 "\\([ \t*&]+\\sw+\\>\\)*")
+ − 2300 ;; Fontify each declaration item.
+ − 2301 '(font-lock-match-c++-style-declaration-item-and-skip-to-next
+ − 2302 ;; Start with point after all type specifiers.
+ − 2303 (goto-char (or (match-beginning 8) (match-end 1)))
+ − 2304 ;; Finish with point after first type specifier.
+ − 2305 (goto-char (match-end 1))
+ − 2306 ;; Fontify as a variable or function name.
+ − 2307 (1 (if (match-beginning 4)
+ − 2308 font-lock-function-name-face
+ − 2309 font-lock-variable-name-face))))
+ − 2310 ;;
+ − 2311 ;; Fontify structures, or typedef names, plus their items.
+ − 2312 '("\\(}\\)[ \t*]*\\sw"
+ − 2313 (font-lock-match-c++-style-declaration-item-and-skip-to-next
+ − 2314 (goto-char (match-end 1)) nil
+ − 2315 (1 (if (match-beginning 4)
+ − 2316 font-lock-function-name-face
+ − 2317 font-lock-variable-name-face))))
+ − 2318 ;;
+ − 2319 ;; Fontify anything at beginning of line as a declaration or definition.
+ − 2320 '("^\\(\\sw+\\)\\>\\([ \t*]+\\sw+\\>\\)*"
+ − 2321 (1 font-lock-type-face)
+ − 2322 (font-lock-match-c++-style-declaration-item-and-skip-to-next
+ − 2323 (goto-char (or (match-beginning 2) (match-end 1))) nil
+ − 2324 (1 (if (match-beginning 4)
+ − 2325 font-lock-function-name-face
+ − 2326 font-lock-variable-name-face))))
+ − 2327 )))
+ − 2328
+ − 2329 (setq c++-font-lock-keywords-1
+ − 2330 (append
+ − 2331 ;;
+ − 2332 ;; The list `c-font-lock-keywords-1' less that for function names.
+ − 2333 ;; the simple function form regexp has been removed. --dmoore
+ − 2334 ;;(cdr c-font-lock-keywords-1)
+ − 2335 c-font-lock-keywords-1
+ − 2336 ;;
+ − 2337 ;; Fontify function name definitions, possibly incorporating class name.
+ − 2338 (list
+ − 2339 '("^\\(\\sw+\\)\\(::\\(\\sw+\\)\\)?[ \t]*("
+ − 2340 (1 (if (match-beginning 2)
+ − 2341 font-lock-type-face
+ − 2342 font-lock-function-name-face))
+ − 2343 (3 (if (match-beginning 2) font-lock-function-name-face) nil t))
+ − 2344 )))
+ − 2345
+ − 2346 (setq c++-font-lock-keywords-2
+ − 2347 (append c++-font-lock-keywords-1
+ − 2348 (list
+ − 2349 ;;
+ − 2350 ;; The list `c-font-lock-keywords-2' for C++ plus operator overloading.
+ − 2351 (cons (concat "\\<\\(" c++-type-types "\\)\\>") 'font-lock-type-face)
+ − 2352 ;;
+ − 2353 ;; Fontify operator function name overloading.
+ − 2354 '("\\<\\(operator\\)\\>[ \t]*\\([][)(><!=+-][][)(><!=+-]?\\)?"
+ − 2355 (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t))
+ − 2356 ;;
+ − 2357 ;; Fontify case/goto keywords and targets, and case default/goto tags.
+ − 2358 '("\\<\\(case\\|goto\\)\\>[ \t]*\\([^ \t\n:;]+\\)?"
+ − 2359 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t))
+ − 2360 '("^[ \t]*\\(\\sw+\\)[ \t]*:[^:]" 1 font-lock-reference-face)
+ − 2361 ;;
+ − 2362 ;; Fontify other builtin keywords.
+ − 2363 (cons (concat "\\<\\(" c++-keywords "\\)\\>") 'font-lock-keyword-face)
+ − 2364 )))
+ − 2365
+ − 2366 (setq c++-font-lock-keywords-3
+ − 2367 (append c++-font-lock-keywords-2
+ − 2368 ;;
+ − 2369 ;; More complicated regexps for more complete highlighting for types.
+ − 2370 (list
+ − 2371 ;;
+ − 2372 ;; Fontify all storage classes and type specifiers, plus their items.
+ − 2373 (list (concat "\\<\\(" c++-type-types "\\)\\>"
+ − 2374 "\\([ \t*&]+\\sw+\\>\\)*")
+ − 2375 ;; Fontify each declaration item.
+ − 2376 '(font-lock-match-c++-style-declaration-item-and-skip-to-next
+ − 2377 ;; Start with point after all type specifiers.
+ − 2378 (goto-char (or (match-beginning 13) (match-end 1)))
+ − 2379 ;; Finish with point after first type specifier.
+ − 2380 (goto-char (match-end 1))
+ − 2381 ;; Fontify as a variable or function name.
+ − 2382 (1 (cond ((match-beginning 2) 'font-lock-type-face)
+ − 2383 ((match-beginning 4) 'font-lock-function-name-face)
+ − 2384 (t 'font-lock-variable-name-face)))
+ − 2385 (3 (if (match-beginning 4)
+ − 2386 'font-lock-function-name-face
+ − 2387 'font-lock-variable-name-face) nil t)))
+ − 2388 ;;
+ − 2389 ;; Fontify structures, or typedef names, plus their items.
+ − 2390 '("\\(}\\)[ \t*]*\\sw"
+ − 2391 (font-lock-match-c++-style-declaration-item-and-skip-to-next
+ − 2392 (goto-char (match-end 1)) nil
+ − 2393 (1 (if (match-beginning 4)
+ − 2394 font-lock-function-name-face
+ − 2395 font-lock-variable-name-face))))
+ − 2396 ;;
+ − 2397 ;; Fontify anything at beginning of line as a declaration or definition.
+ − 2398 '("^\\(\\sw+\\)\\>\\([ \t*]+\\sw+\\>\\)*"
+ − 2399 (1 font-lock-type-face)
+ − 2400 (font-lock-match-c++-style-declaration-item-and-skip-to-next
+ − 2401 (goto-char (or (match-beginning 2) (match-end 1))) nil
+ − 2402 (1 (cond ((match-beginning 2) 'font-lock-type-face)
+ − 2403 ((match-beginning 4) 'font-lock-function-name-face)
+ − 2404 (t 'font-lock-variable-name-face)))
+ − 2405 (3 (if (match-beginning 4)
+ − 2406 'font-lock-function-name-face
+ − 2407 'font-lock-variable-name-face) nil t)))
+ − 2408 )))
+ − 2409 )
+ − 2410
+ − 2411 (defvar c-font-lock-keywords c-font-lock-keywords-1
+ − 2412 "Default expressions to highlight in C mode.")
+ − 2413
+ − 2414 (defvar c++-font-lock-keywords c++-font-lock-keywords-1
+ − 2415 "Default expressions to highlight in C++ mode.")
+ − 2416
+ − 2417 ;;; Java.
+ − 2418
+ − 2419 ;; Java support has been written by XEmacs people, and it's apparently
+ − 2420 ;; totally divergent from the FSF. I don't know if it's better or
+ − 2421 ;; worse, so I'm leaving it in until someone convinces me the FSF
+ − 2422 ;; version is better. --hniksic
+ − 2423
+ − 2424 (defconst java-font-lock-keywords-1 nil
+ − 2425 "For consideration as a value of `java-font-lock-keywords'.
+ − 2426 This does fairly subdued highlighting.")
+ − 2427
+ − 2428 (defconst java-font-lock-keywords-2 nil
+ − 2429 "For consideration as a value of `java-font-lock-keywords'.
+ − 2430 This adds highlighting of types and identifier names.")
+ − 2431
+ − 2432 (defconst java-font-lock-keywords-3 nil
+ − 2433 "For consideration as a value of `java-font-lock-keywords'.
+ − 2434 This adds highlighting of Java documentation tags, such as @see.")
+ − 2435
+ − 2436 (defvar java-font-lock-type-regexp
+ − 2437 (concat "\\<\\(boolean\\|byte\\|char\\|double\\|float\\|int"
+ − 2438 "\\|long\\|short\\|void\\)\\>")
+ − 2439 "Regexp which should match a primitive type.")
+ − 2440
+ − 2441 (defvar java-font-lock-identifier-regexp
442
+ − 2442 (let ((letter "a-zA-Z_$\300-\326\330-\366\370-\377")
+ − 2443 (digit "0-9"))
+ − 2444 (concat "\\<\\([" letter "][" letter digit "]*\\)\\>"))
428
+ − 2445 "Regexp which should match all Java identifiers.")
+ − 2446
+ − 2447 (defvar java-font-lock-class-name-regexp
442
+ − 2448 (let ((capital-letter "A-Z\300-\326\330-\337")
+ − 2449 (letter "a-zA-Z_$\300-\326\330-\366\370-\377")
+ − 2450 (digit "0-9"))
+ − 2451 (concat "\\<\\([" capital-letter "][" letter digit "]*\\)\\>"))
428
+ − 2452 "Regexp which should match a class or an interface name.
+ − 2453 The name is assumed to begin with a capital letter.")
+ − 2454
+ − 2455 (let ((java-modifier-regexp
+ − 2456 (concat "\\<\\(abstract\\|const\\|final\\|native\\|"
+ − 2457 "private\\|protected\\|public\\|"
+ − 2458 "static\\|synchronized\\|transient\\|volatile\\)\\>")))
+ − 2459
+ − 2460 ;; Basic font-lock support:
+ − 2461 (setq java-font-lock-keywords-1
+ − 2462 (list
+ − 2463 ;; Keywords:
+ − 2464 (list
+ − 2465 (concat
+ − 2466 "\\<\\("
+ − 2467 "break\\|byvalue\\|"
+ − 2468 "case\\|cast\\|catch\\|class\\|continue\\|"
+ − 2469 "do\\|else\\|extends\\|"
+ − 2470 "finally\\|for\\|future\\|"
+ − 2471 "generic\\|goto\\|"
+ − 2472 "if\\|implements\\|import\\|"
+ − 2473 "instanceof\\|interface\\|"
+ − 2474 "new\\|package\\|return\\|switch\\|"
+ − 2475 "throws?\\|try\\|while\\)\\>")
+ − 2476 1 'font-lock-keyword-face)
+ − 2477
+ − 2478 ;; Modifiers:
+ − 2479 (list java-modifier-regexp 1 font-lock-type-face)
+ − 2480
+ − 2481 ;; Special constants:
+ − 2482 '("\\<\\(this\\|super\\)\\>" (1 font-lock-reference-face))
+ − 2483 '("\\<\\(false\\|null\\|true\\)\\>" (1 font-lock-keyword-face))
+ − 2484
+ − 2485 ;; Class names:
442
+ − 2486 (list (concat "\\<\\(class\\|interface\\)\\>\\s *"
+ − 2487 java-font-lock-identifier-regexp)
+ − 2488 2 'font-lock-function-name-face)
428
+ − 2489
+ − 2490 ;; Package declarations:
+ − 2491 (list (concat "\\<\\(package\\|import\\)\\>\\s *"
+ − 2492 java-font-lock-identifier-regexp)
+ − 2493 '(2 font-lock-reference-face)
+ − 2494 (list (concat
+ − 2495 "\\=\\.\\(" java-font-lock-identifier-regexp "\\)")
+ − 2496 nil nil '(1 (if (equal (char-after (match-end 0)) ?.)
+ − 2497 'font-lock-reference-face
+ − 2498 'font-lock-type-face))))
+ − 2499
+ − 2500 ;; Constructors:
+ − 2501 (list (concat
+ − 2502 "^\\s *\\(" java-modifier-regexp "\\s +\\)*"
+ − 2503 java-font-lock-class-name-regexp "\\s *\(")
+ − 2504 (list 3
+ − 2505 '(condition-case nil
+ − 2506 (save-excursion
+ − 2507 (goto-char (scan-sexps (- (match-end 0) 1) 1))
+ − 2508 (parse-partial-sexp (point) (point-max) nil t)
+ − 2509 (and (looking-at "\\($\\|\\<throws\\>\\|{\\)")
+ − 2510 'font-lock-function-name-face))
+ − 2511 (error 'font-lock-function-name-face))))
+ − 2512
+ − 2513 ;; Methods:
+ − 2514 (list (concat "\\(" java-font-lock-type-regexp "\\|"
+ − 2515 java-font-lock-class-name-regexp "\\)"
+ − 2516 "\\s *\\(\\[\\s *\\]\\s *\\)*"
+ − 2517 java-font-lock-identifier-regexp "\\s *\(")
+ − 2518 5
+ − 2519 'font-lock-function-name-face)
+ − 2520
+ − 2521 ;; Labels:
+ − 2522 (list ":"
+ − 2523 (list
+ − 2524 (concat "^\\s *" java-font-lock-identifier-regexp "\\s *:")
+ − 2525 '(beginning-of-line) '(end-of-line)
+ − 2526 '(1 font-lock-reference-face)))
+ − 2527
+ − 2528 ;; `break' and continue' destination labels:
+ − 2529 (list (concat "\\<\\(break\\|continue\\)\\>\\s *"
+ − 2530 java-font-lock-identifier-regexp)
+ − 2531 2 'font-lock-reference-face)
+ − 2532
+ − 2533 ;; Case statements:
+ − 2534 ;; In Java, any constant expression is allowed.
+ − 2535 '("\\<case\\>\\s *\\(.*\\):" 1 font-lock-reference-face)))
+ − 2536
+ − 2537 ;; Types and declared variable names:
+ − 2538 (setq java-font-lock-keywords-2
+ − 2539 (append
+ − 2540
+ − 2541 java-font-lock-keywords-1
+ − 2542 (list
+ − 2543 ;; Keywords followed by a type:
+ − 2544 (list (concat "\\<\\(extends\\|instanceof\\|new\\)\\>\\s *"
+ − 2545 java-font-lock-identifier-regexp)
+ − 2546 '(2 (if (equal (char-after (match-end 0)) ?.)
+ − 2547 'font-lock-reference-face 'font-lock-type-face))
+ − 2548 (list (concat "\\=\\." java-font-lock-identifier-regexp)
+ − 2549 '(goto-char (match-end 0)) nil
+ − 2550 '(1 (if (equal (char-after (match-end 0)) ?.)
+ − 2551 'font-lock-reference-face 'font-lock-type-face))))
+ − 2552
+ − 2553 ;; Keywords followed by a type list:
+ − 2554 (list (concat "\\<\\(implements\\|throws\\)\\>\\ s*"
+ − 2555 java-font-lock-identifier-regexp)
+ − 2556 '(2 (if (equal (char-after (match-end 0)) ?.)
+ − 2557 font-lock-reference-face font-lock-type-face))
+ − 2558 (list (concat "\\=\\(\\.\\|\\s *\\(,\\)\\s *\\)"
+ − 2559 java-font-lock-identifier-regexp)
+ − 2560 '(goto-char (match-end 0)) nil
+ − 2561 '(3 (if (equal (char-after (match-end 0)) ?.)
+ − 2562 font-lock-reference-face font-lock-type-face))))
+ − 2563
+ − 2564 ;; primitive types, can't be confused with anything else.
+ − 2565 (list java-font-lock-type-regexp
+ − 2566 '(1 font-lock-type-face)
+ − 2567 '(font-lock-match-java-declarations
+ − 2568 (goto-char (match-end 0))
+ − 2569 (goto-char (match-end 0))
+ − 2570 (0 font-lock-variable-name-face)))
+ − 2571
+ − 2572 ;; Declarations, class types and capitalized variables:
+ − 2573 ;;
+ − 2574 ;; Declarations are easy to recognize. Capitalized words
+ − 2575 ;; followed by a closing parenthesis are treated as casts if they
+ − 2576 ;; also are followed by an expression. Expressions beginning with
+ − 2577 ;; a unary numerical operator, e.g. +, can't be cast to an object
+ − 2578 ;; type.
+ − 2579 ;;
+ − 2580 ;; The path of a fully qualified type, e.g. java.lang.Foo, is
+ − 2581 ;; fontified in the reference face.
+ − 2582 ;;
+ − 2583 ;; An access to a static field, e.g. System.out.println, is
+ − 2584 ;; not fontified since it can't be distinguished from the
+ − 2585 ;; usage of a capitalized variable, e.g. Foo.out.println.
+ − 2586
+ − 2587 (list (concat java-font-lock-class-name-regexp
+ − 2588 "\\s *\\(\\[\\s *\\]\\s *\\)*"
+ − 2589 "\\(\\<\\|$\\|)\\s *\\([\(\"]\\|\\<\\)\\)")
+ − 2590 '(1 (save-match-data
+ − 2591 (save-excursion
+ − 2592 (goto-char
+ − 2593 (match-beginning 3))
+ − 2594 (if (not (looking-at "\\<instanceof\\>"))
+ − 2595 'font-lock-type-face))))
+ − 2596 (list (concat "\\=" java-font-lock-identifier-regexp "\\.")
+ − 2597 '(progn
+ − 2598 (goto-char (match-beginning 0))
+ − 2599 (while (or (= (preceding-char) ?.)
+ − 2600 (= (char-syntax (preceding-char)) ?w))
+ − 2601 (backward-char)))
+ − 2602 '(goto-char (match-end 0))
+ − 2603 '(1 font-lock-reference-face)
+ − 2604 '(0 nil)) ; Workaround for bug in XEmacs.
+ − 2605 '(font-lock-match-java-declarations
+ − 2606 (goto-char (match-end 1))
+ − 2607 (goto-char (match-end 0))
+ − 2608 (1 font-lock-variable-name-face))))))
+ − 2609
+ − 2610 ;; Modifier keywords and Java doc tags
+ − 2611 (setq java-font-lock-keywords-3
+ − 2612 (append
+ − 2613
+ − 2614 '(
+ − 2615 ;; Feature scoping:
+ − 2616 ;; These must come first or the Modifiers from keywords-1 will
+ − 2617 ;; catch them. We don't want to use override fontification here
+ − 2618 ;; because then these terms will be fontified within comments.
+ − 2619 ("\\<private\\>" 0 font-lock-string-face)
+ − 2620 ("\\<protected\\>" 0 font-lock-preprocessor-face)
+ − 2621 ("\\<public\\>" 0 font-lock-reference-face))
+ − 2622 java-font-lock-keywords-2
+ − 2623
+ − 2624 (list
+ − 2625
442
+ − 2626 ;; Javadoc tags
+ − 2627 '("@\\(author\\|deprecated\\|exception\\|throws\\|param\\|return\\|see\\|since\\|version\\|serial\\|serialData\\|serialField\\)\\s "
428
+ − 2628 0 font-lock-keyword-face t)
+ − 2629
+ − 2630 ;; Doc tag - Parameter identifiers
+ − 2631 (list (concat "@param\\s +" java-font-lock-identifier-regexp)
+ − 2632 1 'font-lock-variable-name-face t)
+ − 2633
+ − 2634 ;; Doc tag - Exception types
442
+ − 2635 (list (concat "@\\(exception\\|throws\\)\\s +"
428
+ − 2636 java-font-lock-identifier-regexp)
442
+ − 2637 '(2 (if (equal (char-after (match-end 0)) ?.)
428
+ − 2638 font-lock-reference-face font-lock-type-face) t)
+ − 2639 (list (concat "\\=\\." java-font-lock-identifier-regexp)
+ − 2640 '(goto-char (match-end 0)) nil
+ − 2641 '(1 (if (equal (char-after (match-end 0)) ?.)
+ − 2642 'font-lock-reference-face 'font-lock-type-face) t)))
+ − 2643
+ − 2644 ;; Doc tag - Cross-references, usually to methods
+ − 2645 '("@see\\s +\\(\\S *[^][ \t\n\r\f(){},.;:]\\)"
+ − 2646 1 font-lock-function-name-face t)
+ − 2647
442
+ − 2648 ;; Doc tag - docRoot (1.3)
+ − 2649 '("\\({ *@docRoot *}\\)"
+ − 2650 0 font-lock-keyword-face t)
+ − 2651 ;; Doc tag - beaninfo, unofficial but widely used, even by Sun
+ − 2652 '("\\(@beaninfo\\)"
428
+ − 2653 0 font-lock-keyword-face t)
+ − 2654 ;; Doc tag - Links
442
+ − 2655 '("{ *@link\\s +\\([^}]+\\)}"
+ − 2656 0 font-lock-keyword-face t)
+ − 2657 ;; Doc tag - Links
+ − 2658 '("{ *@link\\s +\\(\\(\\S +\\)\\|\\(\\S +\\s +\\S +\\)\\) *}"
428
+ − 2659 1 font-lock-function-name-face t)
+ − 2660
+ − 2661 )))
+ − 2662 )
+ − 2663
+ − 2664 (defvar java-font-lock-keywords java-font-lock-keywords-1
+ − 2665 "Additional expressions to highlight in Java mode.")
+ − 2666
+ − 2667 ;; Match and move over any declaration/definition item after
+ − 2668 ;; point. Does not match items which look like a type declaration
+ − 2669 ;; (primitive types and class names, i.e. capitalized words.)
+ − 2670 ;; Should the variable name be followed by a comma, we reposition
+ − 2671 ;; the cursor to fontify more identifiers.
+ − 2672 (defun font-lock-match-java-declarations (limit)
+ − 2673 "Match and skip over variable definitions."
+ − 2674 (if (looking-at "\\s *\\(\\[\\s *\\]\\s *\\)*")
+ − 2675 (goto-char (match-end 0)))
+ − 2676 (and
+ − 2677 (looking-at java-font-lock-identifier-regexp)
+ − 2678 (save-match-data
+ − 2679 (not (string-match java-font-lock-type-regexp
+ − 2680 (buffer-substring (match-beginning 1)
+ − 2681 (match-end 1)))))
+ − 2682 (save-match-data
+ − 2683 (save-excursion
+ − 2684 (goto-char (match-beginning 1))
+ − 2685 (not (looking-at
+ − 2686 (concat java-font-lock-class-name-regexp
+ − 2687 "\\s *\\(\\[\\s *\\]\\s *\\)*\\<")))))
+ − 2688 (save-match-data
+ − 2689 (condition-case nil
+ − 2690 (save-restriction
+ − 2691 (narrow-to-region (point-min) limit)
+ − 2692 (goto-char (match-end 0))
+ − 2693 ;; Note: Both `scan-sexps' and the second goto-char can
+ − 2694 ;; generate an error which is caught by the
+ − 2695 ;; `condition-case' expression.
+ − 2696 (while (not (looking-at "\\s *\\(\\(,\\)\\|;\\|$\\)"))
+ − 2697 (goto-char (or (scan-sexps (point) 1) (point-max))))
+ − 2698 (goto-char (match-end 2))) ; non-nil
+ − 2699 (error t)))))
+ − 2700
+ − 2701
+ − 2702 (defvar tex-font-lock-keywords
+ − 2703 ; ;; Regexps updated with help from Ulrik Dickow <dickow@nbi.dk>.
+ − 2704 ; '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}"
+ − 2705 ; 2 font-lock-function-name-face)
+ − 2706 ; ("\\\\\\(cite\\|label\\|pageref\\|ref\\){\\([^} \t\n]+\\)}"
+ − 2707 ; 2 font-lock-reference-face)
+ − 2708 ; ;; It seems a bit dubious to use `bold' and `italic' faces since we might
+ − 2709 ; ;; not be able to display those fonts.
+ − 2710 ; ("{\\\\bf\\([^}]+\\)}" 1 'bold keep)
+ − 2711 ; ("{\\\\\\(em\\|it\\|sl\\)\\([^}]+\\)}" 2 'italic keep)
+ − 2712 ; ("\\\\\\([a-zA-Z@]+\\|.\\)" . font-lock-keyword-face)
+ − 2713 ; ("^[ \t\n]*\\\\def[\\\\@]\\(\\w+\\)" 1 font-lock-function-name-face keep))
+ − 2714 ;; Rewritten and extended for LaTeX2e by Ulrik Dickow <dickow@nbi.dk>.
+ − 2715 '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}"
+ − 2716 2 font-lock-function-name-face)
+ − 2717 ("\\\\\\(cite\\|label\\|pageref\\|ref\\){\\([^} \t\n]+\\)}"
+ − 2718 2 font-lock-reference-face)
+ − 2719 ("^[ \t]*\\\\def\\\\\\(\\(\\w\\|@\\)+\\)" 1 font-lock-function-name-face)
+ − 2720 "\\\\\\([a-zA-Z@]+\\|.\\)"
+ − 2721 ;; It seems a bit dubious to use `bold' and `italic' faces since we might
+ − 2722 ;; not be able to display those fonts.
+ − 2723 ;; LaTeX2e: \emph{This is emphasized}.
+ − 2724 ("\\\\emph{\\([^}]+\\)}" 1 'italic keep)
+ − 2725 ;; LaTeX2e: \textbf{This is bold}, \textit{...}, \textsl{...}
+ − 2726 ("\\\\text\\(\\(bf\\)\\|it\\|sl\\){\\([^}]+\\)}"
+ − 2727 3 (if (match-beginning 2) 'bold 'italic) keep)
+ − 2728 ;; Old-style bf/em/it/sl. Stop at `\\' and un-escaped `&', for good tables.
+ − 2729 ("\\\\\\(\\(bf\\)\\|em\\|it\\|sl\\)\\>\\(\\([^}&\\]\\|\\\\[^\\]\\)+\\)"
+ − 2730 3 (if (match-beginning 2) 'bold 'italic) keep))
+ − 2731 "Default expressions to highlight in TeX modes.")
+ − 2732
444
+ − 2733 (defconst ksh-font-lock-keywords
428
+ − 2734 (list
+ − 2735 '("\\(^\\|[^\$\\\]\\)#.*" . font-lock-comment-face)
+ − 2736 '("\\<\\(if\\|then\\|else\\|elif\\|fi\\|case\\|esac\\|for\\|do\\|done\\|foreach\\|in\\|end\\|select\\|while\\|repeat\\|time\\|function\\|until\\|exec\\|command\\|coproc\\|noglob\\|nohup\\|nocorrect\\|source\\|autoload\\|alias\\|unalias\\|export\\|set\\|echo\\|eval\\|cd\\|log\\|compctl\\)\\>" . font-lock-keyword-face)
+ − 2737 '("\\<\\[\\[.*\\]\\]\\>" . font-lock-type-face)
+ − 2738 '("\$\(.*\)" . font-lock-type-face)
444
+ − 2739 )
428
+ − 2740 "Additional expressions to highlight in ksh-mode.")
+ − 2741
444
+ − 2742 (defconst sh-font-lock-keywords
428
+ − 2743 (list
+ − 2744 '("\\(^\\|[^\$\\\]\\)#.*" . font-lock-comment-face)
+ − 2745 '("\\<\\(if\\|then\\|else\\|elif\\|fi\\|case\\|esac\\|for\\|do\\|done\\|in\\|while\\|exec\\|export\\|set\\|echo\\|eval\\|cd\\)\\>" . font-lock-keyword-face)
+ − 2746 '("\\[.*\\]" . font-lock-type-face)
+ − 2747 '("`.*`" . font-lock-type-face)
444
+ − 2748 )
428
+ − 2749 "Additional expressions to highlight in sh-mode.")
+ − 2750
+ − 2751
+ − 2752 ;; Install ourselves:
+ − 2753
+ − 2754 (add-hook 'find-file-hooks 'font-lock-set-defaults t)
+ − 2755
+ − 2756 ;;;###autoload
+ − 2757 (add-minor-mode 'font-lock-mode " Font")
+ − 2758
+ − 2759 ;; Provide ourselves:
+ − 2760
+ − 2761 (provide 'font-lock)
+ − 2762
+ − 2763 ;;; font-lock.el ends here