From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Anders Lindgren Newsgroups: gmane.emacs.devel Subject: Re: Emacs OS X GUI doesn't set locale Date: Tue, 26 Jan 2016 08:11:13 +0100 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a114406ea05dc35052a3764f5 X-Trace: ger.gmane.org 1453792306 32038 80.91.229.3 (26 Jan 2016 07:11:46 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 26 Jan 2016 07:11:46 +0000 (UTC) Cc: 22392@debbugs.gnu.org, emacs-devel To: Alan Third Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jan 26 08:11:38 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 1aNxmr-0003f9-62 for ged-emacs-devel@m.gmane.org; Tue, 26 Jan 2016 08:11:37 +0100 Original-Received: from localhost ([::1]:42245 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNxmq-0001jY-EN for ged-emacs-devel@m.gmane.org; Tue, 26 Jan 2016 02:11:36 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54486) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNxmX-0001jK-J3 for emacs-devel@gnu.org; Tue, 26 Jan 2016 02:11:19 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aNxmV-00023W-9f for emacs-devel@gnu.org; Tue, 26 Jan 2016 02:11:17 -0500 Original-Received: from mail-vk0-x236.google.com ([2607:f8b0:400c:c05::236]:33747) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNxmV-00023M-2j for emacs-devel@gnu.org; Tue, 26 Jan 2016 02:11:15 -0500 Original-Received: by mail-vk0-x236.google.com with SMTP id e64so87709065vkg.0 for ; Mon, 25 Jan 2016 23:11:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=z1FZThLkIND2G5Y057ETp19TvlMrny9jjAFu1iXki/Q=; b=vv4kReFm9K9nsi2DvnqigKLZkk1Y4ZuiTg5hspLjCl0FG1cGGQEq9pPVK9rY0PUXlP HQZgivWzUSje70uknTFGEgSv9NNqBtrYd9b4ql5r24YHFPwpFdINBslevI/J1O8V7egV VGr2o1/JxtOUBLfHbmkNIx8aZAsxhvZhfUZNbsd9Qm0+akr516Rp2Sivw5GnJX6oY2E5 zxVjMAqBWxBrxJkBjdQqvTPQkiR1gmzw2yS3+qkHEC4LBthOnklXQDVaaBm/e9GtPdib 5Sw9BrPEpzgj57n+pDHhjciDmBfjmk6B6864is+24Qs2q6hkn8SW267hqidoZcVhw5Zd xb/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=z1FZThLkIND2G5Y057ETp19TvlMrny9jjAFu1iXki/Q=; b=RBqqnnCGnm9Q67TjKyGalPPXGW1a+8NFBHl1x25UpiO9K0UHJCXtiPZmQlLfLUgR8l ADUD1RptTt6UgU6B0i/8YKcK64rfwXljDSLEonJ8LYlQ1UIRfZqwnKRQ+tRqQl1Vbhhr b4T8bVDx09GQJqpcj4mDddIua0G9fEuRrrK/vqdoODz8j/FokhR9TexIw17bBqhQfnCg hSDCInoIgaVFN6WCiIMUBDhMWPx2T3AO1WL3w71hlKxtSgxIYu+SvWJ9f7IxxUSCG8od FUDFkZOgFuTOSxDLNtRJPX/0c3ThXcXfEjLc6HibRxa7kqUDPoQnfZX+DMkNJIFCzFfb 952Q== X-Gm-Message-State: AG10YOQ+YPebRvX59xcGV2ys3v7HPkxpAf9WB9HZB5FO4IQGkBHs1qC4XEAegjyYwGtB1cr2NCBxUayWOUaUWQ== X-Received: by 10.31.162.3 with SMTP id l3mr13614600vke.68.1453792273224; Mon, 25 Jan 2016 23:11:13 -0800 (PST) Original-Received: by 10.31.214.131 with HTTP; Mon, 25 Jan 2016 23:11:13 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400c:c05::236 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:198832 Archived-At: --001a114406ea05dc35052a3764f5 Content-Type: text/plain; charset=UTF-8 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 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 > 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 > #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 . */ > + > +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 . */ > + > +#include > +#include > + > +/* 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 > > --001a114406ea05dc35052a3764f5 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi,

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

* Why a se= parate source file? Is there any technical reasons why this couldn't re= side in, say, nsterm.m?

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

