comparison lisp/font-core.el @ 50595:7633f45262ae

(font-lock-maximum-size, font-lock-verbose): Remove. (font-lock-multiline, font-lock-fontified, font-lock-set-defaults): Move back to font-lock.el (font-lock-default-function): Use font-lock-mode-internal.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 14 Apr 2003 23:07:49 +0000
parents 1713a3efdd23
children 1963828b8333
comparison
equal deleted inserted replaced
50594:09c07c654b23 50595:7633f45262ae
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA. 24 ;; Boston, MA 02111-1307, USA.
25 25
26 ;;; Code: 26 ;;; Code:
27
28 (defvar font-lock-maximum-size)
29 (defvar font-lock-verbose)
30 27
31 ;; This variable is used by mode packages that support Font Lock mode by 28 ;; This variable is used by mode packages that support Font Lock mode by
32 ;; defining their own keywords to use for `font-lock-keywords'. (The mode 29 ;; defining their own keywords to use for `font-lock-keywords'. (The mode
33 ;; command should make it buffer-local and set it to provide the set up.) 30 ;; command should make it buffer-local and set it to provide the set up.)
34 (defvar font-lock-defaults nil 31 (defvar font-lock-defaults nil
128 125
129 where MAJOR-MODE is a symbol and FONT-LOCK-DEFAULTS is a list of default 126 where MAJOR-MODE is a symbol and FONT-LOCK-DEFAULTS is a list of default
130 settings. See the variable `font-lock-defaults', which takes precedence.") 127 settings. See the variable `font-lock-defaults', which takes precedence.")
131 (make-obsolete-variable 'font-lock-defaults-alist 'font-lock-defaults) 128 (make-obsolete-variable 'font-lock-defaults-alist 'font-lock-defaults)
132 129
133 (defvar font-lock-multiline nil
134 "Whether font-lock should cater to multiline keywords.
135 If nil, don't try to handle multiline patterns.
136 If t, always handle multiline patterns.
137 If `undecided', don't try to handle multiline patterns until you see one.
138 Major/minor modes can set this variable if they know which option applies.")
139
140 (defvar font-lock-fontified nil) ; Whether we have fontified the buffer.
141
142 (defvar font-lock-function 'font-lock-default-function 130 (defvar font-lock-function 'font-lock-default-function
143 "A function which is called when `font-lock-mode' is toggled. 131 "A function which is called when `font-lock-mode' is toggled.
144 It will be passed one argument, which is the current value of 132 It will be passed one argument, which is the current value of
145 `font-lock-mode'.") 133 `font-lock-mode'.")
146 (make-variable-buffer-local 'font-lock-function)
147 134
148 (define-minor-mode font-lock-mode 135 (define-minor-mode font-lock-mode
149 "Toggle Font Lock mode. 136 "Toggle Font Lock mode.
150 With arg, turn Font Lock mode off if and only if arg is a non-positive 137 With arg, turn Font Lock mode off if and only if arg is a non-positive
151 number; if arg is nil, toggle Font Lock mode; anything else turns Font 138 number; if arg is nil, toggle Font Lock mode; anything else turns Font
220 (defun font-lock-change-mode () 207 (defun font-lock-change-mode ()
221 (font-lock-mode -1)) 208 (font-lock-mode -1))
222 209
223 (defun font-lock-defontify () 210 (defun font-lock-defontify ()
224 "Clear out all `font-lock-face' properties in current buffer. 211 "Clear out all `font-lock-face' properties in current buffer.
225 A major mode that uses `font-lock-face' properties should put 212 A major mode that uses `font-lock-face' properties might want to put
226 this function onto `change-major-mode-hook'." 213 this function onto `change-major-mode-hook'."
227 (let ((modp (buffer-modified-p)) 214 (let ((modp (buffer-modified-p))
228 (inhibit-read-only t)) 215 (inhibit-read-only t))
229 (save-restriction 216 (save-restriction
230 (widen) 217 (widen)
233 (restore-buffer-modified-p modp))) 220 (restore-buffer-modified-p modp)))
234 221
235 (defun font-lock-default-function (mode) 222 (defun font-lock-default-function (mode)
236 ;; Turn on Font Lock mode. 223 ;; Turn on Font Lock mode.
237 (when mode 224 (when mode
238 (font-lock-set-defaults)
239 (set (make-local-variable 'char-property-alias-alist) 225 (set (make-local-variable 'char-property-alias-alist)
240 (copy-tree char-property-alias-alist)) 226 (copy-tree char-property-alias-alist))
241 ;; Add `font-lock-face' as an alias for the `face' property. 227 ;; Add `font-lock-face' as an alias for the `face' property.
242 (let ((elt (assq 'face char-property-alias-alist))) 228 (let ((elt (assq 'face char-property-alias-alist)))
243 (if elt 229 (if elt
244 (unless (memq 'font-lock-face (cdr elt)) 230 (unless (memq 'font-lock-face (cdr elt))
245 (setcdr elt (nconc (cdr elt) (list 'font-lock-face)))) 231 (setcdr elt (nconc (cdr elt) (list 'font-lock-face))))
246 (push (list 'face 'font-lock-face) char-property-alias-alist))) 232 (push (list 'face 'font-lock-face) char-property-alias-alist))))
247 ;; Only do hard work if the mode has specified stuff in
248 ;; `font-lock-defaults'.
249 (when font-lock-defaults
250 (add-hook 'after-change-functions 'font-lock-after-change-function t t)
251 (font-lock-turn-on-thing-lock)
252 ;; Fontify the buffer if we have to.
253 (let ((max-size (font-lock-value-in-major-mode font-lock-maximum-size)))
254 (cond (font-lock-fontified
255 nil)
256 ((or (null max-size) (> max-size (buffer-size)))
257 (font-lock-fontify-buffer))
258 (font-lock-verbose
259 (message "Fontifying %s...buffer size greater than font-lock-maximum-size"
260 (buffer-name)))))))
261 ;; Turn off Font Lock mode. 233 ;; Turn off Font Lock mode.
262 (unless mode 234 (unless mode
263 ;; Remove `font-lock-face' as an alias for the `face' property. 235 ;; Remove `font-lock-face' as an alias for the `face' property.
264 (set (make-local-variable 'char-property-alias-alist) 236 (set (make-local-variable 'char-property-alias-alist)
265 (copy-tree char-property-alias-alist)) 237 (copy-tree char-property-alias-alist))
266 (let ((elt (assq 'face char-property-alias-alist))) 238 (let ((elt (assq 'face char-property-alias-alist)))
267 (when elt 239 (when elt
268 (setcdr elt (remq 'font-lock-face (cdr elt))) 240 (setcdr elt (remq 'font-lock-face (cdr elt)))
269 (when (null (cdr elt)) 241 (when (null (cdr elt))
270 (setq char-property-alias-alist (delq elt char-property-alias-alist))))) 242 (setq char-property-alias-alist
271 (when font-lock-defaults 243 (delq elt char-property-alias-alist))))))
272 (remove-hook 'after-change-functions 'font-lock-after-change-function t) 244
273 (font-lock-unfontify-buffer) 245 ;; Only do hard work if the mode has specified stuff in
274 (font-lock-turn-off-thing-lock)))) 246 ;; `font-lock-defaults'.
247 (when (or font-lock-defaults
248 (cdr (assq major-mode font-lock-defaults-alist)))
249 (font-lock-mode-internal mode)))
275 250
276 (defun turn-on-font-lock () 251 (defun turn-on-font-lock ()
277 "Turn on Font Lock mode (only if the terminal can display it)." 252 "Turn on Font Lock mode (only if the terminal can display it)."
278 (unless font-lock-mode 253 (unless font-lock-mode
279 (font-lock-mode))) 254 (font-lock-mode)))
280
281 (defvar font-lock-set-defaults nil) ; Whether we have set up defaults.
282
283 (defun font-lock-set-defaults ()
284 "Set fontification defaults appropriately for this mode.
285 Sets various variables using `font-lock-defaults' (or, if nil, using
286 `font-lock-defaults-alist') and `font-lock-maximum-decoration'."
287 (unless font-lock-set-defaults
288 (set (make-local-variable 'font-lock-set-defaults) t)
289 (make-local-variable 'font-lock-fontified)
290 (make-local-variable 'font-lock-multiline)
291 (let ((defaults (or font-lock-defaults
292 (cdr (assq major-mode font-lock-defaults-alist)))))
293 (when defaults
294 (require 'font-lock)
295 (font-lock-set-defaults-1)))))
296 255
297 ;;; Global Font Lock mode. 256 ;;; Global Font Lock mode.
298 257
299 ;; A few people have hassled in the past for a way to make it easier to turn on 258 ;; A few people have hassled in the past for a way to make it easier to turn on
300 ;; Font Lock mode, without the user needing to know for which modes s/he has to 259 ;; Font Lock mode, without the user needing to know for which modes s/he has to