unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Anders Lindgren <andlind@gmail.com>
To: Alan Third <alan@idiocy.org>
Cc: 22392@debbugs.gnu.org, Paul Eggert <eggert@cs.ucla.edu>,
	emacs-devel <emacs-devel@gnu.org>
Subject: bug#22392: Emacs OS X GUI doesn't set locale
Date: Mon, 1 Feb 2016 06:03:30 +0100	[thread overview]
Message-ID: <CABr8ebZ21MwYwDTeHogk4Afg7m73LGiiiVWNz2y=tJ0SSSsysQ__22038.86106513$1454303063$gmane$org@mail.gmail.com> (raw)
In-Reply-To: <m260ydxqmp.fsf@galloway.idiocy.org>

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

Hi!

Today, I tested this patch on OS X and GNUstep. From what I can see, it
applies cleanly and work as intended.

As the LANG variable is set early in the initialisation process, it will be
propagated to `process-environment' and thus set for all processes started
by Emacs.

I suggest that we apply this patch, so that it will be included in the next
Emacs 25 pretest.

    -- Anders Lindgren

On Thu, Jan 28, 2016 at 11:53 PM, Alan Third <alan@idiocy.org> wrote:

> Paul Eggert <eggert@cs.ucla.edu> 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.
>
>
> From b96c97cb16a980243389c01c10c5ab232fe6827e Mon Sep 17 00:00:00 2001
> From: Alan Third <alan@idiocy.org>
> 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)
>
>
>
> --
> Alan Third
>
>

[-- Attachment #2: Type: text/html, Size: 5137 bytes --]

  parent reply	other threads:[~2016-02-01  5:03 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <m27fix2thu.fsf@galloway.idiocy.org>
2016-01-26  7:11 ` bug#22392: Emacs OS X GUI doesn't set locale Anders Lindgren
     [not found] ` <CABr8ebazqBT5tVtRc_bDj0x72gR52T=zAmmamyhkTB8e4pz6rg@mail.gmail.com>
2016-01-26 14:44   ` Eli Zaretskii
     [not found]   ` <83twm01ju1.fsf@gnu.org>
2016-01-26 15:06     ` Anders Lindgren
     [not found]     ` <CABr8ebbTc1no_vra4m2Q6sbC=VqaZ4Xn8OGnQu78Z=uquKpGRA@mail.gmail.com>
2016-01-26 15:14       ` Eli Zaretskii
     [not found]       ` <83lh7c1igo.fsf@gnu.org>
2016-01-26 16:58         ` Anders Lindgren
2016-01-26 23:05         ` Alan Third
     [not found]         ` <m2bn880wna.fsf@galloway.idiocy.org>
2016-01-27 18:06           ` Paul Eggert
2016-01-17 14:27             ` bug#22392: 25.0.50; NS Emacs run from " Alan Third
2016-01-17 22:38               ` Random832
2016-01-18 21:12                 ` Alan Third
2016-01-18 22:09                   ` Random832
2016-01-18 23:11                     ` Alan Third
2016-01-19 15:55                       ` Eli Zaretskii
2016-01-19 16:03                     ` Eli Zaretskii
2016-01-30  6:13               ` bug#22392: Emacs " Random832
2016-02-05  7:12               ` Random832
2016-02-05  7:32                 ` Eli Zaretskii
2016-02-05  7:36                   ` Random832
2016-02-05  9:21                     ` Eli Zaretskii
2016-02-05 17:28                       ` Random832
2016-02-05 19:46                         ` Eli Zaretskii
     [not found]           ` <56A90735.7090508@cs.ucla.edu>
2016-01-27 19:44             ` Eli Zaretskii
     [not found]             ` <83fuxizu1d.fsf@gnu.org>
2016-01-27 22:27               ` Paul Eggert
2016-01-28 22:53             ` Alan Third
     [not found]             ` <m260ydxqmp.fsf@galloway.idiocy.org>
2016-02-01  5:03               ` Anders Lindgren [this message]
     [not found]               ` <CABr8ebZ21MwYwDTeHogk4Afg7m73LGiiiVWNz2y=tJ0SSSsysQ@mail.gmail.com>
2016-02-01 17:48                 ` Alan Third
2016-02-01 18:57                 ` Eli Zaretskii
2016-02-10 23:57                 ` Alan Third
2016-02-11  2:37                   ` Paul Eggert
2016-01-26 22:50   ` Alan Third
     [not found]   ` <m2fuxk0xbz.fsf@galloway.idiocy.org>
2016-01-27  6:21     ` Anders Lindgren
     [not found]     ` <CABr8ebb55SEwE2MOnKdSYm=xO6VReRU8g_dr0vN4CGMVwVYrvg@mail.gmail.com>
2016-01-27 15:53       ` Eli Zaretskii

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='CABr8ebZ21MwYwDTeHogk4Afg7m73LGiiiVWNz2y=tJ0SSSsysQ__22038.86106513$1454303063$gmane$org@mail.gmail.com' \
    --to=andlind@gmail.com \
    --cc=22392@debbugs.gnu.org \
    --cc=alan@idiocy.org \
    --cc=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    /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).