unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: storm@cua.dk (Kim F. Storm)
Subject: Re: Broken sit-for [was: Re: Minor fix for life.el.]
Date: Sun, 10 Sep 2006 01:02:26 +0200	[thread overview]
Message-ID: <m3venwlk3h.fsf@kfs-l.imdomain.dk> (raw)
In-Reply-To: <m3r6yniwev.fsf_-_@kfs-l.imdomain.dk> (Kim F. Storm's message of "Thu\, 07 Sep 2006 16\:27\:52 +0200")

storm@cua.dk (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))))))
  \f
  ;;; 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))))))
  \f
  ;;; Atomic change groups.
  

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

  parent reply	other threads:[~2006-09-09 23:02 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-06 17:05 Minor fix for life.el Michaël Cadilhac
2006-09-06 18:03 ` David Kastrup
2006-09-06 18:14   ` Michaël Cadilhac
2006-09-06 18:34     ` David Kastrup
2006-09-07 14:27       ` Broken sit-for [was: Re: Minor fix for life.el.] Kim F. Storm
2006-09-08  9:16         ` Broken sit-for Michaël Cadilhac
2006-09-09 23:02         ` Kim F. Storm [this message]
2006-09-10  0:28           ` David Kastrup
2006-09-10  9:18             ` Michaël Cadilhac
2006-09-10 21:26               ` Kim F. Storm
2006-09-11 14:22                 ` Michaël Cadilhac
2006-09-10 21:06             ` Kim F. Storm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3venwlk3h.fsf@kfs-l.imdomain.dk \
    --to=storm@cua.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).