2

Suppose I set two idle timers

(run-with-idle-timer 3 nil #'function1)
(run-with-idle-timer 3 nil #'function2)

What is the effect? After roughly 3 seconds will emacs run function1 and then wait 3 further seconds, or will there be no second delay before running function2?

I have browsed through the timer.el code and could not see what action to expect.

Update/Conclusion

Thanks to phils' answer I tried evaluating

(run-with-idle-timer 2 nil #'message "Function 1")
(run-with-idle-timer 3 nil #'message "Function 2")
(run-with-idle-timer 3 nil #'message "Function 3")
(run-with-idle-timer 4 nil #'message "Function 4")

in the *scratch* buffer and consistently get

Function 1
Function 3
Function 2
Function 4

printed in the *Messages* buffer after 4 seconds idle time, demonstrating exactly the behaviour he describes.

2

After three seconds of idleness, both timers will be triggered (and experimentally it is likely to be the second function which runs first, although I'm not sure if that's always going to be the case).

Executing an idle timer function does not cause Emacs to cease to be idle! That requires user input:

Emacs becomes "idle" when it starts waiting for user input, 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.

See C-hig (elisp) Idle Timers RET

  • Thanks. I had read that. So each idle timer is independent? – Andrew Swann Jun 1 '16 at 13:28
  • Most definitely, yes. I'd say you should just have a play with them, to get a feel for how they work in practice. – phils Jun 1 '16 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.