]> code.delx.au - gnu-emacs/blobdiff - lisp/international/mule-cmds.el
Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-6
[gnu-emacs] / lisp / international / mule-cmds.el
index cd60e266b456b85547455e0b5fc81bcebbb72356..3de363a596fc3cbfc1006ff1284f44d854bac6ea 100644 (file)
@@ -1,7 +1,8 @@
 ;;; mule-cmds.el --- commands for mulitilingual environment -*-coding: iso-2022-7bit -*-
+
+;; Copyright (C) 2000, 2001, 2002, 2003, 2004  Free Software Foundation, Inc.
 ;; Copyright (C) 1995, 2003 Electrotechnical Laboratory, JAPAN.
-;;   Licensed to the Free Software Foundation.
-;; Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+;; Licensed to the Free Software Foundation.
 ;; Copyright (C) 2003
 ;;   National Institute of Advanced Industrial Science and Technology (AIST)
 ;;   Registration Number H13PRO009
@@ -611,6 +612,176 @@ The meaning is the same as the argument ACCEPT-DEFAULT-P of the
 function `select-safe-coding-system' (which see).  This variable
 overrides that argument.")
 
+(defun select-safe-coding-system-interactively (from to codings unsafe
+                                               &optional rejected default)
+  "Select interactively a coding system for the region FROM ... TO.
+FROM can be a string, as in `write-region'.
+CODINGS is the list of base coding systems known to be safe for this region,
+  typically obtained with `find-coding-systems-region'.
+UNSAFE is a list of coding systems known to be unsafe for this region.
+REJECTED is a list of coding systems which were safe but for some reason
+  were not recommended in the particular context.
+DEFAULT is the coding system to use by default in the query."
+  ;; At first, if some defaults are unsafe, record at most 11
+  ;; problematic characters and their positions for them by turning
+  ;;   (CODING ...)
+  ;; into
+  ;;   ((CODING (POS . CHAR) (POS . CHAR) ...) ...)
+  (if unsafe
+      (setq unsafe
+           (mapcar #'(lambda (coding)
+                       (cons coding
+                             (if (stringp from)
+                                 (mapcar #'(lambda (pos)
+                                             (cons pos (aref from pos)))
+                                         (unencodable-char-position
+                                          0 (length from) coding
+                                          11 from))
+                               (mapcar #'(lambda (pos)
+                                           (cons pos (char-after pos)))
+                                       (unencodable-char-position
+                                        from to coding 11)))))
+                   unsafe)))
+
+  ;; Change each safe coding system to the corresponding
+  ;; mime-charset name if it is also a coding system.  Such a name
+  ;; is more friendly to users.
+  (let ((l codings)
+       mime-charset)
+    (while l
+      (setq mime-charset (coding-system-get (car l) :mime-charset))
+      (if (and mime-charset (coding-system-p mime-charset)
+              (coding-system-equal (car l) mime-charset))
+         (setcar l mime-charset))
+      (setq l (cdr l))))
+
+  ;; Don't offer variations with locking shift, which you
+  ;; basically never want.
+  (let (l)
+    (dolist (elt codings (setq codings (nreverse l)))
+      (unless (or (eq 'coding-category-iso-7-else
+                     (coding-system-category elt))
+                 (eq 'coding-category-iso-8-else
+                     (coding-system-category elt)))
+       (push elt l))))
+
+  ;; Remove raw-text, emacs-mule and no-conversion unless nothing
+  ;; else is available.
+  (setq codings
+       (or (delq 'raw-text
+                 (delq 'emacs-mule
+                       (delq 'no-conversion codings)))
+           '(raw-text emacs-mule no-conversion)))
+
+  (let ((window-configuration (current-window-configuration))
+       (bufname (buffer-name))
+       coding-system)
+    (save-excursion
+      ;; If some defaults are unsafe, make sure the offending
+      ;; buffer is displayed.
+      (when (and unsafe (not (stringp from)))
+       (pop-to-buffer bufname)
+       (goto-char (apply 'min (mapcar #'(lambda (x) (car (cadr x)))
+                                      unsafe))))
+      ;; Then ask users to select one from CODINGS while showing
+      ;; the reason why none of the defaults are not used.
+      (with-output-to-temp-buffer "*Warning*"
+       (with-current-buffer standard-output
+         (if (and (null rejected) (null unsafe))
+             (insert "No default coding systems to try for "
+                     (if (stringp from)
+                         (format "string \"%s\"." from)
+                       (format "buffer `%s'." bufname)))
+           (insert
+            "These default coding systems were tried to encode"
+            (if (stringp from)
+                (concat " \"" (if (> (length from) 10)
+                                  (concat (substring from 0 10) "...\"")
+                                (concat from "\"")))
+              (format " text\nin the buffer `%s'" bufname))
+            ":\n")
+           (let ((pos (point))
+                 (fill-prefix "  "))
+             (dolist (x (append rejected unsafe))
+               (princ "  ") (princ (car x)))
+             (insert "\n")
+             (fill-region-as-paragraph pos (point)))
+           (when rejected
+             (insert "These safely encodes the target text,
+but it is not recommended for encoding text in this context,
+e.g., for sending an email message.\n ")
+             (dolist (x rejected)
+               (princ " ") (princ x))
+             (insert "\n"))
+           (when unsafe
+             (insert (if rejected "And the others"
+                       "However, each of them")
+                     " encountered these problematic characters:\n")
+             (dolist (coding unsafe)
+               (insert (format "  %s:" (car coding)))
+               (let ((i 0)
+                     (func1
+                      #'(lambda (bufname pos)
+                          (when (buffer-live-p (get-buffer bufname))
+                            (pop-to-buffer bufname)
+                            (goto-char pos))))
+                     (func2
+                      #'(lambda (bufname pos coding)
+                          (when (buffer-live-p (get-buffer bufname))
+                            (pop-to-buffer bufname)
+                            (if (< (point) pos)
+                                (goto-char pos)
+                              (forward-char 1)
+                              (search-unencodable-char coding)
+                              (forward-char -1))))))
+                 (dolist (elt (cdr coding))
+                   (insert " ")
+                   (if (stringp from)
+                       (insert (if (< i 10) (cdr elt) "..."))
+                     (if (< i 10)
+                         (insert-text-button
+                          (cdr elt)
+                          :type 'help-xref
+                          'help-echo
+                          "mouse-2, RET: jump to this character"
+                          'help-function func1
+                          'help-args (list bufname (car elt)))
+                       (insert-text-button
+                        "..."
+                        :type 'help-xref
+                        'help-echo
+                        "mouse-2, RET: next unencodable character"
+                        'help-function func2
+                        'help-args (list bufname (car elt)
+                                         (car coding)))))
+                   (setq i (1+ i))))
+               (insert "\n"))
+             (insert "\
+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 "\nSelect \
+one of the following safe coding systems, or edit the buffer:\n")
+         (let ((pos (point))
+               (fill-prefix "  "))
+           (dolist (x codings)
+             (princ "  ") (princ x))
+           (insert "\n")
+           (fill-region-as-paragraph pos (point)))
+         (insert "Or specify any other coding system
+at the risk of losing the problematic characters.\n")))
+
+      ;; Read a coding system.
+      (setq coding-system
+           (read-coding-system
+            (format "Select coding system (default %s): " default)
+            default))
+      (setq last-coding-system-specified coding-system))
+
+    (kill-buffer "*Warning*")
+    (set-window-configuration window-configuration)
+    coding-system))
+
 (defun select-safe-coding-system (from to &optional default-coding-system
                                       accept-default-p file)
   "Ask a user to select a safe coding system from candidates.
@@ -705,7 +876,6 @@ and TO is ignored."
 
   (let ((codings (find-coding-systems-region from to))
        (coding-system nil)
-       (bufname (buffer-name))
        safe rejected unsafe)
     ;; Classify the defaults into safe, rejected, and unsafe.
     (dolist (elt default-coding-system)
@@ -721,173 +891,8 @@ and TO is ignored."
 
     ;; If all the defaults failed, ask a user.
     (unless coding-system
-      ;; At first, if some defaults are unsafe, record at most 11
-      ;; problematic characters and their positions for them by turning
-      ;;       (CODING ...)
-      ;; into
-      ;;       ((CODING (POS . CHAR) (POS . CHAR) ...) ...)
-      (if unsafe
-         (if (stringp from)
-             (setq unsafe
-                   (mapcar #'(lambda (coding)
-                               (cons coding
-                                     (mapcar #'(lambda (pos)
-                                                 (cons pos (aref from pos)))
-                                             (unencodable-char-position
-                                              0 (length from) coding
-                                              11 from))))
-                           unsafe))
-           (setq unsafe
-                 (mapcar #'(lambda (coding)
-                             (cons coding
-                                   (mapcar #'(lambda (pos)
-                                               (cons pos (char-after pos)))
-                                           (unencodable-char-position
-                                            from to coding 11))))
-                         unsafe))))
-
-      ;; Change each safe coding system to the corresponding
-      ;; mime-charset name if it is also a coding system.  Such a name
-      ;; is more friendly to users.
-      (let ((l codings)
-           mime-charset)
-       (while l
-         (setq mime-charset (coding-system-get (car l) :mime-charset))
-         (if (and mime-charset (coding-system-p mime-charset)
-                  (coding-system-equal (car l) mime-charset))
-             (setcar l mime-charset))
-         (setq l (cdr l))))
-
-      ;; Don't offer variations with locking shift, which you
-      ;; basically never want.
-      (let (l)
-       (dolist (elt codings (setq codings (nreverse l)))
-         (unless (or (eq 'coding-category-iso-7-else
-                         (coding-system-category elt))
-                     (eq 'coding-category-iso-8-else
-                         (coding-system-category elt)))
-           (push elt l))))
-
-      ;; Remove raw-text, emacs-mule and no-conversion unless nothing
-      ;; else is available.
-      (setq codings
-           (or (delq 'raw-text
-                     (delq 'emacs-mule
-                           (delq 'no-conversion codings)))
-               '(raw-text emacs-mule no-conversion)))
-
-      (let ((window-configuration (current-window-configuration)))
-       (save-excursion
-         ;; If some defaults are unsafe, make sure the offending
-         ;; buffer is displayed.
-         (when (and unsafe (not (stringp from)))
-           (pop-to-buffer bufname)
-           (goto-char (apply 'min (mapcar #'(lambda (x) (car (cadr x)))
-                                          unsafe))))
-         ;; Then ask users to select one from CODINGS while showing
-         ;; the reason why none of the defaults are not used.
-         (with-output-to-temp-buffer "*Warning*"
-           (save-excursion
-             (set-buffer standard-output)
-             (if (not default-coding-system)
-                 (insert "No default coding systems to try for "
-                         (if (stringp from)
-                             (format "string \"%s\"." from)
-                           (format "buffer `%s'." bufname)))
-               (insert
-                "These default coding systems were tried to encode"
-                (if (stringp from)
-                    (concat " \"" (if (> (length from) 10)
-                                      (concat (substring from 0 10) "...\"")
-                                    (concat from "\"")))
-                  (format " text\nin the buffer `%s'" bufname))
-                ":\n")
-               (let ((pos (point))
-                     (fill-prefix "  "))
-                 (mapc #'(lambda (x) (princ "  ") (princ (car x)))
-                       default-coding-system)
-                 (insert "\n")
-                 (fill-region-as-paragraph pos (point)))
-               (when rejected
-                 (insert "These safely encodes the target text,
-but it is not recommended for encoding text in this context,
-e.g., for sending an email message.\n ")
-                 (mapc #'(lambda (x) (princ " ") (princ x)) rejected)
-                 (insert "\n"))
-               (when unsafe
-                 (insert (if rejected "And the others"
-                           "However, each of them")
-                         " encountered these problematic characters:\n")
-                 (mapc
-                  #'(lambda (coding)
-                      (insert (format "  %s:" (car coding)))
-                      (let ((i 0)
-                            (func1
-                             #'(lambda (bufname pos)
-                                 (when (buffer-live-p (get-buffer bufname))
-                                   (pop-to-buffer bufname)
-                                   (goto-char pos))))
-                            (func2
-                             #'(lambda (bufname pos coding)
-                                 (when (buffer-live-p (get-buffer bufname))
-                                   (pop-to-buffer bufname)
-                                   (if (< (point) pos)
-                                       (goto-char pos)
-                                     (forward-char 1)
-                                     (search-unencodable-char coding)
-                                     (forward-char -1))))))
-                        (dolist (elt (cdr coding))
-                          (insert " ")
-                          (if (stringp from)
-                              (insert (if (< i 10) (cdr elt) "..."))
-                            (if (< i 10)
-                                (insert-text-button
-                                 (cdr elt)
-                                 :type 'help-xref
-                                 'help-echo
-                                 "mouse-2, RET: jump to this character"
-                                 'help-function func1
-                                 'help-args (list bufname (car elt)))
-                              (insert-text-button
-                               "..."
-                               :type 'help-xref
-                               'help-echo
-                               "mouse-2, RET: next unencodable character"
-                               'help-function func2
-                               'help-args (list bufname (car elt)
-                                                (car coding)))))
-                          (setq i (1+ i))))
-                      (insert "\n"))
-                  unsafe)
-                 (insert "\
-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 rejected
-                         "\nSelect the above, or "
-                       "\nSelect ")
-                     "\
-one of the following safe coding systems, or edit the buffer:\n")
-             (let ((pos (point))
-                   (fill-prefix "  "))
-               (mapcar (function (lambda (x) (princ "  ") (princ x)))
-                       codings)
-               (insert "\n")
-               (fill-region-as-paragraph pos (point)))
-             (insert "Or specify any other coding system
-at the risk of losing the problematic characters.\n")))
-
-         ;; Read a coding system.
-         (setq default-coding-system (or (car safe) (car codings)))
-         (setq coding-system
-               (read-coding-system
-                (format "Select coding system (default %s): "
-                        default-coding-system)
-                default-coding-system))
-         (setq last-coding-system-specified coding-system))
-
-       (kill-buffer "*Warning*")
-       (set-window-configuration window-configuration)))
+      (setq coding-system (select-safe-coding-system-interactively
+                          from to codings unsafe rejected (car codings))))
 
     (if (and coding-system (vectorp (coding-system-eol-type coding-system)))
        (let ((eol (coding-system-eol-type buffer-file-coding-system)))
@@ -1030,7 +1035,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))))))
 
@@ -1344,12 +1349,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]."
@@ -1357,14 +1364,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.
 
