From 32d5e62a222fc1c542758016325839cdc705cd28 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Wed, 22 Jun 2022 18:21:51 +0530 Subject: utils: Add call-with-current-directory utility function. * tissue/utils.scm (call-with-current-directory): New public function. --- tissue/utils.scm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tissue/utils.scm b/tissue/utils.scm index 6832fb8..156d333 100644 --- a/tissue/utils.scm +++ b/tissue/utils.scm @@ -20,10 +20,19 @@ #:use-module (rnrs io ports) #:use-module (srfi srfi-26) #:use-module (ice-9 popen) - #:export (call-with-input-pipe + #:export (call-with-current-directory + call-with-input-pipe get-line-dos-or-unix memoize-thunk)) +(define (call-with-current-directory curdir thunk) + "Call THUNK with current directory set to CURDIR. Restore current +directory after THUNK returns." + (let ((original-current-directory (getcwd))) + (dynamic-wind (cut chdir curdir) + thunk + (cut chdir original-current-directory)))) + (define (call-with-input-pipe proc program . args) "Execute PROGRAM ARGS ... in a subprocess with a pipe to it. Call PROC with an input port to that pipe. Close the pipe once PROC exits, -- cgit v1.2.3