Mercurial > hg > xemacs-beta
comparison lisp/packages/lazy-lock.el @ 70:131b0175ea99 r20-0b30
Import from CVS: tag r20-0b30
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:02:59 +0200 |
parents | 4103f0995bd7 |
children | c7528f8e288d |
comparison
equal
deleted
inserted
replaced
69:804d1389bcd6 | 70:131b0175ea99 |
---|---|
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, 1997 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1994, 1995 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.16 | 7 ;; Version: 1.14 |
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-Oct-95|1.14|~/modes/lazy-lock.el.Z| | |
13 | |
14 ;; The archive is archive.cis.ohio-state.edu in /pub/gnu/emacs/elisp-archive. | |
8 | 15 |
9 ;;; This file is part of GNU Emacs. | 16 ;;; This file is part of GNU Emacs. |
10 | 17 |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | 18 ;; GNU Emacs is free software; you can redistribute it and/or modify |
12 ;; it under the terms of the GNU General Public License as published by | 19 ;; it under the terms of the GNU General Public License as published by |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | 24 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 ;; GNU General Public License for more details. | 26 ;; GNU General Public License for more details. |
20 | 27 |
21 ;; You should have received a copy of the GNU General Public License | 28 ;; You should have received a copy of the GNU General Public License |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | 29 ;; along with GNU Emacs; see the file COPYING. If not, write to |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 30 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
24 ;; Boston, MA 02111-1307, USA. | 31 |
32 ;;; Synched up with: Not in FSF. (This seems very strange to me.) | |
25 | 33 |
26 ;;; Commentary: | 34 ;;; Commentary: |
27 | 35 |
28 ;; Purpose: | 36 ;; Purpose: |
29 ;; | 37 ;; |
98 ;; Let me know if you use any other `advice' and I'll put it here. Thanks. | 106 ;; Let me know if you use any other `advice' and I'll put it here. Thanks. |
99 ;; | 107 ;; |
100 ;; These kinds of things with `advice' aren't done automatically because they | 108 ;; These kinds of things with `advice' aren't done automatically because they |
101 ;; cause large packages (advice.el plus bytecomp.el and friends) to be loaded. | 109 ;; cause large packages (advice.el plus bytecomp.el and friends) to be loaded. |
102 | 110 |
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 | |
202 ;; Caveats: | 111 ;; Caveats: |
203 | 112 ;; |
204 ;; Lazy Lock mode does not work efficiently with Outline mode. This is because | 113 ;; Lazy Lock mode does not work efficiently with Outline mode. This is because |
205 ;; when in Outline mode, although text may be hidden (not visible in the | 114 ;; when in Outline mode, although text may be hidden (not visible in the |
206 ;; window), the text is visible to Emacs Lisp code (not surprisingly) and Lazy | 115 ;; window), the text is visible to Emacs Lisp code (not surprisingly) and Lazy |
207 ;; Lock fontifies it mercilessly. Hopefully this will be fixed one day. | 116 ;; Lock fontifies it mercilessly. Hopefully this will be fixed one day. |
208 ;; | 117 ;; |
251 ;; | 160 ;; |
252 ;; The solution is to upgrade! (With thanks to Kevin Broadey for help here.) | 161 ;; The solution is to upgrade! (With thanks to Kevin Broadey for help here.) |
253 ;; | 162 ;; |
254 ;; For XEmacs 19.11 and Lucid Emacs 19.10 users, lazy-lock sort-of works. | 163 ;; For XEmacs 19.11 and Lucid Emacs 19.10 users, lazy-lock sort-of works. |
255 ;; There are bugs in text property and point/window primatives. Upgrade! | 164 ;; There are bugs in text property and point/window primatives. Upgrade! |
256 ;; | 165 |
257 ;; Currently XEmacs does not have the features to support version 2 of | 166 ;; Feedback: |
258 ;; lazy-lock.el. Maybe it will one day. | 167 ;; |
168 ;; Feedback is welcome. | |
169 ;; To submit a bug report (or make comments) please use the mechanism provided: | |
170 ;; | |
171 ;; M-x lazy-lock-submit-bug-report RET | |
259 | 172 |
260 ;; History: | 173 ;; History: |
261 ;; | 174 ;; |
262 ;; 0.01--1.00: | 175 ;; 0.01--1.00: |
263 ;; - Changed name from fore-lock to lazy-lock. Shame though. | 176 ;; - Changed name from fore-lock to lazy-lock. Shame though. |
264 ;; - Dropped `advice'-wrapping completely. Ask me if you're interested in it. | 177 ;; - Dropped `advice'-wrapping completely. Ask me if you're interested in it. |
265 ;; - Made `lazy-lock-mode' ignore `post-command-hook' and `buffer-file-name' | 178 ;; - Made `lazy-lock-mode' ignore `post-command-hook' and `buffer-file-name'. |
266 ;; - Made `lazy-lock-fontify-window' check `lazy-lock-mode' and `this-command' | 179 ;; - Made `lazy-lock-fontify-window' check `lazy-lock-mode' and `this-command'. |
267 ;; - Made `lazy-lock-fontify-window' redisplay via `sit-for' | 180 ;; - Made `lazy-lock-fontify-window' redisplay via `sit-for'. |
268 ;; - Added `lazy-lock-minimum-size' to control `lazy-lock-mode' | 181 ;; - Added `lazy-lock-minimum-size' to control `lazy-lock-mode'. |
269 ;; 1.00--1.01: | 182 ;; 1.00--1.01: |
270 ;; - Added `lazy-lock-fontify-buffer' | 183 ;; - Added `lazy-lock-fontify-buffer'. |
271 ;; - Made `lazy-lock-fontify-window' ignore `lazy-lock-mode' | 184 ;; - Made `lazy-lock-fontify-window' ignore `lazy-lock-mode'. |
272 ;; - Made `lazy-lock-fontify-window' suspicious of `window-' favourites again | 185 ;; - Made `lazy-lock-fontify-window' suspicious of `window-' favourites again. |
273 ;; - Added `lazy-lock-delay-commands' (idea from William G. Dubuque) | 186 ;; - Added `lazy-lock-delay-commands' (idea from William G. Dubuque). |
274 ;; - Added `lazy-lock-ignore-commands' for completeness | 187 ;; - Added `lazy-lock-ignore-commands' for completeness. |
275 ;; - Added `lazy-lock-continuity-time' for normal input delay | 188 ;; - Added `lazy-lock-continuity-time' for normal input delay. |
276 ;; 1.01--1.02: | 189 ;; 1.01--1.02: |
277 ;; - Made `lazy-lock-fontify-window' cope with multiple unfontified regions | 190 ;; - Made `lazy-lock-fontify-window' cope with multiple unfontified regions. |
278 ;; - Made `lazy-lock-mode' remove `fontified' properties if turned off | 191 ;; - Made `lazy-lock-mode' remove `fontified' properties if turned off. |
279 ;; - Made `lazy-lock-fontify-window' fontify by lines | 192 ;; - Made `lazy-lock-fontify-window' fontify by lines. |
280 ;; - Added `lazy-lock-cache-position' buffer local to detect visibility change | 193 ;; - Added `lazy-lock-cache-position' buffer local to detect visibility change. |
281 ;; - Added `lazy-lock-post-command-hook' to do the waiting | 194 ;; - Added `lazy-lock-post-command-hook' to do the waiting. |
282 ;; - Made `lazy-lock-fontify-window' just do the fontification | 195 ;; - Made `lazy-lock-fontify-window' just do the fontification. |
283 ;; - Made `lazy-lock-mode' append `lazy-lock-post-command-hook' | 196 ;; - Made `lazy-lock-mode' append `lazy-lock-post-command-hook'. |
284 ;; - Added `lazy-lock-walk-windows' to hack multi-window motion | 197 ;; - Added `lazy-lock-walk-windows' to hack multi-window motion. |
285 ;; - Made `lazy-lock-post-command-hook' `walk-windows' if variable is non-nil | 198 ;; - Made `lazy-lock-post-command-hook' `walk-windows' if variable is non-nil. |
286 ;; - Removed `lazy-lock-ignore-commands' since insertion may change window | 199 ;; - Removed `lazy-lock-ignore-commands' since insertion may change window. |
287 ;; - Added `lazy-lock-fontify-stealthily' and `lazy-lock-stealth-time' | 200 ;; - Added `lazy-lock-fontify-stealthily' and `lazy-lock-stealth-time'. |
288 ;; - Made `lazy-lock-post-command-hook' use them | 201 ;; - Made `lazy-lock-post-command-hook' use them. |
289 ;; 1.02--1.03: | 202 ;; 1.02--1.03: |
290 ;; - Made `lazy-lock-fontify-stealthily' do `forward-line' not `previous-line' | 203 ;; - Made `lazy-lock-fontify-stealthily' do `forward-line' not `previous-line'. |
291 ;; - Made `lazy-lock-fontify-stealthily' `move-to-window-line' first | 204 ;; - Made `lazy-lock-fontify-stealthily' `move-to-window-line' first. |
292 ;; - Made `lazy-lock-fontify-stealthily' use `text-property-any' for region | 205 ;; - Made `lazy-lock-fontify-stealthily' use `text-property-any' for region. |
293 ;; - Made `lazy-lock-post-command-hook' loop on `lazy-lock-fontify-stealthily' | 206 ;; - Made `lazy-lock-post-command-hook' loop on `lazy-lock-fontify-stealthily'. |
294 ;; 1.03--1.04: | 207 ;; 1.03--1.04: |
295 ;; - Made `lazy-lock-mode' reset `lazy-lock-cache-position' | 208 ;; - Made `lazy-lock-mode' reset `lazy-lock-cache-position'. |
296 ;; - Made `lazy-lock-post-command-hook' `widen' for `if' `text-property-any' | 209 ;; - Made `lazy-lock-post-command-hook' `widen' for `if' `text-property-any'. |
297 ;; - Made `lazy-lock-fontify-stealthily' return `text-property-any' | 210 ;; - Made `lazy-lock-fontify-stealthily' return `text-property-any'. |
298 ;; - Added `lazy-lock-percent-fontified' for a/be-musement | 211 ;; - Added `lazy-lock-percent-fontified' for a/be-musement. |
299 ;; - Made `lazy-lock-post-command-hook' use it | 212 ;; - Made `lazy-lock-post-command-hook' use it. |
300 ;; - Made `lazy-lock-mode' use `make-local-hook' etc. if available | 213 ;; - Made `lazy-lock-mode' use `make-local-hook' etc. if available. |
301 ;; - Made `lazy-lock-mode' use `before-revert-hook' and `after-revert-hook' | 214 ;; - Made `lazy-lock-mode' use `before-revert-hook' and `after-revert-hook'. |
302 ;; - Made `lazy-lock-post-command-hook' protect `deactivate-mark' | 215 ;; - Made `lazy-lock-post-command-hook' protect `deactivate-mark'. |
303 ;; - Adds `lazy-lock-post-command-hook' globally to `post-command-hook' | 216 ;; - Adds `lazy-lock-post-command-hook' globally to `post-command-hook'. |
304 ;; 1.04--1.05: | 217 ;; 1.04--1.05: |
305 ;; - Made `lazy-lock-mode' test `make-local-hook' not `emacs-minor-version' | 218 ;; - Made `lazy-lock-mode' test `make-local-hook' not `emacs-minor-version'. |
306 ;; 1.05--1.06: | 219 ;; 1.05--1.06: |
307 ;; - Added `lazy-lock-ignore-commands' for commands that leave no event but do | 220 ;; - Added `lazy-lock-ignore-commands' for commands that leave no event but do. |
308 ;; - Made `lazy-lock-post-command-hook' check `lazy-lock-ignore-commands' | 221 ;; - Made `lazy-lock-post-command-hook' check `lazy-lock-ignore-commands'. |
309 ;; 1.06--1.07: | 222 ;; 1.06--1.07: |
310 ;; - Removed `before-revert-hook' and `after-revert-hook' use | 223 ;; - Removed `before-revert-hook' and `after-revert-hook' use. |
311 ;; 1.07--1.08: | 224 ;; 1.07--1.08: |
312 ;; - Added `lazy-lock-submit-bug-report' | 225 ;; - Added `lazy-lock-submit-bug-report'. |
313 ;; - Made `lazy-lock-post-command-hook' check `executing-macro' | 226 ;; - Made `lazy-lock-post-command-hook' check `executing-macro'. |
314 ;; - Made it sort-of/almost work for XEmacs (help from Jonas Jarnestrom) | 227 ;; - Made it sort-of/almost work for XEmacs (help from Jonas Jarnestrom). |
315 ;; - XEmacs: Fix `text-property-not-all' (fix based on fast-lock.el 3.05 fix) | 228 ;; - XEmacs: Fix `text-property-not-all' (fix based on fast-lock.el 3.05 fix). |
316 ;; - XEmacs: Set `font-lock-no-comments' and alias `frame-parameters' | 229 ;; - XEmacs: Set `font-lock-no-comments' and alias `frame-parameters'. |
317 ;; - Made `byte-compile-warnings' omit `unresolved' on compilation | 230 ;; - Made `byte-compile-warnings' omit `unresolved' on compilation. |
318 ;; - Made `lazy-lock-post-command-hook' protect `buffer-undo-list' | 231 ;; - Made `lazy-lock-post-command-hook' protect `buffer-undo-list'. |
319 ;; - Moved `deactivate-mark' and `buffer-undo-list' protection to functions | 232 ;; - Moved `deactivate-mark' and `buffer-undo-list' protection to functions. |
320 ;; - Added `lazy-lock-invisible-foreground' (idea from Boris Goldowsky) | 233 ;; - Added `lazy-lock-invisible-foreground' (idea from Boris Goldowsky). |
321 ;; - XEmacs: Fix to use `text-property-not-all' t, not `text-property-any' nil | 234 ;; - XEmacs: Fix to use `text-property-not-all' t, not `text-property-any' nil. |
322 ;; - Made `lazy-lock-percent-fontified' return `round' to an integer | 235 ;; - Made `lazy-lock-percent-fontified' return `round' to an integer. |
323 ;; - XEmacs: Fix `text-property-any' (fix and work around for a bug elsewhere) | 236 ;; - XEmacs: Fix `text-property-any' (fix and work around for a bug elsewhere). |
324 ;; - XEmacs: Fix `lazy-lock-submit-bug-report' for reporter.el & vm-window.el | 237 ;; - XEmacs: Fix `lazy-lock-submit-bug-report' for reporter.el & vm-window.el. |
325 ;; - XEmacs: Made `lazy-lock-fontify-window' loop `while' `<' not `/=' | 238 ;; - XEmacs: Made `lazy-lock-fontify-window' loop `while' `<' not `/='. |
326 ;; - Use `font-lock-after-change-function' to do the fontification | 239 ;; - Use `font-lock-after-change-function' to do the fontification. |
327 ;; 1.08--1.09: | 240 ;; 1.08--1.09: |
328 ;; - Made `lazy-lock-post-command-hook' protect with `condition-case' | 241 ;; - Made `lazy-lock-post-command-hook' protect with `condition-case'. |
329 ;; - Made `lazy-lock-cache-start' to cache `window-start' | 242 ;; - Made `lazy-lock-cache-start' to cache `window-start'. |
330 ;; - Made `lazy-lock-fontify-window' check and cache `lazy-lock-cache-start' | 243 ;; - Made `lazy-lock-fontify-window' check and cache `lazy-lock-cache-start'. |
331 ;; - Renamed `lazy-lock-cache-position' to `lazy-lock-cache-end' | 244 ;; - Renamed `lazy-lock-cache-position' to `lazy-lock-cache-end'. |
332 ;; - XEmacs: Fix for `font-lock-after-change-function' | 245 ;; - XEmacs: Fix for `font-lock-after-change-function'. |
333 ;; - Adds `lazy-lock-post-command-hook' globally to `window-setup-hook' | 246 ;; - Adds `lazy-lock-post-command-hook' globally to `window-setup-hook'. |
334 ;; 1.09--1.10: | 247 ;; 1.09--1.10: |
335 ;; - Made `buffer-file-name' be `let' to prevent supersession (Kevin Broadey) | 248 ;; - Made `buffer-file-name' be `let' to prevent supersession (Kevin Broadey). |
336 ;; - Made `lazy-lock-submit-bug-report' `require' reporter (Ilya Zakharevich) | 249 ;; - Made `lazy-lock-submit-bug-report' `require' reporter (Ilya Zakharevich). |
337 ;; - Made `lazy-lock-mode' and `turn-on-lazy-lock' succeed `autoload' cookies | 250 ;; - Made `lazy-lock-mode' and `turn-on-lazy-lock' succeed `autoload' cookies. |
338 ;; - Added `lazy-lock-fontify-walk-windows' for walking window fontification | 251 ;; - Added `lazy-lock-fontify-walk-windows' for walking window fontification. |
339 ;; - Added `lazy-lock-fontify-walk-stealthily' for walking stealth | 252 ;; - Added `lazy-lock-fontify-walk-stealthily' for walking stealth. |
340 ;; - Removed `move-to-window-line' from `lazy-lock-fontify-stealthily' | 253 ;; - Removed `move-to-window-line' from `lazy-lock-fontify-stealthily'. |
341 ;; - Made `lazy-lock-percent-fontified' use `truncate' rather than `round' | 254 ;; - Made `lazy-lock-percent-fontified' use `truncate' rather than `round'. |
342 ;; - Added other `*-argument' to `lazy-lock-ignore-commands' (Kevin Broadey) | 255 ;; - Added other `*-argument' to `lazy-lock-ignore-commands' (Kevin Broadey). |
343 ;; - Made `lazy-lock-fontify-stealthily' not assume buffer is part `fontified' | 256 ;; - Made `lazy-lock-fontify-stealthily' not assume buffer is part `fontified'. |
344 ;; - Emacs: Fix for `font-lock-fontify-region' | 257 ;; - Emacs: Fix for `font-lock-fontify-region'. |
345 ;; - Made `lazy-lock-post-command-hook' check for minibuffer (Kevin Broadey) | 258 ;; - Made `lazy-lock-post-command-hook' check for minibuffer (Kevin Broadey). |
346 ;; - Added `lazy-lock-stealth-nice' for niceness during stealth fontification | 259 ;; - Added `lazy-lock-stealth-nice' for niceness during stealth fontification. |
347 ;; - Added `lazy-lock-stealth-lines' for chunks of stealth fontification | 260 ;; - Added `lazy-lock-stealth-lines' for chunks of stealth fontification. |
348 ;; 1.10--1.11: incorporated hack by Ben Wing from William Dubuque's fontifly.el | 261 ;; 1.10--1.11: incorporated hack by Ben Wing from William Dubuque's fontifly.el |
349 ;; - Made `lazy-lock-fontify-stealthily' see a non `fontified' preceding line | 262 ;; - Made `lazy-lock-fontify-stealthily' see a non `fontified' preceding line. |
350 ;; - XEmacs: Fix `text-property-any' and `text-property-not-all' (Ben Wing) | 263 ;; - XEmacs: Fix `text-property-any' and `text-property-not-all' (Ben Wing). |
351 ;; - XEmacs: Fix `lazy-lock-continuity-time' (Ben Wing) | 264 ;; - XEmacs: Fix `lazy-lock-continuity-time' (Ben Wing). |
352 ;; - Added awful `lazy-lock-running-xemacs-p' (Ben Wing) | 265 ;; - Added awful `lazy-lock-running-xemacs-p' (Ben Wing). |
353 ;; - Made loading set `emacs-minor-version' if it's not bound | 266 ;; - Made loading set `emacs-minor-version' if it's not bound. |
354 ;; - Added `lazy-lock-hide-invisible' to control redisplay | 267 ;; - Added `lazy-lock-hide-invisible' to control redisplay. |
355 ;; - Made `lazy-lock-post-command-hook' use it in `sit-for' (Ben Wing) | 268 ;; - Made `lazy-lock-post-command-hook' use it in `sit-for' (Ben Wing). |
356 ;; - Made `lazy-lock-fontify-window' move relative to `end-of-line' if non-nil | 269 ;; - Made `lazy-lock-fontify-window' move relative to `end-of-line' if non-nil. |
357 ;; - Added `lazy-lock-fontify-region' so packages can ensure fontification | 270 ;; - Added `lazy-lock-fontify-region' so packages can ensure fontification. |
358 ;; - Made `lazy-lock-fontify-walk-stealthily' do stealth widening | 271 ;; - Made `lazy-lock-fontify-walk-stealthily' do stealth widening. |
359 ;; - Made `lazy-lock-fontify-stealthily' always do adjacent preceding regions | 272 ;; - Made `lazy-lock-fontify-stealthily' always do adjacent preceding regions. |
360 ;; - Added `lazy-lock-after-fontify-buffer' | 273 ;; - Added `lazy-lock-after-fontify-buffer'. |
361 ;; - XEmacs: Removed `font-lock-no-comments' incompatibility code | 274 ;; - XEmacs: Removed `font-lock-no-comments' incompatibility code. |
362 ;; - Removed `lazy-lock-delay-time' and `lazy-lock-delay-commands' | 275 ;; - Removed `lazy-lock-delay-time' and `lazy-lock-delay-commands'. |
363 ;; - Removed `lazy-lock-post-command' and split the functionality | 276 ;; - Removed `lazy-lock-post-command' and split the functionality. |
364 ;; - Adds `lazy-lock-post-command-fontify-windows' on first | 277 ;; - Adds `lazy-lock-post-command-fontify-windows' on first. |
365 ;; - Adds `lazy-lock-post-command-fontify-stealthily' on last | 278 ;; - Adds `lazy-lock-post-command-fontify-stealthily' on last. |
366 ;; - Made `lazy-lock-mode' ensure both first and last on `post-command-hook' | 279 ;; - Made `lazy-lock-mode' ensure both first and last on `post-command-hook'. |
367 ;; - Made `lazy-lock-mode' ensure `font-lock-mode' is on | 280 ;; - Made `lazy-lock-mode' ensure `font-lock-mode' is on. |
368 ;; - Wrap `lazy-lock-post-command-fontify-stealthily' for errors (David Karr) | 281 ;; - Wrap `lazy-lock-post-command-fontify-stealthily' for errors (David Karr). |
369 ;; - Added `calcDigit-key' to `lazy-lock-ignore-commands' (Bob Glickstein) | 282 ;; - Added `calcDigit-key' to `lazy-lock-ignore-commands' (Bob Glickstein). |
370 ;; - Wrap `lazy-lock-running-xemacs-p' with `eval-and-compile' (Erik Naggum) | 283 ;; - Wrap `lazy-lock-running-xemacs-p' with `eval-and-compile' (Erik Naggum). |
371 ;; - XEmacs: Fix use of `previous-single-property-change' (Jim Thompson) | 284 ;; - XEmacs: Fix use of `previous-single-property-change' (Jim Thompson). |
372 ;; - XEmacs: Fix `next-single-property-change' fix for 19.11 (Jim Thompson) | 285 ;; - XEmacs: Fix `next-single-property-change' fix for 19.11 (Jim Thompson). |
373 ;; - Added `lazy-lock-post-resize-fontify-windows' to fontify on resizing | 286 ;; - Added `lazy-lock-post-resize-fontify-windows' to fontify on resizing. |
374 ;; - Adds globally to `window-size-change-functions' | 287 ;; - Adds globally to `window-size-change-functions'. |
375 ;; - Added `lazy-lock-post-setup-fontify-windows' to fontify after start up | 288 ;; - Added `lazy-lock-post-setup-fontify-windows' to fontify after start up. |
376 ;; - Adds globally to `window-setup-hook' | 289 ;; - Adds globally to `window-setup-hook'. |
377 ;; - Made `lazy-lock-post-command-fontify-windows' check for `input-pending-p' | 290 ;; - Made `lazy-lock-post-command-fontify-windows' check for `input-pending-p'. |
378 ;; - Made `save-selected-window' to restore the `selected-window' | 291 ;; - Made `save-selected-window' to restore the `selected-window'. |
379 ;; - Use `save-selected-window' rather than `save-window-excursion' | 292 ;; - Use `save-selected-window' rather than `save-window-excursion'. |
380 ;; 1.11--1.12: | 293 ;; 1.11--1.12: |
381 ;; - Made `lazy-lock-post-command-fontify-windows' do `set-buffer' first | 294 ;; - Made `lazy-lock-post-command-fontify-windows' do `set-buffer' first. |
382 ;; - Made `lazy-lock-fontify-stealthily' respect narrowing before point | 295 ;; - Made `lazy-lock-fontify-stealthily' respect narrowing before point. |
383 ;; - Added `lazy-lock-post-setup-ediff-control-frame' for Ediff control frame | 296 ;; - Added `lazy-lock-post-setup-ediff-control-frame' for Ediff control frame. |
384 ;; - Adds globally to `ediff-after-setup-control-frame-hooks' | 297 ;; - Adds globally to `ediff-after-setup-control-frame-hooks'. |
385 ;; - Wrap `save-selected-window' with `save-excursion' for `current-buffer' | 298 ;; - Wrap `save-selected-window' with `save-excursion' for `current-buffer'. |
386 ;; 1.12--1.13: | 299 ;; 1.12--1.13: |
387 ;; - XEmacs: Add `lazy-lock-after-fontify-buffer' to the Font Lock hook | 300 ;; - XEmacs: Add `lazy-lock-after-fontify-buffer' to the Font Lock hook. |
388 ;; - Made `buffer-file-truename' also wrapped for supersession (Rick Sladkey) | 301 ;; - Made `buffer-file-truename' also wrapped for supersession (Rick Sladkey). |
389 ;; - Made `font-lock-beginning-of-syntax-function' wrapped for fontification | 302 ;; - Made `font-lock-beginning-of-syntax-function' wrapped for fontification. |
390 ;; - Added `lazy-lock-stealth-verbose' (after harassment from Ben Wing) | 303 ;; - Added `lazy-lock-stealth-verbose' (after harassment from Ben Wing). |
391 ;; - XEmacs: Made `font-lock-verbose' wrapped for stealth fontification | 304 ;; - XEmacs: Made `font-lock-verbose' wrapped for stealth fontification. |
392 ;; 1.13--1.14: | 305 ;; 1.13--1.14: |
393 ;; - Wrap `lazy-lock-colour-invisible' for `set-face-foreground' (Jari Aalto) | 306 ;; - Wrap `lazy-lock-colour-invisible' for `set-face-foreground' (Jari Aalto). |
394 ;; 1.14--1.15: | |
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 | |
402 | 307 |
403 ;;; Code: | |
404 | |
405 (require 'font-lock) | 308 (require 'font-lock) |
406 | 309 |
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 | |
413 (eval-when-compile | 310 (eval-when-compile |
414 ;; | 311 ;; Only `require' so `ediff-multiframe-setup-p' is expanded at compile time. |
415 ;; We don't do this at the top-level as we only use non-autoloaded macros. | 312 (condition-case nil (require 'ediff) (file-error)) |
416 (require 'cl) | |
417 ;; | |
418 ;; Well, shouldn't Lazy Lock be as lazy as possible? | 313 ;; Well, shouldn't Lazy Lock be as lazy as possible? |
419 (setq byte-compile-dynamic t byte-compile-dynamic-docstrings t)) | 314 ;(setq byte-compile-dynamic t byte-compile-dynamic-docstrings t) |
420 | 315 ;; Shut Emacs' byte-compiler up (cf. stop me getting mail from users). |
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.14" | |
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-major-version', `emacs-minor-version', and | |
339 ;; `emacs-version>=' if no-one else has. | |
340 | |
341 (if (not (boundp 'emacs-major-version)) | |
342 (eval-and-compile | |
343 (defconst emacs-major-version | |
344 (progn (or (string-match "^[0-9]+" emacs-version) | |
345 (error "emacs-version unparsable")) | |
346 (string-to-int (match-string 0 emacs-version))) | |
347 "Major version number of this version of Emacs, as an integer. | |
348 Warning, this variable did not exist in Emacs versions earlier than: | |
349 FSF Emacs: 19.23 | |
350 XEmacs: 19.10"))) | |
351 | |
352 (if (not (boundp 'emacs-minor-version)) | |
353 (eval-and-compile | |
354 (defconst emacs-minor-version | |
355 (progn (or (string-match "^[0-9]+\\.\\([0-9]+\\)" emacs-version) | |
356 (error "emacs-version unparsable")) | |
357 (string-to-int (match-string 1 emacs-version))) | |
358 "Minor version number of this version of Emacs, as an integer. | |
359 Warning, this variable did not exist in Emacs versions earlier than: | |
360 FSF Emacs: 19.23 | |
361 XEmacs: 19.10"))) | |
362 | |
363 (if (not (fboundp 'emacs-version>=)) | |
364 (eval-and-compile | |
365 (defun emacs-version>= (major &optional minor) | |
366 "Return true if the Emacs version is >= to the given MAJOR and MINOR numbers. | |
367 | |
368 The MAJOR version number argument is required, but the MINOR version number | |
369 argument is optional. If the minor version number is not specified (or is the | |
370 symbol `nil') then only the major version numbers are considered in the test." | |
371 (if (null minor) | |
372 (>= emacs-major-version major) | |
373 (or (> emacs-major-version major) | |
374 (and (= emacs-major-version major) | |
375 (>= emacs-minor-version minor)) | |
376 ) | |
377 )))) | |
378 | |
379 ;; Yuck, but we make so much use of this variable it's probably worth it. | |
421 (eval-and-compile | 380 (eval-and-compile |
422 ;; Yuck, but we make so much use of this variable it's probably worth it. | 381 (defconst lazy-lock-running-xemacs-p |
423 (defconst lazy-lock-running-xemacs | |
424 (not (null (save-match-data (string-match "Lucid" emacs-version)))))) | 382 (not (null (save-match-data (string-match "Lucid" emacs-version)))))) |
425 | 383 |
426 (defvar lazy-lock-cache-start nil) ; for window fontifiction | 384 (defvar lazy-lock-cache-start nil) ; for window fontifiction |
427 (defvar lazy-lock-cache-end nil) ; for window fontifiction | 385 (defvar lazy-lock-cache-end nil) ; for window fontifiction |
428 (defvar lazy-lock-cache-continue nil) ; for stealth fontifiction | 386 (defvar lazy-lock-cache-continue nil) ; for stealth fontifiction |
387 | |
388 ;;;###autoload | |
429 (defvar lazy-lock-mode nil) ; for modeline | 389 (defvar lazy-lock-mode nil) ; for modeline |
430 | 390 |
431 ;; User Variables: | 391 ;; User Variables: |
432 | 392 |
433 (defvar lazy-lock-minimum-size (* 25 1024) | 393 (defvar lazy-lock-minimum-size (* 25 1024) |
440 If `all-frames', fontify windows even on other frames. | 400 If `all-frames', fontify windows even on other frames. |
441 A non-nil value slows down redisplay.") | 401 A non-nil value slows down redisplay.") |
442 | 402 |
443 ;; XEmacs 19.11 and below exercise a bug in the Xt event loop. | 403 ;; XEmacs 19.11 and below exercise a bug in the Xt event loop. |
444 (defvar lazy-lock-continuity-time | 404 (defvar lazy-lock-continuity-time |
445 (cond ((not lazy-lock-running-xemacs) | 405 (if (or (not lazy-lock-running-xemacs-p) (emacs-version>= 19 12)) |
446 0) | 406 0 |
447 ((and (= emacs-major-version 19) (< emacs-minor-version 12)) | 407 (if (featurep 'lisp-float-type) 0.001 1)) |
448 (if (featurep 'lisp-float-type) (/ (float 1) (float 1000)) 1)) | |
449 (t | |
450 0)) | |
451 "*Time in seconds to delay before normal window fontification. | 408 "*Time in seconds to delay before normal window fontification. |
452 Window fontification occurs if there is no input within this time.") | 409 Window fontification occurs if there is no input within this time.") |
453 | 410 |
454 ;; `previous-single-property-change' at `point-min' up to Emacs 19.25 is fatal. | 411 ;; `previous-single-property-change' at `point-min' up to Emacs 19.25 is fatal. |
455 ;; `text-property-any', `text-property-not-all' and | 412 ;; `text-property-any', `text-property-not-all' and |
456 ;; `next-single-property-change' up to XEmacs 19.11 are too broke. | 413 ;; `next-single-property-change' up to XEmacs 19.11 are too broke. |
457 (defvar lazy-lock-stealth-time | 414 (defvar lazy-lock-stealth-time |
458 (when (or (> emacs-major-version 19) | 415 (if (emacs-version>= 19 (if lazy-lock-running-xemacs-p 12 26)) 30) |
459 (and (not lazy-lock-running-xemacs) (> emacs-minor-version 25)) | |
460 (and lazy-lock-running-xemacs (> emacs-minor-version 11))) | |
461 30) | |
462 "*Time in seconds to delay before beginning stealth fontification. | 416 "*Time in seconds to delay before beginning stealth fontification. |
463 Stealth fontification occurs if there is no input within this time. | 417 Stealth fontification occurs if there is no input within this time. |
464 If nil, means no fontification by stealth.") | 418 If nil, means no fontification by stealth.") |
465 | 419 |
466 (defvar lazy-lock-stealth-lines | 420 (defvar lazy-lock-stealth-lines |
467 (if lazy-lock-running-xemacs | 421 (cond ((boundp 'font-lock-maximum-decoration) |
468 (if font-lock-maximum-decoration 50 100) | 422 (if font-lock-maximum-decoration 75 150)) |
469 (if font-lock-maximum-decoration 100 250)) | 423 ((boundp 'font-lock-use-maximal-decoration) |
424 (if font-lock-use-maximal-decoration 50 100)) | |
425 (t | |
426 50)) | |
470 "*If non-nil, the maximum size of a chunk of stealth fontification. | 427 "*If non-nil, the maximum size of a chunk of stealth fontification. |
471 Each iteration of stealth fontification can fontify this number of lines. | 428 Each iteration of stealth fontification can fontify this number of lines. |
472 To speed up input response during stealth fontification, at the cost of stealth | 429 To speed up input response during stealth fontification, at the cost of stealth |
473 taking longer to fontify, you could reduce the value of this variable. | 430 taking longer to fontify, you could reduce the value of this variable. |
474 If nil, means use `window-height' for the maximum chunk size.") | 431 If nil, means use `window-height' for the maximum chunk size.") |
475 | 432 |
476 (defvar lazy-lock-stealth-nice | 433 (defvar lazy-lock-stealth-nice (if (featurep 'lisp-float-type) 0.125 1) |
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)) | |
480 "*Time in seconds to pause during chunks of stealth fontification. | 434 "*Time in seconds to pause during chunks of stealth fontification. |
481 To reduce machine load during stealth fontification, at the cost of stealth | 435 To reduce machine load during stealth fontification, at the cost of stealth |
482 taking longer to fontify, you could increase the value of this variable.") | 436 taking longer to fontify, you could increase the value of this variable.") |
483 | 437 |
484 (defvar lazy-lock-stealth-verbose font-lock-verbose | 438 (defvar lazy-lock-stealth-verbose font-lock-verbose |
493 (if (fboundp 'calc) '(calcDigit-key))) | 447 (if (fboundp 'calc) '(calcDigit-key))) |
494 "A list of commands after which fontification should not occur. | 448 "A list of commands after which fontification should not occur. |
495 To speed up typing response, at the cost of Lazy Lock not fontifying when | 449 To speed up typing response, at the cost of Lazy Lock not fontifying when |
496 insertion causes scrolling, you could add `self-insert-command' to this list.") | 450 insertion causes scrolling, you could add `self-insert-command' to this list.") |
497 | 451 |
498 (defvar lazy-lock-hide-invisible lazy-lock-running-xemacs | 452 (defvar lazy-lock-hide-invisible lazy-lock-running-xemacs-p |
499 "*If non-nil, hide invisible text while it is fontified. | 453 "*If non-nil, hide invisible text while it is fontified. |
500 If non-nil, redisplay is delayed until after fontification occurs. If nil, | 454 If non-nil, redisplay is delayed until after fontification occurs. If nil, |
501 text is shown (in `lazy-lock-invisible-foreground') while it is fontified. | 455 text is shown (in `lazy-lock-invisible-foreground') while it is fontified. |
502 A non-nil value slows down redisplay and can slow down cursor motion.") | 456 A non-nil value slows down redisplay and can slow down cursor motion.") |
503 | 457 |
540 (if (and lazy-lock-mode (not font-lock-mode)) | 494 (if (and lazy-lock-mode (not font-lock-mode)) |
541 ;; Turned on `lazy-lock-mode' rather than using `font-lock-mode-hook'. | 495 ;; Turned on `lazy-lock-mode' rather than using `font-lock-mode-hook'. |
542 (progn | 496 (progn |
543 (add-hook 'font-lock-mode-hook 'turn-on-lazy-lock) | 497 (add-hook 'font-lock-mode-hook 'turn-on-lazy-lock) |
544 (font-lock-mode 1)) | 498 (font-lock-mode 1)) |
499 (lazy-lock-fixup-hooks) | |
545 ;; Let's get down to business. | 500 ;; Let's get down to business. |
546 (lazy-lock-post-command-setup) | |
547 (if (not lazy-lock-mode) | 501 (if (not lazy-lock-mode) |
548 (let ((modified (buffer-modified-p)) (inhibit-read-only t) | 502 (let ((modified (buffer-modified-p)) (inhibit-read-only t) |
549 (buffer-undo-list t) | 503 (buffer-undo-list t) |
550 deactivate-mark buffer-file-name buffer-file-truename) | 504 deactivate-mark buffer-file-name buffer-file-truename) |
551 (remove-text-properties (point-min) (point-max) '(fontified nil)) | 505 (remove-text-properties (point-min) (point-max) '(fontified nil)) |
559 ;;;###autoload | 513 ;;;###autoload |
560 (defun turn-on-lazy-lock () | 514 (defun turn-on-lazy-lock () |
561 "Unconditionally turn on Lazy Lock mode." | 515 "Unconditionally turn on Lazy Lock mode." |
562 (lazy-lock-mode 1)) | 516 (lazy-lock-mode 1)) |
563 | 517 |
564 (when (and (= emacs-major-version 19) | 518 (if (not (emacs-version>= 19 (if lazy-lock-running-xemacs-p 12 29))) |
565 (< emacs-minor-version (if lazy-lock-running-xemacs 12 29))) | 519 ;; We don't need this in Emacs 19.29 or XEmacs 19.12. |
566 ;; We don't need this in Emacs 19.29 or XEmacs 19.12. | 520 (defun lazy-lock-fontify-buffer () |
567 (defun lazy-lock-fontify-buffer () | 521 "Fontify the current buffer where necessary." |
568 "Fontify the current buffer where necessary." | 522 (interactive) |
569 (interactive) | 523 (lazy-lock-fontify-region (point-min) (point-max)))) |
570 (lazy-lock-fontify-region (point-min) (point-max)))) | |
571 | 524 |
572 ;; API Functions: | 525 ;; API Functions: |
526 | |
527 (defun lazy-lock-fixup-hooks () | |
528 ;; Make sure our hooks are correct. | |
529 (remove-hook 'pre-idle-hook 'lazy-lock-pre-idle-fontify-windows) | |
530 (remove-hook 'post-command-hook 'lazy-lock-post-command-fontify-stealthily) | |
531 ;; Make sure our hooks are at the end. Font-lock in XEmacs installs | |
532 ;; its own pre-idle-hook to implement deferral (#### something that | |
533 ;; should really be merged with this file; or more likely, lazy-lock | |
534 ;; in its entirety should be merged into font-lock). | |
535 (add-hook 'pre-idle-hook 'lazy-lock-pre-idle-fontify-windows t) | |
536 (add-hook 'post-command-hook 'lazy-lock-post-command-fontify-stealthily t) | |
537 ;; Fascistically remove font-lock's after-change-function and install | |
538 ;; our own. We know better than font-lock what to do. Otherwise, | |
539 ;; revert-buffer, insert-file, etc. cause full refontification of the | |
540 ;; entire changed area. | |
541 (if lazy-lock-mode | |
542 (progn | |
543 (remove-hook 'after-change-functions 'font-lock-after-change-function | |
544 t) | |
545 (make-local-hook 'after-change-functions) | |
546 (add-hook 'after-change-functions 'lazy-lock-after-change-function | |
547 nil t)) | |
548 (remove-hook 'after-change-functions 'lazy-lock-after-change-function t) | |
549 (if font-lock-mode | |
550 (add-hook 'after-change-functions 'font-lock-after-change-function | |
551 nil t))) | |
552 ) | |
553 | |
554 ;; use put-nonduplicable-text-property to avoid unfriendly behavior | |
555 ;; when doing undo, etc. We really don't want syntax-highlighting text | |
556 ;; properties copied into strings or tracked by undo. | |
557 ;; | |
558 ;; #### If start-open and end-open really behaved like they are supposed to, | |
559 ;; we wouldn't really need this. I kind of fixed them up, but there's still | |
560 ;; a bug -- inserting text into the middle of a region of | |
561 ;; (start-open t end-open t) text should cause it not to inherit, but it | |
562 ;; does. | |
563 | |
564 (if lazy-lock-running-xemacs-p | |
565 (defalias 'lazy-lock-put-text-property 'put-nonduplicable-text-property) | |
566 (defalias 'lazy-lock-put-text-property 'put-text-property)) | |
573 | 567 |
574 (defun lazy-lock-fontify-region (start end &optional buffer) | 568 (defun lazy-lock-fontify-region (start end &optional buffer) |
575 "Fontify between START and END in BUFFER where necessary." | 569 "Fontify between START and END in BUFFER where necessary." |
576 (save-excursion | 570 (save-excursion |
577 (and buffer (set-buffer buffer)) | 571 (and buffer (set-buffer buffer)) |
584 (defun lazy-lock-after-fontify-buffer () | 578 (defun lazy-lock-after-fontify-buffer () |
585 ;; Mark the buffer as `fontified'. | 579 ;; Mark the buffer as `fontified'. |
586 (let ((modified (buffer-modified-p)) (inhibit-read-only t) | 580 (let ((modified (buffer-modified-p)) (inhibit-read-only t) |
587 (buffer-undo-list t) | 581 (buffer-undo-list t) |
588 deactivate-mark buffer-file-name buffer-file-truename) | 582 deactivate-mark buffer-file-name buffer-file-truename) |
589 (put-text-property (point-min) (point-max) 'fontified t) | 583 (lazy-lock-put-text-property (point-min) (point-max) 'fontified t) |
590 (or modified (set-buffer-modified-p nil)))) | 584 (or modified (set-buffer-modified-p nil)))) |
591 | 585 |
592 ;; Just a cleaner-looking way of coping with Emacs' and XEmacs' `sit-for'. | 586 ;; Just a cleaner-looking way of coping with Emacs' and XEmacs' `sit-for'. |
593 (defmacro lazy-lock-sit-for (seconds &optional nodisp) | 587 (defmacro lazy-lock-sit-for (seconds &optional nodisp) |
594 (if lazy-lock-running-xemacs | 588 (if lazy-lock-running-xemacs-p |
595 (` (sit-for (, seconds) (, nodisp))) | 589 (` (sit-for (, seconds) (, nodisp))) |
596 (` (sit-for (, seconds) 0 (, nodisp))))) | 590 (` (sit-for (, seconds) 0 (, nodisp))))) |
597 | 591 |
598 ;; Using `save-window-excursion' provokes `window-size-change-functions'. | 592 ;; Using `save-window-excursion' provokes `window-size-change-functions'. |
599 ;; I prefer `save-walking-excursion', of course, because I have a warped mind. | 593 ;; I prefer `save-walking-excursion', of course, because I have a warped mind. |
600 (unless (fboundp 'save-selected-window) | 594 (if (fboundp 'save-selected-window) |
595 nil | |
601 (eval-and-compile | 596 (eval-and-compile |
602 (defmacro save-selected-window (&rest body) | 597 (defmacro save-selected-window (&rest body) |
603 "Execute the BODY forms, restoring the selected window. | 598 "Execute the BODY forms, restoring the selected window. |
604 Does not restore the value of point in the selected window, or anything else." | 599 Does not restore the value of point in the selected window, or anything else." |
605 (` (let ((original-window (selected-window))) | 600 (` (let ((original-window (selected-window))) |
608 (select-window original-window)))))) | 603 (select-window original-window)))))) |
609 (put 'save-selected-window 'lisp-indent-function 0)) | 604 (put 'save-selected-window 'lisp-indent-function 0)) |
610 | 605 |
611 ;; Functions for hooks: | 606 ;; Functions for hooks: |
612 | 607 |
613 (defun lazy-lock-post-command-fontify-windows () | 608 ;; lazy-lock optimization: |
614 ;; We might not be where we think we are, since `post-command-hook' is run | 609 ;; |
615 ;; before `command_loop_1' makes sure we have the correct buffer selected. | 610 ;; pre-idle-hook is called an awful lot -- pretty much every time the |
616 ; (set-buffer (window-buffer)) | 611 ;; mouse moves or a timeout expires, for example. On Linux (sometimes), |
617 ;; Do groovy things if (a) not in a macro, (b) no input pending, (c) got a | 612 ;; IRIX 5.x, and Solaris 2.something, it happens every 1/4 of a second |
618 ;; real command, (d) not in the minibuffer, and (e) no input after waiting | 613 ;; due to the 1/4-second timers installed to compensate for various |
619 ;; for `lazy-lock-continuity-time'. | 614 ;; operating system deficiencies in the handling of SIGIO and SIGCHLD. |
620 (if (or executing-kbd-macro | 615 ;; (Those timers cause a cycle of the event loop. They don't necessarily |
621 (input-pending-p) | 616 ;; have to, but rewriting to avoid this is fairly tricky and requires |
622 (memq this-command lazy-lock-ignore-commands) | 617 ;; having significant amounts of code called from signal handlers, which |
623 (window-minibuffer-p (selected-window))) | 618 ;; (despite that fact that FSF Emacs reads its X input during a signal |
619 ;; handler ?!), is almost always a bad idea -- it's extremely easy to | |
620 ;; introduce race conditions, which are very hard to track down. | |
621 ;; | |
622 ;; So to improve things, I added `frame-modified-tick'. This is an | |
623 ;; internal counter that gets ticked any time that any internal | |
624 ;; redisplay variable gets ticked. If `frame-modified-tick' is | |
625 ;; the same as the last time we checked, it means that redisplay will | |
626 ;; do absolutely nothing when encountering this frame, and thus we | |
627 ;; can skip out immediately. This happens when the 1/4-second timer | |
628 ;; fires while we're idle, or if we just move the mouse. (Moving | |
629 ;; around in a buffer changes `frame-modified-tick' because the | |
630 ;; internal redisplay variable "point_changed" gets ticked. We could | |
631 ;; easily improve things further by adding more tick counters, mirroring | |
632 ;; more closely the internal redisplay counters -- e.g. if we had | |
633 ;; another counter that didn't get ticked when point moved, we could | |
634 ;; tell if anything was going to happen by seeing if point is within | |
635 ;; window-start and window-end, since we know that redisplay will | |
636 ;; only do a window-scroll if it's not. (If window-start or window-end | |
637 ;; or window-buffer or anything else changed, windows_changed or | |
638 ;; some other variable will get ticked.)) | |
639 ;; | |
640 ;; Also, it's wise to try and avoid things that cons. Avoiding | |
641 ;; `save-window-excursion', as we do, is definitely a major win | |
642 ;; because that's a heavy-duty function as regards consing and such. | |
643 | |
644 (defvar lazy-lock-pre-idle-frame-modified-tick nil) | |
645 (defvar lazy-lock-pre-idle-selected-frame nil) | |
646 | |
647 (defun lazy-lock-pre-idle-fontify-windows () | |
648 ;; Do groovy things always unless we're in one of the ignored commands. | |
649 ;; The old version did the following five checks: | |
650 ;; | |
651 ;; (a) not in a macro, | |
652 ;; (b) no input pending, | |
653 ;; (c) got a real command (i.e. not an ignored command) | |
654 ;; (d) not in the minibuffer | |
655 ;; (e) no input after waiting for `lazy-lock-continuity-time'. | |
656 ;; | |
657 ;; (a), (b), and (e) are automatically taken care of by `pre-idle-hook'. | |
658 ;; I removed (d) because there doesn't seem to be any reason for it. | |
659 ;; | |
660 ;; Also, we do not have to `set-buffer' and in fact it would be | |
661 ;; incorrect to do so, since we may be being called from | |
662 ;; `accept-process-output' or whatever. | |
663 ;; | |
664 (if (memq this-command lazy-lock-ignore-commands) | |
624 (setq lazy-lock-cache-continue nil) | 665 (setq lazy-lock-cache-continue nil) |
625 (setq lazy-lock-cache-continue t) | 666 (setq lazy-lock-cache-continue t) |
626 (if (lazy-lock-sit-for lazy-lock-continuity-time lazy-lock-hide-invisible) | 667 ;; #### we don't yet handle frame-modified-tick on multiple frames. |
627 ;; Do the visible parts of the buffer(s), i.e., the window(s). | 668 ;; handling this shouldn't be hard but I just haven't done it yet. |
628 (if (or (not lazy-lock-walk-windows) | 669 (if (or (eq 'all-frames lazy-lock-walk-windows) |
629 (and (eq lazy-lock-walk-windows t) (one-window-p t))) | 670 (not (eq lazy-lock-pre-idle-selected-frame (selected-frame))) |
630 (if lazy-lock-mode (condition-case nil (lazy-lock-fontify-window))) | 671 (not (eq lazy-lock-pre-idle-frame-modified-tick |
631 (lazy-lock-fontify-walk-windows))))) | 672 (frame-modified-tick (selected-frame))))) |
632 | 673 (progn |
674 ;; Do the visible parts of the buffer(s), i.e., the window(s). | |
675 (if (or (not lazy-lock-walk-windows) | |
676 (and (eq lazy-lock-walk-windows t) (one-window-p t))) | |
677 (if lazy-lock-mode (condition-case nil | |
678 (lazy-lock-fontify-window))) | |
679 (lazy-lock-fontify-walk-windows)) | |
680 (setq lazy-lock-pre-idle-selected-frame (selected-frame)) | |
681 (setq lazy-lock-pre-idle-frame-modified-tick | |
682 (frame-modified-tick (selected-frame))))))) | |
683 | |
684 (defun lazy-lock-after-change-function (beg end old-len) | |
685 (and lazy-lock-mode | |
686 (if (= beg end) | |
687 (font-lock-after-change-function beg end old-len) | |
688 (lazy-lock-put-text-property beg end 'fontified nil)))) | |
689 | |
690 ;; DO NOT put this as a pre-idle hook! The sit-for messes up | |
691 ;; mouse dragging. | |
633 (defun lazy-lock-post-command-fontify-stealthily () | 692 (defun lazy-lock-post-command-fontify-stealthily () |
634 ;; Do groovy things if (a-d) above, (e) not moving the mouse, and (f) no | 693 ;; Do groovy things if (a-d) above, (e) not moving the mouse, and (f) no |
635 ;; input after after waiting for `lazy-lock-stealth-time'. | 694 ;; input after waiting for `lazy-lock-stealth-time'. |
636 (if (and lazy-lock-cache-continue lazy-lock-stealth-time) | 695 (if (and lazy-lock-cache-continue lazy-lock-stealth-time) |
637 (condition-case data | 696 (condition-case data |
638 (if (lazy-lock-sit-for lazy-lock-stealth-time) | 697 (if (lazy-lock-sit-for lazy-lock-stealth-time) |
639 ;; Do the invisible parts of buffers. | 698 ;; Do the invisible parts of buffers. |
640 (lazy-lock-fontify-walk-stealthily)) | 699 (lazy-lock-fontify-walk-stealthily)) |
641 (error (message "Fontifying stealthily... %s" data))))) | 700 (error (message "Fontifying stealthily... %s" data))))) |
642 | 701 |
702 ;; In XEmacs 19.14 with pre-idle-hook we do not have to call this. | |
643 (defun lazy-lock-post-resize-fontify-windows (frame) | 703 (defun lazy-lock-post-resize-fontify-windows (frame) |
644 ;; Fontify all windows in FRAME. | 704 ;; Fontify all windows in FRAME. |
645 (let ((lazy-lock-walk-windows t) executing-kbd-macro this-command) | 705 (let ((lazy-lock-walk-windows t) executing-kbd-macro this-command) |
646 (save-excursion | 706 (save-excursion |
647 (save-selected-window | 707 (save-selected-window |
648 (select-frame frame) | 708 (select-frame frame) |
649 (lazy-lock-post-command-fontify-windows))))) | 709 (lazy-lock-pre-idle-fontify-windows))))) |
650 | 710 |
651 (defun lazy-lock-post-setup-emacs-fontify-windows () | 711 (defun lazy-lock-post-setup-emacs-fontify-windows () |
652 ;; Fontify all windows in all frames. | 712 ;; Fontify all windows in all frames. |
653 (let ((lazy-lock-walk-windows 'all-frames) executing-kbd-macro this-command) | 713 (let ((lazy-lock-walk-windows 'all-frames) executing-kbd-macro this-command) |
654 (lazy-lock-post-command-fontify-windows))) | 714 (lazy-lock-pre-idle-fontify-windows))) |
655 | 715 |
656 (defun lazy-lock-post-setup-ediff-control-frame () | 716 (defun lazy-lock-post-setup-ediff-control-frame () |
657 ;; Fontify all windows in all frames when using the Ediff control frame. | 717 ;; Fontify all windows in all frames when using the Ediff control frame. |
658 (make-local-variable 'lazy-lock-walk-windows) | 718 (make-local-variable 'lazy-lock-walk-windows) |
659 (setq lazy-lock-walk-windows (if (ediff-multiframe-setup-p) 'all-frames t)) | 719 (setq lazy-lock-walk-windows (if (ediff-multiframe-setup-p) 'all-frames t)) |
660 (lazy-lock-post-command-setup)) | 720 (lazy-lock-fixup-hooks)) |
661 | |
662 (defun lazy-lock-post-command-setup () | |
663 ;; Make sure that we're in the correct positions to avoid hassle. | |
664 (remove-hook 'post-command-hook 'lazy-lock-post-command-fontify-windows) | |
665 (remove-hook 'post-command-hook 'lazy-lock-post-command-fontify-stealthily) | |
666 (add-hook 'post-command-hook 'lazy-lock-post-command-fontify-windows) | |
667 (add-hook (if (boundp 'post-command-idle-hook) | |
668 'post-command-idle-hook | |
669 'post-command-hook) | |
670 'lazy-lock-post-command-fontify-stealthily t)) | |
671 | 721 |
672 ;; Functions for fontification: | 722 ;; Functions for fontification: |
673 | 723 |
674 (defun lazy-lock-fontify-window () | 724 (defun lazy-lock-fontify-window () |
675 ;; Fontify the visible part of the buffer where necessary. | 725 ;; Fontify the visible part of the buffer where necessary. |
676 (let (ws we wh) | 726 (let ((ws (if lazy-lock-hide-invisible |
677 ;; Find the bounds of the visible part exactly or conservatively. | 727 (save-excursion |
678 (if (not lazy-lock-hide-invisible) | 728 (end-of-line) (forward-line (- (window-height))) (point)) |
679 (setq ws (min (max (window-start) (point-min)) (point-max)) | 729 (min (max (window-start) (point-min)) (point-max)))) |
680 we (min (max (1- (window-end)) (point-min)) (point-max))) | 730 (we (if lazy-lock-hide-invisible |
681 (setq wh (window-height) ; Buggy: (window-displayed-height) | 731 (save-excursion |
682 ws (save-excursion (forward-line (- wh)) (point)) | 732 (end-of-line) (forward-line (window-height)) (point)) |
683 we (save-excursion (forward-line wh) (point)))) | 733 (min (max (1- (window-end)) (point-min)) (point-max))))) |
684 ;; Find whether bounds have changed since previous fontification. | |
685 (if (or (/= ws lazy-lock-cache-start) (/= we lazy-lock-cache-end)) | 734 (if (or (/= ws lazy-lock-cache-start) (/= we lazy-lock-cache-end)) |
686 ;; Find where we haven't `fontified' before. | 735 ;; Find where we haven't `fontified' before. |
687 (let* ((start (or (text-property-not-all ws we 'fontified t) ws)) | 736 (let* ((start (or (text-property-not-all ws we 'fontified t) ws)) |
688 (end (or (text-property-any start we 'fontified t) we)) | 737 (end (or (text-property-any start we 'fontified t) we)) |
689 (modified (buffer-modified-p)) (inhibit-read-only t) | 738 (modified (buffer-modified-p)) (inhibit-read-only t) |
695 font-lock-beginning-of-syntax-function | 744 font-lock-beginning-of-syntax-function |
696 ;; Prevent XEmacs 19.13 during fontification from messages. | 745 ;; Prevent XEmacs 19.13 during fontification from messages. |
697 font-lock-verbose) | 746 font-lock-verbose) |
698 (while (< start end) | 747 (while (< start end) |
699 ;; Fontify and flag the region as `fontified'. | 748 ;; Fontify and flag the region as `fontified'. |
700 (font-lock-after-change-function start end 0) | 749 ;; XEmacs: need to bind `font-lock-always-fontify-immediately' |
701 (put-text-property start end 'fontified t) | 750 ;; or we'll mess up in the presence of deferred font-locking. |
751 (let ((font-lock-always-fontify-immediately t)) | |
752 (font-lock-after-change-function start end 0)) | |
753 (lazy-lock-put-text-property start end 'fontified t) | |
702 ;; Find the next region. | 754 ;; Find the next region. |
703 (setq start (or (text-property-not-all ws we 'fontified t) ws) | 755 (setq start (or (text-property-not-all ws we 'fontified t) ws) |
704 end (or (text-property-any start we 'fontified t) we))) | 756 end (or (text-property-any start we 'fontified t) we))) |
705 (setq lazy-lock-cache-start ws lazy-lock-cache-end we) | 757 (setq lazy-lock-cache-start ws lazy-lock-cache-end we) |
706 (or modified (set-buffer-modified-p nil)))))) | 758 (or modified (set-buffer-modified-p nil)))))) |
762 ;; Maybe the region is already partially `fontified'. | 814 ;; Maybe the region is already partially `fontified'. |
763 (setq start | 815 (setq start |
764 (or (previous-single-property-change prev 'fontified nil (point)) | 816 (or (previous-single-property-change prev 'fontified nil (point)) |
765 (point))))) | 817 (point))))) |
766 ;; Fontify and flag the region as `fontified'. | 818 ;; Fontify and flag the region as `fontified'. |
767 (font-lock-after-change-function start end 0) | 819 ;; XEmacs: need to bind `font-lock-always-fontify-immediately' |
768 (put-text-property start end 'fontified t) | 820 ;; or we'll mess up in the presence of deferred font-locking. |
821 (let ((font-lock-always-fontify-immediately t)) | |
822 (font-lock-after-change-function start end 0)) | |
823 (lazy-lock-put-text-property start end 'fontified t) | |
769 (or modified (set-buffer-modified-p nil))))) | 824 (or modified (set-buffer-modified-p nil))))) |
770 | 825 |
771 (defun lazy-lock-fontify-walk-stealthily () | 826 (defun lazy-lock-fontify-walk-stealthily () |
772 ;; Fontify regions in all required buffers while there is no input. | 827 ;; Fontify regions in all required buffers while there is no input. |
773 (let ((buffers (buffer-list)) (continue t) fontified message-log-max) | 828 (let ((buffers (buffer-list)) (continue t) fontified message-log-max) |
808 (let ((size 0) (start (point-min)) (max (point-max)) end) | 863 (let ((size 0) (start (point-min)) (max (point-max)) end) |
809 (while (setq start (text-property-any start max 'fontified t)) | 864 (while (setq start (text-property-any start max 'fontified t)) |
810 (setq end (or (text-property-not-all start max 'fontified t) max) | 865 (setq end (or (text-property-not-all start max 'fontified t) max) |
811 size (+ size (- end start)) | 866 size (+ size (- end start)) |
812 start end)) | 867 start end)) |
813 ;; Float because using integer multiplication will frequently overflow. | 868 ;; Saying "99% done" is probably better than "100% done" when it isn't. |
814 (truncate (* (/ (float size) (point-max)) 100))))) | 869 (truncate (/ (* size 100.0) (buffer-size)))))) |
815 | 870 |
816 (defun lazy-lock-colour-invisible () | 871 (defun lazy-lock-colour-invisible () |
817 ;; Fontify the current buffer in `lazy-lock-invisible-face'. | 872 ;; Fontify the current buffer in `lazy-lock-invisible-face'. |
818 (save-restriction | 873 (save-restriction |
819 (widen) | 874 (widen) |
827 (make-face face) | 882 (make-face face) |
828 (if (not (equal (face-foreground face) fore)) | 883 (if (not (equal (face-foreground face) fore)) |
829 (condition-case nil | 884 (condition-case nil |
830 (set-face-foreground face fore) | 885 (set-face-foreground face fore) |
831 (error (message "Unable to use foreground \"%s\"" fore)))) | 886 (error (message "Unable to use foreground \"%s\"" fore)))) |
832 (put-text-property (point-min) (point-max) 'face face) | 887 (lazy-lock-put-text-property (point-min) (point-max) 'face face) |
833 (put-text-property (point-min) (point-max) 'fontified nil) | 888 (lazy-lock-put-text-property (point-min) (point-max) 'fontified nil) |
834 (or modified (set-buffer-modified-p nil))))) | 889 (or modified (set-buffer-modified-p nil))))) |
835 | 890 |
836 ;; Functions for Emacs: | 891 ;; Functions for Emacs: |
837 | 892 |
838 ;; This fix is for a number of bugs in the function in Emacs 19.28. | 893 ;; This fix is for a number of bugs in the function in Emacs 19.28. |
839 (when (and (not lazy-lock-running-xemacs) | 894 (if (and (not lazy-lock-running-xemacs-p) |
840 (= emacs-major-version 19) (< emacs-minor-version 28)) | 895 (not (emacs-version>= 19 29))) |
841 (defun font-lock-fontify-region (start end &optional loudly) | 896 (defun font-lock-fontify-region (start end &optional loudly) |
842 "Put proper face on each string and comment between START and END." | 897 "Put proper face on each string and comment between START and END." |
843 (save-excursion | 898 (save-excursion |
844 (save-restriction | 899 (save-restriction |
845 (widen) | 900 (widen) |
846 (goto-char start) | 901 (goto-char start) |
847 (beginning-of-line) | 902 (beginning-of-line) |
848 (if loudly (message "Fontifying %s... (syntactically...)" (buffer-name))) | 903 (if loudly (message "Fontifying %s... (syntactically...)" (buffer-name))) |
849 (let ((inhibit-read-only t) (buffer-undo-list t) | 904 (let ((inhibit-read-only t) (buffer-undo-list t) |
850 buffer-file-name buffer-file-truename | 905 buffer-file-name buffer-file-truename |
851 (modified (buffer-modified-p)) | 906 (modified (buffer-modified-p)) |
852 (old-syntax (syntax-table)) | 907 (old-syntax (syntax-table)) |
853 (synstart (if comment-start-skip | 908 (synstart (if comment-start-skip |
854 (concat "\\s\"\\|" comment-start-skip) | 909 (concat "\\s\"\\|" comment-start-skip) |
855 "\\s\"")) | 910 "\\s\"")) |
856 (comstart (if comment-start-skip | 911 (comstart (if comment-start-skip |
857 (concat "\\s<\\|" comment-start-skip) | 912 (concat "\\s<\\|" comment-start-skip) |
858 "\\s<")) | 913 "\\s<")) |
859 (startline (point)) | 914 (startline (point)) |
860 state prev prevstate) | 915 state prev prevstate) |
861 (unwind-protect | 916 (unwind-protect |
862 (progn | 917 (progn |
863 (if font-lock-syntax-table | 918 (if font-lock-syntax-table |
864 (set-syntax-table font-lock-syntax-table)) | 919 (set-syntax-table font-lock-syntax-table)) |
865 ;; Find the state at the line-beginning before START. | 920 ;; Find the state at the line-beginning before START. |
866 (if (eq startline font-lock-cache-position) | 921 (if (eq startline font-lock-cache-position) |
867 (setq state font-lock-cache-state) | 922 (setq state font-lock-cache-state) |
868 ;; Find outermost containing sexp. | 923 ;; Find outermost containing sexp. |
869 (beginning-of-defun) | 924 (beginning-of-defun) |
870 ;; Find the state at STARTLINE. | 925 ;; Find the state at STARTLINE. |
871 (while (< (point) startline) | 926 (while (< (point) startline) |
872 (setq state (parse-partial-sexp (point) startline 0))) | 927 (setq state (parse-partial-sexp (point) startline 0))) |
873 (setq font-lock-cache-state state | 928 (setq font-lock-cache-state state |
874 font-lock-cache-position (point))) | 929 font-lock-cache-position (point))) |
875 ;; Now find the state precisely at START. | 930 ;; Now find the state precisely at START. |
876 (setq state (parse-partial-sexp (point) start nil nil state)) | 931 (setq state (parse-partial-sexp (point) start nil nil state)) |
877 ;; If the region starts inside a string, show the extent of it. | 932 ;; If the region starts inside a string, show the extent of it. |
878 (if (nth 3 state) | 933 (if (nth 3 state) |
879 (let ((beg (point))) | 934 (let ((beg (point))) |
880 (while (and (re-search-forward "\\s\"" end 'move) | 935 (while (and (re-search-forward "\\s\"" end 'move) |
881 (nth 3 (parse-partial-sexp beg (point) nil nil | 936 (nth 3 (parse-partial-sexp beg (point) nil nil |
882 state)))) | 937 state)))) |
883 (put-text-property beg (point) 'face font-lock-string-face) | 938 (lazy-lock-put-text-property |
884 (setq state (parse-partial-sexp beg (point) | 939 beg (point) 'face font-lock-string-face) |
885 nil nil state)))) | 940 (setq state (parse-partial-sexp beg (point) |
886 ;; Likewise for a comment. | 941 nil nil state)))) |
887 (if (or (nth 4 state) (nth 7 state)) | 942 ;; Likewise for a comment. |
888 (let ((beg (point))) | 943 (if (or (nth 4 state) (nth 7 state)) |
889 (save-restriction | 944 (let ((beg (point))) |
890 (narrow-to-region (point-min) end) | 945 (save-restriction |
891 (condition-case nil | 946 (narrow-to-region (point-min) end) |
892 (progn | 947 (condition-case nil |
893 (re-search-backward comstart (point-min) 'move) | 948 (progn |
894 (forward-comment 1) | 949 (re-search-backward comstart (point-min) 'move) |
895 ;; forward-comment skips all whitespace, | 950 (forward-comment 1) |
896 ;; so go back to the real end of the comment. | 951 ;; forward-comment skips all whitespace, |
897 (skip-chars-backward " \t")) | 952 ;; so go back to the real end of the comment. |
898 (error (goto-char end)))) | 953 (skip-chars-backward " \t")) |
899 (put-text-property beg (point) 'face | 954 (error (goto-char end)))) |
900 font-lock-comment-face) | 955 (lazy-lock-put-text-property beg (point) 'face |
901 (setq state (parse-partial-sexp beg (point) | 956 font-lock-comment-face) |
902 nil nil state)))) | 957 (setq state (parse-partial-sexp beg (point) |
903 ;; Find each interesting place between here and END. | 958 nil nil state)))) |
904 (while (and (< (point) end) | 959 ;; Find each interesting place between here and END. |
905 (setq prev (point) prevstate state) | 960 (while (and (< (point) end) |
906 (re-search-forward synstart end t) | 961 (setq prev (point) prevstate state) |
907 (progn | 962 (re-search-forward synstart end t) |
908 ;; Clear out the fonts of what we skip over. | 963 (progn |
909 (remove-text-properties prev (point) '(face nil)) | 964 ;; Clear out the fonts of what we skip over. |
910 ;; Verify the state at that place | 965 (remove-text-properties prev (point) '(face nil)) |
911 ;; so we don't get fooled by \" or \;. | 966 ;; Verify the state at that place |
912 (setq state (parse-partial-sexp prev (point) | 967 ;; so we don't get fooled by \" or \;. |
913 nil nil state)))) | 968 (setq state (parse-partial-sexp prev (point) |
914 (let ((here (point))) | 969 nil nil state)))) |
915 (if (or (nth 4 state) (nth 7 state)) | 970 (let ((here (point))) |
916 ;; We found a real comment start. | 971 (if (or (nth 4 state) (nth 7 state)) |
917 (let ((beg (match-beginning 0))) | 972 ;; We found a real comment start. |
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) | |
933 (let ((beg (match-beginning 0))) | 973 (let ((beg (match-beginning 0))) |
934 (while (and (re-search-forward "\\s\"" end 'move) | 974 (goto-char beg) |
935 (nth 3 (parse-partial-sexp | 975 (save-restriction |
936 here (point) nil nil state)))) | 976 (narrow-to-region (point-min) end) |
937 (put-text-property beg (point) 'face | 977 (condition-case nil |
938 font-lock-string-face) | 978 (progn |
979 (forward-comment 1) | |
980 ;; forward-comment skips all whitespace, | |
981 ;; so go back to the real end of the comment. | |
982 (skip-chars-backward " \t")) | |
983 (error (goto-char end)))) | |
984 (lazy-lock-put-text-property | |
985 beg (point) 'face font-lock-comment-face) | |
939 (setq state (parse-partial-sexp here (point) | 986 (setq state (parse-partial-sexp here (point) |
940 nil nil state)))))) | 987 nil nil state))) |
941 ;; Make sure PREV is non-nil after the loop | 988 (if (nth 3 state) |
942 ;; only if it was set on the very last iteration. | 989 (let ((beg (match-beginning 0))) |
943 (setq prev nil))) | 990 (while (and (re-search-forward "\\s\"" end 'move) |
944 (set-syntax-table old-syntax) | 991 (nth 3 (parse-partial-sexp |
945 (and prev | 992 here (point) nil nil state)))) |
946 (remove-text-properties prev end '(face nil))) | 993 (lazy-lock-put-text-property |
947 (and (buffer-modified-p) | 994 beg (point) 'face font-lock-string-face) |
948 (not modified) | 995 (setq state (parse-partial-sexp here (point) |
949 (set-buffer-modified-p nil)))))))) | 996 nil nil state)))))) |
997 ;; Make sure PREV is non-nil after the loop | |
998 ;; only if it was set on the very last iteration. | |
999 (setq prev nil))) | |
1000 (set-syntax-table old-syntax) | |
1001 (and prev | |
1002 (remove-text-properties prev end '(face nil))) | |
1003 (and (buffer-modified-p) | |
1004 (not modified) | |
1005 (set-buffer-modified-p nil)))))))) | |
950 | 1006 |
951 ;; Functions for XEmacs: | 1007 ;; Functions for XEmacs: |
952 | 1008 |
953 ;; These fix bugs in `text-property-any' and `text-property-not-all'. They may | 1009 ;; These fix bugs in `text-property-any' and `text-property-not-all'. They may |
954 ;; not work perfectly in 19.11 and below because `next-single-property-change' | 1010 ;; not work perfectly in 19.11 and below because `next-single-property-change' |
955 ;; is also broke and not easily fixable in Lisp. | 1011 ;; is also broke and not easily fixable in Lisp. |
956 (when (and lazy-lock-running-xemacs | 1012 (if (and lazy-lock-running-xemacs-p |
957 (= emacs-major-version 19) (< emacs-minor-version 12)) | 1013 (not (emacs-version>= 19 12))) |
958 ;; Loop through property changes until found. This fix includes a work | 1014 (progn |
959 ;; around which prevents a bug in `window-start' causing a barf here. | 1015 ;; Loop through property changes until found. This fix includes a work |
960 (defun text-property-any (start end prop value &optional buffer) | 1016 ;; around which prevents a bug in `window-start' causing a barf here. |
961 "Check text from START to END to see if PROP is ever `eq' to VALUE. | 1017 (defun text-property-any (start end prop value &optional buffer) |
1018 "Check text from START to END to see if PROP is ever `eq' to VALUE. | |
962 If so, return the position of the first character whose PROP is `eq' | 1019 If so, return the position of the first character whose PROP is `eq' |
963 to VALUE. Otherwise return nil." | 1020 to VALUE. Otherwise return nil." |
964 (let ((start (min start end)) (end (max start end))) | 1021 (let ((start (min start end)) (end (max start end))) |
965 (while (and start (not (eq (get-text-property start prop buffer) value))) | 1022 (while (and start (not (eq (get-text-property start prop buffer) value))) |
966 (setq start (next-single-property-change start prop buffer end))) | 1023 (setq start (next-single-property-change start prop buffer end))) |
967 start)) | 1024 start)) |
968 ;; No need to loop here; if it's not at START it's at the next change. | 1025 ;; No need to loop here; if it's not at START it's at the next change. |
969 ;; However, `next-single-property-change' sometimes returns LIMIT, or | 1026 ;; However, `next-single-property-change' sometimes returns LIMIT, or |
970 ;; `point-max', if no change is found and sometimes returns nil. | 1027 ;; `point-max', if no change is found and sometimes returns nil. |
971 (defun text-property-not-all (start end prop value &optional buffer) | 1028 (defun text-property-not-all (start end prop value &optional buffer) |
972 "Check text from START to END to see if PROP is ever not `eq' to VALUE. | 1029 "Check text from START to END to see if PROP is ever not `eq' to VALUE. |
973 If so, return the position of the first character whose PROP is not | 1030 If so, return the position of the first character whose PROP is not |
974 `eq' to VALUE. Otherwise, return nil." | 1031 `eq' to VALUE. Otherwise, return nil." |
975 (if (not (eq value (get-text-property start prop buffer))) | 1032 (if (not (eq value (get-text-property start prop buffer))) |
976 start | 1033 start |
977 (let ((next (next-single-property-change start prop buffer end)) | 1034 (let ((next (next-single-property-change start prop buffer end)) |
978 (end (or end (save-excursion (and buffer (set-buffer buffer)) | 1035 (end (or end (save-excursion (and buffer (set-buffer buffer)) |
979 (point-max))))) | 1036 (point-max))))) |
980 (and next (< next end) next))))) | 1037 (and next (< next end) next)))))) |
981 | 1038 |
982 ;; XEmacs 19.11 function `font-lock-any-extents-p' looks for `text-prop' rather | 1039 ;; XEmacs 19.11 function `font-lock-any-extents-p' looks for `text-prop' rather |
983 ;; than `face'. Since `font-lock-unfontify-region' only removes `face', and we | 1040 ;; than `face'. Since `font-lock-unfontify-region' only removes `face', and we |
984 ;; have non-font-lock properties hanging about, `text-prop' never gets removed. | 1041 ;; have non-font-lock properties hanging about, `text-prop' never gets removed. |
985 ;; Unfortunately `font-lock-any-extents-p' is inlined so we can't redefine it. | 1042 ;; Unfortunately `font-lock-any-extents-p' is inlined so we can't redefine it. |
986 (when (and lazy-lock-running-xemacs | 1043 (if (and lazy-lock-running-xemacs-p |
987 (= emacs-major-version 19) (< emacs-minor-version 12)) | 1044 (not (emacs-version>= 19 12))) |
988 (add-hook 'font-lock-mode-hook | 1045 (add-hook 'font-lock-mode-hook |
989 (function (lambda () | 1046 (function (lambda () |
990 (remove-hook 'after-change-functions 'font-lock-after-change-function) | 1047 (remove-hook 'after-change-functions 'font-lock-after-change-function) |
991 (add-hook 'after-change-functions | 1048 (add-hook 'after-change-functions |
992 (function (lambda (beg end old-len) | 1049 (function (lambda (beg end old-len) |
993 (let ((a-c-beg beg) (a-c-end end)) | 1050 (let ((a-c-beg beg) (a-c-end end)) |
994 (save-excursion | 1051 (save-excursion |
995 ;; First set `text-prop' to nil for `font-lock-any-extents-p'. | 1052 ;; First set `text-prop' to nil for `font-lock-any-extents-p'. |
996 (goto-char end) (forward-line 1) (setq end (point)) | 1053 (goto-char end) (forward-line 1) (setq end (point)) |
997 (goto-char beg) (beginning-of-line) (setq beg (point)) | 1054 (goto-char beg) (beginning-of-line) (setq beg (point)) |
998 (put-text-property beg end 'text-prop nil) | 1055 (lazy-lock-put-text-property beg end 'text-prop nil) |
999 ;; Then do the real `font-lock-after-change-function'. | 1056 ;; Then do the real `font-lock-after-change-function'. |
1000 (font-lock-after-change-function a-c-beg a-c-end old-len) | 1057 (font-lock-after-change-function a-c-beg a-c-end old-len) |
1001 ;; Now set `fontified' to t to stop `lazy-lock-fontify-window'. | 1058 ;; Now set `fontified' to t to stop `lazy-lock-fontify-window'. |
1002 (put-text-property beg end 'fontified t)))))))))) | 1059 (lazy-lock-put-text-property beg end 'fontified t)))))))))) |
1003 | 1060 |
1004 ;; XEmacs 19.12 font-lock.el's `font-lock-fontify-buffer' runs a hook. | 1061 (if (and lazy-lock-running-xemacs-p (emacs-version>= 19 12)) |
1005 (when lazy-lock-running-xemacs | 1062 ;; XEmacs 19.12 font-lock.el's `font-lock-fontify-buffer' runs a hook. |
1006 (add-hook 'font-lock-after-fontify-buffer-hook | 1063 (add-hook 'font-lock-after-fontify-buffer-hook |
1007 'lazy-lock-after-fontify-buffer)) | 1064 'lazy-lock-after-fontify-buffer)) |
1008 | 1065 |
1009 ;; Cope with the differences between Emacs and earlier [LX]Emacs. | 1066 ;; Cope with the differences between Emacs and [LX]Emacs. |
1010 (unless (fboundp 'frame-parameters) | 1067 (or (fboundp 'frame-parameters) |
1011 (defalias 'frame-parameters 'screen-parameters)) | 1068 (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)) | |
1016 | 1069 |
1017 ;; Install ourselves: | 1070 ;; Install ourselves: |
1018 | 1071 |
1019 ;; We don't install ourselves on `font-lock-mode-hook' as other packages can be | 1072 ;; We don't install ourselves on `font-lock-mode-hook' as other packages can be |
1020 ;; used with font-lock.el, and lazy-lock.el should be dumpable without forcing | 1073 ;; used with font-lock.el, and lazy-lock.el should be dumpable without forcing |
1021 ;; people to get lazy or making it difficult for people to use alternatives. | 1074 ;; people to get lazy or making it difficult for people to use alternatives. |
1022 | 1075 ;; make sure we add after font-lock's own pre-idle-hook. |
1023 ;; After a command is run. | |
1024 (lazy-lock-post-command-setup) | |
1025 | |
1026 ;; After some relevant event. | |
1027 (add-hook 'window-setup-hook 'lazy-lock-post-setup-emacs-fontify-windows) | 1076 (add-hook 'window-setup-hook 'lazy-lock-post-setup-emacs-fontify-windows) |
1028 (add-hook 'window-size-change-functions 'lazy-lock-post-resize-fontify-windows) | 1077 ;Not needed in XEmacs 19.14: |
1078 ;(add-hook 'window-size-change-functions 'lazy-lock-post-resize-fontify-windows) | |
1029 | 1079 |
1030 ;; Package-specific. | 1080 ;; Package-specific. |
1031 (add-hook 'ediff-after-setup-control-frame-hooks ; Emacs 19.29, Ediff 2.26. | 1081 (add-hook 'ediff-after-setup-control-frame-hooks |
1032 'lazy-lock-post-setup-ediff-control-frame) | 1082 '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) | |
1035 | 1083 |
1036 ;; Might as well uninstall too. Package-local symbols would be nice... | 1084 ;; Might as well uninstall too. Package-local symbols would be nice... |
1037 (when (fboundp 'unintern) | 1085 (and (fboundp 'unintern) (unintern 'lazy-lock-running-xemacs-p)) |
1038 (unintern 'lazy-lock-running-xemacs) | 1086 (and (fboundp 'unintern) (unintern 'lazy-lock-sit-for)) |
1039 (unintern 'lazy-lock-sit-for)) | 1087 |
1040 | 1088 ;; Maybe save on the modeline? |
1089 ;;(setcdr (assq 'font-lock-mode minor-mode-alist) '(" Lazy")) | |
1090 | |
1091 ;(or (assq 'lazy-lock-mode minor-mode-alist) | |
1092 ; (setq minor-mode-alist (cons '(lazy-lock-mode " Lazy") minor-mode-alist))) | |
1093 | |
1094 ;; XEmacs change: do it the right way. This works with modeline mousing. | |
1041 ;;;###autoload | 1095 ;;;###autoload |
1042 (when (fboundp 'add-minor-mode) | 1096 (add-minor-mode 'lazy-lock-mode " Lazy") |
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))))) | |
1048 | 1097 |
1049 ;; Provide ourselves: | 1098 ;; Provide ourselves: |
1050 | 1099 |
1051 (provide 'lazy-lock) | 1100 (provide 'lazy-lock) |
1052 | 1101 |