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?
Malabarba
  • 22,878
  • 6
  • 78
  • 163
  • 1
    [Looks like](https://github.com/search?o=desc&q=extension%3Ael++while-no-input&ref=searchresults&s=indexed&type=Code&utf8=%E2%9C%93) icomplete+, ivy, helm are few of the packages using it. – Kaushal Modi Apr 30 '15 at 12:56

2 Answers2

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).

Stefan
  • 26,154
  • 3
  • 46
  • 84
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.

abo-abo
  • 13,943
  • 1
  • 29
  • 43