]> code.delx.au - gnu-emacs/blobdiff - lisp/international/mule-cmds.el
Merged in changes from CVS trunk.
[gnu-emacs] / lisp / international / mule-cmds.el
index 49eaa1db9adfc06bfcd69b76cd47070893c96a62..510a3c9358d8c495883894972b09a479a4752137 100644 (file)
@@ -1,4 +1,4 @@
-;;; mule-cmds.el --- commands for mulitilingual environment
+;;; mule-cmds.el --- commands for mulitilingual environment -*-coding: iso-2022-7bit -*-
 ;; Copyright (C) 1995, 2003 Electrotechnical Laboratory, JAPAN.
 ;; Licensed to the Free Software Foundation.
 ;; Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
@@ -288,12 +288,12 @@ wrong, use this command again to toggle back to the right mode."
               (not (eq cmd 'universal-argument-other-key)))
        (let ((current-prefix-arg prefix-arg)
              ;; Have to bind `last-command-char' here so that
-             ;; `digit-argument', for isntance, can compute the
+             ;; `digit-argument', for instance, can compute the
              ;; prefix arg.
              (last-command-char (aref keyseq 0)))
          (call-interactively cmd)))
 
-      ;; This is the final call to `univeral-argument-other-key', which
+      ;; This is the final call to `universal-argument-other-key', which
       ;; set's the final `prefix-arg.
       (let ((current-prefix-arg prefix-arg))
        (call-interactively cmd))
@@ -321,6 +321,11 @@ This also sets the following values:
   o default value for the command `set-keyboard-coding-system'."
   (check-coding-system coding-system)
   (setq-default buffer-file-coding-system coding-system)
+  (if (fboundp 'ucs-set-table-for-input)
+      (dolist (buffer (buffer-list))
+       (or (local-variable-p 'buffer-file-coding-system buffer)
+           (ucs-set-table-for-input buffer))))
+
   (if default-enable-multibyte-characters
       (setq default-file-name-coding-system coding-system))
   ;; If coding-system is nil, honor that on MS-DOS as well, so
@@ -541,7 +546,7 @@ The return value is an alist of the following format:
 where
   CHARSET is a character set,
   COUNT is a number of characters,
-  CHARs are found characters of the character set.
+  CHARs are the characters found from the character set.
 Optional 3rd arg MAXCOUNT limits how many CHARs are put in the above list.
 Optional 4th arg EXCLUDE is a list of character sets to be ignored.
 
@@ -887,7 +892,7 @@ one of the following safe coding systems, or edit the buffer:\n")
                (insert "\n")
                (fill-region-as-paragraph pos (point)))
              (insert "Or specify any other coding system
-on your risk of losing the problematic characters.\n")))
+at the risk of losing the problematic characters.\n")))
 
          ;; Read a coding system.
          (setq default-coding-system (or (car safe) (car codings)))
@@ -921,13 +926,33 @@ on your risk of losing the problematic characters.\n")))
                         (goto-char (point-min))
                         (set-auto-coding (or file buffer-file-name "")
                                          (buffer-size))))))
-       (if (and auto-cs coding-system
+       ;; Merge coding-system and auto-cs as far as possible.
+       (if (not coding-system)
+           (setq coding-system auto-cs)
+         (if (not auto-cs)
+             (setq auto-cs coding-system)
+           (let ((eol-type-1 (coding-system-eol-type coding-system))
+                 (eol-type-2 (coding-system-eol-type auto-cs)))
+           (if (eq (coding-system-base coding-system) 'undecided)
+               (setq coding-system (coding-system-change-text-conversion
+                                    coding-system auto-cs))
+             (if (eq (coding-system-base auto-cs) 'undecided)
+                 (setq auto-cs (coding-system-change-text-conversion
+                                auto-cs coding-system))))
+           (if (vectorp eol-type-1)
+               (or (vectorp eol-type-2)
+                   (setq coding-system (coding-system-change-eol-conversion
+                                        coding-system eol-type-2)))
+             (if (vectorp eol-type-2)
+                 (setq auto-cs (coding-system-change-eol-conversion
+                                auto-cs eol-type-1)))))))
+
+       (if (and auto-cs
                 ;; Don't barf if writing a compressed file, say.
                 ;; This check perhaps isn't ideal, but is probably
                 ;; the best thing to do.
                 (not (auto-coding-alist-lookup (or file buffer-file-name "")))
-                (not (coding-system-equal (coding-system-base coding-system)
-                                          (coding-system-base auto-cs))))
+                (not (coding-system-equal coding-system auto-cs)))
            (unless (yes-or-no-p
                     (format "Selected encoding %s disagrees with \
 %s specified by file contents.  Really save (else edit coding cookies \
@@ -1001,6 +1026,12 @@ Meaningful values for KEY include
                        environment.
   features           value is a list of features requested in this
                        language environment.
+  ctext-non-standard-encodings
+                    value is a list of non-standard encoding
+                    names used in extended segments of CTEXT.
+                    See the variable
+                    `ctext-non-standard-encodings' for more
+                    detail.
 
 The following keys take effect only when multibyte characters are
 globally disabled, i.e. the value of `default-enable-multibyte-characters'
@@ -1023,7 +1054,7 @@ For a list of useful values for KEY and their meanings,
 see `language-info-alist'."
   (if (symbolp lang-env)
       (setq lang-env (symbol-name lang-env)))
-  (let ((lang-slot (assoc-ignore-case lang-env language-info-alist)))
+  (let ((lang-slot (assoc-string lang-env language-info-alist t)))
     (if lang-slot
        (cdr (assq key (cdr lang-slot))))))
 
@@ -1191,8 +1222,13 @@ If nil, that means no input method is activated now.")
   "*Default input method for multilingual text (a string).
 This is the input method activated automatically by the command
 `toggle-input-method' (\\[toggle-input-method])."
+  :link  '(custom-manual "(emacs)Input Methods")
   :group 'mule
-  :type '(choice (const nil) string)
+  :type '(choice (const nil) (string
+                             :completion-ignore-case t
+                             :complete-function widget-string-complete
+                             :completion-alist input-method-alist
+                             :prompt-history input-method-history))
   :set-after '(current-language-environment))
 
 (put 'input-method-function 'permanent-local t)
@@ -1332,12 +1368,14 @@ If INPUT-METHOD is nil, deactivate any current input method."
              current-input-method-title nil)
        (force-mode-line-update)))))
 
-(defun set-input-method (input-method)
+(defun set-input-method (input-method &optional interactive)
   "Select and activate input method INPUT-METHOD for the current buffer.
 This also sets the default input method to the one you specify.
 If INPUT-METHOD is nil, this function turns off the input method, and
 also causes you to be prompted for a name of an input method the next
 time you invoke \\[toggle-input-method].
+When called interactively, the optional arg INTERACTIVE is non-nil,
+which marks the variable `default-input-method' as set for Custom buffers.
 
 To deactivate the input method interactively, use \\[toggle-input-method].
 To deactivate it programmatically, use \\[inactivate-input-method]."
@@ -1345,14 +1383,15 @@ To deactivate it programmatically, use \\[inactivate-input-method]."
    (let* ((default (or (car input-method-history) default-input-method)))
      (list (read-input-method-name
            (if default "Select input method (default %s): " "Select input method: ")
-           default t))))
+           default t)
+          t)))
   (activate-input-method input-method)
   (setq default-input-method input-method)
