| Newsgroups |
gmane.emacs.help |
| Message-ID |
<[email protected]> |
[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)
--
The lyf so short, the craft so long to lerne.
- Geoffrey Chaucer, The Parliament of Birds.