diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-05-11 20:49:11 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-05-11 20:49:11 +0200 |
commit | e028886fd03b162c21790cf158aec892f47b9523 (patch) | |
tree | 020607db4ce3b474ea0efa9f6ddc92af03264255 /module/hnh/util/env.scm | |
parent | Move let-env to own module. (diff) | |
download | calp-e028886fd03b162c21790cf158aec892f47b9523.tar.gz calp-e028886fd03b162c21790cf158aec892f47b9523.tar.xz |
Add procedure with-working-directory.
Diffstat (limited to '')
-rw-r--r-- | module/hnh/util/env.scm | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/module/hnh/util/env.scm b/module/hnh/util/env.scm index a6877186..ca0e5ea8 100644 --- a/module/hnh/util/env.scm +++ b/module/hnh/util/env.scm @@ -1,5 +1,5 @@ (define-module (hnh util env) - :export (let-env)) + :export (let-env with-working-directory)) (define-syntax let-env (syntax-rules () @@ -22,4 +22,12 @@ env-pairs))))])) +(define-syntax-rule (with-working-directory directory thunk) + (let ((old-cwd #f)) + (dynamic-wind + (lambda () + (set! old-cwd (getcwd)) + (chdir directory)) + thunk + (lambda () (chdir old-cwd))))) |