unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Gerd Möllmann" <gerd.moellmann@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: ccsmile2008@outlook.com, alan@idiocy.org, 65908@debbugs.gnu.org,
	gregory@heytings.org, stefankangas@gmail.com
Subject: bug#65908: 29.1.50; Emacs 29 regresses on macOS
Date: Thu, 05 Oct 2023 18:39:56 +0200	[thread overview]
Message-ID: <m2edi9xbtv.fsf@Pro.fritz.box> (raw)
In-Reply-To: <83v8bl2fsp.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 05 Oct 2023 19:29:58 +0300")

[-- Attachment #1: Type: text/plain, Size: 502 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Gerd Möllmann <gerd.moellmann@gmail.com>
>> Cc: Eli Zaretskii <eliz@gnu.org>,  gregory@heytings.org,
>>   65908@debbugs.gnu.org,  stefankangas@gmail.com,  ccsmile2008@outlook.com
>> Date: Thu, 05 Oct 2023 17:11:09 +0200
>> 
>> Remains the question if that should go into emacs-29?  I'm for not
>> rocking the boat too much.  Although...
>
> Let's see the final patch, and decide then.

Please find attached.  Not much gas changed, though.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: LANG patch --]
[-- Type: text/x-patch, Size: 2621 bytes --]

From f1ba5bbbd9526197052949525d2ac680337b6d6b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gerd=20M=C3=B6llmann?= <gerd@gnu.org>
Date: Thu, 5 Oct 2023 17:29:17 +0200
Subject: [PATCH] Handle LANG on macOS differently (bug#65908)

* src/nsterm.m (ns_init_locale): If LANG is set, try to use that,
otherwise try to deduce what LANG should be.  Check is the result is
valid, and use LANG="en_US.UTF-8" if not.
---
 src/nsterm.m | 39 +++++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 18 deletions(-)

diff --git a/src/nsterm.m b/src/nsterm.m
index 4e0dfa58c63..56865987b93 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -554,29 +554,32 @@ - (unsigned long)unsignedLong
 /* macOS doesn't set any environment variables for the locale when run
    from the GUI. Get the locale from the OS and set LANG.  */
 {
-  NSLocale *locale = [NSLocale currentLocale];
-
   NSTRACE ("ns_init_locale");
 
-  /* If we were run from a terminal then assume an unset LANG variable
-     is intentional and don't try to "fix" it.  */
-  if (!isatty (STDIN_FILENO))
+  /* Either use LANG, if set, or try to construct LANG from
+     NSLocale.  */
+  const char *lang = getenv ("LANG");
+  if (lang == NULL)
     {
-      char *oldLocale = setlocale (LC_ALL, NULL);
-      /* It seems macOS should probably use UTF-8 everywhere.
-         'localeIdentifier' does not specify the encoding, and I can't
-         find any way to get the OS to tell us which encoding to use,
-         so hard-code '.UTF-8'.  */
-      NSString *localeID = [NSString stringWithFormat:@"%@.UTF-8",
-                                     [locale localeIdentifier]];
-
-      /* Check the locale ID is valid and if so set LANG, but not if
-         it is already set.  */
-      if (setlocale (LC_ALL, [localeID UTF8String]))
-        setenv("LANG", [localeID UTF8String], 0);
+      const NSLocale *locale = [NSLocale currentLocale];
+      const NSString *localeID = [NSString stringWithFormat:@"%@.UTF-8",
+					   [locale localeIdentifier]];
+      lang = [localeID UTF8String];
+    }
 
-      setlocale (LC_ALL, oldLocale);
+  /* Check if LANG can be used for initializing the locale.  If not,
+     use a default setting.  Note that Emacs' main will undo the
+     setlocale below, initializing the locale from the
+     environment.  */
+  if (setlocale (LC_ALL, lang) == NULL)
+    {
+      const char *const default_lang = "en_US.UTF-8";
+      fprintf (stderr, "LANG=%s cannot be used, using %s instead.\n",
+	       lang, default_lang);
+      lang = default_lang;
     }
+
+  setenv ("LANG", lang, 1);
 }
 
 
-- 
2.39.3 (Apple Git-145)


  reply	other threads:[~2023-10-05 16:39 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-13  6:47 bug#65908: 29.1.50; Emacs 29 regresses on macOS Zhang Haijun
2023-10-04  5:44 ` Gerd Möllmann
2023-10-04  7:38   ` Eli Zaretskii
2023-10-04  7:50     ` Gerd Möllmann
2023-10-04  8:29       ` Stefan Kangas
2023-10-04  8:32         ` Gerd Möllmann
2023-10-04  9:02         ` Gregory Heytings
2023-10-04  9:12           ` Gerd Möllmann
2023-10-04  9:12           ` Stefan Kangas
2023-10-04 10:55             ` Gerd Möllmann
2023-10-04 12:43               ` Gerd Möllmann
2023-10-04 21:16                 ` Alan Third
2023-10-05  5:41                   ` Eli Zaretskii
2023-10-05  5:55                   ` Gerd Möllmann
2023-10-05  6:08                     ` Eli Zaretskii
2023-10-05  8:52                       ` Gerd Möllmann
2023-10-05  9:48                         ` Alan Third
2023-10-05 11:12                           ` Gerd Möllmann
2023-10-05 13:18                             ` Gerd Möllmann
2023-10-05 16:11                               ` Eli Zaretskii
2023-10-05 16:33                                 ` Alan Third
2023-10-05 16:38                                   ` Gerd Möllmann
2023-10-05 17:02                                   ` Eli Zaretskii
2023-10-05 17:15                                     ` Alan Third
2023-10-05 13:51                             ` Alan Third
2023-10-05 14:01                               ` Gerd Möllmann
2023-10-05 14:09                               ` Gerd Möllmann
2023-10-05 14:58                                 ` Alan Third
2023-10-05 15:11                                   ` Gerd Möllmann
2023-10-05 16:29                                     ` Eli Zaretskii
2023-10-05 16:39                                       ` Gerd Möllmann [this message]
2023-10-05 17:06                                         ` Eli Zaretskii
2023-10-05 18:08                                           ` Stefan Kangas
2023-10-05 13:56                             ` Gerd Möllmann
2023-10-05 16:19                               ` Eli Zaretskii
2023-10-05 16:26                                 ` Alan Third
2023-10-05 16:43                                   ` Gerd Möllmann
2023-10-05 16:36                                 ` Gerd Möllmann
2023-10-05 17:04                                   ` Eli Zaretskii
2023-10-05 17:15                                     ` Gerd Möllmann
2023-10-05 18:25                                       ` Alan Third
2023-10-05 18:33                                         ` Gerd Möllmann
2023-10-05 18:46                                           ` Gerd Möllmann
2023-10-05  8:58             ` Gregory Heytings
2023-10-05  9:03               ` Gregory Heytings

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2edi9xbtv.fsf@Pro.fritz.box \
    --to=gerd.moellmann@gmail.com \
    --cc=65908@debbugs.gnu.org \
    --cc=alan@idiocy.org \
    --cc=ccsmile2008@outlook.com \
    --cc=eliz@gnu.org \
    --cc=gregory@heytings.org \
    --cc=stefankangas@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).