From 45dee1156393ab2ea52eff206f942eac5cd9cce1 Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Wed, 9 Feb 2022 17:22:44 +0100 Subject: Experiment with a different synchronization method (See #25) --- cape.el | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/cape.el b/cape.el index 5fcaafa..d000bd5 100644 --- a/cape.el +++ b/cape.el @@ -879,23 +879,17 @@ If INTERACTIVE is nil the function acts like a capf." (if toi (unwind-protect (progn - (funcall fetch (lambda (arg) - (when (eq res 'cape--waiting) - (push 'cape--done unread-command-events)) - (setq res arg))) - ;; Force synchronization, interruptible! - (while (eq res 'cape--waiting) - ;; When we've got input, interrupt the computation. - (when unread-command-events (throw toi nil)) - (sit-for 0.1 'noredisplay))) - ;; Remove cape--done introduced by future callback. - ;; NOTE: `sit-for' converts cape--done to (t . cape--done). - ;; It seems that `sit-for' does not use a robust method to - ;; reinject inputs, maybe the implementation will change in - ;; the future. - (setq unread-command-events (delq 'cape--done - (delete '(t . cape--done) - unread-command-events)))) + (funcall fetch + (lambda (arg) + (when (eq res 'cape--waiting) + (push 'cape--done unread-command-events)) + (setq res arg))) + (let ((input-method-function nil)) + (read-event nil t)) + (when (eq res 'cape--waiting) + (throw toi nil))) + (setq unread-command-events + (delq 'cape--done unread-command-events))) (funcall fetch (lambda (arg) (setq res arg))) ;; Force synchronization, not interruptible! We use polling ;; here and ignore pending input since we don't use -- cgit v1.0