-  (when (interactive-p)
+  (when interactive
     (customize-mark-as-set 'default-input-method))
   default-input-method)
 
-(defun toggle-input-method (&optional arg)
+(defun toggle-input-method (&optional arg interactive)
   "Enable or disable multilingual text input method for the current buffer.
 Only one input method can be enabled at any time in a given buffer.
 
@@ -1365,9 +1404,12 @@ minibuffer.
 
 With a prefix argument, read an input method name with the minibuffer
 and enable that one.  The default is the most recent input method specified
-\(not including the currently active input method, if any)."
+\(not including the currently active input method, if any).
 
-  (interactive "P")
+When called interactively, the optional arg INTERACTIVE is non-nil,
+which marks the variable `default-input-method' as set for Custom buffers."
+
+  (interactive "P\np")
   (if (and current-input-method (not arg))
       (inactivate-input-method)
     (let ((default (or (car input-method-history) default-input-method)))
@@ -1384,7 +1426,7 @@ and enable that one.  The default is the most recent input method specified
       (unless default-input-method
        (prog1
            (setq default-input-method current-input-method)
-         (when (interactive-p)
+         (when interactive
            (customize-mark-as-set 'default-input-method)))))))
 
 (defun describe-input-method (input-method)
@@ -1561,11 +1603,11 @@ to using the function `set-language-environment'."
   :link '(custom-manual "(emacs)Language Environments")
   :set (lambda (symbol value) (set-language-environment value))
   :get (lambda (x)
-        (or (car-safe (assoc-ignore-case
+        (or (car-safe (assoc-string
                        (if (symbolp current-language-environment)
                            (symbol-name current-language-environment)
                          current-language-environment)
-                       language-info-alist))
+                       language-info-alist t))
             "English"))
   ;; custom type will be updated with `set-language-info'.
   :type (if language-info-alist
@@ -1675,7 +1717,12 @@ The default status is as follows:
   ;; (set-keyboard-coding-system-internal nil)
 
   (setq nonascii-translation-table nil
-       nonascii-insert-offset 0))
+       nonascii-insert-offset 0)
+
+  ;; Don't invoke fontset-related functions if fontsets aren't
+  ;; supported in this build of Emacs.
+  (and (fboundp 'fontset-list)
+       (set-overriding-fontspec-internal nil)))
 
 (reset-language-environment)
 
@@ -1708,8 +1755,10 @@ specifies the character set for the major languages of Western Europe."
       (if (symbolp language-name)
          (setq language-name (symbol-name language-name)))
     (setq language-name "English"))
-  (or (assoc-ignore-case language-name language-info-alist)
+  (let ((slot (assoc-string language-name language-info-alist t)))
+    (unless slot
       (error "Language environment not defined: %S" language-name))
+    (setq language-name (car slot)))
   (if current-language-environment
       (let ((func (get-language-info current-language-environment
                                     'exit-function)))
@@ -1779,9 +1828,27 @@ specifies the character set for the major languages of Western Europe."
     (while required-features
       (require (car required-features))
       (setq required-features (cdr required-features))))
+
+  ;; Don't invoke fontset-related functions if fontsets aren't
+  ;; supported in this build of Emacs.
+  (when (fboundp 'fontset-list)
+    (let ((overriding-fontspec (get-language-info language-name 
+                                                 'overriding-fontspec)))
+      (if overriding-fontspec
+         (set-overriding-fontspec-internal overriding-fontspec))))
+
   (let ((func (get-language-info language-name 'setup-function)))
     (if (functionp func)
        (funcall func)))
+  (if (and utf-translate-cjk-mode
+          utf-translate-cjk-lang-env
+          (not (eq utf-translate-cjk-lang-env language-name))
+          (catch 'tag
+            (dolist (charset (get-language-info language-name 'charset))
+              (if (memq charset utf-translate-cjk-charsets)
+                  (throw 'tag t)))
+            nil))
+      (utf-translate-cjk-load-tables))
   (run-hooks 'set-language-environment-hook)
   (force-mode-line-update t))
 
@@ -1798,7 +1865,7 @@ specifies the character set for the major languages of Western Europe."
        (aset standard-display-table 160 [32])
        ;; With luck, non-Latin-1 fonts are more recent and so don't
        ;; have this bug.
-       (aset standard-display-table 2208 [32]) ; Latin-1 NBSP
+       (aset standard-display-table (make-char 'latin-iso8859-1 160) [32])
        ;; Most Windows programs send out apostrophes as \222.  Most X fonts
        ;; don't contain a character at that position.  Map it to the ASCII
        ;; apostrophe.  [This is actually RIGHT SINGLE QUOTATION MARK,
@@ -1806,7 +1873,23 @@ specifies the character set for the major languages of Western Europe."
        ;; fonts probably have the appropriate glyph at this position,
        ;; so they could use standard-display-8bit.  It's better to use a
        ;; proper windows-1252 coding system.  --fx]
-       (aset standard-display-table 146 [39]))))
+       (aset standard-display-table 146 [39])
+       ;; XFree86 4 has changed most of the fonts from their designed
+       ;; versions such that `' no longer appears as balanced quotes.
+       ;; Assume it has iso10646 fonts installed, so we can display
+       ;; balanced quotes.
+       (when (and (eq window-system 'x)
+                  (string= "The XFree86 Project, Inc" (x-server-vendor))
+                  (> (aref (number-to-string (nth 2 (x-server-version))) 0)
+                     ?3))
+         ;; We suppress these setting for the moment because the
+         ;; above assumption is wrong.
+         ;; (aset standard-display-table ?' [?\e$,1ry\e(B])
+         ;; (aset standard-display-table ?` [?\e$,1rx\e(B])
+         ;; The fonts don't have the relevant bug.
+         (aset standard-display-table 160 nil)
+         (aset standard-display-table (make-char 'latin-iso8859-1 160)
+               nil)))))
 
 (defun set-language-environment-coding-systems (language-name
                                                &optional eol-type)
@@ -1836,7 +1919,7 @@ of `buffer-file-coding-system' set by this function."
 
 (put 'describe-specified-language-support 'apropos-inhibit t)
 
-;; Print a language specific information such as input methods,
+;; Print language-specific information such as input methods,
 ;; charsets, and coding systems.  This function is intended to be
 ;; called from the menu:
 ;;   [menu-bar mule describe-language-environment LANGUAGE]
@@ -1960,6 +2043,13 @@ of `buffer-file-coding-system' set by this function."
     ;; http://www.din.de/gremien/nas/nabd/iso3166ma/codlstp1/en_listp1.html.
     ;; CODESET and MODIFIER are implementation-dependent.
 
+     ;; jasonr comments: MS Windows uses three letter codes for
+     ;; languages instead of the two letter ISO codes that POSIX
+     ;; uses. In most cases the first two letters are the same, so
+     ;; most of the regexps in locale-language-names work. Japanese
+     ;; and Chinese are exceptions, which are listed in the
+     ;; non-standard section at the bottom of locale-language-names.
+
     ; aa Afar
     ; ab Abkhazian
     ("af" . "Latin-1") ; Afrikaans
@@ -2153,13 +2243,13 @@ If the language name is nil, there is no corresponding language environment.")
      (".*8859[-_]?9\\>" . "Latin-5")
      (".*8859[-_]?14\\>" . "Latin-8")
      (".*8859[-_]?15\\>" . "Latin-9")
-     (".*utf\\(-?8\\)\\>" . "UTF-8")
+     (".*utf\\(?:-?8\\)?\\>" . "UTF-8")
      ;; utf-8@euro exists, so put this last.  (@euro really specifies
      ;; the currency, rather than the charset.)
      (".*@euro\\>" . "Latin-9")))
   "List of pairs of locale regexps and charset language names.
 The first element whose locale regexp matches the start of a downcased locale
-specifies the language name whose charsets corresponds to that locale.
+specifies the language name whose charset corresponds to that locale.
 This language name is used if its charsets disagree with the charsets of
 the language name that would otherwise be used for this locale.")
 
@@ -2186,36 +2276,45 @@ start of KEY, or nil if there is no match."
       (setq alist (cdr alist)))
     (cdr element)))
 
-(defun set-locale-environment (&optional locale-name)
-  "Set up multi-lingual environment for using LOCALE-NAME.
-This sets the language environment, the coding system priority,
-the default input method and sometimes other things.
-
-LOCALE-NAME should be a string
-which is the name of a locale supported by the system;
-often it is of the form xx_XX.CODE, where xx is a language,
-XX is a country, and CODE specifies a character set and coding system.
-For example, the locale name \"ja_JP.EUC\" might name a locale
-for Japanese in Japan using the `japanese-iso-8bit' coding-system.
-
-If LOCALE-NAME is nil, its value is taken from the environment
-variables LC_ALL, LC_CTYPE and LANG (the first one that is set).
-
-The locale names supported by your system can typically be found in a
-directory named `/usr/share/locale' or `/usr/lib/locale'.  LOCALE-NAME
-will be translated according to the table specified by
-`locale-translation-file-name'.
-
-See also `locale-charset-language-names', `locale-language-names',
-`locale-preferred-coding-systems' and `locale-coding-system'."
-  (interactive "sSet environment for locale: ")
-
-  ;; Do this at runtime for the sake of binaries possibly transported
-  ;; to a system without X.
+(defun locale-charset-match-p (charset1 charset2)
+  "Whether charset names (strings) CHARSET1 and CHARSET2 are equivalent.
+Matching is done ignoring case and any hyphens and underscores in the
+names.  E.g. `ISO_8859-1' and `iso88591' both match `iso-8859-1'."
+  (setq charset1 (replace-regexp-in-string "[-_]" "" charset1))
+  (setq charset2 (replace-regexp-in-string "[-_]" "" charset2))
+  (eq t (compare-strings charset1 nil nil charset2 nil nil t)))
+
+(defvar locale-charset-alist nil
+  "Coding system alist keyed on locale-style charset name.
+Used by `locale-charset-to-coding-system'.")
+
+(defun locale-charset-to-coding-system (charset)
+  "Find coding system corresponding to CHARSET.
+CHARSET is any sort of non-Emacs charset name, such as might be used
+in a locale codeset, or elsewhere.  It is matched to a coding system
+first by case-insensitive lookup in `locale-charset-alist'.  Then
+matches are looked for in the coding system list, treating case and
+the characters `-' and `_' as insignificant.  The coding system base
+is returned.  Thus, for instance, if charset \"ISO8859-2\",
+`iso-latin-2' is returned."
+  (or (car (assoc-string charset locale-charset-alist t))
+      (let ((cs coding-system-alist)
+           c)
+       (while (and (not c) cs)
+         (if (locale-charset-match-p charset (caar cs))
+             (setq c (intern (caar cs)))
+           (pop cs)))
+       (if c (coding-system-base c)))))
+
+(defun set-locale-translation-file-name ()
+  "Set up the locale-translation-file-name on the current system.
+
+This needs to be done at runtime for the sake of binaries
+possibly transported to a system without X."
   (setq locale-translation-file-name
        (let ((files
               '("/usr/lib/X11/locale/locale.alias" ; e.g. X11R6.4
-                "/usr/X11R6/lib/X11/locale/locale.alias" ; e.g. RedHat 4.2
+                "/usr/X11R6/lib/X11/locale/locale.alias" ; XFree86, e.g. RedHat 4.2
                 "/usr/openwin/lib/locale/locale.alias" ; e.g. Solaris 2.6
                 ;;
                 ;; The following name appears after the X-related names above,
@@ -2224,28 +2323,132 @@ See also `locale-charset-language-names', `locale-language-names',
                 )))
          (while (and files (not (file-exists-p (car files))))
            (setq files (cdr files)))
-         (car files)))
-
-  (let ((locale locale-name))
+         (car files))))
 
-    (unless locale
-      ;; Use the first of these three environment variables
-      ;; that has a nonempty value.
-      (let ((vars '("LC_ALL" "LC_CTYPE" "LANG")))
-       (while (and vars
-                   (= 0 (length locale))) ; nil or empty string
-         (setq locale (getenv (pop vars))))))
+(defun get-locale-real-name (&optional locale-name)
+  "Return the canonicalized name of locale LOCALE-NAME.
 
-    (when locale
+LOCALE-NAME should be a string which is the name of a locale supported
+by the system.  Often it is of the form xx_XX.CODE, where xx is a
+language, XX is a country, and CODE specifies a character set and
+coding system.  For example, the locale name \"ja_JP.EUC\" might name
+a locale for Japanese in Japan using the `japanese-iso-8bit'
+coding-system.  The name may also have a modifier suffix, e.g. `@euro'
+or `@cyrillic'.
 
+If LOCALE-NAME is nil, its value is taken from the environment
+variables LC_ALL, LC_CTYPE and LANG (the first one that is set).
+On server frames, the environment of the emacsclient process is
+used.
+
+See also `set-locale-environment'."
+  (unless locale-name
+    ;; Use the first of these three environment variables
+    ;; that has a nonempty value.
+    (let ((vars '("LC_ALL" "LC_CTYPE" "LANG")))
+      (while (and vars
+                 (= 0 (length locale-name))) ; nil or empty string
+       (setq locale-name (server-getenv (pop vars))))))
+
+    (when locale-name
       ;; Translate "swedish" into "sv_SE.ISO8859-1", and so on,
       ;; using the translation file that many systems have.
       (when locale-translation-file-name
        (with-temp-buffer
          (insert-file-contents locale-translation-file-name)
          (when (re-search-forward
-                (concat "^" (regexp-quote locale) ":?[ \t]+") nil t)
-           (setq locale (buffer-substring (point) (line-end-position))))))
+                (concat "^" (regexp-quote locale-name) ":?[ \t]+") nil t)
+           (setq locale-name (buffer-substring (point) (line-end-position)))))))
+    locale-name)
+
+(defun get-locale-coding-system (&optional locale)
+  "Return the coding system corresponding to locale LOCALE."
+  (setq locale (or locale (get-locale-real-name nil)))
+  (when locale
+    (or (locale-name-match locale locale-preferred-coding-systems)
+       (when locale
+         (if (string-match "\\.\\([^@]+\\)" locale)
+             (locale-charset-to-coding-system
+              (match-string 1 locale)))))))
+
+(defun configure-display-for-locale (&optional locale)
+  "Set up terminal for locale LOCALE.
+
+The display table, the terminal coding system and the keyboard
+coding system of the current display device are set up for the
+given locale."
+  (setq locale (or locale (get-locale-real-name nil)))
+
+  (when locale
+    (let ((language-name
+          (locale-name-match locale locale-language-names))
+         (charset-language-name
+          (locale-name-match locale locale-charset-language-names))
+         (coding-system
+          (get-locale-coding-system locale)))
+
+      ;; Give preference to charset-language-name over language-name.
+      (if (and charset-language-name
+              (not
+               (equal (get-language-info language-name 'charset)
+                      (get-language-info charset-language-name 'charset))))
+         (setq language-name charset-language-name))
+
+      (when language-name
+
+       ;; If default-enable-multibyte-characters is nil,
+       ;; we are using single-byte characters,
+       ;; so the display table and terminal coding system are irrelevant.
+       (when default-enable-multibyte-characters
+         ;; Override default-terminal-coding-system in case the
+         ;; display coding can not be derived from the language
+         ;; environment.
+         (let ((default-terminal-coding-system coding-system))
+           (set-display-table-and-terminal-coding-system language-name)))
+
+       ;; Set the `keyboard-coding-system' if appropriate (tty
+       ;; only).  At least X and MS Windows can generate
+       ;; multilingual input.
+       (unless window-system
+         (let ((kcs (or coding-system
+                        (car (get-language-info language-name
+                                                'coding-system)))))
+           (if kcs (set-keyboard-coding-system kcs))))))))
+
+;; Fixme: This ought to deal with the territory part of the locale
+;; too, for setting things such as calendar holidays, ps-print paper
+;; size, spelling dictionary.
+
+(defun set-locale-environment (&optional locale-name)
+  "Set up multi-lingual environment for using LOCALE-NAME.
+This sets the language environment, the coding system priority,
+the default input method and sometimes other things.
+
+LOCALE-NAME should be a string which is the name of a locale supported
+by the system.  Often it is of the form xx_XX.CODE, where xx is a
+language, XX is a country, and CODE specifies a character set and
+coding system.  For example, the locale name \"ja_JP.EUC\" might name
+a locale for Japanese in Japan using the `japanese-iso-8bit'
+coding-system.  The name may also have a modifier suffix, e.g. `@euro'
+or `@cyrillic'.
+
+If LOCALE-NAME is nil, its value is taken from the environment
+variables LC_ALL, LC_CTYPE and LANG (the first one that is set).
+On server frames, the environment of the emacsclient process is
+used.
+
+The locale names supported by your system can typically be found in a
+directory named `/usr/share/locale' or `/usr/lib/locale'.  LOCALE-NAME
+will be translated according to the table specified by
+`locale-translation-file-name'.
+
+See also `locale-charset-language-names', `locale-language-names',
+`locale-preferred-coding-systems' and `locale-coding-system'."
+  (interactive "sSet environment for locale: ")
+
+  (let ((locale (get-locale-real-name locale-name)))
+
+    (when locale
 
       ;; Leave the system locales alone if the caller did not specify
       ;; an explicit locale name, as their defaults are set from
@@ -2257,12 +2460,14 @@ See also `locale-charset-language-names', `locale-language-names',
 
       (setq locale (downcase locale))
 
+      (configure-display-for-locale locale)
+
       (let ((language-name
             (locale-name-match locale locale-language-names))
            (charset-language-name
             (locale-name-match locale locale-charset-language-names))
            (coding-system
-            (locale-name-match locale locale-preferred-coding-systems)))
+            (get-locale-coding-system locale)))
 
        ;; Give preference to charset-language-name over language-name.
        (if (and charset-language-name
@@ -2277,21 +2482,6 @@ See also `locale-charset-language-names', `locale-language-names',
          ;; to do it for both unibyte and multibyte modes.
          (set-language-environment language-name)
 
-         ;; If default-enable-multibyte-characters is nil,
-         ;; we are using single-byte characters,
-         ;; so the display table and terminal coding system are irrelevant.
-         (when default-enable-multibyte-characters
-           (set-display-table-and-terminal-coding-system language-name))
-
-         ;; Set the `keyboard-coding-system' if appropriate (tty
-         ;; only).  At least X and MS Windows can generate
-         ;; multilingual input.
-         (unless window-system
-           (let ((kcs (or coding-system
-                          (car (get-language-info language-name
-                                                  'coding-system)))))
-             (if kcs (set-keyboard-coding-system kcs))))
-
          (setq locale-coding-system
                (car (get-language-info language-name 'coding-priority))))
 
@@ -2299,10 +2489,20 @@ See also `locale-charset-language-names', `locale-language-names',
          (prefer-coding-system coding-system)
          (setq locale-coding-system coding-system))))
 
+    ;; On Windows, override locale-coding-system, keyboard-coding-system,
+    ;; selection-coding-system with system codepage.
+    (when (boundp 'w32-ansi-code-page)
+      (let ((code-page-coding (intern (format "cp%d" w32-ansi-code-page))))
+       (when (coding-system-p code-page-coding)
+         (setq locale-coding-system code-page-coding)
+         (set-selection-coding-system code-page-coding)
+         (set-keyboard-coding-system code-page-coding)
+         (set-terminal-coding-system code-page-coding))))
+
     ;; Default to A4 paper if we're not in a C, POSIX or US locale.
-    ;; (See comments in Flanginfo.)
+    ;; (See comments in Flocale_info.)
     (let ((locale locale)
-         (paper (langinfo 'paper)))
+         (paper (locale-info 'paper)))
       (if paper
          ;; This will always be null at the time of writing.
          (cond
@@ -2321,7 +2521,11 @@ See also `locale-charset-language-names', `locale-language-names',
                                                ("posix$" . letter)
                                                (".._us" . letter)
                                                (".._pr" . letter)
-                                               (".._ca" . letter)))
+                                               (".._ca" . letter)
+                                               ("enu$" . letter) ; Windows
+                                               ("esu$" . letter)
+                                               ("enc$" . letter)
+                                               ("frc$" . letter)))
                    'a4))))))
   nil)
 \f
@@ -2387,7 +2591,7 @@ It can be retrieved with `(get-char-code-property CHAR PROPNAME)'."
    (if (and coding-system (eq (coding-system-type coding-system) 2))
        ;; Try to get a pretty description for ISO 2022 escape sequences.
        (function (lambda (x) (or (cdr (assq x iso-2022-control-alist))
-                                (format "%02X" x))))
+                                (format "0x%02X" x))))
      (function (lambda (x) (format "0x%02X" x))))
    str " "))
 
@@ -2405,7 +2609,7 @@ If CODING-SYSTEM can't safely encode CHAR, return nil."
              (and safe-chars (aref safe-chars char)))
       ;; We must find the encoded string of CHAR.  But, just encoding
       ;; CHAR will put extra control sequences (usually to designate
-      ;; ASCII charaset) at the tail if type of CODING is ISO 2022.
+      ;; ASCII charset) at the tail if type of CODING is ISO 2022.
       ;; To exclude such tailing bytes, we at first encode one-char
       ;; string and two-char string, then check how many bytes at the
       ;; tail of both encoded strings are the same.
@@ -2423,4 +2627,5 @@ If CODING-SYSTEM can't safely encode CHAR, return nil."
       (substring enc2 0 i2))))
 
 
+;;; arch-tag: b382c432-4b36-460e-bf4c-05efd0bb18dc
 ;;; mule-cmds.el ends here