From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Third Newsgroups: gmane.emacs.bugs Subject: bug#22392: Emacs OS X GUI doesn't set locale Date: Thu, 28 Jan 2016 22:53:34 +0000 Message-ID: References: <83twm01ju1.fsf@gnu.org> <83lh7c1igo.fsf@gnu.org> <56A90735.7090508@cs.ucla.edu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1454021660 7516 80.91.229.3 (28 Jan 2016 22:54:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 28 Jan 2016 22:54:20 +0000 (UTC) Cc: 22392@debbugs.gnu.org, Anders Lindgren , emacs-devel@gnu.org To: Paul Eggert Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jan 28 23:54:11 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aOvS7-0002AD-1s for geb-bug-gnu-emacs@m.gmane.org; Thu, 28 Jan 2016 23:54:11 +0100 Original-Received: from localhost ([::1]:58951 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOvS6-0001lY-Ex for geb-bug-gnu-emacs@m.gmane.org; Thu, 28 Jan 2016 17:54:10 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38566) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOvS1-0001iK-Ur for bug-gnu-emacs@gnu.org; Thu, 28 Jan 2016 17:54:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aOvRy-0005HI-0j for bug-gnu-emacs@gnu.org; Thu, 28 Jan 2016 17:54:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:51890) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOvRx-0005H4-UP for bug-gnu-emacs@gnu.org; Thu, 28 Jan 2016 17:54:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1aOvRx-0004dX-Kd for bug-gnu-emacs@gnu.org; Thu, 28 Jan 2016 17:54:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 28 Jan 2016 22:54:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 22392 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 22392-submit@debbugs.gnu.org id=B22392.145402162617797 (code B ref 22392); Thu, 28 Jan 2016 22:54:01 +0000 Original-Received: (at 22392) by debbugs.gnu.org; 28 Jan 2016 22:53:46 +0000 Original-Received: from localhost ([127.0.0.1]:40110 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aOvRi-0004cz-6g for submit@debbugs.gnu.org; Thu, 28 Jan 2016 17:53:46 -0500 Original-Received: from mail-wm0-f50.google.com ([74.125.82.50]:36280) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aOvRf-0004cm-Ta for 22392@debbugs.gnu.org; Thu, 28 Jan 2016 17:53:44 -0500 Original-Received: by mail-wm0-f50.google.com with SMTP id p63so45658883wmp.1 for <22392@debbugs.gnu.org>; Thu, 28 Jan 2016 14:53:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=gbmWZpN4a8KEdH9PrPTzBL/Dg6BCTGF69JXmQ82OBoM=; b=JKcaGgdpZnZKQ5o/4q8hqFapxB2hdFQ7m+MW5XFmfp+P49++l22R2aJ7oEl3vBO9my MvGoJ0xOCpwOKadhUuUIwD/gqisyYFblcQEBukjwZ19GwwlAkr3zZnS61IAuJyZJ3dpk q/EfXMQEjFAZ0ctmN6Ds8JxBwYhS9PYf99rWqd5yXKPItFV+Pw7XqlKQ8dbLFyjem0kO q1kQx4Ct73LFSmSdu2fa8NJY4ao+/l/M0wfY+u4tciTv6hLVsH7c3xHS7Elp1X4diYcH DF9pQuWkk+M6WNLGuMva/BOqLRPGJM47C1kvM4XXBisxLAChhlLXnBmp3fwpChN5Rbho GwFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version:content-type; bh=gbmWZpN4a8KEdH9PrPTzBL/Dg6BCTGF69JXmQ82OBoM=; b=Yvx8BUgA/PxkNaRuRO/uXYe5BvGiUi8Kcesmrk2hMwJ86P2xQIuUBCI2M2ZuLQkf5b y8JylI9J9UehK86fZKyWOsHTTiQjiuxjzZ0jVRaxp+aq9VMkEcb+Ou0wWsTSfZVLciZ4 LyC82ZHQEsLEzohJ5ssKsVadS1XXgHeipRrhJ0P4RbweQ7iOxtXyPfWnKMYxL0tRINpP 3RjpukLZlpH2VuYfbBiP1xuJ7+IPornHwNNeN23FdKpap588jDeLU8czem0kTNVFtsXm URXfaiHnfI6cY0YjzDF4J4jw3QPDEKnjTa79fGh3Z9TgycU26YVK7IiKCglFDtPngcip yeyw== X-Gm-Message-State: AG10YOQe98vBrZCUG3p+HuS8Uaiq2hiSj0HFMGvhwyIipwG6BsoWix0Un6w9NL9d2tlhIw== X-Received: by 10.28.180.10 with SMTP id d10mr5945493wmf.14.1454021618141; Thu, 28 Jan 2016 14:53:38 -0800 (PST) Original-Received: from galloway.idiocy.org (c.b.6.1.e.1.d.8.5.4.1.0.f.a.8.c.9.2.1.8.8.f.3.0.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:3f8:8129:c8af:145:8d1e:16bc]) by smtp.gmail.com with ESMTPSA id m206sm4824236wmf.16.2016.01.28.14.53.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jan 2016 14:53:36 -0800 (PST) In-Reply-To: <56A90735.7090508@cs.ucla.edu> (Paul Eggert's message of "Wed, 27 Jan 2016 10:06:45 -0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (darwin) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:112066 Archived-At: --=-=-= Content-Type: text/plain Paul Eggert writes: > On 01/26/2016 03:05 PM, Alan Third wrote: > > I looked around, and it appears the GnuCash ran into a similar > problem. You might want to look at its solution, in: > > https://github.com/Gnucash/gnucash/blob/master/src/bin/gnucash-bin.c I've had a look at that code and was initially worried at how much more they have than I'd written, but I'm pretty sure that most of their code is doing things that are done by mule in emacs. One thing I don't understand is that they're building up the locale value from the two parts (language and country code) when NSLocale provides a function that does that for you. Makes me wonder if they know something I don't. They've also wrapped that bit of code in a try/catch as someone was apparently getting a crash due to not having the country code set. I can't replicate this, the only way I've found through Google is by using XCode to unset the user's locale, and we don't use XCode. I've put in a try/catch anyway, just in case. --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=0001-Set-locale-when-run-from-OS-X-GUI.patch Content-Description: OS X Locale fix >From b96c97cb16a980243389c01c10c5ab232fe6827e Mon Sep 17 00:00:00 2001 From: Alan Third Date: Thu, 28 Jan 2016 21:42:04 +0000 Subject: [PATCH] Set locale when run from OS X GUI * src/emacs.c (main): Call ns_init_locale. * src/nsterm.m (ns_init_locale): Get locale from OS and set LANG. * src/nsterm.h: Include ns_init_locale. --- src/emacs.c | 5 +++++ src/nsterm.h | 2 ++ src/nsterm.m | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/src/emacs.c b/src/emacs.c index aaf058e..10e81d5 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -1378,6 +1378,11 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem init_ntproc (dumping); /* must precede init_editfns. */ #endif +#ifdef HAVE_NS + /* Initialise the locale from user defaults. */ + ns_init_locale(); +#endif + /* Initialize and GC-protect Vinitial_environment and Vprocess_environment before set_initial_environment fills them in. */ diff --git a/src/nsterm.h b/src/nsterm.h index 6ca584e..fa5399c 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -1141,6 +1141,8 @@ extern void ns_retain_object (void *obj); extern void *ns_alloc_autorelease_pool (void); extern void ns_release_autorelease_pool (void *); extern const char *ns_get_defaults_value (const char *key); +extern void ns_init_locale (void); + /* in nsmenu */ extern void update_frame_tool_bar (struct frame *f); diff --git a/src/nsterm.m b/src/nsterm.m index b270e0e..4b04fd5 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -586,6 +586,27 @@ ns_load_path (void) void +ns_init_locale (void) +/* OS X 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"); + + @try + { + /* Set LANG to locale, but not if LANG is already set. */ + setenv("LANG", [[locale localeIdentifier] UTF8String], 0); + } + @catch (NSException *e) + { + NSLog (@"Locale detection failed: %@: %@", [e name], [e reason]); + } +} + + +void ns_release_object (void *obj) /* -------------------------------------------------------------------------- Release an object (callable from C) -- 2.5.4 (Apple Git-61) --=-=-= Content-Type: text/plain -- Alan Third --=-=-=--