]> code.delx.au - gnu-emacs/blobdiff - src/coding.c
(mail-extr-all-top-level-domains): More domains.
[gnu-emacs] / src / coding.c
index beb4de911dc50d295e35c984b38f0ab42da9ff15..ad73f5d2dbd96a13883c75ad3e8b0bdcf719f19e 100644 (file)
@@ -67,7 +67,12 @@ Boston, MA 02111-1307, USA.  */
   (all uppercase), we mean the coding system, and when we write
   "Big5" (capitalized), we mean the character set.
 
-  4. Other
+  4. Raw text
+
+  A coding system for a text containing random 8-bit code.  Emacs does
+  no code conversion on such a text except for end-of-line format.
+
+  5. Other
 
   If a user wants to read/write a text encoded in a coding system not
   listed above, he can supply a decoder and an encoder for it in CCL
@@ -246,6 +251,9 @@ encode_coding_XXX (coding, source, destination, src_bytes, dst_bytes, consumed)
 Lisp_Object Qcoding_system, Qeol_type;
 Lisp_Object Qbuffer_file_coding_system;
 Lisp_Object Qpost_read_conversion, Qpre_write_conversion;
+Lisp_Object Qno_conversion, Qundecided;
+Lisp_Object Qcoding_system_history;
+Lisp_Object Qsafe_charsets;
 
 extern Lisp_Object Qinsert_file_contents, Qwrite_region;
 Lisp_Object Qcall_process, Qcall_process_region, Qprocess_argument;
@@ -264,7 +272,9 @@ int system_eol_type;
 
 #ifdef emacs
 
-Lisp_Object Qcoding_system_spec, Qcoding_system_p, Qcoding_system_error;
+Lisp_Object Vcoding_system_list, Vcoding_system_alist;
+
+Lisp_Object Qcoding_system_p, Qcoding_system_error;
 
 /* Coding system emacs-mule is for converting only end-of-line format.  */
 Lisp_Object Qemacs_mule;
@@ -279,8 +289,8 @@ Lisp_Object Vcoding_system_for_write;
 Lisp_Object Vlast_coding_system_used;
 
 /* A vector of length 256 which contains information about special
-   Microsoft codes.  */
-Lisp_Object Vmicrosoft_code_table;
+   Latin codes (espepcially for dealing with Microsoft code).  */
+Lisp_Object Vlatin_extra_code_table;
 
 /* Flag to inhibit code conversion of end-of-line format.  */
 int inhibit_eol_conversion;
@@ -319,6 +329,7 @@ char *coding_category_name[CODING_CATEGORY_IDX_MAX] = {
   "coding-category-iso-7-else",
   "coding-category-iso-8-else",
   "coding-category-big5",
+  "coding-category-raw-text",
   "coding-category-binary"
 };
 
@@ -621,8 +632,17 @@ detect_coding_iso2022 (src, src_end)
              );
   int g1 = 0;                  /* 1 iff designating to G1.  */
   int c, i;
+  struct coding_system coding_iso_8_1, coding_iso_8_2;
 
-  while (src < src_end)
+  /* Coding systems of these categories may accept latin extra codes.  */
+  setup_coding_system
+    (XSYMBOL (coding_category_table[CODING_CATEGORY_IDX_ISO_8_1])->value,
+     &coding_iso_8_1);
+  setup_coding_system
+    (XSYMBOL (coding_category_table[CODING_CATEGORY_IDX_ISO_8_2])->value,
+     &coding_iso_8_2);
+
+  while (mask && src < src_end)
     {
       c = *src++;
       switch (c)
@@ -683,21 +703,46 @@ detect_coding_iso2022 (src, src_end)
        case ISO_CODE_CSI:
        case ISO_CODE_SS2:
        case ISO_CODE_SS3:
-         return CODING_CATEGORY_MASK_ISO_8_ELSE;
+         {
+           int newmask = CODING_CATEGORY_MASK_ISO_8_ELSE;
+
+           if (c != ISO_CODE_CSI)
+             {
+               if (coding_iso_8_1.flags & CODING_FLAG_ISO_SINGLE_SHIFT)
+                 newmask |= CODING_CATEGORY_MASK_ISO_8_1;
+               if (coding_iso_8_2.flags & CODING_FLAG_ISO_SINGLE_SHIFT)
+                 newmask |= CODING_CATEGORY_MASK_ISO_8_2;
+             }
+           if (VECTORP (Vlatin_extra_code_table)
+               && !NILP (XVECTOR (Vlatin_extra_code_table)->contents[c]))
+             {
+               if (coding_iso_8_1.flags & CODING_FLAG_ISO_LATIN_EXTRA)
+                 newmask |= CODING_CATEGORY_MASK_ISO_8_1;
+               if (coding_iso_8_2.flags & CODING_FLAG_ISO_LATIN_EXTRA)
+                 newmask |= CODING_CATEGORY_MASK_ISO_8_2;
+             }
+           mask &= newmask;
+         }
+         break;
 
        default:
          if (c < 0x80)
            break;
          else if (c < 0xA0)
            {
-             if (VECTORP (Vmicrosoft_code_table)
-                 && !NILP (XVECTOR (Vmicrosoft_code_table)->contents[c]))
+             if (VECTORP (Vlatin_extra_code_table)
+                 && !NILP (XVECTOR (Vlatin_extra_code_table)->contents[c]))
                {
-                 mask &= ~(CODING_CATEGORY_MASK_ISO_7
-                           | CODING_CATEGORY_MASK_ISO_7_ELSE);
-                 break;
+                 int newmask = 0;
+
+                 if (coding_iso_8_1.flags & CODING_FLAG_ISO_LATIN_EXTRA)
+                   newmask |= CODING_CATEGORY_MASK_ISO_8_1;
+                 if (coding_iso_8_2.flags & CODING_FLAG_ISO_LATIN_EXTRA)
+                   newmask |= CODING_CATEGORY_MASK_ISO_8_2;
+                 mask &= newmask;
                }
-             return 0;
+             else
+               return 0;
            }
          else
            {
@@ -737,7 +782,15 @@ detect_coding_iso2022 (src, src_end)
     if ((charset) >= 0)                                                        \
       {                                                                        \
        if (CHARSET_DIMENSION (charset) == 2)                           \
-         ONE_MORE_BYTE (c2);                                           \
+         {                                                             \
+           ONE_MORE_BYTE (c2);                                         \
+           if (iso_code_class[(c2) & 0x7F] != ISO_0x20_or_0x7F         \
+               && iso_code_class[(c2) & 0x7F] != ISO_graphic_plane_0)  \
+             {                                                         \
+               src--;                                                  \
+               c2 = ' ';                                               \
+             }                                                         \
+         }                                                             \
        if (!NILP (unification_table)                                   \
            && ((c_alt = unify_char (unification_table,                 \
                                     -1, (charset), c1, c2)) >= 0))     \
@@ -1094,13 +1147,12 @@ decode_coding_iso2022 (coding, source, destination,
     unsigned char final_char = CHARSET_ISO_FINAL_CHAR (charset);       \
     char *intermediate_char_94 = "()*+";                               \
     char *intermediate_char_96 = ",-./";                               \
-    Lisp_Object temp                                                   \
-      = Fassq (make_number (charset), Vcharset_revision_alist);                \
-    if (! NILP (temp))                                                 \
-       {                                                               \
+    int revision = CODING_SPEC_ISO_REVISION_NUMBER(coding, charset);   \
+    if (revision < 255)                                                        \
+      {                                                                        \
        *dst++ = ISO_CODE_ESC;                                          \
        *dst++ = '&';                                                   \
-       *dst++ = XINT (XCONS (temp)->cdr) + '@';                        \
+       *dst++ = '@' + revision;                                        \
       }                                                                        \
     *dst++ = ISO_CODE_ESC;                                             \
     if (CHARSET_DIMENSION (charset) == 1)                              \
@@ -1182,88 +1234,86 @@ decode_coding_iso2022 (coding, source, destination,
    sequences are also produced in advance if necessary.  */
 
 
-#define ENCODE_ISO_CHARACTER_DIMENSION1(charset, c1)                    \
-  do {                                                                  \
-    if (CODING_SPEC_ISO_SINGLE_SHIFTING (coding))                       \
-      {                                                                         \
-       if (coding->flags & CODING_FLAG_ISO_SEVEN_BITS)                  \
-         *dst++ = c1 & 0x7F;                                            \
-       else                                                             \
-         *dst++ = c1 | 0x80;                                            \
-       CODING_SPEC_ISO_SINGLE_SHIFTING (coding) = 0;                    \
-       break;                                                           \
-      }                                                                         \
-    else if (charset == CODING_SPEC_ISO_PLANE_CHARSET (coding, 0))      \
-      {                                                                         \
-       *dst++ = c1 & 0x7F;                                              \
-       break;                                                           \
-      }                                                                         \
-    else if (charset == CODING_SPEC_ISO_PLANE_CHARSET (coding, 1))      \
-      {                                                                         \
-       *dst++ = c1 | 0x80;                                              \
-       break;                                                           \
-      }                                                                         \
-    else if (coding->flags & CODING_FLAG_ISO_SAFE                       \
-            && (CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) \
-                == CODING_SPEC_ISO_NO_REQUESTED_DESIGNATION))           \
-      {                                                                         \
-       /* We should not encode this character, instead produce one or   \
-          two `?'s.  */                                                 \
-       *dst++ = CODING_INHIBIT_CHARACTER_SUBSTITUTION;                  \
-       if (CHARSET_WIDTH (charset) == 2)                                \
-         *dst++ = CODING_INHIBIT_CHARACTER_SUBSTITUTION;                \
-       break;                                                           \
-      }                                                                         \
-    else                                                                \
-      /* Since CHARSET is not yet invoked to any graphic planes, we     \
-        must invoke it, or, at first, designate it to some graphic      \
-        register.  Then repeat the loop to actually produce the         \
-        character.  */                                                  \
-      dst = encode_invocation_designation (charset, coding, dst);       \
+#define ENCODE_ISO_CHARACTER_DIMENSION1(charset, c1)                   \
+  do {                                                                 \
+    if (CODING_SPEC_ISO_SINGLE_SHIFTING (coding))                      \
+      {                                                                        \
+       if (coding->flags & CODING_FLAG_ISO_SEVEN_BITS)                 \
+         *dst++ = c1 & 0x7F;                                           \
+       else                                                            \
+         *dst++ = c1 | 0x80;                                           \
+       CODING_SPEC_ISO_SINGLE_SHIFTING (coding) = 0;                   \
+       break;                                                          \
+      }                                                                        \
+    else if (charset == CODING_SPEC_ISO_PLANE_CHARSET (coding, 0))     \
+      {                                                                        \
+       *dst++ = c1 & 0x7F;                                             \
+       break;                                                          \
+      }                                                                        \
+    else if (charset == CODING_SPEC_ISO_PLANE_CHARSET (coding, 1))     \
+      {                                                                        \
+       *dst++ = c1 | 0x80;                                             \
+       break;                                                          \
+      }                                                                        \
+    else if (coding->flags & CODING_FLAG_ISO_SAFE                      \
+            && !coding->safe_charsets[charset])                        \
+      {                                                                        \
+       /* We should not encode this character, instead produce one or  \
+          two `?'s.  */                                                \
+       *dst++ = CODING_INHIBIT_CHARACTER_SUBSTITUTION;                 \
+       if (CHARSET_WIDTH (charset) == 2)                               \
+         *dst++ = CODING_INHIBIT_CHARACTER_SUBSTITUTION;               \
+       break;                                                          \
+      }                                                                        \
+    else                                                               \
+      /* Since CHARSET is not yet invoked to any graphic planes, we    \
+        must invoke it, or, at first, designate it to some graphic     \
+        register.  Then repeat the loop to actually produce the        \
+        character.  */                                                 \
+      dst = encode_invocation_designation (charset, coding, dst);      \
   } while (1)
 
 /* Produce codes for a DIMENSION2 character whose character set is
    CHARSET and whose position-codes are C1 and C2.  Designation and
    invocation codes are also produced in advance if necessary.  */
 
-#define ENCODE_ISO_CHARACTER_DIMENSION2(charset, c1, c2)                \
-  do {                                                                  \
-    if (CODING_SPEC_ISO_SINGLE_SHIFTING (coding))                       \
-      {                                                                         \
-       if (coding->flags & CODING_FLAG_ISO_SEVEN_BITS)                  \
-         *dst++ = c1 & 0x7F, *dst++ = c2 & 0x7F;                        \
-       else                                                             \
-         *dst++ = c1 | 0x80, *dst++ = c2 | 0x80;                        \
-       CODING_SPEC_ISO_SINGLE_SHIFTING (coding) = 0;                    \
-       break;                                                           \
-      }                                                                         \
-    else if (charset == CODING_SPEC_ISO_PLANE_CHARSET (coding, 0))      \
-      {                                                                         \
-       *dst++ = c1 & 0x7F, *dst++= c2 & 0x7F;                           \
-       break;                                                           \
-      }                                                                         \
-    else if (charset == CODING_SPEC_ISO_PLANE_CHARSET (coding, 1))      \
-      {                                                                         \
-       *dst++ = c1 | 0x80, *dst++= c2 | 0x80;                           \
-       break;                                                           \
-      }                                                                         \
-    else if (coding->flags & CODING_FLAG_ISO_SAFE                       \
-            && (CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) \
-                == CODING_SPEC_ISO_NO_REQUESTED_DESIGNATION))           \
-      {                                                                         \
-       /* We should not encode this character, instead produce one or   \
-          two `?'s.  */                                                 \
-       *dst++ = CODING_INHIBIT_CHARACTER_SUBSTITUTION;                  \
-       if (CHARSET_WIDTH (charset) == 2)                                \
-         *dst++ = CODING_INHIBIT_CHARACTER_SUBSTITUTION;                \
-       break;                                                           \
-      }                                                                         \
-    else                                                                \
-      /* Since CHARSET is not yet invoked to any graphic planes, we     \
-        must invoke it, or, at first, designate it to some graphic      \
-        register.  Then repeat the loop to actually produce the         \
-        character.  */                                                  \
-      dst = encode_invocation_designation (charset, coding, dst);       \
+#define ENCODE_ISO_CHARACTER_DIMENSION2(charset, c1, c2)               \
+  do {                                                                 \
+    if (CODING_SPEC_ISO_SINGLE_SHIFTING (coding))                      \
+      {                                                                        \
+       if (coding->flags & CODING_FLAG_ISO_SEVEN_BITS)                 \
+         *dst++ = c1 & 0x7F, *dst++ = c2 & 0x7F;                       \
+       else                                                            \
+         *dst++ = c1 | 0x80, *dst++ = c2 | 0x80;                       \
+       CODING_SPEC_ISO_SINGLE_SHIFTING (coding) = 0;                   \
+       break;                                                          \
+      }                                                                        \
+    else if (charset == CODING_SPEC_ISO_PLANE_CHARSET (coding, 0))     \
+      {                                                                        \
+       *dst++ = c1 & 0x7F, *dst++= c2 & 0x7F;                          \
+       break;                                                          \
+      }                                                                        \
+    else if (charset == CODING_SPEC_ISO_PLANE_CHARSET (coding, 1))     \
+      {                                                                        \
+       *dst++ = c1 | 0x80, *dst++= c2 | 0x80;                          \
+       break;                                                          \
+      }                                                                        \
+    else if (coding->flags & CODING_FLAG_ISO_SAFE                      \
+            && !coding->safe_charsets[charset])                        \
+      {                                                                        \
+       /* We should not encode this character, instead produce one or  \
+          two `?'s.  */                                                \
+       *dst++ = CODING_INHIBIT_CHARACTER_SUBSTITUTION;                 \
+       if (CHARSET_WIDTH (charset) == 2)                               \
+         *dst++ = CODING_INHIBIT_CHARACTER_SUBSTITUTION;               \
+       break;                                                          \
+      }                                                                        \
+    else                                                               \
+      /* Since CHARSET is not yet invoked to any graphic planes, we    \
+        must invoke it, or, at first, designate it to some graphic     \
+        register.  Then repeat the loop to actually produce the        \
+        character.  */                                                 \
+      dst = encode_invocation_designation (charset, coding, dst);      \
   } while (1)
 
 #define ENCODE_ISO_CHARACTER(charset, c1, c2)                            \
@@ -1406,7 +1456,8 @@ encode_designation_at_bol (coding, table, src, src_end, dstp)
        charset = CHARSET_AT (src);
       else
        {
-         int c_alt, c1, c2;
+         int c_alt;
+         unsigned char c1, c2;
 
          SPLIT_STRING(src, bytes, charset, c1, c2);
          if ((c_alt = unify_char (table, -1, charset, c1, c2)) >= 0)
@@ -1414,7 +1465,7 @@ encode_designation_at_bol (coding, table, src, src_end, dstp)
        }
 
       reg = CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset);
-      if (r[reg] == CODING_SPEC_ISO_NO_REQUESTED_DESIGNATION)
+      if (r[reg] < 0)
        {
          found++;
          r[reg] = charset;
@@ -2264,10 +2315,11 @@ setup_coding_system (coding_system, coding)
      Lisp_Object coding_system;
      struct coding_system *coding;
 {
-  Lisp_Object type, eol_type;
+  Lisp_Object coding_spec, plist, type, eol_type;
+  Lisp_Object val;
+  int i;
 
   /* At first, set several fields to default values.  */
-  coding->require_flushing = 0;
   coding->last_block = 0;
   coding->selective = 0;
   coding->composing = 0;
@@ -2279,82 +2331,102 @@ setup_coding_system (coding_system, coding)
 
   Vlast_coding_system_used = coding->symbol = coding_system;
   eol_type = Qnil;
-  /* Get value of property `coding-system' until we get a vector.
-     While doing that, also get values of properties
+
+  /* Get values of property `coding-system' and `eol-type'.
+     Also get values of coding system properties:
      `post-read-conversion', `pre-write-conversion',
      `character-unification-table-for-decode',
-     `character-unification-table-for-encode' and `eol-type'.  */
-  while (!NILP (coding_system) && SYMBOLP (coding_system))
+     `character-unification-table-for-encode'.  */
+  coding_spec = Fget (coding_system, Qcoding_system);
+  if (!VECTORP (coding_spec)
+      || XVECTOR (coding_spec)->size != 5
+      || !CONSP (XVECTOR (coding_spec)->contents[3]))
+    goto label_invalid_coding_system;
+  if (!inhibit_eol_conversion)
+    eol_type = Fget (coding_system, Qeol_type);
+
+  plist = XVECTOR (coding_spec)->contents[3];
+  coding->post_read_conversion = Fplist_get (plist, Qpost_read_conversion);
+  coding->pre_write_conversion = Fplist_get (plist, Qpre_write_conversion);
+  val = Fplist_get (plist, Qcharacter_unification_table_for_decode);
+  if (SYMBOLP (val))
+    val = Fget (val, Qcharacter_unification_table_for_decode);
+  coding->character_unification_table_for_decode
+    = CHAR_TABLE_P (val) ? val : Qnil;
+  val = Fplist_get (plist, Qcharacter_unification_table_for_encode);
+  if (SYMBOLP (val))
+    val = Fget (val, Qcharacter_unification_table_for_encode);
+  coding->character_unification_table_for_encode
+    = CHAR_TABLE_P (val) ? val : Qnil;
+  
+  val = Fplist_get (plist, Qsafe_charsets);
+  if (EQ (val, Qt))
     {
-      if (NILP (coding->post_read_conversion))
-       coding->post_read_conversion = Fget (coding_system,
-                                            Qpost_read_conversion);
-      if (NILP (coding->pre_write_conversion)) 
-       coding->pre_write_conversion = Fget (coding_system,
-                                            Qpre_write_conversion);
-      if (!inhibit_eol_conversion && NILP (eol_type))
-       eol_type = Fget (coding_system, Qeol_type);
-
-      if (NILP (coding->character_unification_table_for_decode))
-       coding->character_unification_table_for_decode
-         = Fget (coding_system, Qcharacter_unification_table_for_decode);
-
-      if (NILP (coding->character_unification_table_for_encode))
-       coding->character_unification_table_for_encode
-         = Fget (coding_system, Qcharacter_unification_table_for_encode);
-
-      coding_system = Fget (coding_system, Qcoding_system);
+      for (i = 0; i <= MAX_CHARSET; i++)
+       coding->safe_charsets[i] = 1;
+    }
+  else
+    {
+      bzero (coding->safe_charsets, MAX_CHARSET + 1);
+      while (CONSP (val))
+       {
+         if ((i = get_charset_id (XCONS (val)->car)) >= 0)
+           coding->safe_charsets[i] = 1;
+         val = XCONS (val)->cdr;
+       }
     }
-
-  while (!NILP (coding->character_unification_table_for_decode)
-        && SYMBOLP (coding->character_unification_table_for_decode))
-       coding->character_unification_table_for_decode
-         = Fget (coding->character_unification_table_for_decode,
-                 Qcharacter_unification_table_for_decode);
-  if (!NILP (coding->character_unification_table_for_decode)
-      && !CHAR_TABLE_P (coding->character_unification_table_for_decode))
-      coding->character_unification_table_for_decode = Qnil;
-
-  while (!NILP (coding->character_unification_table_for_encode)
-        && SYMBOLP (coding->character_unification_table_for_encode))
-       coding->character_unification_table_for_encode
-         = Fget (coding->character_unification_table_for_encode,
-                 Qcharacter_unification_table_for_encode);
-  if (!NILP (coding->character_unification_table_for_encode)
-      && !CHAR_TABLE_P (coding->character_unification_table_for_encode))
-      coding->character_unification_table_for_encode = Qnil;
-
-  if (!VECTORP (coding_system)
-      || XVECTOR (coding_system)->size != 5)
-    goto label_invalid_coding_system;
 
   if (VECTORP (eol_type))
-    coding->eol_type = CODING_EOL_UNDECIDED;
+    {
+      coding->eol_type = CODING_EOL_UNDECIDED;
+      coding->common_flags = CODING_REQUIRE_DETECTION_MASK;
+    }
   else if (XFASTINT (eol_type) == 1)
-    coding->eol_type = CODING_EOL_CRLF;
+    {
+      coding->eol_type = CODING_EOL_CRLF;
+      coding->common_flags
+       = CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK;
+    }
   else if (XFASTINT (eol_type) == 2)
-    coding->eol_type = CODING_EOL_CR;
+    {
+      coding->eol_type = CODING_EOL_CR;
+      coding->common_flags
+       = CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK;
+    }
   else
-    coding->eol_type = CODING_EOL_LF;
+    {
+      coding->eol_type = CODING_EOL_LF;
+      coding->common_flags = 0;
+    }
 
-  type = XVECTOR (coding_system)->contents[0];
+  type = XVECTOR (coding_spec)->contents[0];
   switch (XFASTINT (type))
     {
     case 0:
       coding->type = coding_type_emacs_mule;
+      if (!NILP (coding->post_read_conversion))
+       coding->common_flags |= CODING_REQUIRE_DECODING_MASK;
+      if (!NILP (coding->pre_write_conversion))
+       coding->common_flags |= CODING_REQUIRE_ENCODING_MASK;
       break;
 
     case 1:
       coding->type = coding_type_sjis;
+      coding->common_flags
+       |= CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK;
       break;
 
     case 2:
       coding->type = coding_type_iso2022;
+      coding->common_flags
+       |= CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK;
       {
-       Lisp_Object val = XVECTOR (coding_system)->contents[4];
+       Lisp_Object val, temp;
        Lisp_Object *flags;
        int i, charset, default_reg_bits = 0;
 
+       val = XVECTOR (coding_spec)->contents[4];
+
        if (!VECTORP (val) || XVECTOR (val)->size != 32)
          goto label_invalid_coding_system;
 
@@ -2372,6 +2444,7 @@ setup_coding_system (coding_system, coding)
             | (NILP (flags[13]) ? 0 : CODING_FLAG_ISO_INIT_AT_BOL)
             | (NILP (flags[14]) ? 0 : CODING_FLAG_ISO_DESIGNATE_AT_BOL)
             | (NILP (flags[15]) ? 0 : CODING_FLAG_ISO_SAFE)
+            | (NILP (flags[16]) ? 0 : CODING_FLAG_ISO_LATIN_EXTRA)
             );
 
        /* Invoke graphic register 0 to plane 0.  */
@@ -2380,9 +2453,22 @@ setup_coding_system (coding_system, coding)
        CODING_SPEC_ISO_INVOCATION (coding, 1)
          = (coding->flags & CODING_FLAG_ISO_SEVEN_BITS ? -1 : 1);
        /* Not single shifting at first.  */
-       CODING_SPEC_ISO_SINGLE_SHIFTING(coding) = 0;
+       CODING_SPEC_ISO_SINGLE_SHIFTING (coding) = 0;
        /* Beginning of buffer should also be regarded as bol. */
-       CODING_SPEC_ISO_BOL(coding) = 1;
+       CODING_SPEC_ISO_BOL (coding) = 1;
+
+       for (charset = 0; charset <= MAX_CHARSET; charset++)
+         CODING_SPEC_ISO_REVISION_NUMBER (coding, charset) = 255;
+       val = Vcharset_revision_alist;
+       while (CONSP (val))
+         {
+           charset = get_charset_id (Fcar_safe (XCONS (val)->car));
+           if (charset >= 0
+               && (temp = Fcdr_safe (XCONS (val)->car), INTEGERP (temp))
+               && (i = XINT (temp), (i >= 0 && (i + '@') < 128)))
+             CODING_SPEC_ISO_REVISION_NUMBER (coding, charset) = i;
+           val = XCONS (val)->cdr;
+         }
 
        /* Checks FLAGS[REG] (REG = 0, 1, 2 3) and decide designations.
           FLAGS[REG] can be one of below:
@@ -2456,51 +2542,54 @@ setup_coding_system (coding_system, coding)
              default_reg_bits &= 3;
          }
 
-       if (! (coding->flags & CODING_FLAG_ISO_SAFE))
-         for (charset = 0; charset <= MAX_CHARSET; charset++)
-           if (CHARSET_VALID_P (charset)
-               && (CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset)
-                   == CODING_SPEC_ISO_NO_REQUESTED_DESIGNATION))
-             {
-               /* We have not yet decided where to designate CHARSET.  */
-               int reg_bits = default_reg_bits;
-
-               if (CHARSET_CHARS (charset) == 96)
-                 /* A charset of CHARS96 can't be designated to REG 0.  */
-                 reg_bits &= ~1;
-
-               if (reg_bits)
-                 /* There exist some default graphic register.  */
-                 CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset)
-                   = (reg_bits & 1
-                      ? 0 : (reg_bits & 2 ? 1 : (reg_bits & 4 ? 2 : 3)));
-               else
-                 /* We anyway have to designate CHARSET to somewhere.  */
-                 CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset)
-                   = (CHARSET_CHARS (charset) == 94
-                      ? 0
-                      : ((coding->flags & CODING_FLAG_ISO_LOCKING_SHIFT
-                          || ! coding->flags & CODING_FLAG_ISO_SEVEN_BITS)
-                         ? 1
-                         : (coding->flags & CODING_FLAG_ISO_SINGLE_SHIFT
-                            ? 2 : 0)));
-             }
+       for (charset = 0; charset <= MAX_CHARSET; charset++)
+         if (CHARSET_VALID_P (charset)
+             && (CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset)
+                 == CODING_SPEC_ISO_NO_REQUESTED_DESIGNATION))
+           {
+             /* We have not yet decided where to designate CHARSET.  */
+             int reg_bits = default_reg_bits;
+
+             if (CHARSET_CHARS (charset) == 96)
+               /* A charset of CHARS96 can't be designated to REG 0.  */
+               reg_bits &= ~1;
+
+             if (reg_bits)
+               /* There exist some default graphic register.  */
+               CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset)
+                 = (reg_bits & 1
+                    ? 0 : (reg_bits & 2 ? 1 : (reg_bits & 4 ? 2 : 3)));
+             else
+               /* We anyway have to designate CHARSET to somewhere.  */
+               CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset)
+                 = (CHARSET_CHARS (charset) == 94
+                    ? 0
+                    : ((coding->flags & CODING_FLAG_ISO_LOCKING_SHIFT
+                        || ! coding->flags & CODING_FLAG_ISO_SEVEN_BITS)
+                       ? 1
+                       : (coding->flags & CODING_FLAG_ISO_SINGLE_SHIFT
+                          ? 2 : 0)));
+           }
       }
-      coding->require_flushing = 1;
+      coding->common_flags |= CODING_REQUIRE_FLUSHING_MASK;
       break;
 
     case 3:
       coding->type = coding_type_big5;
+      coding->common_flags
+       |= CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK;
       coding->flags
-       = (NILP (XVECTOR (coding_system)->contents[4])
+       = (NILP (XVECTOR (coding_spec)->contents[4])
           ? CODING_FLAG_BIG5_HKU
           : CODING_FLAG_BIG5_ETEN);
       break;
 
     case 4:
       coding->type = coding_type_ccl;
+      coding->common_flags
+       |= CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK;
       {
-       Lisp_Object val = XVECTOR (coding_system)->contents[4];
+       Lisp_Object val = XVECTOR (coding_spec)->contents[4];
        if (CONSP  (val)
            && VECTORP (XCONS (val)->car)
            && VECTORP (XCONS (val)->cdr))
@@ -2511,12 +2600,19 @@ setup_coding_system (coding_system, coding)
        else
          goto label_invalid_coding_system;
       }
-      coding->require_flushing = 1;
+      coding->common_flags |= CODING_REQUIRE_FLUSHING_MASK;
+      break;
+
+    case 5:
+      coding->type = coding_type_raw_text;
       break;
 
     default:
       if (EQ (type, Qt))
-       coding->type = coding_type_undecided;
+       {
+         coding->type = coding_type_undecided;
+         coding->common_flags |= CODING_REQUIRE_DETECTION_MASK;
+       }
       else
        coding->type = coding_type_no_conversion;
       break;
@@ -2525,6 +2621,7 @@ setup_coding_system (coding_system, coding)
 
  label_invalid_coding_system:
   coding->type = coding_type_no_conversion;
+  coding->common_flags = 0;
   coding->eol_type = CODING_EOL_LF;
   coding->symbol = coding->pre_write_conversion = coding->post_read_conversion
     = Qnil;
@@ -2646,18 +2743,19 @@ detect_coding_mask (src, src_bytes)
       /* C is an ISO2022 specific control code of C0.  */
       mask = detect_coding_iso2022 (src, src_end);
       src++;
-      if (mask == CODING_CATEGORY_MASK_ANY)
+      if (mask == 0)
        /* No valid ISO2022 code follows C.  Try again.  */
        goto label_loop_detect_coding;
+      mask |= CODING_CATEGORY_MASK_RAW_TEXT;
     }
   else if (c < 0xA0)
     {
-      /* If C is a special Microsoft code,
+      /* If C is a special latin extra code,
         or is an ISO2022 specific control code of C1 (SS2 or SS3), 
         or is an ISO2022 control-sequence-introducer (CSI),
-        we should also consider the possibility of someof ISO2022 codings.  */
-      if ((VECTORP (Vmicrosoft_code_table)
-          && !NILP (XVECTOR (Vmicrosoft_code_table)->contents[c]))
+        we should also consider the possibility of ISO2022 codings.  */
+      if ((VECTORP (Vlatin_extra_code_table)
+          && !NILP (XVECTOR (Vlatin_extra_code_table)->contents[c]))
          || (c == ISO_CODE_SS2 || c == ISO_CODE_SS3)
          || (c == ISO_CODE_CSI
              && (src < src_end
@@ -2668,14 +2766,14 @@ detect_coding_mask (src, src_bytes)
        mask = (detect_coding_iso2022 (src, src_end)
                | detect_coding_sjis (src, src_end)
                | detect_coding_emacs_mule (src, src_end)
-               | CODING_CATEGORY_MASK_BINARY);
+               | CODING_CATEGORY_MASK_RAW_TEXT);
 
       else
-       /* C is the first byte of SJIS character code, or a
-          leading-code of Emacs.  */
+       /* C is the first byte of SJIS character code,
+          or a leading-code of Emacs' internal format (emacs-mule).  */
        mask = (detect_coding_sjis (src, src_end)
                | detect_coding_emacs_mule (src, src_end)
-               | CODING_CATEGORY_MASK_BINARY);
+               | CODING_CATEGORY_MASK_RAW_TEXT);
     }
   else
     /* C is a character of ISO2022 in graphic plane right,
@@ -2684,7 +2782,7 @@ detect_coding_mask (src, src_bytes)
     mask = (detect_coding_iso2022 (src, src_end)
            | detect_coding_sjis (src, src_end)
            | detect_coding_big5 (src, src_end)
-           | CODING_CATEGORY_MASK_BINARY);
+           | CODING_CATEGORY_MASK_RAW_TEXT);
 
   return mask;
 }
@@ -2700,42 +2798,33 @@ detect_coding (coding, src, src_bytes)
 {
   int mask = detect_coding_mask (src, src_bytes);
   int idx;
+  Lisp_Object val = Vcoding_category_list;
 
   if (mask == CODING_CATEGORY_MASK_ANY)
     /* We found nothing other than ASCII.  There's nothing to do.  */
     return;
 
-  if (!mask)
-    /* The source text seems to be encoded in unknown coding system.
-       Emacs regards the category of such a kind of coding system as
-       `coding-category-binary'.  We assume that a user has assigned
-       an appropriate coding system for a `coding-category-binary'.  */
-    idx = CODING_CATEGORY_IDX_BINARY;
-  else
-    {
-      /* We found some plausible coding systems.  Let's use a coding
-        system of the highest priority.  */
-      Lisp_Object val = Vcoding_category_list;
+  /* We found some plausible coding systems.  Let's use a coding
+     system of the highest priority.  */
 
-      if (CONSP (val))
-       while (!NILP (val))
-         {
-           idx = XFASTINT (Fget (XCONS (val)->car, Qcoding_category_index));
-           if ((idx < CODING_CATEGORY_IDX_MAX) && (mask & (1 << idx)))
-             break;
-           val = XCONS (val)->cdr;
-         }
-      else
-       val = Qnil;
+  if (CONSP (val))
+    while (!NILP (val))
+      {
+       idx = XFASTINT (Fget (XCONS (val)->car, Qcoding_category_index));
+       if ((idx < CODING_CATEGORY_IDX_MAX) && (mask & (1 << idx)))
+         break;
+       val = XCONS (val)->cdr;
+      }
+  else
+    val = Qnil;
 
-      if (NILP (val))
-       {
-         /* For unknown reason, `Vcoding_category_list' contains none
-            of found categories.  Let's use any of them.  */
-         for (idx = 0; idx < CODING_CATEGORY_IDX_MAX; idx++)
-           if (mask & (1 << idx))
-             break;
-       }
+  if (NILP (val))
+    {
+      /* For unknown reason, `Vcoding_category_list' contains none of
+        found categories.  Let's use any of them.  */
+      for (idx = 0; idx < CODING_CATEGORY_IDX_MAX; idx++)
+       if (mask & (1 << idx))
+         break;
     }
   setup_coding_system (XSYMBOL (coding_category_table[idx])->value, coding);
 }
@@ -2775,8 +2864,8 @@ detect_eol_type (src, src_bytes)
            eol_type = this_eol_type;
          else if (eol_type != this_eol_type)
            /* The found type is different from what found before.
-              We had better not decode end-of-line.  */
-           return CODING_EOL_LF;
+              Let's notice the caller about this inconsistency.  */
+           return CODING_EOL_INCONSISTENT;
        }
     }
 
@@ -2800,6 +2889,24 @@ detect_eol (coding, src, src_bytes)
     /*  We found no end-of-line in the source text.  */
     return;
 
+  if (eol_type == CODING_EOL_INCONSISTENT)
+    {
+#if 0
+      /* This code is suppressed until we find a better way to
+        distinguish raw text file and binary file.  */
+
+      /* If we have already detected that the coding is raw-text, the
+        coding should actually be no-conversion.  */
+      if (coding->type == coding_type_raw_text)
+       {
+         setup_coding_system (Qno_conversion, coding);
+         return;
+       }
+      /* Else, let's decode only text code anyway.  */
+#endif /* 0 */
+      eol_type = CODING_EOL_LF;
+    }
+
   val = Fget (coding->symbol, Qeol_type);
   if (VECTORP (val) && XVECTOR (val)->size == 3)
     setup_coding_system (XVECTOR (val)->contents[eol_type], coding);
@@ -2842,6 +2949,7 @@ decode_coding (coding, source, destination, src_bytes, dst_bytes, consumed)
 
     case coding_type_emacs_mule:
     case coding_type_undecided:
+    case coding_type_raw_text:
       if (coding->eol_type == CODING_EOL_LF
          ||  coding->eol_type == CODING_EOL_UNDECIDED)
        goto label_no_conversion;
@@ -2906,6 +3014,7 @@ encode_coding (coding, source, destination, src_bytes, dst_bytes, consumed)
 
     case coding_type_emacs_mule:
     case coding_type_undecided:
+    case coding_type_raw_text:
       if (coding->eol_type == CODING_EOL_LF
          ||  coding->eol_type == CODING_EOL_UNDECIDED)
        goto label_no_conversion;
@@ -3012,26 +3121,20 @@ get_conversion_buffer (size)
 #ifdef emacs
 /*** 7. Emacs Lisp library functions ***/
 
-DEFUN ("coding-system-spec", Fcoding_system_spec, Scoding_system_spec,
-       1, 1, 0,
-  "Return coding-spec of CODING-SYSTEM.\n\
-If CODING-SYSTEM is not a valid coding-system, return nil.")
-  (obj)
-     Lisp_Object obj;
-{
-  while (SYMBOLP (obj) && !NILP (obj))
-    obj = Fget (obj, Qcoding_system);
-  return ((NILP (obj) || !VECTORP (obj) || XVECTOR (obj)->size != 5)
-         ? Qnil : obj);
-}
-
 DEFUN ("coding-system-p", Fcoding_system_p, Scoding_system_p, 1, 1, 0,
   "Return t if OBJECT is nil or a coding-system.\n\
 See document of make-coding-system for coding-system object.")
   (obj)
      Lisp_Object obj;
 {
-  return ((NILP (obj) || !NILP (Fcoding_system_spec (obj))) ? Qt : Qnil);
+  if (NILP (obj))
+    return Qt;
+  if (!SYMBOLP (obj))
+    return Qnil;
+  /* Get coding-spec vector for OBJ.  */
+  obj = Fget (obj, Qcoding_system);
+  return ((VECTORP (obj) && XVECTOR (obj)->size == 5)
+         ? Qt : Qnil);
 }
 
 DEFUN ("read-non-nil-coding-system", Fread_non_nil_coding_system,
@@ -3043,20 +3146,25 @@ DEFUN ("read-non-nil-coding-system", Fread_non_nil_coding_system,
   Lisp_Object val;
   do
     {
-      val = Fcompleting_read (prompt, Vobarray, Qcoding_system_spec,
-                             Qt, Qnil, Qnil, Qnil);
+      val = Fcompleting_read (prompt, Vcoding_system_alist, Qnil,
+                             Qt, Qnil, Qcoding_system_history, Qnil, Qnil);
     }
   while (XSTRING (val)->size == 0);
   return (Fintern (val, Qnil));
 }
 
-DEFUN ("read-coding-system", Fread_coding_system, Sread_coding_system, 1, 1, 0,
-  "Read a coding system or nil from the minibuffer, prompting with string PROMPT.")
-  (prompt)
-     Lisp_Object prompt;
+DEFUN ("read-coding-system", Fread_coding_system, Sread_coding_system, 1, 2, 0,
+  "Read a coding system from the minibuffer, prompting with string PROMPT.\n\
+If the user enters null input, return second argument DEFAULT-CODING-SYSTEM.")
+  (prompt, default_coding_system)
+     Lisp_Object prompt, default_coding_system;
 {
-  Lisp_Object val = Fcompleting_read (prompt, Vobarray, Qcoding_system_p,
-                                     Qt, Qnil, Qnil, Qnil);
+  Lisp_Object val;
+  if (SYMBOLP (default_coding_system))
+    XSETSTRING (default_coding_system, XSYMBOL (default_coding_system)->name);
+  val = Fcompleting_read (prompt, Vcoding_system_alist, Qnil,
+                         Qt, Qnil, Qcoding_system_history,
+                         default_coding_system, Qnil);
   return (XSTRING (val)->size == 0 ? Qnil : Fintern (val, Qnil));
 }
 
@@ -3098,10 +3206,12 @@ If only ASCII characters are found, it returns `undecided'\n\
 
   if (coding_mask == CODING_CATEGORY_MASK_ANY)
     {
-      val = intern ("undecided");
-      if (eol_type != CODING_EOL_UNDECIDED)
+      val = Qundecided;
+      if (eol_type != CODING_EOL_UNDECIDED
+         && eol_type != CODING_EOL_INCONSISTENT)
        {
-         Lisp_Object val2 = Fget (val, Qeol_type);
+         Lisp_Object val2;
+         val2 = Fget (Qundecided, Qeol_type);
          if (VECTORP (val2))
            val = XVECTOR (val2)->contents[eol_type];
        }
@@ -3120,20 +3230,34 @@ If only ASCII characters are found, it returns `undecided'\n\
          int idx
            = XFASTINT (Fget (XCONS (val2)->car, Qcoding_category_index));
          if (coding_mask & (1 << idx))
-           val = Fcons (Fsymbol_value (XCONS (val2)->car), val);
+           {
+#if 0
+             /* This code is suppressed until we find a better way to
+                distinguish raw text file and binary file.  */
+
+             if (idx == CODING_CATEGORY_IDX_RAW_TEXT
+                 && eol_type == CODING_EOL_INCONSISTENT)
+               val = Fcons (Qno_conversion, val);
+             else
+#endif /* 0 */
+               val = Fcons (Fsymbol_value (XCONS (val2)->car), val);
+           }
        }
 
       /* Then, change the order of the list, while getting subsidiary
         coding-systems.  */
       val2 = val;
       val = Qnil;
+      if (eol_type == CODING_EOL_INCONSISTENT)
+       eol_type == CODING_EOL_UNDECIDED;
       for (; !NILP (val2); val2 = XCONS (val2)->cdr)
        {
          if (eol_type == CODING_EOL_UNDECIDED)
            val = Fcons (XCONS (val2)->car, val);
          else
            {
-             Lisp_Object val3 = Fget (XCONS (val2)->car, Qeol_type);
+             Lisp_Object val3;
+             val3 = Fget (XCONS (val2)->car, Qeol_type);
              if (VECTORP (val3))
                val = Fcons (XVECTOR (val3)->contents[eol_type], val);
              else
@@ -3171,6 +3295,7 @@ shrink_conversion_area (begp, endp, coding, encodep)
        case coding_type_no_conversion:
        case coding_type_emacs_mule:
        case coding_type_undecided:
+       case coding_type_raw_text:
          /* We need no conversion.  */
          *begp = *endp;
          return;
@@ -3208,6 +3333,7 @@ shrink_conversion_area (begp, endp, coding, encodep)
          *begp = *endp;
          return;
        case coding_type_emacs_mule:
+       case coding_type_raw_text:
          if (coding->eol_type == CODING_EOL_LF)
            {
              /* We need no conversion.  */
@@ -3336,6 +3462,11 @@ code_convert_region (b, e, coding, encodep)
       TEMP_SET_PT (beg);
       insval = call1 (coding->post_read_conversion, make_number (len));
       CHECK_NUMBER (insval, 0);
+      if (pos >= beg + len)
+       pos += XINT (insval) - len;
+      else if (pos > beg)
+       pos = beg;
+      TEMP_SET_PT (pos);
       len = XINT (insval);
     }
 
@@ -3461,8 +3592,8 @@ Return length of encoded text.")
 DEFUN ("decode-coding-string", Fdecode_coding_string, Sdecode_coding_string,
        2, 3, 0,
   "Decode STRING which is encoded in CODING-SYSTEM, and return the result.\n\
-Optional arg NOCOPY non-nil means return STRING itself if there's no need\n\
-of decoding.")
+Optional arg NOCOPY non-nil means it is ok to return STRING itself\n\
+if the decoding operation is trivial.")
   (string, coding_system, nocopy)
      Lisp_Object string, coding_system, nocopy;
 {
@@ -3482,8 +3613,8 @@ of decoding.")
 DEFUN ("encode-coding-string", Fencode_coding_string, Sencode_coding_string,
        2, 3, 0,
   "Encode STRING to CODING-SYSTEM, and return the result.\n\
-Optional arg NOCOPY non-nil means return STRING itself if there's no need\n\
-of encoding.")
+Optional arg NOCOPY non-nil means it is ok to return STRING itself\n\
+if the encoding operation is trivial.")
   (string, coding_system, nocopy)
      Lisp_Object string, coding_system, nocopy;
 {
@@ -3585,6 +3716,9 @@ DEFUN ("set-terminal-coding-system-internal",
 {
   CHECK_SYMBOL (coding_system, 0);
   setup_coding_system (Fcheck_coding_system (coding_system), &terminal_coding);
+  /* We had better not send unsafe characters to terminal.  */
+  terminal_coding.flags |= CODING_FLAG_ISO_SAFE;
+
   return Qnil;
 }
 
@@ -3690,7 +3824,8 @@ which is a list of all the arguments given to this function.")
 
   for (; CONSP (chain); chain = XCONS (chain)->cdr)
     {
-      Lisp_Object elt = XCONS (chain)->car;
+      Lisp_Object elt;
+      elt = XCONS (chain)->car;
 
       if (CONSP (elt)
          && ((STRINGP (target)
@@ -3699,14 +3834,22 @@ which is a list of all the arguments given to this function.")
              || (INTEGERP (target) && EQ (target, XCONS (elt)->car))))
        {
          val = XCONS (elt)->cdr;
+         /* Here, if VAL is both a valid coding system and a valid
+             function symbol, we return VAL as a coding system.  */
          if (CONSP (val))
            return val;
          if (! SYMBOLP (val))
            return Qnil;
          if (! NILP (Fcoding_system_p (val)))
            return Fcons (val, val);
-         if (!NILP (Ffboundp (val)))
-           return call1 (val, Flist (nargs, args));
+         if (! NILP (Ffboundp (val)))
+           {
+             val = call1 (val, Flist (nargs, args));
+             if (CONSP (val))
+               return val;
+             if (SYMBOLP (val) && ! NILP (Fcoding_system_p (val)))
+               return Fcons (val, val);
+           }
          return Qnil;
        }
     }
@@ -3779,6 +3922,10 @@ syms_of_coding ()
   Qtarget_idx = intern ("target-idx");
   staticpro (&Qtarget_idx);
 
+  Qcoding_system_history = intern ("coding-system-history");
+  staticpro (&Qcoding_system_history);
+  Fset (Qcoding_system_history, Qnil);
+
   /* Target FILENAME is the first argument.  */
   Fput (Qinsert_file_contents, Qtarget_idx, make_number (0));
   /* Target FILENAME is the third argument.  */
@@ -3819,8 +3966,11 @@ syms_of_coding ()
   Qpre_write_conversion = intern ("pre-write-conversion");
   staticpro (&Qpre_write_conversion);
 
-  Qcoding_system_spec = intern ("coding-system-spec");
-  staticpro (&Qcoding_system_spec);
+  Qno_conversion = intern ("no-conversion");
+  staticpro (&Qno_conversion);
+
+  Qundecided = intern ("undecided");
+  staticpro (&Qundecided);
 
   Qcoding_system_p = intern ("coding-system-p");
   staticpro (&Qcoding_system_p);
@@ -3860,10 +4010,12 @@ syms_of_coding ()
     = intern ("character-unification-table-for-encode");
   staticpro (&Qcharacter_unification_table_for_encode);
 
+  Qsafe_charsets = intern ("safe-charsets");
+  staticpro (&Qsafe_charsets);
+
   Qemacs_mule = intern ("emacs-mule");
   staticpro (&Qemacs_mule);
 
-  defsubr (&Scoding_system_spec);
   defsubr (&Scoding_system_p);
   defsubr (&Sread_coding_system);
   defsubr (&Sread_non_nil_coding_system);
@@ -3884,6 +4036,24 @@ syms_of_coding ()
   defsubr (&Skeyboard_coding_system);
   defsubr (&Sfind_operation_coding_system);
 
+  DEFVAR_LISP ("coding-system-list", &Vcoding_system_list,
+    "List of coding systems.\n\
+\n\
+Do not alter the value of this variable manually.  This variable should be\n\
+updated by the functions `make-coding-system' and\n\
+`define-coding-system-alias'.");
+  Vcoding_system_list = Qnil;
+
+  DEFVAR_LISP ("coding-system-alist", &Vcoding_system_alist,
+    "Alist of coding system names.\n\
+Each element is one element list of coding system name.\n\
+This variable is given to `completing-read' as TABLE argument.\n\
+\n\
+Do not alter the value of this variable manually.  This variable should be\n\
+updated by the functions `make-coding-system' and\n\
+`define-coding-system-alias'.");
+  Vcoding_system_alist = Qnil;
+
   DEFVAR_LISP ("coding-category-list", &Vcoding_category_list,
     "List of coding-categories (symbols) ordered by priority.");
   {
@@ -4010,15 +4180,16 @@ The car part is used for decoding a process output,\n\
 the cdr part is used for encoding a text to be sent to a process.");
   Vdefault_process_coding_system = Qnil;
 
-  DEFVAR_LISP ("special-microsoft-code-table", &Vmicrosoft_code_table,
-    "Table of special Microsoft codes in the range 128..159 (inclusive).\n\
+  DEFVAR_LISP ("latin-extra-code-table", &Vlatin_extra_code_table,
+    "Table of extra Latin codes in the range 128..159 (inclusive).\n\
 This is a vector of length 256.\n\
 If Nth element is non-nil, the existence of code N in a file\n\
-(or output of subprocess) doesn't prevent it to be detected as\n\
-a coding system of ISO 2022 variant (e.g. iso-latin-1) on reading a file\n\
+\(or output of subprocess) doesn't prevent it to be detected as\n\
+a coding system of ISO 2022 variant which has a flag\n\
+`accept-latin-extra-code' t (e.g. iso-latin-1) on reading a file\n\
 or reading output of a subprocess.\n\
 Only 128th through 159th elements has a meaning.");
-  Vmicrosoft_code_table = Fmake_vector (make_number (256), Qnil);
+  Vlatin_extra_code_table = Fmake_vector (make_number (256), Qnil);
 }
 
 #endif /* emacs */