From 78c438b24cb64c70b5c97b87ad1cd8b6923d07f5 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Thu, 24 Nov 2011 08:35:26 +0000 Subject: [PATCH] Don't fail with an error when starting in a terminal environment without the "locale" command (fixes #6) --- init-locales.el | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/init-locales.el b/init-locales.el index b9f9ddf3f3..855fcdf43f 100644 --- a/init-locales.el +++ b/init-locales.el @@ -1,4 +1,12 @@ -(when (or window-system (string-match "UTF-8" (shell-command-to-string "locale"))) +(defun locale-is-utf8-p () + "Return t iff the \"locale\" command or environment variables prefer UTF-8." + (flet ((is-utf8 (v) (and v (string-match "UTF-8" v)))) + (or (is-utf8 (and (executable-find "locale") (shell-command-to-string "locale"))) + (is-utf8 (getenv "LC_ALL")) + (is-utf8 (getenv "LC_CTYPE")) + (is-utf8 (getenv "LANG"))))) + +(when (or window-system (locale-is-utf8-p)) (setq utf-translate-cjk-mode nil) ; disable CJK coding/encoding (Chinese/Japanese/Korean characters) (set-language-environment 'utf-8) (when *is-carbon-emacs* @@ -9,4 +17,4 @@ (set-selection-coding-system 'utf-8) (prefer-coding-system 'utf-8)) -(provide 'init-locales) \ No newline at end of file +(provide 'init-locales)