From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: unwind-protect within while-no-input Date: Wed, 08 May 2024 14:52:11 +0300 Message-ID: <86jzk4a5ck.fsf@gnu.org> References: <86msp1a24a.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11312"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Spencer Baugh Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed May 08 13:52:41 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1s4fqi-0002lz-IH for ged-emacs-devel@m.gmane-mx.org; Wed, 08 May 2024 13:52:40 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4fqM-00007r-0u; Wed, 08 May 2024 07:52:18 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4fqI-0008Q8-HI for emacs-devel@gnu.org; Wed, 08 May 2024 07:52:15 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4fqH-0007EB-QJ; Wed, 08 May 2024 07:52:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=nouTNTeg7MbSGH2UHPrfVdt5bUwE/trpZUwyOV7zcrU=; b=Y8EuO+Kx3x21H8SKGtan sn4A2FsIaCJyKKx+DEEBo0p4wC4Yd2nINNq/nCm0IzFEV0NWJJNAG1D6e5XYVmSrDgU6jqWjiaHKD hkp7jJMcR8yqVU4+3VdAdL4WWSscUAMYcGMPDJvUzgy9layWCOm/6Z3wjuzRhY5/SAl0IOS0VEzM5 uxchEUanvyGstUqUecn1mi1s2+S9GCcE1L2360LLYHMT1jEDsLB12Xb5FV2f4WKOtJo4g+TXePr6h Y0F+rqFVTCFLIHnqqEnnJrzDfWugKpxAR/lEF2fkMmGM8BgXxQXHhmo1wYsD+PH0Qq6R4PQGIjRgQ Yo6NoEFzEV9bug==; In-Reply-To: (message from Spencer Baugh on Tue, 07 May 2024 15:43:43 -0400) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:318998 Archived-At: > From: Spencer Baugh > Date: Tue, 07 May 2024 15:43:43 -0400 > > Eli Zaretskii writes: > >> 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 think you can use condition-case for that: > > > > (setq foo > > (condition-case nil > > (while t nil) > > (quit 'interrupted))) C-M-x C-g > > => interrupted > > That doesn't work with while-no-input: The message to which I responded said nothing about while-no-input, it made a much more general and broad assertion, see above. But if while-no-input must be in the picture, then you just need to do it the other way around: (progn (setq foo (condition-case nil (let ((i 0)) (while-no-input (while (< i 100000000) (setq i (1+ i))) i)) (quit 'interrupted))) foo) This produces: * The last i value in the loop if run uninterrupted * ‘interrupted’ if interrupted by C-g (QUIT) * t if interrupted by input