feat(lib): backport with-environment-variables from 28.1
And alias letenv! to it. Not sure if I want to deprecate it though, given the length of the macro it's linked to...
This commit is contained in:
parent
efa3e9791f
commit
65c86ea3ff
1 changed files with 20 additions and 7 deletions
|
@ -198,13 +198,8 @@ TRIGGER-HOOK is a list of quoted hooks and/or sharp-quoted functions."
|
||||||
(buffer-file-name)
|
(buffer-file-name)
|
||||||
((error "Cannot get this file-path"))))
|
((error "Cannot get this file-path"))))
|
||||||
|
|
||||||
(defmacro letenv! (envvars &rest body)
|
;; REVIEW Should I deprecate this? The macro's name is so long...
|
||||||
"Lexically bind ENVVARS in BODY, like `let' but for `process-environment'."
|
(defalias 'letenv! 'with-environment-variables)
|
||||||
(declare (indent 1))
|
|
||||||
`(let ((process-environment (copy-sequence process-environment)))
|
|
||||||
,@(cl-loop for (var val) in envvars
|
|
||||||
collect `(setenv ,var ,val))
|
|
||||||
,@body))
|
|
||||||
|
|
||||||
(defmacro letf! (bindings &rest body)
|
(defmacro letf! (bindings &rest body)
|
||||||
"Temporarily rebind function, macros, and advice in BODY.
|
"Temporarily rebind function, macros, and advice in BODY.
|
||||||
|
@ -827,5 +822,23 @@ inserted before contatenating."
|
||||||
collect (match-string 1 str)))
|
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)
|
(provide 'doom-lib)
|
||||||
;;; doom-lib.el ends here
|
;;; doom-lib.el ends here
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue