(defvar foo-timer nil) (defun foo-pre-command () (when foo-timer (cancel-timer foo-timer) (setq foo-timer nil))) (defun foo-post-command () (run-with-timer 0.01 nil #'foo-idle)) (defun foo-idle () (sit-for 5)) (add-hook 'pre-command-hook 'foo-pre-command) (add-hook 'post-command-hook 'foo-post-command) (flyspell-mode) ;; This causes unread-command-events to sometimes contain ;; e.g. ((t t . 45)) mmmmmm