diff options
| author | Richard M. Stallman | 1993-07-09 20:27:43 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1993-07-09 20:27:43 +0000 |
| commit | 030f4a352d9cf12f4ed72fa416506ac0205378cd (patch) | |
| tree | 16281ee565ce42d50b62ddca710a67dedb99745b | |
| parent | 72a339d7e3fab18a50233dce97eab9d9d95c3932 (diff) | |
| download | emacs-030f4a352d9cf12f4ed72fa416506ac0205378cd.tar.gz emacs-030f4a352d9cf12f4ed72fa416506ac0205378cd.zip | |
Initial revision
| -rw-r--r-- | lisp/font-lock.el | 589 |
1 files changed, 589 insertions, 0 deletions
diff --git a/lisp/font-lock.el b/lisp/font-lock.el new file mode 100644 index 00000000000..58e70ec62a2 --- /dev/null +++ b/lisp/font-lock.el | |||
| @@ -0,0 +1,589 @@ | |||
| 1 | ;; Electric Font Lock Mode | ||
| 2 | ;; Copyright (C) 1992, 1993 Free Software Foundation, Inc. | ||
| 3 | |||
| 4 | ;; Author: jwz, then rms | ||
| 5 | ;; Maintainer: FSF | ||
| 6 | ;; Keywords: languages, faces | ||
| 7 | |||
| 8 | ;; This file is part of GNU Emacs. | ||
| 9 | |||
| 10 | ;; GNU Emacs is free software; you can redistribute it and/or modify | ||
| 11 | ;; it under the terms of the GNU General Public License as published by | ||
| 12 | ;; the Free Software Foundation; either version 2, or (at your option) | ||
| 13 | ;; any later version. | ||
| 14 | |||
| 15 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 18 | ;; GNU General Public License for more details. | ||
| 19 | |||
| 20 | ;; You should have received a copy of the GNU General Public License | ||
| 21 | ;; along with GNU Emacs; see the file COPYING. If not, write to | ||
| 22 | ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 23 | |||
| 24 | |||
| 25 | ;;; Commentary: | ||
| 26 | |||
| 27 | ;; Font-lock-mode is a minor mode that causes your comments to be | ||
| 28 | ;; displayed in one face, strings in another, reserved words in another, | ||
| 29 | ;; documentation strings in another, and so on. | ||
| 30 | ;; | ||
| 31 | ;; Comments will be displayed in `font-lock-comment-face'. | ||
| 32 | ;; Strings will be displayed in `font-lock-string-face'. | ||
| 33 | ;; Doc strings will be displayed in `font-lock-doc-string-face'. | ||
| 34 | ;; Function and variable names (in their defining forms) will be | ||
| 35 | ;; displayed in `font-lock-function-name-face'. | ||
| 36 | ;; Reserved words will be displayed in `font-lock-keyword-face'. | ||
| 37 | ;; | ||
| 38 | ;; To make the text you type be fontified, use M-x font-lock-mode. | ||
| 39 | ;; When this minor mode is on, the fonts of the current line are | ||
| 40 | ;; updated with every insertion or deletion. | ||
| 41 | ;; | ||
| 42 | ;; To define new reserved words or other patterns to highlight, use | ||
| 43 | ;; the `font-lock-keywords' variable. This should be mode-local. | ||
| 44 | ;; | ||
| 45 | ;; To turn this on automatically, add this to your .emacs file: | ||
| 46 | ;; | ||
| 47 | ;; (setq emacs-lisp-mode-hook '(lambda () (font-lock-mode 1))) | ||
| 48 | ;; | ||
| 49 | ;; On a Sparc2, the initial fontification takes about 12 seconds for a 120k | ||
| 50 | ;; file of C code, using the default configuration. You can speed this up | ||
| 51 | ;; substantially by removing some of the patterns that are highlighted by | ||
| 52 | ;; default. Fontifying Lisp code is significantly faster, because Lisp has a | ||
| 53 | ;; more regular syntax than C, so the expressions don't have to be as hairy. | ||
| 54 | |||
| 55 | ;;; Code: | ||
| 56 | |||
| 57 | (or (internal-find-face 'underline) | ||
| 58 | (copy-face 'default 'underline)) | ||
| 59 | (set-face-underline-p 'underline t) | ||
| 60 | |||
| 61 | (defvar font-lock-comment-face | ||
| 62 | 'italic | ||
| 63 | "Face to use for comments.") | ||
| 64 | |||
| 65 | (defvar font-lock-doc-string-face | ||
| 66 | 'italic | ||
| 67 | "Face to use for documentation strings.") | ||
| 68 | |||
| 69 | (defvar font-lock-string-face | ||
| 70 | 'underline | ||
| 71 | "Face to use for string constants.") | ||
| 72 | |||
| 73 | (defvar font-lock-function-face | ||
| 74 | 'bold-italic | ||
| 75 | "Face to use for function names.") | ||
| 76 | |||
| 77 | (defvar font-lock-keyword-face | ||
| 78 | 'bold | ||
| 79 | "Face to use for keywords.") | ||
| 80 | |||
| 81 | (defvar font-lock-type-face | ||
| 82 | 'italic | ||
| 83 | "Face to use for data types.") | ||
| 84 | |||
| 85 | (make-variable-buffer-local 'font-lock-keywords) | ||
| 86 | (defvar font-lock-keywords nil | ||
| 87 | "*The keywords to highlight. | ||
| 88 | If this is a list, then elements may be of the forms: | ||
| 89 | |||
| 90 | \"string\" ; a regexp to highlight in the | ||
| 91 | ; `font-lock-keyword-face'. | ||
| 92 | (\"string\" . integer) ; match N of the regexp will be highlighted | ||
| 93 | (\"string\" . face-name) ; use the named face | ||
| 94 | (\"string\" integer face-name) ; both of the above | ||
| 95 | (\"string\" integer face-name t) ; this allows highlighting to overlap | ||
| 96 | ; with already-highlighted regions. | ||
| 97 | |||
| 98 | These regular expressions should not match text which spans lines. | ||
| 99 | While \\[font-lock-fontify-buffer] handles multi-line patterns correctly, | ||
| 100 | updating when you edit the buffer does not, | ||
| 101 | since it considers text one line at a time. | ||
| 102 | |||
| 103 | Be careful composing regexps for this list; the wrong pattern can dramatically | ||
| 104 | slow things down!") | ||
| 105 | |||
| 106 | (defvar font-lock-keywords-case-fold-search nil | ||
| 107 | "*Non-nil means the patterns in `font-lock-keywords' are case-insensitive.") | ||
| 108 | |||
| 109 | (defvar font-lock-verbose t | ||
| 110 | "*Non-nil means `font-lock-fontify-buffer' should print status messages.") | ||
| 111 | |||
| 112 | (defvar font-lock-mode-hook nil | ||
| 113 | "Function or functions to run on entry to Font Lock mode.") | ||
| 114 | |||
| 115 | ;;; These variables record, for each buffer, | ||
| 116 | ;;; the parse state at a particular position, always the start of a line. | ||
| 117 | ;;; This is used to make font-lock-fontify-region faster. | ||
| 118 | (defvar font-lock-cache-position nil) | ||
| 119 | (defvar font-lock-cache-state nil) | ||
| 120 | (make-variable-buffer-local 'font-lock-cache-position) | ||
| 121 | (make-variable-buffer-local 'font-lock-cache-state) | ||
| 122 | |||
| 123 | (defun font-lock-fontify-region (start end) | ||
| 124 | "Put proper face on each string and comment between START and END." | ||
| 125 | (save-excursion | ||
| 126 | (goto-char start) | ||
| 127 | (beginning-of-line) | ||
| 128 | (setq end (min end (point-max))) | ||
| 129 | (let (state startline prev prevstate) | ||
| 130 | ;; Find the state at the line-beginning before START. | ||
| 131 | (setq startline (point)) | ||
| 132 | (if (eq (point) font-lock-cache-position) | ||
| 133 | (setq state font-lock-cache-state) | ||
| 134 | ;; Find outermost containing sexp. | ||
| 135 | (beginning-of-defun) | ||
| 136 | ;; Find the state at STARTLINE. | ||
| 137 | (while (< (point) startline) | ||
| 138 | (setq state (parse-partial-sexp (point) startline 0))) | ||
| 139 | (setq font-lock-cache-state state | ||
| 140 | font-lock-cache-position (point))) | ||
| 141 | ;; Now find the state precisely at START. | ||
| 142 | (setq state (parse-partial-sexp (point) start nil nil state)) | ||
| 143 | ;; If the region starts inside a string, show the extent of it. | ||
| 144 | (if (nth 3 state) | ||
| 145 | (let ((beg (point))) | ||
| 146 | (while (and (re-search-forward "\\s\"" end 'move) | ||
| 147 | (nth 3 (parse-partial-sexp beg (point) | ||
| 148 | nil nil state)))) | ||
| 149 | (put-text-property beg (point) 'face font-lock-string-face) | ||
| 150 | (setq state (parse-partial-sexp beg (point) nil nil state)))) | ||
| 151 | ;; Likewise for a comment. | ||
| 152 | (if (or (nth 4 state) (nth 7 state)) | ||
| 153 | (let ((beg (point))) | ||
| 154 | (while (and (re-search-forward (if comment-end | ||
| 155 | (concat "\\s>\\|" | ||
| 156 | (regexp-quote comment-end)) | ||
| 157 | "\\s>") | ||
| 158 | end 'move) | ||
| 159 | (nth 3 (parse-partial-sexp beg (point) | ||
| 160 | nil nil state)))) | ||
| 161 | (put-text-property beg (point) 'face font-lock-comment-face) | ||
| 162 | (setq state (parse-partial-sexp beg (point) nil nil state)))) | ||
| 163 | ;; Find each interesting place between here and END. | ||
| 164 | (while (and (< (point) end) | ||
| 165 | (setq prev (point) prevstate state) | ||
| 166 | (re-search-forward (concat "\\s\"\\|" (regexp-quote comment-start)) end t) | ||
| 167 | ;; Clear out the fonts of what we skip over. | ||
| 168 | (progn (remove-text-properties prev (point) '(face nil)) t) | ||
| 169 | ;; Verify the state at that place | ||
| 170 | ;; so we don't get fooled by \" or \;. | ||
| 171 | (setq state (parse-partial-sexp prev (point) | ||
| 172 | nil nil state))) | ||
| 173 | (let ((here (point))) | ||
| 174 | (if (or (nth 4 state) (nth 7 state)) | ||
| 175 | ;; We found a real comment start. | ||
| 176 | (let ((beg (match-beginning 0))) | ||
| 177 | (goto-char beg) | ||
| 178 | (save-restriction | ||
| 179 | (narrow-to-region (point-min) end) | ||
| 180 | (condition-case nil | ||
| 181 | (progn | ||
| 182 | (forward-comment 1) | ||
| 183 | ;; forward-comment skips all whitespace, | ||
| 184 | ;; so go back to the real end of the comment. | ||
| 185 | (skip-chars-backward " \t")) | ||
| 186 | (error (goto-char end)))) | ||
| 187 | (put-text-property beg (point) 'face font-lock-comment-face) | ||
| 188 | (setq state (parse-partial-sexp here (point) nil nil state))) | ||
| 189 | (if (nth 3 state) | ||
| 190 | (let ((beg (match-beginning 0))) | ||
| 191 | (while (and (re-search-forward "\\s\"" end 'move) | ||
| 192 | (nth 3 (parse-partial-sexp here (point) | ||
| 193 | nil nil state)))) | ||
| 194 | (put-text-property beg (point) 'face font-lock-string-face) | ||
| 195 | (setq state (parse-partial-sexp here (point) nil nil state)))) | ||
| 196 | )) | ||
| 197 | ;; Make sure PREV is non-nil after the loop | ||
| 198 | ;; only if it was set on the very last iteration. | ||
| 199 | (setq prev nil)) | ||
| 200 | (and prev | ||
| 201 | (remove-text-properties prev end '(face nil)))))) | ||
| 202 | |||
| 203 | ;; This code used to be used to show a string on reaching the end of it. | ||
| 204 | ;; It is probably not needed due to later changes to handle strings | ||
| 205 | ;; starting before the region in question. | ||
| 206 | ;; (if (and (null (nth 3 state)) | ||
| 207 | ;; (eq (char-syntax (preceding-char)) ?\") | ||
| 208 | ;; (save-excursion | ||
| 209 | ;; (nth 3 (parse-partial-sexp prev (1- (point)) | ||
| 210 | ;; nil nil prevstate)))) | ||
| 211 | ;; ;; We found the end of a string. | ||
| 212 | ;; (save-excursion | ||
| 213 | ;; (setq foo2 (point)) | ||
| 214 | ;; (let ((ept (point))) | ||
| 215 | ;; (forward-sexp -1) | ||
| 216 | ;; ;; Highlight the string when we see the end. | ||
| 217 | ;; ;; Doing it at the start leads to trouble: | ||
| 218 | ;; ;; either it fails to handle multiline strings | ||
| 219 | ;; ;; or it can run away when an unmatched " is inserted. | ||
| 220 | ;; (put-text-property (point) ept 'face | ||
| 221 | ;; (if (= (car state) 1) | ||
| 222 | ;; font-lock-doc-string-face | ||
| 223 | ;; font-lock-string-face))))) | ||
| 224 | |||
| 225 | (defun font-lock-unfontify-region (beg end) | ||
| 226 | (remove-text-properties beg end '(face nil))) | ||
| 227 | |||
| 228 | ;; Called when any modification is made to buffer text. | ||
| 229 | (defun font-lock-after-change-function (beg end old-len) | ||
| 230 | (save-excursion | ||
| 231 | (save-match-data | ||
| 232 | (goto-char beg) | ||
| 233 | ;; Discard the cache info if text before it has changed. | ||
| 234 | (and font-lock-cache-position | ||
| 235 | (> font-lock-cache-position beg) | ||
| 236 | (setq font-lock-cache-position nil)) | ||
| 237 | ;; Rescan till end of line. yes! | ||
| 238 | (goto-char end) | ||
| 239 | (end-of-line) | ||
| 240 | (setq end (point)) | ||
| 241 | ;; First scan for strings and comments. | ||
| 242 | (font-lock-fontify-region beg (1+ end)) | ||
| 243 | (goto-char beg) | ||
| 244 | (beginning-of-line) | ||
| 245 | (setq beg (point)) | ||
| 246 | ;; Now scan for keywords. | ||
| 247 | (font-lock-hack-keywords beg end)))) | ||
| 248 | |||
| 249 | ;;; Fontifying arbitrary patterns | ||
| 250 | |||
| 251 | (defsubst font-lock-any-properties-p (start end) | ||
| 252 | (or (get-text-property start 'font-lock) | ||
| 253 | (let ((next (next-single-property-change start 'font-lock))) | ||
| 254 | (and next (< next end))))) | ||
| 255 | |||
| 256 | (defun font-lock-hack-keywords (start end &optional loudly) | ||
| 257 | (goto-char start) | ||
| 258 | (let ((case-fold-search font-lock-keywords-case-fold-search) | ||
| 259 | (rest font-lock-keywords) | ||
| 260 | (count 0) | ||
| 261 | first str match face s e allow-overlap-p) | ||
| 262 | (while rest | ||
| 263 | (setq first (car rest) rest (cdr rest)) | ||
| 264 | (goto-char start) | ||
| 265 | (cond ((consp first) | ||
| 266 | (setq str (car first)) | ||
| 267 | (cond ((consp (cdr first)) | ||
| 268 | (setq match (nth 1 first) | ||
| 269 | face (nth 2 first) | ||
| 270 | allow-overlap-p (nth 3 first))) | ||
| 271 | ((symbolp (cdr first)) | ||
| 272 | (setq match 0 allow-overlap-p nil | ||
| 273 | face (cdr first))) | ||
| 274 | (t | ||
| 275 | (setq match (cdr first) | ||
| 276 | allow-overlap-p nil | ||
| 277 | face font-lock-keyword-face)))) | ||
| 278 | (t | ||
| 279 | (setq str first match 0 allow-overlap-p nil | ||
| 280 | face font-lock-keyword-face))) | ||
| 281 | ;(message "regexp: %s" str) | ||
| 282 | (while (re-search-forward str end t) | ||
| 283 | (setq s (match-beginning match) | ||
| 284 | e (match-end match)) | ||
| 285 | (or s (error "expression did not match subexpression %d" match)) | ||
| 286 | ;; don't fontify this keyword if we're already in some other context. | ||
| 287 | (or (if allow-overlap-p nil (font-lock-any-properties-p s e)) | ||
| 288 | (progn | ||
| 289 | (put-text-property s e 'face face)))) | ||
| 290 | (if loudly (message "Fontifying %s... (regexps...%s)" | ||
| 291 | (buffer-name) | ||
| 292 | (make-string (setq count (1+ count)) ?.)))))) | ||
| 293 | |||
| 294 | |||
| 295 | ;; The user level functions | ||
| 296 | |||
| 297 | (defvar font-lock-mode nil) ; for modeline | ||
| 298 | (or (assq 'font-lock-mode minor-mode-alist) | ||
| 299 | (setq minor-mode-alist | ||
| 300 | (append minor-mode-alist | ||
| 301 | '((font-lock-mode " Font"))))) | ||
| 302 | |||
| 303 | (defvar font-lock-fontified nil) ; whether we have hacked this buffer | ||
| 304 | (put 'font-lock-fontified 'permanent-local t) | ||
| 305 | |||
| 306 | ;;;###autoload | ||
| 307 | (defun font-lock-mode (&optional arg) | ||
| 308 | "Toggle Font Lock mode. | ||
| 309 | With arg, turn Font Lock mode on if and only if arg is positive. | ||
| 310 | |||
| 311 | When Font Lock mode is enabled, text is fontified as you type it: | ||
| 312 | |||
| 313 | - comments are displayed in `font-lock-comment-face'; | ||
| 314 | (That is a variable whose value should be a face name.) | ||
| 315 | - strings are displayed in `font-lock-string-face'; | ||
| 316 | - documentation strings are displayed in `font-lock-doc-string-face'; | ||
| 317 | - function and variable names in their defining forms are displayed | ||
| 318 | in `font-lock-function-name-face'; | ||
| 319 | - and certain other expressions are displayed in other faces | ||
| 320 | according to the value of the variable `font-lock-keywords'. | ||
| 321 | |||
| 322 | When you turn Font Lock mode on/off, the buffer is fontified/defontified. | ||
| 323 | To fontify a buffer without having newly typed text become fontified, you | ||
| 324 | can use \\[font-lock-fontify-buffer]." | ||
| 325 | (interactive "P") | ||
| 326 | (let ((on-p (if (null arg) | ||
| 327 | (not font-lock-mode) | ||
| 328 | (> (prefix-numeric-value arg) 0)))) | ||
| 329 | (if (equal (buffer-name) " *Compiler Input*") ; hack for bytecomp... | ||
| 330 | (setq on-p nil)) | ||
| 331 | (or (memq after-change-function | ||
| 332 | '(nil font-lock-after-change-function)) | ||
| 333 | (error "after-change-function is %s" after-change-function)) | ||
| 334 | (set (make-local-variable 'after-change-function) | ||
| 335 | (if on-p 'font-lock-after-change-function nil)) | ||
| 336 | (set (make-local-variable 'font-lock-mode) on-p) | ||
| 337 | (cond (on-p | ||
| 338 | (font-lock-set-defaults) | ||
| 339 | (run-hooks 'font-lock-mode-hook) | ||
| 340 | (or font-lock-fontified (font-lock-fontify-buffer))) | ||
| 341 | (font-lock-fontified | ||
| 342 | (setq font-lock-fontified nil) | ||
| 343 | (font-lock-unfontify-region (point-min) (point-max)))) | ||
| 344 | (force-mode-line-update))) | ||
| 345 | |||
| 346 | |||
| 347 | (defun font-lock-fontify-buffer () | ||
| 348 | "Fontify the current buffer the way `font-lock-mode' would: | ||
| 349 | |||
| 350 | - comments are displayed in `font-lock-comment-face'; | ||
| 351 | - strings are displayed in `font-lock-string-face'; | ||
| 352 | - documentation strings are displayed in `font-lock-doc-string-face'; | ||
| 353 | - function and variable names in their defining forms are displayed | ||
| 354 | in `font-lock-function-name-face'; | ||
| 355 | - and certain other expressions are displayed in other faces | ||
| 356 | according to the value of the variable `font-lock-keywords'. | ||
| 357 | |||
| 358 | This can take a while for large buffers." | ||
| 359 | (interactive) | ||
| 360 | (let ((was-on font-lock-mode) | ||
| 361 | (font-lock-verbose (or font-lock-verbose (interactive-p)))) | ||
| 362 | (if font-lock-verbose (message "Fontifying %s..." (buffer-name))) | ||
| 363 | ;; Turn it on to run hooks and get the right font-lock-keywords. | ||
| 364 | (or was-on (font-lock-mode 1)) | ||
| 365 | (font-lock-unfontify-region (point-min) (point-max)) | ||
| 366 | (if font-lock-verbose (message "Fontifying %s... (syntactically...)" | ||
| 367 | (buffer-name))) | ||
| 368 | ;; (buffer-syntactic-context-flush-cache) | ||
| 369 | (save-excursion | ||
| 370 | (font-lock-fontify-region (point-min) (point-max)) | ||
| 371 | (if font-lock-verbose (message "Fontifying %s... (regexps...)" | ||
| 372 | (buffer-name))) | ||
| 373 | (font-lock-hack-keywords (point-min) (point-max) font-lock-verbose)) | ||
| 374 | (or was-on (font-lock-mode 0)) ; turn it off if it was off. | ||
| 375 | (set (make-local-variable 'font-lock-fontified) t) | ||
| 376 | (if font-lock-verbose (message "Fontifying %s... done." (buffer-name))) | ||
| 377 | )) | ||
| 378 | |||
| 379 | |||
| 380 | ;;; Various mode-specific information. | ||
| 381 | |||
| 382 | (defun font-lock-set-defaults () | ||
| 383 | "sets font-lock-keywords to something appropriate for this mode." | ||
| 384 | (setq font-lock-keywords | ||
| 385 | (cond ((eq major-mode 'lisp-mode) lisp-font-lock-keywords) | ||
| 386 | ((eq major-mode 'emacs-lisp-mode) lisp-font-lock-keywords) | ||
| 387 | ((eq major-mode 'c-mode) c-font-lock-keywords) | ||
| 388 | ((eq major-mode 'c++-c-mode) c-font-lock-keywords) | ||
| 389 | ((eq major-mode 'c++-mode) c++-font-lock-keywords) | ||
| 390 | ((eq major-mode 'perl-mode) perl-font-lock-keywords) | ||
| 391 | ((eq major-mode 'tex-mode) tex-font-lock-keywords) | ||
| 392 | ((eq major-mode 'texinfo-mode) texi-font-lock-keywords) | ||
| 393 | (t nil)))) | ||
| 394 | |||
| 395 | (defconst lisp-font-lock-keywords-1 | ||
| 396 | '(;; | ||
| 397 | ;; highlight defining forms. This doesn't work too nicely for | ||
| 398 | ;; (defun (setf foo) ...) but it does work for (defvar foo) which | ||
| 399 | ;; is more important. | ||
| 400 | ("^(def[-a-z]+\\s +\\([^ \t\n\)]+\\)" 1 font-lock-function-name-face) | ||
| 401 | ;; | ||
| 402 | ;; highlight CL keywords | ||
| 403 | ("\\s :\\(\\(\\sw\\|\\s_\\)+\\)\\>" . 1) | ||
| 404 | ;; | ||
| 405 | ;; this is highlights things like (def* (setf foo) (bar baz)), but may | ||
| 406 | ;; be slower (I haven't really thought about it) | ||
| 407 | ; ("^(def[-a-z]+\\s +\\(\\s(\\S)*\\s)\\|\\S(\\S *\\)" | ||
| 408 | ; 1 font-lock-function-name-face) | ||
| 409 | ) | ||
| 410 | "For consideration as a value of `lisp-font-lock-keywords'. | ||
| 411 | This does fairly subdued highlighting.") | ||
| 412 | |||
| 413 | (defconst lisp-font-lock-keywords-2 | ||
| 414 | (append | ||
| 415 | lisp-font-lock-keywords-1 | ||
| 416 | '(;; | ||
| 417 | ;; Highlight control structures | ||
| 418 | ("(\\(cond\\|if\\|when\\|unless\\|[ec]?\\(type\\)?case\\)[ \t\n]" . 1) | ||
| 419 | ("(\\(while\\|do\\|let*?\\|flet\\|labels\\|prog[nv12*]?\\)[ \t\n]" . 1) | ||
| 420 | ("(\\(catch\\|\\throw\\|block\\|return\\|return-from\\)[ \t\n]" . 1) | ||
| 421 | ("(\\(save-restriction\\|save-window-restriction\\)[ \t\n]" . 1) | ||
| 422 | ("(\\(save-excursion\\|unwind-protect\\|condition-case\\)[ \t\n]" . 1) | ||
| 423 | ;; | ||
| 424 | ;; highlight function names in emacs-lisp docstrings (in the syntax | ||
| 425 | ;; that substitute-command-keys understands.) | ||
| 426 | ("\\\\\\\\\\[\\([^]\\\n]+\\)]" 1 font-lock-keyword-face t) | ||
| 427 | ;; | ||
| 428 | ;; highlight words inside `' which tend to be function names | ||
| 429 | ("`\\([-a-zA-Z0-9_][-a-zA-Z0-9_][-a-zA-Z0-9_.]+\\)'" | ||
| 430 | 1 font-lock-keyword-face t) | ||
| 431 | )) | ||
| 432 | "For consideration as a value of `lisp-font-lock-keywords'. | ||
| 433 | This does a lot more highlighting.") | ||
| 434 | |||
| 435 | ;; default to the gaudier variety? | ||
| 436 | ;(defvar lisp-font-lock-keywords lisp-font-lock-keywords-2 | ||
| 437 | ; "Additional expressions to highlight in Lisp modes.") | ||
| 438 | (defvar lisp-font-lock-keywords lisp-font-lock-keywords-1 | ||
| 439 | "Additional expressions to highlight in Lisp modes.") | ||
| 440 | |||
| 441 | |||
| 442 | (defconst c-font-lock-keywords-1 nil | ||
| 443 | "For consideration as a value of `c-font-lock-keywords'. | ||
| 444 | This does fairly subdued highlighting.") | ||
| 445 | |||
| 446 | (defconst c-font-lock-keywords-2 nil | ||
| 447 | "For consideration as a value of `c-font-lock-keywords'. | ||
| 448 | This does a lot more highlighting.") | ||
| 449 | |||
| 450 | (let ((storage "auto\\|extern\\|register\\|static\\|volatile") | ||
| 451 | (prefixes "unsigned\\|short\\|long") | ||
| 452 | (types (concat "int\\|char\\|float\\|double\\|void\\|struct\\|" | ||
| 453 | "union\\|enum\\|typedef")) | ||
| 454 | (ctoken "[a-zA-Z0-9_:~*]+") | ||
| 455 | ) | ||
| 456 | (setq c-font-lock-keywords-1 | ||
| 457 | (list | ||
| 458 | ;; fontify preprocessor directives as comments. | ||
| 459 | '("^#[ \t]*[a-z]+" . font-lock-comment-face) | ||
| 460 | ;; | ||
| 461 | ;; fontify names being defined. | ||
| 462 | '("^#[ \t]*\\(define\\|undef\\)[ \t]+\\(\\(\\sw\\|\\s_\\)+\\)" 2 | ||
| 463 | font-lock-function-name-face) | ||
| 464 | ;; | ||
| 465 | ;; fontify other preprocessor lines. | ||
| 466 | '("^#[ \t]*\\(if\\|ifn?def\\)[ \t]+\\([^\n]+\\)" | ||
| 467 | 2 font-lock-function-name-face t) | ||
| 468 | ;; | ||
| 469 | ;; fontify the filename in #include <...> | ||
| 470 | ;; don't need to do this for #include "..." because those were | ||
| 471 | ;; already fontified as strings by the syntactic pass. | ||
| 472 | '("^#[ \t]*include[ \t]+\\(<[^>\"\n]+>\\)" 1 font-lock-string-face) | ||
| 473 | ;; | ||
| 474 | ;; fontify the names of functions being defined. | ||
| 475 | (list (concat | ||
| 476 | "^\\(" ctoken "[ \t]+\\)?" ; type specs; there can be no | ||
| 477 | "\\(" ctoken "[ \t]+\\)?" ; more than 3 tokens, right? | ||
| 478 | "\\(" ctoken "[ \t]+\\)?" | ||
| 479 | "\\(\\*+[ \t]*\\)?" ; pointer | ||
| 480 | "\\(" ctoken "\\)[ \t]*(") ; name | ||
| 481 | 5 'font-lock-function-name-face) | ||
| 482 | ;; | ||
| 483 | ;; | ||
| 484 | ;; Fontify structure names (in structure definition form). | ||
| 485 | (list (concat "^\\(typedef[ \t]+struct\\|struct\\|static[ \t]+struct\\)" | ||
| 486 | "[ \t]+\\(" ctoken "\\)[ \t]*\\(\{\\|$\\)") | ||
| 487 | 2 'font-lock-function-name-face) | ||
| 488 | ;; | ||
| 489 | ;; Fontify case clauses. This is fast because its anchored on the left. | ||
| 490 | '("case[ \t]+\\(\\(\\sw\\|\\s_\\)+\\):". 1) | ||
| 491 | '("\\<\\(default\\):". 1) | ||
| 492 | )) | ||
| 493 | |||
| 494 | (setq c-font-lock-keywords-2 | ||
| 495 | (append c-font-lock-keywords-1 | ||
| 496 | (list | ||
| 497 | ;; | ||
| 498 | ;; fontify all storage classes and type specifiers | ||
| 499 | (cons (concat "\\<\\(" storage "\\)\\>") 'font-lock-type-face) | ||
| 500 | (cons (concat "\\<\\(" types "\\)\\>") 'font-lock-type-face) | ||
| 501 | (cons (concat "\\<\\(" prefixes "[ \t]+" types "\\)\\>") | ||
| 502 | 'font-lock-type-face) | ||
| 503 | ;; | ||
| 504 | ;; fontify all builtin tokens | ||
| 505 | (cons (concat | ||
| 506 | "[ \t]\\(" | ||
| 507 | (mapconcat 'identity | ||
| 508 | '("for" "while" "do" "return" "goto" "case" "break" "switch" | ||
| 509 | "if" "then" "else if" "else" "return" "default" "continue" | ||
| 510 | "default" | ||
| 511 | ) | ||
| 512 | "\\|") | ||
| 513 | "\\)[ \t\n(){};,]") | ||
| 514 | 1) | ||
| 515 | ;; | ||
| 516 | ;; fontify case targets and goto-tags. This is slow because the | ||
| 517 | ;; expression is anchored on the right. | ||
| 518 | "\\(\\(\\sw\\|\\s_\\)+\\):" | ||
| 519 | ;; | ||
| 520 | ;; Fontify variables declared with structures, or typedef names. | ||
| 521 | '("}[ \t*]*\\(\\(\\sw\\|\\s_\\)+\\)[ \t]*[,;]" | ||
| 522 | 1 font-lock-function-name-face) | ||
| 523 | ;; | ||
| 524 | ;; Fontify global variables without a type. | ||
| 525 | ; '("^\\([_a-zA-Z0-9:~*]+\\)[ \t]*[[;={]" 1 font-lock-function-name-face) | ||
| 526 | |||
| 527 | ))) | ||
| 528 | ) | ||
| 529 | |||
| 530 | ; default to the gaudier variety? | ||
| 531 | ;(defvar c-font-lock-keywords c-font-lock-keywords-2 | ||
| 532 | ; "Additional expressions to highlight in C mode.") | ||
| 533 | (defvar c-font-lock-keywords c-font-lock-keywords-1 | ||
| 534 | "Additional expressions to highlight in C mode.") | ||
| 535 | |||
| 536 | (defvar c++-font-lock-keywords c-font-lock-keywords | ||
| 537 | "Additional expressions to highlight in C++ mode.") | ||
| 538 | |||
| 539 | |||
| 540 | (defvar perl-font-lock-keywords | ||
| 541 | (list | ||
| 542 | (concat "[ \n\t{]*\\(" | ||
| 543 | (mapconcat 'identity | ||
| 544 | '("if" "until" "while" "elsif" "else" "unless" "for" | ||
| 545 | "foreach" "continue" "exit" "die" "last" "goto" "next" | ||
| 546 | "redo" "return" "local" "exec") | ||
| 547 | "\\|") | ||
| 548 | "\\)[ \n\t;(]") | ||
| 549 | (mapconcat 'identity | ||
| 550 | '("#endif" "#else" "#ifdef" "#ifndef" "#if" "#include" | ||
| 551 | "#define" "#undef") | ||
| 552 | "\\|") | ||
| 553 | '("^[ \n\t]*sub[ \t]+\\([^ \t{]+\\)\\{" . font-lock-function-name-face) | ||
| 554 | '("[ \n\t{]*\\(eval\\)[ \n\t(;]" . font-lock-function-name-face) | ||
| 555 | '("\\(--- .* ---\\|=== .* ===\\)" . font-lock-doc-string-face) | ||
| 556 | ) | ||
| 557 | "Additional expressions to highlight in Perl mode.") | ||
| 558 | |||
| 559 | (defvar tex-font-lock-keywords | ||
| 560 | (list | ||
| 561 | '("\\(\\\\\\w+\\)" 1 font-lock-keyword-face t) | ||
| 562 | '("{\\\\em\\([^}]+\\)}" 1 font-lock-comment-face t) | ||
| 563 | '("{\\\\bf\\([^}]+\\)}" 1 font-lock-keyword-face t) | ||
| 564 | '("^[ \t\n]*\\\\def[\\\\@]\\(\\w+\\)" 1 font-lock-function-name-face t) | ||
| 565 | '("\\\\\\(begin\\|end\\){\\([a-zA-Z0-9\\*]+\\)}" | ||
| 566 | 2 font-lock-function-name-face t) | ||
| 567 | '("[^\\\\]\\$\\([^$]*\\)\\$" 1 font-lock-string-face t) | ||
| 568 | ; '("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t) | ||
| 569 | ) | ||
| 570 | "Additional expressions to highlight in TeX mode.") | ||
| 571 | |||
| 572 | (defvar texi-font-lock-keywords | ||
| 573 | (list | ||
| 574 | "@\\(@\\|[^}\t \n{]+\\)" ;commands | ||
| 575 | '("^\\(@c\\|@comment\\)[ \t].*$" . font-lock-comment-face) ;comments | ||
| 576 | '("^\\(*.*\\)[\t ]*$" 1 font-lock-function-name-face t) ;menu items | ||
| 577 | '("@\\(emph\\|strong\\|b\\|i\\){\\([^}]+\\)" 2 font-lock-comment-face t) | ||
| 578 | '("@\\(file\\|kbd\\|key\\){\\([^}]+\\)" 2 font-lock-string-face t) | ||
| 579 | '("@\\(samp\\|code\\|var\\){\\([^}]+\\)" 2 font-lock-function-name-face t) | ||
| 580 | '("@\\(xref\\|pxref\\){\\([^}]+\\)" 2 font-lock-keyword-face t) | ||
| 581 | '("@end *\\([a-zA-Z0-9]+\\)[ \t]*$" 1 font-lock-function-name-face t) | ||
| 582 | '("@item \\(.*\\)$" 1 font-lock-function-name-face t) | ||
| 583 | '("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t) | ||
| 584 | ) | ||
| 585 | "Additional expressions to highlight in TeXinfo mode.") | ||
| 586 | |||
| 587 | (provide 'font-lock) | ||
| 588 | |||
| 589 | ;;; font-lock.el ends here | ||