emacs-devel
[Top][All Lists]
Advanced

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

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


From: Kim F. Storm
Subject: Re: Broken sit-for [was: Re: Minor fix for life.el.]
Date: Sun, 10 Sep 2006 01:02:26 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

address@hidden (Kim F. Storm) writes:

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

Are there any objections to installing the version of sit-for below:


(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]