From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Gerd =?UTF-8?Q?M=C3=B6llmann?= Newsgroups: gmane.emacs.bugs Subject: bug#65908: 29.1.50; Emacs 29 regresses on macOS Date: Thu, 05 Oct 2023 18:39:56 +0200 Message-ID: References: <83o7hd4n5n.fsf@gnu.org> <83v8bl2fsp.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23671"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: ccsmile2008@outlook.com, alan@idiocy.org, 65908@debbugs.gnu.org, gregory@heytings.org, stefankangas@gmail.com To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Oct 05 18:41:07 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qoRPO-0005rf-3t for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 05 Oct 2023 18:41:06 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qoRPB-0004zF-TW; Thu, 05 Oct 2023 12:40:53 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qoRP3-0004yA-0b for bug-gnu-emacs@gnu.org; Thu, 05 Oct 2023 12:40:45 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qoRP2-0002jE-Ic for bug-gnu-emacs@gnu.org; Thu, 05 Oct 2023 12:40:44 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qoRPJ-0005fh-QY for bug-gnu-emacs@gnu.org; Thu, 05 Oct 2023 12:41:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Gerd =?UTF-8?Q?M=C3=B6llmann?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 05 Oct 2023 16:41:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65908 X-GNU-PR-Package: emacs Original-Received: via spool by 65908-submit@debbugs.gnu.org id=B65908.169652402721742 (code B ref 65908); Thu, 05 Oct 2023 16:41:01 +0000 Original-Received: (at 65908) by debbugs.gnu.org; 5 Oct 2023 16:40:27 +0000 Original-Received: from localhost ([127.0.0.1]:48399 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qoROl-0005eb-4r for submit@debbugs.gnu.org; Thu, 05 Oct 2023 12:40:27 -0400 Original-Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]:45141) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qoROg-0005eI-TK for 65908@debbugs.gnu.org; Thu, 05 Oct 2023 12:40:25 -0400 Original-Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-533d9925094so2105787a12.2 for <65908@debbugs.gnu.org>; Thu, 05 Oct 2023 09:40:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696523999; x=1697128799; darn=debbugs.gnu.org; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=Nli+O4iG2GxUnMN+bNcflRD8gw+ID6X2qNwPKHKEoEE=; b=HgUfo2wK2euM0IRv/PRM4HgD5JtAPmRzjnnlIKkk46CUXZhh1o10gtBmaiEijFozBQ nWI1eWS3M6PDqwh0s6CWTsXYJjBvfQR/SUXZ0bMsGoqfu5aTAaU0tCNf3j7N4YWndbQW VotONDTdCpBm4qC8KepqpGMXSBIt2OHNwIU2unIa/f1ArLh74p5pDCc1hSox3ngDiFEj NI5w7ZWq5eiuChOmngis+S7Ur1pNoSx55wkdAQTNrBlYQetPOgFFdlp+l4mCsvE9lB+p OoVKZOc+cpAWDJc0xxT77xjI3E1gpo2mCrhdRuCiSco+DQF8LcaTdEdk3tN1z6fcZrHj peuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696523999; x=1697128799; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Nli+O4iG2GxUnMN+bNcflRD8gw+ID6X2qNwPKHKEoEE=; b=W63R4wIr6oZTvTOMDa9cGcUNc/jQFANkznPI68lGYW+AASNacnWGqE9kiifAy8R35D iycrvhF3ALn4TyALcA+lL65uxLf8YCDBE4+5wZ/tQjcJGdQyD62i8d1RMlm7f1Fol1LS 48teVvBn1LPafVC8PZ30OviwQqjmAs/We6XyEdlc1aj5hpCsaKZ//ceOHi8dxATia3Sz fvwbXOgs64fRQhioFYmkiBc5oUnOnBWSr0q/CJjqN9kC+kfLa4PJxsflPUVk4GhFjxa+ eYozzauPZkoHl0mC3pia9YNOBwlXMPL/jA1j5+9Z7YF++H4bioeGkIpjTzjnYs+DJFOX wiPQ== X-Gm-Message-State: AOJu0YzMhLs8o7MoiFayrlSfnj7n1v3XHxEnECu0fVAEiv5+MuclA4J0 UQ1hsHVCqXTC8vrSz+hMinE= X-Google-Smtp-Source: AGHT+IFjjUxhFa785i6IQpizPwMjTALW1QbUHn/EE28YhMhYxebOx18PyIIwF0gG4pQwZKgkP1o25g== X-Received: by 2002:aa7:d052:0:b0:532:c909:a06c with SMTP id n18-20020aa7d052000000b00532c909a06cmr5543790edo.18.1696523998388; Thu, 05 Oct 2023 09:39:58 -0700 (PDT) Original-Received: from Pro.fritz.box (pd9e3618b.dip0.t-ipconnect.de. [217.227.97.139]) by smtp.gmail.com with ESMTPSA id l21-20020aa7d955000000b00537f44827a8sm1308970eds.64.2023.10.05.09.39.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 09:39:57 -0700 (PDT) In-Reply-To: <83v8bl2fsp.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 05 Oct 2023 19:29:58 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:271896 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Eli Zaretskii writes: >> From: Gerd M=C3=B6llmann >> Cc: Eli Zaretskii , gregory@heytings.org, >> 65908@debbugs.gnu.org, stefankangas@gmail.com, ccsmile2008@outlook.c= om >> Date: Thu, 05 Oct 2023 17:11:09 +0200 >>=20 >> 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. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Handle-LANG-on-macOS-differently-bug-65908.patch Content-Description: LANG patch >From f1ba5bbbd9526197052949525d2ac680337b6d6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerd=20M=C3=B6llmann?= 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) --=-=-=--