@@ -1377,9 +1385,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)))
@@ -1396,7 +1407,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)))))))
 
 (eval-when-compile (autoload 'help-buffer "help-mode"))
@@ -1587,11 +1598,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
@@ -1696,7 +1707,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)))
@@ -1752,14 +1763,6 @@ specifies the character set for the major languages of Western Europe."
       (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)))
@@ -2174,8 +2177,8 @@ of `buffer-file-coding-system' set by this function."
     ; zh_HK/BIG5-HKSCS \
 
     ("zh.*[._]big5" . "Chinese-BIG5")
-    ("zh.*[._].gb18030" . "Chinese-GB18030") ; zh_CN.GB18030/GB18030 in glibc
-    ("zh.*[._].gbk" . "Chinese-GBK")
+    ("zh.*[._]gb18030" . "Chinese-GB18030") ; zh_CN.GB18030/GB18030 in glibc
+    ("zh.*[._]gbk" . "Chinese-GBK")
     ;; glibc has zh_TW.EUC-TW, with zh_TW defaulting to Big5
     ("zh_tw" . "Chinese-CNS") ; glibc uses big5
     ("zh_tw[._]euc-tw" . "Chinese-EUC-TW")
@@ -2268,7 +2271,7 @@ 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-ignore-case charset locale-charset-alist))
+  (or (car (assoc-string charset locale-charset-alist t))
       (let ((cs coding-system-alist)
            c)
        (while (and (not c) cs)
@@ -2413,6 +2416,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)
@@ -2435,7 +2448,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
@@ -2531,5 +2548,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
+;; arch-tag: b382c432-4b36-460e-bf4c-05efd0bb18dc
 ;;; mule-cmds.el ends here