3

(while-no-input &rest BODY)

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 the BODY returns t then there is no way to distinguish it from the input interruption. One way could be to check if the return value is t in the BODY itself and then return certain value like 293851932832985. Is there a cleaner way?

Drew
  • 75,699
  • 9
  • 109
  • 225
tejasvi88
  • 151
  • 5

1 Answers1

4

The Elisp manual (do C-h i g (elisp) RET i while-no-input RET for more details - learning to use Info and the Info manuals is a good investment of your time) suggests the following:

If you want to be able to distinguish all possible values computed by BODY from both kinds of abort conditions, write the code like this:

     (while-no-input
       (list
         (progn . BODY)))

The rest of the description in the manual is also worth reading because there are a couple of wrinkles that are not covered by the doc string of while-no-input.

NickD
  • 27,023
  • 3
  • 23
  • 42