Gnus development mailing list
 help / color / mirror / Atom feed
* [PATCH] Daemon, don't wait another timer period, when idleness is too low.
@ 2012-02-28 22:54 Peter Münster
  2012-02-29  7:18 ` Peter Münster
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Peter Münster @ 2012-02-28 22:54 UTC (permalink / raw)
  To: ding

* 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  <pmrb@free.fr>  (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  <rgm@gnu.org>
 
 	* 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




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

* Re: [PATCH] Daemon, don't wait another timer period, when idleness is too low.
  2012-02-28 22:54 [PATCH] Daemon, don't wait another timer period, when idleness is too low Peter Münster
@ 2012-02-29  7:18 ` Peter Münster
  2012-03-10  0:41 ` Lars Magne Ingebrigtsen
  2012-03-10 22:34 ` Reiner Steib
  2 siblings, 0 replies; 6+ messages in thread
From: Peter Münster @ 2012-02-29  7:18 UTC (permalink / raw)
  To: ding

Motivation for this patch:

When calling "(gnus-demon-add-handler 'task 200 15)" and after each period of
200 minutes the idle time is lower than 15 minutes, the task is never called,
which can be annoying. This patch tries to solve the problem for the case when
the time is a number of minutes. Nothing changes for a time-string.

-- 
           Peter




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

* Re: [PATCH] Daemon, don't wait another timer period, when idleness is too low.
  2012-02-28 22:54 [PATCH] Daemon, don't wait another timer period, when idleness is too low Peter Münster
  2012-02-29  7:18 ` Peter Münster
@ 2012-03-10  0:41 ` Lars Magne Ingebrigtsen
  2012-03-10 14:02   ` Peter Münster
  2012-03-10 22:34 ` Reiner Steib
  2 siblings, 1 reply; 6+ messages in thread
From: Lars Magne Ingebrigtsen @ 2012-03-10  0:41 UTC (permalink / raw)
  To: Peter Münster; +Cc: ding

Peter Münster <pmlists@free.fr> writes:

> +2012-02-28  Peter Münster  <pmrb@free.fr>  (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.

This seems reasonable, I think, but the patch is too large to be applied
without a copyright assignment.  Do you have copyright assignment papers
on file with the FSF?

-- 
(domestic pets only, the antidote for overdose, milk.)
  bloggy blog http://lars.ingebrigtsen.no/



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

* Re: [PATCH] Daemon, don't wait another timer period, when idleness is too low.
  2012-03-10  0:41 ` Lars Magne Ingebrigtsen
@ 2012-03-10 14:02   ` Peter Münster
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Münster @ 2012-03-10 14:02 UTC (permalink / raw)
  To: ding

On Sat, Mar 10 2012, Lars Magne Ingebrigtsen wrote:

> This seems reasonable, I think, but the patch is too large to be applied
> without a copyright assignment.  Do you have copyright assignment papers
> on file with the FSF?

I sent an email to the FSF 2 weeks ago, but no reply yet...
I'll try again with "Disposition-Notification-To".

-- 
           Peter




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

* Re: [PATCH] Daemon, don't wait another timer period, when idleness is too low.
  2012-02-28 22:54 [PATCH] Daemon, don't wait another timer period, when idleness is too low Peter Münster
  2012-02-29  7:18 ` Peter Münster
  2012-03-10  0:41 ` Lars Magne Ingebrigtsen
@ 2012-03-10 22:34 ` Reiner Steib
  2012-03-11  7:13   ` left-margin = 8 (was: [PATCH] Daemon, don't wait another timer period, when idleness is too low.) Peter Münster
  2 siblings, 1 reply; 6+ messages in thread
From: Reiner Steib @ 2012-03-10 22:34 UTC (permalink / raw)
  To: ding

On Tue, Feb 28 2012, Peter Münster wrote:

> --- a/lisp/ChangeLog
> +++ b/lisp/ChangeLog
[...]
> @@ -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:

Please don't insert unrelated changed like this one.

Why do you need this?  For me, left-margin is set to 8 in
change-log-mode already.

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/




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

* left-margin = 8 (was: [PATCH] Daemon, don't wait another timer period, when idleness is too low.)
  2012-03-10 22:34 ` Reiner Steib
@ 2012-03-11  7:13   ` Peter Münster
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Münster @ 2012-03-11  7:13 UTC (permalink / raw)
  To: ding

On Sat, Mar 10 2012, Reiner Steib wrote:

>> +;; left-margin: 8
>
> Please don't insert unrelated changed like this one.
>
> Why do you need this?  For me, left-margin is set to 8 in
> change-log-mode already.

I have
"(add-hook 'change-log-mode-hook (lambda () (setq left-margin 0)))"
in my init.el, and I thought, that this line would not hurt...

-- 
           Peter




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

end of thread, other threads:[~2012-03-11  7:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-28 22:54 [PATCH] Daemon, don't wait another timer period, when idleness is too low Peter Münster
2012-02-29  7:18 ` Peter Münster
2012-03-10  0:41 ` Lars Magne Ingebrigtsen
2012-03-10 14:02   ` Peter Münster
2012-03-10 22:34 ` Reiner Steib
2012-03-11  7:13   ` left-margin = 8 (was: [PATCH] Daemon, don't wait another timer period, when idleness is too low.) Peter Münster

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 NNTP newsgroup(s).