Subject: bug#51321: 29.0.50; date in modelines

From: Daniel Martín <[email-masked]>
Date: Sat, 23 Oct 2021 14:52:14 +0200

Eli Zaretskii <[email-masked]> writes:

>> 
>> It depends on how you start Emacs.  The common case on macOS is that
>> people start Emacs from the GUI, and in that case the OS doesn't
>> configure the locale environment variables.  What the NS port does is it
>> uses the OS API to get the locale and applies the environment variables
>> manually (see ns_init_locale in nsterm.m).
>
> Thanks, I think that explains the issue.
>
>> I see that ns_init_locale only sets LANG, which seems insufficient for
>> this use case.  Perhaps we need to extend ns_init_locale to set other
>> LC_ variables as well (LC_TIME is the key here).
>
> Why not LC_ALL?

Yes, after consulting the POSIX spec, I think setting LC_ALL is the
right thing to do.

I've attached a patch that solves the issue.  If you think it's a good
idea, please install it for me.  Thanks.

>From 472bcdb74139ae53c0c224262c072c462a6f243d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Mart=C3=ADn?= <[email-masked]>
Date: Sat, 23 Oct 2021 14:44:31 +0200
Subject: [PATCH] Set LC_ALL to the current locale in the NS port

* src/nsterm.m (ns_init_locale): If not already set, set LC_ALL to the
current locale ID so that dates, currencies, etc. use the settings
configured in the operating system.  (Bug#51321)
---
 src/nsterm.m | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/nsterm.m b/src/nsterm.m
index aa29c13eb2..e27a025035 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -543,8 +543,10 @@ - (NSColor *)colorUsingDefaultColorSpace
       NSString *localeID = [NSString stringWithFormat:@"%@.UTF-8",
                                      [locale localeIdentifier]];
 
-      /* Set LANG to locale, but not if LANG is already set.  */
+      /* Set LANG and LC_ALL to locale, but not if the variables are
+         already set.  */
       setenv("LANG", [localeID UTF8String], 0);
+      setenv("LC_ALL", [localeID UT8String], 0);
     }
   @catch (NSException *e)
     {
-- 
2.31.0