Mercurial > emacs
comparison lisp/lazy-lock.el @ 15499:aa9675ed8ed4
Test for lazy-lock-mode before swapping hooks.
author | Simon Marshall <simon@gnu.org> |
---|---|
date | Mon, 24 Jun 1996 07:48:15 +0000 |
parents | a0dc879461b8 |
children | f4429e6fe33c |
comparison
equal
deleted
inserted
replaced
15498:4cd3efec2909 | 15499:aa9675ed8ed4 |
---|---|
2 | 2 |
3 ;; Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1994, 1995, 1996 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: 2.05 | 7 ;; Version: 2.06 |
8 | 8 |
9 ;;; This file is part of GNU Emacs. | 9 ;;; This file is part of GNU Emacs. |
10 | 10 |
11 ;; 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 |
12 ;; 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 |
36 | 36 |
37 ;; Installation: | 37 ;; Installation: |
38 ;; | 38 ;; |
39 ;; Put in your ~/.emacs: | 39 ;; Put in your ~/.emacs: |
40 ;; | 40 ;; |
41 ;; (autoload 'turn-on-lazy-lock "lazy-lock" | 41 ;; (setq font-lock-support-mode 'lazy-lock-mode) |
42 ;; "Unconditionally turn on Lazy Lock mode.") | |
43 ;; | |
44 ;; (add-hook 'font-lock-mode-hook 'turn-on-lazy-lock) | |
45 ;; | 42 ;; |
46 ;; Start up a new Emacs and use font-lock as usual (except that you can use the | 43 ;; Start up a new Emacs and use font-lock as usual (except that you can use the |
47 ;; so-called "gaudier" fontification regexps on big files without frustration). | 44 ;; so-called "gaudier" fontification regexps on big files without frustration). |
48 ;; | 45 ;; |
49 ;; In a buffer (which has `font-lock-mode' enabled) which is at least | 46 ;; In a buffer (which has `font-lock-mode' enabled) which is at least |
157 ;; Caveats: | 154 ;; Caveats: |
158 ;; | 155 ;; |
159 ;; Lazy Lock mode does not work efficiently with Outline mode. This is because | 156 ;; Lazy Lock mode does not work efficiently with Outline mode. This is because |
160 ;; when in Outline mode, although text may be hidden (not visible in the | 157 ;; when in Outline mode, although text may be hidden (not visible in the |
161 ;; window), the text is visible to Emacs Lisp code (not surprisingly) and Lazy | 158 ;; window), the text is visible to Emacs Lisp code (not surprisingly) and Lazy |
162 ;; Lock fontifies it mercilessly. Hopefully this will be fixed one day. | 159 ;; Lock fontifies it mercilessly. Maybe it will be fixed one day. |
163 ;; | 160 ;; |
164 ;; Because buffer text is not necessarily fontified, other packages that expect | 161 ;; Because buffer text is not necessarily fontified, other packages that expect |
165 ;; buffer text to be fontified in Font Lock mode either might not work as | 162 ;; buffer text to be fontified in Font Lock mode either might not work as |
166 ;; expected, or might not display buffer text as expected. An example of the | 163 ;; expected, or might not display buffer text as expected. An example of the |
167 ;; latter is `occur', which copies lines of buffer text into another buffer. | 164 ;; latter is `occur', which copies lines of buffer text into another buffer. |
173 ;; In Emacs 19.30, Lazy Lock mode does not work well with Transient Mark mode | 170 ;; In Emacs 19.30, Lazy Lock mode does not work well with Transient Mark mode |
174 ;; or modes based on Comint mode (e.g., Shell mode), and also interferes with | 171 ;; or modes based on Comint mode (e.g., Shell mode), and also interferes with |
175 ;; the echoing of keystrokes in the minibuffer. This is because of the way | 172 ;; the echoing of keystrokes in the minibuffer. This is because of the way |
176 ;; deferral and stealth have to be implemented for Emacs 19.30. Upgrade! | 173 ;; deferral and stealth have to be implemented for Emacs 19.30. Upgrade! |
177 ;; | 174 ;; |
178 ;; Currently XEmacs does not have the features to support lazy-lock.el. Maybe | 175 ;; Currently XEmacs does not have the features to support this version of |
179 ;; it will one day. | 176 ;; lazy-lock.el. Maybe it will one day. |
180 | 177 |
181 ;; Feedback: | 178 ;; Feedback: |
182 ;; | 179 ;; |
183 ;; Feedback is welcome. | 180 ;; Feedback is welcome. |
184 ;; To submit a bug report (or make comments) please use the mechanism provided: | 181 ;; To submit a bug report (or make comments) please use the mechanism provided: |
229 ;; - Added `do-while' macro | 226 ;; - Added `do-while' macro |
230 ;; - Renamed `lazy-lock-let-buffer-state' macro to `save-buffer-state' | 227 ;; - Renamed `lazy-lock-let-buffer-state' macro to `save-buffer-state' |
231 ;; - Returned `lazy-lock-fontify-after-install' hack (Darren Hall hint) | 228 ;; - Returned `lazy-lock-fontify-after-install' hack (Darren Hall hint) |
232 ;; - Added `lazy-lock-defer-driven' functionality (Scott Byer hint) | 229 ;; - Added `lazy-lock-defer-driven' functionality (Scott Byer hint) |
233 ;; - Made `lazy-lock-mode' wrap `font-lock-support-mode' | 230 ;; - Made `lazy-lock-mode' wrap `font-lock-support-mode' |
231 ;; 2.05--2.06: | |
232 ;; - Made `lazy-lock-fontify-after-defer' swap correctly (Scott Byer report) | |
234 | 233 |
235 (require 'font-lock) | 234 (require 'font-lock) |
236 | 235 |
237 ;; Make sure lazy-lock.el is supported. | 236 ;; Make sure lazy-lock.el is supported. |
238 (if (if (save-match-data (string-match "Lucid\\|XEmacs" (emacs-version))) | 237 (if (if (save-match-data (string-match "Lucid\\|XEmacs" (emacs-version))) |
292 | 291 |
293 The value of this variable is used when Lazy Lock mode is turned on.") | 292 The value of this variable is used when Lazy Lock mode is turned on.") |
294 | 293 |
295 (defvar lazy-lock-defer-driven nil | 294 (defvar lazy-lock-defer-driven nil |
296 "*If non-nil, means fontification should be defer-driven. | 295 "*If non-nil, means fontification should be defer-driven. |
297 If nil, means demand-driven fontification is performed. This means when the | 296 If nil, means demand-driven fontification is performed. This means when |
298 window scrolls into unfontified areas of the buffer, those areas are | 297 scrolling into unfontified areas of the buffer, those areas are immediately |
299 immediately fontified. Thus scrolling never presents unfontified areas. | 298 fontified. Thus scrolling never presents unfontified areas. However, since |
300 However, since fontification occurs during scrolling, scrolling may be slow. | 299 fontification occurs during scrolling, scrolling may be slow. |
301 If t, means defer-driven fontification is performed. This means fontification | 300 If t, means defer-driven fontification is performed. This means fontification |
302 of those areas is deferred. Thus scrolling may present momentarily unfontified | 301 of those areas is deferred. Thus scrolling may present momentarily unfontified |
303 areas. However, since fontification does not occur during scrolling, scrolling | 302 areas. However, since fontification does not occur during scrolling, scrolling |
304 will be faster than demand-driven fontification. | 303 will be faster than demand-driven fontification. |
305 If non-nil and non-t, means buffer demand-driven fontification is performed | 304 If any other value, e.g., `eventually', means demand-driven fontification is |
306 until the buffer is fontified, then buffer fontification becomes defer-driven. | 305 performed until the buffer is fontified, then buffer fontification becomes |
307 Thus scrolling never presents unfontified areas until the buffer is fontified, | 306 defer-driven. Thus scrolling never presents unfontified areas until the buffer |
308 at which point subsequent scrolling may present future buffer insertions | 307 is first fontified, after which subsequent scrolling may present future buffer |
309 momentarily unfontified. However, since fontification does not occur during | 308 insertions momentarily unfontified. However, since fontification does not |
310 scrolling once the buffer is fontified, scrolling will become faster. | 309 occur during scrolling after the buffer is first fontified, scrolling will |
310 become faster. | |
311 | 311 |
312 The value of this variable is used when Lazy Lock mode is turned on.") | 312 The value of this variable is used when Lazy Lock mode is turned on.") |
313 | 313 |
314 (defvar lazy-lock-defer-time | 314 (defvar lazy-lock-defer-time |
315 (if (featurep 'lisp-float-type) (/ (float 1) (float 4)) 1) | 315 (if (featurep 'lisp-float-type) (/ (float 1) (float 4)) 1) |
331 Stealth fontification occurs if there is no input within this time. | 331 Stealth fontification occurs if there is no input within this time. |
332 If nil, means stealth fontification is never performed. | 332 If nil, means stealth fontification is never performed. |
333 | 333 |
334 The value of this variable is used when Lazy Lock mode is turned on.") | 334 The value of this variable is used when Lazy Lock mode is turned on.") |
335 | 335 |
336 (defvar lazy-lock-stealth-lines (if font-lock-maximum-decoration 100 200) | 336 (defvar lazy-lock-stealth-lines (if font-lock-maximum-decoration 100 250) |
337 "*Maximum size of a chunk of stealth fontification. | 337 "*Maximum size of a chunk of stealth fontification. |
338 Each iteration of stealth fontification can fontify this number of lines. | 338 Each iteration of stealth fontification can fontify this number of lines. |
339 To speed up input response during stealth fontification, at the cost of stealth | 339 To speed up input response during stealth fontification, at the cost of stealth |
340 taking longer to fontify, you could reduce the value of this variable.") | 340 taking longer to fontify, you could reduce the value of this variable.") |
341 | 341 |
344 "*Time in seconds to pause between chunks of stealth fontification. | 344 "*Time in seconds to pause between chunks of stealth fontification. |
345 Each iteration of stealth fontification is separated by this amount of time. | 345 Each iteration of stealth fontification is separated by this amount of time. |
346 To reduce machine load during stealth fontification, at the cost of stealth | 346 To reduce machine load during stealth fontification, at the cost of stealth |
347 taking longer to fontify, you could increase the value of this variable.") | 347 taking longer to fontify, you could increase the value of this variable.") |
348 | 348 |
349 (defvar lazy-lock-stealth-verbose font-lock-verbose | 349 (defvar lazy-lock-stealth-verbose (not (null font-lock-verbose)) |
350 "*If non-nil, means stealth fontification should show status messages.") | 350 "*If non-nil, means stealth fontification should show status messages.") |
351 | 351 |
352 (defvar lazy-lock-mode nil) | 352 (defvar lazy-lock-mode nil) |
353 (defvar lazy-lock-buffers nil) ; for deferral | 353 (defvar lazy-lock-buffers nil) ; for deferral |
354 (defvar lazy-lock-timers (cons nil nil)) ; for deferral and stealth | 354 (defvar lazy-lock-timers (cons nil nil)) ; for deferral and stealth |
410 | 410 |
411 (defun lazy-lock-submit-bug-report () | 411 (defun lazy-lock-submit-bug-report () |
412 "Submit via mail a bug report on lazy-lock.el." | 412 "Submit via mail a bug report on lazy-lock.el." |
413 (interactive) | 413 (interactive) |
414 (let ((reporter-prompt-for-summary-p t)) | 414 (let ((reporter-prompt-for-summary-p t)) |
415 (reporter-submit-bug-report "simon@gnu.ai.mit.edu" "lazy-lock 2.05" | 415 (reporter-submit-bug-report "simon@gnu.ai.mit.edu" "lazy-lock 2.06" |
416 '(lazy-lock-minimum-size lazy-lock-defer-driven lazy-lock-defer-time | 416 '(lazy-lock-minimum-size lazy-lock-defer-driven lazy-lock-defer-time |
417 lazy-lock-stealth-time lazy-lock-stealth-nice lazy-lock-stealth-lines | 417 lazy-lock-stealth-time lazy-lock-stealth-nice lazy-lock-stealth-lines |
418 lazy-lock-stealth-verbose) | 418 lazy-lock-stealth-verbose) |
419 nil nil | 419 nil nil |
420 (concat "Hi Si., | 420 (concat "Hi Si., |
596 (let ((windows (get-buffer-window-list (car lazy-lock-buffers) 'nomini t))) | 596 (let ((windows (get-buffer-window-list (car lazy-lock-buffers) 'nomini t))) |
597 (while windows | 597 (while windows |
598 (lazy-lock-fontify-window (car windows)) | 598 (lazy-lock-fontify-window (car windows)) |
599 (setq windows (cdr windows))) | 599 (setq windows (cdr windows))) |
600 (setq lazy-lock-buffers (cdr lazy-lock-buffers)))) | 600 (setq lazy-lock-buffers (cdr lazy-lock-buffers)))) |
601 ;; Add hook if fontification should be defer-driven from now on. | 601 ;; Add hook if fontification should now be defer-driven in this buffer. |
602 (unless (or (not lazy-lock-defer-driven) (eq lazy-lock-defer-driven t) | 602 (when (and lazy-lock-mode lazy-lock-defer-driven |
603 (memq 'lazy-lock-defer-after-scroll window-scroll-functions) | 603 (memq 'lazy-lock-fontify-after-scroll window-scroll-functions) |
604 (input-pending-p) (lazy-lock-unfontified-p)) | 604 (not (or (input-pending-p) (lazy-lock-unfontified-p)))) |
605 (remove-hook 'window-scroll-functions 'lazy-lock-fontify-after-scroll t) | 605 (remove-hook 'window-scroll-functions 'lazy-lock-fontify-after-scroll t) |
606 (add-hook 'window-scroll-functions 'lazy-lock-defer-after-scroll nil t))) | 606 (add-hook 'window-scroll-functions 'lazy-lock-defer-after-scroll nil t))) |
607 | 607 |
608 (defun lazy-lock-fontify-after-idle () | 608 (defun lazy-lock-fontify-after-idle () |
609 ;; Called from `timer-idle-list'. | 609 ;; Called from `timer-idle-list'. |
626 (message "Fontifying stealthily...") | 626 (message "Fontifying stealthily...") |
627 (setq message t))) | 627 (setq message t))) |
628 (lazy-lock-fontify-chunk))) | 628 (lazy-lock-fontify-chunk))) |
629 (setq buffers (cdr buffers)))) | 629 (setq buffers (cdr buffers)))) |
630 (when message | 630 (when message |
631 (message "Fontifying stealthily...%s" (if continue "done" "quit"))) | 631 (message "Fontifying stealthily...%s" (if continue "done" "quit")))))) |
632 ))) | |
633 | 632 |
634 (defun lazy-lock-fontify-after-outline () | 633 (defun lazy-lock-fontify-after-outline () |
635 ;; Called from `outline-view-change-hook'. | 634 ;; Called from `outline-view-change-hook'. |
636 ;; Fontify windows showing the current buffer, as its visibility has changed. | 635 ;; Fontify windows showing the current buffer, as its visibility has changed. |
637 ;; This is a conspiracy hack between lazy-lock.el and noutline.el. | 636 ;; This is a conspiracy hack between lazy-lock.el and noutline.el. |
811 minibuf frame) | 810 minibuf frame) |
812 windows))) | 811 windows))) |
813 | 812 |
814 ;; Install ourselves: | 813 ;; Install ourselves: |
815 | 814 |
816 ;; We don't install ourselves on `font-lock-mode-hook' as other packages can be | |
817 ;; used with font-lock.el, and lazy-lock.el should be dumpable without forcing | |
818 ;; people to get lazy or making it difficult for people to use alternatives. | |
819 (add-hook 'window-size-change-functions 'lazy-lock-fontify-after-resize) | 815 (add-hook 'window-size-change-functions 'lazy-lock-fontify-after-resize) |
820 (add-hook 'redisplay-end-trigger-functions 'lazy-lock-fontify-after-trigger) | 816 (add-hook 'redisplay-end-trigger-functions 'lazy-lock-fontify-after-trigger) |
821 | 817 |
822 (unless (assq 'lazy-lock-mode minor-mode-alist) | 818 (unless (assq 'lazy-lock-mode minor-mode-alist) |
823 (setq minor-mode-alist (append minor-mode-alist '((lazy-lock-mode nil))))) | 819 (setq minor-mode-alist (append minor-mode-alist '((lazy-lock-mode nil))))) |