aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/jit-lock.el38
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:
182Stealth fontification only occurs while the system remains unloaded. 184Stealth fontification only occurs while the system remains unloaded.
183If the system load rises above `jit-lock-stealth-load' percent, stealth 185If the system load rises above `jit-lock-stealth-load' percent, stealth
184fontification is suspended. Stealth fontification intensity is controlled via 186fontification is suspended. Stealth fontification intensity is controlled via
185the variable `jit-lock-stealth-nice' and `jit-lock-stealth-lines'." 187the 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."
256This function is added to `fontification-functions' when `jit-lock-mode'
257is 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