mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-15 10:30:25 -08:00
Add new macro with-locale-environment
* lisp/international/mule-cmds.el (with-locale-environment): New macro. (current-locale-environment): New variable.
This commit is contained in:
parent
62591c164c
commit
442101433c
2 changed files with 30 additions and 0 deletions
11
etc/NEWS
11
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue