Re: How to reset the idle timer?

Stéphane Marks <[email protected]>
Newsgroups gmane.emacs.help
Message-ID <CAN+1HbovJhycSNVqTKDTPgREE-R7q+dcR9zSJXf9mQKm9u=81A@mail.gmail.com>
On Sun, Mar 1, 2026 at 2:57 AM <[email protected]> wrote:

> On 2026-02-26, at 09:24, Michael Heerdegen via Users list for the GNU
> Emacs text editor <[email protected]> wrote:
>
> > [email protected] writes:
> >
> >> Hi all,
> >>
> >> I'd like to tell Emacs "start counting the idle time from now", even if
> >> the user didn't do anything.  How to do that?
> >>
> >> I asked an LLM, and it told me to say
> >>
> >> (setq unread-command-events '(t))
> >>
> >> However, it had troubles explaining why I should use `(t)'.  The docs
> >> for `unread-command-events' didn't help much, either.  By trial and
> >> error I found out that
> >>
> >> (setq unread-command-events nil)
> >>
> >> is better in the sense that it doesn't pollute `view-lossage'.  Is that
> >> a correct way?  Is that the best way?
> >
> > Your subject says "How to reset the idle timer".  "Timer" or "Time"?
> > What do you want to do, and for what purpose?
>
> Good point.  I don't mean an "idle timer" in the sense of Emacs idle
> timers (my bad, not the best wording), but the internal something Emacs
> uses to know when to fire idle timers - so to speak, the "master idle
> timer".
>
> Here is my use case.  When I close my laptop (not sure what it's
> technically called - sleep? hibernation?), and then open it again (say,
> after a few hours), I'd like Emacs to set up an idle timer to do
> something, say, 1 minute after I stop pressing any buttons.  I have
> a (not great, but working) way to run some Elisp after I open my laptop,
> but when I set up an idle timer then, it runs immediately, since the
> idle time is several hours.  I'd like to reset that idle time so that my
> idle timer will really run after 1 minute of idleness - so, 1 minute
> /after/ opening the laptop if I don't do anything else, and later if
> I do something in Emacs within 60 seconds of opening my laptop.
>

You could give the new `system-sleep` package a try that is in Emacs 31
from master.  Register a hook on `system-sleep-event-functions` and your
hook will be notified when the system is about to sleep or has woken up.
This will be more reliable than relying on timers, though, if you want to
defer some of the work you could set a one-shot timer upon waking to do
your work.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.