From: Lars Ingebrigtsen Date: Wed, 20 Oct 2021 07:36:25 +0000 (+0200) Subject: Add new macro with-locale-environment X-Git-Tag: emacs-29.0.90~3671^2~485 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=442101433c6459202e325264e3bbf97790f512e6;p=emacs.git Add new macro with-locale-environment * lisp/international/mule-cmds.el (with-locale-environment): New macro. (current-locale-environment): New variable. --- diff --git a/etc/NEWS b/etc/NEWS index 20696afb612..84e2121086b 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 94d2f82e8c8..be4a4eb0cb2 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