diff options
Diffstat (limited to '')
-rw-r--r-- | doc/ref/guile/util.texi | 5 | ||||
-rw-r--r-- | module/hnh/util/env.scm | 13 | ||||
-rw-r--r-- | tests/test/hnh-util-env.scm | 2 |
3 files changed, 19 insertions, 1 deletions
diff --git a/doc/ref/guile/util.texi b/doc/ref/guile/util.texi index 72aa30b1..1d35e0bf 100644 --- a/doc/ref/guile/util.texi +++ b/doc/ref/guile/util.texi @@ -324,6 +324,11 @@ Similar to @var{let}, but sets environment variables for the code in body. Restores the old values once we leave. @end defmac +@defmac with-locale1 category locale thunk +Run @var{thunk} with the locale @var{category} temporarily set to +@var{locale}. +@end defmac + @defmac catch* thunk (symbol proc) ... Macro allowing multiple exception types to be caught. Each (symbol proc) pair expands to a regular @code{catch}, with the leftmost being diff --git a/module/hnh/util/env.scm b/module/hnh/util/env.scm index 18ec0543..32ea1cc1 100644 --- a/module/hnh/util/env.scm +++ b/module/hnh/util/env.scm @@ -1,5 +1,7 @@ (define-module (hnh util env) - :export (let-env with-working-directory)) + :export (let-env + with-working-directory + with-locale1)) (define-syntax let-env (syntax-rules () @@ -33,3 +35,12 @@ thunk (lambda () (chdir old-cwd))))) + +(define-syntax-rule (with-locale1 category locale thunk) + (let ((old #f)) + (dynamic-wind + (lambda () + (set! old (setlocale category)) + (setlocale category locale)) + thunk + (lambda () (setlocale category old))))) diff --git a/tests/test/hnh-util-env.scm b/tests/test/hnh-util-env.scm index 93f72bc9..f38a3a3b 100644 --- a/tests/test/hnh-util-env.scm +++ b/tests/test/hnh-util-env.scm @@ -45,3 +45,5 @@ (test-group "with-working-directory" 'TODO) +(test-group "with-locale" + 'TODO) |