summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-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