2

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

2

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
      end
      ;; only search when necessary:
      (completion-table-dynamic
       (lambda (_)
         ;; Interruptible candidate computation
         (let ((result
                (while-no-input
                  (your-fetch-candidates-function start end))))
           (and (consp result) result))))
      :exclusive 'no
      :annotation-function
      (lambda (candidate)
        (concat " "
                (your-annotation-function candidate))))

Your Answer

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

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