From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: yyoncho Newsgroups: gmane.emacs.devel Subject: Re: Questions about throw-on-input Date: Fri, 8 May 2020 00:11:26 +0300 Message-ID: References: <87r1vwxktw.fsf@gmail.com> <831rnvly58.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000008bf4ba05a51553b7" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="104139"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu May 07 23:12:23 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 1jWnod-000R17-Nr for ged-emacs-devel@m.gmane-mx.org; Thu, 07 May 2020 23:12:23 +0200 Original-Received: from localhost ([::1]:50934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jWnoc-0007FL-Pt for ged-emacs-devel@m.gmane-mx.org; Thu, 07 May 2020 17:12:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54818) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWnny-0006iK-HY for emacs-devel@gnu.org; Thu, 07 May 2020 17:11:42 -0400 Original-Received: from mail-lf1-x132.google.com ([2a00:1450:4864:20::132]:34354) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jWnnx-0001To-9j; Thu, 07 May 2020 17:11:42 -0400 Original-Received: by mail-lf1-x132.google.com with SMTP id s9so5718474lfp.1; Thu, 07 May 2020 14:11:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ibC4p3fZD060sMxCXp3oVAxLMlRTbMcGxMljkbbsPJ0=; b=W0IL6G+FR9TI9dJidpy+QoNf1fG3KO6So1t3QWyh0OI6KAQDMi6gFY7G2huMZnsjJX kv/Knz4LtmCapGyCwpM6vj4+PA2IMFUHdtuztx3gse+izAGRNN9e79LaF0mUoPabKl3R djjwM1AYzOtfmeWZ8PMiH5WYkmz6cpEV7UlkA3+zLByTH+6mNeIGS9zittmOwulmngp6 OHA3BqJK90PplMrfW1upLKyOkep3Eq+GYOzOmn6UndGRckw6Ekh5Q3BrshPe7mv1HukJ W6/rvF8ev2FyoPyqw5ojuIjKRVRet7yKwEOklwNprJVQOdfxo/cFXHQDwle2ZctJV8Uu sXZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ibC4p3fZD060sMxCXp3oVAxLMlRTbMcGxMljkbbsPJ0=; b=oXaEhq8vNqcTP8mQ+XS2jR89OBvQjPt0IeNbS31oF1y3EfyWJJvN2fqQ9DHE68FOHC wgdMoQjjhJla/Sm70GwrusqglQntVcvUM3HloJYk7ULrNGryk4RBVEufXLNuUip+e//A vLTwJMxv1njr+KbLyjIkmkAKlJaMW4NIqTcwROioVJu0h0AcxqyEHpdAMv1ahzt3jMV3 7aEkL313aHMiV4ccLrXPqRk7c8Z4aw1LBoNe3RJQUmBjL7VxOGNqLGFxqLZh4XGDxJ2Q QV4mpEv+ngglqmo5H3CJUazkCLzg8GihlV3H/oN+hgTsaKaQkTN0PhPOjTQPH9yBRc6V tfOg== X-Gm-Message-State: AOAM533zZOyqvEXPtcGcJRrgZZkeLsiiJ1/EHdj3a4X5+NG4CUmvuhHf RjUotPajyPvF5F0A1y7+66Fq1X1PVi4neHBjnvu22OMdZTE= X-Google-Smtp-Source: ABdhPJxr6R28NLkirF3xlDD8T0BzUzZMvIVAwF/Aa8YPGFMoJqbKgG72cO2BaHh7aS/av1M/ReHyhMr4IDvrB7wgM64= X-Received: by 2002:a19:c6c5:: with SMTP id w188mr450322lff.65.1588885898129; Thu, 07 May 2020 14:11:38 -0700 (PDT) In-Reply-To: <831rnvly58.fsf@gnu.org> Received-SPF: pass client-ip=2a00:1450:4864:20::132; envelope-from=yyoncho@gmail.com; helo=mail-lf1-x132.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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:249223 Archived-At: --0000000000008bf4ba05a51553b7 Content-Type: text/plain; charset="UTF-8" Hi Eli, Out of curiosity, do you think that having a function (process-events) which will process all keyboard(?) events and resume the current invocation can be implemented easily? AFAIK a lot of gui toolkits have that kind of function, e. g. https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.application.doevents?view=netcore-3.1 IMO it will be very useful for certain cases. Thanks, Ivan On Thu, May 7, 2020 at 3:37 PM Eli Zaretskii wrote: > > 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. > --0000000000008bf4ba05a51553b7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Eli,

Out of=C2=A0curiosit= y, do you think that having a function=C2=A0
(process-events) whi= ch will process all keyboard(?) events
and resume=C2=A0the curren= t invocation=C2=A0can be implemented easily?=C2=A0
AFAIK a lot of= gui toolkits have that kind of function, e. g.=C2=A0
https://docs.microsoft.com/en-us/dotnet/api/= system.windows.forms.application.doevents?view=3Dnetcore-3.1=C2=A0
<= /div>
IMO it will be very useful=C2=A0for certain cases.

=
Thanks,
Ivan

On Thu, May 7, 2020 at 3:37 PM Eli Zaretsk= ii <eliz@gnu.org> wrote:
> From: Ivan Yonchovs= ki <yyoncho@gmail= .com>
> Date: Thu, 07 May 2020 10:31:23 +0300
>
>
> 1. In the following example:
>
> (dotimes (_ 10)
>=C2=A0 =C2=A0(message "Length %s"
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (length
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(let (result)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(catch t
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(let ((th= row-on-input t))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(d= otimes (counter 10000000)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0(push (number-to-string counter) result))))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0result))))
>
> .. after I execute the following block each of the 10 computations wil= l be
> canceled after pressing C-n for example, how do I force the handling o= f
> 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.=C2=A0 Emacs will process them only after the outer loop ends, because that outer loop is the last
command, and it is still being executed.=C2=A0 Emacs doesn't perform commands in the middle of another command.

> (message "Length %s"
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (length
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(let (result)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(catch t
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(let ((throw-on-= input t))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(dotimes = (counter 10000000)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(p= ush (number-to-string counter) result))))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0result)))
>
>
> (run-with-idle-timer
>=C2=A0 0.0
>=C2=A0 nil
>=C2=A0 (lambda ()
>=C2=A0 =C2=A0 (message "Length %s"
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(length
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (let (result)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (catch t
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (let ((t= hrow-on-input t))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (= dotimes (counter 10000000)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 (push (number-to-string counter) result))))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 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 th= is
> is a bug/desired behavior or I should use something else if I want to<= br> > 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?=C2=A0 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.=C2=A0 That's what jit-stealth font-lock does, for<= br> example.
--0000000000008bf4ba05a51553b7--