From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Third Newsgroups: gmane.emacs.devel Subject: Re: 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 1454021640 7039 80.91.229.3 (28 Jan 2016 22:54:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 28 Jan 2016 22:54:00 +0000 (UTC) Cc: 22392@debbugs.gnu.org, Eli Zaretskii , Anders Lindgren , emacs-devel@gnu.org To: Paul Eggert Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jan 28 23:53:59 2016 Return-path: Envelope-to: ged-emacs-devel@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 1aOvRs-0001xl-Sg for ged-emacs-devel@m.gmane.org; Thu, 28 Jan 2016 23:53:57 +0100 Original-Received: from localhost ([::1]:58947 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOvRs-0001Iu-BR for ged-emacs-devel@m.gmane.org; Thu, 28 Jan 2016 17:53:56 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38243) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOvRc-0001If-Uf for emacs-devel@gnu.org; Thu, 28 Jan 2016 17:53:42 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aOvRb-00059S-Li for emacs-devel@gnu.org; Thu, 28 Jan 2016 17:53:40 -0500 Original-Received: from mail-wm0-x22e.google.com ([2a00:1450:400c:c09::22e]:35724) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOvRb-00059L-3B; Thu, 28 Jan 2016 17:53:39 -0500 Original-Received: by mail-wm0-x22e.google.com with SMTP id r129so45706515wmr.0; Thu, 28 Jan 2016 14:53:38 -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=ICJVN0UnV2qIn2NjlYO4TvS6vDw5S0CxNOzi3UNRKTlDyAj2ob/0wpElFnPAmMfd4o FFMepRA28EC8igneQI9CircI97ehExnNXZcwfQy/y3qFK/o2wDpvCxNLFha2l87rM0FM DMrYCUzP0bX2S6h+tDyJrc6YgpRbIhReZ/qs7G69wIIDE7aPYfSsUcGzwX75KDJVPTwx FBujcPLXzu0t2waLLfZ1IcS/5v03JFUj8Qaur3NZBlC7io9LJxe+LTwIhqFrQJ1HDsYg Nef7dbu/1mOmFRbRZ7XtEyNtaqKs9Bvfrz7Zxa6d9JFPeXt9SfCrAq8QW5xALPzKpQF7 sRgA== X-Gm-Message-State: AG10YORo4z+UHyZkhbFL9PdUqFOdxjGoSEFTlZwAkUa7XDPQMwT2wneIgn4K+4XyUKz89A== 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-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::22e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:198962 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 --=-=-=--