aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Moellmann2000-04-04 21:00:36 +0000
committerGerd Moellmann2000-04-04 21:00:36 +0000
commit60bffb784f89ed2fa0cb1dbfd9c514ba3b034236 (patch)
treea880972486648c66c9a93942d936b81fab5d2539
parent852c283098dae4c7b8ebb98a16678cdc2c523d41 (diff)
downloademacs-60bffb784f89ed2fa0cb1dbfd9c514ba3b034236.tar.gz
emacs-60bffb784f89ed2fa0cb1dbfd9c514ba3b034236.zip
(with-buffer-unmodified): New macro.
(with-buffer-prepared-for-font-lock): Don't preserve buffer's modified state. (jit-lock-function-1): Extracted from jit-lock-function; not preserving buffer's modified state. (jit-lock-function, jit-lock-stealth-fontify): Call jit-lock-function-1.
-rw-r--r--lisp/jit-lock.el153
1 files changed, 84 insertions, 69 deletions
diff --git a/lisp/jit-lock.el b/lisp/jit-lock.el
index 217407f8fe5..38814707104 100644
--- a/lisp/jit-lock.el
+++ b/lisp/jit-lock.el
@@ -33,11 +33,20 @@
33(require 'font-lock) 33(require 'font-lock)
34 34
35(eval-when-compile 35(eval-when-compile
36 (defmacro with-buffer-unmodified (&rest body)
37 "Eval BODY, preserving the current buffer's modified state."
38 (let ((modified (make-symbol "modified")))
39 `(let ((,modified (buffer-modified-p)))
40 ,@body
41 (unless ,modified)
42 ;; Calling set-buffer-modified causes redisplay to consider
43 ;; all windows because that function sets update_mode_lines.
44 (set-buffer-modified-p nil))))
45
36 (defmacro with-buffer-prepared-for-font-lock (&rest body) 46 (defmacro with-buffer-prepared-for-font-lock (&rest body)
37 "Execute BODY in current buffer, overriding several variables. 47 "Execute BODY in current buffer, overriding several variables.
38Preserves the `buffer-modified-p' state of the current buffer." 48Preserves the `buffer-modified-p' state of the current buffer."
39 `(let ((modified (buffer-modified-p)) 49 `(let ((buffer-undo-list t)
40 (buffer-undo-list t)
41 (inhibit-read-only t) 50 (inhibit-read-only t)
42 (inhibit-point-motion-hooks t) 51 (inhibit-point-motion-hooks t)
43 before-change-functions 52 before-change-functions
@@ -45,12 +54,9 @@ Preserves the `buffer-modified-p' state of the current buffer."
45 deactivate-mark 54 deactivate-mark
46 buffer-file-name 55 buffer-file-name
47 buffer-file-truename) 56 buffer-file-truename)
48 ,@body 57 ,@body)))
49 ;; Calling set-buffer-modified causes redisplay to consider
50 ;; all windows because that function sets update_mode_lines.
51 (set-buffer-modified-p modified))))
52
53 58
59
54 60
55;;; Customization. 61;;; Customization.
56 62
@@ -243,50 +249,57 @@ the variable `jit-lock-stealth-nice' and `jit-lock-stealth-lines'."
243This function is added to `fontification-functions' when `jit-lock-mode' 249This function is added to `fontification-functions' when `jit-lock-mode'
244is active." 250is active."
245 (when jit-lock-mode 251 (when jit-lock-mode
246 (with-buffer-prepared-for-font-lock 252 (with-buffer-unmodified (jit-lock-function-1 start))))
247 (save-excursion 253
248 (save-restriction 254
249 (widen) 255(defun jit-lock-function-1 (start)
250 (let ((end (min (point-max) (+ start jit-lock-chunk-size))) 256 "Fontify current buffer starting at position START.
251 (parse-sexp-lookup-properties font-lock-syntactic-keywords) 257This function is added to `fontification-functions' when `jit-lock-mode'
252 (font-lock-beginning-of-syntax-function nil) 258is active."
253 (old-syntax-table (syntax-table)) 259 (with-buffer-prepared-for-font-lock
254 next font-lock-start font-lock-end) 260 (save-excursion
255 (when font-lock-syntax-table 261 (save-restriction
256 (set-syntax-table font-lock-syntax-table)) 262 (widen)
257 (save-match-data 263 (let ((end (min (point-max) (+ start jit-lock-chunk-size)))
258 (condition-case error 264 (parse-sexp-lookup-properties font-lock-syntactic-keywords)
259 ;; Fontify chunks beginning at START. The end of a 265 (font-lock-beginning-of-syntax-function nil)
260 ;; chunk is either `end', or the start of a region 266 (old-syntax-table (syntax-table))
261 ;; before `end' that has already been fontified. 267 next font-lock-start font-lock-end)
262 (while start 268 (when font-lock-syntax-table
263 ;; Determine the end of this chunk. 269 (set-syntax-table font-lock-syntax-table))
264 (setq next (or (text-property-any start end 'fontified t) 270 (save-match-data
265 end)) 271 (condition-case error
266 272 ;; Fontify chunks beginning at START. The end of a
267 ;; Decide which range of text should be fontified. 273 ;; chunk is either `end', or the start of a region
268 ;; The problem is that START and NEXT may be in the 274 ;; before `end' that has already been fontified.
269 ;; middle of something matched by a font-lock regexp. 275 (while start
270 ;; Until someone has a better idea, let's start 276 ;; Determine the end of this chunk.
271 ;; at the start of the line containing START and 277 (setq next (or (text-property-any start end 'fontified t)
272 ;; stop at the start of the line following NEXT. 278 end))
273 (goto-char next) 279
274 (setq font-lock-end (line-beginning-position 2)) 280 ;; Decide which range of text should be fontified.
275 (goto-char start) 281 ;; The problem is that START and NEXT may be in the
276 (setq font-lock-start (line-beginning-position)) 282 ;; middle of something matched by a font-lock regexp.
283 ;; Until someone has a better idea, let's start
284 ;; at the start of the line containing START and
285 ;; stop at the start of the line following NEXT.
286 (goto-char next)
287 (setq font-lock-end (line-beginning-position 2))
288 (goto-char start)
289 (setq font-lock-start (line-beginning-position))
277 290
278 ;; Fontify the chunk, and mark it as fontified. 291 ;; Fontify the chunk, and mark it as fontified.
279 (font-lock-fontify-region font-lock-start font-lock-end nil) 292 (font-lock-fontify-region font-lock-start font-lock-end nil)
280 (add-text-properties start next '(fontified t)) 293 (add-text-properties start next '(fontified t))
281 294
282 ;; Find the start of the next chunk, if any. 295 ;; Find the start of the next chunk, if any.
283 (setq start (text-property-any next end 'fontified nil))) 296 (setq start (text-property-any next end 'fontified nil)))
284 297
285 ((error quit) 298 ((error quit)
286 (message "Fontifying region...%s" error)))) 299 (message "Fontifying region...%s" error))))
287 300
288 ;; Restore previous buffer settings. 301 ;; Restore previous buffer settings.
289 (set-syntax-table old-syntax-table))))))) 302 (set-syntax-table old-syntax-table))))))
290 303
291 304
292(defun jit-lock-after-fontify-buffer () 305(defun jit-lock-after-fontify-buffer ()
@@ -381,31 +394,33 @@ This functions is called after Emacs has been idle for
381 (concat "JIT stealth lock " 394 (concat "JIT stealth lock "
382 (buffer-name))) 395 (buffer-name)))
383 396
384 ;; Perform deferred unfontification, if any. 397 (with-buffer-unmodified
385 (when jit-lock-first-unfontify-pos 398
386 (save-restriction 399 ;; Perform deferred unfontification, if any.
387 (widen) 400 (when jit-lock-first-unfontify-pos
388 (when (and (>= jit-lock-first-unfontify-pos (point-min)) 401 (save-restriction
389 (< jit-lock-first-unfontify-pos (point-max))) 402 (widen)
390 (with-buffer-prepared-for-font-lock 403 (when (and (>= jit-lock-first-unfontify-pos (point-min))
391 (put-text-property jit-lock-first-unfontify-pos 404 (< jit-lock-first-unfontify-pos (point-max)))
392 (point-max) 'fontified nil)) 405 (with-buffer-prepared-for-font-lock
393 (setq jit-lock-first-unfontify-pos nil)))) 406 (put-text-property jit-lock-first-unfontify-pos
407 (point-max) 'fontified nil))
408 (setq jit-lock-first-unfontify-pos nil))))
394 409
395 (let (start 410 (let (start
396 (nice (or jit-lock-stealth-nice 0)) 411 (nice (or jit-lock-stealth-nice 0))
397 (point (point))) 412 (point (point)))
398 (while (and (setq start (jit-lock-stealth-chunk-start point)) 413 (while (and (setq start (jit-lock-stealth-chunk-start point))
399 (sit-for nice)) 414 (sit-for nice))
400 415
401 ;; Wait a little if load is too high. 416 ;; Wait a little if load is too high.
402 (when (and jit-lock-stealth-load 417 (when (and jit-lock-stealth-load
403 (> (car (load-average)) jit-lock-stealth-load)) 418 (> (car (load-average)) jit-lock-stealth-load))
404 (sit-for (or jit-lock-stealth-time 30))) 419 (sit-for (or jit-lock-stealth-time 30)))
405 420
406 ;; Unless there's input pending now, fontify. 421 ;; Unless there's input pending now, fontify.
407 (unless (input-pending-p) 422 (unless (input-pending-p)
408 (jit-lock-function start)))))))))))) 423 (jit-lock-function-1 start)))))))))))))
409 424
410 425
411 426