all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier via "Emacs development discussions." <emacs-devel@gnu.org>
To: emacs-devel@gnu.org
Subject: Re: unwind-protect within while-no-input
Date: Sat, 25 May 2024 22:47:07 -0400	[thread overview]
Message-ID: <jwvttil9uai.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: ier8r0lsdj1.fsf@janestreet.com

> It seems like it's impossible right now to use unwind-protect robustly
> in face of quits, because a quit triggered in the body forms of the
> unwind-protect will also interrupt the unwind forms.

I believe that is indeed the case.  🙁

> And there is no way to work around this, because binding inhibit-quit
> in the unwind forms can *also* be interrupted.

Yup.  I have seen such problems when I hit `C-g` frantically to get out
of some problematic state, and some of the repetitions end up happening
while we're running the unwind forms.

> Maybe there should be a version of unwind-protect which automatically
> and atomically inhibits quit in the unwind forms?

I tend to agree.  I even considered that this should apply to all unwind
forms, tho I suspect it would be too drastic, making it impossible to
escape problems where the unwind form itself is stuck in an inf-loop.
At the very least things like `C-g` should not be able to interrupt the
unwinding of things like dynamically scoped let-bindings or
`save-excursion`.

Is there a bug-report associated to this thread?

Maybe a "cheaper" answer for your specific problem is to make sure
that once `while-no-input` has started a non-local exit (which it does
with `throw`, IIRC), we mark "this while-no-input" as being done
so it won't cause a nested exit while we process the unwind form of the
original exit.

E.g. with a patch like the one below?  Would it fix your case?


        Stefan


diff --git a/src/keyboard.c b/src/keyboard.c
index 3551a77a9c9..c2c326f434c 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -3801,7 +3816,10 @@ kbd_buffer_store_buffered_event (union buffered_input_event *event,
      as input, set quit-flag to cause an interrupt.  */
   if (!NILP (Vthrow_on_input)
       && !is_ignored_event (event))
-    Vquit_flag = Vthrow_on_input;
+    {
+      Vquit_flag = Vthrow_on_input;
+      Vthrow_on_input = !nil;
+    }
 }
 
 /* Limit help event positions to this range, to avoid overflow problems.  */




  parent reply	other threads:[~2024-05-26  2:47 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-03 12:45 unwind-protect within while-no-input Spencer Baugh
2024-05-07 18:05 ` Spencer Baugh
2024-05-07 18:49   ` Eli Zaretskii
2024-05-07 19:43     ` Spencer Baugh
2024-05-08  3:59       ` Po Lu
2024-05-08 11:42         ` Michael Heerdegen via Emacs development discussions.
2024-05-08 11:47           ` Michael Heerdegen via Emacs development discussions.
2024-05-08 13:44             ` Spencer Baugh
2024-05-08 16:13               ` Michael Heerdegen via Emacs development discussions.
2024-05-08 17:18                 ` Spencer Baugh
2024-05-08 20:43                   ` Michael Heerdegen via Emacs development discussions.
2024-05-09 12:57                     ` Spencer Baugh
2024-05-09 14:13                       ` Michael Heerdegen via Emacs development discussions.
2024-05-08 12:12           ` Eli Zaretskii
2024-05-08 12:36             ` Michael Heerdegen via Emacs development discussions.
2024-05-08 11:52       ` Eli Zaretskii
2024-05-08 13:57         ` Spencer Baugh
2024-05-08 14:18           ` Eli Zaretskii
2024-05-08 14:38             ` Spencer Baugh
2024-05-08 15:06               ` Eli Zaretskii
2024-05-08 15:14                 ` Spencer Baugh
2024-05-08 18:51                   ` Eli Zaretskii
2024-05-08 19:28                     ` Spencer Baugh
2024-05-09  5:46                       ` Eli Zaretskii
2024-05-09 13:07                         ` Spencer Baugh
2024-05-09 17:41                           ` Dmitry Gutov
2024-05-11  9:48                           ` Eli Zaretskii
2024-05-11 10:37                             ` Eshel Yaron
2024-05-11 10:42                           ` Zhengyi Fu
2024-05-11 21:45                             ` Dmitry Gutov
2024-05-11 22:08                               ` Daniel Mendler via Emacs development discussions.
2024-05-12  1:59                                 ` Dmitry Gutov
2024-05-12  8:50                                   ` Daniel Mendler via Emacs development discussions.
2024-05-12 11:49                                     ` Dmitry Gutov
2024-05-14 21:30                           ` Dmitry Gutov
2024-05-26  2:49                             ` Stefan Monnier via Emacs development discussions.
2024-05-26 15:36                               ` Dmitry Gutov
2024-05-26 18:00                                 ` Stefan Monnier
2024-05-26 22:56                                   ` Dmitry Gutov
2024-05-29  0:39                                     ` Stefan Monnier
2024-05-29  1:17                                       ` Dmitry Gutov
2024-05-08 20:34                     ` Michael Heerdegen via Emacs development discussions.
2024-05-08 16:17               ` Michael Heerdegen via Emacs development discussions.
2024-05-26  2:47   ` Stefan Monnier via Emacs development discussions. [this message]
2024-05-26  4:36     ` Stefan Monnier
2024-05-26  4:55     ` Eli Zaretskii
2024-05-26 18:12       ` Stefan Monnier

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

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

  git send-email \
    --in-reply-to=jwvttil9uai.fsf-monnier+emacs@gnu.org \
    --to=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.