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 07:36:42 +0300 Message-ID: References: <87r1vwxktw.fsf@gmail.com> <831rnvly58.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000eb45b805a51b8b11" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="77575"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , emacs-devel To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri May 08 06:37:51 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 1jWuli-000K5Y-Ib for ged-emacs-devel@m.gmane-mx.org; Fri, 08 May 2020 06:37:50 +0200 Original-Received: from localhost ([::1]:50210 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jWulh-0007rY-Jj for ged-emacs-devel@m.gmane-mx.org; Fri, 08 May 2020 00:37:49 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47272) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWuks-0007CY-At for emacs-devel@gnu.org; Fri, 08 May 2020 00:36:58 -0400 Original-Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]:36128) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jWukq-00054X-Jt; Fri, 08 May 2020 00:36:58 -0400 Original-Received: by mail-lf1-x131.google.com with SMTP id t2so368993lfc.3; Thu, 07 May 2020 21:36:55 -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=aw67R6s+7s7AlDIJFpBftJmQW+XJFyxcuLirlFzd5A8=; b=Km/gr1b9eSA6ohDqset4il/VytjpN/b39/DZ4eQ8WRAc1qLlbACZBB7aatmrEsq0g4 oG0THtQrlIFVeLy6IRAvom91WA64oqEs3iiX9mx2JME7qqVXHd3mE2SIyigOhOHv7kBe OWQCU3UKRZ2J3O4L0IBofUVsU71PbbuqTv9udagthw+Jj9HPq4jR8V6ggPRPuGaxUFJ3 uYasuK73EybDuLEcwoIKDrE0DqdNw/7u2/5T7ANudJ3wGHBShe5+gBOumYSBMLgslB6C MVUoq94xgeUdEboPsnMxj2Xzo1RpMLcNhCS5MC+2iIlR8d1WI7u/DouqNetQ9aJuOffO fLMg== 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=aw67R6s+7s7AlDIJFpBftJmQW+XJFyxcuLirlFzd5A8=; b=pA8xEz0ol3HZQrfeh+GfI8x/dMHPVdxs/Y/hKLjDxUTNY3Ta0MIg7KjKOhLcbAoLr9 WyeCZbcEkIfugC58c0Os2j+yxD4LkijKjNdGC64LR6vwAPMHUgARms7OxTJ+j4A2Wawr h83D4PTBf9mEB4lh3/Je0AS6FBct2EOHajo+aTqBnwRtzwd/eFdj24N223eu2BGeV3DD urbHPCayenbsmjG6fi9j7Iolt3hmH/IUhUQNejw7yoQ0oQpVoYQB4ZePDtm1PUXrvkUD sPRs5+dBHrRfreUOO6Wu31O4Td/edKOfx0ZbwzxpesCdRtxoJ6Zvmg3Nnjr7ywKCz3pj VrDg== X-Gm-Message-State: AOAM530VTLVGw6Jomja0X7fFbhbS47Ok7YArjsVBd0BOur37DDEcK1d7 15YX9oaCqdYo58N59wnwSV+zzUSaqKkNYdTJezI= X-Google-Smtp-Source: ABdhPJwnydF2SqBxOwCKRX2ErgXg/sETXPjekf8KcFv5ForAG4SIw0r1DF9imcATmd0u0Ghjd5NSOQxAUS6lHLK76vM= X-Received: by 2002:a05:6512:3136:: with SMTP id p22mr543254lfd.159.1588912613703; Thu, 07 May 2020 21:36:53 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::131; envelope-from=yyoncho@gmail.com; helo=mail-lf1-x131.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:249242 Archived-At: --000000000000eb45b805a51b8b11 Content-Type: text/plain; charset="UTF-8" Hi Stefan, Thank you for your reply! Can you elaborate on "won't have the desired semantics"? I would suggest something crazier - using inhibit-quit to Thanks, Ivan On Fri, May 8, 2020 at 4:59 AM Stefan Monnier wrote: > > 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? > > It can be implemented, but it won't have the desired semantics. > If you want something robust you have 2 options: > > - write in an event-driven style (or CPS style) so that you can easily > stop at various points in the program and stash the rest of the > computation for later. > > - use a thread (which will basically do the same, but transparently, > i.e. without the awkward programming style.) > > > Stefan > > > > 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. > >> > > --000000000000eb45b805a51b8b11 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Stefan,

Thank you for your reply! Ca= n you elaborate on "won't have the desired semantics"? I woul= d=C2=A0suggest something crazier=C2=A0- using inhibit-quit to=C2=A0

Thanks,
Ivan

On Fri, May 8, 2020 at 4:59 A= M Stefan Monnier <monnier@ir= o.umontreal.ca> wrote:
> 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?

It can be implemented, but it won't have the desired semantics.
If you want something robust you have 2 options:

- write in an event-driven style (or CPS style) so that you can easily
=C2=A0 stop at various points in the program and stash the rest of the
=C2=A0 computation for later.

- use a thread (which will basically do the same, but transparently,
=C2=A0 i.e. without the awkward programming style.)


=C2=A0 =C2=A0 =C2=A0 =C2=A0 Stefan


> AFAIK a lot of gui toolkits have that kind of function, e. g.
> https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.a= pplication.doevents?view=3Dnetcore-3.1
>
> IMO it will be very useful for certain cases.
>
> Thanks,
> Ivan
>
> On Thu, May 7, 2020 at 3:37 PM Eli Zaretskii <eliz@gnu.org> wrote:
>
>> > From: Ivan Yonchovski <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)<= br> >> >=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 ((throw-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=A0result)= )))
>> >
>> > .. after I execute the following block each of the 10 computa= tions will
>> be
>> > canceled after pressing C-n for example, how do I force the h= andling of
>> > the command to be processed? I tried redisplay but it does no= t help.
>>
>> Invoking redisplay won't help because the commands which inter= rupted
>> the inner loop (C-n) were not yet executed.=C2=A0 Emacs will proce= ss them
>> only after the outer loop ends, because that outer loop is the las= t
>> command, and it is still being executed.=C2=A0 Emacs doesn't p= erform
>> 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(push (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 ((throw-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-in= put is
>> > disregarded when used in run-with-idle-timer. Can anyone conf= irm 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 t= hat
>> the user's C-g would not interrupt the timer function, for exa= mple).
>> And throw-on-input uses quitting to do its job.
>>
>> Why do you need to interrupt an idle timer like that?=C2=A0 The us= ual 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 chu= nks
>> and do it piecemeal.=C2=A0 That's what jit-stealth font-lock d= oes, for
>> example.
>>

--000000000000eb45b805a51b8b11--