From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Spencer Baugh Newsgroups: gmane.emacs.devel Subject: Re: unwind-protect within while-no-input Date: Wed, 08 May 2024 11:14:05 -0400 Organization: Jane Street Capital Message-ID: References: <86msp1a24a.fsf@gnu.org> <86jzk4a5ck.fsf@gnu.org> <8634qs9yl0.fsf@gnu.org> <861q6c9wdj.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13769"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: emacs-devel@gnu.org Cancel-Lock: sha1:aO2nJ0y+mz9tJ6IQvIixsdloDs8= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed May 08 20:22:19 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 1s4lvn-0003W1-KY for ged-emacs-devel@m.gmane-mx.org; Wed, 08 May 2024 20:22:19 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4lv3-0002fB-Nw; Wed, 08 May 2024 14:21:33 -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 1s4izv-0008Q4-69 for emacs-devel@gnu.org; Wed, 08 May 2024 11:14:23 -0400 Original-Received: from ciao.gmane.io ([116.202.254.214]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4izs-0001L1-G5 for emacs-devel@gnu.org; Wed, 08 May 2024 11:14:22 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1s4izl-0006F3-Sj for emacs-devel@gnu.org; Wed, 08 May 2024 17:14:13 +0200 X-Injected-Via-Gmane: http://gmane.org/ Received-SPF: pass client-ip=116.202.254.214; envelope-from=ged-emacs-devel@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Wed, 08 May 2024 14:21:31 -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:319021 Archived-At: Eli Zaretskii writes: >> From: Spencer Baugh >> Date: Wed, 08 May 2024 10:38:11 -0400 >> >> Eli Zaretskii writes: >> >> >> Your code does not run the unwind forms when run inside a >> >> while-no-input. >> > >> > Why should it? When while-no-input is interrupted by input, it >> > conceptually is not "quitting"; the fact that it uses quit-flag is an >> > internal implementation detail. >> >> Because there might be something I want to clean up. >> >> For example, my code might create a process or temporary directory which >> should be deleted even if interrupted by input. >> >> > If you want the unwind forms to run when while-no-input is interrupted >> > by input, simply do it: while-no-input provides a clear documented >> > indication that it was interrupted by input, and you can use that to >> > decide whether to run the unwind forms in that case. >> >> What concretely are you suggesting? Could you give an example in code? > > I cannot give a concrete example, because even now you describe more > and more details of your code that you haven't disclosed previously. > So any code I will show will most probably not work for you because of > those undisclosed details. > > I can only say what I mean generally: the unwind forms are just code, > so when you detect that while-no-input was interrupted by some input, > simply call those unwind forms "by hand". What exactly that means and > how exactly to do that is something the depends on those details and > on what exactly your unwind forms need to do. > >> Note that my code doesn't require while-no-input or always run inside >> while-no-input - it's just that whenever my code happens to be inside a >> while-no-input, my code should still do the cleanup. > > As I said, while-no-input provides an indication whether it was > interrupted, so you can easily do whatever you need to do in that > case. If I have a function: (defun my-function () ...do something...) which might be invoked by some other package that I don't control like this: (defun some-other-package () (while-no-input ... (my-function) ...)) How does my-function run the unwind-forms when it is interrupted by while-no-input?