unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Ship Mints <shipmints@gmail.com>
To: Jean Louis <bugs@gnu.support>
Cc: 75361@debbugs.gnu.org
Subject: bug#75361: SOLVED - Re: bug#75361: 31.0.50; run-with-idle-timer not working unless there is some activity
Date: Mon, 6 Jan 2025 15:47:36 -0500	[thread overview]
Message-ID: <CAN+1HbrORUxsqgYPZDw+QTcgrWTVPM3NMKHwQgXyH+eCPDxj=g@mail.gmail.com> (raw)
In-Reply-To: <Z3mKT_fOiBY815rF@lco2>

[-- Attachment #1: Type: text/plain, Size: 3052 bytes --]

Also in the documentation for idle timers, you can find a different
approach that might work for you than the one you proposed. At the very
least, your timer will fire only when Emacs is idle rather than polling for
idleness. HTH.

https://www.gnu.org/software/emacs/manual/html_node/elisp/Idle-Timers.html

"Similarly, do not write an idle timer function that sets up another idle
timer (including the same idle timer) with secs argument less than or equal
to the current idleness time. Such a timer will run almost immediately, and
continue running again and again, instead of waiting for the next time
Emacs becomes idle. The correct approach is to reschedule with an
appropriate increment of the current value of the idleness time, as
described below."

-Stephane

On Mon, Jan 6, 2025 at 3:30 PM Jean Louis <bugs@gnu.support> wrote:

> * Ship Mints <shipmints@gmail.com> [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
>
>
>
>

[-- Attachment #2: Type: text/html, Size: 4561 bytes --]

  reply	other threads:[~2025-01-06 20:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-03 22:30 bug#75361: 31.0.50; run-with-idle-timer not working unless there is some activity Jean Louis
2025-01-04 17:56 ` Ship Mints
2025-01-04 19:21   ` bug#75361: SOLVED - " Jean Louis
2025-01-06 20:47     ` Ship Mints [this message]
2025-01-10 15:42       ` Jean Louis
2025-01-10 20:22         ` Eli Zaretskii
2025-01-04 18:46 ` Eli Zaretskii
2025-01-06 21:28   ` Stefan Kangas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAN+1HbrORUxsqgYPZDw+QTcgrWTVPM3NMKHwQgXyH+eCPDxj=g@mail.gmail.com' \
    --to=shipmints@gmail.com \
    --cc=75361@debbugs.gnu.org \
    --cc=bugs@gnu.support \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).