Subject: Re: bug#57531: 28.1; Character encoding missing for "eo"

From: Eli Zaretskii <[email-masked]>
Date: Sun, 04 Sep 2022 11:28:06 +0300

> Cc: [email-masked], [email-masked]
> Date: Sun, 04 Sep 2022 10:46:29 +0300
> From: Eli Zaretskii <[email-masked]>
> 
> But like I said: feel free to submit a patch that doesn't potentially
> destroy everything we have in that setup.  If the patch is safe
> enough, I see no reason not to accept it.

Something like the below could be acceptable, if it solves the
problem.

diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el
index 4137642..6866291 100644
--- a/lisp/international/mule-cmds.el
+++ b/lisp/international/mule-cmds.el
@@ -2317,7 +2317,7 @@ locale-language-names
     ;; en_IN -- fx.
     ("en_IN" "English" utf-8) ; glibc uses utf-8 for English in India
     ("en" "English" iso-8859-1) ; English
-    ("eo" . "Esperanto") ; Esperanto
+    ("eo" "Esperanto" locale-info) ; Esperanto
     ("es" "Spanish" iso-8859-1)
     ("et" . "Latin-9") ; Estonian
     ("eu" . "Latin-1") ; Basque
@@ -2522,8 +2522,12 @@ locale-language-names
   (LOCALE-REGEXP LANG-ENV CODING-SYSTEM)
 The first element whose LOCALE-REGEXP matches the start of a
 downcased locale specifies the LANG-ENV \(language environment)
-and CODING-SYSTEM corresponding to that locale.  If there is no
-appropriate language environment, the element may have this form:
+and CODING-SYSTEM corresponding to that locale.
+CODING-SYSTEM can be the special symbol `locale-info', which
+means we should call `locale-info' to request the codeset of
+the current locale.
+If there is no appropriate language environment, the element may
+have this form:
   (LOCALE-REGEXP . LANG-ENV)
 In this case, LANG-ENV is one of generic language environments for an
 specific encoding such as \"Latin-1\" and \"UTF-8\".")
@@ -2794,9 +2798,23 @@ set-locale-environment
 	    ;; locale-language-names specify both lang-env and coding.
 	    ;; But, what specified in locale-preferred-coding-systems
 	    ;; has higher priority.
-	    (setq coding-system (or coding-system
-				    (nth 1 language-name))
-		  language-name (car language-name))
+            (progn
+	      (setq coding-system (or coding-system
+				      (nth 1 language-name))
+		    language-name (car language-name))
+              ;; If locale-language-names specifies we should query
+              ;; the underlying libc, do that now, but only when we
+              ;; are setting up for the current locale, i.e. when this
+              ;; function is called from startup.el with an argument
+              ;; of nil.
+              (if (eq coding-system 'locale-info)
+                  (if locale-name
+                      (setq coding-system nil)
+                    (let ((locale-codeset (locale-info 'codeset)))
+                      (when (stringp locale-codeset)
+                        (setq coding-system (intern (downcase locale-codeset)))
+                        (unless (coding-system-p coding-system)
+                          (setq coding-system nil)))))))
 	  ;; Otherwise, if locale is not listed in locale-language-names,
 	  ;; use what listed in locale-charset-language-names.
 	  (if (not language-name)