11

From the docstring:

Execute BODY only as long as there's no pending input.
If input arrives, that ends the execution of BODY, and while-no-input returns t. Quitting makes it return nil. If BODY finishes, while-no-input returns whatever value BODY produced.

If I understand correctly, this macro allows me to (attempt to) perform a heavy computation without hanging the interface. That's certainly a concept that I find attractive, but I'm left wondering when is that useful in practice.

It seems that the computation can be interrupted at any moment, with no information on where that happened, and no easy way of resuming it later. Which makes me think it might not be that useful after all...

  • Is there a recommended way of using the while-no-input macro?
  • Are there any example usages of this macro in the wild?
10

Indeed, there is no support for resumption. Of course, the body of while-no-input can do regular "checkpoints" so as to know where to start next time.

But the original motivation for this functionality was in cases where the computed information is likely useless after the next command. More specifically, it was introduced for icomplete, so that the computation of the set of completion candidates does not prevent the user from typing further text (which in turn requires recomputation of that set of completion candidates anyway).

4

It's super-useful in counsel-git-grep: I'm able to call git grep on the whole 3,800,000 lines of the Emacs git repository after each key stroke. No hangups. And it's OK to be interrupted, you just need to check for that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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