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: Emacs OS X GUI doesn't set locale Date: Mon, 25 Jan 2016 22:18:21 +0000 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1453760327 15839 80.91.229.3 (25 Jan 2016 22:18:47 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 25 Jan 2016 22:18:47 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jan 25 23:18:34 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 1aNpSz-0001M0-8B for ged-emacs-devel@m.gmane.org; Mon, 25 Jan 2016 23:18:33 +0100 Original-Received: from localhost ([::1]:41038 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNpSy-0002X5-HM for ged-emacs-devel@m.gmane.org; Mon, 25 Jan 2016 17:18:32 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:32943) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNpSs-0002WQ-Uf for emacs-devel@gnu.org; Mon, 25 Jan 2016 17:18:28 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aNpSr-0006c9-G9 for emacs-devel@gnu.org; Mon, 25 Jan 2016 17:18:26 -0500 Original-Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]:35816) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNpSr-0006c5-4X for emacs-devel@gnu.org; Mon, 25 Jan 2016 17:18:25 -0500 Original-Received: by mail-wm0-x236.google.com with SMTP id r129so82519217wmr.0 for ; Mon, 25 Jan 2016 14:18:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=sender:from:to:subject:date:message-id:mime-version:content-type; bh=02bzI1wqwq1H3ssHfyQuN9Oq2BHrIDrzFhs5jtLfdRE=; b=uz+0XEllJPKomda4Zr0IlK9rbwsYARVt6eoDVbCyGZvSIbRvpQ8VZTNJQ0cDtyPPRO Hn6gMDgLBG6czejCDCpJEzCZSv3jr7CrFNpVV1g95wUlKPPgqdsKZdqXifLalCqynD/l XMW36+jHzuiQU6GyMeM9P7mI98MExtb2HfR+Ar/23ZBdbrrKrM7c4GDzD26md5eAuVu9 CoffUcshGD6Kce+tRai6rOxH+RUPjumfCe5NvanE5Suyj+VjjDDeUatCtj2vc8CIwYST nBk4mmPXcXyEC14hf445XJWQ8hydnnvnPTI6BBqLh3HnJHc1AikkryBqMoLWqXo2KnIQ Uw5w== 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:subject:date:message-id :mime-version:content-type; bh=02bzI1wqwq1H3ssHfyQuN9Oq2BHrIDrzFhs5jtLfdRE=; b=h+FBTgFqBg6jR1yt0VEs7mOIEd80EAwl9zpQfBkEee/vqLwC8o2ir8vjTj15etAx7S NFr70zVPAjMtAlFArLNPA8aUxITJalHzwQiOObZ0cxsCiVzG9wNHynzQl23D1oNese6M 88g/nTpMEYToksXcPrSu00KtAqISrIzGHZgaqLw13EcHCLcr3I/ykw/Wbyku/O8Lztn+ /wd5oTa0tFzWB7en3GxBfqzA4G8YeQN9DBZeHw1iI4yTJjXTdb4wiJzYeN8r3x+wwrjW 4/uI4JhSfsMmdK399L71V3QFoMNRcRGwpgdNM0V3Ujw8zat0ONpz0Ky19uBPYSBWWcHj XVQQ== X-Gm-Message-State: AG10YOSl6/yxPEsEu1SBdqcS9aGj2J/Y+owdmMhDE2dHjMhc32tyDx27UtTrD7tFiqqPQA== X-Received: by 10.194.243.103 with SMTP id wx7mr22294409wjc.136.1453760304130; Mon, 25 Jan 2016 14:18:24 -0800 (PST) Original-Received: from galloway.idiocy.org (8.8.e.8.5.4.6.0.9.b.3.0.8.9.0.c.9.2.1.8.8.f.3.0.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:3f8:8129:c098:3b9:645:8e88]) by smtp.gmail.com with ESMTPSA id y188sm36493wmy.11.2016.01.25.14.18.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Jan 2016 14:18:23 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::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:198818 Archived-At: --=-=-= Content-Type: text/plain 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? --=-=-= 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 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 . */ #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) --=-=-= Content-Type: text/plain -- Alan Third --=-=-=--