From 6f1f0de1c1a843b75083d827109dbe489f50d3b6 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 12 Apr 2022 13:16:49 -0500 Subject: Add dlet to compat.el --- lisp/compat.el | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lisp/compat.el') diff --git a/lisp/compat.el b/lisp/compat.el index 0cc4c42..4bb8706 100644 --- a/lisp/compat.el +++ b/lisp/compat.el @@ -13,5 +13,22 @@ (dolist (file (directory-files (locate-user-emacs-file "lisp/compat") :full "\\.el\\'")) (load file :noerror)) +;; Other stuff... + +(unless (fboundp 'dlet) + (defmacro dlet (binders &rest body) + "Like `let' but using dynamic scoping." + (declare (indent 1) (debug let)) + ;; (defvar FOO) only affects the current scope, but in order for + ;; this not to affect code after the main `let' we need to create a new scope, + ;; which is what the surrounding `let' is for. + ;; FIXME: (let () ...) currently doesn't actually create a new scope, + ;; which is why we use (let (_) ...). + `(let (_) + ,@(mapcar (lambda (binder) + `(defvar ,(if (consp binder) (car binder) binder))) + binders) + (let ,binders ,@body)))) + (provide 'compat) ;;; compat.el ends here -- cgit 1.4.1-21-gabe81