aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2006-08-24 23:40:00 +0000
committerChong Yidong2006-08-24 23:40:00 +0000
commit1063efe807c0195c62f2dc22bcc78c61cf25c376 (patch)
tree08f46a4c502a4fef248df2c1c36fa0167199e5a9
parent8d8dafebb36347734c5f81f8154d0749ca16bfaf (diff)
downloademacs-1063efe807c0195c62f2dc22bcc78c61cf25c376.tar.gz
emacs-1063efe807c0195c62f2dc22bcc78c61cf25c376.zip
* emacs-lisp/timer.el (timer-set-idle-time, run-with-idle-timer):
Accept internal time format for SECS arg. (timer-relative-time): Doc fix. * jit-lock.el: "Stealth fontification by requeuing timers" patch, adapted from Martin Rudalics. (jit-lock-stealth-repeat-timer, jit-lock-stealth-buffers): New vars. (jit-lock-mode): Create jit-lock-stealth-repeat-timer. (jit-lock-stealth-fontify): Reschedule as a idle timer instead of using sit-for.
-rw-r--r--lisp/ChangeLog13
-rw-r--r--lisp/emacs-lisp/timer.el21
-rw-r--r--lisp/jit-lock.el117
3 files changed, 84 insertions, 67 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 72a1bed4397..554274a2544 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,16 @@
12006-08-24 Chong Yidong <cyd@stupidchicken.com>
2
3 * emacs-lisp/timer.el (timer-set-idle-time, run-with-idle-timer):
4 Accept internal time format for SECS arg.
5 (timer-relative-time): Doc fix.
6
7 * jit-lock.el: "Stealth fontification by requeuing timers" patch,
8 adapted from Martin Rudalics.
9 (jit-lock-stealth-repeat-timer, jit-lock-stealth-buffers): New vars.
10 (jit-lock-mode): Create jit-lock-stealth-repeat-timer.
11 (jit-lock-stealth-fontify): Reschedule as a idle timer instead of
12 using sit-for.
13
12006-08-24 Francesc Rocher <francesc.rocher@gmail.com> 142006-08-24 Francesc Rocher <francesc.rocher@gmail.com>
2 15
3 * cus-start.el (all): Add `overline-margin' and 16 * cus-start.el (all): Add `overline-margin' and
diff --git a/lisp/emacs-lisp/timer.el b/lisp/emacs-lisp/timer.el
index ed85bc765f7..82eac50c874 100644
--- a/lisp/emacs-lisp/timer.el
+++ b/lisp/emacs-lisp/timer.el
@@ -60,14 +60,22 @@ fire repeatedly that many seconds apart."
60 60
61(defun timer-set-idle-time (timer secs &optional repeat) 61(defun timer-set-idle-time (timer secs &optional repeat)
62 "Set the trigger idle time of TIMER to SECS. 62 "Set the trigger idle time of TIMER to SECS.
63SECS may be an integer, floating point number, or the internal
64time format (HIGH LOW USECS) returned by, e.g., `current-idle-time'.
63If optional third argument REPEAT is non-nil, make the timer 65If optional third argument REPEAT is non-nil, make the timer
64fire each time Emacs is idle for that many seconds." 66fire each time Emacs is idle for that many seconds."
65 (or (timerp timer) 67 (or (timerp timer)
66 (error "Invalid timer")) 68 (error "Invalid timer"))
67 (aset timer 1 0) 69 (if (consp secs)
68 (aset timer 2 0) 70 (progn (aset timer 1 (car secs))
69 (aset timer 3 0) 71 (aset timer 2 (if (consp (cdr secs)) (car (cdr secs)) (cdr secs)))
70 (timer-inc-time timer secs) 72 (aset timer 3 (or (and (consp (cdr secs)) (consp (cdr (cdr secs)))
73 (nth 2 secs))
74 0)))
75 (aset timer 1 0)
76 (aset timer 2 0)
77 (aset timer 3 0)
78 (timer-inc-time timer secs))
71 (aset timer 4 repeat) 79 (aset timer 4 repeat)
72 timer) 80 timer)
73 81
@@ -104,7 +112,7 @@ of SECS seconds since the epoch. SECS may be a fraction."
104 112
105(defun timer-relative-time (time secs &optional usecs) 113(defun timer-relative-time (time secs &optional usecs)
106 "Advance TIME by SECS seconds and optionally USECS microseconds. 114 "Advance TIME by SECS seconds and optionally USECS microseconds.
107SECS may be a fraction." 115SECS may be either an integer or a floating point number."
108 (let ((high (car time)) 116 (let ((high (car time))
109 (low (if (consp (cdr time)) (nth 1 time) (cdr time))) 117 (low (if (consp (cdr time)) (nth 1 time) (cdr time)))
110 (micro (if (numberp (car-safe (cdr-safe (cdr time)))) 118 (micro (if (numberp (car-safe (cdr-safe (cdr time))))
@@ -412,7 +420,8 @@ This function is for compatibility; see also `run-with-timer'."
412(defun run-with-idle-timer (secs repeat function &rest args) 420(defun run-with-idle-timer (secs repeat function &rest args)
413 "Perform an action the next time Emacs is idle for SECS seconds. 421 "Perform an action the next time Emacs is idle for SECS seconds.
414The action is to call FUNCTION with arguments ARGS. 422The action is to call FUNCTION with arguments ARGS.
415SECS may be an integer or a floating point number. 423SECS may be an integer, a floating point number, or the internal
424time format (HIGH LOW USECS) returned by, e.g., `current-idle-time'.
416If Emacs is currently idle, and has been idle for N seconds (N < SECS), 425If Emacs is currently idle, and has been idle for N seconds (N < SECS),
417then it will call FUNCTION in SECS - N seconds from now. 426then it will call FUNCTION in SECS - N seconds from now.
418 427
diff --git a/lisp/jit-lock.el b/lisp/jit-lock.el
index 606cd1e0b84..89959ad8525 100644
--- a/lisp/jit-lock.el
+++ b/lisp/jit-lock.el
@@ -171,6 +171,8 @@ If nil, contextual fontification is disabled.")
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
@@ -178,6 +180,8 @@ If nil, contextual fontification is disabled.")
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
@@ -225,6 +229,13 @@ the variable `jit-lock-stealth-nice'."
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)))
227 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)))
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
@@ -443,71 +454,55 @@ Value is nil if there is nothing more to fontify."
443 (t next)))) 454 (t next))))
444 result)))) 455 result))))
445 456
446 457(defun jit-lock-stealth-fontify (&optional repeat)
447(defun jit-lock-stealth-fontify ()
448 "Fontify buffers stealthily. 458 "Fontify buffers stealthily.
449This functions is called after Emacs has been idle for 459This function is called repeatedly after Emacs has become idle for
450`jit-lock-stealth-time' seconds." 460`jit-lock-stealth-time' seconds. Optional argument REPEAT is expected
451 ;; I used to check `inhibit-read-only' here, but I can't remember why. -stef 461non-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))
452 (unless (or executing-kbd-macro 465 (unless (or executing-kbd-macro
453 memory-full 466 memory-full
454 (window-minibuffer-p (selected-window))) 467 (window-minibuffer-p (selected-window))
455 (let ((buffers (buffer-list)) 468 ;; For first invocation set up `jit-lock-stealth-buffers'.
456 (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)
457 minibuffer-auto-raise 475 minibuffer-auto-raise
458 message-log-max) 476 message-log-max
459 (with-local-quit 477 start)
460 (while (and buffers (not (input-pending-p))) 478 (if (and jit-lock-stealth-load
461 (with-current-buffer (pop buffers) 479 (> (car (load-average)) jit-lock-stealth-load))
462 (when jit-lock-mode 480 ;; Wait a little if load is too high.
463 ;; This is funny. Calling sit-for with 3rd arg non-nil 481 (setq delay jit-lock-stealth-time)
464 ;; so that it doesn't redisplay, internally calls 482 (if (buffer-live-p buffer)
465 ;; wait_reading_process_input also with a parameter 483 (with-current-buffer buffer
466 ;; saying "don't redisplay." Since this function here 484 (if (and jit-lock-mode
467 ;; is called periodically, this effectively leads to 485 (setq start (jit-lock-stealth-chunk-start (point))))
468 ;; process output not being redisplayed at all because 486 ;; Fontify one block of at most `jit-lock-chunk-size'
469 ;; redisplay_internal is never called. (That didn't 487 ;; characters.
470 ;; work in the old redisplay either.) So, we learn that 488 (with-temp-message (if jit-lock-stealth-verbose
471 ;; we mustn't call sit-for that way here. But then, we 489 (concat "JIT stealth lock "
472 ;; have to be cautious not to call sit-for in a widened 490 (buffer-name)))
473 ;; buffer, since this could display hidden parts of that 491 (jit-lock-fontify-now start
474 ;; buffer. This explains the seemingly weird use of 492 (+ start jit-lock-chunk-size))
475 ;; save-restriction/widen here. 493 ;; Run again after `jit-lock-stealth-nice' seconds.
476 494 (setq delay (or jit-lock-stealth-nice 0)))
477 (with-temp-message (if jit-lock-stealth-verbose 495 ;; Nothing to fontify here. Remove this buffer from
478 (concat "JIT stealth lock " 496 ;; `jit-lock-stealth-buffers' and run again immediately.
479 (buffer-name))) 497 (setq jit-lock-stealth-buffers (cdr jit-lock-stealth-buffers))))
480 498 ;; Buffer is no longer live. Remove it from
481 ;; In the following code, the `sit-for' calls cause a 499 ;; `jit-lock-stealth-buffers' and run again immediately.
482 ;; redisplay, so it's required that the 500 (setq jit-lock-stealth-buffers (cdr jit-lock-stealth-buffers))))
483 ;; buffer-modified flag of a buffer that is displayed 501 ;; Call us again.
484 ;; has the right value---otherwise the mode line of 502 (when jit-lock-stealth-buffers
485 ;; an unmodified buffer would show a `*'. 503 (timer-set-idle-time jit-lock-stealth-repeat-timer (current-idle-time))
486 (let (start 504 (timer-inc-time jit-lock-stealth-repeat-timer delay)
487 (nice (or jit-lock-stealth-nice 0)) 505 (timer-activate-when-idle jit-lock-stealth-repeat-timer t)))))
488 (point (point-min)))
489 (while (and (setq start
490 (jit-lock-stealth-chunk-start point))
491 ;; In case sit-for runs any timers,
492 ;; give them the expected current buffer.
493 (with-current-buffer outer-buffer
494 (sit-for nice)))
495
496 ;; fontify a block.
497 (jit-lock-fontify-now start (+ start jit-lock-chunk-size))
498 ;; If stealth jit-locking is done backwards, this leads to
499 ;; excessive O(n^2) refontification. -stef
500 ;; (when (>= jit-lock-context-unfontify-pos start)
501 ;; (setq jit-lock-context-unfontify-pos end))
502
503 ;; Wait a little if load is too high.
504 (when (and jit-lock-stealth-load
505 (> (car (load-average)) jit-lock-stealth-load))
506 ;; In case sit-for runs any timers,
507 ;; give them the expected current buffer.
508 (with-current-buffer outer-buffer
509 (sit-for (or jit-lock-stealth-time 30))))))))))))))
510
511 506
512 507
513;;; Deferred fontification. 508;;; Deferred fontification.