* Have you cons= idered populating `process-environment' instead of setting LANG in the = Emacs process? Would there be any advantages/disadvantages with this approa= ch?

=C2=A0 =C2=A0 -- Anders Lindgren

On Mon, Jan 25, 201= 6 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 fro= m
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<= br> set. I'm not sure that's it's the best way of doing it. I had t= o 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<= br> 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

* conf= igure.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.
---
=C2=A0= configure.ac |=C2=A0 4 ++--
=C2=A0src/emacs.c=C2=A0 |=C2=A0 8 ++++++++
=C2=A0src/nsinit.h | 20 ++++++++++++++++++++
=C2=A0src/nsinit.m | 33 +++++++++++++++++++++++++++++++++
=C2=A04 files changed, 63 insertions(+), 2 deletions(-)
=C2=A0create mode 100644 src/nsinit.h
=C2=A0create 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}" =3D yes; then
=C2=A0 =C2=A0 =C2=A0 INSTALL_ARCH_INDEP_EXTRA=3D
=C2=A0 =C2=A0fi

-=C2=A0 NS_OBJC_OBJ=3D"nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o = $ns_fontfile"
+=C2=A0 NS_OBJC_OBJ=3D"nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o = nsinit.o $ns_fontfile"
=C2=A0fi
=C2=A0CFLAGS=3D"$tmp_CFLAGS"
=C2=A0CPPFLAGS=3D"$tmp_CPPFLAGS"
@@ -5083,7 +5083,7 @@ case "$opsys" in
=C2=A0 =C2=A0 ## only costs about 1.5K of wasted binary space.
=C2=A0 =C2=A0 headerpad_extra=3D1000
=C2=A0 =C2=A0 if test "$HAVE_NS" =3D "yes"; then
-=C2=A0 =C2=A0 =C2=A0libs_nsgui=3D"-framework AppKit"
+=C2=A0 =C2=A0 =C2=A0libs_nsgui=3D"-framework AppKit -framework Founda= tion"
=C2=A0 =C2=A0 =C2=A0 if test "$NS_IMPL_COCOA" =3D "yes"= ; then
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0libs_nsgui=3D"$libs_nsgui -framework= IOKit"
=C2=A0 =C2=A0 =C2=A0 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.=C2=A0 If not, see <http://ww= w.gnu.org/licenses/>.=C2=A0 */
=C2=A0#include <binary-io.h>
=C2=A0#endif

+#ifdef HAVE_NS
+#include "nsinit.h"
+#endif
+
=C2=A0#ifdef HAVE_WINDOW_SYSTEM
=C2=A0#include TERM_HEADER
=C2=A0#endif /* HAVE_WINDOW_SYSTEM */
@@ -1371,6 +1375,10 @@ Using an Emacs configured with --with-x-toolkit=3Dlu= cid does not have this problem
=C2=A0 =C2=A0init_ntproc (dumping); /* must precede init_editfns.=C2=A0 */<= br> =C2=A0#endif

+#ifdef HAVE_NS
+=C2=A0 init_environment();
+#endif
+
=C2=A0 =C2=A0/* Initialize and GC-protect Vinitial_environment and
=C2=A0 =C2=A0 =C2=A0 Vprocess_environment before set_initial_environment fi= lls them
=C2=A0 =C2=A0 =C2=A0 in.=C2=A0 */
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
+=C2=A0 =C2=A0Copyright (C) 2016 Free Software Foundation,
+=C2=A0 =C2=A0Inc.
+
+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.=C2=A0 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.=C2=A0 If not, see <http://www.gnu.org/licenses= />.=C2=A0 */
+
+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.=C2=A0 =C2=A0 =C2= =A0 -*- 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.=C2=A0 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.=C2=A0 If not, see <http://www.gnu.org/licenses= />.=C2=A0 */
+
+#include <config.h>
+#include <Foundation/Foundation.h>
+
+/* Set up the environment in cases where Emacs has been run from the
+=C2=A0 =C2=A0GUI and therefore has missing environment variables. */
+void
+init_environment (void)
+{
+=C2=A0 =C2=A0 const char * locale =3D [[[NSLocale currentLocale] localeIde= ntifier] UTF8String];
+
+=C2=A0 =C2=A0 /* Set LANG to locale, but not if LANG is already set. */ +=C2=A0 =C2=A0 setenv("LANG", locale, 0);
+}
--
2.5.4 (Apple Git-61)




--
Alan Third


--001a114406ea05dc35052a3764f5--