(lispref.info)Waiting


Next: Quitting Prev: Reading Input Up: Command Loop

Waiting for Elapsed Time or Input
=================================

   The waiting commands are designed to make Emacs wait for a certain
amount of time to pass or until there is input.  For example, you may
wish to pause in the middle of a computation to allow the user time to
view the display.  `sit-for' pauses and updates the screen, and returns
immediately if input comes in, while `sleep-for' pauses without
updating the screen.

   Note that in FSF Emacs, the commands `sit-for' and `sleep-for' take
two arguments to specify the time (one integer and one float value),
instead of a single argument that can be either an integer or a float.

 - Function: sit-for SECONDS &optional NODISP
     This function performs redisplay (provided there is no pending
     input from the user), then waits SECONDS seconds, or until input is
     available.  SECONDS may be a float, meaning a fractional part of a
     second.  The result is `t' if `sit-for' waited the full time with
     no input arriving (see `input-pending-p' in Note: Peeking and
     Discarding).  Otherwise, the value is `nil'.

     Redisplay is normally preempted if input arrives, and does not
     happen at all if input is available before it starts. (You can
     force screen updating in such a case by using `force-redisplay'.
     Note: Refresh Screen.) If there is no input pending, you can
     force an update with no delay by using `(sit-for 0)'.

     If NODISP is non-`nil', then `sit-for' does not redisplay, but it
     still returns as soon as input is available (or when the timeout
     elapses).

     The usual purpose of `sit-for' is to give the user time to read
     text that you display.

 - Function: sleep-for SECONDS
     This function simply pauses for SECONDS seconds without updating
     the display.  SECONDS may be a float, meaning pause for some
     fractional part of a second.  This function pays no attention to
     available input.  It returns `nil'.

     Use `sleep-for' when you wish to guarantee a delay.

   Note: Time of Day, for functions to get the current time.


automatically generated by info2www