From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Richard Stallman Newsgroups: gmane.emacs.devel Subject: Re: while-no-input Date: Tue, 30 Nov 2004 02:03:08 -0500 Message-ID: References: <1B3ACCFD5694A94DBA4E231402B0E9ED9DD6C2@mucmail1.sdm.de> Reply-To: rms@gnu.org NNTP-Posting-Host: deer.gmane.org X-Trace: sea.gmane.org 1101798473 9330 80.91.229.6 (30 Nov 2004 07:07:53 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 30 Nov 2004 07:07:53 +0000 (UTC) Cc: klaus.berndl@sdm.de, emacs-devel@gnu.org, storm@cua.dk Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Nov 30 08:07:48 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1CZ272-0001Ez-00 for ; Tue, 30 Nov 2004 08:07:48 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CZ2GT-0002M0-88 for ged-emacs-devel@m.gmane.org; Tue, 30 Nov 2004 02:17:33 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1CZ2FW-0001dS-HB for emacs-devel@gnu.org; Tue, 30 Nov 2004 02:16:34 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1CZ2FV-0001d1-EJ for emacs-devel@gnu.org; Tue, 30 Nov 2004 02:16:34 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CZ2FV-0001cM-3U for emacs-devel@gnu.org; Tue, 30 Nov 2004 02:16:33 -0500 Original-Received: from [199.232.76.164] (helo=fencepost.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.34) id 1CZ254-0001BK-4E for emacs-devel@gnu.org; Tue, 30 Nov 2004 02:05:46 -0500 Original-Received: from rms by fencepost.gnu.org with local (Exim 4.34) id 1CZ22W-0003pW-Li; Tue, 30 Nov 2004 02:03:08 -0500 Original-To: Stefan Monnier In-reply-to: (message from Stefan Monnier on Mon, 29 Nov 2004 09:20:17 -0500) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:30518 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:30518 > The only thing programs do to control quitting is to bind inhibit-quit > on and off. That is not relevant to handling with-no-input, so I think Could you substantiate that claim? AFAIK inhibit-quit is used to get more-or-less-atomic behavior in places where it matters. while-no-input should very clearly obey inhibit-quit I am not sure about that point, but the issue at hand is how to do the nonlocal exit. If while-no-input's implementation looks at inhibit-quit, that is orthogonal to how do to the nonlocal exit. So let me make my statement more precise: The only thing programs do to control quitting is to bind inhibit-quit on and off. Since inhibit-quit has no effect on what either Fsignal or Fthrow does when it is called, using Fthrow instead of Fsignal is entirely orthogonal to anything user programs do to control quitting. Here is another way to say the ame thing: of all the non-local exits we have right now, `quit' is the only one that's asynchronous. The setting of Vquit_flag is asynchronous, but I don't see that that relates to the issue. Quitting itself can be done asynchronously in a few primitives, but usually it occurs synchronously in a place that checks for it and does QUIT. The operational difference between signal and throw is that the former is caught by `condition-case' while the latter is caught by `catch'. So the way to decide the issue is based on whether `condition-case' ought to catch this. If the definition of with-no-input is that it alone catches this, then it has to use `catch'. So here's my simpler proposal for how to implement this. (defmacro while-no-input (&rest body) "Execute BODY only as long as there's no pending input. If input arrives, that ends the execution of BODY." (declare (debug t) (indent 0)) (let ((catch-sym (make-symbol "input"))) `(with-local-quit (catch ',catch-sym (let ((throw-on-input ',catch-sym)) (when (sit-for 0 0 t) ,@body)))))) #define QUIT \ do { \ if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) \ { \ Lisp_Object flag = Vquit_flag; \ Vquit_flag = Qnil; \ if (EQ (Vthrow_on_input, flag)) \ Fthrow (Vthrow_on_input, Qnil); \ Fsignal (Qquit, Qnil); \ } \ else if (interrupt_input_pending) \ handle_async_input (); \ } while (0) Index: keyboard.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/keyboard.c,v retrieving revision 1.708 diff -u -u -b -r1.708 keyboard.c --- keyboard.c 27 Sep 2002 17:03:46 -0000 1.708 +++ keyboard.c 1 Oct 2002 21:15:14 -0000 @@ -3374,6 +3402,9 @@ } #endif + +Lisp_Object Vthrow_on_input; + /* Store an event obtained at interrupt level into kbd_buffer, fifo */ void @@ -3501,6 +3538,14 @@ ASET (kbd_buffer_gcpro, idx + 1, event->arg); ++kbd_store_ptr; } + + /* If we're in a section that requested to be interrupted as soon + as input comes, then set quit-flag to cause an interrupt. */ + if (!NILP (Vthrow_on_input) + && event->kind != FOCUS_IN_EVENT + && event->kind != HELP_EVENT + && event->kind != DEICONIFY_EVENT) + Vquit_flag = Vthrow_on_input; } @@ -11038,6 +11029,12 @@ doc: /* *How long to display an echo-area message when the minibuffer is active. If the value is not a number, such messages don't time out. */); Vminibuffer_message_timeout = make_number (2); + + DEFVAR_LISP ("throw-on-input", &Vthrow_on_input, + doc: /* If non-nil, any keyboard input throws to this symbol. +The value of that variable is passed to `quit-flag' and later causes a +peculiar kind of quitting. */); + Vthrow_on_input = Qnil; } void