diff --git a/lisp/doom-lib.el b/lisp/doom-lib.el index 33f4ae1bb..396f1b78f 100644 --- a/lisp/doom-lib.el +++ b/lisp/doom-lib.el @@ -198,13 +198,8 @@ TRIGGER-HOOK is a list of quoted hooks and/or sharp-quoted functions." (buffer-file-name) ((error "Cannot get this file-path")))) -(defmacro letenv! (envvars &rest body) - "Lexically bind ENVVARS in BODY, like `let' but for `process-environment'." - (declare (indent 1)) - `(let ((process-environment (copy-sequence process-environment))) - ,@(cl-loop for (var val) in envvars - collect `(setenv ,var ,val)) - ,@body)) +;; REVIEW Should I deprecate this? The macro's name is so long... +(defalias 'letenv! 'with-environment-variables) (defmacro letf! (bindings &rest body) "Temporarily rebind function, macros, and advice in BODY. @@ -827,5 +822,23 @@ inserted before contatenating." collect (match-string 1 str))) "/"))) +;; Introduced in 28.1 +(unless (fboundp 'with-environment-variables) + (defmacro with-environment-variables (variables &rest body) + "Set VARIABLES in the environment and execute BODY. +VARIABLES is a list of variable settings of the form (VAR VALUE), +where VAR is the name of the variable (a string) and VALUE +is its value (also a string). + +The previous values will be be restored upon exit." + (declare (indent 1) (debug (sexp body))) + (unless (consp variables) + (error "Invalid VARIABLES: %s" variables)) + `(let ((process-environment (copy-sequence process-environment))) + ,@(mapcar (lambda (elem) + `(setenv ,(car elem) ,(cadr elem))) + variables) + ,@body))) + (provide 'doom-lib) ;;; doom-lib.el ends here