From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.devel Subject: RE: Should `cancel-timer' use `delete' instead of `delq'? Date: Tue, 5 Sep 2006 14:24:08 -0700 Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1157491504 2085 80.91.229.2 (5 Sep 2006 21:25:04 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 5 Sep 2006 21:25:04 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Sep 05 23:24:59 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1GKiPQ-0001rI-Ni for ged-emacs-devel@m.gmane.org; Tue, 05 Sep 2006 23:24:43 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GKiPQ-0002Ze-7J for ged-emacs-devel@m.gmane.org; Tue, 05 Sep 2006 17:24:40 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GKiPC-0002YN-4b for emacs-devel@gnu.org; Tue, 05 Sep 2006 17:24:26 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GKiPA-0002XX-Jj for emacs-devel@gnu.org; Tue, 05 Sep 2006 17:24:25 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GKiPA-0002XT-Au for emacs-devel@gnu.org; Tue, 05 Sep 2006 17:24:24 -0400 Original-Received: from [141.146.126.228] (helo=agminet01.oracle.com) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA:24) (Exim 4.52) id 1GKiPA-0005Rk-6c for emacs-devel@gnu.org; Tue, 05 Sep 2006 17:24:24 -0400 Original-Received: from rgmsgw01.us.oracle.com (rgmsgw01.us.oracle.com [138.1.186.51]) by agminet01.oracle.com (Switch-3.1.7/Switch-3.1.7) with ESMTP id k85LOLRw010932 for ; Tue, 5 Sep 2006 16:24:21 -0500 Original-Received: from dradamslap (dhcp-amer-csvpn-gw2-141-144-74-150.vpn.oracle.com [141.144.74.150]) by rgmsgw01.us.oracle.com (Switch-3.1.7/Switch-3.1.7) with SMTP id k85LOK1I025855 for ; Tue, 5 Sep 2006 15:24:20 -0600 Original-To: X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) In-Reply-To: Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1807 X-Brightmail-Tracker: AAAAAQAAAAI= X-Brightmail-Tracker: AAAAAQAAAAI= X-Whitelist: TRUE X-Whitelist: TRUE X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:59394 Archived-At: > > (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?