Commit 953c43d8 authored by Richard M. Stallman's avatar Richard M. Stallman

New function.

(timer-max-repeats): New variable.
(timer-event-handler): Avoid rerunning a timer many times
if real time has "jumped" forward.
parent 21cfcccf
......@@ -248,6 +248,17 @@ fire repeatedly that many seconds apart."
(defvar timer-event-last-1 nil)
(defvar timer-event-last nil)
(defvar timer-max-repeats 10
"*Maximum number of times to repeat a timer, if real time jumps.")
(defun timer-until (timer time)
"Calculate number of seconds from when TIMER will run, until TIME.
TIMER is a timer, and stands for the time when its next repeat is scheduled.
TIME is a time-list.
(let ((high (- (car time) (aref timer 1)))
(low (- (nth 1 time) (aref timer 2))))
(+ low (* high 65536))))
(defun timer-event-handler (event)
"Call the handler for the timer in the event EVENT."
(interactive "e")
......@@ -269,6 +280,15 @@ fire repeatedly that many seconds apart."
(if (aref timer 7)
(timer-activate-when-idle timer)
(timer-inc-time timer (aref timer 4) 0)
;; If real time has jumped forward,
;; perhaps because Emacs was suspended for a long time,
;; limit how many times things get repeated.
(if (and (numberp timer-max-repeats)
(< 0 (timer-until timer (current-time))))
(let ((repeats (/ (timer-until timer (current-time))
(aref timer 4))))
(if (> repeats timer-max-repeats)
(timer-inc-time timer (* (aref timer 4) repeats)))))
(timer-activate timer))))
(error "Bogus timer event"))))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment