Jon-Michael Deldin has a short post detailing how to schedule periodic events in Emacs. Most of us probably don’t want to have Emacs natter at us as implemented in Deldin’s example but it’s easy to imagine many helpful uses for the run-with-idle-timer
function.
More useful, perhaps, are the run-with-timer
and run-at-time
functions. The run-with-idle-timer
function runs a function when Emacs has been idle for some period of time. The other two run every \(n\) seconds (run-with-timer
) or at a specific time and optionally every \(n\) seconds thereafter (run-at-time
).
The latter two functions are very flexible and perform a bit differently depending on their arguments so be sure to read their documentation. If you want to do things like schedule a git push every hour (or when Emacs is otherwise idle), these functions could be just what you need.