Re: How to reset the idle timer?

[email protected]
Newsgroups gmane.emacs.help
Message-ID <[email protected]>
On 2026-02-26, at 11:28, [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?
>>
>
> What is your algorithm?  Here is a guess:
>
>   - Start a timer after Emacs has been idle for 1 second
>   - Do nothing while Emacs is idle
>   - When an event happens, report how long Emacs was idle
>
> The following sets an idle timer to start after Emacs has
> been idle for 3 seconds.  At the next input event, it
> reports how many seconds have passed since Emacs was first
> idle.  ‘sit-for’ is arbitrarily set to 10000 seconds,
> assuming that you only want to measure idle periods less
> than that amount of time.
>
> (defvar my-idle-time nil)
>
> (defvar my-timer nil)
>
> (defun report-idle-time ()
>   (message "starting idle time")
>   (sit-for 10000 t)
>   (setq my-idle-time (current-idle-time))
>   (message "idle time: %S" (time-convert my-idle-time 'integer)))
>
> (setq my-timer (run-with-idle-timer 3 nil #'report-idle-time))
> (cancel-timer my-timer)

Not sure this would work, with `cancel-timer' right after
`run-with-idle-timer'.  Anyway, it seems this is not what I need anyway.
Sorry for the poor wording of my initial question.

Best,

-- 
Marcin Borkowski
https://mbork.pl
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.