in my library, i have completion backends that i add to completion-at-point-functions as per the docs, but my completion candidates are fetched from a server with an http request. the call is very slow, and i would like to make it asynchronous. ideally completion wouldn't interrupt user input at all.

from what i can see, completion-at-point-functions can't seem to handle an async response, say with aio.el and writing callbacks, for example with url-retrieve won't work with it either.

is there any way the two features can be made to play with each other nicely?

1 Answer 1


looks like using while-no-input is the simplest way to go. i received advice from capf guru extraordinaire minad to this effect:

(list start
      ;; only search when necessary:
       (lambda (_)
         ;; Interruptible candidate computation
         (let ((result
                  (your-fetch-candidates-function start end))))
           (and (consp result) result))))
      :exclusive 'no
      (lambda (candidate)
        (concat " "
                (your-annotation-function candidate))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.