diff options
Diffstat (limited to 'lisp/env.el')
-rw-r--r-- | lisp/env.el | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/lisp/env.el b/lisp/env.el index 51247f1ff84..2f7cd9d3dbb 100644 --- a/lisp/env.el +++ b/lisp/env.el @@ -44,7 +44,7 @@ If it is also not t, RET does not exit if it does non-null completion." (completing-read prompt (mapcar (lambda (enventry) (let ((str (substring enventry 0 - (string-match "=" enventry)))) + (string-search "=" enventry)))) (if (multibyte-string-p str) (decode-coding-string str locale-coding-system t) @@ -184,7 +184,7 @@ a side-effect." (setq variable (encode-coding-string variable locale-coding-system))) (if (and value (multibyte-string-p value)) (setq value (encode-coding-string value locale-coding-system))) - (if (string-match-p "=" variable) + (if (string-search "=" variable) (error "Environment variable name `%s' contains `='" variable)) (if (string-equal "TZ" variable) (set-time-zone-rule value)) @@ -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 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 'env) ;;; env.el ends here |