Mercurial > emacs
comparison lisp/lazy-lock.el @ 23753:c1bedc24e8af
* lazy-lock.el (lazy-lock-unstall):
(lazy-lock-fontify-after-idle): Rewritten to use with-temp-message.
author | Simon Marshall <simon@gnu.org> |
---|---|
date | Mon, 23 Nov 1998 11:14:33 +0000 |
parents | bd6a5af23e19 |
children | 42a8238f0597 |
comparison
equal
deleted
inserted
replaced
23752:001e0e875d56 | 23753:c1bedc24e8af |
---|---|
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, 1996, 1997 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: Simon Marshall <simon@gnu.org> | 5 ;; Author: Simon Marshall <simon@gnu.org> |
6 ;; Keywords: faces files | 6 ;; Keywords: faces files |
7 ;; Version: 2.10 | 7 ;; Version: 2.11 |
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 |
255 ;; - Removed `byte-*' variables from `eval-when-compile' (Erik Naggum hint) | 255 ;; - Removed `byte-*' variables from `eval-when-compile' (Erik Naggum hint) |
256 ;; - Made various wrapping `inhibit-point-motion-hooks' (Vinicius Latorre hint) | 256 ;; - Made various wrapping `inhibit-point-motion-hooks' (Vinicius Latorre hint) |
257 ;; - Made `lazy-lock-fontify-after-idle' wrap `minibuffer-auto-raise' | 257 ;; - Made `lazy-lock-fontify-after-idle' wrap `minibuffer-auto-raise' |
258 ;; - Made `lazy-lock-fontify-after-defer' paranoid about deferred buffers | 258 ;; - Made `lazy-lock-fontify-after-defer' paranoid about deferred buffers |
259 ;; 2.09--2.10: | 259 ;; 2.09--2.10: |
260 ;; - Use `window-end' UPDATE arg for Emacs 20.3 and later. | 260 ;; - Use `window-end' UPDATE arg for Emacs 20.4 and later. |
261 ;; - Made deferral `widen' before unfontifying (Dan Nicolaescu report) | 261 ;; - Made deferral `widen' before unfontifying (Dan Nicolaescu report) |
262 ;; - Use `lazy-lock-fontify-after-visage' for hideshow.el (Dan Nicolaescu hint) | 262 ;; - Use `lazy-lock-fontify-after-visage' for hideshow.el (Dan Nicolaescu hint) |
263 ;; - Use `other' widget where possible (Andreas Schwab fix) | 263 ;; - Use `other' widget where possible (Andreas Schwab fix) |
264 ;; 2.10--2.11: | |
265 ;; - Used `with-temp-message' where possible to make messages temporary. | |
264 | 266 |
265 ;;; Code: | 267 ;;; Code: |
266 | 268 |
267 (require 'font-lock) | 269 (require 'font-lock) |
268 | 270 |
307 The value returned is the value of the last form in BODY." | 309 The value returned is the value of the last form in BODY." |
308 (` (save-excursion (set-buffer (, buffer)) (,@ body))))) | 310 (` (save-excursion (set-buffer (, buffer)) (,@ body))))) |
309 (put 'with-current-buffer 'lisp-indent-function 1) | 311 (put 'with-current-buffer 'lisp-indent-function 1) |
310 ;; | 312 ;; |
311 ;; We use this for compatibility with a future Emacs. | 313 ;; We use this for compatibility with a future Emacs. |
314 (or (fboundp 'with-temp-message) | |
315 (defmacro with-temp-message (message &rest body) | |
316 (` (let ((current-message (current-message))) | |
317 (unwind-protect | |
318 (progn (message (, message)) (,@ body)) | |
319 (message current-message)))))) | |
320 ;; | |
321 ;; We use this for compatibility with a future Emacs. | |
312 (or (fboundp 'defcustom) | 322 (or (fboundp 'defcustom) |
313 (defmacro defcustom (symbol value doc &rest args) | 323 (defmacro defcustom (symbol value doc &rest args) |
314 (` (defvar (, symbol) (, value) (, doc)))))) | 324 (` (defvar (, symbol) (, value) (, doc)))))) |
315 | 325 |
316 ;(defun lazy-lock-submit-bug-report () | 326 ;(defun lazy-lock-submit-bug-report () |
317 ; "Submit via mail a bug report on lazy-lock.el." | 327 ; "Submit via mail a bug report on lazy-lock.el." |
318 ; (interactive) | 328 ; (interactive) |
319 ; (let ((reporter-prompt-for-summary-p t)) | 329 ; (let ((reporter-prompt-for-summary-p t)) |
320 ; (reporter-submit-bug-report "simon@gnu.ai.mit.edu" "lazy-lock 2.10" | 330 ; (reporter-submit-bug-report "simon@gnu.ai.mit.edu" "lazy-lock 2.11" |
321 ; '(lazy-lock-minimum-size lazy-lock-defer-on-the-fly | 331 ; '(lazy-lock-minimum-size lazy-lock-defer-on-the-fly |
322 ; lazy-lock-defer-on-scrolling lazy-lock-defer-contextually | 332 ; lazy-lock-defer-on-scrolling lazy-lock-defer-contextually |
323 ; lazy-lock-defer-time lazy-lock-stealth-time | 333 ; lazy-lock-defer-time lazy-lock-stealth-time |
324 ; lazy-lock-stealth-load lazy-lock-stealth-nice lazy-lock-stealth-lines | 334 ; lazy-lock-stealth-load lazy-lock-stealth-nice lazy-lock-stealth-lines |
325 ; lazy-lock-stealth-verbose) | 335 ; lazy-lock-stealth-verbose) |
336 (defvar lazy-lock-buffers nil) ; For deferral. | 346 (defvar lazy-lock-buffers nil) ; For deferral. |
337 (defvar lazy-lock-timers (cons nil nil)) ; For deferral and stealth. | 347 (defvar lazy-lock-timers (cons nil nil)) ; For deferral and stealth. |
338 | 348 |
339 ;; User Variables: | 349 ;; User Variables: |
340 | 350 |
341 (defcustom lazy-lock-minimum-size (* 25 1024) | 351 (defcustom lazy-lock-minimum-size 25600 |
342 "*Minimum size of a buffer for demand-driven fontification. | 352 "*Minimum size of a buffer for demand-driven fontification. |
343 On-demand fontification occurs if the buffer size is greater than this value. | 353 On-demand fontification occurs if the buffer size is greater than this value. |
344 If nil, means demand-driven fontification is never performed. | 354 If nil, means demand-driven fontification is never performed. |
345 If a list, each element should be a cons pair of the form (MAJOR-MODE . SIZE), | 355 If a list, each element should be a cons pair of the form (MAJOR-MODE . SIZE), |
346 where MAJOR-MODE is a symbol or t (meaning the default). For example: | 356 where MAJOR-MODE is a symbol or t (meaning the default). For example: |
667 (when font-lock-mode | 677 (when font-lock-mode |
668 (when (lazy-lock-unfontified-p) | 678 (when (lazy-lock-unfontified-p) |
669 (let ((verbose (if (numberp font-lock-verbose) | 679 (let ((verbose (if (numberp font-lock-verbose) |
670 (> (buffer-size) font-lock-verbose) | 680 (> (buffer-size) font-lock-verbose) |
671 font-lock-verbose))) | 681 font-lock-verbose))) |
672 (if verbose (message "Fontifying %s..." (buffer-name))) | 682 (with-temp-message |
673 ;; Make sure we fontify etc. in the whole buffer. | 683 (if verbose |
674 (save-restriction | 684 (format "Fontifying %s..." (buffer-name)) |
675 (widen) | 685 (current-message)) |
676 (lazy-lock-fontify-region (point-min) (point-max))) | 686 ;; Make sure we fontify etc. in the whole buffer. |
677 (if verbose (message "Fontifying %s...%s" (buffer-name) | 687 (save-restriction |
678 (if (lazy-lock-unfontified-p) "quit" "done"))))) | 688 (widen) |
689 (lazy-lock-fontify-region (point-min) (point-max)))))) | |
679 (add-hook 'after-change-functions 'font-lock-after-change-function nil t)) | 690 (add-hook 'after-change-functions 'font-lock-after-change-function nil t)) |
680 ;; | 691 ;; |
681 ;; Remove the text properties. | 692 ;; Remove the text properties. |
682 (lazy-lock-after-unfontify-buffer) | 693 (lazy-lock-after-unfontify-buffer) |
683 ;; | 694 ;; |
861 (do-while (and buffers continue) | 872 (do-while (and buffers continue) |
862 (set-buffer (car buffers)) | 873 (set-buffer (car buffers)) |
863 (if (not (and lazy-lock-mode (lazy-lock-unfontified-p))) | 874 (if (not (and lazy-lock-mode (lazy-lock-unfontified-p))) |
864 (setq continue (not (input-pending-p))) | 875 (setq continue (not (input-pending-p))) |
865 ;; Fontify regions in this buffer while there is no input. | 876 ;; Fontify regions in this buffer while there is no input. |
866 (do-while (and (lazy-lock-unfontified-p) continue) | 877 (with-temp-message |
867 (if (and lazy-lock-stealth-load | 878 (if lazy-lock-stealth-verbose |
868 (> (car (load-average)) lazy-lock-stealth-load)) | 879 "Fontifying stealthily..." |
869 ;; Wait a while before continuing with the loop. | 880 (current-message)) |
870 (progn | 881 (do-while (and (lazy-lock-unfontified-p) continue) |
871 (when message | 882 (if (and lazy-lock-stealth-load |
872 (message "Fontifying stealthily...suspended") | 883 (> (car (load-average)) lazy-lock-stealth-load)) |
873 (setq message nil)) | 884 ;; Wait a while before continuing with the loop. |
874 (setq continue (sit-for (or lazy-lock-stealth-time 30)))) | 885 (progn |
875 ;; Fontify a chunk. | 886 (when message |
876 (when lazy-lock-stealth-verbose | 887 (message "Fontifying stealthily...suspended") |
877 (if message | 888 (setq message nil)) |
878 (message "Fontifying stealthily... %2d%% of %s" | 889 (setq continue (sit-for (or lazy-lock-stealth-time 30)))) |
879 (lazy-lock-percent-fontified) (buffer-name)) | 890 ;; Fontify a chunk. |
880 (message "Fontifying stealthily...") | 891 (when lazy-lock-stealth-verbose |
881 (setq message t))) | 892 (if message |
882 (lazy-lock-fontify-chunk) | 893 (message "Fontifying stealthily... %2d%% of %s" |
883 (setq continue (sit-for (or lazy-lock-stealth-nice 0)))))) | 894 (lazy-lock-percent-fontified) (buffer-name)) |
884 (setq buffers (cdr buffers)))) | 895 (message "Fontifying stealthily...") |
885 (when message | 896 (setq message t))) |
886 (message "Fontifying stealthily...%s" (if continue "done" "quit")))))) | 897 (lazy-lock-fontify-chunk) |
898 (setq continue (sit-for (or lazy-lock-stealth-nice 0))))))) | |
899 (setq buffers (cdr buffers))))))) | |
887 | 900 |
888 ;; 4. Special circumstances. | 901 ;; 4. Special circumstances. |
889 | 902 |
890 (defun lazy-lock-fontify-after-visage () | 903 (defun lazy-lock-fontify-after-visage () |
891 ;; Called from `outline-view-change-hook' and `hs-hide-hook'. | 904 ;; Called from `outline-view-change-hook' and `hs-hide-hook'. |
1047 (mapcar 'lazy-lock-fontify-conservatively | 1060 (mapcar 'lazy-lock-fontify-conservatively |
1048 (get-buffer-window-list (pop lazy-lock-install) 'nomini t))))) | 1061 (get-buffer-window-list (pop lazy-lock-install) 'nomini t))))) |
1049 | 1062 |
1050 (when (if (save-match-data (string-match "Lucid\\|XEmacs" (emacs-version))) | 1063 (when (if (save-match-data (string-match "Lucid\\|XEmacs" (emacs-version))) |
1051 nil | 1064 nil |
1052 (or (and (= emacs-major-version 20) (< emacs-minor-version 3)) | 1065 (or (and (= emacs-major-version 20) (< emacs-minor-version 4)) |
1053 (= emacs-major-version 19))) | 1066 (= emacs-major-version 19))) |
1054 ;; | 1067 ;; |
1055 ;; We use `vertical-motion' rather than `window-end' UPDATE arg. | 1068 ;; We use `vertical-motion' rather than `window-end' UPDATE arg. |
1056 (defun lazy-lock-fontify-after-scroll (window window-start) | 1069 (defun lazy-lock-fontify-after-scroll (window window-start) |
1057 ;; Called from `window-scroll-functions'. | 1070 ;; Called from `window-scroll-functions'. |
1078 ;; In 2.06.04 and below, `lazy-lock-defer-time' could specify modes and time. | 1091 ;; In 2.06.04 and below, `lazy-lock-defer-time' could specify modes and time. |
1079 (with-output-to-temp-buffer "*Help*" | 1092 (with-output-to-temp-buffer "*Help*" |
1080 (princ "The value of the variable `lazy-lock-defer-time' was\n ") | 1093 (princ "The value of the variable `lazy-lock-defer-time' was\n ") |
1081 (princ lazy-lock-defer-time) | 1094 (princ lazy-lock-defer-time) |
1082 (princ "\n") | 1095 (princ "\n") |
1083 (princ "This variable cannot now be a list of modes and time, ") | 1096 (princ "This variable cannot now be a list of modes and time,\n") |
1084 (princ "so instead use the forms:\n") | 1097 (princ "so instead use ") |
1098 (princ (substitute-command-keys "\\[customize-option]")) | |
1099 (princ " to modify the variables, or put the forms:\n") | |
1085 (princ " (setq lazy-lock-defer-time ") | 1100 (princ " (setq lazy-lock-defer-time ") |
1086 (princ (cdr lazy-lock-defer-time)) | 1101 (princ (cdr lazy-lock-defer-time)) |
1087 (princ ")\n") | 1102 (princ ")\n") |
1088 (princ " (setq lazy-lock-defer-on-the-fly '") | 1103 (princ " (setq lazy-lock-defer-on-the-fly '") |
1089 (princ (car lazy-lock-defer-time)) | 1104 (princ (car lazy-lock-defer-time)) |
1090 (princ ")\n") | 1105 (princ ")\n") |
1091 (princ "in your ~/.emacs. ") | 1106 (princ "in your ~/.emacs. ") |
1092 (princ "The above forms have been evaluated for this editor session,\n") | 1107 (princ "The above forms have been evaluated for this editor session,\n") |
1093 (princ "but you should change your ~/.emacs now.")) | 1108 (princ "but you should use ") |
1109 (princ (substitute-command-keys "\\[customize-option]")) | |
1110 (princ " or change your ~/.emacs now.")) | |
1094 (setq lazy-lock-defer-on-the-fly (car lazy-lock-defer-time) | 1111 (setq lazy-lock-defer-on-the-fly (car lazy-lock-defer-time) |
1095 lazy-lock-defer-time (cdr lazy-lock-defer-time))) | 1112 lazy-lock-defer-time (cdr lazy-lock-defer-time))) |
1096 | 1113 |
1097 (when (boundp 'lazy-lock-defer-driven) | 1114 (when (boundp 'lazy-lock-defer-driven) |
1098 ;; | 1115 ;; |
1104 (princ "`") | 1121 (princ "`") |
1105 (princ lazy-lock-defer-driven) | 1122 (princ lazy-lock-defer-driven) |
1106 (princ "'")) | 1123 (princ "'")) |
1107 (princ ".\n") | 1124 (princ ".\n") |
1108 (princ "This variable is now called `lazy-lock-defer-on-scrolling',\n") | 1125 (princ "This variable is now called `lazy-lock-defer-on-scrolling',\n") |
1109 (princ "so instead use the form:\n") | 1126 (princ "so instead use ") |
1127 (princ (substitute-command-keys "\\[customize-option]")) | |
1128 (princ " to modify the variable, or put the form:\n") | |
1110 (princ " (setq lazy-lock-defer-on-scrolling ") | 1129 (princ " (setq lazy-lock-defer-on-scrolling ") |
1111 (unless (memq lazy-lock-defer-driven '(nil t)) | 1130 (unless (memq lazy-lock-defer-driven '(nil t)) |
1112 (princ "'")) | 1131 (princ "'")) |
1113 (princ lazy-lock-defer-driven) | 1132 (princ lazy-lock-defer-driven) |
1114 (princ ")\n") | 1133 (princ ")\n") |
1115 (princ "in your ~/.emacs. ") | 1134 (princ "in your ~/.emacs. ") |
1116 (princ "The above form has been evaluated for this editor session,\n") | 1135 (princ "The above form has been evaluated for this editor session,\n") |
1117 (princ "but you should change your ~/.emacs now.")) | 1136 (princ "but you should use ") |
1137 (princ (substitute-command-keys "\\[customize-option]")) | |
1138 (princ " or change your ~/.emacs now.")) | |
1118 (setq lazy-lock-defer-on-scrolling lazy-lock-defer-driven)) | 1139 (setq lazy-lock-defer-on-scrolling lazy-lock-defer-driven)) |
1119 | 1140 |
1120 ;; Possibly absent. | 1141 ;; Possibly absent. |
1121 | 1142 |
1122 (unless (boundp 'font-lock-inhibit-thing-lock) | 1143 (unless (boundp 'font-lock-inhibit-thing-lock) |
1145 (walk-windows (function (lambda (window) | 1166 (walk-windows (function (lambda (window) |
1146 (when (eq (window-buffer window) buffer) | 1167 (when (eq (window-buffer window) buffer) |
1147 (push window windows)))) | 1168 (push window windows)))) |
1148 minibuf frame) | 1169 minibuf frame) |
1149 windows))) | 1170 windows))) |
1171 | |
1172 (unless (fboundp 'current-message) | |
1173 (defun current-message () | |
1174 "")) | |
1150 | 1175 |
1151 ;; Install ourselves: | 1176 ;; Install ourselves: |
1152 | 1177 |
1153 (add-hook 'window-size-change-functions 'lazy-lock-fontify-after-resize) | 1178 (add-hook 'window-size-change-functions 'lazy-lock-fontify-after-resize) |
1154 (add-hook 'redisplay-end-trigger-functions 'lazy-lock-fontify-after-trigger) | 1179 (add-hook 'redisplay-end-trigger-functions 'lazy-lock-fontify-after-trigger) |