branch: externals/consult commit 65ba52d44218ccb09a7a2bdfc700eaa3a4506eca Author: Daniel Mendler <m...@daniel-mendler.de> Commit: Daniel Mendler <m...@daniel-mendler.de>
Improve consult--dynamic-compute interrupt handling --- consult.el | 46 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/consult.el b/consult.el index 1b01be2dbe..3fbfa36e8e 100644 --- a/consult.el +++ b/consult.el @@ -2382,34 +2382,26 @@ highlighting function." "Dynamic computation of candidates. ASYNC is the sink. FUN computes the candidates given the input." - (let (request current) + (let (current) (lambda (action) - (pcase action - ('nil - ;; Perform the computation when the candidates are requested, since - ;; then the computation can be interrupted by the completion UI. - (when request - (let ((state 'killed)) - (unwind-protect - (progn - (funcall async 'indicator 'running) - (redisplay) - ;; Run computation - (let ((response (funcall fun request))) - ;; Flush and update candidate list - (funcall async 'flush) - (funcall async response) - (setq state 'finished current request request nil))) - (funcall async 'indicator state)))) - (funcall async nil)) - ((pred stringp) - ;; Do not perform the computation immediately, only when the - ;; candidates are requested. - (if (equal action current) - (setq request nil) - (setq request action) - (funcall async 'refresh))) - (_ (funcall async action)))))) + (cond + ((stringp action) + (if (equal action current) + (funcall async 'indicator 'finished) + (let ((state 'killed)) + (unwind-protect + (while-no-input + (funcall async 'indicator 'running) + (redisplay) + ;; Run computation + (let ((response (funcall fun action))) + ;; Flush and update candidate list + (funcall async 'flush) + (funcall async response) + (funcall async 'refresh) + (setq state 'finished current action))) + (funcall async 'indicator state))))) + (t (funcall async action)))))) (defun consult--dynamic-collection (fun &optional debounce min-input) "Dynamic collection with input splitting.