(defun pretend (keys)
(dolist (e (reverse (listify-key-sequence (kbd keys))))
(push e unread-command-events)
;; (mystery-function)
(redisplay t)
(sleep-for 0.1)))
(pretend "M-x my-function-")
This function is intended to take key events and 'pretend' they were entered by the user at a reasonable pace of 100ms/key. Unfortunately, it doesn't seem like unread-command-events
is being processed – probably because emacs is not idle during execution. One way to get around this is to abuse run-with-idle-timer
, but this seems like the wrong approach.
How can I process/flush unread-command-events
before continuing execution?
(I suspect I won't need the call to reverse
after this is fixed.)