3

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.

Andrew Swann
  • 3,436
  • 2
  • 15
  • 43

1 Answers1

3

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

phils
  • 48,657
  • 3
  • 76
  • 115