comparison lisp/jit-lock.el @ 90596:6823a91487f2

Merge from emacs--devo--0 Patches applied: * emacs--devo--0 (patch 399-413) - Update from CVS - Rcirc update from Ryan Yeske - Merge from gnus--rel--5.10 - Miscellaneous tq-related fixes. * gnus--rel--5.10 (patch 126-127) - Merge from emacs--devo--0 - Update from CVS Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-105
author Miles Bader <miles@gnu.org>
date Mon, 28 Aug 2006 04:33:45 +0000
parents 858cb33ae39d 5d642f9eff22
children b5c13d1564a9
comparison
equal deleted inserted replaced
90595:fd59c4164a14 90596:6823a91487f2
169 (make-variable-buffer-local 'jit-lock-context-unfontify-pos) 169 (make-variable-buffer-local 'jit-lock-context-unfontify-pos)
170 170
171 171
172 (defvar jit-lock-stealth-timer nil 172 (defvar jit-lock-stealth-timer nil
173 "Timer for stealth fontification in Just-in-time Lock mode.") 173 "Timer for stealth fontification in Just-in-time Lock mode.")
174 (defvar jit-lock-stealth-repeat-timer nil
175 "Timer for repeated stealth fontification in Just-in-time Lock mode.")
174 (defvar jit-lock-context-timer nil 176 (defvar jit-lock-context-timer nil
175 "Timer for context fontification in Just-in-time Lock mode.") 177 "Timer for context fontification in Just-in-time Lock mode.")
176 (defvar jit-lock-defer-timer nil 178 (defvar jit-lock-defer-timer nil
177 "Timer for deferred fontification in Just-in-time Lock mode.") 179 "Timer for deferred fontification in Just-in-time Lock mode.")
178 180
179 (defvar jit-lock-defer-buffers nil 181 (defvar jit-lock-defer-buffers nil
180 "List of buffers with pending deferred fontification.") 182 "List of buffers with pending deferred fontification.")
183 (defvar jit-lock-stealth-buffers nil
184 "List of buffers that are being fontified stealthily.")
181 185
182 ;;; JIT lock mode 186 ;;; JIT lock mode
183 187
184 (defun jit-lock-mode (arg) 188 (defun jit-lock-mode (arg)
185 "Toggle Just-in-time Lock mode. 189 "Toggle Just-in-time Lock mode.
222 ;; Install an idle timer for stealth fontification. 226 ;; Install an idle timer for stealth fontification.
223 (when (and jit-lock-stealth-time (null jit-lock-stealth-timer)) 227 (when (and jit-lock-stealth-time (null jit-lock-stealth-timer))
224 (setq jit-lock-stealth-timer 228 (setq jit-lock-stealth-timer
225 (run-with-idle-timer jit-lock-stealth-time t 229 (run-with-idle-timer jit-lock-stealth-time t
226 'jit-lock-stealth-fontify))) 230 'jit-lock-stealth-fontify)))
231
232 ;; Create, but do not activate, the idle timer for repeated
233 ;; stealth fontification.
234 (when (and jit-lock-stealth-time (null jit-lock-stealth-repeat-timer))
235 (setq jit-lock-stealth-repeat-timer (timer-create))
236 (timer-set-function jit-lock-stealth-repeat-timer
237 'jit-lock-stealth-fontify '(t)))
227 238
228 ;; Init deferred fontification timer. 239 ;; Init deferred fontification timer.
229 (when (and jit-lock-defer-time (null jit-lock-defer-timer)) 240 (when (and jit-lock-defer-time (null jit-lock-defer-timer))
230 (setq jit-lock-defer-timer 241 (setq jit-lock-defer-timer
231 (run-with-idle-timer jit-lock-defer-time t 242 (run-with-idle-timer jit-lock-defer-time t
389 (lexical-let ((start start) 400 (lexical-let ((start start)
390 (orig-start orig-start) 401 (orig-start orig-start)
391 (buf (current-buffer))) 402 (buf (current-buffer)))
392 (run-with-timer 403 (run-with-timer
393 0 nil (lambda () 404 0 nil (lambda ()
394 (with-buffer-prepared-for-jit-lock 405 (with-current-buffer buf
395 (put-text-property start orig-start 406 (with-buffer-prepared-for-jit-lock
396 'fontified t buf)))))) 407 (put-text-property start orig-start
408 'fontified t)))))))
397 409
398 ;; Find the start of the next chunk, if any. 410 ;; Find the start of the next chunk, if any.
399 (setq start (text-property-any next end 'fontified nil)))))))) 411 (setq start (text-property-any next end 'fontified nil))))))))
400 412
401 413
440 ((null next) start) 452 ((null next) start)
441 ((< (- around start) (- next around)) start) 453 ((< (- around start) (- next around)) start)
442 (t next)))) 454 (t next))))
443 result)))) 455 result))))
444 456
445 457 (defun jit-lock-stealth-fontify (&optional repeat)
446 (defun jit-lock-stealth-fontify ()
447 "Fontify buffers stealthily. 458 "Fontify buffers stealthily.
448 This functions is called after Emacs has been idle for 459 This function is called repeatedly after Emacs has become idle for
449 `jit-lock-stealth-time' seconds." 460 `jit-lock-stealth-time' seconds. Optional argument REPEAT is expected
450 ;; I used to check `inhibit-read-only' here, but I can't remember why. -stef 461 non-nil in a repeated invocation of this function."
462 ;; Cancel timer for repeated invocations.
463 (unless repeat
464 (cancel-timer jit-lock-stealth-repeat-timer))
451 (unless (or executing-kbd-macro 465 (unless (or executing-kbd-macro
452 memory-full 466 memory-full
453 (window-minibuffer-p (selected-window))) 467 (window-minibuffer-p (selected-window))
454 (let ((buffers (buffer-list)) 468 ;; For first invocation set up `jit-lock-stealth-buffers'.
455 (outer-buffer (current-buffer)) 469 ;; In repeated invocations it's already been set up.
470 (null (if repeat
471 jit-lock-stealth-buffers
472 (setq jit-lock-stealth-buffers (buffer-list)))))
473 (let ((buffer (car jit-lock-stealth-buffers))
474 (delay 0)
456 minibuffer-auto-raise 475 minibuffer-auto-raise
457 message-log-max) 476 message-log-max
458 (with-local-quit 477 start)
459 (while (and buffers (not (input-pending-p))) 478 (if (and jit-lock-stealth-load
460 (with-current-buffer (pop buffers) 479 (> (car (load-average)) jit-lock-stealth-load))
461 (when jit-lock-mode 480 ;; Wait a little if load is too high.
462 ;; This is funny. Calling sit-for with 3rd arg non-nil 481 (setq delay jit-lock-stealth-time)
463 ;; so that it doesn't redisplay, internally calls 482 (if (buffer-live-p buffer)
464 ;; wait_reading_process_input also with a parameter 483 (with-current-buffer buffer
465 ;; saying "don't redisplay." Since this function here 484 (if (and jit-lock-mode
466 ;; is called periodically, this effectively leads to 485 (setq start (jit-lock-stealth-chunk-start (point))))
467 ;; process output not being redisplayed at all because 486 ;; Fontify one block of at most `jit-lock-chunk-size'
468 ;; redisplay_internal is never called. (That didn't 487 ;; characters.
469 ;; work in the old redisplay either.) So, we learn that 488 (with-temp-message (if jit-lock-stealth-verbose
470 ;; we mustn't call sit-for that way here. But then, we 489 (concat "JIT stealth lock "
471 ;; have to be cautious not to call sit-for in a widened 490 (buffer-name)))
472 ;; buffer, since this could display hidden parts of that 491 (jit-lock-fontify-now start
473 ;; buffer. This explains the seemingly weird use of 492 (+ start jit-lock-chunk-size))
474 ;; save-restriction/widen here. 493 ;; Run again after `jit-lock-stealth-nice' seconds.
475 494 (setq delay (or jit-lock-stealth-nice 0)))
476 (with-temp-message (if jit-lock-stealth-verbose 495 ;; Nothing to fontify here. Remove this buffer from
477 (concat "JIT stealth lock " 496 ;; `jit-lock-stealth-buffers' and run again immediately.
478 (buffer-name))) 497 (setq jit-lock-stealth-buffers (cdr jit-lock-stealth-buffers))))
479 498 ;; Buffer is no longer live. Remove it from
480 ;; In the following code, the `sit-for' calls cause a 499 ;; `jit-lock-stealth-buffers' and run again immediately.
481 ;; redisplay, so it's required that the 500 (setq jit-lock-stealth-buffers (cdr jit-lock-stealth-buffers))))
482 ;; buffer-modified flag of a buffer that is displayed 501 ;; Call us again.
483 ;; has the right value---otherwise the mode line of 502 (when jit-lock-stealth-buffers
484 ;; an unmodified buffer would show a `*'. 503 (timer-set-idle-time jit-lock-stealth-repeat-timer (current-idle-time))
485 (let (start 504 (timer-inc-time jit-lock-stealth-repeat-timer delay)
486 (nice (or jit-lock-stealth-nice 0)) 505 (timer-activate-when-idle jit-lock-stealth-repeat-timer t)))))
487 (point (point-min)))
488 (while (and (setq start
489 (jit-lock-stealth-chunk-start point))
490 ;; In case sit-for runs any timers,
491 ;; give them the expected current buffer.
492 (with-current-buffer outer-buffer
493 (sit-for nice)))
494
495 ;; fontify a block.
496 (jit-lock-fontify-now start (+ start jit-lock-chunk-size))
497 ;; If stealth jit-locking is done backwards, this leads to
498 ;; excessive O(n^2) refontification. -stef
499 ;; (when (>= jit-lock-context-unfontify-pos start)
500 ;; (setq jit-lock-context-unfontify-pos end))
501
502 ;; Wait a little if load is too high.
503 (when (and jit-lock-stealth-load
504 (> (car (load-average)) jit-lock-stealth-load))
505 ;; In case sit-for runs any timers,
506 ;; give them the expected current buffer.
507 (with-current-buffer outer-buffer
508 (sit-for (or jit-lock-stealth-time 30))))))))))))))
509
510 506
511 507
512 ;;; Deferred fontification. 508 ;;; Deferred fontification.
513 509
514 (defun jit-lock-deferred-fontify () 510 (defun jit-lock-deferred-fontify ()
575 This is run after every buffer change. The functions are called with 571 This is run after every buffer change. The functions are called with
576 the three arguments of `after-change-functions': START END OLD-LEN. 572 the three arguments of `after-change-functions': START END OLD-LEN.
577 The extended region to refontify is returned indirectly by modifying 573 The extended region to refontify is returned indirectly by modifying
578 the variables `jit-lock-start' and `jit-lock-end'. 574 the variables `jit-lock-start' and `jit-lock-end'.
579 575
580 Note that extending the region this way is not strictly necessary, 576 Note that extending the region this way is not strictly necessary, except
581 except that the nature of the redisplay code tends to otherwise leave 577 that the nature of the redisplay code tends to otherwise leave some of
582 some of the rehighlighted text displayed with the old highlight until the 578 the rehighlighted text displayed with the old highlight until the next
583 next redisplay. See comment in `jit-lock-fontify-now'.") 579 redisplay (see comment about repeated redisplay in `jit-lock-fontify-now').")
584 580
585 (defun jit-lock-after-change (start end old-len) 581 (defun jit-lock-after-change (start end old-len)
586 "Mark the rest of the buffer as not fontified after a change. 582 "Mark the rest of the buffer as not fontified after a change.
587 Installed on `after-change-functions'. 583 Installed on `after-change-functions'.
588 START and END are the start and end of the changed text. OLD-LEN 584 START and END are the start and end of the changed text. OLD-LEN