unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Richard Stallman <rms@gnu.org>
Cc: klaus.berndl@sdm.de, emacs-devel@gnu.org, storm@cua.dk
Subject: Re: while-no-input
Date: Tue, 30 Nov 2004 02:03:08 -0500	[thread overview]
Message-ID: <E1CZ22W-0003pW-Li@fencepost.gnu.org> (raw)
In-Reply-To: <jwvact07ndl.fsf-monnier+emacs@gnu.org> (message from Stefan Monnier on Mon, 29 Nov 2004 09:20:17 -0500)

    > 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

  reply	other threads:[~2004-11-30  7:03 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-26  9:26 AW: vc-state always calls heuristic function klaus.berndl
2004-11-26 11:44 ` Kim F. Storm
2004-11-27 18:51   ` while-no-input Richard Stallman
2004-11-27 23:03     ` while-no-input Kim F. Storm
2004-11-29  6:11       ` while-no-input Richard Stallman
2004-11-29 14:20         ` while-no-input Stefan Monnier
2004-11-30  7:03           ` Richard Stallman [this message]
2004-11-30 14:56             ` while-no-input Kim F. Storm
  -- strict thread matches above, loose matches on Subject: below --
2004-11-29 15:02 while-no-input klaus.berndl
2004-11-29 14:30 while-no-input klaus.berndl
2004-11-29 14:55 ` while-no-input Stefan Monnier
2002-10-01 21:19 while-no-input Stefan Monnier
2002-10-02 19:24 ` while-no-input Richard Stallman
2002-10-02 21:43   ` while-no-input Stefan Monnier
2002-10-03 13:28     ` while-no-input Richard Stallman
2002-10-03 15:53       ` while-no-input Stefan Monnier
2002-10-03 22:44         ` while-no-input Kim F. Storm
2002-10-03 22:33           ` while-no-input Stefan Monnier
2002-10-04 15:46         ` while-no-input Richard Stallman
2002-10-04 15:59           ` while-no-input Stefan Monnier
2002-10-05 16:33             ` while-no-input Richard Stallman
2002-10-24  0:06             ` while-no-input Kim F. Storm
2002-10-24  7:20               ` while-no-input Stefan Monnier
2002-10-24 10:24                 ` while-no-input Kim F. Storm
2002-10-25  5:35                   ` while-no-input Richard Stallman
2002-10-25  9:19                     ` while-no-input Kim F. Storm
2002-10-26 20:15                       ` while-no-input Richard Stallman
2002-10-25 13:44                     ` while-no-input Stefan Monnier
2002-10-26 20:13                       ` while-no-input Richard Stallman
2002-10-29 19:45                         ` while-no-input Stefan Monnier
2002-10-31 17:25                           ` while-no-input Richard Stallman
2002-10-31 18:03                             ` while-no-input Stefan Monnier
2002-11-02  3:32                               ` while-no-input Richard Stallman
2002-10-05 22:43       ` while-no-input 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=E1CZ22W-0003pW-Li@fencepost.gnu.org \
    --to=rms@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=klaus.berndl@sdm.de \
    --cc=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).