all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Should `cancel-timer' use `delete' instead of `delq'?
@ 2006-09-05  0:14 Drew Adams
  2006-09-05  1:44 ` Miles Bader
                   ` (2 more replies)
  0 siblings, 3 replies; 23+ messages in thread
From: Drew Adams @ 2006-09-05  0:14 UTC (permalink / raw)


I may misunderstand this completely. If so, please set me straight. IIUC:

`cancel-timer' removes a particular vector (timer) from `timer-idle-list',
using delq. It does not remove all vectors that have the same elements,
however "same" might be defined for those elements. It uses eq for the
vector itself.

If you should happen to evaluate `run-with-idle-timer' more than once using
the same arguments, then a different timer (vector) would be created and run
for each evaluation. If you assigned the result of `run-with-idle-timer' to
a variable (setq or defvar), then passing that variable to `cancel-timer'
would cancel only the timer that was last created with those arguments to
`run-with-idle-timer' (and assigned to the variable).

I don't know - is that a feature or not?

Perhaps someone should never re-evaluate a particular `run-with-idle-timer'
expression, but it might happen, for instance, during debugging, if someone
used `C-M-x' on the timer defvar. Once that's done, IIUC, there is no way to
cancel the timer that was created and run previously (unless there is some
other variable that has it as value, or unless you manipulate
`timer-idle-list' directly and knowingly). I was bit by this, and I had to
delve into the source code to understand why my timer was still running.

E.g.

; 1st timer can never be cancelled, once 2nd is created.
(setq toto (run-with-idle-timer 10 t 'fn))
(setq toto (run-with-idle-timer 10 t 'fn))
; Cancel 2nd timer created and assigned to toto.
(cancel-timer toto)

I see code (e.g. in avoid.el) that uses setq in a context where it seems
like there could be multiple evaluations of the same `run-with-idle-timer'
expression. I don't know whether this particular code has a problem if it is
executed more than once; I just point it out to show that it might happen
that `run-with-idle-timer' is executed more than once with the same args,
and the same variable is assigned the result.

If the use of delq (vector identity) in `cancel-timer' is intentional and it
is considered a feature to have multiple idle timers with the same
parameters, then perhaps the doc should warn people of this gotcha - perhaps
advise them to use `cancel-timer' first, before `run-with-idle-timer':

(when(boundp 'foo-timer) (cancel-timer foo-timer))
(setq foo-timer (run-with-idle-timer 2 t 'foo))

I can only imagine that such a feature might have a use if, for some reason,
different variables were assigned to different timers that used the same
parameters:

(setq toto (run-with-idle-timer 10 t 'fn))
(setq titi (run-with-idle-timer 10 t 'fn))

I'm not sure when that might be useful, but it could be an argument to
support this feature.

If, on the other hand, the use of delq in `cancel-timer' is unintentional
and is not needed, then perhaps delete should be used instead of delq, so
that all timers with the same parameters are cancelled at once.

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2006-09-06 19:05 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-05  0:14 Should `cancel-timer' use `delete' instead of `delq'? Drew Adams
2006-09-05  1:44 ` Miles Bader
2006-09-05 15:38   ` Stefan Monnier
2006-09-05 16:20     ` Drew Adams
2006-09-05 17:22       ` Stefan Monnier
2006-09-05 17:36         ` Drew Adams
2006-09-05 20:46           ` Kevin Rodgers
2006-09-05 21:24             ` Drew Adams
2006-09-06  1:11               ` Miles Bader
2006-09-06  2:09                 ` Drew Adams
2006-09-06  2:38                   ` Miles Bader
2006-09-06  6:31                     ` Drew Adams
2006-09-06  6:48                       ` Miles Bader
2006-09-06  7:29                       ` David Kastrup
2006-09-06 14:00                       ` Stefan Monnier
2006-09-06 15:27                         ` Drew Adams
2006-09-06  6:38                   ` David Kastrup
2006-09-05 21:56     ` David Kastrup
2006-09-06  0:59       ` Stefan Monnier
2006-09-06 19:05     ` Richard Stallman
2006-09-05 19:13 ` Stuart D. Herring
2006-09-05 19:22   ` Drew Adams
2006-09-06  8:49 ` Richard Stallman

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.