about summary refs log tree commit diff
diff options
context:
space:
mode:
authorArun Isaac2026-06-22 01:33:52 +0100
committerArun Isaac2026-06-22 01:36:15 +0100
commite75dbbcf867d0d574a45bf4b860a75be671ead02 (patch)
tree31095bab4e43ed65aa0999f9f3b590137c371786
parentfdedfc0088714ed82c93a0e44e2d8cd2def10f91 (diff)
downloadccwl-e75dbbcf867d0d574a45bf4b860a75be671ead02.tar.gz
ccwl-e75dbbcf867d0d574a45bf4b860a75be671ead02.tar.lz
ccwl-e75dbbcf867d0d574a45bf4b860a75be671ead02.zip
utils: Add call-with-current-directory.
-rw-r--r--.dir-locals.el1
-rw-r--r--ccwl/utils.scm11
2 files changed, 11 insertions, 1 deletions
diff --git a/.dir-locals.el b/.dir-locals.el
index 5b74ad4..fe4eb82 100644
--- a/.dir-locals.el
+++ b/.dir-locals.el
@@ -6,6 +6,7 @@
  (makefile-gmake-mode
   (indent-tabs-mode t))
  (scheme-mode
+  (eval put 'call-with-current-directory 'scheme-indent-function 1)
   (eval put 'lambda** 'scheme-indent-function 1)
   (eval put 'set-function-inputs 'scheme-indent-function 1)
   (eval put 'set-input-default 'scheme-indent-function 1)
diff --git a/ccwl/utils.scm b/ccwl/utils.scm
index 2abc404..2c8522c 100644
--- a/ccwl/utils.scm
+++ b/ccwl/utils.scm
@@ -41,7 +41,8 @@
             mapn
             map2
             foldn
-            filter-mapi))
+            filter-mapi
+            call-with-current-directory))
 
 (define (indent-level port level)
   "Emit whitespaces to PORT corresponding to nesting LEVEL."
@@ -358,3 +359,11 @@ the first call. For example,
                  (call-with-values (cut apply proc element results) list))
                inits
                lst)))
+
+(define (call-with-current-directory curdir thunk)
+  "Call @var{thunk} with current directory set to @var{curdir}. Restore
+current directory after @var{thunk} returns."
+  (let ((original-current-directory (getcwd)))
+    (dynamic-wind (cut chdir curdir)
+                  thunk
+                  (cut chdir original-current-directory))))