From: "Drew Adams" <drew.adams@oracle.com>
Subject: RE: Should `cancel-timer' use `delete' instead of `delq'?
Date: Tue, 5 Sep 2006 14:24:08 -0700 [thread overview]
Message-ID: <EIENLHALHGIMHGDOLMIMCEBLCLAA.drew.adams@oracle.com> (raw)
In-Reply-To: <edknp1$qii$1@sea.gmane.org>
> > (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?
OK.
My point was about re-evaluating setq or defvar assignment of a variable to
a `run-with-idle-timer' expression. In the case of defvar, it would be by
hand, and I guess if someone knows enough to add the protective cruft, then
s?he should also know enough to cancel the timer before re-evaling the
defvar by hand. I was bitten by it, but then I might not be as thoughtful as
most users.
There are some uses of setq with `run-with-idle-timer' in the standard Lisp
libraries. I have no idea if there is any chance that that code could be
re-eval'd, leaving running, orphan timers as a result. Whether it's a minor
mode or a separate `define-idle-timer macro', providing the protection in
some kind of ready-to-use bottle seems like a good idea to me.
To repeat my question: Is it a good idea to either document the
"traditional" `define-minor-mode' approach or define a new macro for this,
or should we just let people discover this on their own?
next prev parent reply other threads:[~2006-09-05 21:24 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=EIENLHALHGIMHGDOLMIMCEBLCLAA.drew.adams@oracle.com \
--to=drew.adams@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).