From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Questions about throw-on-input Date: Thu, 07 May 2020 15:36:51 +0300 Message-ID: <831rnvly58.fsf@gnu.org> References: <87r1vwxktw.fsf@gmail.com> Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="122391"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Ivan Yonchovski Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu May 07 14:37:45 2020 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 1jWfmb-000VkL-CT for ged-emacs-devel@m.gmane-mx.org; Thu, 07 May 2020 14:37:45 +0200 Original-Received: from localhost ([::1]:33794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jWfma-00081n-Ef for ged-emacs-devel@m.gmane-mx.org; Thu, 07 May 2020 08:37:44 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46804) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWflz-0007Yp-Jl for emacs-devel@gnu.org; Thu, 07 May 2020 08:37:07 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:49471) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jWflz-0008CB-AA; Thu, 07 May 2020 08:37:07 -0400 Original-Received: from [176.228.60.248] (port=2200 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1jWfly-0007aG-HX; Thu, 07 May 2020 08:37:07 -0400 In-Reply-To: <87r1vwxktw.fsf@gmail.com> (message from Ivan Yonchovski on Thu, 07 May 2020 10:31:23 +0300) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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" Xref: news.gmane.io gmane.emacs.devel:249167 Archived-At: > From: Ivan Yonchovski > Date: Thu, 07 May 2020 10:31:23 +0300 > > > 1. In the following example: > > (dotimes (_ 10) > (message "Length %s" > (length > (let (result) > (catch t > (let ((throw-on-input t)) > (dotimes (counter 10000000) > (push (number-to-string counter) result)))) > result)))) > > .. after I execute the following block each of the 10 computations will be > canceled after pressing C-n for example, how do I force the handling of > the command to be processed? I tried redisplay but it does not help. Invoking redisplay won't help because the commands which interrupted the inner loop (C-n) were not yet executed. Emacs will process them only after the outer loop ends, because that outer loop is the last command, and it is still being executed. Emacs doesn't perform commands in the middle of another command. > (message "Length %s" > (length > (let (result) > (catch t > (let ((throw-on-input t)) > (dotimes (counter 10000000) > (push (number-to-string counter) result)))) > result))) > > > (run-with-idle-timer > 0.0 > nil > (lambda () > (message "Length %s" > (length > (let (result) > (catch t > (let ((throw-on-input t)) > (dotimes (counter 10000000) > (push (number-to-string counter) result)))) > result))))) > > The issue is with the second block, it seems like throw-on-input is > disregarded when used in run-with-idle-timer. Can anyone confirm if this > is a bug/desired behavior or I should use something else if I want to > run cancelable tasks in on-idle? When the time function is run, Emacs binds inhibit-quit to t (so that the user's C-g would not interrupt the timer function, for example). And throw-on-input uses quitting to do its job. Why do you need to interrupt an idle timer like that? The usual way of doing this is not to call expensive functions in an idle timer, and if you have a lot of processing, divide them into small enough chunks and do it piecemeal. That's what jit-stealth font-lock does, for example.