bug in ~set-language-environment~ (was: XEmacs doesn't support windows-1252)

Mike FABIAN mfabian at suse.de
Tue Jul 31 09:23:57 EDT 2007


Aidan Kehoe <kehoea at parhasard.net> さんは書きました:

> But for most people that code should not be necessary if the locale was
> correctly determined at startup (before the window-system code) and if each
> language environment set the language-unicode-precedence-mapping. Is the
> language environment incorrectly set by default for you without your
> site-start.el? I’ve added code that handles that much better in the last
> year, so examining LANG may no longer be necessary.

I'll check later whether the precedence mapping is OK now without
my site-start.el.

But when I reviewed my language-environment related code in
site-start.el again, I found that at least saving the locale
environment is still necessary. In my site-start.el, I save the old
value of LANG before calling set-language-environment and then restore
it. Like this:

    (when (emacs-version>= 21 5 6)
      (let ((old-lang (getenv "LANG"))
            (case-fold-search nil))
        (when (getenv "LANG")
          (cond ((string-match "af" (getenv "LANG"))
                 (set-language-environment "Afrikaans"))

                 [... more calls to s-l-e for other languages ...]

                (t
                 (set-language-environment "English")))
          (setenv "LANG" old-lang)
          (set-current-locale old-lang))))

Please try this:

    (setenv "LANG" "ja_JP.UTF-8")
    (getenv "LANG")
    → "ja_JP.UTF-8"
    (set-language-environment "Japanese")
    (getenv "LANG")
    → "ja_JP.eucJP"

That is bad, ‘set-language-environment’ should not change the value of
LANG!

When I start my XEmacs in ja_JP.UTF-8 locale, I want subprocesses
started from XEmacs also use ja_JP.UTF-8 locale. But after
(set-language-environment "Japanese") subprocesses are suddenly
started in ja_JP.eucJP locale, which causes problems.

I believe that if an UTF-8 locale is already used, XEmacs should *not*
switch to a non-UTF-8 locale when calling 'set-language-environment.

Probably it is best not to change the locale at all in
‘set-language-environment’. That's why I restore the old LANG value in
site-start.el.

Changing from ja_JP.UTF-8 to de_DE.UTF-8 and back to ja_JP.UTF-8
when calling

    (set-language-environment "German")
    (set-language-environment "Japanese")

might be acceptable (although I still doubt that this would
be useful).

But changing from a xx_YY.UTF-8 locale to a locale with a non-UTF-8
encoding is just broken. It will cause problems for external programs
called from XEmacs.

By the way, I reported this problem already some time ago, in February
2004 (Message-ID: <s3tllmsmzym.fsf at magellan.suse.de>). But I cannot
find this message in the archive, it is in my outgoing mail archive
but it may not have reached the xemacs-beta list for whatever reason.

-- 
Mike FABIAN   <mfabian at suse.de>   http://www.suse.de/~mfabian
睡眠不足はいい仕事の敵だ。
I � Unicode




More information about the XEmacs-Beta mailing list