Gnus development mailing list
 help / color / mirror / Atom feed
* HH:MM time spec for gnus-demon-add-handler
@ 2011-11-05  9:56 Gábor Vida
  2012-01-03 23:05 ` Lars Magne Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Gábor Vida @ 2011-11-05  9:56 UTC (permalink / raw)
  To: ding

Hi!

I tried to use

  (gnus-demon-add-handler 'gnus-demon-scan-news "11:20" 5)

According to the manual, it is possible to specify the time as HH:MM:

  And if TIME is a string, it should look like `07:31', and the function
  will then be called once every day somewhere near that time.  Modified
  by the IDLE parameter, of course.

But I get the following:

  Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p "11:20")
    gnus-demon-init()
    gnus-demon-remove-handler(gnus-demon-scan-news)
    gnus-demon-add-handler(gnus-demon-scan-news "11:20" 5)
    eval((gnus-demon-add-handler (quote gnus-demon-scan-news) "11:20" 5))
    eval-last-sexp-1(nil)
    eval-last-sexp(nil)
    call-interactively(eval-last-sexp nil nil)

And it seems that the code has been modified so that this possibility is
removed.

I use the latest git version of Gnus.

-- 
Best regards,
Gábor




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

* Re: HH:MM time spec for gnus-demon-add-handler
  2011-11-05  9:56 HH:MM time spec for gnus-demon-add-handler Gábor Vida
@ 2012-01-03 23:05 ` Lars Magne Ingebrigtsen
  2012-01-24  6:35   ` Vida Gábor
  0 siblings, 1 reply; 5+ messages in thread
From: Lars Magne Ingebrigtsen @ 2012-01-03 23:05 UTC (permalink / raw)
  To: Gábor Vida; +Cc: ding

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

>   And if TIME is a string, it should look like `07:31', and the function
>   will then be called once every day somewhere near that time.  Modified
>   by the IDLE parameter, of course.

I've now resurrected this code, which was apparently lost in 2010.

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



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

* Re: HH:MM time spec for gnus-demon-add-handler
  2012-01-03 23:05 ` Lars Magne Ingebrigtsen
@ 2012-01-24  6:35   ` Vida Gábor
  2012-01-26  8:33     ` Vida Gábor
  0 siblings, 1 reply; 5+ messages in thread
From: Vida Gábor @ 2012-01-24  6:35 UTC (permalink / raw)
  To: Lars Magne Ingebrigtsen; +Cc: ding

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

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.

-- 
Regards,
Gábor


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

diff --git a/lisp/gnus-demon.el b/lisp/gnus-demon.el
index 2f99522..78035f8 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 idle (> (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,28 @@ 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))))
            (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))

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

* Re: HH:MM time spec for gnus-demon-add-handler
  2012-01-24  6:35   ` Vida Gábor
@ 2012-01-26  8:33     ` Vida Gábor
  2012-01-27 17:45       ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Vida Gábor @ 2012-01-26  8:33 UTC (permalink / raw)
  To: Lars Magne Ingebrigtsen; +Cc: ding

[-- 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))

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

* Re: HH:MM time spec for gnus-demon-add-handler
  2012-01-26  8:33     ` Vida Gábor
@ 2012-01-27 17:45       ` Lars Ingebrigtsen
  0 siblings, 0 replies; 5+ messages in thread
From: Lars Ingebrigtsen @ 2012-01-27 17:45 UTC (permalink / raw)
  To: Vida Gábor; +Cc: ding

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

> 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.

Thanks; applied.  The patch is borderline for needing FSF copyright
assignment papers, but since parts of it is moving lines around, it
looks bigger than it is, so I think the total comes down to less than
ten lines.

But would you be willing to sign copyright assignment papers for the FSF
to cover any future patches you may write?

-- 
(domestic pets only, the antidote for overdose, milk.)
  http://lars.ingebrigtsen.no  *  Sent from my Rome



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

end of thread, other threads:[~2012-01-27 17:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-05  9:56 HH:MM time spec for gnus-demon-add-handler 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
2012-01-27 17:45       ` Lars Ingebrigtsen

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).