Mercurial > hg > xemacs-beta
comparison lisp/packages/lazy-lock.el @ 24:4103f0995bd7 r19-15b95
Import from CVS: tag r19-15b95
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:51:03 +0200 |
parents | bcdc7deadc19 |
children | 131b0175ea99 |
comparison
equal
deleted
inserted
replaced
23:0edd3412f124 | 24:4103f0995bd7 |
---|---|
1 ;;; lazy-lock.el --- Lazy demand-driven fontification for fast Font Lock mode. | 1 ;;; lazy-lock.el --- Lazy demand-driven fontification for fast Font Lock mode. |
2 | 2 |
3 ;; Copyright (C) 1994, 1995 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1994, 1995, 1997 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: Simon Marshall <simon@gnu.ai.mit.edu> | 5 ;; Author: Simon Marshall <simon@gnu.ai.mit.edu> |
6 ;; Keywords: faces files | 6 ;; Keywords: faces files |
7 ;; Version: 1.15 | 7 ;; Version: 1.16 |
8 | |
9 ;; LCD Archive Entry: | |
10 ;; lazy-lock|Simon Marshall|simon@gnu.ai.mit.edu| | |
11 ;; Lazy Font Lock mode (with fast demand-driven fontification).| | |
12 ;; 13-Nov-95|1.15|~/modes/lazy-lock.el.Z| | |
13 | |
14 ;; The archive is archive.cis.ohio-state.edu in /pub/gnu/emacs/elisp-archive. | |
15 | 8 |
16 ;;; This file is part of GNU Emacs. | 9 ;;; This file is part of GNU Emacs. |
17 | 10 |
18 ;; GNU Emacs is free software; you can redistribute it and/or modify | 11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
19 ;; it under the terms of the GNU General Public License as published by | 12 ;; it under the terms of the GNU General Public License as published by |
24 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | 17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
26 ;; GNU General Public License for more details. | 19 ;; GNU General Public License for more details. |
27 | 20 |
28 ;; You should have received a copy of the GNU General Public License | 21 ;; You should have received a copy of the GNU General Public License |
29 ;; along with GNU Emacs; see the file COPYING. If not, write to | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
30 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
24 ;; Boston, MA 02111-1307, USA. | |
31 | 25 |
32 ;;; Commentary: | 26 ;;; Commentary: |
33 | 27 |
34 ;; Purpose: | 28 ;; Purpose: |
35 ;; | 29 ;; |
104 ;; Let me know if you use any other `advice' and I'll put it here. Thanks. | 98 ;; Let me know if you use any other `advice' and I'll put it here. Thanks. |
105 ;; | 99 ;; |
106 ;; These kinds of things with `advice' aren't done automatically because they | 100 ;; These kinds of things with `advice' aren't done automatically because they |
107 ;; cause large packages (advice.el plus bytecomp.el and friends) to be loaded. | 101 ;; cause large packages (advice.el plus bytecomp.el and friends) to be loaded. |
108 | 102 |
103 ;; Implementation differences with version 2: | |
104 ;; | |
105 ;; - Version 1 of lazy-lock.el is a bit of a hack. Version 1 demand-driven | |
106 ;; fontification, the core feature of lazy-lock.el, is implemented by placing a | |
107 ;; function on `post-command-hook'. This function fontifies where necessary, | |
108 ;; i.e., where a window scroll has occurred. However, there are a number of | |
109 ;; problems with using `post-command-hook': | |
110 ;; | |
111 ;; (a) As the name suggests, `post-command-hook' is run after every command, | |
112 ;; i.e., frequently and regardless of whether scrolling has occurred. | |
113 ;; (b) Scrolling can occur during a command, when `post-command-hook' is not | |
114 ;; run, i.e., it is not necessarily run after scrolling has occurred. | |
115 ;; (c) When `post-command-hook' is run, there is nothing to suggest where | |
116 ;; scrolling might have occurred, i.e., which windows have scrolled. | |
117 ;; | |
118 ;; Thus lazy-lock.el's function is called almost as often as possible, usually | |
119 ;; when it need not be called, yet it is not always called when it is needed. | |
120 ;; Also, lazy-lock.el's function must check each window to see if a scroll has | |
121 ;; occurred there. Worse still, lazy-lock.el's function must fontify a region | |
122 ;; twice as large as necessary to make sure the window is completely fontified. | |
123 ;; Basically, `post-command-hook' is completely inappropriate for lazy-lock.el. | |
124 ;; | |
125 ;; Ideally, we want to attach lazy-lock.el's function to a hook that is run | |
126 ;; only when scrolling occurs, e.g., `window-start' has changed, and tells us | |
127 ;; as much information as we need, i.e., the window and its new buffer region. | |
128 ;; Richard Stallman implemented a `window-scroll-functions' for Emacs 19.30. | |
129 ;; Functions on it are run when `window-start' has changed, and are supplied | |
130 ;; with the window and the window's new `window-start' position. (It would be | |
131 ;; better if it also supplied the window's new `window-end' position, but that | |
132 ;; is calculated as part of the redisplay process, and the functions on | |
133 ;; `window-scroll-functions' are run before redisplay has finished.) Thus, the | |
134 ;; hook deals with the above problems (a), (b) and (c). | |
135 ;; | |
136 ;; If only life was that easy. Version 2 demand-driven fontification is mostly | |
137 ;; implemented by placing a function on `window-scroll-functions'. However, | |
138 ;; not all scrolling occurs when `window-start' has changed. A change in | |
139 ;; window size, e.g., via C-x 1, or a significant deletion, e.g., of a number | |
140 ;; of lines, causes text previously invisible (i.e., after `window-end') to | |
141 ;; become visible without changing `window-start'. Arguably, these events are | |
142 ;; not scrolling events, but fontification must occur for lazy-lock.el to work. | |
143 ;; Hooks `window-size-change-functions' and `redisplay-end-trigger-functions' | |
144 ;; were added for these circumstances. | |
145 ;; | |
146 ;; (Ben Wing thinks these hooks are "horribly horribly kludgy", and implemented | |
147 ;; a `pre-idle-hook', a `mother-of-all-post-command-hooks', for XEmacs 19.14. | |
148 ;; He then hacked up a version 1 lazy-lock.el to use `pre-idle-hook' rather | |
149 ;; than `post-command-hook'. Whereas functions on `post-command-hook' are | |
150 ;; called almost as often as possible, functions on `pre-idle-hook' really are | |
151 ;; called as often as possible, even when the mouse moves and, on some systems, | |
152 ;; while XEmacs is idle. Thus, the hook deals with the above problem (b), but | |
153 ;; unfortunately it makes (a) worse and does not address (c) at all. | |
154 ;; | |
155 ;; I freely admit that `redisplay-end-trigger-functions' and, to a much lesser | |
156 ;; extent, `window-size-change-functions' are not pretty. However, I feel that | |
157 ;; a `window-scroll-functions' feature is cleaner than a `pre-idle-hook', and | |
158 ;; the result is faster and smaller, less intrusive and more targeted, code. | |
159 ;; Since `pre-idle-hook' is pretty much like `post-command-hook', there is no | |
160 ;; point in making this version of lazy-lock.el work with it. Anyway, that's | |
161 ;; Lit 30 of my humble opinion. | |
162 ;; | |
163 ;; Steve Baur reverted to a non-hacked version 1 lazy-lock.el for XEmacs 19.15 | |
164 ;; and 20.0. Obviously, the above `post-command-hook' problems still apply.) | |
165 ;; | |
166 ;; - Version 1 stealth fontification is also implemented by placing a function | |
167 ;; on `post-command-hook'. This function waits for a given amount of time, | |
168 ;; and, if Emacs remains idle, fontifies where necessary. Again, there are a | |
169 ;; number of problems with using `post-command-hook': | |
170 ;; | |
171 ;; (a) Functions on `post-command-hook' are run sequentially, so this function | |
172 ;; can interfere with other functions on the hook, and vice versa. | |
173 ;; (b) This function waits for a given amount of time, so it can interfere with | |
174 ;; various features that are dealt with by Emacs after a command, e.g., | |
175 ;; region highlighting, asynchronous updating and keystroke echoing. | |
176 ;; (c) Fontification may be required during a command, when `post-command-hook' | |
177 ;; is not run. (Version 2 deferred fontification only.) | |
178 ;; | |
179 ;; Again, `post-command-hook' is completely inappropriate for lazy-lock.el. | |
180 ;; Richard Stallman and Morten Welinder implemented internal Timers and Idle | |
181 ;; Timers for Emacs 19.31. Functions can be run independently at given times | |
182 ;; or after given amounts of idle time. Thus, the feature deals with the above | |
183 ;; problems (a), (b) and (c). Version 2 deferral and stealth are implemented | |
184 ;; by functions on Idle Timers. (A function on XEmacs' `pre-idle-hook' is | |
185 ;; similar to an Emacs Idle Timer function with a fixed zero second timeout.) | |
186 ;; | |
187 ;; - Version 1 has the following problems (relative to version 2): | |
188 ;; | |
189 ;; (a) It is slow when it does its job. | |
190 ;; (b) It does not always do its job when it should. | |
191 ;; (c) It slows all interaction (when it doesn't need to do its job). | |
192 ;; (d) It interferes with other package functions on `post-command-hook'. | |
193 ;; (e) It interferes with Emacs things within the read-eval loop. | |
194 ;; | |
195 ;; Ben's hacked-up lazy-lock.el 1.14 almost solved (b) but made (c) worse. | |
196 ;; | |
197 ;; - Version 2 has the following additional features (relative to version 1): | |
198 ;; | |
199 ;; (a) It can defer fontification (both on-the-fly and on-scrolling). | |
200 ;; (b) It can fontify contextually (syntactically true on-the-fly). | |
201 | |
109 ;; Caveats: | 202 ;; Caveats: |
110 ;; | 203 |
111 ;; Lazy Lock mode does not work efficiently with Outline mode. This is because | 204 ;; Lazy Lock mode does not work efficiently with Outline mode. This is because |
112 ;; when in Outline mode, although text may be hidden (not visible in the | 205 ;; when in Outline mode, although text may be hidden (not visible in the |
113 ;; window), the text is visible to Emacs Lisp code (not surprisingly) and Lazy | 206 ;; window), the text is visible to Emacs Lisp code (not surprisingly) and Lazy |
114 ;; Lock fontifies it mercilessly. Hopefully this will be fixed one day. | 207 ;; Lock fontifies it mercilessly. Hopefully this will be fixed one day. |
115 ;; | 208 ;; |
158 ;; | 251 ;; |
159 ;; The solution is to upgrade! (With thanks to Kevin Broadey for help here.) | 252 ;; The solution is to upgrade! (With thanks to Kevin Broadey for help here.) |
160 ;; | 253 ;; |
161 ;; For XEmacs 19.11 and Lucid Emacs 19.10 users, lazy-lock sort-of works. | 254 ;; For XEmacs 19.11 and Lucid Emacs 19.10 users, lazy-lock sort-of works. |
162 ;; There are bugs in text property and point/window primatives. Upgrade! | 255 ;; There are bugs in text property and point/window primatives. Upgrade! |
163 | 256 ;; |
164 ;; Feedback: | 257 ;; Currently XEmacs does not have the features to support version 2 of |
165 ;; | 258 ;; lazy-lock.el. Maybe it will one day. |
166 ;; Feedback is welcome. | |
167 ;; To submit a bug report (or make comments) please use the mechanism provided: | |
168 ;; | |
169 ;; M-x lazy-lock-submit-bug-report RET | |
170 | 259 |
171 ;; History: | 260 ;; History: |
172 ;; | 261 ;; |
173 ;; 0.01--1.00: | 262 ;; 0.01--1.00: |
174 ;; - Changed name from fore-lock to lazy-lock. Shame though. | 263 ;; - Changed name from fore-lock to lazy-lock. Shame though. |
175 ;; - Dropped `advice'-wrapping completely. Ask me if you're interested in it. | 264 ;; - Dropped `advice'-wrapping completely. Ask me if you're interested in it. |
176 ;; - Made `lazy-lock-mode' ignore `post-command-hook' and `buffer-file-name'. | 265 ;; - Made `lazy-lock-mode' ignore `post-command-hook' and `buffer-file-name' |
177 ;; - Made `lazy-lock-fontify-window' check `lazy-lock-mode' and `this-command'. | 266 ;; - Made `lazy-lock-fontify-window' check `lazy-lock-mode' and `this-command' |
178 ;; - Made `lazy-lock-fontify-window' redisplay via `sit-for'. | 267 ;; - Made `lazy-lock-fontify-window' redisplay via `sit-for' |
179 ;; - Added `lazy-lock-minimum-size' to control `lazy-lock-mode'. | 268 ;; - Added `lazy-lock-minimum-size' to control `lazy-lock-mode' |
180 ;; 1.00--1.01: | 269 ;; 1.00--1.01: |
181 ;; - Added `lazy-lock-fontify-buffer'. | 270 ;; - Added `lazy-lock-fontify-buffer' |
182 ;; - Made `lazy-lock-fontify-window' ignore `lazy-lock-mode'. | 271 ;; - Made `lazy-lock-fontify-window' ignore `lazy-lock-mode' |
183 ;; - Made `lazy-lock-fontify-window' suspicious of `window-' favourites again. | 272 ;; - Made `lazy-lock-fontify-window' suspicious of `window-' favourites again |
184 ;; - Added `lazy-lock-delay-commands' (idea from William G. Dubuque). | 273 ;; - Added `lazy-lock-delay-commands' (idea from William G. Dubuque) |
185 ;; - Added `lazy-lock-ignore-commands' for completeness. | 274 ;; - Added `lazy-lock-ignore-commands' for completeness |
186 ;; - Added `lazy-lock-continuity-time' for normal input delay. | 275 ;; - Added `lazy-lock-continuity-time' for normal input delay |
187 ;; 1.01--1.02: | 276 ;; 1.01--1.02: |
188 ;; - Made `lazy-lock-fontify-window' cope with multiple unfontified regions. | 277 ;; - Made `lazy-lock-fontify-window' cope with multiple unfontified regions |
189 ;; - Made `lazy-lock-mode' remove `fontified' properties if turned off. | 278 ;; - Made `lazy-lock-mode' remove `fontified' properties if turned off |
190 ;; - Made `lazy-lock-fontify-window' fontify by lines. | 279 ;; - Made `lazy-lock-fontify-window' fontify by lines |
191 ;; - Added `lazy-lock-cache-position' buffer local to detect visibility change. | 280 ;; - Added `lazy-lock-cache-position' buffer local to detect visibility change |
192 ;; - Added `lazy-lock-post-command-hook' to do the waiting. | 281 ;; - Added `lazy-lock-post-command-hook' to do the waiting |
193 ;; - Made `lazy-lock-fontify-window' just do the fontification. | 282 ;; - Made `lazy-lock-fontify-window' just do the fontification |
194 ;; - Made `lazy-lock-mode' append `lazy-lock-post-command-hook'. | 283 ;; - Made `lazy-lock-mode' append `lazy-lock-post-command-hook' |
195 ;; - Added `lazy-lock-walk-windows' to hack multi-window motion. | 284 ;; - Added `lazy-lock-walk-windows' to hack multi-window motion |
196 ;; - Made `lazy-lock-post-command-hook' `walk-windows' if variable is non-nil. | 285 ;; - Made `lazy-lock-post-command-hook' `walk-windows' if variable is non-nil |
197 ;; - Removed `lazy-lock-ignore-commands' since insertion may change window. | 286 ;; - Removed `lazy-lock-ignore-commands' since insertion may change window |
198 ;; - Added `lazy-lock-fontify-stealthily' and `lazy-lock-stealth-time'. | 287 ;; - Added `lazy-lock-fontify-stealthily' and `lazy-lock-stealth-time' |
199 ;; - Made `lazy-lock-post-command-hook' use them. | 288 ;; - Made `lazy-lock-post-command-hook' use them |
200 ;; 1.02--1.03: | 289 ;; 1.02--1.03: |
201 ;; - Made `lazy-lock-fontify-stealthily' do `forward-line' not `previous-line'. | 290 ;; - Made `lazy-lock-fontify-stealthily' do `forward-line' not `previous-line' |
202 ;; - Made `lazy-lock-fontify-stealthily' `move-to-window-line' first. | 291 ;; - Made `lazy-lock-fontify-stealthily' `move-to-window-line' first |
203 ;; - Made `lazy-lock-fontify-stealthily' use `text-property-any' for region. | 292 ;; - Made `lazy-lock-fontify-stealthily' use `text-property-any' for region |
204 ;; - Made `lazy-lock-post-command-hook' loop on `lazy-lock-fontify-stealthily'. | 293 ;; - Made `lazy-lock-post-command-hook' loop on `lazy-lock-fontify-stealthily' |
205 ;; 1.03--1.04: | 294 ;; 1.03--1.04: |
206 ;; - Made `lazy-lock-mode' reset `lazy-lock-cache-position'. | 295 ;; - Made `lazy-lock-mode' reset `lazy-lock-cache-position' |
207 ;; - Made `lazy-lock-post-command-hook' `widen' for `if' `text-property-any'. | 296 ;; - Made `lazy-lock-post-command-hook' `widen' for `if' `text-property-any' |
208 ;; - Made `lazy-lock-fontify-stealthily' return `text-property-any'. | 297 ;; - Made `lazy-lock-fontify-stealthily' return `text-property-any' |
209 ;; - Added `lazy-lock-percent-fontified' for a/be-musement. | 298 ;; - Added `lazy-lock-percent-fontified' for a/be-musement |
210 ;; - Made `lazy-lock-post-command-hook' use it. | 299 ;; - Made `lazy-lock-post-command-hook' use it |
211 ;; - Made `lazy-lock-mode' use `make-local-hook' etc. if available. | 300 ;; - Made `lazy-lock-mode' use `make-local-hook' etc. if available |
212 ;; - Made `lazy-lock-mode' use `before-revert-hook' and `after-revert-hook'. | 301 ;; - Made `lazy-lock-mode' use `before-revert-hook' and `after-revert-hook' |
213 ;; - Made `lazy-lock-post-command-hook' protect `deactivate-mark'. | 302 ;; - Made `lazy-lock-post-command-hook' protect `deactivate-mark' |
214 ;; - Adds `lazy-lock-post-command-hook' globally to `post-command-hook'. | 303 ;; - Adds `lazy-lock-post-command-hook' globally to `post-command-hook' |
215 ;; 1.04--1.05: | 304 ;; 1.04--1.05: |
216 ;; - Made `lazy-lock-mode' test `make-local-hook' not `emacs-minor-version'. | 305 ;; - Made `lazy-lock-mode' test `make-local-hook' not `emacs-minor-version' |
217 ;; 1.05--1.06: | 306 ;; 1.05--1.06: |
218 ;; - Added `lazy-lock-ignore-commands' for commands that leave no event but do. | 307 ;; - Added `lazy-lock-ignore-commands' for commands that leave no event but do |
219 ;; - Made `lazy-lock-post-command-hook' check `lazy-lock-ignore-commands'. | 308 ;; - Made `lazy-lock-post-command-hook' check `lazy-lock-ignore-commands' |
220 ;; 1.06--1.07: | 309 ;; 1.06--1.07: |
221 ;; - Removed `before-revert-hook' and `after-revert-hook' use. | 310 ;; - Removed `before-revert-hook' and `after-revert-hook' use |
222 ;; 1.07--1.08: | 311 ;; 1.07--1.08: |
223 ;; - Added `lazy-lock-submit-bug-report'. | 312 ;; - Added `lazy-lock-submit-bug-report' |
224 ;; - Made `lazy-lock-post-command-hook' check `executing-macro'. | 313 ;; - Made `lazy-lock-post-command-hook' check `executing-macro' |
225 ;; - Made it sort-of/almost work for XEmacs (help from Jonas Jarnestrom). | 314 ;; - Made it sort-of/almost work for XEmacs (help from Jonas Jarnestrom) |
226 ;; - XEmacs: Fix `text-property-not-all' (fix based on fast-lock.el 3.05 fix). | 315 ;; - XEmacs: Fix `text-property-not-all' (fix based on fast-lock.el 3.05 fix) |
227 ;; - XEmacs: Set `font-lock-no-comments' and alias `frame-parameters'. | 316 ;; - XEmacs: Set `font-lock-no-comments' and alias `frame-parameters' |
228 ;; - Made `byte-compile-warnings' omit `unresolved' on compilation. | 317 ;; - Made `byte-compile-warnings' omit `unresolved' on compilation |
229 ;; - Made `lazy-lock-post-command-hook' protect `buffer-undo-list'. | 318 ;; - Made `lazy-lock-post-command-hook' protect `buffer-undo-list' |
230 ;; - Moved `deactivate-mark' and `buffer-undo-list' protection to functions. | 319 ;; - Moved `deactivate-mark' and `buffer-undo-list' protection to functions |
231 ;; - Added `lazy-lock-invisible-foreground' (idea from Boris Goldowsky). | 320 ;; - Added `lazy-lock-invisible-foreground' (idea from Boris Goldowsky) |
232 ;; - XEmacs: Fix to use `text-property-not-all' t, not `text-property-any' nil. | 321 ;; - XEmacs: Fix to use `text-property-not-all' t, not `text-property-any' nil |
233 ;; - Made `lazy-lock-percent-fontified' return `round' to an integer. | 322 ;; - Made `lazy-lock-percent-fontified' return `round' to an integer |
234 ;; - XEmacs: Fix `text-property-any' (fix and work around for a bug elsewhere). | 323 ;; - XEmacs: Fix `text-property-any' (fix and work around for a bug elsewhere) |
235 ;; - XEmacs: Fix `lazy-lock-submit-bug-report' for reporter.el & vm-window.el. | 324 ;; - XEmacs: Fix `lazy-lock-submit-bug-report' for reporter.el & vm-window.el |
236 ;; - XEmacs: Made `lazy-lock-fontify-window' loop `while' `<' not `/='. | 325 ;; - XEmacs: Made `lazy-lock-fontify-window' loop `while' `<' not `/=' |
237 ;; - Use `font-lock-after-change-function' to do the fontification. | 326 ;; - Use `font-lock-after-change-function' to do the fontification |
238 ;; 1.08--1.09: | 327 ;; 1.08--1.09: |
239 ;; - Made `lazy-lock-post-command-hook' protect with `condition-case'. | 328 ;; - Made `lazy-lock-post-command-hook' protect with `condition-case' |
240 ;; - Made `lazy-lock-cache-start' to cache `window-start'. | 329 ;; - Made `lazy-lock-cache-start' to cache `window-start' |
241 ;; - Made `lazy-lock-fontify-window' check and cache `lazy-lock-cache-start'. | 330 ;; - Made `lazy-lock-fontify-window' check and cache `lazy-lock-cache-start' |
242 ;; - Renamed `lazy-lock-cache-position' to `lazy-lock-cache-end'. | 331 ;; - Renamed `lazy-lock-cache-position' to `lazy-lock-cache-end' |
243 ;; - XEmacs: Fix for `font-lock-after-change-function'. | 332 ;; - XEmacs: Fix for `font-lock-after-change-function' |
244 ;; - Adds `lazy-lock-post-command-hook' globally to `window-setup-hook'. | 333 ;; - Adds `lazy-lock-post-command-hook' globally to `window-setup-hook' |
245 ;; 1.09--1.10: | 334 ;; 1.09--1.10: |
246 ;; - Made `buffer-file-name' be `let' to prevent supersession (Kevin Broadey). | 335 ;; - Made `buffer-file-name' be `let' to prevent supersession (Kevin Broadey) |
247 ;; - Made `lazy-lock-submit-bug-report' `require' reporter (Ilya Zakharevich). | 336 ;; - Made `lazy-lock-submit-bug-report' `require' reporter (Ilya Zakharevich) |
248 ;; - Made `lazy-lock-mode' and `turn-on-lazy-lock' succeed `autoload' cookies. | 337 ;; - Made `lazy-lock-mode' and `turn-on-lazy-lock' succeed `autoload' cookies |
249 ;; - Added `lazy-lock-fontify-walk-windows' for walking window fontification. | 338 ;; - Added `lazy-lock-fontify-walk-windows' for walking window fontification |
250 ;; - Added `lazy-lock-fontify-walk-stealthily' for walking stealth. | 339 ;; - Added `lazy-lock-fontify-walk-stealthily' for walking stealth |
251 ;; - Removed `move-to-window-line' from `lazy-lock-fontify-stealthily'. | 340 ;; - Removed `move-to-window-line' from `lazy-lock-fontify-stealthily' |
252 ;; - Made `lazy-lock-percent-fontified' use `truncate' rather than `round'. | 341 ;; - Made `lazy-lock-percent-fontified' use `truncate' rather than `round' |
253 ;; - Added other `*-argument' to `lazy-lock-ignore-commands' (Kevin Broadey). | 342 ;; - Added other `*-argument' to `lazy-lock-ignore-commands' (Kevin Broadey) |
254 ;; - Made `lazy-lock-fontify-stealthily' not assume buffer is part `fontified'. | 343 ;; - Made `lazy-lock-fontify-stealthily' not assume buffer is part `fontified' |
255 ;; - Emacs: Fix for `font-lock-fontify-region'. | 344 ;; - Emacs: Fix for `font-lock-fontify-region' |
256 ;; - Made `lazy-lock-post-command-hook' check for minibuffer (Kevin Broadey). | 345 ;; - Made `lazy-lock-post-command-hook' check for minibuffer (Kevin Broadey) |
257 ;; - Added `lazy-lock-stealth-nice' for niceness during stealth fontification. | 346 ;; - Added `lazy-lock-stealth-nice' for niceness during stealth fontification |
258 ;; - Added `lazy-lock-stealth-lines' for chunks of stealth fontification. | 347 ;; - Added `lazy-lock-stealth-lines' for chunks of stealth fontification |
259 ;; 1.10--1.11: incorporated hack by Ben Wing from William Dubuque's fontifly.el | 348 ;; 1.10--1.11: incorporated hack by Ben Wing from William Dubuque's fontifly.el |
260 ;; - Made `lazy-lock-fontify-stealthily' see a non `fontified' preceding line. | 349 ;; - Made `lazy-lock-fontify-stealthily' see a non `fontified' preceding line |
261 ;; - XEmacs: Fix `text-property-any' and `text-property-not-all' (Ben Wing). | 350 ;; - XEmacs: Fix `text-property-any' and `text-property-not-all' (Ben Wing) |
262 ;; - XEmacs: Fix `lazy-lock-continuity-time' (Ben Wing). | 351 ;; - XEmacs: Fix `lazy-lock-continuity-time' (Ben Wing) |
263 ;; - Added awful `lazy-lock-running-xemacs-p' (Ben Wing). | 352 ;; - Added awful `lazy-lock-running-xemacs-p' (Ben Wing) |
264 ;; - Made loading set `emacs-minor-version' if it's not bound. | 353 ;; - Made loading set `emacs-minor-version' if it's not bound |
265 ;; - Added `lazy-lock-hide-invisible' to control redisplay. | 354 ;; - Added `lazy-lock-hide-invisible' to control redisplay |
266 ;; - Made `lazy-lock-post-command-hook' use it in `sit-for' (Ben Wing). | 355 ;; - Made `lazy-lock-post-command-hook' use it in `sit-for' (Ben Wing) |
267 ;; - Made `lazy-lock-fontify-window' move relative to `end-of-line' if non-nil. | 356 ;; - Made `lazy-lock-fontify-window' move relative to `end-of-line' if non-nil |
268 ;; - Added `lazy-lock-fontify-region' so packages can ensure fontification. | 357 ;; - Added `lazy-lock-fontify-region' so packages can ensure fontification |
269 ;; - Made `lazy-lock-fontify-walk-stealthily' do stealth widening. | 358 ;; - Made `lazy-lock-fontify-walk-stealthily' do stealth widening |
270 ;; - Made `lazy-lock-fontify-stealthily' always do adjacent preceding regions. | 359 ;; - Made `lazy-lock-fontify-stealthily' always do adjacent preceding regions |
271 ;; - Added `lazy-lock-after-fontify-buffer'. | 360 ;; - Added `lazy-lock-after-fontify-buffer' |
272 ;; - XEmacs: Removed `font-lock-no-comments' incompatibility code. | 361 ;; - XEmacs: Removed `font-lock-no-comments' incompatibility code |
273 ;; - Removed `lazy-lock-delay-time' and `lazy-lock-delay-commands'. | 362 ;; - Removed `lazy-lock-delay-time' and `lazy-lock-delay-commands' |
274 ;; - Removed `lazy-lock-post-command' and split the functionality. | 363 ;; - Removed `lazy-lock-post-command' and split the functionality |
275 ;; - Adds `lazy-lock-post-command-fontify-windows' on first. | 364 ;; - Adds `lazy-lock-post-command-fontify-windows' on first |
276 ;; - Adds `lazy-lock-post-command-fontify-stealthily' on last. | 365 ;; - Adds `lazy-lock-post-command-fontify-stealthily' on last |
277 ;; - Made `lazy-lock-mode' ensure both first and last on `post-command-hook'. | 366 ;; - Made `lazy-lock-mode' ensure both first and last on `post-command-hook' |
278 ;; - Made `lazy-lock-mode' ensure `font-lock-mode' is on. | 367 ;; - Made `lazy-lock-mode' ensure `font-lock-mode' is on |
279 ;; - Wrap `lazy-lock-post-command-fontify-stealthily' for errors (David Karr). | 368 ;; - Wrap `lazy-lock-post-command-fontify-stealthily' for errors (David Karr) |
280 ;; - Added `calcDigit-key' to `lazy-lock-ignore-commands' (Bob Glickstein). | 369 ;; - Added `calcDigit-key' to `lazy-lock-ignore-commands' (Bob Glickstein) |
281 ;; - Wrap `lazy-lock-running-xemacs-p' with `eval-and-compile' (Erik Naggum). | 370 ;; - Wrap `lazy-lock-running-xemacs-p' with `eval-and-compile' (Erik Naggum) |
282 ;; - XEmacs: Fix use of `previous-single-property-change' (Jim Thompson). | 371 ;; - XEmacs: Fix use of `previous-single-property-change' (Jim Thompson) |
283 ;; - XEmacs: Fix `next-single-property-change' fix for 19.11 (Jim Thompson). | 372 ;; - XEmacs: Fix `next-single-property-change' fix for 19.11 (Jim Thompson) |
284 ;; - Added `lazy-lock-post-resize-fontify-windows' to fontify on resizing. | 373 ;; - Added `lazy-lock-post-resize-fontify-windows' to fontify on resizing |
285 ;; - Adds globally to `window-size-change-functions'. | 374 ;; - Adds globally to `window-size-change-functions' |
286 ;; - Added `lazy-lock-post-setup-fontify-windows' to fontify after start up. | 375 ;; - Added `lazy-lock-post-setup-fontify-windows' to fontify after start up |
287 ;; - Adds globally to `window-setup-hook'. | 376 ;; - Adds globally to `window-setup-hook' |
288 ;; - Made `lazy-lock-post-command-fontify-windows' check for `input-pending-p'. | 377 ;; - Made `lazy-lock-post-command-fontify-windows' check for `input-pending-p' |
289 ;; - Made `save-selected-window' to restore the `selected-window'. | 378 ;; - Made `save-selected-window' to restore the `selected-window' |
290 ;; - Use `save-selected-window' rather than `save-window-excursion'. | 379 ;; - Use `save-selected-window' rather than `save-window-excursion' |
291 ;; 1.11--1.12: | 380 ;; 1.11--1.12: |
292 ;; - Made `lazy-lock-post-command-fontify-windows' do `set-buffer' first. | 381 ;; - Made `lazy-lock-post-command-fontify-windows' do `set-buffer' first |
293 ;; - Made `lazy-lock-fontify-stealthily' respect narrowing before point. | 382 ;; - Made `lazy-lock-fontify-stealthily' respect narrowing before point |
294 ;; - Added `lazy-lock-post-setup-ediff-control-frame' for Ediff control frame. | 383 ;; - Added `lazy-lock-post-setup-ediff-control-frame' for Ediff control frame |
295 ;; - Adds globally to `ediff-after-setup-control-frame-hooks'. | 384 ;; - Adds globally to `ediff-after-setup-control-frame-hooks' |
296 ;; - Wrap `save-selected-window' with `save-excursion' for `current-buffer'. | 385 ;; - Wrap `save-selected-window' with `save-excursion' for `current-buffer' |
297 ;; 1.12--1.13: | 386 ;; 1.12--1.13: |
298 ;; - XEmacs: Add `lazy-lock-after-fontify-buffer' to the Font Lock hook. | 387 ;; - XEmacs: Add `lazy-lock-after-fontify-buffer' to the Font Lock hook |
299 ;; - Made `buffer-file-truename' also wrapped for supersession (Rick Sladkey). | 388 ;; - Made `buffer-file-truename' also wrapped for supersession (Rick Sladkey) |
300 ;; - Made `font-lock-beginning-of-syntax-function' wrapped for fontification. | 389 ;; - Made `font-lock-beginning-of-syntax-function' wrapped for fontification |
301 ;; - Added `lazy-lock-stealth-verbose' (after harassment from Ben Wing). | 390 ;; - Added `lazy-lock-stealth-verbose' (after harassment from Ben Wing) |
302 ;; - XEmacs: Made `font-lock-verbose' wrapped for stealth fontification. | 391 ;; - XEmacs: Made `font-lock-verbose' wrapped for stealth fontification |
303 ;; 1.13--1.14: | 392 ;; 1.13--1.14: |
304 ;; - Wrap `lazy-lock-colour-invisible' for `set-face-foreground' (Jari Aalto). | 393 ;; - Wrap `lazy-lock-colour-invisible' for `set-face-foreground' (Jari Aalto) |
305 ;; 1.14--1.15: | 394 ;; 1.14--1.15: |
306 ;; - Made `lazy-lock-post-command-setup'; may add to `post-command-idle-hook'. | 395 ;; - Made `lazy-lock-post-command-setup'; may add to `post-command-idle-hook' |
396 ;; 1.15--1.16: | |
397 ;; - Test `emacs-major-version' as well as `emacs-minor-version' | |
398 ;; - Barf if Emacs 19.30 or up is running | |
399 ;; - Adds globally to `ediff-after-setup-control-frame-hook' too | |
400 ;; - Renamed `lazy-lock-running-xemacs-p' to `lazy-lock-running-xemacs' | |
401 ;; - Removed `lazy-lock-submit-bug-report' and bade farewell | |
307 | 402 |
403 ;;; Code: | |
404 | |
308 (require 'font-lock) | 405 (require 'font-lock) |
309 | 406 |
407 ;; Make sure lazy-lock.el isn't depreciated. | |
408 (if (if (save-match-data (string-match "Lucid\\|XEmacs" (emacs-version))) | |
409 nil | |
410 (or (> emacs-major-version 19) (> emacs-minor-version 29))) | |
411 (error "`lazy-lock' version 2 should be used for Emacs 19.30 or later")) | |
412 | |
310 (eval-when-compile | 413 (eval-when-compile |
311 ;; Only `require' so `ediff-multiframe-setup-p' is expanded at compile time. | 414 ;; |
312 (condition-case nil (require 'ediff) (file-error)) | 415 ;; We don't do this at the top-level as we only use non-autoloaded macros. |
416 (require 'cl) | |
417 ;; | |
313 ;; Well, shouldn't Lazy Lock be as lazy as possible? | 418 ;; Well, shouldn't Lazy Lock be as lazy as possible? |
314 ;(setq byte-compile-dynamic t byte-compile-dynamic-docstrings t) | 419 (setq byte-compile-dynamic t byte-compile-dynamic-docstrings t)) |
315 ;; Shut Emacs' byte-compiler up (cf. stop me getting mail from users). | 420 |
316 (setq byte-compile-warnings '(free-vars callargs redefine))) | |
317 | |
318 (defun lazy-lock-submit-bug-report () | |
319 "Submit via mail a bug report on lazy-lock.el." | |
320 (interactive) | |
321 (require 'reporter) | |
322 (let ((reporter-prompt-for-summary-p t)) | |
323 (reporter-submit-bug-report "simon@gnu.ai.mit.edu" "lazy-lock 1.15" | |
324 '(lazy-lock-walk-windows lazy-lock-continuity-time | |
325 lazy-lock-stealth-time lazy-lock-stealth-nice | |
326 lazy-lock-stealth-lines lazy-lock-stealth-verbose | |
327 lazy-lock-hide-invisible lazy-lock-invisible-foreground | |
328 lazy-lock-minimum-size lazy-lock-ignore-commands) | |
329 nil nil | |
330 (concat "Hi Si., | |
331 | |
332 I want to report a bug. I've read the `Bugs' section of `Info' on Emacs, so I | |
333 know how to make a clear and unambiguous report. To reproduce the bug: | |
334 | |
335 Start a fresh Emacs via `" invocation-name " -no-init-file -no-site-file'. | |
336 In the `*scratch*' buffer, evaluate:")))) | |
337 | |
338 ;; Let's define `emacs-minor-version' if no-one else has. | |
339 (if (not (boundp 'emacs-minor-version)) | |
340 (eval-and-compile | |
341 (defconst emacs-minor-version | |
342 (save-match-data | |
343 (string-match "^[0-9]+\\.\\([0-9]+\\)" emacs-version) | |
344 (string-to-int | |
345 (substring emacs-version (match-beginning 1) (match-end 1))))))) | |
346 | |
347 ;; Yuck, but we make so much use of this variable it's probably worth it. | |
348 (eval-and-compile | 421 (eval-and-compile |
349 (defconst lazy-lock-running-xemacs-p | 422 ;; Yuck, but we make so much use of this variable it's probably worth it. |
423 (defconst lazy-lock-running-xemacs | |
350 (not (null (save-match-data (string-match "Lucid" emacs-version)))))) | 424 (not (null (save-match-data (string-match "Lucid" emacs-version)))))) |
351 | 425 |
352 (defvar lazy-lock-cache-start nil) ; for window fontifiction | 426 (defvar lazy-lock-cache-start nil) ; for window fontifiction |
353 (defvar lazy-lock-cache-end nil) ; for window fontifiction | 427 (defvar lazy-lock-cache-end nil) ; for window fontifiction |
354 (defvar lazy-lock-cache-continue nil) ; for stealth fontifiction | 428 (defvar lazy-lock-cache-continue nil) ; for stealth fontifiction |
355 | |
356 ;; XEmacs change | |
357 ;;;###autoload | |
358 (defvar lazy-lock-mode nil) ; for modeline | 429 (defvar lazy-lock-mode nil) ; for modeline |
359 | 430 |
360 ;; User Variables: | 431 ;; User Variables: |
361 | 432 |
362 (defvar lazy-lock-minimum-size (* 25 1024) | 433 (defvar lazy-lock-minimum-size (* 25 1024) |
369 If `all-frames', fontify windows even on other frames. | 440 If `all-frames', fontify windows even on other frames. |
370 A non-nil value slows down redisplay.") | 441 A non-nil value slows down redisplay.") |
371 | 442 |
372 ;; XEmacs 19.11 and below exercise a bug in the Xt event loop. | 443 ;; XEmacs 19.11 and below exercise a bug in the Xt event loop. |
373 (defvar lazy-lock-continuity-time | 444 (defvar lazy-lock-continuity-time |
374 (if (or (not lazy-lock-running-xemacs-p) (> emacs-minor-version 11)) | 445 (cond ((not lazy-lock-running-xemacs) |
375 0 | 446 0) |
376 (if (featurep 'lisp-float-type) 0.001 1)) | 447 ((and (= emacs-major-version 19) (< emacs-minor-version 12)) |
448 (if (featurep 'lisp-float-type) (/ (float 1) (float 1000)) 1)) | |
449 (t | |
450 0)) | |
377 "*Time in seconds to delay before normal window fontification. | 451 "*Time in seconds to delay before normal window fontification. |
378 Window fontification occurs if there is no input within this time.") | 452 Window fontification occurs if there is no input within this time.") |
379 | 453 |
380 ;; `previous-single-property-change' at `point-min' up to Emacs 19.25 is fatal. | 454 ;; `previous-single-property-change' at `point-min' up to Emacs 19.25 is fatal. |
381 ;; `text-property-any', `text-property-not-all' and | 455 ;; `text-property-any', `text-property-not-all' and |
382 ;; `next-single-property-change' up to XEmacs 19.11 are too broke. | 456 ;; `next-single-property-change' up to XEmacs 19.11 are too broke. |
383 (defvar lazy-lock-stealth-time | 457 (defvar lazy-lock-stealth-time |
384 (if (> emacs-minor-version (if lazy-lock-running-xemacs-p 11 25)) 30) | 458 (when (or (> emacs-major-version 19) |
459 (and (not lazy-lock-running-xemacs) (> emacs-minor-version 25)) | |
460 (and lazy-lock-running-xemacs (> emacs-minor-version 11))) | |
461 30) | |
385 "*Time in seconds to delay before beginning stealth fontification. | 462 "*Time in seconds to delay before beginning stealth fontification. |
386 Stealth fontification occurs if there is no input within this time. | 463 Stealth fontification occurs if there is no input within this time. |
387 If nil, means no fontification by stealth.") | 464 If nil, means no fontification by stealth.") |
388 | 465 |
389 (defvar lazy-lock-stealth-lines | 466 (defvar lazy-lock-stealth-lines |
390 (cond ((boundp 'font-lock-maximum-decoration) | 467 (if lazy-lock-running-xemacs |
391 (if font-lock-maximum-decoration 75 150)) | 468 (if font-lock-maximum-decoration 50 100) |
392 ((boundp 'font-lock-use-maximal-decoration) | 469 (if font-lock-maximum-decoration 100 250)) |
393 (if font-lock-use-maximal-decoration 50 100)) | |
394 (t | |
395 50)) | |
396 "*If non-nil, the maximum size of a chunk of stealth fontification. | 470 "*If non-nil, the maximum size of a chunk of stealth fontification. |
397 Each iteration of stealth fontification can fontify this number of lines. | 471 Each iteration of stealth fontification can fontify this number of lines. |
398 To speed up input response during stealth fontification, at the cost of stealth | 472 To speed up input response during stealth fontification, at the cost of stealth |
399 taking longer to fontify, you could reduce the value of this variable. | 473 taking longer to fontify, you could reduce the value of this variable. |
400 If nil, means use `window-height' for the maximum chunk size.") | 474 If nil, means use `window-height' for the maximum chunk size.") |
401 | 475 |
402 (defvar lazy-lock-stealth-nice (if (featurep 'lisp-float-type) 0.125 1) | 476 (defvar lazy-lock-stealth-nice |
477 (if lazy-lock-running-xemacs | |
478 (if (featurep 'lisp-float-type) (/ (float 1) (float 4)) 1) | |
479 (if (featurep 'lisp-float-type) (/ (float 1) (float 8)) 1)) | |
403 "*Time in seconds to pause during chunks of stealth fontification. | 480 "*Time in seconds to pause during chunks of stealth fontification. |
404 To reduce machine load during stealth fontification, at the cost of stealth | 481 To reduce machine load during stealth fontification, at the cost of stealth |
405 taking longer to fontify, you could increase the value of this variable.") | 482 taking longer to fontify, you could increase the value of this variable.") |
406 | 483 |
407 (defvar lazy-lock-stealth-verbose font-lock-verbose | 484 (defvar lazy-lock-stealth-verbose font-lock-verbose |
416 (if (fboundp 'calc) '(calcDigit-key))) | 493 (if (fboundp 'calc) '(calcDigit-key))) |
417 "A list of commands after which fontification should not occur. | 494 "A list of commands after which fontification should not occur. |
418 To speed up typing response, at the cost of Lazy Lock not fontifying when | 495 To speed up typing response, at the cost of Lazy Lock not fontifying when |
419 insertion causes scrolling, you could add `self-insert-command' to this list.") | 496 insertion causes scrolling, you could add `self-insert-command' to this list.") |
420 | 497 |
421 (defvar lazy-lock-hide-invisible lazy-lock-running-xemacs-p | 498 (defvar lazy-lock-hide-invisible lazy-lock-running-xemacs |
422 "*If non-nil, hide invisible text while it is fontified. | 499 "*If non-nil, hide invisible text while it is fontified. |
423 If non-nil, redisplay is delayed until after fontification occurs. If nil, | 500 If non-nil, redisplay is delayed until after fontification occurs. If nil, |
424 text is shown (in `lazy-lock-invisible-foreground') while it is fontified. | 501 text is shown (in `lazy-lock-invisible-foreground') while it is fontified. |
425 A non-nil value slows down redisplay and can slow down cursor motion.") | 502 A non-nil value slows down redisplay and can slow down cursor motion.") |
426 | 503 |
482 ;;;###autoload | 559 ;;;###autoload |
483 (defun turn-on-lazy-lock () | 560 (defun turn-on-lazy-lock () |
484 "Unconditionally turn on Lazy Lock mode." | 561 "Unconditionally turn on Lazy Lock mode." |
485 (lazy-lock-mode 1)) | 562 (lazy-lock-mode 1)) |
486 | 563 |
487 (if (< emacs-minor-version (if lazy-lock-running-xemacs-p 12 29)) | 564 (when (and (= emacs-major-version 19) |
488 ;; We don't need this in Emacs 19.29 or XEmacs 19.12. | 565 (< emacs-minor-version (if lazy-lock-running-xemacs 12 29))) |
489 (defun lazy-lock-fontify-buffer () | 566 ;; We don't need this in Emacs 19.29 or XEmacs 19.12. |
490 "Fontify the current buffer where necessary." | 567 (defun lazy-lock-fontify-buffer () |
491 (interactive) | 568 "Fontify the current buffer where necessary." |
492 (lazy-lock-fontify-region (point-min) (point-max)))) | 569 (interactive) |
570 (lazy-lock-fontify-region (point-min) (point-max)))) | |
493 | 571 |
494 ;; API Functions: | 572 ;; API Functions: |
495 | 573 |
496 (defun lazy-lock-fontify-region (start end &optional buffer) | 574 (defun lazy-lock-fontify-region (start end &optional buffer) |
497 "Fontify between START and END in BUFFER where necessary." | 575 "Fontify between START and END in BUFFER where necessary." |
511 (put-text-property (point-min) (point-max) 'fontified t) | 589 (put-text-property (point-min) (point-max) 'fontified t) |
512 (or modified (set-buffer-modified-p nil)))) | 590 (or modified (set-buffer-modified-p nil)))) |
513 | 591 |
514 ;; Just a cleaner-looking way of coping with Emacs' and XEmacs' `sit-for'. | 592 ;; Just a cleaner-looking way of coping with Emacs' and XEmacs' `sit-for'. |
515 (defmacro lazy-lock-sit-for (seconds &optional nodisp) | 593 (defmacro lazy-lock-sit-for (seconds &optional nodisp) |
516 (if lazy-lock-running-xemacs-p | 594 (if lazy-lock-running-xemacs |
517 (` (sit-for (, seconds) (, nodisp))) | 595 (` (sit-for (, seconds) (, nodisp))) |
518 (` (sit-for (, seconds) 0 (, nodisp))))) | 596 (` (sit-for (, seconds) 0 (, nodisp))))) |
519 | 597 |
520 ;; Using `save-window-excursion' provokes `window-size-change-functions'. | 598 ;; Using `save-window-excursion' provokes `window-size-change-functions'. |
521 ;; I prefer `save-walking-excursion', of course, because I have a warped mind. | 599 ;; I prefer `save-walking-excursion', of course, because I have a warped mind. |
522 (if (fboundp 'save-selected-window) | 600 (unless (fboundp 'save-selected-window) |
523 nil | |
524 (eval-and-compile | 601 (eval-and-compile |
525 (defmacro save-selected-window (&rest body) | 602 (defmacro save-selected-window (&rest body) |
526 "Execute the BODY forms, restoring the selected window. | 603 "Execute the BODY forms, restoring the selected window. |
527 Does not restore the value of point in the selected window, or anything else." | 604 Does not restore the value of point in the selected window, or anything else." |
528 (` (let ((original-window (selected-window))) | 605 (` (let ((original-window (selected-window))) |
534 ;; Functions for hooks: | 611 ;; Functions for hooks: |
535 | 612 |
536 (defun lazy-lock-post-command-fontify-windows () | 613 (defun lazy-lock-post-command-fontify-windows () |
537 ;; We might not be where we think we are, since `post-command-hook' is run | 614 ;; We might not be where we think we are, since `post-command-hook' is run |
538 ;; before `command_loop_1' makes sure we have the correct buffer selected. | 615 ;; before `command_loop_1' makes sure we have the correct buffer selected. |
539 (set-buffer (window-buffer)) | 616 ; (set-buffer (window-buffer)) |
540 ;; Do groovy things if (a) not in a macro, (b) no input pending, (c) got a | 617 ;; Do groovy things if (a) not in a macro, (b) no input pending, (c) got a |
541 ;; real command, (d) not in the minibuffer, and (e) no input after waiting | 618 ;; real command, (d) not in the minibuffer, and (e) no input after waiting |
542 ;; for `lazy-lock-continuity-time'. | 619 ;; for `lazy-lock-continuity-time'. |
543 (if (or executing-kbd-macro | 620 (if (or executing-kbd-macro |
544 (input-pending-p) | 621 (input-pending-p) |
594 | 671 |
595 ;; Functions for fontification: | 672 ;; Functions for fontification: |
596 | 673 |
597 (defun lazy-lock-fontify-window () | 674 (defun lazy-lock-fontify-window () |
598 ;; Fontify the visible part of the buffer where necessary. | 675 ;; Fontify the visible part of the buffer where necessary. |
599 (let ((ws (if lazy-lock-hide-invisible | 676 (let (ws we wh) |
600 (save-excursion | 677 ;; Find the bounds of the visible part exactly or conservatively. |
601 (end-of-line) (forward-line (- (window-height))) (point)) | 678 (if (not lazy-lock-hide-invisible) |
602 (min (max (window-start) (point-min)) (point-max)))) | 679 (setq ws (min (max (window-start) (point-min)) (point-max)) |
603 (we (if lazy-lock-hide-invisible | 680 we (min (max (1- (window-end)) (point-min)) (point-max))) |
604 (save-excursion | 681 (setq wh (window-height) ; Buggy: (window-displayed-height) |
605 (end-of-line) (forward-line (window-height)) (point)) | 682 ws (save-excursion (forward-line (- wh)) (point)) |
606 (min (max (1- (window-end)) (point-min)) (point-max))))) | 683 we (save-excursion (forward-line wh) (point)))) |
684 ;; Find whether bounds have changed since previous fontification. | |
607 (if (or (/= ws lazy-lock-cache-start) (/= we lazy-lock-cache-end)) | 685 (if (or (/= ws lazy-lock-cache-start) (/= we lazy-lock-cache-end)) |
608 ;; Find where we haven't `fontified' before. | 686 ;; Find where we haven't `fontified' before. |
609 (let* ((start (or (text-property-not-all ws we 'fontified t) ws)) | 687 (let* ((start (or (text-property-not-all ws we 'fontified t) ws)) |
610 (end (or (text-property-any start we 'fontified t) we)) | 688 (end (or (text-property-any start we 'fontified t) we)) |
611 (modified (buffer-modified-p)) (inhibit-read-only t) | 689 (modified (buffer-modified-p)) (inhibit-read-only t) |
730 (let ((size 0) (start (point-min)) (max (point-max)) end) | 808 (let ((size 0) (start (point-min)) (max (point-max)) end) |
731 (while (setq start (text-property-any start max 'fontified t)) | 809 (while (setq start (text-property-any start max 'fontified t)) |
732 (setq end (or (text-property-not-all start max 'fontified t) max) | 810 (setq end (or (text-property-not-all start max 'fontified t) max) |
733 size (+ size (- end start)) | 811 size (+ size (- end start)) |
734 start end)) | 812 start end)) |
735 ;; Saying "99% done" is probably better than "100% done" when it isn't. | 813 ;; Float because using integer multiplication will frequently overflow. |
736 (truncate (/ (* size 100.0) (buffer-size)))))) | 814 (truncate (* (/ (float size) (point-max)) 100))))) |
737 | 815 |
738 (defun lazy-lock-colour-invisible () | 816 (defun lazy-lock-colour-invisible () |
739 ;; Fontify the current buffer in `lazy-lock-invisible-face'. | 817 ;; Fontify the current buffer in `lazy-lock-invisible-face'. |
740 (save-restriction | 818 (save-restriction |
741 (widen) | 819 (widen) |
756 (or modified (set-buffer-modified-p nil))))) | 834 (or modified (set-buffer-modified-p nil))))) |
757 | 835 |
758 ;; Functions for Emacs: | 836 ;; Functions for Emacs: |
759 | 837 |
760 ;; This fix is for a number of bugs in the function in Emacs 19.28. | 838 ;; This fix is for a number of bugs in the function in Emacs 19.28. |
761 (if (and (not lazy-lock-running-xemacs-p) (< emacs-minor-version 29)) | 839 (when (and (not lazy-lock-running-xemacs) |
762 (defun font-lock-fontify-region (start end &optional loudly) | 840 (= emacs-major-version 19) (< emacs-minor-version 28)) |
763 "Put proper face on each string and comment between START and END." | 841 (defun font-lock-fontify-region (start end &optional loudly) |
764 (save-excursion | 842 "Put proper face on each string and comment between START and END." |
765 (save-restriction | 843 (save-excursion |
766 (widen) | 844 (save-restriction |
767 (goto-char start) | 845 (widen) |
768 (beginning-of-line) | 846 (goto-char start) |
769 (if loudly (message "Fontifying %s... (syntactically...)" (buffer-name))) | 847 (beginning-of-line) |
770 (let ((inhibit-read-only t) (buffer-undo-list t) | 848 (if loudly (message "Fontifying %s... (syntactically...)" (buffer-name))) |
771 buffer-file-name buffer-file-truename | 849 (let ((inhibit-read-only t) (buffer-undo-list t) |
772 (modified (buffer-modified-p)) | 850 buffer-file-name buffer-file-truename |
773 (old-syntax (syntax-table)) | 851 (modified (buffer-modified-p)) |
774 (synstart (if comment-start-skip | 852 (old-syntax (syntax-table)) |
775 (concat "\\s\"\\|" comment-start-skip) | 853 (synstart (if comment-start-skip |
776 "\\s\"")) | 854 (concat "\\s\"\\|" comment-start-skip) |
777 (comstart (if comment-start-skip | 855 "\\s\"")) |
778 (concat "\\s<\\|" comment-start-skip) | 856 (comstart (if comment-start-skip |
779 "\\s<")) | 857 (concat "\\s<\\|" comment-start-skip) |
780 (startline (point)) | 858 "\\s<")) |
781 state prev prevstate) | 859 (startline (point)) |
782 (unwind-protect | 860 state prev prevstate) |
783 (progn | 861 (unwind-protect |
784 (if font-lock-syntax-table | 862 (progn |
785 (set-syntax-table font-lock-syntax-table)) | 863 (if font-lock-syntax-table |
786 ;; Find the state at the line-beginning before START. | 864 (set-syntax-table font-lock-syntax-table)) |
787 (if (eq startline font-lock-cache-position) | 865 ;; Find the state at the line-beginning before START. |
788 (setq state font-lock-cache-state) | 866 (if (eq startline font-lock-cache-position) |
789 ;; Find outermost containing sexp. | 867 (setq state font-lock-cache-state) |
790 (beginning-of-defun) | 868 ;; Find outermost containing sexp. |
791 ;; Find the state at STARTLINE. | 869 (beginning-of-defun) |
792 (while (< (point) startline) | 870 ;; Find the state at STARTLINE. |
793 (setq state (parse-partial-sexp (point) startline 0))) | 871 (while (< (point) startline) |
794 (setq font-lock-cache-state state | 872 (setq state (parse-partial-sexp (point) startline 0))) |
795 font-lock-cache-position (point))) | 873 (setq font-lock-cache-state state |
796 ;; Now find the state precisely at START. | 874 font-lock-cache-position (point))) |
797 (setq state (parse-partial-sexp (point) start nil nil state)) | 875 ;; Now find the state precisely at START. |
798 ;; If the region starts inside a string, show the extent of it. | 876 (setq state (parse-partial-sexp (point) start nil nil state)) |
799 (if (nth 3 state) | 877 ;; If the region starts inside a string, show the extent of it. |
800 (let ((beg (point))) | 878 (if (nth 3 state) |
801 (while (and (re-search-forward "\\s\"" end 'move) | 879 (let ((beg (point))) |
802 (nth 3 (parse-partial-sexp beg (point) nil nil | 880 (while (and (re-search-forward "\\s\"" end 'move) |
803 state)))) | 881 (nth 3 (parse-partial-sexp beg (point) nil nil |
804 (put-text-property beg (point) 'face font-lock-string-face) | 882 state)))) |
805 (setq state (parse-partial-sexp beg (point) | 883 (put-text-property beg (point) 'face font-lock-string-face) |
806 nil nil state)))) | 884 (setq state (parse-partial-sexp beg (point) |
807 ;; Likewise for a comment. | 885 nil nil state)))) |
808 (if (or (nth 4 state) (nth 7 state)) | 886 ;; Likewise for a comment. |
809 (let ((beg (point))) | 887 (if (or (nth 4 state) (nth 7 state)) |
810 (save-restriction | 888 (let ((beg (point))) |
811 (narrow-to-region (point-min) end) | 889 (save-restriction |
812 (condition-case nil | 890 (narrow-to-region (point-min) end) |
813 (progn | 891 (condition-case nil |
814 (re-search-backward comstart (point-min) 'move) | 892 (progn |
815 (forward-comment 1) | 893 (re-search-backward comstart (point-min) 'move) |
816 ;; forward-comment skips all whitespace, | 894 (forward-comment 1) |
817 ;; so go back to the real end of the comment. | 895 ;; forward-comment skips all whitespace, |
818 (skip-chars-backward " \t")) | 896 ;; so go back to the real end of the comment. |
819 (error (goto-char end)))) | 897 (skip-chars-backward " \t")) |
820 (put-text-property beg (point) 'face | 898 (error (goto-char end)))) |
821 font-lock-comment-face) | 899 (put-text-property beg (point) 'face |
822 (setq state (parse-partial-sexp beg (point) | 900 font-lock-comment-face) |
823 nil nil state)))) | 901 (setq state (parse-partial-sexp beg (point) |
824 ;; Find each interesting place between here and END. | 902 nil nil state)))) |
825 (while (and (< (point) end) | 903 ;; Find each interesting place between here and END. |
826 (setq prev (point) prevstate state) | 904 (while (and (< (point) end) |
827 (re-search-forward synstart end t) | 905 (setq prev (point) prevstate state) |
828 (progn | 906 (re-search-forward synstart end t) |
829 ;; Clear out the fonts of what we skip over. | 907 (progn |
830 (remove-text-properties prev (point) '(face nil)) | 908 ;; Clear out the fonts of what we skip over. |
831 ;; Verify the state at that place | 909 (remove-text-properties prev (point) '(face nil)) |
832 ;; so we don't get fooled by \" or \;. | 910 ;; Verify the state at that place |
833 (setq state (parse-partial-sexp prev (point) | 911 ;; so we don't get fooled by \" or \;. |
834 nil nil state)))) | 912 (setq state (parse-partial-sexp prev (point) |
835 (let ((here (point))) | 913 nil nil state)))) |
836 (if (or (nth 4 state) (nth 7 state)) | 914 (let ((here (point))) |
837 ;; We found a real comment start. | 915 (if (or (nth 4 state) (nth 7 state)) |
916 ;; We found a real comment start. | |
917 (let ((beg (match-beginning 0))) | |
918 (goto-char beg) | |
919 (save-restriction | |
920 (narrow-to-region (point-min) end) | |
921 (condition-case nil | |
922 (progn | |
923 (forward-comment 1) | |
924 ;; forward-comment skips all whitespace, | |
925 ;; so go back to the real end of the comment. | |
926 (skip-chars-backward " \t")) | |
927 (error (goto-char end)))) | |
928 (put-text-property beg (point) 'face | |
929 font-lock-comment-face) | |
930 (setq state (parse-partial-sexp here (point) | |
931 nil nil state))) | |
932 (if (nth 3 state) | |
838 (let ((beg (match-beginning 0))) | 933 (let ((beg (match-beginning 0))) |
839 (goto-char beg) | 934 (while (and (re-search-forward "\\s\"" end 'move) |
840 (save-restriction | 935 (nth 3 (parse-partial-sexp |
841 (narrow-to-region (point-min) end) | 936 here (point) nil nil state)))) |
842 (condition-case nil | |
843 (progn | |
844 (forward-comment 1) | |
845 ;; forward-comment skips all whitespace, | |
846 ;; so go back to the real end of the comment. | |
847 (skip-chars-backward " \t")) | |
848 (error (goto-char end)))) | |
849 (put-text-property beg (point) 'face | 937 (put-text-property beg (point) 'face |
850 font-lock-comment-face) | 938 font-lock-string-face) |
851 (setq state (parse-partial-sexp here (point) | 939 (setq state (parse-partial-sexp here (point) |
852 nil nil state))) | 940 nil nil state)))))) |
853 (if (nth 3 state) | 941 ;; Make sure PREV is non-nil after the loop |
854 (let ((beg (match-beginning 0))) | 942 ;; only if it was set on the very last iteration. |
855 (while (and (re-search-forward "\\s\"" end 'move) | 943 (setq prev nil))) |
856 (nth 3 (parse-partial-sexp | 944 (set-syntax-table old-syntax) |
857 here (point) nil nil state)))) | 945 (and prev |
858 (put-text-property beg (point) 'face | 946 (remove-text-properties prev end '(face nil))) |
859 font-lock-string-face) | 947 (and (buffer-modified-p) |
860 (setq state (parse-partial-sexp here (point) | 948 (not modified) |
861 nil nil state)))))) | 949 (set-buffer-modified-p nil)))))))) |
862 ;; Make sure PREV is non-nil after the loop | |
863 ;; only if it was set on the very last iteration. | |
864 (setq prev nil))) | |
865 (set-syntax-table old-syntax) | |
866 (and prev | |
867 (remove-text-properties prev end '(face nil))) | |
868 (and (buffer-modified-p) | |
869 (not modified) | |
870 (set-buffer-modified-p nil)))))))) | |
871 | 950 |
872 ;; Functions for XEmacs: | 951 ;; Functions for XEmacs: |
873 | 952 |
874 ;; These fix bugs in `text-property-any' and `text-property-not-all'. They may | 953 ;; These fix bugs in `text-property-any' and `text-property-not-all'. They may |
875 ;; not work perfectly in 19.11 and below because `next-single-property-change' | 954 ;; not work perfectly in 19.11 and below because `next-single-property-change' |
876 ;; is also broke and not easily fixable in Lisp. | 955 ;; is also broke and not easily fixable in Lisp. |
877 (if (and lazy-lock-running-xemacs-p (< emacs-minor-version 12)) | 956 (when (and lazy-lock-running-xemacs |
878 (progn | 957 (= emacs-major-version 19) (< emacs-minor-version 12)) |
879 ;; Loop through property changes until found. This fix includes a work | 958 ;; Loop through property changes until found. This fix includes a work |
880 ;; around which prevents a bug in `window-start' causing a barf here. | 959 ;; around which prevents a bug in `window-start' causing a barf here. |
881 (defun text-property-any (start end prop value &optional buffer) | 960 (defun text-property-any (start end prop value &optional buffer) |
882 "Check text from START to END to see if PROP is ever `eq' to VALUE. | 961 "Check text from START to END to see if PROP is ever `eq' to VALUE. |
883 If so, return the position of the first character whose PROP is `eq' | 962 If so, return the position of the first character whose PROP is `eq' |
884 to VALUE. Otherwise return nil." | 963 to VALUE. Otherwise return nil." |
885 (let ((start (min start end)) (end (max start end))) | 964 (let ((start (min start end)) (end (max start end))) |
886 (while (and start (not (eq (get-text-property start prop buffer) value))) | 965 (while (and start (not (eq (get-text-property start prop buffer) value))) |
887 (setq start (next-single-property-change start prop buffer end))) | 966 (setq start (next-single-property-change start prop buffer end))) |
888 start)) | 967 start)) |
889 ;; No need to loop here; if it's not at START it's at the next change. | 968 ;; No need to loop here; if it's not at START it's at the next change. |
890 ;; However, `next-single-property-change' sometimes returns LIMIT, or | 969 ;; However, `next-single-property-change' sometimes returns LIMIT, or |
891 ;; `point-max', if no change is found and sometimes returns nil. | 970 ;; `point-max', if no change is found and sometimes returns nil. |
892 (defun text-property-not-all (start end prop value &optional buffer) | 971 (defun text-property-not-all (start end prop value &optional buffer) |
893 "Check text from START to END to see if PROP is ever not `eq' to VALUE. | 972 "Check text from START to END to see if PROP is ever not `eq' to VALUE. |
894 If so, return the position of the first character whose PROP is not | 973 If so, return the position of the first character whose PROP is not |
895 `eq' to VALUE. Otherwise, return nil." | 974 `eq' to VALUE. Otherwise, return nil." |
896 (if (not (eq value (get-text-property start prop buffer))) | 975 (if (not (eq value (get-text-property start prop buffer))) |
897 start | 976 start |
898 (let ((next (next-single-property-change start prop buffer end)) | 977 (let ((next (next-single-property-change start prop buffer end)) |
899 (end (or end (save-excursion (and buffer (set-buffer buffer)) | 978 (end (or end (save-excursion (and buffer (set-buffer buffer)) |
900 (point-max))))) | 979 (point-max))))) |
901 (and next (< next end) next)))))) | 980 (and next (< next end) next))))) |
902 | 981 |
903 ;; XEmacs 19.11 function `font-lock-any-extents-p' looks for `text-prop' rather | 982 ;; XEmacs 19.11 function `font-lock-any-extents-p' looks for `text-prop' rather |
904 ;; than `face'. Since `font-lock-unfontify-region' only removes `face', and we | 983 ;; than `face'. Since `font-lock-unfontify-region' only removes `face', and we |
905 ;; have non-font-lock properties hanging about, `text-prop' never gets removed. | 984 ;; have non-font-lock properties hanging about, `text-prop' never gets removed. |
906 ;; Unfortunately `font-lock-any-extents-p' is inlined so we can't redefine it. | 985 ;; Unfortunately `font-lock-any-extents-p' is inlined so we can't redefine it. |
907 (if (and lazy-lock-running-xemacs-p (< emacs-minor-version 12)) | 986 (when (and lazy-lock-running-xemacs |
908 (add-hook 'font-lock-mode-hook | 987 (= emacs-major-version 19) (< emacs-minor-version 12)) |
909 (function (lambda () | 988 (add-hook 'font-lock-mode-hook |
910 (remove-hook 'after-change-functions 'font-lock-after-change-function) | 989 (function (lambda () |
911 (add-hook 'after-change-functions | 990 (remove-hook 'after-change-functions 'font-lock-after-change-function) |
912 (function (lambda (beg end old-len) | 991 (add-hook 'after-change-functions |
913 (let ((a-c-beg beg) (a-c-end end)) | 992 (function (lambda (beg end old-len) |
914 (save-excursion | 993 (let ((a-c-beg beg) (a-c-end end)) |
915 ;; First set `text-prop' to nil for `font-lock-any-extents-p'. | 994 (save-excursion |
916 (goto-char end) (forward-line 1) (setq end (point)) | 995 ;; First set `text-prop' to nil for `font-lock-any-extents-p'. |
917 (goto-char beg) (beginning-of-line) (setq beg (point)) | 996 (goto-char end) (forward-line 1) (setq end (point)) |
918 (put-text-property beg end 'text-prop nil) | 997 (goto-char beg) (beginning-of-line) (setq beg (point)) |
919 ;; Then do the real `font-lock-after-change-function'. | 998 (put-text-property beg end 'text-prop nil) |
920 (font-lock-after-change-function a-c-beg a-c-end old-len) | 999 ;; Then do the real `font-lock-after-change-function'. |
921 ;; Now set `fontified' to t to stop `lazy-lock-fontify-window'. | 1000 (font-lock-after-change-function a-c-beg a-c-end old-len) |
922 (put-text-property beg end 'fontified t)))))))))) | 1001 ;; Now set `fontified' to t to stop `lazy-lock-fontify-window'. |
923 | 1002 (put-text-property beg end 'fontified t)))))))))) |
924 (if (and lazy-lock-running-xemacs-p (>= emacs-minor-version 12)) | 1003 |
925 ;; XEmacs 19.12 font-lock.el's `font-lock-fontify-buffer' runs a hook. | 1004 ;; XEmacs 19.12 font-lock.el's `font-lock-fontify-buffer' runs a hook. |
926 (add-hook 'font-lock-after-fontify-buffer-hook | 1005 (when lazy-lock-running-xemacs |
927 'lazy-lock-after-fontify-buffer)) | 1006 (add-hook 'font-lock-after-fontify-buffer-hook |
928 | 1007 'lazy-lock-after-fontify-buffer)) |
929 ;; Cope with the differences between Emacs and [LX]Emacs. | 1008 |
930 (or (fboundp 'frame-parameters) | 1009 ;; Cope with the differences between Emacs and earlier [LX]Emacs. |
931 (defalias 'frame-parameters 'screen-parameters)) | 1010 (unless (fboundp 'frame-parameters) |
1011 (defalias 'frame-parameters 'screen-parameters)) | |
1012 | |
1013 ;; Cope with the differences between Emacs and earlier [LX]Emacs. Buggy. | |
1014 ;(unless (fboundp 'window-displayed-height) | |
1015 ; (defalias 'window-displayed-height 'window-height)) | |
932 | 1016 |
933 ;; Install ourselves: | 1017 ;; Install ourselves: |
934 | 1018 |
935 ;; We don't install ourselves on `font-lock-mode-hook' as other packages can be | 1019 ;; We don't install ourselves on `font-lock-mode-hook' as other packages can be |
936 ;; used with font-lock.el, and lazy-lock.el should be dumpable without forcing | 1020 ;; used with font-lock.el, and lazy-lock.el should be dumpable without forcing |
939 ;; After a command is run. | 1023 ;; After a command is run. |
940 (lazy-lock-post-command-setup) | 1024 (lazy-lock-post-command-setup) |
941 | 1025 |
942 ;; After some relevant event. | 1026 ;; After some relevant event. |
943 (add-hook 'window-setup-hook 'lazy-lock-post-setup-emacs-fontify-windows) | 1027 (add-hook 'window-setup-hook 'lazy-lock-post-setup-emacs-fontify-windows) |
944 ;Not needed in XEmacs 19.15: | 1028 (add-hook 'window-size-change-functions 'lazy-lock-post-resize-fontify-windows) |
945 ;(add-hook 'window-size-change-functions 'lazy-lock-post-resize-fontify-windows) | |
946 | 1029 |
947 ;; Package-specific. | 1030 ;; Package-specific. |
948 (add-hook 'ediff-after-setup-control-frame-hooks | 1031 (add-hook 'ediff-after-setup-control-frame-hooks ; Emacs 19.29, Ediff 2.26. |
949 'lazy-lock-post-setup-ediff-control-frame) | 1032 'lazy-lock-post-setup-ediff-control-frame) |
1033 (add-hook 'ediff-after-setup-control-frame-hook ; Emacs 19.30, Ediff 2.47. | |
1034 'lazy-lock-post-setup-ediff-control-frame) | |
950 | 1035 |
951 ;; Might as well uninstall too. Package-local symbols would be nice... | 1036 ;; Might as well uninstall too. Package-local symbols would be nice... |
952 (and (fboundp 'unintern) (unintern 'lazy-lock-running-xemacs-p)) | 1037 (when (fboundp 'unintern) |
953 (and (fboundp 'unintern) (unintern 'lazy-lock-sit-for)) | 1038 (unintern 'lazy-lock-running-xemacs) |
954 | 1039 (unintern 'lazy-lock-sit-for)) |
955 ;; Maybe save on the modeline? | 1040 |
956 ;;(setcdr (assq 'font-lock-mode minor-mode-alist) '(" Lazy")) | |
957 | |
958 ;(or (assq 'lazy-lock-mode minor-mode-alist) | |
959 ; (setq minor-mode-alist (cons '(lazy-lock-mode " Lazy") minor-mode-alist))) | |
960 | |
961 ;; XEmacs change: do it the right way. This works with modeline mousing. | |
962 ;;;###autoload | 1041 ;;;###autoload |
963 (add-minor-mode 'lazy-lock-mode " Lazy") | 1042 (when (fboundp 'add-minor-mode) |
1043 (defvar lazy-lock-mode nil) | |
1044 (add-minor-mode 'lazy-lock-mode nil)) | |
1045 ;;;###dont-autoload | |
1046 (unless (assq 'lazy-lock-mode minor-mode-alist) | |
1047 (setq minor-mode-alist (append minor-mode-alist '((lazy-lock-mode nil))))) | |
964 | 1048 |
965 ;; Provide ourselves: | 1049 ;; Provide ourselves: |
966 | 1050 |
967 (provide 'lazy-lock) | 1051 (provide 'lazy-lock) |
968 | 1052 |