diff options
| author | Richard M. Stallman | 1997-04-14 11:09:20 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1997-04-14 11:09:20 +0000 |
| commit | 953c43d8e73b051c0627efae860fec3e10df6b5c (patch) | |
| tree | 768aaa7bcc98dbd7dfdc0ffe3f20231c5f5b0cf3 | |
| parent | 21cfcccfb18c19bc4518672108b7395e4770edaf (diff) | |
| download | emacs-953c43d8e73b051c0627efae860fec3e10df6b5c.tar.gz emacs-953c43d8e73b051c0627efae860fec3e10df6b5c.zip | |
New function.
(timer-max-repeats): New variable.
(timer-event-handler): Avoid rerunning a timer many times
if real time has "jumped" forward.
| -rw-r--r-- | lisp/timer.el | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lisp/timer.el b/lisp/timer.el index 1a343755661..3b6382989cb 100644 --- a/lisp/timer.el +++ b/lisp/timer.el | |||
| @@ -248,6 +248,17 @@ fire repeatedly that many seconds apart." | |||
| 248 | (defvar timer-event-last-1 nil) | 248 | (defvar timer-event-last-1 nil) |
| 249 | (defvar timer-event-last nil) | 249 | (defvar timer-event-last nil) |
| 250 | 250 | ||
| 251 | (defvar timer-max-repeats 10 | ||
| 252 | "*Maximum number of times to repeat a timer, if real time jumps.") | ||
| 253 | |||
| 254 | (defun timer-until (timer time) | ||
| 255 | "Calculate number of seconds from when TIMER will run, until TIME. | ||
| 256 | TIMER is a timer, and stands for the time when its next repeat is scheduled. | ||
| 257 | TIME is a time-list. | ||
| 258 | (let ((high (- (car time) (aref timer 1))) | ||
| 259 | (low (- (nth 1 time) (aref timer 2)))) | ||
| 260 | (+ low (* high 65536)))) | ||
| 261 | |||
| 251 | (defun timer-event-handler (event) | 262 | (defun timer-event-handler (event) |
| 252 | "Call the handler for the timer in the event EVENT." | 263 | "Call the handler for the timer in the event EVENT." |
| 253 | (interactive "e") | 264 | (interactive "e") |
| @@ -269,6 +280,15 @@ fire repeatedly that many seconds apart." | |||
| 269 | (if (aref timer 7) | 280 | (if (aref timer 7) |
| 270 | (timer-activate-when-idle timer) | 281 | (timer-activate-when-idle timer) |
| 271 | (timer-inc-time timer (aref timer 4) 0) | 282 | (timer-inc-time timer (aref timer 4) 0) |
| 283 | ;; If real time has jumped forward, | ||
| 284 | ;; perhaps because Emacs was suspended for a long time, | ||
| 285 | ;; limit how many times things get repeated. | ||
| 286 | (if (and (numberp timer-max-repeats) | ||
| 287 | (< 0 (timer-until timer (current-time)))) | ||
| 288 | (let ((repeats (/ (timer-until timer (current-time)) | ||
| 289 | (aref timer 4)))) | ||
| 290 | (if (> repeats timer-max-repeats) | ||
| 291 | (timer-inc-time timer (* (aref timer 4) repeats))))) | ||
| 272 | (timer-activate timer)))) | 292 | (timer-activate timer)))) |
| 273 | (error "Bogus timer event")))) | 293 | (error "Bogus timer event")))) |
| 274 | 294 | ||