Gnus development mailing list
 help / color / mirror / Atom feed
From: "Vida Gábor" <vidagabor@gmail.com>
To: Lars Magne Ingebrigtsen <larsi@gnus.org>
Cc: ding@gnus.org
Subject: Re: HH:MM time spec for gnus-demon-add-handler
Date: Thu, 26 Jan 2012 09:33:05 +0100	[thread overview]
Message-ID: <kod0wr8eg8xq.fsf@gmail.com> (raw)
In-Reply-To: <kod0liox621j.fsf@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1026 bytes --]

Vida Gábor <vidagabor@gmail.com> writes:

> Lars Magne Ingebrigtsen <larsi@gnus.org> writes:
>
>> I've now resurrected this code, which was apparently lost in 2010.
>
> Hi Lars!
>
> Here comes my findings and a patch that fix them.
>
> - `gnus-demon-time-to-step' returns the steps needed to TIME, but
>   run-with-timer requires seconds.
>
> - The repeat value in case the time is "HH:MM" should be a day.
>
> - There were an other missing -- but documented -- feature when TIME is
>   a number and IDLE is nil when calling `gnus-demon-add-handler'.
>
> - And I removed those clauses of the last cond in
>   `gnus-demon-time-to-step' that became unnecessary due to the previous
>   modification.

I've fixed two more bugs: one that I had introduced with my previous
modification and one that the IDLE should be interpreted as minutes and
passed to run-with-timer in seconds (according to the documentation).

The attached diff contains every hunks I posted before.

-- 
Best regards,
Gábor


[-- Attachment #2: gnus-demon.el.diff --]
[-- Type: text/x-patch, Size: 2911 bytes --]

diff --git a/lisp/gnus-demon.el b/lisp/gnus-demon.el
index 2f99522..c91c725 100644
--- a/lisp/gnus-demon.el
+++ b/lisp/gnus-demon.el
@@ -102,6 +102,7 @@ Emacs has been idle for IDLE `gnus-demon-timestep's."
   "Run FUNC if Emacs has been idle for longer than IDLE seconds."
   (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
@@ -115,6 +116,7 @@ Emacs has been idle for IDLE `gnus-demon-timestep's."
     ;; Set up the timer.
     (let* ((func (nth 0 handler))
            (time (nth 1 handler))
+           (time-type (type-of time))
            (idle (nth 2 handler))
            ;; Compute time according with timestep.
            ;; If t, replace by 1
@@ -123,33 +125,32 @@ Emacs has been idle for IDLE `gnus-demon-timestep's."
                        ((null time)
 			nil)
 		       ((stringp time)
-			(gnus-demon-time-to-step time))
+			(* (gnus-demon-time-to-step time) gnus-demon-timestep))
                        (t
 			(* time gnus-demon-timestep))))
+           (idle (if (numberp idle)
+                     (* idle gnus-demon-timestep)
+                   idle))
+
            (timer
             (cond
-             ;; (func number t)
-             ;; Call when Emacs has been idle for `time'
-             ((and (numberp time) (eq idle t))
-              (run-with-timer time time 'gnus-demon-run-callback func time))
-             ;; (func number number)
-             ;; Call every `time' when Emacs has been idle for `idle'
-             ((and (numberp time) (numberp idle))
-              (run-with-timer time time 'gnus-demon-run-callback func idle))
              ;; (func nil number)
              ;; Only call when Emacs has been idle for `idle'
              ((and (null time) (numberp idle))
               (run-with-idle-timer (* idle gnus-demon-timestep) t
                                    'gnus-demon-run-callback func))
-             ;; (func number nil)
+             ;; (func number any)
              ;; Call every `time'
-             ((and (numberp time) (null idle))
-              (run-with-timer time time 'gnus-demon-run-callback func)))))
+             ((eq time-type 'integer)
+              (run-with-timer time time 'gnus-demon-run-callback func idle))
+             ;; (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)))))
 
 (defun gnus-demon-time-to-step (time)
-  "Find out how many seconds to TIME, which is on the form \"17:43\"."
+  "Find out how many steps to TIME, which is on the form \"17:43\"."
   (let* ((now (current-time))
 	 ;; obtain NOW as discrete components -- make a vector for speed
 	 (nowParts (decode-time now))

  reply	other threads:[~2012-01-26  8:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-05  9:56 Gábor Vida
2012-01-03 23:05 ` Lars Magne Ingebrigtsen
2012-01-24  6:35   ` Vida Gábor
2012-01-26  8:33     ` Vida Gábor [this message]
2012-01-27 17:45       ` Lars Ingebrigtsen

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=kod0wr8eg8xq.fsf@gmail.com \
    --to=vidagabor@gmail.com \
    --cc=ding@gnus.org \
    --cc=larsi@gnus.org \
    /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.
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).