From b3e2850fcfe63d06f8e00ba985d964a4ba6e3935 Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Sun, 28 Nov 2021 23:38:02 +0100 Subject: Add unwind-protect --- cape.el | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/cape.el b/cape.el index 6251e11..d653593 100644 --- a/cape.el +++ b/cape.el @@ -744,20 +744,22 @@ If INTERACTIVE is nil the function acts like a capf." (`(:async . ,future) (let ((res 'cape--waiting) (start (time-to-seconds))) - (funcall future (lambda (arg) - (when (eq res 'cape--waiting) - (push 'cape--event unread-command-events)) - (setq res arg))) - ;; Force synchronization. - (while (eq res 'cape--waiting) - ;; When we've got input, interrupt the computation. - (when (and unread-command-events toi) - (throw toi nil)) - (when (> (- (time-to-seconds) start) cape-company-timeout) - (error "Cape company backend async timeout")) - (sit-for 0.1 'noredisplay)) - ;; Remove cape--events introduced by future callback - (setq unread-command-events (delq 'cape--event unread-command-events)) + (unwind-protect + (progn + (funcall future (lambda (arg) + (when (eq res 'cape--waiting) + (push 'cape--event unread-command-events)) + (setq res arg))) + ;; Force synchronization. + (while (eq res 'cape--waiting) + ;; When we've got input, interrupt the computation. + (when (and unread-command-events toi) + (throw toi nil)) + (when (> (- (time-to-seconds) start) cape-company-timeout) + (error "Cape company backend async timeout")) + (sit-for 0.1 'noredisplay))) + ;; Remove cape--events introduced by future callback + (setq unread-command-events (delq 'cape--event unread-command-events))) res)) (res res)))) -- cgit v1.0