annotate lisp/font-lock.el @ 4092:e72012acb5fb

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