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