summaryrefslogtreecommitdiff
path: root/lisp/env.el
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2021-09-26 08:27:51 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2021-09-26 08:27:51 +0200
commit7cb29440433bda1ad8defad70cbd43fb2f9f4d1f (patch)
tree5328f0be5e70930ce38e5c19eb6ef96f6eb725e6 /lisp/env.el
parent43ae8c828d853382bbc2a27b9e14b9fff6ba18b6 (diff)
downloademacs-7cb29440433bda1ad8defad70cbd43fb2f9f4d1f.tar.gz
Add new macro with-environment-variables
* doc/lispref/os.texi (System Environment): Document it. * lisp/env.el (with-environment-variables): New macro.
Diffstat (limited to 'lisp/env.el')
-rw-r--r--lisp/env.el17
1 files changed, 17 insertions, 0 deletions
diff --git a/lisp/env.el b/lisp/env.el
index 83f43d1006b..31a728c0e56 100644
--- a/lisp/env.el
+++ b/lisp/env.el
@@ -218,6 +218,23 @@ in the environment list of the selected frame."
(message "%s" (if value value "Not set")))
value))
+;;;###autoload
+(defmacro with-environment-variables (variables &rest body)
+ "Set VARIABLES in the environent and execute BODY.
+VARIABLES is a list of variable settings where first element
+should be the name of the variable and the second element should
+be the value.
+
+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 'env)
;;; env.el ends here