[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Revamping sit-for [Was: Lingering input pending with motif menu bar]

From: Chong Yidong
Subject: Revamping sit-for [Was: Lingering input pending with motif menu bar]
Date: Fri, 07 Jul 2006 17:55:50 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

In the thread

  address@hidden: Lingering input pending with motif menu bar]

Richard has said he wanted to replace sit-for so that only actual
Emacs Lisp events will interrupt input.  I still think this is a
little dangerous so close to the release, but if we gotta do what we
gotta do, I have written the necessary code for it.  It involves the
following changes:

1. Delete the built-in function Fsit_for, and change the four places
   in the C source code that call Fsit_for to call sit_for instead.

2. Insert a new built-in function `redisplay':

DEFUN ("redisplay", Fredisplay, Sredisplay, 0, 0, 0,
       doc: /* Perform redisplay.
If input is available before this starts, redisplay is preempted
unless `redisplay-dont-pause' is non-nil.  */)
  swallow_events (Qt);
  redisplay_preserve_echo_area (2);
  return Qt;

3. Put a new function `sit-for' in subr.el:

(defun sit-for (seconds &optional nodisp obsolete)
  "Perform redisplay, then wait for SECONDS seconds or until input is available.
SECONDS may be a floating-point value, meaning that you can wait for a
fraction of a second.
\(Not all operating systems support waiting for a fraction of a second.)
Optional arg NODISP non-nil means don't redisplay, just wait for input.
Redisplay is preempted as always if input arrives, and does not happen
if input is available before it starts.
Value is t if waited the full time with no input arriving, and nil otherwise.

Redisplay will occur even when input is available if SECONDS is negative.

An obsolete but still supported form is
Where the optional arg MILLISECONDS specifies an additional wait period,
in milliseconds; this was useful when Emacs was built without
floating point support.
usage: (sit-for SECONDS &optional NODISP OLD-NODISP)"
  (when obsolete
    (setq seconds (+ seconds (* 1e-3 nodisp)))
    (setq nodisp obsolete))
  (unless nodisp
    (let ((redisplay-dont-pause (or (< seconds 0) redisplay-dont-pause)))
  (or (<= seconds 0)
      (let ((tag (cons nil nil))
            event timer)
        (if (catch tag
              (setq timer (run-with-timer seconds nil 'with-timeout-handler 
              (setq event (read-event))
          (cancel-timer timer)
          (push event unread-command-events)

I have tested out these changes, and observed that Emacs does not
explode.  Richard, if you really want to do this, I can check the
changes in so that they can get as much testing as possible before the

reply via email to

[Prev in Thread] Current Thread [Next in Thread]