diff options
| author | Stefan Monnier | 2000-06-05 03:08:50 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2000-06-05 03:08:50 +0000 |
| commit | 02b420eb35814cd05f36685b84f683ca699e2ed9 (patch) | |
| tree | 25fcea22c8c04539da8e5e2b8892ee4d5980cb09 | |
| parent | 560ef11a16d6d25446e62753fe6e89d4e54f47fd (diff) | |
| download | emacs-02b420eb35814cd05f36685b84f683ca699e2ed9.tar.gz emacs-02b420eb35814cd05f36685b84f683ca699e2ed9.zip | |
(jit-lock-saved-fontify-buffer-function): New var.
(jit-lock-fontify-buffer): New function for JIT refontification.
(jit-lock-mode): Fix docstring.
Use jit-lock-fontify-buffer for font-lock-fontify-buffer-function.
Remove jit-lock-after-change from the _local_ hook.
(jit-lock-function-1): Fix docstring.
| -rw-r--r-- | lisp/jit-lock.el | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/lisp/jit-lock.el b/lisp/jit-lock.el index 8fb46da9657..db41a15595f 100644 --- a/lisp/jit-lock.el +++ b/lisp/jit-lock.el | |||
| @@ -147,6 +147,8 @@ The value of this variable is used when JIT Lock mode is turned on." | |||
| 147 | (defvar jit-lock-stealth-timer nil | 147 | (defvar jit-lock-stealth-timer nil |
| 148 | "Timer for stealth fontification in Just-in-time Lock mode.") | 148 | "Timer for stealth fontification in Just-in-time Lock mode.") |
| 149 | 149 | ||
| 150 | (defvar jit-lock-saved-fontify-buffer-function nil | ||
| 151 | "Value of `font-lock-fontify-buffer-function' before jit-lock's activation.") | ||
| 150 | 152 | ||
| 151 | 153 | ||
| 152 | ;;; JIT lock mode | 154 | ;;; JIT lock mode |
| @@ -182,7 +184,7 @@ following ways: | |||
| 182 | Stealth fontification only occurs while the system remains unloaded. | 184 | Stealth fontification only occurs while the system remains unloaded. |
| 183 | If the system load rises above `jit-lock-stealth-load' percent, stealth | 185 | If the system load rises above `jit-lock-stealth-load' percent, stealth |
| 184 | fontification is suspended. Stealth fontification intensity is controlled via | 186 | fontification is suspended. Stealth fontification intensity is controlled via |
| 185 | the variable `jit-lock-stealth-nice' and `jit-lock-stealth-lines'." | 187 | the variable `jit-lock-stealth-nice'." |
| 186 | (interactive "P") | 188 | (interactive "P") |
| 187 | (setq jit-lock-mode (if arg | 189 | (setq jit-lock-mode (if arg |
| 188 | (> (prefix-numeric-value arg) 0) | 190 | (> (prefix-numeric-value arg) 0) |
| @@ -199,16 +201,23 @@ the variable `jit-lock-stealth-nice' and `jit-lock-stealth-lines'." | |||
| 199 | (jit-lock-mode | 201 | (jit-lock-mode |
| 200 | ;; Setting `font-lock-fontified' makes font-lock believe the | 202 | ;; Setting `font-lock-fontified' makes font-lock believe the |
| 201 | ;; buffer is already fontified, so that it won't highlight | 203 | ;; buffer is already fontified, so that it won't highlight |
| 202 | ;; the whole buffer. | 204 | ;; the whole buffer or bail out on a large buffer. |
| 203 | (make-local-variable 'font-lock-fontified) | 205 | (make-local-variable 'font-lock-fontified) |
| 204 | (setq font-lock-fontified t) | 206 | (setq font-lock-fontified t) |
| 205 | 207 | ||
| 208 | ;; Setup JIT font-lock-fontify-buffer. | ||
| 209 | (unless jit-lock-saved-fontify-buffer-function | ||
| 210 | (set (make-local-variable 'jit-lock-saved-fontify-buffer-function) | ||
| 211 | font-lock-fontify-buffer-function) | ||
| 212 | (set (make-local-variable 'font-lock-fontify-buffer-function) | ||
| 213 | 'jit-lock-fontify-buffer)) | ||
| 214 | |||
| 206 | (setq jit-lock-first-unfontify-pos nil) | 215 | (setq jit-lock-first-unfontify-pos nil) |
| 207 | 216 | ||
| 208 | ;; Install an idle timer for stealth fontification. | 217 | ;; Install an idle timer for stealth fontification. |
| 209 | (when (and jit-lock-stealth-time | 218 | (when (and jit-lock-stealth-time |
| 210 | (null jit-lock-stealth-timer)) | 219 | (null jit-lock-stealth-timer)) |
| 211 | (setq jit-lock-stealth-timer | 220 | (setq jit-lock-stealth-timer |
| 212 | (run-with-idle-timer jit-lock-stealth-time | 221 | (run-with-idle-timer jit-lock-stealth-time |
| 213 | jit-lock-stealth-time | 222 | jit-lock-stealth-time |
| 214 | 'jit-lock-stealth-fontify))) | 223 | 'jit-lock-stealth-fontify))) |
| @@ -229,8 +238,14 @@ the variable `jit-lock-stealth-nice' and `jit-lock-stealth-lines'." | |||
| 229 | (cancel-timer jit-lock-stealth-timer) | 238 | (cancel-timer jit-lock-stealth-timer) |
| 230 | (setq jit-lock-stealth-timer nil)) | 239 | (setq jit-lock-stealth-timer nil)) |
| 231 | 240 | ||
| 241 | ;; Restore non-JIT font-lock-fontify-buffer. | ||
| 242 | (when jit-lock-saved-fontify-buffer-function | ||
| 243 | (set (make-local-variable 'font-lock-fontify-buffer-function) | ||
| 244 | jit-lock-saved-fontify-buffer-function) | ||
| 245 | (setq jit-lock-saved-fontify-buffer-function nil)) | ||
| 246 | |||
| 232 | ;; Remove hooks. | 247 | ;; Remove hooks. |
| 233 | (remove-hook 'after-change-functions 'jit-lock-after-change) | 248 | (remove-hook 'after-change-functions 'jit-lock-after-change t) |
| 234 | (remove-hook 'fontification-functions 'jit-lock-function)))) | 249 | (remove-hook 'fontification-functions 'jit-lock-function)))) |
| 235 | 250 | ||
| 236 | 251 | ||
| @@ -239,6 +254,17 @@ the variable `jit-lock-stealth-nice' and `jit-lock-stealth-lines'." | |||
| 239 | "Unconditionally turn on Just-in-time Lock mode." | 254 | "Unconditionally turn on Just-in-time Lock mode." |
| 240 | (jit-lock-mode 1)) | 255 | (jit-lock-mode 1)) |
| 241 | 256 | ||
| 257 | ;; This function is used to prevent font-lock-fontify-buffer from | ||
| 258 | ;; fontifying eagerly the whole buffer. This is important for | ||
| 259 | ;; things like CWarn mode which adds/removes a few keywords and | ||
| 260 | ;; does a refontify (which takes ages on large files). | ||
| 261 | (defun jit-lock-fontify-buffer () | ||
| 262 | (if (not (and font-lock-mode jit-lock-mode)) | ||
| 263 | (funcall jit-lock-saved-fontify-buffer-function) | ||
| 264 | (with-buffer-prepared-for-font-lock | ||
| 265 | (save-restriction | ||
| 266 | (widen) | ||
| 267 | (add-text-properties (point-min) (point-max) '(fontified nil)))))) | ||
| 242 | 268 | ||
| 243 | 269 | ||
| 244 | ;;; On demand fontification. | 270 | ;;; On demand fontification. |
| @@ -252,9 +278,7 @@ is active." | |||
| 252 | 278 | ||
| 253 | 279 | ||
| 254 | (defun jit-lock-function-1 (start) | 280 | (defun jit-lock-function-1 (start) |
| 255 | "Fontify current buffer starting at position START. | 281 | "Fontify current buffer starting at position START." |
| 256 | This function is added to `fontification-functions' when `jit-lock-mode' | ||
| 257 | is active." | ||
| 258 | (with-buffer-prepared-for-font-lock | 282 | (with-buffer-prepared-for-font-lock |
| 259 | (save-excursion | 283 | (save-excursion |
| 260 | (save-restriction | 284 | (save-restriction |