]> code.delx.au - gnu-emacs/blob - lisp/lazy-lock.el
(comint-input-face): Deleted.
[gnu-emacs] / lisp / lazy-lock.el
1 ;;; lazy-lock.el --- Lazy demand-driven fontification for fast Font Lock mode.
2
3 ;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
4
5 ;; Author: Simon Marshall <simon@gnu.ai.mit.edu>
6 ;; Keywords: faces files
7 ;; Version: 2.08
8
9 ;;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;; Purpose:
29 ;;
30 ;; Lazy Lock mode is a Font Lock support mode.
31 ;; It makes visiting buffers in Font Lock mode faster by making fontification
32 ;; be demand-driven, deferred and stealthy, so that fontification only occurs
33 ;; when, and where, necessary.
34 ;;
35 ;; See caveats and feedback below.
36 ;; See also the fast-lock package. (But don't use them at the same time!)
37
38 ;; Installation:
39 ;;
40 ;; Put in your ~/.emacs:
41 ;;
42 ;; (setq font-lock-support-mode 'lazy-lock-mode)
43 ;;
44 ;; Start up a new Emacs and use font-lock as usual (except that you can use the
45 ;; so-called "gaudier" fontification regexps on big files without frustration).
46 ;;
47 ;; In a buffer (which has `font-lock-mode' enabled) which is at least
48 ;; `lazy-lock-minimum-size' characters long, buffer fontification will not
49 ;; occur and only the visible portion of the buffer will be fontified. Motion
50 ;; around the buffer will fontify those visible portions not previously
51 ;; fontified. If stealth fontification is enabled, buffer fontification will
52 ;; occur in invisible parts of the buffer after `lazy-lock-stealth-time'
53 ;; seconds of idle time. If on-the-fly fontification is deferred, on-the-fly
54 ;; fontification will occur after `lazy-lock-defer-time' seconds of idle time.
55
56 ;; User-visible differences with version 1:
57 ;;
58 ;; - Version 2 can defer on-the-fly fontification. Therefore you need not, and
59 ;; should not, use defer-lock.el with this version of lazy-lock.el.
60 ;;
61 ;; A number of variables have changed meaning:
62 ;;
63 ;; - A value of nil for the variable `lazy-lock-minimum-size' means never turn
64 ;; on demand-driven fontification. In version 1 this meant always turn on
65 ;; demand-driven fontification. If you really want demand-driven fontification
66 ;; regardless of buffer size, set this variable to 0.
67 ;;
68 ;; - The variable `lazy-lock-stealth-lines' cannot have a nil value. In
69 ;; version 1 this meant use `window-height' as the maximum number of lines to
70 ;; fontify as a stealth chunk. This makes no sense; stealth fontification is
71 ;; of a buffer, not a window.
72
73 ;; Implementation differences with version 1:
74 ;;
75 ;; - Version 1 of lazy-lock.el is a bit of a hack. Version 1 demand-driven
76 ;; fontification, the core feature of lazy-lock.el, is implemented by placing a
77 ;; function on `post-command-hook'. This function fontifies where necessary,
78 ;; i.e., where a window scroll has occurred. However, there are a number of
79 ;; problems with using `post-command-hook':
80 ;;
81 ;; (a) As the name suggests, `post-command-hook' is run after every command,
82 ;; i.e., frequently and regardless of whether scrolling has occurred.
83 ;; (b) Scrolling can occur during a command, when `post-command-hook' is not
84 ;; run, i.e., it is not necessarily run after scrolling has occurred.
85 ;; (c) When `post-command-hook' is run, there is nothing to suggest where
86 ;; scrolling might have occurred, i.e., which windows have scrolled.
87 ;;
88 ;; Thus lazy-lock.el's function is called almost as often as possible, usually
89 ;; when it need not be called, yet it is not always called when it is needed.
90 ;; Also, lazy-lock.el's function must check each window to see if a scroll has
91 ;; occurred there. Worse still, lazy-lock.el's function must fontify a region
92 ;; twice as large as necessary to make sure the window is completely fontified.
93 ;; Basically, `post-command-hook' is completely inappropriate for lazy-lock.el.
94 ;;
95 ;; Ideally, we want to attach lazy-lock.el's function to a hook that is run
96 ;; only when scrolling occurs, e.g., `window-start' has changed, and tells us
97 ;; as much information as we need, i.e., the window and its new buffer region.
98 ;; Richard Stallman implemented a `window-scroll-functions' for Emacs 19.30.
99 ;; Functions on it are run when `window-start' has changed, and are supplied
100 ;; with the window and the window's new `window-start' position. (It would be
101 ;; better if it also supplied the window's new `window-end' position, but that
102 ;; is calculated as part of the redisplay process, and the functions on
103 ;; `window-scroll-functions' are run before redisplay has finished.) Thus, the
104 ;; hook deals with the above problems (a), (b) and (c).
105 ;;
106 ;; If only life was that easy. Version 2 demand-driven fontification is mostly
107 ;; implemented by placing a function on `window-scroll-functions'. However,
108 ;; not all scrolling occurs when `window-start' has changed. A change in
109 ;; window size, e.g., via C-x 1, or a significant deletion, e.g., of a number
110 ;; of lines, causes text previously invisible (i.e., after `window-end') to
111 ;; become visible without changing `window-start'. Arguably, these events are
112 ;; not scrolling events, but fontification must occur for lazy-lock.el to work.
113 ;; Hooks `window-size-change-functions' and `redisplay-end-trigger-functions'
114 ;; were added for these circumstances.
115 ;;
116 ;; (Ben Wing thinks these hooks are "horribly horribly kludgy", and implemented
117 ;; a `pre-idle-hook', a `mother-of-all-post-command-hooks', for XEmacs 19.14.
118 ;; He then hacked up a version 1 lazy-lock.el to use `pre-idle-hook' rather
119 ;; than `post-command-hook'. Whereas functions on `post-command-hook' are
120 ;; called almost as often as possible, functions on `pre-idle-hook' really are
121 ;; called as often as possible, even when the mouse moves and, on some systems,
122 ;; while XEmacs is idle. Thus, the hook deals with the above problem (b), but
123 ;; unfortunately it makes (a) worse and does not address (c) at all.
124 ;;
125 ;; I freely admit that `redisplay-end-trigger-functions' and, to a much lesser
126 ;; extent, `window-size-change-functions' are not pretty. However, I feel that
127 ;; a `window-scroll-functions' feature is cleaner than a `pre-idle-hook', and
128 ;; the result is faster and smaller, less intrusive and more targeted, code.
129 ;; Since `pre-idle-hook' is pretty much like `post-command-hook', there is no
130 ;; point in making this version of lazy-lock.el work with it. Anyway, that's
131 ;; Lit 30 of my humble opinion.
132 ;;
133 ;; Steve Baur reverted to a non-hacked version 1 lazy-lock.el for XEmacs 19.15
134 ;; and 20.0. Obviously, the above `post-command-hook' problems still apply.)
135 ;;
136 ;; - Version 1 stealth fontification is also implemented by placing a function
137 ;; on `post-command-hook'. This function waits for a given amount of time,
138 ;; and, if Emacs remains idle, fontifies where necessary. Again, there are a
139 ;; number of problems with using `post-command-hook':
140 ;;
141 ;; (a) Functions on `post-command-hook' are run sequentially, so this function
142 ;; can interfere with other functions on the hook, and vice versa.
143 ;; (b) This function waits for a given amount of time, so it can interfere with
144 ;; various features that are dealt with by Emacs after a command, e.g.,
145 ;; region highlighting, asynchronous updating and keystroke echoing.
146 ;; (c) Fontification may be required during a command, when `post-command-hook'
147 ;; is not run. (Version 2 deferred fontification only.)
148 ;;
149 ;; Again, `post-command-hook' is completely inappropriate for lazy-lock.el.
150 ;; Richard Stallman and Morten Welinder implemented internal Timers and Idle
151 ;; Timers for Emacs 19.31. Functions can be run independently at given times
152 ;; or after given amounts of idle time. Thus, the feature deals with the above
153 ;; problems (a), (b) and (c). Version 2 deferral and stealth are implemented
154 ;; by functions on Idle Timers. (A function on XEmacs' `pre-idle-hook' is
155 ;; similar to an Emacs Idle Timer function with a fixed zero second timeout.)
156
157 ;; - Version 1 has the following problems (relative to version 2):
158 ;;
159 ;; (a) It is slow when it does its job.
160 ;; (b) It does not always do its job when it should.
161 ;; (c) It slows all interaction (when it doesn't need to do its job).
162 ;; (d) It interferes with other package functions on `post-command-hook'.
163 ;; (e) It interferes with Emacs things within the read-eval loop.
164 ;;
165 ;; Ben's hacked-up lazy-lock.el 1.14 almost solved (b) but made (c) worse.
166 ;;
167 ;; - Version 2 has the following additional features (relative to version 1):
168 ;;
169 ;; (a) It can defer fontification (both on-the-fly and on-scrolling).
170 ;; (b) It can fontify contextually (syntactically true on-the-fly).
171
172 ;; Caveats:
173 ;;
174 ;; Lazy Lock mode does not work efficiently with Outline mode.
175 ;; This is because when in Outline mode, although text may be not visible to
176 ;; you in the window, the text is visible to Emacs Lisp code (not surprisingly)
177 ;; and Lazy Lock fontifies it mercilessly. Maybe it will be fixed one day.
178 ;;
179 ;; Because buffer text is not necessarily fontified, other packages that expect
180 ;; buffer text to be fontified in Font Lock mode either might not work as
181 ;; expected, or might not display buffer text as expected. An example of the
182 ;; latter is `occur', which copies lines of buffer text into another buffer.
183 ;;
184 ;; In Emacs 19.30, Lazy Lock mode does not ensure that an existing buffer is
185 ;; fontified if it is made visible via a minibuffer-less command that replaces
186 ;; an existing window's buffer (e.g., via the Buffers menu). Upgrade!
187 ;;
188 ;; In Emacs 19.30, Lazy Lock mode does not work well with Transient Mark mode
189 ;; or modes based on Comint mode (e.g., Shell mode), and also interferes with
190 ;; the echoing of keystrokes in the minibuffer. This is because of the way
191 ;; deferral and stealth have to be implemented for Emacs 19.30. Upgrade!
192 ;;
193 ;; Currently XEmacs does not have the features to support this version of
194 ;; lazy-lock.el. Maybe it will one day.
195 \f
196 ;;; Code:
197
198 (require 'font-lock)
199
200 ;; Make sure lazy-lock.el is supported.
201 (if (if (save-match-data (string-match "Lucid\\|XEmacs" (emacs-version)))
202 t
203 (and (= emacs-major-version 19) (< emacs-minor-version 30)))
204 (error "`lazy-lock' was written for Emacs 19.30 or later"))
205
206 (eval-when-compile
207 ;;
208 ;; We don't do this at the top-level as idle timers are not necessarily used.
209 (require 'timer)
210 ;; We don't do this at the top-level as we only use non-autoloaded macros.
211 (require 'cl))
212
213 ;; We use this to preserve or protect things when modifying text properties.
214 (defmacro save-buffer-state (varlist &rest body)
215 "Bind variables according to VARLIST and eval BODY restoring buffer state."
216 (` (let* ((,@ (append varlist
217 '((modified (buffer-modified-p)) (buffer-undo-list t)
218 (inhibit-read-only t) (inhibit-point-motion-hooks t)
219 before-change-functions after-change-functions
220 deactivate-mark buffer-file-name buffer-file-truename))))
221 (,@ body)
222 (when (and (not modified) (buffer-modified-p))
223 (set-buffer-modified-p nil)))))
224 (put 'save-buffer-state 'lisp-indent-function 1)
225
226 ;; We use this for clarity and speed. Naughty but nice.
227 (defmacro do-while (test &rest body)
228 "(do-while TEST BODY...): eval BODY... and repeat if TEST yields non-nil.
229 The order of execution is thus BODY, TEST, BODY, TEST and so on
230 until TEST returns nil."
231 (` (while (progn (,@ body) (, test)))))
232 (put 'do-while 'lisp-indent-function (get 'while 'lisp-indent-function))
233
234 ;(defun lazy-lock-submit-bug-report ()
235 ; "Submit via mail a bug report on lazy-lock.el."
236 ; (interactive)
237 ; (let ((reporter-prompt-for-summary-p t))
238 ; (reporter-submit-bug-report "simon@gnu.ai.mit.edu" "lazy-lock 2.08"
239 ; '(lazy-lock-minimum-size lazy-lock-defer-on-the-fly
240 ; lazy-lock-defer-on-scrolling lazy-lock-defer-contextually
241 ; lazy-lock-defer-time lazy-lock-stealth-time
242 ; lazy-lock-stealth-load lazy-lock-stealth-nice lazy-lock-stealth-lines
243 ; lazy-lock-stealth-verbose)
244 ; nil nil
245 ; (concat "Hi Si.,
246 ;
247 ;I want to report a bug. I've read the `Bugs' section of `Info' on Emacs, so I
248 ;know how to make a clear and unambiguous report. To reproduce the bug:
249 ;
250 ;Start a fresh editor via `" invocation-name " -no-init-file -no-site-file'.
251 ;In the `*scratch*' buffer, evaluate:"))))
252
253 (defvar lazy-lock-mode nil) ; Whether we are turned on.
254 (defvar lazy-lock-buffers nil) ; For deferral.
255 (defvar lazy-lock-timers (cons nil nil)) ; For deferral and stealth.
256 \f
257 ;; User Variables:
258
259 (defgroup lazy-lock nil
260 "Font Lock support mode to fontify lazily."
261 :link '(custom-manual "(emacs)Support Modes")
262 :group 'font-lock)
263
264 (defcustom lazy-lock-minimum-size (* 25 1024)
265 "*Minimum size of a buffer for demand-driven fontification.
266 On-demand fontification occurs if the buffer size is greater than this value.
267 If nil, means demand-driven fontification is never performed.
268 If a list, each element should be a cons pair of the form (MAJOR-MODE . SIZE),
269 where MAJOR-MODE is a symbol or t (meaning the default). For example:
270 ((c-mode . 25600) (c++-mode . 25600) (rmail-mode . 1048576))
271 means that the minimum size is 25K for buffers in C or C++ modes, one megabyte
272 for buffers in Rmail mode, and size is irrelevant otherwise.
273
274 The value of this variable is used when Lazy Lock mode is turned on."
275 :type '(choice (const :tag "none" nil)
276 (integer :tag "size")
277 (repeat :menu-tag "mode specific" :tag "mode specific"
278 :value ((t . nil))
279 (cons :tag "Instance"
280 (radio :tag "Mode"
281 (const :tag "all" t)
282 (symbol :tag "name"))
283 (radio :tag "Size"
284 (const :tag "none" nil)
285 (integer :tag "size")))))
286 :group 'lazy-lock)
287
288 (defcustom lazy-lock-defer-on-the-fly t
289 "*If non-nil, means fontification after a change should be deferred.
290 If nil, means on-the-fly fontification is performed. This means when changes
291 occur in the buffer, those areas are immediately fontified.
292 If a list, it should be a list of `major-mode' symbol names for which deferred
293 fontification should occur. The sense of the list is negated if it begins with
294 `not'. For example:
295 (c-mode c++-mode)
296 means that on-the-fly fontification is deferred for buffers in C and C++ modes
297 only, and deferral does not occur otherwise.
298
299 The value of this variable is used when Lazy Lock mode is turned on."
300 :type '(choice (const :tag "never" nil)
301 (const :tag "always" t)
302 (set :menu-tag "mode specific" :tag "modes"
303 :value (not)
304 (const :tag "Except" not)
305 (repeat :inline t (symbol :tag "mode"))))
306 :group 'lazy-lock)
307
308 (defcustom lazy-lock-defer-on-scrolling nil
309 "*If non-nil, means fontification after a scroll should be deferred.
310 If nil, means demand-driven fontification is performed. This means when
311 scrolling into unfontified areas of the buffer, those areas are immediately
312 fontified. Thus scrolling never presents unfontified areas. However, since
313 fontification occurs during scrolling, scrolling may be slow.
314 If t, means defer-driven fontification is performed. This means fontification
315 of those areas is deferred. Thus scrolling may present momentarily unfontified
316 areas. However, since fontification does not occur during scrolling, scrolling
317 will be faster than demand-driven fontification.
318 If any other value, e.g., `eventually', means demand-driven fontification is
319 performed until the buffer is fontified, then buffer fontification becomes
320 defer-driven. Thus scrolling never presents unfontified areas until the buffer
321 is first fontified, after which subsequent scrolling may present future buffer
322 insertions momentarily unfontified. However, since fontification does not
323 occur during scrolling after the buffer is first fontified, scrolling will
324 become faster. (But, since contextual changes continually occur, such a value
325 makes little sense if `lazy-lock-defer-contextually' is non-nil.)
326
327 The value of this variable is used when Lazy Lock mode is turned on."
328 :type '(choice (const :tag "never" nil)
329 (const :tag "always" t)
330 (const eventually))
331 :group 'lazy-lock)
332
333 (defcustom lazy-lock-defer-contextually 'syntax-driven
334 "*If non-nil, means deferred fontification should be syntactically true.
335 If nil, means deferred fontification occurs only on those lines modified. This
336 means where modification on a line causes syntactic change on subsequent lines,
337 those subsequent lines are not refontified to reflect their new context.
338 If t, means deferred fontification occurs on those lines modified and all
339 subsequent lines. This means those subsequent lines are refontified to reflect
340 their new syntactic context, either immediately or when scrolling into them.
341 If any other value, e.g., `syntax-driven', means deferred syntactically true
342 fontification occurs only if syntactic fontification is performed using the
343 buffer mode's syntax table, i.e., only if `font-lock-keywords-only' is nil.
344
345 The value of this variable is used when Lazy Lock mode is turned on."
346 :type '(choice (const :tag "never" nil)
347 (const :tag "always" t)
348 (const syntax-driven))
349 :group 'lazy-lock)
350
351 (defcustom lazy-lock-defer-time
352 (if (featurep 'lisp-float-type) (/ (float 1) (float 3)) 1)
353 "*Time in seconds to delay before beginning deferred fontification.
354 Deferred fontification occurs if there is no input within this time.
355 If nil, means fontification is never deferred, regardless of the values of the
356 variables `lazy-lock-defer-on-the-fly', `lazy-lock-defer-on-scrolling' and
357 `lazy-lock-defer-contextually'.
358
359 The value of this variable is used when Lazy Lock mode is turned on."
360 :type '(choice (const :tag "never" nil)
361 (number :tag "seconds"))
362 :group 'lazy-lock)
363
364 (defcustom lazy-lock-stealth-time 30
365 "*Time in seconds to delay before beginning stealth fontification.
366 Stealth fontification occurs if there is no input within this time.
367 If nil, means stealth fontification is never performed.
368
369 The value of this variable is used when Lazy Lock mode is turned on."
370 :type '(choice (const :tag "never" nil)
371 (number :tag "seconds"))
372 :group 'lazy-lock)
373
374 (defcustom lazy-lock-stealth-lines (if font-lock-maximum-decoration 100 250)
375 "*Maximum size of a chunk of stealth fontification.
376 Each iteration of stealth fontification can fontify this number of lines.
377 To speed up input response during stealth fontification, at the cost of stealth
378 taking longer to fontify, you could reduce the value of this variable."
379 :type '(integer :tag "lines")
380 :group 'lazy-lock)
381
382 (defcustom lazy-lock-stealth-load
383 (if (condition-case nil (load-average) (error)) 200)
384 "*Load in percentage above which stealth fontification is suspended.
385 Stealth fontification pauses when the system short-term load average (as
386 returned by the function `load-average' if supported) goes above this level,
387 thus reducing the demand that stealth fontification makes on the system.
388 If nil, means stealth fontification is never suspended.
389 To reduce machine load during stealth fontification, at the cost of stealth
390 taking longer to fontify, you could reduce the value of this variable.
391 See also `lazy-lock-stealth-nice'."
392 :type (if (condition-case nil (load-average) (error))
393 '(choice (const :tag "never" nil)
394 (integer :tag "load"))
395 '(const :tag "never" nil))
396 :group 'lazy-lock)
397
398 (defcustom lazy-lock-stealth-nice
399 (if (featurep 'lisp-float-type) (/ (float 1) (float 8)) 1)
400 "*Time in seconds to pause between chunks of stealth fontification.
401 Each iteration of stealth fontification is separated by this amount of time,
402 thus reducing the demand that stealth fontification makes on the system.
403 If nil, means stealth fontification is never paused.
404 To reduce machine load during stealth fontification, at the cost of stealth
405 taking longer to fontify, you could increase the value of this variable.
406 See also `lazy-lock-stealth-load'."
407 :type '(choice (const :tag "never" nil)
408 (number :tag "seconds"))
409 :group 'lazy-lock)
410
411 (defcustom lazy-lock-stealth-verbose
412 (if (featurep 'lisp-float-type)
413 (and (not lazy-lock-defer-contextually) (not (null font-lock-verbose))))
414 "*If non-nil, means stealth fontification should show status messages."
415 :type 'boolean
416 :group 'lazy-lock)
417 \f
418 ;; User Functions:
419
420 ;;;###autoload
421 (defun lazy-lock-mode (&optional arg)
422 "Toggle Lazy Lock mode.
423 With arg, turn Lazy Lock mode on if and only if arg is positive. Enable it
424 automatically in your `~/.emacs' by:
425
426 (setq font-lock-support-mode 'lazy-lock-mode)
427
428 When Lazy Lock mode is enabled, fontification can be lazy in a number of ways:
429
430 - Demand-driven buffer fontification if `lazy-lock-minimum-size' is non-nil.
431 This means initial fontification does not occur if the buffer is greater than
432 `lazy-lock-minimum-size' characters in length. Instead, fontification occurs
433 when necessary, such as when scrolling through the buffer would otherwise
434 reveal unfontified areas. This is useful if buffer fontification is too slow
435 for large buffers.
436
437 - Deferred scroll fontification if `lazy-lock-defer-on-scrolling' is non-nil.
438 This means demand-driven fontification does not occur as you scroll.
439 Instead, fontification is deferred until after `lazy-lock-defer-time' seconds
440 of Emacs idle time, while Emacs remains idle. This is useful if
441 fontification is too slow to keep up with scrolling.
442
443 - Deferred on-the-fly fontification if `lazy-lock-defer-on-the-fly' is non-nil.
444 This means on-the-fly fontification does not occur as you type. Instead,
445 fontification is deferred until after `lazy-lock-defer-time' seconds of Emacs
446 idle time, while Emacs remains idle. This is useful if fontification is too
447 slow to keep up with your typing.
448
449 - Deferred context fontification if `lazy-lock-defer-contextually' is non-nil.
450 This means fontification updates the buffer corresponding to true syntactic
451 context, after `lazy-lock-defer-time' seconds of Emacs idle time, while Emacs
452 remains idle. Otherwise, fontification occurs on modified lines only, and
453 subsequent lines can remain fontified corresponding to previous syntactic
454 contexts. This is useful where strings or comments span lines.
455
456 - Stealthy buffer fontification if `lazy-lock-stealth-time' is non-nil.
457 This means remaining unfontified areas of buffers are fontified if Emacs has
458 been idle for `lazy-lock-stealth-time' seconds, while Emacs remains idle.
459 This is useful if any buffer has any deferred fontification.
460
461 Basic Font Lock mode on-the-fly fontification behaviour fontifies modified
462 lines only. Thus, if `lazy-lock-defer-contextually' is non-nil, Lazy Lock mode
463 on-the-fly fontification may fontify differently, albeit correctly. In any
464 event, to refontify some lines you can use \\[font-lock-fontify-block].
465
466 Stealth fontification only occurs while the system remains unloaded.
467 If the system load rises above `lazy-lock-stealth-load' percent, stealth
468 fontification is suspended. Stealth fontification intensity is controlled via
469 the variable `lazy-lock-stealth-nice' and `lazy-lock-stealth-lines', and
470 verbosity is controlled via the variable `lazy-lock-stealth-verbose'."
471 (interactive "P")
472 (let* ((was-on lazy-lock-mode)
473 (now-on (unless (memq 'lazy-lock-mode font-lock-inhibit-thing-lock)
474 (if arg (> (prefix-numeric-value arg) 0) (not was-on)))))
475 (cond ((and now-on (not font-lock-mode))
476 ;; Turned on `lazy-lock-mode' rather than `font-lock-mode'.
477 (let ((font-lock-support-mode 'lazy-lock-mode))
478 (font-lock-mode t)))
479 (now-on
480 ;; Turn ourselves on.
481 (set (make-local-variable 'lazy-lock-mode) t)
482 (lazy-lock-install))
483 (was-on
484 ;; Turn ourselves off.
485 (set (make-local-variable 'lazy-lock-mode) nil)
486 (lazy-lock-unstall)))))
487
488 ;;;###autoload
489 (defun turn-on-lazy-lock ()
490 "Unconditionally turn on Lazy Lock mode."
491 (lazy-lock-mode t))
492
493 (defun lazy-lock-install ()
494 (let ((min-size (font-lock-value-in-major-mode lazy-lock-minimum-size))
495 (defer-change (and lazy-lock-defer-time lazy-lock-defer-on-the-fly))
496 (defer-scroll (and lazy-lock-defer-time lazy-lock-defer-on-scrolling))
497 (defer-context (and lazy-lock-defer-time lazy-lock-defer-contextually
498 (or (eq lazy-lock-defer-contextually t)
499 (null font-lock-keywords-only)))))
500 ;;
501 ;; Tell Font Lock whether Lazy Lock will do fontification.
502 (make-local-variable 'font-lock-fontified)
503 (setq font-lock-fontified (and min-size (>= (buffer-size) min-size)))
504 ;;
505 ;; Add the text properties and fontify.
506 (if (not font-lock-fontified)
507 (lazy-lock-after-fontify-buffer)
508 ;; Make sure we fontify in any existing windows showing the buffer.
509 (let ((windows (get-buffer-window-list (current-buffer) 'nomini t)))
510 (lazy-lock-after-unfontify-buffer)
511 (while windows
512 (lazy-lock-fontify-conservatively (car windows))
513 (setq windows (cdr windows)))))
514 ;;
515 ;; Add the fontification hooks.
516 (lazy-lock-install-hooks
517 font-lock-fontified
518 (cond ((eq (car-safe defer-change) 'not)
519 (not (memq major-mode (cdr defer-change))))
520 ((listp defer-change)
521 (memq major-mode defer-change))
522 (t
523 defer-change))
524 (eq defer-scroll t)
525 defer-context)
526 ;;
527 ;; Add the fontification timers.
528 (lazy-lock-install-timers
529 (if (or defer-change defer-scroll defer-context) lazy-lock-defer-time)
530 lazy-lock-stealth-time)))
531
532 (defun lazy-lock-install-hooks (fontifying
533 defer-change defer-scroll defer-context)
534 ;;
535 ;; Add hook if lazy-lock.el is fontifying on scrolling or is deferring.
536 (when (or fontifying defer-change defer-scroll defer-context)
537 (make-local-hook 'window-scroll-functions)
538 (add-hook 'window-scroll-functions (if defer-scroll
539 'lazy-lock-defer-after-scroll
540 'lazy-lock-fontify-after-scroll)
541 nil t))
542 ;;
543 ;; Add hook if lazy-lock.el is fontifying and is not deferring changes.
544 (when (and fontifying (not defer-change) (not defer-context))
545 (make-local-hook 'before-change-functions)
546 (add-hook 'before-change-functions 'lazy-lock-arrange-before-change nil t))
547 ;;
548 ;; Replace Font Lock mode hook.
549 (remove-hook 'after-change-functions 'font-lock-after-change-function t)
550 (add-hook 'after-change-functions
551 (cond ((and defer-change defer-context)
552 'lazy-lock-defer-rest-after-change)
553 (defer-change
554 'lazy-lock-defer-line-after-change)
555 (defer-context
556 'lazy-lock-fontify-rest-after-change)
557 (t
558 'lazy-lock-fontify-line-after-change))
559 nil t)
560 ;;
561 ;; Add package-specific hook.
562 (make-local-hook 'outline-view-change-hook)
563 (add-hook 'outline-view-change-hook 'lazy-lock-fontify-after-outline nil t))
564
565 (defun lazy-lock-install-timers (dtime stime)
566 ;; Schedule or re-schedule the deferral and stealth timers.
567 ;; The layout of `lazy-lock-timers' is:
568 ;; ((DEFER-TIME . DEFER-TIMER) (STEALTH-TIME . STEALTH-TIMER)
569 ;; If an idle timeout has changed, cancel the existing idle timer (if there
570 ;; is one) and schedule a new one (if the new idle timeout is non-nil).
571 (unless (eq dtime (car (car lazy-lock-timers)))
572 (let ((defer (car lazy-lock-timers)))
573 (when (cdr defer)
574 (cancel-timer (cdr defer)))
575 (setcar lazy-lock-timers (cons dtime (and dtime
576 (run-with-idle-timer dtime t 'lazy-lock-fontify-after-defer))))))
577 (unless (eq stime (car (cdr lazy-lock-timers)))
578 (let ((stealth (cdr lazy-lock-timers)))
579 (when (cdr stealth)
580 (cancel-timer (cdr stealth)))
581 (setcdr lazy-lock-timers (cons stime (and stime
582 (run-with-idle-timer stime t 'lazy-lock-fontify-after-idle)))))))
583
584 (defun lazy-lock-unstall ()
585 ;;
586 ;; If Font Lock mode is still enabled, make sure that the buffer is
587 ;; fontified, and reinstall its hook. We must do this first.
588 (when font-lock-mode
589 (when (lazy-lock-unfontified-p)
590 (let ((verbose (if (numberp font-lock-verbose)
591 (> (buffer-size) font-lock-verbose)
592 font-lock-verbose)))
593 (if verbose (message "Fontifying %s..." (buffer-name)))
594 ;; Make sure we fontify etc. in the whole buffer.
595 (save-restriction
596 (widen)
597 (lazy-lock-fontify-region (point-min) (point-max)))
598 (if verbose (message "Fontifying %s...%s" (buffer-name)
599 (if (lazy-lock-unfontified-p) "quit" "done")))))
600 (add-hook 'after-change-functions 'font-lock-after-change-function nil t))
601 ;;
602 ;; Remove the text properties.
603 (lazy-lock-after-unfontify-buffer)
604 ;;
605 ;; Remove the fontification hooks.
606 (remove-hook 'window-scroll-functions 'lazy-lock-fontify-after-scroll t)
607 (remove-hook 'window-scroll-functions 'lazy-lock-defer-after-scroll t)
608 (remove-hook 'before-change-functions 'lazy-lock-arrange-before-change t)
609 (remove-hook 'after-change-functions 'lazy-lock-fontify-line-after-change t)
610 (remove-hook 'after-change-functions 'lazy-lock-fontify-rest-after-change t)
611 (remove-hook 'after-change-functions 'lazy-lock-defer-line-after-change t)
612 (remove-hook 'after-change-functions 'lazy-lock-defer-rest-after-change t)
613 (remove-hook 'outline-view-change-hook 'lazy-lock-fontify-after-outline t))
614 \f
615 ;; Hook functions.
616
617 ;; Lazy Lock mode intervenes when (1) a previously invisible buffer region
618 ;; becomes visible, i.e., for demand- or defer-driven on-the-scroll
619 ;; fontification, (2) a buffer modification occurs, i.e., for defer-driven
620 ;; on-the-fly fontification, (3) Emacs becomes idle, i.e., for fontification of
621 ;; deferred fontification and stealth fontification, and (4) other special
622 ;; occasions.
623
624 ;; 1. There are three ways whereby this can happen.
625 ;;
626 ;; (a) Scrolling the window, either explicitly (e.g., `scroll-up') or
627 ;; implicitly (e.g., `search-forward'). Here, `window-start' changes.
628 ;; Fontification occurs by adding `lazy-lock-fontify-after-scroll' (for
629 ;; demand-driven fontification) or `lazy-lock-defer-after-scroll' (for
630 ;; defer-driven fontification) to the hook `window-scroll-functions'.
631
632 (defun lazy-lock-fontify-after-scroll (window window-start)
633 ;; Called from `window-scroll-functions'.
634 ;; Fontify WINDOW from WINDOW-START following the scroll. We cannot use
635 ;; `window-end' so we work out what it would be via `vertical-motion'.
636 (save-excursion
637 (goto-char window-start)
638 (vertical-motion (window-height window) window)
639 (lazy-lock-fontify-region window-start (point)))
640 ;; A prior deletion that did not cause scrolling, followed by a scroll, would
641 ;; result in an unnecessary trigger after this if we did not cancel it now.
642 (set-window-redisplay-end-trigger window nil))
643
644 (defun lazy-lock-defer-after-scroll (window window-start)
645 ;; Called from `window-scroll-functions'.
646 ;; Defer fontification following the scroll. Save the current buffer so that
647 ;; we subsequently fontify in all windows showing the buffer.
648 (unless (memq (current-buffer) lazy-lock-buffers)
649 (push (current-buffer) lazy-lock-buffers))
650 ;; A prior deletion that did not cause scrolling, followed by a scroll, would
651 ;; result in an unnecessary trigger after this if we did not cancel it now.
652 (set-window-redisplay-end-trigger window nil))
653
654 ;; (b) Resizing the window, either explicitly (e.g., `enlarge-window') or
655 ;; implicitly (e.g., `delete-other-windows'). Here, `window-end' changes.
656 ;; Fontification occurs by adding `lazy-lock-fontify-after-resize' to the
657 ;; hook `window-size-change-functions'.
658
659 (defun lazy-lock-fontify-after-resize (frame)
660 ;; Called from `window-size-change-functions'.
661 ;; Fontify windows in FRAME following the resize. We cannot use
662 ;; `window-start' or `window-end' so we fontify conservatively.
663 (save-excursion
664 (save-selected-window
665 (select-frame frame)
666 (walk-windows (function (lambda (window)
667 (set-buffer (window-buffer window))
668 (when lazy-lock-mode
669 (lazy-lock-fontify-conservatively window))
670 (set-window-redisplay-end-trigger window nil)))
671 'nomini frame))))
672
673 ;; (c) Deletion in the buffer. Here, a `window-end' marker can become visible.
674 ;; Fontification occurs by adding `lazy-lock-arrange-before-change' to
675 ;; `before-change-functions' and `lazy-lock-fontify-after-trigger' to the
676 ;; hook `redisplay-end-trigger-functions'. Before every deletion, the
677 ;; marker `window-redisplay-end-trigger' position is set to the soon-to-be
678 ;; changed `window-end' position. If the marker becomes visible,
679 ;; `lazy-lock-fontify-after-trigger' gets called. Ouch. Note that we only
680 ;; have to deal with this eventuality if there is no on-the-fly deferral.
681
682 (defun lazy-lock-arrange-before-change (beg end)
683 ;; Called from `before-change-functions'.
684 ;; Arrange that if text becomes visible it will be fontified (if a deletion
685 ;; is pending, text might become visible at the bottom).
686 (unless (eq beg end)
687 (let ((windows (get-buffer-window-list (current-buffer) 'nomini t)) window)
688 (while windows
689 (setq window (car windows))
690 (unless (markerp (window-redisplay-end-trigger window))
691 (set-window-redisplay-end-trigger window (make-marker)))
692 (set-marker (window-redisplay-end-trigger window) (window-end window))
693 (setq windows (cdr windows))))))
694
695 (defun lazy-lock-fontify-after-trigger (window trigger-point)
696 ;; Called from `redisplay-end-trigger-functions'.
697 ;; Fontify WINDOW from TRIGGER-POINT. We cannot use `window-end' so we work
698 ;; out what it would be via `vertical-motion'.
699 ;; We could probably just use `lazy-lock-fontify-after-scroll' without loss:
700 ;; (lazy-lock-fontify-after-scroll window (window-start window))
701 (save-excursion
702 (goto-char (window-start window))
703 (vertical-motion (window-height window) window)
704 (lazy-lock-fontify-region trigger-point (point))))
705
706 ;; 2. Modified text must be marked as unfontified so it can be identified and
707 ;; fontified later when Emacs is idle. Deferral occurs by adding one of
708 ;; `lazy-lock-fontify-*-after-change' (for on-the-fly fontification) or
709 ;; `lazy-lock-defer-*-after-change' (for deferred fontification) to the
710 ;; hook `after-change-functions'.
711
712 (defalias 'lazy-lock-fontify-line-after-change
713 ;; Called from `after-change-functions'.
714 ;; Fontify the current change.
715 'font-lock-after-change-function)
716
717 (defun lazy-lock-fontify-rest-after-change (beg end old-len)
718 ;; Called from `after-change-functions'.
719 ;; Fontify the current change and defer fontification of the rest of the
720 ;; buffer. Save the current buffer so that we subsequently fontify in all
721 ;; windows showing the buffer.
722 (lazy-lock-fontify-line-after-change beg end old-len)
723 (save-buffer-state nil
724 (unless (memq (current-buffer) lazy-lock-buffers)
725 (push (current-buffer) lazy-lock-buffers))
726 (remove-text-properties end (point-max) '(lazy-lock nil))))
727
728 (defun lazy-lock-defer-line-after-change (beg end old-len)
729 ;; Called from `after-change-functions'.
730 ;; Defer fontification of the current change. Save the current buffer so
731 ;; that we subsequently fontify in all windows showing the buffer.
732 (save-buffer-state nil
733 (unless (memq (current-buffer) lazy-lock-buffers)
734 (push (current-buffer) lazy-lock-buffers))
735 (remove-text-properties (max (1- beg) (point-min))
736 (min (1+ end) (point-max))
737 '(lazy-lock nil))))
738
739 (defun lazy-lock-defer-rest-after-change (beg end old-len)
740 ;; Called from `after-change-functions'.
741 ;; Defer fontification of the rest of the buffer. Save the current buffer so
742 ;; that we subsequently fontify in all windows showing the buffer.
743 (save-buffer-state nil
744 (unless (memq (current-buffer) lazy-lock-buffers)
745 (push (current-buffer) lazy-lock-buffers))
746 (remove-text-properties (max (1- beg) (point-min))
747 (point-max)
748 '(lazy-lock nil))))
749
750 ;; 3. Deferred fontification and stealth fontification are done from these two
751 ;; functions. They are set up as Idle Timers.
752
753 (defun lazy-lock-fontify-after-defer ()
754 ;; Called from `timer-idle-list'.
755 ;; Fontify all windows where deferral has occurred for its buffer.
756 (while (and lazy-lock-buffers (not (input-pending-p)))
757 (let ((windows (get-buffer-window-list (car lazy-lock-buffers) 'nomini t)))
758 (while windows
759 (lazy-lock-fontify-window (car windows))
760 (setq windows (cdr windows)))
761 (setq lazy-lock-buffers (cdr lazy-lock-buffers))))
762 ;; Add hook if fontification should now be defer-driven in this buffer.
763 (when (and lazy-lock-mode lazy-lock-defer-on-scrolling
764 (memq 'lazy-lock-fontify-after-scroll window-scroll-functions)
765 (not (or (input-pending-p) (lazy-lock-unfontified-p))))
766 (remove-hook 'window-scroll-functions 'lazy-lock-fontify-after-scroll t)
767 (add-hook 'window-scroll-functions 'lazy-lock-defer-after-scroll nil t)))
768
769 (defun lazy-lock-fontify-after-idle ()
770 ;; Called from `timer-idle-list'.
771 ;; Fontify all buffers that need it, stealthily while idle.
772 (unless (or executing-kbd-macro (window-minibuffer-p (selected-window)))
773 ;; Loop over all buffers, fontify stealthily for each if necessary.
774 (let ((buffers (buffer-list)) (continue t) message message-log-max)
775 (save-excursion
776 (do-while (and buffers continue)
777 (set-buffer (car buffers))
778 (if (not (and lazy-lock-mode (lazy-lock-unfontified-p)))
779 (setq continue (not (input-pending-p)))
780 ;; Fontify regions in this buffer while there is no input.
781 (do-while (and (lazy-lock-unfontified-p) continue)
782 (if (and lazy-lock-stealth-load
783 (> (car (load-average)) lazy-lock-stealth-load))
784 ;; Wait a while before continuing with the loop.
785 (progn
786 (when message
787 (message "Fontifying stealthily...suspended")
788 (setq message nil))
789 (setq continue (sit-for (or lazy-lock-stealth-time 30))))
790 ;; Fontify a chunk.
791 (when lazy-lock-stealth-verbose
792 (if message
793 (message "Fontifying stealthily... %2d%% of %s"
794 (lazy-lock-percent-fontified) (buffer-name))
795 (message "Fontifying stealthily...")
796 (setq message t)))
797 (lazy-lock-fontify-chunk)
798 (setq continue (sit-for (or lazy-lock-stealth-nice 0))))))
799 (setq buffers (cdr buffers))))
800 (when message
801 (message "Fontifying stealthily...%s" (if continue "done" "quit"))))))
802
803 ;; 4. Special circumstances.
804
805 (defun lazy-lock-fontify-after-outline ()
806 ;; Called from `outline-view-change-hook'.
807 ;; Fontify windows showing the current buffer, as its visibility has changed.
808 ;; This is a conspiracy hack between lazy-lock.el and noutline.el.
809 (let ((windows (get-buffer-window-list (current-buffer) 'nomini t)))
810 (while windows
811 (lazy-lock-fontify-conservatively (car windows))
812 (setq windows (cdr windows)))))
813
814 (defun lazy-lock-after-fontify-buffer ()
815 ;; Called from `font-lock-after-fontify-buffer'.
816 ;; Mark the current buffer as fontified.
817 ;; This is a conspiracy hack between lazy-lock.el and font-lock.el.
818 (save-buffer-state nil
819 (add-text-properties (point-min) (point-max) '(lazy-lock t))))
820
821 (defun lazy-lock-after-unfontify-buffer ()
822 ;; Called from `font-lock-after-unfontify-buffer'.
823 ;; Mark the current buffer as unfontified.
824 ;; This is a conspiracy hack between lazy-lock.el and font-lock.el.
825 (save-buffer-state nil
826 (remove-text-properties (point-min) (point-max) '(lazy-lock nil))))
827 \f
828 ;; Fontification functions.
829
830 ;; If packages want to ensure that some region of the buffer is fontified, they
831 ;; should use this function. For an example, see ps-print.el.
832 (defun lazy-lock-fontify-region (beg end)
833 ;; Fontify between BEG and END, where necessary, in the current buffer.
834 (when (setq beg (text-property-any beg end 'lazy-lock nil))
835 (save-excursion
836 (save-match-data
837 (save-buffer-state
838 ;; Ensure syntactic fontification is always correct.
839 (font-lock-beginning-of-syntax-function next)
840 ;; Find successive unfontified regions between BEG and END.
841 (condition-case data
842 (do-while beg
843 (setq next (or (text-property-any beg end 'lazy-lock t) end))
844 ;; Make sure the region end points are at beginning of line.
845 (goto-char beg)
846 (unless (bolp)
847 (beginning-of-line)
848 (setq beg (point)))
849 (goto-char next)
850 (unless (bolp)
851 (forward-line)
852 (setq next (point)))
853 ;; Fontify the region, then flag it as fontified.
854 (font-lock-fontify-region beg next)
855 (add-text-properties beg next '(lazy-lock t))
856 (setq beg (text-property-any next end 'lazy-lock nil)))
857 ((error quit) (message "Fontifying region...%s" data))))))))
858
859 (defun lazy-lock-fontify-chunk ()
860 ;; Fontify the nearest chunk, for stealth, in the current buffer.
861 (save-excursion
862 (save-restriction
863 (widen)
864 ;; Move to end of line in case the character at point is not fontified.
865 (end-of-line)
866 ;; Find where the previous, and next, unfontified regions end, and begin.
867 (let ((prev (previous-single-property-change (point) 'lazy-lock))
868 (next (text-property-any (point) (point-max) 'lazy-lock nil)))
869 ;; Fontify from the nearest unfontified position.
870 (if (or (null prev) (and next (< (- next (point)) (- (point) prev))))
871 ;; The next, or neither, region is the nearest not fontified.
872 (lazy-lock-fontify-region
873 (progn (goto-char (or next (point-min)))
874 (beginning-of-line)
875 (point))
876 (progn (goto-char (or next (point-min)))
877 (forward-line lazy-lock-stealth-lines)
878 (point)))
879 ;; The previous region is the nearest not fontified.
880 (lazy-lock-fontify-region
881 (progn (goto-char prev)
882 (forward-line (- lazy-lock-stealth-lines))
883 (point))
884 (progn (goto-char prev)
885 (forward-line)
886 (point))))))))
887
888 (defun lazy-lock-fontify-window (window)
889 ;; Fontify in WINDOW between `window-start' and `window-end'.
890 ;; We can only do this when we can use `window-start' and `window-end'.
891 (with-current-buffer (window-buffer window)
892 (lazy-lock-fontify-region (window-start window) (window-end window))))
893
894 (defun lazy-lock-fontify-conservatively (window)
895 ;; Fontify in WINDOW conservatively around point.
896 ;; Where we cannot use `window-start' and `window-end' we do `window-height'
897 ;; lines around point. That way we guarantee to have done enough.
898 (with-current-buffer (window-buffer window)
899 (lazy-lock-fontify-region
900 (save-excursion
901 (goto-char (window-point window))
902 (vertical-motion (- (window-height window)) window) (point))
903 (save-excursion
904 (goto-char (window-point window))
905 (vertical-motion (window-height window) window) (point)))))
906
907 (defun lazy-lock-unfontified-p ()
908 ;; Return non-nil if there is anywhere still to be fontified.
909 (save-restriction
910 (widen)
911 (text-property-any (point-min) (point-max) 'lazy-lock nil)))
912
913 (defun lazy-lock-percent-fontified ()
914 ;; Return the percentage (of characters) of the buffer that are fontified.
915 (save-restriction
916 (widen)
917 (let ((beg (point-min)) (size 0) next)
918 ;; Find where the next fontified region begins.
919 (while (setq beg (text-property-any beg (point-max) 'lazy-lock t))
920 (setq next (or (text-property-any beg (point-max) 'lazy-lock nil)
921 (point-max)))
922 (incf size (- next beg))
923 (setq beg next))
924 ;; Float because using integer multiplication will frequently overflow.
925 (truncate (* (/ (float size) (point-max)) 100)))))
926 \f
927 ;; Version dependent workarounds and fixes.
928
929 (when (if (save-match-data (string-match "Lucid\\|XEmacs" (emacs-version)))
930 nil
931 (and (= emacs-major-version 19) (= emacs-minor-version 30)))
932 ;;
933 ;; We use `post-command-idle-hook' for deferral and stealth. Oh Lordy.
934 (defun lazy-lock-install-timers (foo bar)
935 (add-hook 'post-command-idle-hook 'lazy-lock-fontify-post-command t)
936 (add-hook 'post-command-idle-hook 'lazy-lock-fontify-post-idle t)
937 (add-to-list 'lazy-lock-install (current-buffer))
938 (add-hook 'post-command-hook 'lazy-lock-fontify-after-install))
939 (defun lazy-lock-fontify-post-command ()
940 (and lazy-lock-buffers (not executing-kbd-macro)
941 (progn
942 (and deactivate-mark (deactivate-mark))
943 (sit-for
944 (or (cdr-safe lazy-lock-defer-time) lazy-lock-defer-time 0)))
945 (lazy-lock-fontify-after-defer)))
946 (defun lazy-lock-fontify-post-idle ()
947 (and lazy-lock-stealth-time (not executing-kbd-macro)
948 (not (window-minibuffer-p (selected-window)))
949 (progn
950 (and deactivate-mark (deactivate-mark))
951 (sit-for lazy-lock-stealth-time))
952 (lazy-lock-fontify-after-idle)))
953 ;;
954 ;; Simulate running of `window-scroll-functions' in `set-window-buffer'.
955 (defvar lazy-lock-install nil)
956 (defun lazy-lock-fontify-after-install ()
957 (remove-hook 'post-command-hook 'lazy-lock-fontify-after-install)
958 (while lazy-lock-install
959 (mapcar 'lazy-lock-fontify-conservatively
960 (get-buffer-window-list (pop lazy-lock-install) 'nomini t)))))
961
962 (when (consp lazy-lock-defer-time)
963 ;;
964 ;; In 2.06.04 and below, `lazy-lock-defer-time' could specify modes and time.
965 (with-output-to-temp-buffer "*Help*"
966 (princ "The value of the variable `lazy-lock-defer-time' was\n ")
967 (princ lazy-lock-defer-time)
968 (princ "\n")
969 (princ "This variable cannot now be a list of modes and time, ")
970 (princ "so instead use the forms:\n")
971 (princ " (setq lazy-lock-defer-time ")
972 (princ (cdr lazy-lock-defer-time))
973 (princ ")\n")
974 (princ " (setq lazy-lock-defer-on-the-fly '")
975 (princ (car lazy-lock-defer-time))
976 (princ ")\n")
977 (princ "in your ~/.emacs. ")
978 (princ "The above forms have been evaluated for this editor session,\n")
979 (princ "but you should change your ~/.emacs now."))
980 (setq lazy-lock-defer-on-the-fly (car lazy-lock-defer-time)
981 lazy-lock-defer-time (cdr lazy-lock-defer-time)))
982
983 (when (boundp 'lazy-lock-defer-driven)
984 ;;
985 ;; In 2.06.04 and below, `lazy-lock-defer-driven' was the variable name.
986 (with-output-to-temp-buffer "*Help*"
987 (princ "The value of the variable `lazy-lock-defer-driven' is set to ")
988 (if (memq lazy-lock-defer-driven '(nil t))
989 (princ lazy-lock-defer-driven)
990 (princ "`")
991 (princ lazy-lock-defer-driven)
992 (princ "'"))
993 (princ ".\n")
994 (princ "This variable is now called `lazy-lock-defer-on-scrolling',\n")
995 (princ "so instead use the form:\n")
996 (princ " (setq lazy-lock-defer-on-scrolling ")
997 (unless (memq lazy-lock-defer-driven '(nil t))
998 (princ "'"))
999 (princ lazy-lock-defer-driven)
1000 (princ ")\n")
1001 (princ "in your ~/.emacs. ")
1002 (princ "The above form has been evaluated for this editor session,\n")
1003 (princ "but you should change your ~/.emacs now."))
1004 (setq lazy-lock-defer-on-scrolling lazy-lock-defer-driven))
1005 \f
1006 ;; Possibly absent.
1007
1008 (unless (boundp 'font-lock-inhibit-thing-lock)
1009 ;; Font Lock mode uses this to direct Lazy and Fast Lock modes to stay off.
1010 (defvar font-lock-inhibit-thing-lock nil
1011 "List of Font Lock mode related modes that should not be turned on."))
1012
1013 (unless (fboundp 'font-lock-value-in-major-mode)
1014 (defun font-lock-value-in-major-mode (alist)
1015 ;; Return value in ALIST for `major-mode'.
1016 (if (consp alist)
1017 (cdr (or (assq major-mode alist) (assq t alist)))
1018 alist)))
1019
1020 (unless (fboundp 'get-buffer-window-list)
1021 ;; We use this to get all windows showing a buffer we have to fontify.
1022 (defun get-buffer-window-list (buffer &optional minibuf frame)
1023 "Return windows currently displaying BUFFER, or nil if none."
1024 (let ((buffer (if (bufferp buffer) buffer (get-buffer buffer))) windows)
1025 (walk-windows (function (lambda (window)
1026 (when (eq (window-buffer window) buffer)
1027 (push window windows))))
1028 minibuf frame)
1029 windows)))
1030 \f
1031 ;; Install ourselves:
1032
1033 (add-hook 'window-size-change-functions 'lazy-lock-fontify-after-resize)
1034 (add-hook 'redisplay-end-trigger-functions 'lazy-lock-fontify-after-trigger)
1035
1036 (unless (assq 'lazy-lock-mode minor-mode-alist)
1037 (setq minor-mode-alist (append minor-mode-alist '((lazy-lock-mode nil)))))
1038
1039 ;; Provide ourselves:
1040
1041 (provide 'lazy-lock)
1042
1043 ;;; lazy-lock.el ends here