summaryrefslogtreecommitdiff
path: root/lisp/subr.el
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2022-09-28 13:19:08 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2022-09-28 13:19:08 +0200
commit12f63c18f6d5a886f62f10b4c8de8de3509e52df (patch)
treead7a5b8d620d976b6c9bf3c737d5bc666cbe746d /lisp/subr.el
parentfe002cc8ce38efb256a2a60660ee626c2b2cdf81 (diff)
downloademacs-12f63c18f6d5a886f62f10b4c8de8de3509e52df.tar.gz
emacs-12f63c18f6d5a886f62f10b4c8de8de3509e52df.tar.bz2
emacs-12f63c18f6d5a886f62f10b4c8de8de3509e52df.zip
Add new macro 'while-let'
* doc/lispref/control.texi (Conditionals): Document when-let/if-let/while-let. * lisp/subr.el (while-let): New macro.
Diffstat (limited to 'lisp/subr.el')
-rw-r--r--lisp/subr.el13
1 files changed, 13 insertions, 0 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index 26fba4771bc..2a8fc46a9f9 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2514,7 +2514,20 @@ The variable list SPEC is the same as in `if-let'."
(declare (indent 1) (debug if-let))
(list 'if-let spec (macroexp-progn body)))
+(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
+ (if-let ,spec
+ (progn
+ ,@body)
+ (throw ',done nil))))))
;; PUBLIC: find if the current mode derives from another.