]> code.delx.au - gnu-emacs/commitdiff
* lisp/emacs-lisp/cl-macs.el (cl--prog): New function
authorStefan Monnier <monnier@iro.umontreal.ca>
Tue, 12 Jul 2016 16:05:01 +0000 (12:05 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Tue, 12 Jul 2016 16:05:01 +0000 (12:05 -0400)
(cl-prog, cl-prog*): New macros.

lisp/emacs-lisp/cl-macs.el

index d2c90c2b8091a74dd6c0101073480e95d97bbafd..56170e6a71b5a29d74798d1d8d89f888e66cef17 100644 (file)
@@ -1808,6 +1808,27 @@ Labels have lexical scope and dynamic extent."
                     `(throw ',catch-tag ',label))))
          ,@macroexpand-all-environment)))))
 
+(defun cl--prog (binder bindings body)
+  (let (decls)
+    (while (eq 'declare (car-safe (car body)))
+      (push (pop body) decls))
+    `(cl-block nil
+       (,binder ,bindings
+         ,@(nreverse decls)
+         (cl-tagbody . ,body)))))
+
+;;;###autoload
+(defmacro cl-prog (bindings &rest body)
+  "Run BODY like a `cl-tagbody' after setting up the BINDINGS.
+Shorthand for (cl-block nil (let BINDINGS (cl-tagbody BODY)))"
+  (cl--prog 'let bindings body))
+
+;;;###autoload
+(defmacro cl-prog* (bindings &rest body)
+  "Run BODY like a `cl-tagbody' after setting up the BINDINGS.
+Shorthand for (cl-block nil (let* BINDINGS (cl-tagbody BODY)))"
+  (cl--prog 'let* bindings body))
+
 ;;;###autoload
 (defmacro cl-do-symbols (spec &rest body)
   "Loop over all symbols.