Subject: bug#75361: SOLVED - Re: bug#75361: 31.0.50; run-with-idle-timer not working unless there is some activity

From: Jean Louis <[email-masked]>
Date: Sat, 4 Jan 2025 22:21:51 +0300

* Ship Mints <[email-masked]> [2025-01-04 20:58]:
> I believe this is intended behavior. You should use a regular interval
> timer if you want repeating executions that do not depend upon Emacs
> entering the idle state. Not sure why you think this worked differently in
> the recent past.
> 
> "Emacs becomes *idle* when it starts waiting for user input (unless it
> waits for input with a timeout, see Reading One Event
> <https://www.gnu.org/software/emacs/manual/html_node/elisp/Reading-One-Event.html>),
> and it remains idle until the user provides some input. If a timer is set
> for five seconds of idleness, it runs approximately five seconds after
> Emacs first becomes idle. Even if repeat is non-nil, this timer will not
> run again as long as Emacs remains idle, because the duration of idleness
> will continue to increase and will not go down to five seconds again."

Okay I got it. Though I am surprised as I was using idle timer
thousands of times. I was thinking it repeated itself, while it
didn't.

Recently I started observing and have seen it is getting blocked, I
wondered why, due to lack of understanding.

I have found solution to my problem, so I will simply run the function
`run-with-timer` and then check if user is idle to execute it.

Basically, I do not need executions if user is not idle.

(defun my-hello ()
  (when (and (current-idle-time)
	     (>= (cadr (current-idle-time)) 5))
    (rcd-message "Current idle time: %s" (cadr (current-idle-time)))))

(run-with-timer 5 5 'my-hello)

So in the sense of how I understand it, `run-with-idle-timer` only
sounds as the function I need, while it is not.

I can make it this way:

(run-with-timer 10 10 'rcd-run-repeatingly-when-idle 5 'my-hello)

(defun rcd-run-repeatingly-when-idle (secs function &rest args)
    (when (and (current-idle-time)
	       (>= (cadr (current-idle-time)) secs))
      (apply 'funcall function args)))

As that way it will use `run-with-timer` though only when user is idle
for SECS.

-- 
Jean Louis