annotate lisp/lazy-lock.el @ 16297:701db778b7a4

(Fwindow_edges): Use new WINDOW_RIGHT_EDGE macro. (coordinates_in_window): Use WINDOW_LEFT_MARGIN, WINDOW_RIGHT_MARGIN, and WINDOW_RIGHT_EDGE. Adjust for left-side scroll bar margin. (window_loop, Fdisplay_buffer): Use new WINDOW_FULL_WIDTH_P macro. (window_internal_width): Window width now always includes the scroll bar, if any. Use WINDOW_RIGHTMOST_P and WINDOW_FULL_WIDTH_P.
author Richard M. Stallman <rms@gnu.org>
date Mon, 23 Sep 1996 04:36:43 +0000
parents aa9675ed8ed4
children f4429e6fe33c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15461
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; lazy-lock.el --- Lazy demand-driven fontification for fast Font Lock mode.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: Simon Marshall <simon@gnu.ai.mit.edu>
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Keywords: faces files
15499
aa9675ed8ed4 Test for lazy-lock-mode before swapping hooks.
Simon Marshall <simon@gnu.org>
parents: 15461
diff changeset
7 ;; Version: 2.06
15461
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;;; This file is part of GNU Emacs.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; any later version.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; Purpose:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; To make visiting buffers in `font-lock-mode' faster by making fontification
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;; be demand-driven, deferred and stealthy.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; Fontification only occurs when, and where, necessary.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;; See caveats and feedback below.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; See also the fast-lock package. (But don't use them at the same time!)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;; Installation:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;; Put in your ~/.emacs:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;;
15499
aa9675ed8ed4 Test for lazy-lock-mode before swapping hooks.
Simon Marshall <simon@gnu.org>
parents: 15461
diff changeset
41 ;; (setq font-lock-support-mode 'lazy-lock-mode)
15461
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; Start up a new Emacs and use font-lock as usual (except that you can use the
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;; so-called "gaudier" fontification regexps on big files without frustration).
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;; In a buffer (which has `font-lock-mode' enabled) which is at least
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;; `lazy-lock-minimum-size' characters long, buffer fontification will not
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;; occur and only the visible portion of the buffer will be fontified. Motion
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;; around the buffer will fontify those visible portions not previously
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;; fontified. If stealth fontification is enabled, buffer fontification will
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;; occur in invisible parts of the buffer after `lazy-lock-stealth-time'
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;; seconds of idle time. If on-the-fly fontification is deferred, on-the-fly
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;; fontification will occur after `lazy-lock-defer-time' seconds of idle time.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;; User-visible differences with version 1:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;; - Version 2 can defer on-the-fly fontification. Therefore you need not, and
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;; should not, use defer-lock.el with this version of lazy-lock.el.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;; A number of variables have changed meaning:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;; - A value of nil for the variable `lazy-lock-minimum-size' means never turn
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;; on demand-driven fontification. In version 1 this meant always turn on
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;; demand-driven fontification. If you really want demand-driven fontification
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;; regardless of buffer size, set this variable to 0.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ;; - The variable `lazy-lock-stealth-lines' cannot have a nil value. In
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 ;; version 1 this meant use `window-height' as the maximum number of lines to
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ;; fontify as a stealth chunk. This makes no sense; stealth fontification is
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 ;; of a buffer, not a window.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 ;; Implementation differences with version 1:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 ;; - Version 1 of lazy-lock.el is a bit of a hack. Version 1 demand-driven
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 ;; fontification, the core feature of lazy-lock.el, is implemented by placing a
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ;; function on `post-command-hook'. This function fontifies where necessary,
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;; i.e., where a window scroll has occurred. However, there are a number of
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ;; problems with using `post-command-hook':
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 ;; (a) As the name suggests, `post-command-hook' is run after every command,
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 ;; i.e., frequently and regardless of whether scrolling has occurred.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 ;; (b) Scrolling can occur during a command, when `post-command-hook' is not
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 ;; run, i.e., it is not necessarily run after scrolling has occurred.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 ;; (c) When `post-command-hook' is run, there is nothing to suggest where
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 ;; scrolling might have occurred, i.e., which windows have scrolled.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 ;; Thus lazy-lock.el's function is called almost as often as possible, usually
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 ;; when it need not be called, yet it is not always called when it is needed.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 ;; Also, lazy-lock.el's function must check each window to see if a scroll has
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 ;; occurred there. Worse still, lazy-lock.el's function must fontify a region
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 ;; twice as large as necessary to make sure the window is completely fontified.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 ;; Basically, `post-command-hook' is completely inappropriate for lazy-lock.el.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 ;; Ideally, we want to attach lazy-lock.el's function to a hook that is run
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 ;; only when scrolling occurs, e.g., `window-start' has changed, and tells us
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 ;; as much information as we need, i.e., the window and its new buffer region.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 ;; Richard Stallman implemented a `window-scroll-functions' for Emacs 19.30.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 ;; Functions on it are run when `window-start' has changed, and are supplied
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 ;; with the window and the window's new `window-start' position. (It would be
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 ;; better if it also supplied the window's new `window-end' position, but that
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 ;; is calculated as part of the redisplay process, and the functions on
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 ;; `window-scroll-functions' are run before redisplay has finished.) Thus, the
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 ;; hook deals with the above problems (a), (b) and (c).
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 ;; If only life was that easy. Version 2 demand-driven fontification is mostly
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 ;; implemented by placing a function on `window-scroll-functions'. However,
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 ;; not all scrolling occurs when `window-start' has changed. A change in
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 ;; window size, e.g., via C-x 1, or a significant deletion, e.g., of a number
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 ;; of lines, causes `window-end' to change without changing `window-start'.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 ;; Arguably, these events are not scrolling events, but fontification must
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 ;; occur for lazy-lock.el to work. Hooks `window-size-change-functions' and
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 ;; `redisplay-end-trigger-functions' were added for these circumstances.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 ;; Ben Wing thinks these hooks are "horribly horribly kludgy", and implemented
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 ;; a `pre-idle-hook', a `mother-of-all-post-command-hooks', for XEmacs 19.14.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 ;; He then hacked up a version 1 lazy-lock.el to use `pre-idle-hook' rather
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 ;; than `post-command-hook'. Whereas functions on `post-command-hook' are
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 ;; called almost as often as possible, functions on `pre-idle-hook' really are
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 ;; called as often as possible, even when the mouse moves and, on some systems,
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 ;; while XEmacs is idle. Thus, the hook deals with the above problem (b), but
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 ;; unfortunately it makes (a) worse and does not address (c) at all.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 ;; I freely admit that `redisplay-end-trigger-functions' and, to a much lesser
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 ;; extent, `window-size-change-functions' are not pretty. However, I feel that
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 ;; a `window-scroll-functions' feature is cleaner than a `pre-idle-hook', and
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 ;; the result is faster and smaller, less intrusive and more targeted, code.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 ;; Since `pre-idle-hook' is pretty much like `post-command-hook', there is no
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 ;; point in making this version of lazy-lock.el work with it. Anyway, that's
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 ;; Lit 30 of my humble opinion.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 ;; - Version 1 stealth fontification is also implemented by placing a function
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 ;; on `post-command-hook'. This function waits for a given amount of time,
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 ;; and, if Emacs remains idle, fontifies where necessary. Again, there are a
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 ;; number of problems with using `post-command-hook':
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 ;; (a) Functions on `post-command-hook' are run sequentially, so this function
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 ;; can interfere with other functions on the hook, and vice versa.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 ;; (b) This function waits for a given amount of time, so it can interfere with
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 ;; various features that are dealt with by Emacs after a command, e.g.,
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 ;; region highlighting, asynchronous updating and keystroke echoing.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 ;; (c) Fontification may be required during a command, when `post-command-hook'
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 ;; is not run. (Version 2 deferred fontification only.)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 ;; Again, `post-command-hook' is completely inappropriate for lazy-lock.el.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 ;; Richard Stallman and Morten Welinder implemented internal Timers and Idle
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 ;; Timers for Emacs 19.31. Functions can be run independently at given times
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 ;; or after given amounts of idle time. Thus, the feature deals with the above
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 ;; problems (a), (b) and (c). Version 2 deferral and stealth are implemented
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 ;; by functions on Idle Timers. (A function on XEmacs' `pre-idle-hook' is
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 ;; similar to an Emacs Idle Timer function with a fixed zero second timeout.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 ;; Hey, maybe I could stop using `window-scroll-functions' for demand-driven
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 ;; fontification and use a zero second Emacs Idle Timer instead? Only joking!)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 ;; Caveats:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 ;; Lazy Lock mode does not work efficiently with Outline mode. This is because
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 ;; when in Outline mode, although text may be hidden (not visible in the
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 ;; window), the text is visible to Emacs Lisp code (not surprisingly) and Lazy
15499
aa9675ed8ed4 Test for lazy-lock-mode before swapping hooks.
Simon Marshall <simon@gnu.org>
parents: 15461
diff changeset
159 ;; Lock fontifies it mercilessly. Maybe it will be fixed one day.
15461
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 ;; Because buffer text is not necessarily fontified, other packages that expect
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 ;; buffer text to be fontified in Font Lock mode either might not work as
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 ;; expected, or might not display buffer text as expected. An example of the
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 ;; latter is `occur', which copies lines of buffer text into another buffer.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 ;; In Emacs 19.30, Lazy Lock mode does not ensure that an existing buffer is
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 ;; fontified if it is made visible via a minibuffer-less command that replaces
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 ;; an existing window's buffer (e.g., via the Buffers menu). Upgrade!
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 ;; In Emacs 19.30, Lazy Lock mode does not work well with Transient Mark mode
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 ;; or modes based on Comint mode (e.g., Shell mode), and also interferes with
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 ;; the echoing of keystrokes in the minibuffer. This is because of the way
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 ;; deferral and stealth have to be implemented for Emacs 19.30. Upgrade!
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 ;;
15499
aa9675ed8ed4 Test for lazy-lock-mode before swapping hooks.
Simon Marshall <simon@gnu.org>
parents: 15461
diff changeset
175 ;; Currently XEmacs does not have the features to support this version of
aa9675ed8ed4 Test for lazy-lock-mode before swapping hooks.
Simon Marshall <simon@gnu.org>
parents: 15461
diff changeset
176 ;; lazy-lock.el. Maybe it will one day.
15461
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 ;; Feedback:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 ;; Feedback is welcome.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 ;; To submit a bug report (or make comments) please use the mechanism provided:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 ;; M-x lazy-lock-submit-bug-report RET
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 ;; History:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 ;; 1.15--2.00:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 ;; - Rewrite for Emacs 19.30 and the features rms added to support lazy-lock.el
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 ;; so that it could work correctly and efficiently.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 ;; - Many thanks to those who reported bugs, fixed bugs, made suggestions or
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 ;; otherwise contributed in the version 1 cycle; Jari Aalto, Kevin Broadey,
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 ;; Ulrik Dickow, Bill Dubuque, Bob Glickstein, Boris Goldowsky,
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 ;; Jonas Jarnestrom, David Karr, Michael Kifer, Erik Naggum, Rick Sladkey,
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 ;; Jim Thompson, Ben Wing, Ilya Zakharevich, and Richard Stallman.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 ;; 2.00--2.01:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 ;; - Made `lazy-lock-fontify-after-command' always `sit-for' and so redisplay
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 ;; - Use `buffer-name' not `buffer-live-p' (Bill Dubuque hint)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 ;; - Made `lazy-lock-install' do `add-to-list' not `setq' of `current-buffer'
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 ;; - Made `lazy-lock-fontify-after-install' loop over buffer list
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 ;; - Made `lazy-lock-arrange-before-change' to arrange `window-end' triggering
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 ;; - Made `lazy-lock-let-buffer-state' wrap both `befter-change-functions'
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 ;; - Made `lazy-lock-fontify-region' do `condition-case' (Hyman Rosen report)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 ;; 2.01--2.02:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 ;; - Use `buffer-live-p' as `buffer-name' can barf (Richard Stanton report)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 ;; - Made `lazy-lock-install' set `font-lock-fontified' (Kevin Davidson report)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 ;; - Made `lazy-lock-install' add hooks only if needed
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 ;; - Made `lazy-lock-unstall' add `font-lock-after-change-function' if needed
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 ;; 2.02--2.03:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 ;; - Made `lazy-lock-fontify-region' do `condition-case' for `quit' too
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 ;; - Made `lazy-lock-mode' respect the value of `font-lock-inhibit-thing-lock'
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 ;; - Added `lazy-lock-after-unfontify-buffer'
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 ;; - Removed `lazy-lock-fontify-after-install' hack
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 ;; - Made `lazy-lock-fontify-after-scroll' not `set-buffer' to `window-buffer'
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 ;; - Made `lazy-lock-fontify-after-trigger' not `set-buffer' to `window-buffer'
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 ;; - Made `lazy-lock-fontify-after-idle' be interruptible (Scott Burson hint)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 ;; 2.03--2.04:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 ;; - Rewrite for Emacs 19.31 idle timers
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 ;; - Renamed `buffer-windows' to `get-buffer-window-list'
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 ;; - Removed `buffer-live-p'
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 ;; - Made `lazy-lock-defer-after-change' always save `current-buffer'
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 ;; - Made `lazy-lock-fontify-after-defer' just process buffers
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 ;; - Made `lazy-lock-install-hooks' add hooks correctly (Kevin Broadey report)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 ;; - Made `lazy-lock-install' cope if `lazy-lock-defer-time' is a list
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 ;; 2.04--2.05:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 ;; - Rewrite for Common Lisp macros
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 ;; - Added `do-while' macro
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 ;; - Renamed `lazy-lock-let-buffer-state' macro to `save-buffer-state'
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 ;; - Returned `lazy-lock-fontify-after-install' hack (Darren Hall hint)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 ;; - Added `lazy-lock-defer-driven' functionality (Scott Byer hint)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 ;; - Made `lazy-lock-mode' wrap `font-lock-support-mode'
15499
aa9675ed8ed4 Test for lazy-lock-mode before swapping hooks.
Simon Marshall <simon@gnu.org>
parents: 15461
diff changeset
231 ;; 2.05--2.06:
aa9675ed8ed4 Test for lazy-lock-mode before swapping hooks.
Simon Marshall <simon@gnu.org>
parents: 15461
diff changeset
232 ;; - Made `lazy-lock-fontify-after-defer' swap correctly (Scott Byer report)
15461
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (require 'font-lock)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 ;; Make sure lazy-lock.el is supported.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (if (if (save-match-data (string-match "Lucid\\|XEmacs" (emacs-version)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 t
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 (and (= emacs-major-version 19) (< emacs-minor-version 30)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 (error "`lazy-lock' was written for Emacs 19.30 or later"))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 ;; Flush out those lusers who didn't read all of the Commentary.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (if (or (memq 'turn-on-defer-lock font-lock-mode-hook)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (memq 'defer-lock-mode font-lock-mode-hook))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (error "`lazy-lock' was written for use without `defer-lock'"))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (eval-when-compile
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 ;; We don't do this at the top-level as idle timers are not necessarily used.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (require 'timer)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 ;; We don't do this at the top-level as we only use non-autoloaded macros.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (require 'cl)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 ;; Well, shouldn't Lazy Lock mode be as lazy as possible?
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (setq byte-compile-dynamic t byte-compile-dynamic-docstrings t)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 ;; But, we make sure that the code is as zippy as can be.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (setq byte-optimize t)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 ;; We use this to preserve or protect things when modifying text properties.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 (defmacro save-buffer-state (varlist &rest body)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 "Bind variables according to VARLIST and eval BODY restoring buffer state."
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 (` (let* ((,@ (append varlist
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 '((modified (buffer-modified-p))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (inhibit-read-only t) (buffer-undo-list t)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 before-change-functions after-change-functions
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 deactivate-mark buffer-file-name buffer-file-truename))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (,@ body)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 (when (and (not modified) (buffer-modified-p))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (set-buffer-modified-p nil)))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (put 'save-buffer-state 'lisp-indent-function 1)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 ;; We use this for clarity and speed. Naughty but nice.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (defmacro do-while (test &rest body)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 "(do-while TEST BODY...): eval BODY... and repeat if TEST yields non-nil.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 The order of execution is thus BODY, TEST, BODY, TEST and so on
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 until TEST returns nil."
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (` (while (progn (,@ body) (, test)))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (put 'do-while 'lisp-indent-function (get 'while 'lisp-indent-function)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 ;; User Variables:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 (defvar lazy-lock-minimum-size (* 25 1024)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 "*Minimum size of a buffer for demand-driven fontification.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 On-demand fontification occurs if the buffer size is greater than this value.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 If nil, means demand-driven fontification is never performed.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 If a list, each element should be a cons pair of the form (MAJOR-MODE . SIZE),
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 where MAJOR-MODE is a symbol or t (meaning the default). For example:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 ((c-mode . 25600) (c++-mode . 25600) (rmail-mode . 1048576))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 means that the minimum size is 25K for buffers in C or C++ modes, one megabyte
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 for buffers in Rmail mode, and size is irrelevant otherwise.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 The value of this variable is used when Lazy Lock mode is turned on.")
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 (defvar lazy-lock-defer-driven nil
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 "*If non-nil, means fontification should be defer-driven.
15499
aa9675ed8ed4 Test for lazy-lock-mode before swapping hooks.
Simon Marshall <simon@gnu.org>
parents: 15461
diff changeset
296 If nil, means demand-driven fontification is performed. This means when
aa9675ed8ed4 Test for lazy-lock-mode before swapping hooks.
Simon Marshall <simon@gnu.org>
parents: 15461
diff changeset
297 scrolling into unfontified areas of the buffer, those areas are immediately
aa9675ed8ed4 Test for lazy-lock-mode before swapping hooks.
Simon Marshall <simon@gnu.org>
parents: 15461
diff changeset
298 fontified. Thus scrolling never presents unfontified areas. However, since
aa9675ed8ed4 Test for lazy-lock-mode before swapping hooks.
Simon Marshall <simon@gnu.org>
parents: 15461
diff changeset
299 fontification occurs during scrolling, scrolling may be slow.
15461
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 If t, means defer-driven fontification is performed. This means fontification
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 of those areas is deferred. Thus scrolling may present momentarily unfontified
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 areas. However, since fontification does not occur during scrolling, scrolling
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 will be faster than demand-driven fontification.
15499
aa9675ed8ed4 Test for lazy-lock-mode before swapping hooks.
Simon Marshall <simon@gnu.org>
parents: 15461
diff changeset
304 If any other value, e.g., `eventually', means demand-driven fontification is
aa9675ed8ed4 Test for lazy-lock-mode before swapping hooks.
Simon Marshall <simon@gnu.org>
parents: 15461
diff changeset
305 performed until the buffer is fontified, then buffer fontification becomes
aa9675ed8ed4 Test for lazy-lock-mode before swapping hooks.
Simon Marshall <simon@gnu.org>
parents: 15461
diff changeset
306 defer-driven. Thus scrolling never presents unfontified areas until the buffer
aa9675ed8ed4 Test for lazy-lock-mode before swapping hooks.
Simon Marshall <simon@gnu.org>
parents: 15461
diff changeset
307 is first fontified, after which subsequent scrolling may present future buffer
aa9675ed8ed4 Test for lazy-lock-mode before swapping hooks.
Simon Marshall <simon@gnu.org>
parents: 15461
diff changeset
308 insertions momentarily unfontified. However, since fontification does not
aa9675ed8ed4 Test for lazy-lock-mode before swapping hooks.
Simon Marshall <simon@gnu.org>
parents: 15461
diff changeset
309 occur during scrolling after the buffer is first fontified, scrolling will
aa9675ed8ed4 Test for lazy-lock-mode before swapping hooks.
Simon Marshall <simon@gnu.org>
parents: 15461
diff changeset
310 become faster.
15461
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 The value of this variable is used when Lazy Lock mode is turned on.")
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 (defvar lazy-lock-defer-time
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 (if (featurep 'lisp-float-type) (/ (float 1) (float 4)) 1)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 "*Time in seconds to delay before beginning deferred fontification.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 Deferred fontification occurs if there is no input within this time.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 If nil, means fontification is never deferred. However, fontification occurs
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 on-the-fly or during scrolling, which may be slow.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 If a list, it should be of the form (MAJOR-MODES . TIME), where MAJOR-MODES is
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 a list of `major-mode' symbols for which deferred fontification should occur.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 The sense of the list is negated if it begins with `not'. For example:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 ((c-mode c++-mode) . 0.25)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 means that the deferral time is 0.25s for buffers in C or C++ modes, and
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 deferral does not occur otherwise.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 The value of this variable is used when Lazy Lock mode is turned on.")
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (defvar lazy-lock-stealth-time 30
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 "*Time in seconds to delay before beginning stealth fontification.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 Stealth fontification occurs if there is no input within this time.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 If nil, means stealth fontification is never performed.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 The value of this variable is used when Lazy Lock mode is turned on.")
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335
15499
aa9675ed8ed4 Test for lazy-lock-mode before swapping hooks.
Simon Marshall <simon@gnu.org>
parents: 15461
diff changeset
336 (defvar lazy-lock-stealth-lines (if font-lock-maximum-decoration 100 250)
15461
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 "*Maximum size of a chunk of stealth fontification.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 Each iteration of stealth fontification can fontify this number of lines.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 To speed up input response during stealth fontification, at the cost of stealth
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 taking longer to fontify, you could reduce the value of this variable.")
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 (defvar lazy-lock-stealth-nice
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 (if (featurep 'lisp-float-type) (/ (float 1) (float 8)) 1)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 "*Time in seconds to pause between chunks of stealth fontification.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 Each iteration of stealth fontification is separated by this amount of time.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 To reduce machine load during stealth fontification, at the cost of stealth
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 taking longer to fontify, you could increase the value of this variable.")
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348
15499
aa9675ed8ed4 Test for lazy-lock-mode before swapping hooks.
Simon Marshall <simon@gnu.org>
parents: 15461
diff changeset
349 (defvar lazy-lock-stealth-verbose (not (null font-lock-verbose))
15461
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 "*If non-nil, means stealth fontification should show status messages.")
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 (defvar lazy-lock-mode nil)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 (defvar lazy-lock-buffers nil) ; for deferral
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 (defvar lazy-lock-timers (cons nil nil)) ; for deferral and stealth
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 ;; User Functions:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 ;;;###autoload
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 (defun lazy-lock-mode (&optional arg)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 "Toggle Lazy Lock mode.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 With arg, turn Lazy Lock mode on if and only if arg is positive. Enable it
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 automatically in your `~/.emacs' by:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 (setq font-lock-support-mode 'lazy-lock-mode)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 When Lazy Lock mode is enabled, fontification can be lazy in a number of ways:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 - Demand-driven buffer fontification if `lazy-lock-minimum-size' is non-nil.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 This means initial fontification does not occur if the buffer is greater
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 than `lazy-lock-minimum-size' characters in length. Instead, fontification
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 occurs when necessary, such as when scrolling through the buffer would
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 otherwise reveal unfontified areas. This is useful if buffer fontification
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 is too slow for large buffers.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 - Defer-driven buffer fontification if `lazy-lock-defer-driven' is non-nil.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 This means all fontification is deferred, such as fontification that occurs
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 when scrolling through the buffer would otherwise reveal unfontified areas.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 Instead, these areas are seen momentarily unfontified. This is useful if
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 demand-driven fontification is too slow to keep up with scrolling.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 - Deferred on-the-fly fontification if `lazy-lock-defer-time' is non-nil.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 This means on-the-fly fontification does not occur as you type. Instead,
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 fontification is deferred until after `lazy-lock-defer-time' seconds of
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 Emacs idle time, while Emacs remains idle. This is useful if on-the-fly
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 fontification is too slow to keep up with your typing.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 - Stealthy buffer fontification if `lazy-lock-stealth-time' is non-nil.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 This means remaining unfontified areas of buffers are fontified if Emacs has
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 been idle for `lazy-lock-stealth-time' seconds, while Emacs remains idle.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 This is useful if any buffer has demand- or defer-driven fontification.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 See also variables `lazy-lock-stealth-lines', `lazy-lock-stealth-nice' and
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 `lazy-lock-stealth-verbose' for stealth fontification.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 Use \\[lazy-lock-submit-bug-report] to send bug reports or feedback."
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 (interactive "P")
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 (set (make-local-variable 'lazy-lock-mode)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 (and (not (memq 'lazy-lock-mode font-lock-inhibit-thing-lock))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 (if arg (> (prefix-numeric-value arg) 0) (not lazy-lock-mode))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 (cond ((and lazy-lock-mode (not font-lock-mode))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 ;; Turned on `lazy-lock-mode' rather than `font-lock-mode'.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 (let ((font-lock-support-mode 'lazy-lock-mode))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 (font-lock-mode t)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 (lazy-lock-mode
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 ;; Turn ourselves on.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 (lazy-lock-install))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 (t
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 ;; Turn ourselves off.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 (lazy-lock-unstall))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 (defun lazy-lock-submit-bug-report ()
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 "Submit via mail a bug report on lazy-lock.el."
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 (interactive)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 (let ((reporter-prompt-for-summary-p t))
15499
aa9675ed8ed4 Test for lazy-lock-mode before swapping hooks.
Simon Marshall <simon@gnu.org>
parents: 15461
diff changeset
415 (reporter-submit-bug-report "simon@gnu.ai.mit.edu" "lazy-lock 2.06"
15461
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 '(lazy-lock-minimum-size lazy-lock-defer-driven lazy-lock-defer-time
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 lazy-lock-stealth-time lazy-lock-stealth-nice lazy-lock-stealth-lines
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 lazy-lock-stealth-verbose)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 nil nil
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 (concat "Hi Si.,
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 I want to report a bug. I've read the `Bugs' section of `Info' on Emacs, so I
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 know how to make a clear and unambiguous report. To reproduce the bug:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 Start a fresh Emacs via `" invocation-name " -no-init-file -no-site-file'.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 In the `*scratch*' buffer, evaluate:"))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 ;;;###autoload
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 (defun turn-on-lazy-lock ()
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 "Unconditionally turn on Lazy Lock mode."
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 (lazy-lock-mode t))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 (defun lazy-lock-install ()
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 (let ((min-size (font-lock-value-in-major-mode lazy-lock-minimum-size)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 ;; Tell Font Lock whether Lazy Lock will do fontification.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 (make-local-variable 'font-lock-fontified)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 (setq font-lock-fontified (and min-size (>= (buffer-size) min-size)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 ;; Add the text properties and fontify.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 (if (not font-lock-fontified)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 (lazy-lock-after-fontify-buffer)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 ;; Make sure we fontify in any existing windows showing the buffer.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 (let ((windows (get-buffer-window-list (current-buffer) 'nomini t)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 (lazy-lock-after-unfontify-buffer)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 (while windows
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 (lazy-lock-fontify-conservatively (car windows))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 (setq windows (cdr windows)))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 ;; Add the fontification hooks.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 (lazy-lock-install-hooks
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 (or (numberp lazy-lock-defer-time)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 (if (eq (car (car lazy-lock-defer-time)) 'not)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 (not (memq major-mode (cdr (car lazy-lock-defer-time))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 (memq major-mode (car lazy-lock-defer-time))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 font-lock-fontified
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 (eq lazy-lock-defer-driven t))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 ;; Add the fontification timers.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 (lazy-lock-install-timers
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 (or (cdr-safe lazy-lock-defer-time) lazy-lock-defer-time)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 lazy-lock-stealth-time)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 (defun lazy-lock-install-hooks (deferring fontifying defer-driven)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 ;; Add hook if lazy-lock.el is deferring or is fontifying on scrolling.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 (when (or deferring fontifying)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 (make-local-hook 'window-scroll-functions)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 (add-hook 'window-scroll-functions (if (and deferring defer-driven)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 'lazy-lock-defer-after-scroll
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 'lazy-lock-fontify-after-scroll)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 nil t))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 ;; Add hook if lazy-lock.el is not deferring and is fontifying.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 (when (and (not deferring) fontifying)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 (make-local-hook 'before-change-functions)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 (add-hook 'before-change-functions 'lazy-lock-arrange-before-change nil t))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 ;; Add hook if lazy-lock.el is deferring.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 (when deferring
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481 (remove-hook 'after-change-functions 'font-lock-after-change-function t)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 (add-hook 'after-change-functions 'lazy-lock-defer-after-change nil t))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 ;; Add package-specific hooks.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485 (make-local-hook 'outline-view-change-hook)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486 (add-hook 'outline-view-change-hook 'lazy-lock-fontify-after-outline nil t))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 (defun lazy-lock-install-timers (dtime stime)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489 ;; Schedule or re-schedule the deferral and stealth timers.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 ;; The layout of `lazy-lock-timers' is:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 ;; ((DEFER-TIME . DEFER-TIMER) (STEALTH-TIME . STEALTH-TIMER)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 ;; If an idle timeout has changed, cancel the existing idle timer (if there
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493 ;; is one) and schedule a new one (if the new idle timeout is non-nil).
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 (unless (eq dtime (car (car lazy-lock-timers)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 (let ((defer (car lazy-lock-timers)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 (when (cdr defer)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497 (cancel-timer (cdr defer)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498 (setcar lazy-lock-timers (cons dtime (and dtime
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 (run-with-idle-timer dtime t 'lazy-lock-fontify-after-defer))))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 (unless (eq stime (car (cdr lazy-lock-timers)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 (let ((stealth (cdr lazy-lock-timers)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 (when (cdr stealth)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 (cancel-timer (cdr stealth)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 (setcdr lazy-lock-timers (cons stime (and stime
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505 (run-with-idle-timer stime t 'lazy-lock-fontify-after-idle)))))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 (defun lazy-lock-unstall ()
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 ;; Remove the text properties.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510 (lazy-lock-after-unfontify-buffer)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 ;; Remove the fontification hooks.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513 (remove-hook 'window-scroll-functions 'lazy-lock-fontify-after-scroll t)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514 (remove-hook 'window-scroll-functions 'lazy-lock-defer-after-scroll t)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 (remove-hook 'before-change-functions 'lazy-lock-arrange-before-change t)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516 (remove-hook 'after-change-functions 'lazy-lock-defer-after-change t)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517 (remove-hook 'outline-view-change-hook 'lazy-lock-fontify-after-outline t)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519 ;; If Font Lock mode is still enabled, reinstall its hook.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 (when font-lock-mode
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 (add-hook 'after-change-functions 'font-lock-after-change-function nil t)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 ;; Hook functions.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525 (defun lazy-lock-fontify-after-scroll (window window-start)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526 ;; Called from `window-scroll-functions'.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527 ;; Fontify WINDOW from WINDOW-START. We cannot use `window-end' so we work
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
528 ;; out what it would be via `vertical-motion'.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529 (save-excursion
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 (goto-char window-start)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 (vertical-motion (window-height window) window)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 (lazy-lock-fontify-region window-start (point)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
533 ;; A prior deletion that did not cause scrolling, followed by a scroll, would
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
534 ;; result in an unnecessary trigger after this if we did not cancel it now.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535 (set-window-redisplay-end-trigger window nil))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 (defun lazy-lock-fontify-after-trigger (window trigger-point)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538 ;; Called from `redisplay-end-trigger-functions'.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
539 ;; Fontify WINDOW from TRIGGER-POINT. We cannot use `window-end' so we work
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 ;; out what it would be via `vertical-motion'.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541 ;; We could probably just use `lazy-lock-fontify-after-scroll' without loss:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542 ;; (lazy-lock-fontify-after-scroll window (window-start window))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543 (save-excursion
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
544 (goto-char (window-start window))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
545 (vertical-motion (window-height window) window)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
546 (lazy-lock-fontify-region trigger-point (point))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
547
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548 (defun lazy-lock-fontify-after-resize (frame)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549 ;; Called from `window-size-change-functions'.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550 ;; Fontify windows in FRAME. We cannot use `window-start' or `window-end' so
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551 ;; we fontify conservatively.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
552 (save-excursion
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
553 (save-selected-window
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554 (select-frame frame)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 (walk-windows (function (lambda (window)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556 (set-buffer (window-buffer window))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557 (when lazy-lock-mode
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558 (lazy-lock-fontify-conservatively window))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559 (set-window-redisplay-end-trigger window nil)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560 'nomini frame))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562 (defun lazy-lock-arrange-before-change (beg end)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563 ;; Called from `before-change-functions'.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564 ;; Arrange that if text becomes visible it will be fontified (if a deletion
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565 ;; is pending, text might become visible at the bottom).
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566 (unless (eq beg end)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567 (let ((windows (get-buffer-window-list (current-buffer) 'nomini t)) window)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
568 (while windows
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
569 (setq window (car windows))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
570 (unless (markerp (window-redisplay-end-trigger window))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
571 (set-window-redisplay-end-trigger window (make-marker)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572 (set-marker (window-redisplay-end-trigger window) (window-end window))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
573 (setq windows (cdr windows))))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
574
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575 (defun lazy-lock-defer-after-scroll (window window-start)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
576 ;; Called from `window-scroll-functions'.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
577 ;; Defer fontification following the scroll. Save the current buffer so that
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578 ;; we subsequently fontify in all windows showing the buffer.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
579 (unless (memq (current-buffer) lazy-lock-buffers)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
580 (push (current-buffer) lazy-lock-buffers)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582 (defun lazy-lock-defer-after-change (beg end old-len)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
583 ;; Called from `after-change-functions'.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
584 ;; Defer fontification of the current line. Save the current buffer so that
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
585 ;; we subsequently fontify in all windows showing the buffer.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
586 (save-buffer-state nil
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587 (unless (memq (current-buffer) lazy-lock-buffers)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
588 (push (current-buffer) lazy-lock-buffers))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
589 (remove-text-properties
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
590 (max (1- beg) (point-min)) (min (1+ end) (point-max)) '(lazy-lock nil))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
592 (defun lazy-lock-fontify-after-defer ()
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
593 ;; Called from `timer-idle-list'.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
594 ;; Fontify all windows where deferral has occurred for its buffer.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
595 (while (and lazy-lock-buffers (not (input-pending-p)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
596 (let ((windows (get-buffer-window-list (car lazy-lock-buffers) 'nomini t)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
597 (while windows
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
598 (lazy-lock-fontify-window (car windows))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
599 (setq windows (cdr windows)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
600 (setq lazy-lock-buffers (cdr lazy-lock-buffers))))
15499
aa9675ed8ed4 Test for lazy-lock-mode before swapping hooks.
Simon Marshall <simon@gnu.org>
parents: 15461
diff changeset
601 ;; Add hook if fontification should now be defer-driven in this buffer.
aa9675ed8ed4 Test for lazy-lock-mode before swapping hooks.
Simon Marshall <simon@gnu.org>
parents: 15461
diff changeset
602 (when (and lazy-lock-mode lazy-lock-defer-driven
aa9675ed8ed4 Test for lazy-lock-mode before swapping hooks.
Simon Marshall <simon@gnu.org>
parents: 15461
diff changeset
603 (memq 'lazy-lock-fontify-after-scroll window-scroll-functions)
aa9675ed8ed4 Test for lazy-lock-mode before swapping hooks.
Simon Marshall <simon@gnu.org>
parents: 15461
diff changeset
604 (not (or (input-pending-p) (lazy-lock-unfontified-p))))
15461
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
605 (remove-hook 'window-scroll-functions 'lazy-lock-fontify-after-scroll t)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
606 (add-hook 'window-scroll-functions 'lazy-lock-defer-after-scroll nil t)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
607
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
608 (defun lazy-lock-fontify-after-idle ()
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
609 ;; Called from `timer-idle-list'.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
610 ;; Fontify all buffers that need it, stealthily while idle.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
611 (unless (or executing-kbd-macro (window-minibuffer-p (selected-window)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
612 ;; Loop over all buffers, fontify stealthily for each if necessary.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
613 (let ((buffers (buffer-list)) (continue t) message message-log-max)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
614 (save-excursion
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
615 (do-while (and buffers continue)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
616 (set-buffer (car buffers))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
617 (if (not (and lazy-lock-mode (lazy-lock-unfontified-p)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
618 (setq continue (not (input-pending-p)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
619 ;; Fontify regions in this buffer while there is no input.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
620 (do-while (and (lazy-lock-unfontified-p)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
621 (setq continue (sit-for lazy-lock-stealth-nice)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
622 (when lazy-lock-stealth-verbose
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
623 (if message
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
624 (message "Fontifying stealthily... %2d%% of %s"
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
625 (lazy-lock-percent-fontified) (buffer-name))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
626 (message "Fontifying stealthily...")
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
627 (setq message t)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
628 (lazy-lock-fontify-chunk)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
629 (setq buffers (cdr buffers))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
630 (when message
15499
aa9675ed8ed4 Test for lazy-lock-mode before swapping hooks.
Simon Marshall <simon@gnu.org>
parents: 15461
diff changeset
631 (message "Fontifying stealthily...%s" (if continue "done" "quit"))))))
15461
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
633 (defun lazy-lock-fontify-after-outline ()
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
634 ;; Called from `outline-view-change-hook'.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
635 ;; Fontify windows showing the current buffer, as its visibility has changed.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
636 ;; This is a conspiracy hack between lazy-lock.el and noutline.el.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
637 (let ((windows (get-buffer-window-list (current-buffer) 'nomini t)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
638 (while windows
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
639 (lazy-lock-fontify-conservatively (car windows))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
640 (setq windows (cdr windows)))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
641
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
642 (defun lazy-lock-after-fontify-buffer ()
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
643 ;; Called from `font-lock-after-fontify-buffer'.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
644 ;; Mark the current buffer as fontified.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
645 ;; This is a conspiracy hack between lazy-lock.el and font-lock.el.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
646 (save-buffer-state nil
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
647 (add-text-properties (point-min) (point-max) '(lazy-lock t))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
648
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
649 (defun lazy-lock-after-unfontify-buffer ()
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
650 ;; Called from `font-lock-after-unfontify-buffer'.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
651 ;; Mark the current buffer as unfontified.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
652 ;; This is a conspiracy hack between lazy-lock.el and font-lock.el.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
653 (save-buffer-state nil
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
654 (remove-text-properties (point-min) (point-max) '(lazy-lock nil))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
655
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
656 ;; Fontification functions.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
657
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
658 ;; If packages want to ensure that some region of the buffer is fontified, they
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
659 ;; should use this function. For an example, see ps-print.el.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
660 (defun lazy-lock-fontify-region (beg end)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
661 ;; Fontify between BEG and END, where necessary, in the current buffer.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
662 (when (setq beg (text-property-any beg end 'lazy-lock nil))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
663 (save-excursion
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
664 (save-match-data
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
665 (save-buffer-state
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
666 ;; Ensure syntactic fontification is always correct.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
667 (font-lock-beginning-of-syntax-function next)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
668 ;; Find successive unfontified regions between BEG and END.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
669 (condition-case data
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
670 (do-while beg
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
671 (setq next (or (text-property-any beg end 'lazy-lock t) end))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
672 ;; Make sure the region end points are at beginning of line.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
673 (goto-char beg)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
674 (unless (bolp)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
675 (beginning-of-line)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
676 (setq beg (point)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
677 (goto-char next)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
678 (unless (bolp)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
679 (forward-line)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
680 (setq next (point)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
681 ;; Fontify the region, then flag it as fontified.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
682 (font-lock-fontify-region beg next)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
683 (add-text-properties beg next '(lazy-lock t))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
684 (setq beg (text-property-any next end 'lazy-lock nil)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
685 ((error quit) (message "Fontifying region...%s" data))))))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
686
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
687 (defun lazy-lock-fontify-chunk ()
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
688 ;; Fontify the nearest chunk, for stealth, in the current buffer.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
689 (save-excursion
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
690 (save-restriction
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
691 (widen)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
692 ;; Move to end of line in case the character at point is not fontified.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
693 (end-of-line)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
694 ;; Find where the previous, and next, unfontified regions end, and begin.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
695 (let ((prev (previous-single-property-change (point) 'lazy-lock))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
696 (next (text-property-any (point) (point-max) 'lazy-lock nil)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
697 ;; Fontify from the nearest unfontified position.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
698 (if (or (null prev) (and next (< (- next (point)) (- (point) prev))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
699 ;; The next, or neither, region is the nearest not fontified.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
700 (lazy-lock-fontify-region
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
701 (progn (goto-char (or next (point-min)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
702 (beginning-of-line)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
703 (point))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
704 (progn (goto-char (or next (point-min)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
705 (forward-line lazy-lock-stealth-lines)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
706 (point)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
707 ;; The previous region is the nearest not fontified.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
708 (lazy-lock-fontify-region
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
709 (progn (goto-char prev)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
710 (forward-line (- lazy-lock-stealth-lines))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
711 (point))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
712 (progn (goto-char prev)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
713 (forward-line)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
714 (point))))))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
715
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
716 (defun lazy-lock-fontify-window (window)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
717 ;; Fontify in WINDOW between `window-start' and `window-end'.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
718 ;; We can only do this when we can use `window-start' and `window-end'.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
719 (save-excursion
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
720 (set-buffer (window-buffer window))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
721 (lazy-lock-fontify-region (window-start window) (window-end window))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
722
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
723 (defun lazy-lock-fontify-conservatively (window)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
724 ;; Fontify in WINDOW conservatively around point.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
725 ;; Where we cannot use `window-start' and `window-end' we do `window-height'
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
726 ;; lines around point. That way we guarantee to have done enough.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
727 (save-excursion
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
728 (set-buffer (window-buffer window))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
729 (lazy-lock-fontify-region
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
730 (save-excursion
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
731 (vertical-motion (- (window-height window)) window) (point))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
732 (save-excursion
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
733 (vertical-motion (window-height window) window) (point)))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
734
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
735 (defun lazy-lock-unfontified-p ()
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
736 ;; Return non-nil if there is anywhere still to be fontified.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
737 (save-restriction
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
738 (widen)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
739 (text-property-any (point-min) (point-max) 'lazy-lock nil)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
740
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
741 (defun lazy-lock-percent-fontified ()
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
742 ;; Return the percentage (of characters) of the buffer that are fontified.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
743 (save-restriction
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
744 (widen)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
745 (let ((beg (point-min)) (end (point-max)) (size 0) next)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
746 ;; Find where the next fontified region begins.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
747 (while (setq beg (text-property-any beg end 'lazy-lock t))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
748 (setq next (or (text-property-any beg end 'lazy-lock nil) end)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
749 size (+ size (- next beg))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
750 beg next))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
751 (/ (* size 100) (buffer-size)))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
752
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
753 ;; Version dependent workarounds and fixes.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
754
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
755 (when (if (save-match-data (string-match "Lucid\\|XEmacs" (emacs-version)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
756 nil
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
757 (and (= emacs-major-version 19) (= emacs-minor-version 30)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
758 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
759 ;; We use `post-command-idle-hook' for deferral and stealth. Oh Lordy.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
760 (defun lazy-lock-install-timers (foo bar)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
761 (add-hook 'post-command-idle-hook 'lazy-lock-fontify-post-command t)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
762 (add-hook 'post-command-idle-hook 'lazy-lock-fontify-post-idle t)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
763 (add-to-list 'lazy-lock-install (current-buffer))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
764 (add-hook 'post-command-hook 'lazy-lock-fontify-after-install))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
765 (defun lazy-lock-fontify-post-command ()
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
766 (and lazy-lock-buffers (not executing-kbd-macro)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
767 (progn
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
768 (and deactivate-mark (deactivate-mark))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
769 (sit-for
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
770 (or (cdr-safe lazy-lock-defer-time) lazy-lock-defer-time 0)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
771 (lazy-lock-fontify-after-defer)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
772 (defun lazy-lock-fontify-post-idle ()
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
773 (and lazy-lock-stealth-time (not executing-kbd-macro)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
774 (not (window-minibuffer-p (selected-window)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
775 (progn
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
776 (and deactivate-mark (deactivate-mark))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
777 (sit-for lazy-lock-stealth-time))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
778 (lazy-lock-fontify-after-idle)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
779 ;;
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
780 ;; Simulate running of `window-scroll-functions' in `set-window-buffer'.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
781 (defvar lazy-lock-install nil)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
782 (defun lazy-lock-fontify-after-install ()
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
783 (remove-hook 'post-command-hook 'lazy-lock-fontify-after-install)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
784 (while lazy-lock-install
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
785 (mapcar 'lazy-lock-fontify-conservatively
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
786 (get-buffer-window-list (pop lazy-lock-install) 'nomini t)))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
787
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
788 ;; Possibly absent.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
789
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
790 (unless (boundp 'font-lock-inhibit-thing-lock)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
791 ;; Font Lock mode uses this to direct Lazy and Fast Lock modes to stay off.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
792 (defvar font-lock-inhibit-thing-lock nil
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
793 "List of Font Lock mode related modes that should not be turned on."))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
794
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
795 (unless (fboundp 'font-lock-value-in-major-mode)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
796 (defun font-lock-value-in-major-mode (alist)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
797 ;; Return value in ALIST for `major-mode'.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
798 (if (consp alist)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
799 (cdr (or (assq major-mode alist) (assq t alist)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
800 alist)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
801
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
802 (unless (fboundp 'get-buffer-window-list)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
803 ;; We use this to get all windows showing a buffer we have to fontify.
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
804 (defun get-buffer-window-list (buffer &optional minibuf frame)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
805 "Return windows currently displaying BUFFER, or nil if none."
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
806 (let ((buffer (if (bufferp buffer) buffer (get-buffer buffer))) windows)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
807 (walk-windows (function (lambda (window)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
808 (when (eq (window-buffer window) buffer)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
809 (push window windows))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
810 minibuf frame)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
811 windows)))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
812
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
813 ;; Install ourselves:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
814
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
815 (add-hook 'window-size-change-functions 'lazy-lock-fontify-after-resize)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
816 (add-hook 'redisplay-end-trigger-functions 'lazy-lock-fontify-after-trigger)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
817
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
818 (unless (assq 'lazy-lock-mode minor-mode-alist)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
819 (setq minor-mode-alist (append minor-mode-alist '((lazy-lock-mode nil)))))
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
820
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
821 ;; Provide ourselves:
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
822
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
823 (provide 'lazy-lock)
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
824
a0dc879461b8 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
825 ;;; lazy-lock.el ends here