$idle-time - System idle event delay time
$idle-time milliseconds; Default is 1000
10 <= milliseconds <= t
$idle-time sets the time waited between the last user event and the generation of a idle-pick key event. When user input stops for $idle-time milliseconds MicroEmacs checks the binding of the special idle-pick key, if this pseudo key is bound then the command it is bound to will be executed. MicroEmacs will then cycle, generating a idle-pick every $idle-time milliseconds until user activity starts. At this point a idle-drop key event is generated, if this pseudo key is bound then the command it is bound to will be executed.
This system is useful for things which can be done in the background.
The following example is taken from ssaver.emf and implements a simple screen saver:-
set-variable %screen-saver 0 define-macro screen-saver !if ¬ &pinc %screen-saver 1 !if &seq @cck "idle-pick" ; default is to switch on in 5 minutes time &cond @? @# 300000 create-callback screen-saver !else !if &seq @cck "callback" @# create-callback screen-saver !elif @? ; user has suppled argument, install or remove !if &gre @# 0 &mul @# 60000 global-bind-key screen-saver "idle-pick" !else !force global-unbind-key "idle-pick" !endif set-variable %screen-saver &sub %screen-saver 1 !return !endif set-variable @# $frame-depth !while &dec @# 1 2 screen-poke @# 0 $global-scheme &spr "%n" $frame-width " " !done 0 screen-poke 0 0 $global-scheme &spr "%n" $frame-width " " -1 show-cursor ; must set this to stop recursion when waiting for a key! set-variable %screen-saver 0 set-variable @# @cg set-variable %screen-saver 1 1 show-cursor screen-update 0 ml-write !endif !endif set-variable %screen-saver &sub %screen-saver 1 !emacro
Care must be taken to ensure that a recursive loop is not created, consider the following example:-
define-macro bored !if &iseq @mc1 "Are you bored (y/n)? " "nNyY" "y" ml-write "Play a silly game!" !endif !emacro global-bind-key bored idle-pick
If this was executed MicroEmacs would very quickly crash! As soon as a second past bored would execute, which will prompt the user and wait for input. If a second passes without input bored will be executed again and again and again until stack memory runs out! To avoid this idle-pick should be unbound before waiting for user input, i.e.:-
define-macro bored global-unbind-key idle-pick !if &iseq @mc1 "Are you bored (y/n)? " "nNyY" "y" ml-write "Play a silly game!" !endif global-bind-key bored idle-pick !emacro global-bind-key bored idle-pick
Copyright (c) 1998-2006 JASSPA
Last Modified: 2004/12/10
Generated On: 2006/10/07