|
| From: | Kevin Rodgers |
| Subject: | Re: Should `cancel-timer' use `delete' instead of `delq'? |
| Date: | Tue, 05 Sep 2006 14:46:42 -0600 |
| User-agent: | Thunderbird 1.5.0.5 (Windows/20060719) |
Drew Adams wrote:
> (defvar foo-timer
> (progn ; Cancel to prevent ~duplication.
> (when (boundp 'foo-timer) (cancel-timer foo-timer))
> (run-with-idle-timer 2 t 'foo))
> "Timer used to foo whenever Emacs is idle.")
The traditional way to do something like the above is:
(defvar foo-timer nil)
(define-minor-mode foo "blala" :toto 1 :titi 0
(when foo-timer
(cancel foo-timer)
(setq foo-timer nil))
(when foo-mode
(setq foo-timer (run-with-idle-timer 5 t 'foo-fun))))
OK. I'm not sure why that's better, but it does seem to move a little toward
the direction I was suggesting with a `define-idle-timer' macro.
It seems clearly better to me, because the (progn ...) form in your defvar will only be evalated once: the first time, when foo-timer is unbound. Or am I missing something, in particular something that would subsequently make foo-timer unbound? -- Kevin
| [Prev in Thread] | Current Thread | [Next in Thread] |