From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/81491 Path: news.gmane.org!not-for-mail From: =?utf-8?Q?Peter_M=C3=BCnster?= Newsgroups: gmane.emacs.gnus.general Subject: [PATCH] Daemon, don't wait another timer period, when idleness is too low. Date: Tue, 28 Feb 2012 23:54:45 +0100 Message-ID: <87linma7g1.fsf@micropit.couberia.bzh> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1330473298 6723 80.91.229.3 (28 Feb 2012 23:54:58 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 28 Feb 2012 23:54:58 +0000 (UTC) To: ding@gnus.org Original-X-From: ding-owner+M29771@lists.math.uh.edu Wed Feb 29 00:54:57 2012 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1S2Wsc-0005jb-Na for ding-account@gmane.org; Wed, 29 Feb 2012 00:54:51 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1S2Wrc-0004mL-NG; Tue, 28 Feb 2012 17:53:48 -0600 Original-Received: from mx2.math.uh.edu ([129.7.128.33]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1S2Wra-0004m8-Et for ding@lists.math.uh.edu; Tue, 28 Feb 2012 17:53:46 -0600 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx2.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1S2WrZ-0006GO-6N for ding@lists.math.uh.edu; Tue, 28 Feb 2012 17:53:46 -0600 Original-Received: from plane.gmane.org ([80.91.229.3]) by quimby.gnus.org with esmtp (Exim 4.72) (envelope-from ) id 1S2W3G-0005nA-Kh for ding@gnus.org; Wed, 29 Feb 2012 00:01:46 +0100 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1S2W3F-0001xT-R9 for ding@gnus.org; Wed, 29 Feb 2012 00:01:45 +0100 Original-Received: from arennes-359-1-256-163.w2-2.abo.wanadoo.fr ([2.2.207.163]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 29 Feb 2012 00:01:45 +0100 Original-Received: from pmlists by arennes-359-1-256-163.w2-2.abo.wanadoo.fr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 29 Feb 2012 00:01:45 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 116 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: arennes-359-1-256-163.w2-2.abo.wanadoo.fr User-Agent: Gnus/5.130004 (Ma Gnus v0.4) Emacs/24.0.93 (gnu/linux) Cancel-Lock: sha1:2MKNTr/0ZaKbEgRWs8wqzh1FVbg= X-Spam-Score: -1.9 (-) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:81491 Archived-At: * gnus-demon.el (gnus-demon-timers): Now a plist (function -> timer). (gnus-demon-cancel): Ditto. (gnus-demon-run-callback): When function cannot be called due to low idleness, call it when idleness reaches the expected value, instead of waiting another timer period. (gnus-demon-init): Add `time' to arguments of call-back. --- lisp/ChangeLog | 10 ++++++++++ lisp/gnus-demon.el | 43 ++++++++++++++++++++++++++++++------------- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 8501aee..5231eef 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,12 @@ +2012-02-28 Peter Münster (tiny change) + + * gnus-demon.el (gnus-demon-timers): Now a plist (function -> timer). + (gnus-demon-cancel): Ditto. + (gnus-demon-run-callback): When function cannot be called due to low + idleness, call it when idleness reaches the expected value, instead of + waiting another timer period. + (gnus-demon-init): Add `time' to arguments of call-back. + 2012-02-28 Glenn Morris * gmm-utils.el, gnus-agent.el, gnus-score.el, messagexmas.el, @@ -24353,4 +24362,5 @@ See ChangeLog.2 for earlier changes. ;; coding: utf-8 ;; fill-column: 79 ;; add-log-time-zone-rule: t +;; left-margin: 8 ;; End: diff --git a/lisp/gnus-demon.el b/lisp/gnus-demon.el index d0baf25..224bb3d 100644 --- a/lisp/gnus-demon.el +++ b/lisp/gnus-demon.el @@ -71,7 +71,7 @@ Emacs has been idle for IDLE `gnus-demon-timestep's." ;;; Internal variables. (defvar gnus-demon-timers nil - "List of idle timers which are running.") + "Plist of idle timers which are running.") (defvar gnus-inhibit-demon nil "If non-nil, no daemonic function will be run.") @@ -98,15 +98,32 @@ Emacs has been idle for IDLE `gnus-demon-timestep's." (float-time (or (current-idle-time) '(0 0 0))))) -(defun gnus-demon-run-callback (func &optional idle) - "Run FUNC if Emacs has been idle for longer than IDLE seconds." +(defun gnus-demon-run-callback (func &optional idle time special) + "Run FUNC if Emacs has been idle for longer than IDLE seconds. +If not, and a TIME is given, restart a new idle timer, so FUNC +can be called at the next opportunity. Such a special idle run is +marked with SPECIAL." (unless gnus-inhibit-demon - (when (or (not idle) - (and (eq idle t) (> (gnus-demon-idle-since) 0)) - (<= idle (gnus-demon-idle-since))) - (with-local-quit - (ignore-errors - (funcall func)))))) + (let ((run t)) + (when (eq idle t) + (setq idle 0.001)) + (cond (special + (setq gnus-demon-timers + (plist-put gnus-demon-timers func + (run-with-timer time time 'gnus-demon-run-callback + func idle time)))) + ((and idle (> idle (gnus-demon-idle-since))) + (setq run nil) + (when time + (nnheader-cancel-timer (plist-get gnus-demon-timers func)) + (setq gnus-demon-timers + (plist-put gnus-demon-timers func + (run-with-idle-timer idle nil 'gnus-demon-run-callback + func idle time t)))))) + (when run + (with-local-quit + (ignore-errors + (funcall func))))))) (defun gnus-demon-init () "Initialize the Gnus daemon." @@ -141,12 +158,12 @@ Emacs has been idle for IDLE `gnus-demon-timestep's." ;; (func number any) ;; Call every `time' ((eq time-type 'integer) - (run-with-timer time time 'gnus-demon-run-callback func idle)) + (run-with-timer time time 'gnus-demon-run-callback func idle time)) ;; (func string any) ((eq time-type 'string) (run-with-timer time (* 24 60 60) 'gnus-demon-run-callback func idle))))) (when timer - (add-to-list 'gnus-demon-timers timer))))) + (setq gnus-demon-timers (plist-put gnus-demon-timers func timer)))))) (defun gnus-demon-time-to-step (time) "Find out how many steps to TIME, which is on the form \"17:43\"." @@ -185,8 +202,8 @@ Emacs has been idle for IDLE `gnus-demon-timestep's." (defun gnus-demon-cancel () "Cancel any Gnus daemons." (interactive) - (dolist (timer gnus-demon-timers) - (nnheader-cancel-timer timer)) + (dotimes (i (/ (length gnus-demon-timers) 2)) + (nnheader-cancel-timer (nth (1+ (* i 2)) gnus-demon-timers))) (setq gnus-demon-timers nil)) (defun gnus-demon-add-disconnection () -- 1.7.3.4