Add 2010 to copyright years.
[bpt/emacs.git] / lisp / international / mule.el
index fa1c413..8d2f6de 100644 (file)
@@ -1,9 +1,10 @@
 ;;; mule.el --- basic commands for multilingual environment
 
-;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
+;;   2007, 2008, 2009, 2010
 ;;   Free Software Foundation, Inc.
 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007, 2008
+;;   2005, 2006, 2007, 2008, 2009, 2010
 ;;   National Institute of Advanced Industrial Science and Technology (AIST)
 ;;   Registration Number H14PRO021
 ;; Copyright (C) 2003
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -25,9 +26,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
@@ -52,7 +51,7 @@ Distribution date of this version of MULE (multilingual environment).")
 (defvar emacs-mule-charset-table (make-vector 256 nil))
 (aset emacs-mule-charset-table 0 'ascii)
 
-;; Convert the argument of old-style calll of define-charset to a
+;; Convert the argument of old-style call of define-charset to a
 ;; property list used by the new-style.
 ;; INFO-VECTOR is a vector of the format:
 ;;   [DIMENSION CHARS WIDTH DIRECTION ISO-FINAL-CHAR ISO-GRAPHIC-PLANE
@@ -84,7 +83,7 @@ Distribution date of this version of MULE (multilingual environment).")
       (if (> (- private-char-area-2-max private-char-area-2-min) total)
          (setq code-offset private-char-area-2-min
                private-char-area-2-min (+ private-char-area-2-min total))
-       (error "No more space for a new charset.")))
+       (error "No more space for a new charset")))
     (list :dimension dim
          :code-space code-space
          :iso-final-char (aref info-vector 4)
@@ -265,7 +264,7 @@ attribute."
          (aset emacs-mule-charset-table emacs-mule-id name)))
 
     (dolist (slot attrs)
-      (setcdr slot (plist-get props (car slot))))
+      (setcdr slot (purecopy (plist-get props (car slot)))))
 
     ;; Make sure that the value of :code-space is a vector of 8
     ;; elements.
