annotate lisp/packages/font-lock.el @ 209:41ff10fd062f r20-4b3

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