emacs-devel
[Top][All Lists]
Advanced

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

Broken sit-for [was: Re: Minor fix for life.el.]


From: Kim F. Storm
Subject: Broken sit-for [was: Re: Minor fix for life.el.]
Date: Thu, 07 Sep 2006 16:27:52 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

David Kastrup <address@hidden> writes:

>> However, the problem is not fixed by this as sit-for returns
>> immediately `t' if its argument is zero (AFAICT).
>
> Probably the option least likely to require any changes even if
> sit-for is about to change.
>
> Kim, any idea whether this sit-for return value is turning out the way
> you intended it?  At least the documentation says "t if waited for
> whole time" and this does not imply that the keyboard needs to be
> checked at all if the time has expired before it would have been worth
> checking the keyboard.  But since pending keyboard is supposed to
> inhibit redisplay for (sit-for 0), we can't avoid checking it anyway,
> right?
>
> And supposedly the return value of t from sit-for should at least
> imply that a redisplay has occured and completed.

I agree that (sit-for 0) should return nil if input is pending on entry.

Can you try the following version of sit-for?

[It assumes that `redisplay' returns t if display completed, nil if
there is pending input.  The code does that, but the doc string
doesn't say so explicitly...  so its doc string should be fixed.]


(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.
\(On operating systems that do not support waiting for fractions of a
second, floating-point values are rounded down to the nearest integer.)

If optional arg NODISP is t, don't redisplay, just wait for input.
Redisplay 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.

An obsolete, but still supported form is
\(sit-for SECONDS &optional MILLISECONDS NODISP)
where the optional arg MILLISECONDS specifies an additional wait period,
in milliseconds; this was useful when Emacs was built without
floating point support.

\(fn SECONDS &optional NODISP)"
  (when (or obsolete (numberp nodisp))
    (setq seconds (+ seconds (* 1e-3 nodisp)))
    (setq nodisp obsolete))
  (cond
   (noninteractive
    (sleep-for seconds)
    t)
   ((input-pending-p)
    nil)
   ((<= seconds 0)
    (or nodisp (redisplay)))
   (t
    (or nodisp (redisplay))
    (let ((read (read-event nil nil seconds)))
      (or (null read)
          (progn (push read unread-command-events) nil))))))


Patch:

*** subr.el     29 Jul 2006 00:53:10 +0200      1.523
--- subr.el     07 Sep 2006 16:22:40 +0200      
***************
*** 1733,1745 ****
    (when (or obsolete (numberp nodisp))
      (setq seconds (+ seconds (* 1e-3 nodisp)))
      (setq nodisp obsolete))
!   (if noninteractive
!       (progn (sleep-for seconds) t)
!     (unless nodisp (redisplay))
!     (or (<= seconds 0)
!       (let ((read (read-event nil nil seconds)))
!         (or (null read)
!             (progn (push read unread-command-events) nil))))))
  
  ;;; Atomic change groups.
  
--- 1733,1751 ----
    (when (or obsolete (numberp nodisp))
      (setq seconds (+ seconds (* 1e-3 nodisp)))
      (setq nodisp obsolete))
!   (cond
!    (noninteractive
!     (sleep-for seconds)
!     t)
!    ((input-pending-p)
!     nil)
!    ((<= seconds 0)
!     (or nodisp (redisplay)))
!    (t
!     (or nodisp (redisplay))
!     (let ((read (read-event nil nil seconds)))
!       (or (null read)
!         (progn (push read unread-command-events) nil))))))
  
  ;;; Atomic change groups.
  

-- 
Kim F. Storm <address@hidden> http://www.cua.dk





reply via email to

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