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, emacs-devel <emacs-devel@gnu.org>
Subject: bug#22392: Emacs OS X GUI doesn't set locale
Date: Tue, 26 Jan 2016 08:11:13 +0100	[thread overview]
Message-ID: <CABr8ebazqBT5tVtRc_bDj0x72gR52T=zAmmamyhkTB8e4pz6rg__19379.7935302884$1453792343$gmane$org@mail.gmail.com> (raw)
In-Reply-To: <m27fix2thu.fsf@galloway.idiocy.org>

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

Hi,

This sounds like a good change. Unfortunately, I can't answer the
locale-questions you raised in the mail. However, I have a few small
questions:

* Why a separate source file? Is there any technical reasons why this
couldn't reside in, say, nsterm.m?

* Can you add a "NSTRACE" line to the function, so that it's clear when
this function is called, when NSTRACE is enabled.

* Have you considered populating `process-environment' instead of setting
LANG in the Emacs process? Would there be any advantages/disadvantages with
this approach?

    -- Anders Lindgren

On Mon, Jan 25, 2016 at 11:18 PM, Alan Third <alan@idiocy.org> wrote:

> I've raised a bug (bug#22392) about Emacs on OS X not setting the locale
> and character encodings when launched from the GUI (finder, spotlight,
> etc.). As far as I can tell it's because Emacs looks at LC_ALL, LC_TYPE
> and LANG for the locale information, but it's not set when launched from
> the GUI. It IS set in terminal.app, so if you launch from there it all
> looks good.
>
> Apparently the Windows version has the same problem and sorts it by
> setting LANG from a function called early in in main in emacs.c.
>
> I've written a patch that copies this method. It calls the NextStep
> function for getting the locale and then sets LANG if it's not already
> set. I'm not sure that's it's the best way of doing it. I had to create
> a new Objective C file and header to include in emacs.c.
>
> There was also a question raised about what the correct character
> encodings are for OS X. On my machine it sets LANG to en_GB and most of
> the character encodings to iso-latin-1-unix, which looks OK to me, but
> it was suggested that they should be UTF-8.
>
> Does anyone know what the correct encodings are on OS X?
>
>
> From 85d5d2f0213e052d1eccb6dc9e00f090b894ef90 Mon Sep 17 00:00:00 2001
> From: Alan Third <alan@idiocy.org>
> Date: Sun, 17 Jan 2016 13:56:12 +0000
> Subject: [PATCH] Set locale when run from OS X GUI
>
> * configure.ac: Add nsinit.o to NS_OBJC_OBJ and link the Foundation
> framework.
> * src/emacs.c (main): Include nsinit.h and run init_environment.
> * src/nsinit.c (init_environment): Get locale from OS and set LANG.
> * src/nsinit.h: header for including nsinit.c.
> ---
>  configure.ac |  4 ++--
>  src/emacs.c  |  8 ++++++++
>  src/nsinit.h | 20 ++++++++++++++++++++
>  src/nsinit.m | 33 +++++++++++++++++++++++++++++++++
>  4 files changed, 63 insertions(+), 2 deletions(-)
>  create mode 100644 src/nsinit.h
>  create mode 100644 src/nsinit.m
>
> diff --git a/configure.ac b/configure.ac
> index 6c9b621..7f61344 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -1892,7 +1892,7 @@ if test "${HAVE_NS}" = yes; then
>       INSTALL_ARCH_INDEP_EXTRA=
>    fi
>
> -  NS_OBJC_OBJ="nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o
> $ns_fontfile"
> +  NS_OBJC_OBJ="nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o nsinit.o
> $ns_fontfile"
>  fi
>  CFLAGS="$tmp_CFLAGS"
>  CPPFLAGS="$tmp_CPPFLAGS"
> @@ -5083,7 +5083,7 @@ case "$opsys" in
>     ## only costs about 1.5K of wasted binary space.
>     headerpad_extra=1000
>     if test "$HAVE_NS" = "yes"; then
> -     libs_nsgui="-framework AppKit"
> +     libs_nsgui="-framework AppKit -framework Foundation"
>       if test "$NS_IMPL_COCOA" = "yes"; then
>          libs_nsgui="$libs_nsgui -framework IOKit"
>       fi
> diff --git a/src/emacs.c b/src/emacs.c
> index b1b2170..9473bcd 100644
> --- a/src/emacs.c
> +++ b/src/emacs.c
> @@ -56,6 +56,10 @@ along with GNU Emacs.  If not, see <
> http://www.gnu.org/licenses/>.  */
>  #include <binary-io.h>
>  #endif
>
> +#ifdef HAVE_NS
> +#include "nsinit.h"
> +#endif
> +
>  #ifdef HAVE_WINDOW_SYSTEM
>  #include TERM_HEADER
>  #endif /* HAVE_WINDOW_SYSTEM */
> @@ -1371,6 +1375,10 @@ 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
> +  init_environment();
> +#endif
> +
>    /* Initialize and GC-protect Vinitial_environment and
>       Vprocess_environment before set_initial_environment fills them
>       in.  */
> diff --git a/src/nsinit.h b/src/nsinit.h
> new file mode 100644
> index 0000000..41b79c8
> --- /dev/null
> +++ b/src/nsinit.h
> @@ -0,0 +1,20 @@
> +/* Definitions for initialising NeXT/Open/GNUstep environment
> +   Copyright (C) 2016 Free Software Foundation,
> +   Inc.
> +
> +This file is part of GNU Emacs.
> +
> +GNU Emacs is free software: you can redistribute it and/or modify
> +it under the terms of the GNU General Public License as published by
> +the Free Software Foundation, either version 3 of the License, or
> +(at your option) any later version.
> +
> +GNU Emacs is distributed in the hope that it will be useful,
> +but WITHOUT ANY WARRANTY; without even the implied warranty of
> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +GNU General Public License for more details.
> +
> +You should have received a copy of the GNU General Public License
> +along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
> +
> +void init_environment (void);
> diff --git a/src/nsinit.m b/src/nsinit.m
> new file mode 100644
> index 0000000..32281a6
> --- /dev/null
> +++ b/src/nsinit.m
> @@ -0,0 +1,33 @@
> +/* NeXT/Open/GNUstep / MacOSX initialisation functions.      -*- coding:
> utf-8 -*-
> +
> +Copyright (C) 1989, 1993-1994, 2005-2006, 2008-2016 Free Software
> +Foundation, Inc.
> +
> +This file is part of GNU Emacs.
> +
> +GNU Emacs is free software: you can redistribute it and/or modify
> +it under the terms of the GNU General Public License as published by
> +the Free Software Foundation, either version 3 of the License, or
> +(at your option) any later version.
> +
> +GNU Emacs is distributed in the hope that it will be useful,
> +but WITHOUT ANY WARRANTY; without even the implied warranty of
> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +GNU General Public License for more details.
> +
> +You should have received a copy of the GNU General Public License
> +along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
> +
> +#include <config.h>
> +#include <Foundation/Foundation.h>
> +
> +/* Set up the environment in cases where Emacs has been run from the
> +   GUI and therefore has missing environment variables. */
> +void
> +init_environment (void)
> +{
> +    const char * locale = [[[NSLocale currentLocale] localeIdentifier]
> UTF8String];
> +
> +    /* Set LANG to locale, but not if LANG is already set. */
> +    setenv("LANG", locale, 0);
> +}
> --
> 2.5.4 (Apple Git-61)
>
>
>
>
> --
> Alan Third
>
>

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

       reply	other threads:[~2016-01-26  7:11 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 ` Anders Lindgren [this message]
     [not found] ` <CABr8ebazqBT5tVtRc_bDj0x72gR52T=zAmmamyhkTB8e4pz6rg@mail.gmail.com>
2016-01-26 14:44   ` bug#22392: Emacs OS X GUI doesn't set locale 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
     [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='CABr8ebazqBT5tVtRc_bDj0x72gR52T=zAmmamyhkTB8e4pz6rg__19379.7935302884$1453792343$gmane$org@mail.gmail.com' \
    --to=andlind@gmail.com \
    --cc=22392@debbugs.gnu.org \
    --cc=alan@idiocy.org \
    --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).