emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 4421014 1/2: Add new macro with-locale-environment


From: Lars Ingebrigtsen
Subject: master 4421014 1/2: Add new macro with-locale-environment
Date: Wed, 20 Oct 2021 03:38:53 -0400 (EDT)

branch: master
commit 442101433c6459202e325264e3bbf97790f512e6
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Add new macro with-locale-environment
    
    * lisp/international/mule-cmds.el (with-locale-environment): New macro.
    (current-locale-environment): New variable.
---
 etc/NEWS                        | 11 +++++++++++
 lisp/international/mule-cmds.el | 19 +++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index 20696af..84e2121 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -236,6 +236,17 @@ with recent versions of Firefox.
 
 * Lisp Changes in Emacs 29.1
 
+** Locale
+
+---
+*** New variable 'current-locale-environment'.
+This holds the value of the previous call to 'set-locale-environment'.
+
+---
+*** New macro 'with-locale-environment'.
+This macro can be used to change the locale temporarily while
+executing code.
+
 +++
 ** 'define-key' now understands a new strict 'kbd' representation for keys.
 The '(define-key map ["C-c M-f"] #'some-command)' syntax is now
diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el
index 94d2f82..be4a4eb 100644
--- a/lisp/international/mule-cmds.el
+++ b/lisp/international/mule-cmds.el
@@ -2665,6 +2665,20 @@ For example, translate \"swedish\" into 
\"sv_SE.ISO8859-1\"."
           locale))
     locale))
 
+(defvar current-locale-environment nil
+  "The currently set locale environment.")
+
+(defmacro with-locale-environment (locale-name &rest body)
+  "Execute BODY with the locale set to LOCALE-NAME."
+  (declare (indent 1) (debug (sexp def-body)))
+  (let ((current (gensym)))
+    `(let ((,current current-locale-environment))
+       (unwind-protect
+           (progn
+             (set-locale-environment ,locale-name)
+             ,@body)
+         (set-locale-environment ,current)))))
+
 (defun set-locale-environment (&optional locale-name frame)
   "Set up multilingual environment for using LOCALE-NAME.
 This sets the language environment, the coding system priority,
@@ -2690,6 +2704,10 @@ If FRAME is non-nil, only set the keyboard coding system 
and the
 terminal coding system for the terminal of that frame, and don't
 touch session-global parameters like the language environment.
 
+This function sets the `current-locale-environment' variable.  To
+change the locale temporarily, `with-locale-environment' can be
+used.
+
 See also `locale-charset-language-names', `locale-language-names',
 `locale-preferred-coding-systems' and `locale-coding-system'."
   (interactive (list (completing-read "Set environment for locale: "
@@ -2723,6 +2741,7 @@ See also `locale-charset-language-names', 
`locale-language-names',
 
     (when locale
       (setq locale (locale-translate locale))
+      (setq current-locale-environment locale)
 
       ;; Leave the system locales alone if the caller did not specify
       ;; an explicit locale name, as their defaults are set from



reply via email to

[Prev in Thread] Current Thread [Next in Thread]