* Timers for weekly events
@ 2024-07-24 16:28 Christopher Howard
2024-07-24 16:45 ` Eli Zaretskii
0 siblings, 1 reply; 11+ messages in thread
From: Christopher Howard @ 2024-07-24 16:28 UTC (permalink / raw)
To: Emacs Devel Mailing List
Hi, I'm running 29.4, but I don't think there were any recent changes in this area: I really appreciate the timers library, but I feel like one deficiency is that it doesn't make it easy to set up weekly reoccuring timers. In my use case, I need to send an automated e-mail once per week. But I can imagine other use cases, such as downloading online science data or managing log files.
I was wondering if it might be helpful to have some kind of helper function available in timer.el (and documented in the manual) that would make this easier. Here is the one I am using:
http://gem.librehacker.com/gemlog/starlog/20240723-0.gmi
Or perhaps, alternatively, there would be some appropriate adjustment to the run-at-time interface...?
--
📛 Christopher Howard
🚀 gemini://gem.librehacker.com
🌐 http://gem.librehacker.com
בראשית ברא אלהים את השמים ואת הארץ
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Timers for weekly events
2024-07-24 16:28 Christopher Howard
@ 2024-07-24 16:45 ` Eli Zaretskii
0 siblings, 0 replies; 11+ messages in thread
From: Eli Zaretskii @ 2024-07-24 16:45 UTC (permalink / raw)
To: Christopher Howard; +Cc: emacs-devel
> From: Christopher Howard <christopher@librehacker.com>
> Date: Wed, 24 Jul 2024 08:28:11 -0800
>
> Hi, I'm running 29.4, but I don't think there were any recent changes in this area: I really appreciate the timers library, but I feel like one deficiency is that it doesn't make it easy to set up weekly reoccuring timers. In my use case, I need to send an automated e-mail once per week. But I can imagine other use cases, such as downloading online science data or managing log files.
What exactly is the difficulty you need to solve?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Timers for weekly events
@ 2024-07-24 17:35 Christopher Howard
2024-07-24 18:38 ` Eli Zaretskii
2024-07-24 23:44 ` James Thomas
0 siblings, 2 replies; 11+ messages in thread
From: Christopher Howard @ 2024-07-24 17:35 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: emacs-devel
So, let's say you want to have a run-at-time call in your init.el, which starts a timer that will execute once per week, say Tuesday at 4am. How exactly do you go about this?
One option would be you could pass a time of day to run-at-time. However, then the function you call needs to implement two things: (1) it needs to first check if it is on the right day of the week; (2) due to the design of run-at-time, it will need to check if the time is *actually* the correct time of day, since when passing a time-of-day to run-at-time, run-at-time will go ahead and call the function if the specified time of day has already occured anytime in the past day. (I once mistakenly reported this as a bug.)
Alternatively, we can pass in a relative time (number of seconds) until the next occurrence of Tuesday 4am. But how does the user calculate that value, without having to supply his own additional function that somehow works out the logic and math? So far as I know, there isn't any built in elisp function that makes such a calculation simple for the user.
I chose the second approach, as it does not require the callback to have any knowledge of times and dates and such. And then I wrote my own function, as documented in my post <http://gem.librehacker.com/gemlog/starlog/20240723-0.gmi>. But it seems like this, or some other simple solution, should be readily available to all users of the timer library.
--
Christopher Howard
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Timers for weekly events
2024-07-24 17:35 Christopher Howard
@ 2024-07-24 18:38 ` Eli Zaretskii
2024-07-24 23:44 ` James Thomas
1 sibling, 0 replies; 11+ messages in thread
From: Eli Zaretskii @ 2024-07-24 18:38 UTC (permalink / raw)
To: Christopher Howard; +Cc: emacs-devel
> X-Spam-Status: No, score=-0.999 tagged_above=-10 required=5
> tests=[ALL_TRUSTED=-1, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
> From: Christopher Howard <christopher@librehacker.com>
> Cc: emacs-devel@gnu.org
> Date: Wed, 24 Jul 2024 09:35:22 -0800
>
> So, let's say you want to have a run-at-time call in your init.el, which starts a timer that will execute once per week, say Tuesday at 4am. How exactly do you go about this?
>
> One option would be you could pass a time of day to run-at-time. However, then the function you call needs to implement two things: (1) it needs to first check if it is on the right day of the week; (2) due to the design of run-at-time, it will need to check if the time is *actually* the correct time of day, since when passing a time-of-day to run-at-time, run-at-time will go ahead and call the function if the specified time of day has already occured anytime in the past day. (I once mistakenly reported this as a bug.)
>
> Alternatively, we can pass in a relative time (number of seconds) until the next occurrence of Tuesday 4am. But how does the user calculate that value, without having to supply his own additional function that somehow works out the logic and math? So far as I know, there isn't any built in elisp function that makes such a calculation simple for the user.
>
> I chose the second approach, as it does not require the callback to have any knowledge of times and dates and such. And then I wrote my own function, as documented in my post <http://gem.librehacker.com/gemlog/starlog/20240723-0.gmi>. But it seems like this, or some other simple solution, should be readily available to all users of the timer library.
I suggest to take a look at midnight.el, it solves a very similar
problem: how to run a function at midnight of every day (or at a
user-defined offset from midnight). It sounds like you want to do
something very similar, except in your case the function should run
once every 7 days, not once per day.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Timers for weekly events
@ 2024-07-24 21:28 Christopher Howard
0 siblings, 0 replies; 11+ messages in thread
From: Christopher Howard @ 2024-07-24 21:28 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: emacs-devel
> I suggest to take a look at midnight.el, it solves a very similar
> problem: how to run a function at midnight of every day (or at a
> user-defined offset from midnight). It sounds like you want to do
> something very similar, except in your case the function should run
> once every 7 days, not once per day.
I see that `midnight-next' function does a similar calculation to the one my function does, though simpler because it only has to calculate seconds to the next midnight. I could see how midnight mode could be used to drive weekly events. The main downsides to this approach I'm seeing are (1) if you want events to occur at various times of day, the functions you pass in must launch their own timers with the offset time amount; (2) your timers wouldn't launch until at least midnight, if you had just (re)started Emacs; (3) `list-timers' wouldn't necessarily show all forth-coming timer events, only those timers that had already been launched in the midnight hook; (4) Your functions would still need to check what day it is. So, I'll keep using my function for now, though maybe rename it to `wee
kly-next'. I'm still not sure where weekly-next would fit amongst the Emacs libraries, though timer.el still seems the most likely candidate.
--
Christopher Howard
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Timers for weekly events
2024-07-24 17:35 Christopher Howard
2024-07-24 18:38 ` Eli Zaretskii
@ 2024-07-24 23:44 ` James Thomas
1 sibling, 0 replies; 11+ messages in thread
From: James Thomas @ 2024-07-24 23:44 UTC (permalink / raw)
To: Christopher Howard; +Cc: emacs-devel
Christopher Howard wrote:
> So, let's say you want to have a run-at-time call in your init.el,
> which starts a timer that will execute once per week, say Tuesday at
> 4am. How exactly do you go about this?
One option is to add a (info "(emacs) Diary") entry and customize
appt-disp-window-function to do what you want. (I do that, but not for
automation). This means that all the advanced stuff such as in (info
"(emacs) Sexp Diary Entries") are possible.
To check if the run has happened you could save state, perhaps in the
same diary entry.
Regards,
James
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Timers for weekly events
@ 2024-07-26 15:01 Christopher Howard
2024-07-26 16:01 ` Michael Heerdegen via Emacs development discussions.
0 siblings, 1 reply; 11+ messages in thread
From: Christopher Howard @ 2024-07-26 15:01 UTC (permalink / raw)
To: James Thomas; +Cc: emacs-devel
> One option is to add a (info "(emacs) Diary") entry and customize
> appt-disp-window-function to do what you want. (I do that, but not for
> automation). This means that all the advanced stuff such as in (info
> "(emacs) Sexp Diary Entries") are possible.
This would require you, though, to actually to run M-x diary, for the code to run? Or am I misunderstanding something? I want my function to run every Tuesday at exactly 4am even if I am away from the computer for a week.
--
Christopher Howard
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Timers for weekly events
2024-07-26 15:01 Christopher Howard
@ 2024-07-26 16:01 ` Michael Heerdegen via Emacs development discussions.
0 siblings, 0 replies; 11+ messages in thread
From: Michael Heerdegen via Emacs development discussions. @ 2024-07-26 16:01 UTC (permalink / raw)
To: emacs-devel
Christopher Howard <christopher@librehacker.com> writes:
> > One option is to add a (info "(emacs) Diary") entry and customize
> > appt-disp-window-function to do what you want. (I do that, but not for
> > automation). This means that all the advanced stuff such as in (info
> > "(emacs) Sexp Diary Entries") are possible.
>
> This would require you, though, to actually to run M-x diary, for the
> code to run?
No - please see (info "(emacs) Appointments").
Michael.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Timers for weekly events
@ 2024-07-26 16:23 Christopher Howard
2024-07-26 16:37 ` Michael Heerdegen via Emacs development discussions.
0 siblings, 1 reply; 11+ messages in thread
From: Christopher Howard @ 2024-07-26 16:23 UTC (permalink / raw)
To: Michael Heerdegen via Emacs development discussions.; +Cc: Michael Heerdegen
> No - please see (info "(emacs) Appointments").
So, my understanding so far of this approach is...
1) create repeating diary entry for the required time and day of week
2) attach elisp to it that calls desired function, saves state, etc.
3) the appointment reminder system causes the diary entry to be display X number of minutes before the appointment. This causes the attached elisp to be executed.
--
Christopher Howard
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Timers for weekly events
2024-07-26 16:23 Christopher Howard
@ 2024-07-26 16:37 ` Michael Heerdegen via Emacs development discussions.
2024-07-26 19:53 ` James Thomas
0 siblings, 1 reply; 11+ messages in thread
From: Michael Heerdegen via Emacs development discussions. @ 2024-07-26 16:37 UTC (permalink / raw)
To: emacs-devel
Christopher Howard <christopher@librehacker.com> writes:
> > No - please see (info "(emacs) Appointments").
>
> So, my understanding so far of this approach is...
>
> 1) create repeating diary entry for the required time and day of week
> 2) attach elisp to it that calls desired function, saves state, etc.
> 3) the appointment reminder system causes the diary entry to be
> display X number of minutes before the appointment. This causes the
> attached elisp to be executed.
What do you mean by "attaching elisp" - where is this mentioned?
Michael.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Timers for weekly events
2024-07-26 16:37 ` Michael Heerdegen via Emacs development discussions.
@ 2024-07-26 19:53 ` James Thomas
0 siblings, 0 replies; 11+ messages in thread
From: James Thomas @ 2024-07-26 19:53 UTC (permalink / raw)
To: emacs-devel
Michael Heerdegen via "Emacs development discussions." wrote:
> Christopher Howard <christopher@librehacker.com> writes:
>
>> > No - please see (info "(emacs) Appointments").
>>
>> So, my understanding so far of this approach is...
>>
>> 1) create repeating diary entry for the required time and day of week
>> 2) attach elisp to it that calls desired function, saves state, etc.
>> 3) the appointment reminder system causes the diary entry to be
>> display X number of minutes before the appointment.
You can check for the 'min-to-app' argument to be "0" at the exact time.
>> This causes the attached elisp to be executed.
> What do you mean by "attaching elisp" - where is this mentioned?
No this was my idea :)
Regards,
James
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2024-07-26 19:53 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-24 21:28 Timers for weekly events Christopher Howard
-- strict thread matches above, loose matches on Subject: below --
2024-07-26 16:23 Christopher Howard
2024-07-26 16:37 ` Michael Heerdegen via Emacs development discussions.
2024-07-26 19:53 ` James Thomas
2024-07-26 15:01 Christopher Howard
2024-07-26 16:01 ` Michael Heerdegen via Emacs development discussions.
2024-07-24 17:35 Christopher Howard
2024-07-24 18:38 ` Eli Zaretskii
2024-07-24 23:44 ` James Thomas
2024-07-24 16:28 Christopher Howard
2024-07-24 16:45 ` Eli Zaretskii
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).