emacs-devel
[Top][All Lists]
Advanced

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

Re: Questions about throw-on-input


From: Ivan Yonchovski
Subject: Re: Questions about throw-on-input
Date: Fri, 08 May 2020 14:23:34 +0300
User-agent: mu4e 1.3.7; emacs 27.0.91

Hi Eli,

> By "processing all keyboard events" do you mean invoking the commands
> those events are bound to?

Yes.

> If so, I don't think we have machinery to do that in Emacs: there's
> too much of global state that would get in the way.

Here it is overly simplistic code that is close to what I am trying to
achieve.

(defun process-events ()
  (when (input-pending-p)
    (run-with-timer 0.01 nil (lambda () (throw 'exit nil)))
    (recursive-edit)))

(dotimes (counter 1000)
  (sleep-for 0.01) ;; simulate execution of N tasks
  (message "%s" counter)
  (process-events))

This code is able to handle C-n but obviously it will break if someone
starts another recursive-edit or for complex keybindings, e. g. `C-x b`.
Are you aware of something doing something similar? Do you think it
makes sense if you want to process something slow on the background
without blocking emacs?

> AFAIU, such facilities need to have a separate event loop that
> generally runs in a separate thread.

In the C# case it all happens on the UI thread. DoEvents means handle
mouse clicks, repaint controls, etc(the stuff from the event loop) and
then continue with current execution.

Thanks,
Ivan



reply via email to

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