(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?

1 Answer 1


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:

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

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.