From ab799500094fb36b3f26b9c8a4147848b204cf0a Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Wed, 25 Aug 2021 17:33:03 +0200 Subject: [PATCH] Make `set-locale-environment' complete over locale names * lisp/international/mule-cmds.el (get-locale-names): New function. (set-locale-environment): Use it to allow completion (bug#9655). --- etc/NEWS | 5 +++++ lisp/international/mule-cmds.el | 29 +++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 25750610869..2c929e4a629 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -3844,6 +3844,11 @@ locales. They are also available as aliases 'ebcdic-cp-*' (e.g., 'cp278' for 'ibm278'). There are also new charsets 'ibm2xx' to support these coding-systems. +--- +** New function 'get-locale-names'. +This utility function returns a list of locale names on the current +system. + --- ** 'while-no-input-ignore-events' accepts more special events. The special events 'dbus-event' and 'file-notify' are now ignored in diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el index 71e2653ffe9..dc09dad2cb4 100644 --- a/lisp/international/mule-cmds.el +++ b/lisp/international/mule-cmds.el @@ -2610,6 +2610,31 @@ is returned. Thus, for instance, if charset \"ISO8859-2\", (declare-function w32-get-console-codepage "w32proc.c" ()) (declare-function w32-get-console-output-codepage "w32proc.c" ()) +(defun get-locale-names () + "Return a list of locale names." + (cond + ;; On Windows we have a built-in method to get the names. + ((and (fboundp 'w32-get-locale-info) + (fboundp 'w32-get-valid-locale-ids)) + (mapcar #'w32-get-locale-info (w32-get-valid-locale-ids))) + ;; Unix-ey hosts should have a command to output locales currently + ;; defined by the OS. + ((executable-find "locale") + (split-string (shell-command-to-string "locale -a"))) + ;; Fall back on the list of all defined locales. + ((and locale-translation-file-name + (file-exists-p locale-translation-file-name)) + (with-temp-buffer + (insert-file-contents locale-translation-file-name) + (let ((locales nil)) + (while (not (eobp)) + (unless (looking-at-p "#") + (push (cadr (split-string (buffer-substring + (point) (line-end-position)))) + locales)) + (forward-line 1)) + (nreverse locales)))))) + (defun locale-translate (locale) "Expand LOCALE according to `locale-translation-file-name', if possible. For example, translate \"swedish\" into \"sv_SE.ISO8859-1\"." @@ -2650,8 +2675,8 @@ touch session-global parameters like the language environment. See also `locale-charset-language-names', `locale-language-names', `locale-preferred-coding-systems' and `locale-coding-system'." - (interactive "sSet environment for locale: ") - + (interactive (list (completing-read "Set environment for locale: " + (get-locale-names)))) ;; Do this at runtime for the sake of binaries possibly transported ;; to a system without X. (setq locale-translation-file-name -- 2.39.2