[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Questions about throw-on-input

From: Eli Zaretskii
Subject: Re: Questions about throw-on-input
Date: Thu, 07 May 2020 15:36:51 +0300

> From: Ivan Yonchovski <address@hidden>
> 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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]