]> code.delx.au - gnu-emacs/blobdiff - lisp/international/mule-cmds.el
Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-27
[gnu-emacs] / lisp / international / mule-cmds.el
index c3545347335be1e8f3d5540f6869367ce92b9fee..4c93ee6255449f8bb1690a2ee2bb746e3c768d39 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.
@@ -293,7 +293,7 @@ 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)))
@@ -326,6 +326,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
@@ -702,22 +707,20 @@ and TO is ignored."
        (coding-system nil)
        (bufname (buffer-name))
        safe rejected unsafe)
-    (if (eq (car codings) 'undecided)
-       ;; Any coding system is ok.
-       (setq coding-system t)
-      ;; Classify the defaults into safe, rejected, and unsafe.
-      (dolist (elt default-coding-system)
-       (if (memq (cdr elt) codings)
-           (if (and (functionp accept-default-p)
-                    (not (funcall accept-default-p (cdr elt))))
-               (push (car elt) rejected)
-             (push (car elt) safe))
-         (push (car elt) unsafe)))
-      (if safe
-         (setq coding-system (car safe))))
+    ;; Classify the defaults into safe, rejected, and unsafe.
+    (dolist (elt default-coding-system)
+      (if (or (eq (car codings) 'undecided)
+             (memq (cdr elt) codings))
+         (if (and (functionp accept-default-p)
+                  (not (funcall accept-default-p (cdr elt))))
+             (push (car elt) rejected)
+           (push (car elt) safe))
+       (push (car elt) unsafe)))
+    (if safe
+       (setq coding-system (car safe)))
 
     ;; If all the defaults failed, ask a user.
-    (when (not coding-system)
+    (unless coding-system
       ;; At first, if some defaults are unsafe, record at most 11
       ;; problematic characters and their positions for them by turning
       ;;       (CODING ...)
@@ -860,7 +863,7 @@ e.g., for sending an email message.\n ")
 The first problematic character is at point in the displayed buffer,\n"
                          (substitute-command-keys "\
 and \\[universal-argument] \\[what-cursor-position] will give information about it.\n"))))
-             (insert (if safe
+             (insert (if rejected
                          "\nSelect the above, or "
                        "\nSelect ")
                      "\
@@ -872,7 +875,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)))
@@ -886,14 +889,12 @@ on your risk of losing the problematic characters.\n")))
        (kill-buffer "*Warning*")
        (set-window-configuration window-configuration)))
 
-    (if (vectorp (coding-system-eol-type coding-system))
+    (if (and coding-system (vectorp (coding-system-eol-type coding-system)))
        (let ((eol (coding-system-eol-type buffer-file-coding-system)))
          (if (numberp eol)
              (setq coding-system
                    (coding-system-change-eol-conversion coding-system eol)))))
 
-    (if (eq coding-system t)
-       (setq coding-system buffer-file-coding-system))
     ;; Check we're not inconsistent with what `coding:' spec &c would
     ;; give when file is re-read.
     ;; But don't do this if we explicitly ignored the cookie
@@ -906,13 +907,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 \
@@ -985,6 +1006,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'
@@ -1003,7 +1030,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))))))
 
@@ -1560,11 +1587,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
@@ -1669,7 +1696,7 @@ 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"))
-  (let ((slot (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)))
@@ -1700,7 +1727,7 @@ specifies the character set for the major languages of Western Europe."
 
   ;; Put higher priorities to such charsets that are supported by the
   ;; coding systems of higher priorities in this environment.
-  (let ((charsets nil))
+  (let ((charsets (get-language-info language-name 'charset)))
     (dolist (coding (get-language-info language-name 'coding-priority))
       (setq charsets (append charsets (coding-system-charset-list coding))))
     (if charsets
@@ -1724,6 +1751,15 @@ 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)))
@@ -1805,7 +1841,7 @@ Setting this variable directly does not take effect.  See
        (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,
@@ -1813,7 +1849,23 @@ Setting this variable directly does not take effect.  See
        ;; 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$B!G\e(B])
+         ;; (aset standard-display-table ?` [?\e$B!F\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)
@@ -1838,7 +1890,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]
@@ -1962,6 +2014,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
@@ -2155,14 +2214,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")
-     ;; @euro actually indicates the monetary component, but it
-     ;; probably implies a Latin-9 codeset component.
-     ;; utf-8@euro exists, so put this last.
+     (".*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.")
 
@@ -2197,13 +2255,39 @@ names.  E.g. `ISO_8859-1' and `iso88591' both match `iso-8859-1'."
   (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)))))
+
+;; 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
+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'
@@ -2227,7 +2311,7 @@ See also `locale-charset-language-names', `locale-language-names',
   (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,
@@ -2254,6 +2338,7 @@ See also `locale-charset-language-names', `locale-language-names',
       ;; using the translation file that many systems have.
       (when locale-translation-file-name
        (with-temp-buffer
+         (set-buffer-multibyte nil)
          (insert-file-contents locale-translation-file-name)
          (when (re-search-forward
                 (concat "^" (regexp-quote locale) ":?[ \t]+") nil t)
@@ -2274,7 +2359,11 @@ See also `locale-charset-language-names', `locale-language-names',
            (charset-language-name
             (locale-name-match locale locale-charset-language-names))
            (coding-system
-            (locale-name-match locale locale-preferred-coding-systems)))
+            (or (locale-name-match locale locale-preferred-coding-systems)
+                (when locale
+                  (if (string-match "\\.\\([^@]+\\)" locale)
+                      (locale-charset-to-coding-system
+                       (match-string 1 locale)))))))
 
        ;; Give preference to charset-language-name over language-name.
        (if (and charset-language-name
@@ -2324,6 +2413,16 @@ See also `locale-charset-language-names', `locale-language-names',
                  (message "Warning: Default coding system `%s' disagrees with
 system codeset `%s' for this locale." coding-system codeset))))))))
 
+    ;; 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 Flocale_info.)
     (let ((locale locale)
@@ -2346,7 +2445,11 @@ system codeset `%s' for this locale." coding-system codeset))))))))
                                                ("posix$" . letter)
                                                (".._us" . letter)
                                                (".._pr" . letter)
-                                               (".._ca" . letter)))
+                                               (".._ca" . letter)
+                                               ("enu$" . letter) ; Windows
+                                               ("esu$" . letter)
+                                               ("enc$" . letter)
+                                               ("frc$" . letter)))
                    'a4))))))
   nil)
 \f
@@ -2396,7 +2499,7 @@ It can be retrieved with `(get-char-code-property CHAR PROPNAME)'."
    (if (and coding-system (eq (coding-system-type coding-system) 'iso-2022))
        ;; 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 " "))
 
@@ -2442,4 +2545,5 @@ If CODING-SYSTEM can't safely encode CHAR, return nil."
 (defvar nonascii-translation-table nil "This variable is obsolete.")
 
 
+;;; arch-tag: b382c432-4b36-460e-bf4c-05efd0bb18dc
 ;;; mule-cmds.el ends here