aboutsummaryrefslogtreecommitdiff
path: root/module/hnh
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-05-11 20:49:11 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2022-05-11 20:49:11 +0200
commite028886fd03b162c21790cf158aec892f47b9523 (patch)
tree020607db4ce3b474ea0efa9f6ddc92af03264255 /module/hnh
parentMove let-env to own module. (diff)
downloadcalp-e028886fd03b162c21790cf158aec892f47b9523.tar.gz
calp-e028886fd03b162c21790cf158aec892f47b9523.tar.xz
Add procedure with-working-directory.
Diffstat (limited to 'module/hnh')
-rw-r--r--module/hnh/util/env.scm10
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)))))