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