Function: while-let

while-let is a macro defined in subr.el.gz.

Signature

(while-let SPEC &rest BODY)

Documentation

Bind variables according to SPEC and conditionally evaluate BODY.

Evaluate each binding in turn, stopping if a binding value is nil. If all bindings are non-nil, eval BODY and repeat.

The variable list SPEC is the same as in if-let*.

View in manual

Probably introduced at or before Emacs version 29.1.

Source Code

;; Defined in /usr/src/emacs/lisp/subr.el.gz
(defmacro while-let (spec &rest body)
  "Bind variables according to SPEC and conditionally evaluate BODY.
Evaluate each binding in turn, stopping if a binding value is nil.
If all bindings are non-nil, eval BODY and repeat.

The variable list SPEC is the same as in `if-let*'."
  (declare (indent 1) (debug if-let))
  (let ((done (gensym "done")))
    `(catch ',done
       (while t
         ;; This is `if-let*', not `if-let', deliberately, despite the
         ;; name of this macro.  See bug#60758.
         (if-let* ,spec
             (progn
               ,@body)
           (throw ',done nil))))))