@@ -278,7 +277,7 @@ attribute."
 
     ;; Add :name and :docstring properties to PROPS.
     (setq props
-         (cons :name (cons name (cons :docstring (cons docstring props)))))
+         (cons :name (cons name (cons :docstring (cons (purecopy docstring) props)))))
     (or (plist-get props :short-name)
        (plist-put props :short-name (symbol-name name)))
     (or (plist-get props :long-name)
@@ -308,12 +307,9 @@ Return t if file exists."
           (signal 'file-error (list "Cannot open load file" file)))
     ;; Read file with code conversion, and then eval.
     (let* ((buffer
-           ;; To avoid any autoloading, set default-major-mode to
-           ;; fundamental-mode.
-           (let ((default-major-mode 'fundamental-mode))
-             ;; We can't use `generate-new-buffer' because files.el
-             ;; is not yet loaded.
-             (get-buffer-create (generate-new-buffer-name " *load*"))))
+            ;; We can't use `generate-new-buffer' because files.el
+            ;; is not yet loaded.
+            (get-buffer-create (generate-new-buffer-name " *load*")))
           (load-in-progress t)
           (source (save-match-data (string-match "\\.el\\'" fullname))))
       (unless nomessage
@@ -321,7 +317,7 @@ Return t if file exists."
            (message "Loading %s (source)..." file)
          (message "Loading %s..." file)))
       (when purify-flag
-       (push file preloaded-file-list))
+       (push (purecopy file) preloaded-file-list))
       (unwind-protect
          (let ((load-file-name fullname)
                (set-auto-coding-for-load t)
@@ -352,13 +348,12 @@ Return t if file exists."
                         ;; If this Emacs is running with --unibyte,
                         ;; convert multibyte strings to unibyte
                         ;; after reading them.
-;;                      (not default-enable-multibyte-characters)
+;;                      (not (default-value 'enable-multibyte-characters))
                         nil t
                         ))
        (let (kill-buffer-hook kill-buffer-query-functions)
          (kill-buffer buffer)))
-      (unless purify-flag
-       (do-after-load-evaluation fullname))
+      (do-after-load-evaluation fullname)
 
       (unless (or nomessage noninteractive)
        (if source
@@ -421,10 +416,12 @@ PLIST (property list) may contain any type of information a user
 (defun charset-id (charset)
   "Always return 0.  This is provided for backward compatibility."
   0)
+(make-obsolete 'charset-id "do not use it." "23.1")
 
 (defmacro charset-bytes (charset)
   "Always return 0.  This is provided for backward compatibility."
   0)
+(make-obsolete 'charset-bytes "do not use it." "23.1")
 
 (defun get-charset-property (charset propname)
   "Return the value of CHARSET's PROPNAME property.
@@ -436,7 +433,10 @@ This is the last value stored with
   "Set CHARSETS's PROPNAME property to value VALUE.
 It can be retrieved with `(get-charset-property CHARSET PROPNAME)'."
   (set-charset-plist charset
-                    (plist-put (charset-plist charset) propname value)))
+                    (plist-put (charset-plist charset) propname
+                               (if (stringp value)
+                                   (purecopy value)
+                                 value))))
 
 (defun charset-description (charset)
   "Return description string of CHARSET."
@@ -469,22 +469,18 @@ Return -1 if charset isn't an ISO 2022 one."
   (plist-get (charset-plist charset) :long-name))
 
 (defun charset-list ()
-  "Return list of all charsets ever defined.
-
-This function is provided for backward compatibility.
-Now we have the variable `charset-list'."
+  "Return list of all charsets ever defined."
   charset-list)
-(make-obsolete 'charset-list "Use variable `charset-list'" "23.1")
+(make-obsolete 'charset-list "use variable `charset-list'." "23.1")
 
 \f
 ;;; CHARACTER
-(defalias 'char-valid-p 'characterp)
-(make-obsolete 'char-valid-p 'characterp "23.1")
+(define-obsolete-function-alias 'char-valid-p 'characterp "23.1")
 
 (defun generic-char-p (char)
   "Always return nil.  This is provided for backward compatibility."
   nil)
-(make-obsolete 'generic-char-p "Generic characters no longer exist" "23.1")
+(make-obsolete 'generic-char-p "generic characters no longer exist." "23.1")
 
 (defun make-char-internal (charset-id &optional code1 code2)
   (let ((charset (aref emacs-mule-charset-table charset-id)))
@@ -596,7 +592,7 @@ The remaining arguments must come in pairs ATTRIBUTE VALUE.  ATTRIBUTE
 may be any symbol.
 
 The following attributes have special meanings.  Those labeled as
-\"(required)\", should not be omitted.
+\"(required)\" should not be omitted.
 
 `:mnemonic' (required)
 
@@ -612,7 +608,7 @@ VALUE must be one of `charset', `utf-8', `utf-16', `iso-2022',
 VALUE is the EOL (end-of-line) format of the coding system.  It must be
 one of `unix', `dos', `mac'.  The symbol `unix' means Unix-like EOL
 \(i.e. single LF), `dos' means DOS-like EOL \(i.e. sequence of CR LF),
-and `mac' means MAC-like EOL \(i.e. single CR).  If omitted, on
+and `mac' means Mac-like EOL \(i.e. single CR).  If omitted, on
 decoding by the coding system, Emacs automatically detects the EOL
 format of the source text.
 
@@ -671,7 +667,7 @@ results in a unibyte buffer.
 `:eol-type'
 
 VALUE must be `unix', `dos', `mac'.  The symbol `unix' means Unix-like
-EOL (LF), `dos' means DOS-like EOL (CRLF), and `mac' means MAC-like
+EOL (LF), `dos' means DOS-like EOL (CRLF), and `mac' means Mac-like
 EOL (CR).  If omitted, on decoding, the coding system detects EOL
 format automatically, and on encoding, uses Unix-like EOL.
 
@@ -714,8 +710,8 @@ This attribute has a meaning only when `:coding-type' is `iso-2022'.
 `:bom'
 
 This attributes specifies whether the coding system uses a `byte order
-mark'.  VALUE must nil, t, or cons of coding systems whose
-`:coding-type' is `utf-16'.
+mark'.  VALUE must be nil, t, or cons of coding systems whose
+`:coding-type' is `utf-16' or `utf-8'.
 
 If the value is nil, on decoding, don't treat the first two-byte as
 BOM, and on encoding, don't produce BOM bytes.
@@ -723,13 +719,14 @@ BOM, and on encoding, don't produce BOM bytes.
 If the value is t, on decoding, skip the first two-byte as BOM, and on
 encoding, produce BOM bytes accoding to the value of `:endian'.
 
-If the value is cons, on decoding, check the first two-byte.  If theyq
+If the value is cons, on decoding, check the first two-byte.  If they
 are 0xFE 0xFF, use the car part coding system of the value.  If they
-are 0xFF 0xFE, use the car part coding system of the value.
+are 0xFF 0xFE, use the cdr part coding system of the value.
 Otherwise, treat them as bytes for a normal character.  On encoding,
 produce BOM bytes accoding to the value of `:endian'.
 
-This attribute has a meaning only when `:coding-type' is `utf-16'.
+This attribute has a meaning only when `:coding-type' is `utf-16' or
+`utf-8'.
 
 `:endian'
 
@@ -769,6 +766,8 @@ encoding.  This attribute has a meaning only when `:coding-type' is
                                      :reg-usage
                                      :request
                                      :flags))
+                                  ((eq coding-type 'utf-8)
+                                   '(:bom))
                                   ((eq coding-type 'utf-16)
                                    '(:bom
                                      :endian))
@@ -826,7 +825,7 @@ encoding.  This attribute has a meaning only when `:coding-type' is
          (cons :name (cons name (cons :docstring (cons (purecopy docstring)
                                                        props)))))
     (setcdr (assq :plist common-attrs) props)
-    (apply 'define-coding-system-internal 
+    (apply 'define-coding-system-internal
           name (mapcar 'cdr (append common-attrs spec-attrs)))))
 
 (defun coding-system-doc-string (coding-system)
@@ -836,7 +835,7 @@ encoding.  This attribute has a meaning only when `:coding-type' is
 (defun coding-system-mnemonic (coding-system)
   "Return the mnemonic character of CODING-SYSTEM.
 The mnemonic character of a coding system is used in mode line to
-indicate the coding system.  If CODING-SYSTEM. is nil, return ?=."
+indicate the coding system.  If CODING-SYSTEM is nil, return ?=."
   (plist-get (coding-system-plist coding-system) :mnemonic))
 
 (defun coding-system-type (coding-system)
@@ -861,7 +860,7 @@ For compatibility with Emacs 20/21, this accepts old-style symbols
 like `mime-charset' as well as the current style like `:mime-charset'."
   (or (plist-get (coding-system-plist coding-system) prop)
       (if (not (keywordp prop))
-         ;; For backward compatiblity.
+         ;; For backward compatibility.
          (if (eq prop 'ascii-incompatible)
              (not (plist-get (coding-system-plist coding-system)
                              :ascii-compatible-p))
@@ -894,7 +893,7 @@ like `mime-charset' as well as the current style like `:mime-charset'."
 
 (defun coding-system-equal (coding-system-1 coding-system-2)
   "Return t if and only if CODING-SYSTEM-1 and CODING-SYSTEM-2 are identical.
-Two coding systems are identical if two symbols are equal
+Two coding systems are identical if both symbols are equal
 or one is an alias of the other."
   (or (eq coding-system-1 coding-system-2)
       (and (equal (coding-system-plist coding-system-1)
@@ -935,8 +934,8 @@ formats (e.g. iso-latin-1-unix, koi8-r-dos)."
     codings))
 
 (defconst char-coding-system-table nil
-  "This is an obsolete variable.
-It exists just for backward compatibility, and the value is always nil.")
+  "It exists just for backward compatibility, and the value is always nil.")
+(make-obsolete-variable 'char-coding-system-table nil "23.1")
 
 (defun transform-make-coding-system-args (name type &optional doc-string props)
   "For internal use only.
@@ -1025,9 +1024,8 @@ Value is a list of transformed arguments."
                                         properties
                                         eol-type)
   "Define a new coding system CODING-SYSTEM (symbol).
-This function is provided for backward compatibility.
-Use `define-coding-system' instead."
-  ;; For compatiblity with XEmacs, we check the type of TYPE.  If it
+This function is provided for backward compatibility."
+  ;; For compatibility with XEmacs, we check the type of TYPE.  If it
   ;; is a symbol, perhaps, this function is called with XEmacs-style
   ;; arguments.  Here, try to transform that kind of arguments to
   ;; Emacs style.
@@ -1119,6 +1117,8 @@ Use `define-coding-system' instead."
 
   (apply 'define-coding-system coding-system doc-string properties))
 
+(make-obsolete 'make-coding-system 'define-coding-system "23.1")
+
 (defun merge-coding-systems (first second)
   "Fill in any unspecified aspects of coding system FIRST from SECOND.
 Return the resulting coding system."
@@ -1137,7 +1137,7 @@ Return the resulting coding system."
 (defun autoload-coding-system (symbol form)
   "Define SYMBOL as a coding-system that is defined on demand.
 
-FROM is a form to evaluate to define the coding-system."
+FORM is a form to evaluate to define the coding-system."
   (put symbol 'coding-system-define-form form)
   (setq coding-system-alist (cons (list (symbol-name symbol))
                                  coding-system-alist))
@@ -1146,17 +1146,36 @@ FROM is a form to evaluate to define the coding-system."
       (put (intern name) 'coding-system-define-form form)
       (setq coding-system-alist (cons (list name) coding-system-alist)))))
 
+;; This variable is set in these three cases:
+;;   (1) A file is read by a coding system specified explicitly.
+;;       after-insert-file-set-coding sets the car of this value to
+;;       coding-system-for-read, and sets the cdr to nil.
+;;   (2) A buffer is saved.
+;;       After writing, basic-save-buffer-1 sets the car of this value
+;;       to last-coding-system-used.
+;;   (3) set-buffer-file-coding-system is called.
+;;       The cdr of this value is set to the specified coding system.
+;; This variable is used for decoding in revert-buffer and encoding in
+;; select-safe-coding-system.
+(defvar buffer-file-coding-system-explicit nil
+  "The file coding system explicitly specified for the current buffer.
+The value is a cons of coding systems for reading (decoding) and
+writing (encoding).
+Internal use only.")
+(make-variable-buffer-local 'buffer-file-coding-system-explicit)
+(put 'buffer-file-coding-system-explicit 'permanent-local t)
+
 (defun set-buffer-file-coding-system (coding-system &optional force nomodify)
   "Set the file coding-system of the current buffer to CODING-SYSTEM.
 This means that when you save the buffer, it will be converted
-according to CODING-SYSTEM.  For a list of possible values of CODING-SYSTEM,
-use \\[list-coding-systems].
+according to CODING-SYSTEM.  For a list of possible values of
+CODING-SYSTEM, use \\[list-coding-systems].
 
-If CODING-SYSTEM leaves the text conversion unspecified, or if it
-leaves the end-of-line conversion unspecified, FORCE controls what to
-do.  If FORCE is nil, get the unspecified aspect (or aspects) from the
-buffer's previous `buffer-file-coding-system' value (if it is
-specified there).  Otherwise, leave it unspecified.
+If CODING-SYSTEM leaves the text conversion unspecified, or if it leaves
+the end-of-line conversion unspecified, FORCE controls what to do.
+If FORCE is nil, get the unspecified aspect (or aspects) from the buffer's
+previous `buffer-file-coding-system' value (if it is specified there).
+Otherwise, leave it unspecified.
 
 This marks the buffer modified so that the succeeding \\[save-buffer]
 surely saves the buffer with CODING-SYSTEM.  From a program, if you
@@ -1169,6 +1188,9 @@ just set the variable `buffer-file-coding-system' directly."
       (setq coding-system
            (merge-coding-systems coding-system buffer-file-coding-system)))
   (setq buffer-file-coding-system coding-system)
+  (if buffer-file-coding-system-explicit
+      (setcdr buffer-file-coding-system-explicit coding-system)
+    (setq buffer-file-coding-system-explicit (cons nil coding-system)))
   ;; This is in case of an explicit call.  Normally, `normal-mode' and
   ;; `set-buffer-major-mode-hook' take care of setting the table.
   (if (fboundp 'ucs-set-table-for-input) ; don't lose when building
@@ -1181,12 +1203,11 @@ just set the variable `buffer-file-coding-system' directly."
   "Visit the current buffer's file again using coding system CODING-SYSTEM.
 For a list of possible values of CODING-SYSTEM, use \\[list-coding-systems].
 
-If CODING-SYSTEM leaves the text conversion unspecified, or if it
-leaves the end-of-line conversion unspecified, FORCE controls what to
-do.  If FORCE is nil, get the unspecified aspect (or aspects) from the
-buffer's previous `buffer-file-coding-system' value (if it is
-specified there).  Otherwise, determine it from the file contents as
-usual for visiting a file."
+If CODING-SYSTEM leaves the text conversion unspecified, or if it leaves
+the end-of-line conversion unspecified, FORCE controls what to do.
+If FORCE is nil, get the unspecified aspect (or aspects) from the buffer's
+previous `buffer-file-coding-system' value (if it is specified there).
+Otherwise, determine it from the file contents as usual for visiting a file."
   (interactive "zCoding system for visited file (default nil): \nP")
   (check-coding-system coding-system)
   (if (and coding-system buffer-file-coding-system (null force))
@@ -1197,8 +1218,8 @@ usual for visiting a file."
 
 (defun set-file-name-coding-system (coding-system)
   "Set coding system for decoding and encoding file names to CODING-SYSTEM.
-It actually just set the variable `file-name-coding-system' (which
-see) to CODING-SYSTEM."
+It actually just set the variable `file-name-coding-system' (which see)
+to CODING-SYSTEM."
   (interactive "zCoding system for file names (default nil): ")
   (check-coding-system coding-system)
   (if (and coding-system
@@ -1212,17 +1233,18 @@ see) to CODING-SYSTEM."
 This is normally set according to the selected language environment.
 See also the command `set-terminal-coding-system'.")
 
-(defun set-terminal-coding-system (coding-system &optional display)
+(defun set-terminal-coding-system (coding-system &optional terminal)
   "Set coding system of terminal output to CODING-SYSTEM.
-All text output to DISPLAY will be encoded
+All text output to TERMINAL will be encoded
 with the specified coding system.
 
 For a list of possible values of CODING-SYSTEM, use \\[list-coding-systems].
 The default is determined by the selected language environment
 or by the previous use of this command.
 
-DISPLAY may be a display id, a frame, or nil for the selected frame's display.
-The setting has no effect on graphical displays."
+TERMINAL may be a terminal object, a frame, or nil for the
+selected frame's terminal.  The setting has no effect on
+graphical terminals."
   (interactive
    (list (let ((default (if (and (not (terminal-coding-system))
                                 default-terminal-coding-system)
@@ -1236,7 +1258,7 @@ The setting has no effect on graphical displays."
       (setq coding-system default-terminal-coding-system))
   (if coding-system
       (setq default-terminal-coding-system coding-system))
-  (set-terminal-coding-system-internal coding-system display)
+  (set-terminal-coding-system-internal coding-system terminal)
   (redraw-frame (selected-frame)))
 
 (defvar default-keyboard-coding-system nil
@@ -1244,37 +1266,62 @@ The setting has no effect on graphical displays."
 This is normally set according to the selected language environment.
 See also the command `set-keyboard-coding-system'.")
 
-(defun set-keyboard-coding-system (coding-system &optional display)
-  "Set coding system for keyboard input on DISPLAY to CODING-SYSTEM.
-In addition, this command calls `encoded-kbd-setup-display' to set up the
-translation of keyboard input events to the specified coding system.
+(defun set-keyboard-coding-system (coding-system &optional terminal)
+  "Set coding system for keyboard input on TERMINAL to CODING-SYSTEM.
 
 For a list of possible values of CODING-SYSTEM, use \\[list-coding-systems].
 The default is determined by the selected language environment
 or by the previous use of this command.
 
-DISPLAY may be a display id, a frame, or nil for the selected frame's display.
-The setting has no effect on graphical displays."
+If CODING-SYSTEM is nil or the coding-type of CODING-SYSTEM is
+`raw-text', the decoding of keyboard input is disabled.
+
+TERMINAL may be a terminal object, a frame, or nil for the
+selected frame's terminal.  The setting has no effect on
+graphical terminals."
   (interactive
-   (list (let ((default (if (and (not (keyboard-coding-system))
-                                default-keyboard-coding-system)
-                           default-keyboard-coding-system)))
+   (list (let* ((coding (keyboard-coding-system nil))
+               (default (if (eq (coding-system-type coding) 'raw-text)
+                            default-keyboard-coding-system)))
           (read-coding-system
            (format "Coding system for keyboard input (default %s): "
                    default)
            default))))
-  (if (and (not coding-system)
-          (not (keyboard-coding-system)))
-      (setq coding-system default-keyboard-coding-system))
-  (if coding-system
-      (setq default-keyboard-coding-system coding-system))
-  (if (and coding-system
-          (not (coding-system-get coding-system :ascii-compatible-p))
-          (not (coding-system-get coding-system :suitable-for-keyboard)))
-      (error "%s is not suitable for keyboard" coding-system))
-  (set-keyboard-coding-system-internal coding-system display)
-  (setq keyboard-coding-system coding-system)
-  (encoded-kbd-setup-display display))
+  (let ((coding-type (coding-system-type coding-system))
+       (saved-meta-mode
+        (terminal-parameter terminal 'keyboard-coding-saved-meta-mode)))
+    (if (not (eq coding-type 'raw-text))
+       (let (accept-8-bit)
+         (if (not (or (coding-system-get coding-system :suitable-for-keyboard)
+                      (coding-system-get coding-system :ascii-compatible-p)))
+             (error "Unsuitable coding system for keyboard: %s" coding-system))
+         (cond ((memq coding-type '(charset utf-8 shift-jis big5 ccl))
+                (setq accept-8-bit t))
+               ((eq coding-type 'iso-2022)
+                (let ((flags (coding-system-get coding-system :flags)))
+                  (or (memq '7-bit flags)
+                      (setq accept-8-bit t))))
+               (t
+                (error "Unsupported coding system for keyboard: %s"
+                       coding-system)))
+         (when accept-8-bit
+           (or saved-meta-mode
+               (set-terminal-parameter terminal
+                                       'keyboard-coding-saved-meta-mode
+                                       (cons (nth 2 (current-input-mode))
+                                             nil)))
+           (set-input-meta-mode 8))
+         ;; Avoid end-of-line conversion.
+         (setq coding-system
+               (coding-system-change-eol-conversion coding-system 'unix)))
+
+      (when saved-meta-mode
+       (set-input-meta-mode (car saved-meta-mode))
+       (set-terminal-parameter terminal
+                               'keyboard-coding-saved-meta-mode
+                               nil))))
+  (set-keyboard-coding-system-internal coding-system terminal)
+  (setq keyboard-coding-system coding-system))
 
 (defcustom keyboard-coding-system nil
   "Specify coding system for keyboard input.
@@ -1303,7 +1350,7 @@ use either \\[customize] or \\[set-keyboard-coding-system]."
 DECODING is the coding system to be used to decode input from the process,
 ENCODING is the coding system to be used to encode output to the process.
 
-For a list of possible values of CODING-SYSTEM, use \\[list-coding-systems]."
+For a list of possible coding systems, use \\[list-coding-systems]."
   (interactive
    "zCoding-system for output from the process: \nzCoding-system for input to the process: ")
   (let ((proc (get-buffer-process (current-buffer))))
@@ -1349,8 +1396,7 @@ This setting is effective for the next communication only."
   "Set priority of coding categories according to ARG.
 ARG is a list of coding categories ordered by priority.
 
-This function is provided for backward compatibility.
-Now we have more convenient function `set-coding-system-priority'."
+This function is provided for backward compatibility."
   (apply 'set-coding-system-priority
         (mapcar #'(lambda (x) (symbol-value x)) arg)))
 (make-obsolete 'set-coding-priority 'set-coding-system-priority "23.1")
@@ -1358,10 +1404,11 @@ Now we have more convenient function `set-coding-system-priority'."
 ;;; X selections
 
 (defvar ctext-non-standard-encodings-alist
+  (mapcar 'purecopy
   '(("big5-0" big5 2 big5)
     ("ISO8859-14" iso-8859-14 1 latin-iso8859-14)
     ("ISO8859-15" iso-8859-15 1 latin-iso8859-15)
-    ("gbk-0" gbk 2 chinese-gbk))
+    ("gbk-0" gbk 2 chinese-gbk)))
   "Alist of non-standard encoding names vs the corresponding usages in CTEXT.
 
 It controls how extended segments of a compound text are handled
@@ -1369,7 +1416,7 @@ by the coding system `compound-text-with-extensions'.
 
 Each element has the form (ENCODING-NAME CODING-SYSTEM N-OCTET CHARSET).
 
-ENCODING-NAME is an encoding name of an \"extended segments\".
+ENCODING-NAME is an encoding name of an \"extended segment\".
 
 CODING-SYSTEM is the coding-system to encode (or decode) the
 characters into (or from) the extended segment.
@@ -1378,7 +1425,7 @@ N-OCTET is the number of octets (bytes) that encodes a character
 in the segment.  It can be 0 (meaning the number of octets per
 character is variable), 1, 2, 3, or 4.
 
-CHARSET is a charater set containing characters that are encoded
+CHARSET is a character set containing characters that are encoded
 in the segment.  It can be a list of character sets.
 
 On decoding CTEXT, all encoding names listed here are recognized.
@@ -1394,13 +1441,14 @@ Each element must be one of the names listed in the variable
 `ctext-non-standard-encodings-alist' (which see).")
 
 (defvar ctext-non-standard-encodings-regexp
+  (purecopy
   (string-to-multibyte
    (concat
     ;; For non-standard encodings.
     "\\(\e%/[0-4][\200-\377][\200-\377]\\([^\002]+\\)\002\\)"
     "\\|"
     ;; For UTF-8 encoding.
-    "\\(\e%G[^\e]*\e%@\\)")))
+    "\\(\e%G[^\e]*\e%@\\)"))))
 
 ;; Functions to support "Non-Standard Character Set Encodings" defined
 ;; by the COMPOUND-TEXT spec.  They also support "The UTF-8 encoding"
@@ -1494,8 +1542,8 @@ Each element must be one of the names listed in the variable
   "Encode characters between FROM and TO as Compound Text w/Extended Segments.
 
 If FROM is a string, or if the current buffer is not the one set up for us
-by encode-coding-string, generate a new temp buffer, insert the
-text, and convert it in the temporary buffer.  Otherwise, convert in-place."
+by `encode-coding-string', generate a new temp buffer, insert the text,
+and convert it in the temporary buffer.  Otherwise, convert in-place."
   (save-match-data
     ;; Setup a working buffer if necessary.
     (when (stringp from)
@@ -1577,7 +1625,7 @@ text, and convert it in the temporary buffer.  Otherwise, convert in-place."
 (defcustom auto-coding-alist
   ;; .exe and .EXE are added to support archive-mode looking at DOS
   ;; self-extracting exe archives.
-  '(("\\.\\(\
+  (purecopy '(("\\.\\(\
 arc\\|zip\\|lzh\\|lha\\|zoo\\|[jew]ar\\|xpi\\|rar\\|\
 ARC\\|ZIP\\|LZH\\|LHA\\|ZOO\\|[JEW]AR\\|XPI\\|RAR\\)\\'"
      . no-conversion-multibyte)
@@ -1586,7 +1634,7 @@ ARC\\|ZIP\\|LZH\\|LHA\\|ZOO\\|[JEW]AR\\|XPI\\|RAR\\)\\'"
     ("\\.\\(gz\\|Z\\|bz\\|bz2\\|gpg\\)\\'" . no-conversion)
     ("\\.\\(jpe?g\\|png\\|gif\\|tiff?\\|p[bpgn]m\\)\\'" . no-conversion)
     ("\\.pdf\\'" . no-conversion)
-    ("/#[^/]+#\\'" . emacs-mule))
+    ("/#[^/]+#\\'" . emacs-mule)))
   "Alist of filename patterns vs corresponding coding systems.
 Each element looks like (REGEXP . CODING-SYSTEM).
 A file whose name matches REGEXP is decoded by CODING-SYSTEM on reading.
@@ -1600,11 +1648,12 @@ and the contents of `file-coding-system-alist'."
                       (symbol :tag "Coding system"))))
 
 (defcustom auto-coding-regexp-alist
-  '(("^BABYL OPTIONS:[ \t]*-\\*-[ \t]*rmail[ \t]*-\\*-" . no-conversion)
+  (mapcar (lambda (arg) (cons (purecopy (car arg)) (cdr arg)))
+  '(("\\`BABYL OPTIONS:[ \t]*-\\*-[ \t]*rmail[ \t]*-\\*-" . no-conversion)
     ("\\`\xFE\xFF" . utf-16be-with-signature)
     ("\\`\xFF\xFE" . utf-16le-with-signature)
-    ("\\`\xEF\xBB\xBF" . utf-8)
-    ("\\`;ELC\024\0\0\0" . emacs-mule))        ; Emacs 20-compiled
+    ("\\`\xEF\xBB\xBF" . utf-8-with-signature)
+    ("\\`;ELC\024\0\0\0" . emacs-mule)))       ; Emacs 20-compiled
   "Alist of patterns vs corresponding coding systems.
 Each element looks like (REGEXP . CODING-SYSTEM).
 A file whose first bytes match REGEXP is decoded by CODING-SYSTEM on reading.
@@ -1642,8 +1691,8 @@ or nil."
 Each function in this list should be written to operate on the
 current buffer, but should not modify it in any way.  The buffer
 will contain undecoded text of parts of the file.  Each function
-should take one argument, SIZE, which says how many
-characters (starting from point) it should look at.
+should take one argument, SIZE, which says how many characters
+\(starting from point) it should look at.
 
 If one of these functions succeeds in determining a coding
 system, it should return that coding system.  Otherwise, it
@@ -1662,7 +1711,7 @@ This is used for loading and byte-compiling Emacs Lisp files.")
 (defun auto-coding-alist-lookup (filename)
   "Return the coding system specified by `auto-coding-alist' for FILENAME."
   (let ((alist auto-coding-alist)
-       (case-fold-search (memq system-type '(vax-vms windows-nt ms-dos cygwin)))
+       (case-fold-search (memq system-type '(windows-nt ms-dos cygwin)))
        coding-system)
     (while (and alist (not coding-system))
       (if (string-match (car (car alist)) filename)
@@ -1688,12 +1737,12 @@ contents of the current buffer following point against
 succeed, it checks to see if any function in `auto-coding-functions'
 gives a match.
 
-If a coding system is specifed, the return value is a
-cons (CODING . SOURCE), where CODING is the specified coding
-system and SOURCE is a symbol `auto-coding-alist',
-`auto-coding-regexp-alist', `coding:', or `auto-coding-functions'
-indicating by what CODING is specified.  Note that the validity
-of CODING is not checked; it's the caller's responsibility to check it.
+If a coding system is specifed, the return value is a cons
+\(CODING . SOURCE), where CODING is the specified coding system and
+SOURCE is a symbol `auto-coding-alist', `auto-coding-regexp-alist',
+`:coding', or `auto-coding-functions' indicating by what CODING is
+specified.  Note that the validity of CODING is not checked;
+it's the caller's responsibility to check it.
 
 If nothing is specified, the return value is nil."
   (or (let ((coding-system (auto-coding-alist-lookup filename)))
@@ -1833,20 +1882,6 @@ function by default."
 
 (setq set-auto-coding-function 'set-auto-coding)
 
-;; This variable is set in these two cases:
-;;   (1) A file is read by a coding system specified explicitly.
-;;       after-insert-file-set-coding sets this value to
-;;       coding-system-for-read.
-;;   (2) A buffer is saved.
-;;       After writing, basic-save-buffer-1 sets this value to
-;;       last-coding-system-used.
-;; This variable is used for decoding in revert-buffer.
-(defvar buffer-file-coding-system-explicit nil
-  "The file coding system explicitly specified for the current buffer.
-Internal use only.")
-(make-variable-buffer-local 'buffer-file-coding-system-explicit)
-(put 'buffer-file-coding-system-explicit 'permanent-local t)
-
 (defun after-insert-file-set-coding (inserted &optional visit)
   "Set `buffer-file-coding-system' of current buffer after text is inserted.
 INSERTED is the number of characters that were inserted, as figured
@@ -1857,16 +1892,13 @@ The optional second arg VISIT non-nil means that we are visiting a file."
   (if (and visit
           coding-system-for-read
           (not (eq coding-system-for-read 'auto-save-coding)))
-      (setq buffer-file-coding-system-explicit coding-system-for-read))
+      (setq buffer-file-coding-system-explicit
+           (cons coding-system-for-read nil)))
   (if last-coding-system-used
       (let ((coding-system
             (find-new-buffer-file-coding-system last-coding-system-used)))
-       (when coding-system
-         ;; Tell set-buffer-file-coding-system not to mark the file
-         ;; as modified; we just read it, and it's supposed to be unmodified.
-         ;; Marking it modified would try to lock it, which would
-         ;; check the modtime, and we don't want to do that again now.
-         (set-buffer-file-coding-system coding-system t t))))
+       (if coding-system
+           (setq buffer-file-coding-system coding-system))))
   inserted)
 
 ;; The coding-spec and eol-type of coding-system returned is decided
@@ -1945,9 +1977,9 @@ TARGET-TYPE is `process', or a network service name or a port number
 to connect to if TARGET-TYPE is `network'.
 
 CODING-SYSTEM is a coding system to perform code conversion on the I/O
-operation, or a cons cell (DECODING . ENCODING) specifying the coding systems
-for decoding and encoding respectively,
-or a function symbol which, when called, returns such a cons cell."
+operation, or a cons cell (DECODING . ENCODING) specifying the coding
+systems for decoding and encoding respectively, or a function symbol
+which, when called, returns such a cons cell."
   (or (memq target-type '(file process network))
       (error "Invalid target type: %s" target-type))
   (or (stringp regexp)
@@ -2049,7 +2081,9 @@ Part of the job of this function is setting `buffer-undo-list' appropriately."
   (save-restriction
     (narrow-to-region start end)
     (encode-coding-region (point-min) (point-max) coding)
-    (decode-coding-region (point-min) (point-max) new-coding)))
+    (decode-coding-region (point-min) (point-max) new-coding))
+  (if (region-active-p)
+      (deactivate-mark)))
 
 (defun make-translation-table (&rest args)
   "Make a translation table from arguments.
@@ -2219,7 +2253,7 @@ It returns the number of characters changed."
 (put 'with-category-table 'lisp-indent-function 1)
 
 (defmacro with-category-table (table &rest body)
-  "Execute BODY like `progn' with CATEGORY-TABLE the current category table.
+  "Execute BODY like `progn' with TABLE the current category table.
 The category table of the current buffer is saved, BODY is evaluated,
 then the saved table is restored, even in case of an abnormal exit.
 Value is what BODY returns."
@@ -2270,7 +2304,7 @@ Analogous to `define-translation-table', but updates
       (make-char-table 'ignore-relative-composition))
 
 (make-obsolete 'set-char-table-default
-              "Generic characters no longer exist" "23.1")
+              "generic characters no longer exist." "23.1")
 
 ;;; Built-in auto-coding-functions: