Re: How to reset the idle timer?

Stefan Monnier <[email protected]>
Newsgroups gmane.emacs.help
Message-ID <[email protected]>
> Stefan Monnier via Users list for the GNU Emacs text editor
> <[email protected]> writes:
>
>> This is actually an ideal use-case for Daniel Colascione's recent
>> suggestion to change `(run-with-idle-timer N ...)` to mean
>> that N starts counting *now* rather than starting counting when the
>> current idle period started.
>
> I would welcome such a functionality (maybe under a different name).
>
> What I also wanted to mention is that we have `current-idle-time`  With
> this it should be possible to get the same semantics in Elisp now I
> think (?).

Yes, it's possible, but tricky: for the idle-periods beyond the current
one, you still need to call `(run-with-idle-timer N ...)` but you
additionally need to:

- Prevent that timer from running in the current idle period.
- Use a secondary timer that runs at `current-idle-time + N` in the
  current idle period, which requires making sure it tuns only if we're
  still in the same idle period.

That's fairly tricky/delicate to code.

An `end-of-idle-period-hook` would help implement it in a robust way,
tho you can probably still make it work fairly reliably by looking at
the idle *start* time (i.e.  `(subtract-time (current-time)
(current-idle-time))`) to tell if we're still in the same idle period or
not (tho you the idle start time you get this way is approximate and
fluctuates from one call to the next, so you'd need some "fuzzy"
comparison).


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