Use STRING_BYTES and SET_STRING_BYTES.
[bpt/emacs.git] / src / data.c
index be28445..300782a 100644 (file)
@@ -1,11 +1,11 @@
 /* Primitive operations on Lisp data types for GNU Emacs Lisp interpreter.
-   Copyright (C) 1985, 86, 88, 93, 94, 95 Free Software Foundation, Inc.
+   Copyright (C) 1985,86,88,93,94,95,97, 1998 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
 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 1, or (at your option)
+the Free Software Foundation; either version 2, or (at your option)
 any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
@@ -15,7 +15,8 @@ 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, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
 
 #include <signal.h>
@@ -23,25 +24,31 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include <config.h>
 #include "lisp.h"
 #include "puresize.h"
+#include "charset.h"
 
 #ifndef standalone
 #include "buffer.h"
 #include "keyboard.h"
+#include "frame.h"
 #endif
 
 #include "syssignal.h"
 
-#ifdef MSDOS
-/* These are redefined (correctly, but differently) in values.h.  */
-#undef INTBITS
-#undef LONGBITS
-#undef SHORTBITS
-#endif
-
 #ifdef LISP_FLOAT_TYPE
 
 #ifdef STDC_HEADERS
 #include <stdlib.h>
+#include <float.h>
+#endif
+
+/* If IEEE_FLOATING_POINT isn't defined, default it from FLT_*. */
+#ifndef IEEE_FLOATING_POINT
+#if (FLT_RADIX == 2 && FLT_MANT_DIG == 24 \
+     && FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128)
+#define IEEE_FLOATING_POINT 1
+#else
+#define IEEE_FLOATING_POINT 0
+#endif
 #endif
 
 /* Work around a problem that happens because math.h on hpux 7
@@ -74,6 +81,7 @@ Lisp_Object Qstringp, Qarrayp, Qsequencep, Qbufferp;
 Lisp_Object Qchar_or_string_p, Qmarkerp, Qinteger_or_marker_p, Qvectorp;
 Lisp_Object Qbuffer_or_string_p;
 Lisp_Object Qboundp, Qfboundp;
+Lisp_Object Qchar_table_p, Qvector_or_char_table_p;
 
 Lisp_Object Qcdr;
 Lisp_Object Qad_advice_info, Qad_activate;
@@ -87,11 +95,15 @@ Lisp_Object Qnumberp, Qnumber_or_marker_p;
 #endif
 
 static Lisp_Object Qinteger, Qsymbol, Qstring, Qcons, Qmarker, Qoverlay;
-static Lisp_Object Qfloat, Qwindow_configuration, Qprocess, Qwindow;
+static Lisp_Object Qfloat, Qwindow_configuration, Qwindow;
+Lisp_Object Qprocess;
 static Lisp_Object Qcompiled_function, Qbuffer, Qframe, Qvector;
+static Lisp_Object Qchar_table, Qbool_vector;
 
 static Lisp_Object swap_in_symval_forwarding ();
 
+Lisp_Object set_internal ();
+
 Lisp_Object
 wrong_type_argument (predicate, value)
      register Lisp_Object predicate, value;
@@ -103,7 +115,7 @@ wrong_type_argument (predicate, value)
        {
         if (STRINGP (value) &&
             (EQ (predicate, Qintegerp) || EQ (predicate, Qinteger_or_marker_p)))
-          return Fstring_to_number (value);
+          return Fstring_to_number (value, Qnil);
         if (INTEGERP (value) && EQ (predicate, Qstringp))
           return Fnumber_to_string (value);
        }
@@ -141,15 +153,6 @@ args_out_of_range_3 (a1, a2, a3)
     Fsignal (Qargs_out_of_range, Fcons (a1, Fcons (a2, Fcons (a3, Qnil))));
 }
 
-Lisp_Object
-make_number (num)
-     int num;
-{
-  register Lisp_Object val;
-  XSETINT (val, num);
-  return val;
-}
-
 /* On some machines, XINT needs a temporary location.
    Here it is, in case it is needed.  */
 
@@ -170,7 +173,7 @@ sign_extend_lisp_int (num)
 /* Data type predicates */
 
 DEFUN ("eq", Feq, Seq, 2, 2, 0,
-  "T if the two args are the same Lisp object.")
+  "Return t if the two args are the same Lisp object.")
   (obj1, obj2)
      Lisp_Object obj1, obj2;
 {
@@ -179,7 +182,7 @@ DEFUN ("eq", Feq, Seq, 2, 2, 0,
   return Qnil;
 }
 
-DEFUN ("null", Fnull, Snull, 1, 1, 0, "T if OBJECT is nil.")
+DEFUN ("null", Fnull, Snull, 1, 1, 0, "Return t if OBJECT is nil.")
   (object)
      Lisp_Object object;
 {
@@ -234,11 +237,12 @@ for example, (type-of 1) returns `integer'.")
        return Qcompiled_function;
       if (GC_BUFFERP (object))
        return Qbuffer;
-
-#ifdef MULTI_FRAME
+      if (GC_CHAR_TABLE_P (object))
+       return Qchar_table;
+      if (GC_BOOL_VECTOR_P (object))
+       return Qbool_vector;
       if (GC_FRAMEP (object))
        return Qframe;
-#endif
       return Qvector;
 
 #ifdef LISP_FLOAT_TYPE
@@ -251,7 +255,7 @@ for example, (type-of 1) returns `integer'.")
     }
 }
 
-DEFUN ("consp", Fconsp, Sconsp, 1, 1, 0, "T if OBJECT is a cons cell.")
+DEFUN ("consp", Fconsp, Sconsp, 1, 1, 0, "Return t if OBJECT is a cons cell.")
   (object)
      Lisp_Object object;
 {
@@ -260,7 +264,8 @@ DEFUN ("consp", Fconsp, Sconsp, 1, 1, 0, "T if OBJECT is a cons cell.")
   return Qnil;
 }
 
-DEFUN ("atom", Fatom, Satom, 1, 1, 0, "T if OBJECT is not a cons cell.  This includes nil.")
+DEFUN ("atom", Fatom, Satom, 1, 1, 0,
+       "Return t if OBJECT is not a cons cell.  This includes nil.")
   (object)
      Lisp_Object object;
 {
@@ -269,7 +274,8 @@ DEFUN ("atom", Fatom, Satom, 1, 1, 0, "T if OBJECT is not a cons cell.  This inc
   return Qt;
 }
 
-DEFUN ("listp", Flistp, Slistp, 1, 1, 0, "T if OBJECT is a list.  This includes nil.")
+DEFUN ("listp", Flistp, Slistp, 1, 1, 0,
+       "Return t if OBJECT is a list.  This includes nil.")
   (object)
      Lisp_Object object;
 {
@@ -278,7 +284,8 @@ DEFUN ("listp", Flistp, Slistp, 1, 1, 0, "T if OBJECT is a list.  This includes
   return Qnil;
 }
 
-DEFUN ("nlistp", Fnlistp, Snlistp, 1, 1, 0, "T if OBJECT is not a list.  Lists include nil.")
+DEFUN ("nlistp", Fnlistp, Snlistp, 1, 1, 0,
+       "Return t if OBJECT is not a list.  Lists include nil.")
   (object)
      Lisp_Object object;
 {
@@ -287,7 +294,8 @@ DEFUN ("nlistp", Fnlistp, Snlistp, 1, 1, 0, "T if OBJECT is not a list.  Lists i
   return Qt;
 }
 \f
-DEFUN ("symbolp", Fsymbolp, Ssymbolp, 1, 1, 0, "T if OBJECT is a symbol.")
+DEFUN ("symbolp", Fsymbolp, Ssymbolp, 1, 1, 0,
+       "Return t if OBJECT is a symbol.")
   (object)
      Lisp_Object object;
 {
@@ -296,7 +304,8 @@ DEFUN ("symbolp", Fsymbolp, Ssymbolp, 1, 1, 0, "T if OBJECT is a symbol.")
   return Qnil;
 }
 
-DEFUN ("vectorp", Fvectorp, Svectorp, 1, 1, 0, "T if OBJECT is a vector.")
+DEFUN ("vectorp", Fvectorp, Svectorp, 1, 1, 0,
+       "Return t if OBJECT is a vector.")
   (object)
      Lisp_Object object;
 {
@@ -305,7 +314,8 @@ DEFUN ("vectorp", Fvectorp, Svectorp, 1, 1, 0, "T if OBJECT is a vector.")
   return Qnil;
 }
 
-DEFUN ("stringp", Fstringp, Sstringp, 1, 1, 0, "T if OBJECT is a string.")
+DEFUN ("stringp", Fstringp, Sstringp, 1, 1, 0,
+       "Return t if OBJECT is a string.")
   (object)
      Lisp_Object object;
 {
@@ -314,26 +324,68 @@ DEFUN ("stringp", Fstringp, Sstringp, 1, 1, 0, "T if OBJECT is a string.")
   return Qnil;
 }
 
-DEFUN ("arrayp", Farrayp, Sarrayp, 1, 1, 0, "T if OBJECT is an array (string or vector).")
+DEFUN ("multibyte-string-p", Fmultibyte_string_p, Smultibyte_string_p,
+       1, 1, 0, "Return t if OBJECT is a multibyte string.")
+  (object)
+     Lisp_Object object;
+{
+  if (STRINGP (object) && STRING_MULTIBYTE (object))
+    return Qt;
+  return Qnil;
+}
+
+DEFUN ("char-table-p", Fchar_table_p, Schar_table_p, 1, 1, 0,
+       "Return t if OBJECT is a char-table.")
   (object)
      Lisp_Object object;
 {
-  if (VECTORP (object) || STRINGP (object))
+  if (CHAR_TABLE_P (object))
+    return Qt;
+  return Qnil;
+}
+
+DEFUN ("vector-or-char-table-p", Fvector_or_char_table_p,
+       Svector_or_char_table_p, 1, 1, 0,
+       "Return t if OBJECT is a char-table or vector.")
+  (object)
+     Lisp_Object object;
+{
+  if (VECTORP (object) || CHAR_TABLE_P (object))
+    return Qt;
+  return Qnil;
+}
+
+DEFUN ("bool-vector-p", Fbool_vector_p, Sbool_vector_p, 1, 1, 0, "Return t if OBJECT is a bool-vector.")
+  (object)
+     Lisp_Object object;
+{
+  if (BOOL_VECTOR_P (object))
+    return Qt;
+  return Qnil;
+}
+
+DEFUN ("arrayp", Farrayp, Sarrayp, 1, 1, 0, "Return t if OBJECT is an array (string or vector).")
+  (object)
+     Lisp_Object object;
+{
+  if (VECTORP (object) || STRINGP (object)
+      || CHAR_TABLE_P (object) || BOOL_VECTOR_P (object))
     return Qt;
   return Qnil;
 }
 
 DEFUN ("sequencep", Fsequencep, Ssequencep, 1, 1, 0,
-  "T if OBJECT is a sequence (list or array).")
+  "Return t if OBJECT is a sequence (list or array).")
   (object)
      register Lisp_Object object;
 {
-  if (CONSP (object) || NILP (object) || VECTORP (object) || STRINGP (object))
+  if (CONSP (object) || NILP (object) || VECTORP (object) || STRINGP (object)
+      || CHAR_TABLE_P (object) || BOOL_VECTOR_P (object))
     return Qt;
   return Qnil;
 }
 
-DEFUN ("bufferp", Fbufferp, Sbufferp, 1, 1, 0, "T if OBJECT is an editor buffer.")
+DEFUN ("bufferp", Fbufferp, Sbufferp, 1, 1, 0, "Return t if OBJECT is an editor buffer.")
   (object)
      Lisp_Object object;
 {
@@ -342,7 +394,7 @@ DEFUN ("bufferp", Fbufferp, Sbufferp, 1, 1, 0, "T if OBJECT is an editor buffer.
   return Qnil;
 }
 
-DEFUN ("markerp", Fmarkerp, Smarkerp, 1, 1, 0, "T if OBJECT is a marker (editor pointer).")
+DEFUN ("markerp", Fmarkerp, Smarkerp, 1, 1, 0, "Return t if OBJECT is a marker (editor pointer).")
   (object)
      Lisp_Object object;
 {
@@ -351,7 +403,7 @@ DEFUN ("markerp", Fmarkerp, Smarkerp, 1, 1, 0, "T if OBJECT is a marker (editor
   return Qnil;
 }
 
-DEFUN ("subrp", Fsubrp, Ssubrp, 1, 1, 0, "T if OBJECT is a built-in function.")
+DEFUN ("subrp", Fsubrp, Ssubrp, 1, 1, 0, "Return t if OBJECT is a built-in function.")
   (object)
      Lisp_Object object;
 {
@@ -361,7 +413,7 @@ DEFUN ("subrp", Fsubrp, Ssubrp, 1, 1, 0, "T if OBJECT is a built-in function.")
 }
 
 DEFUN ("byte-code-function-p", Fbyte_code_function_p, Sbyte_code_function_p,
-       1, 1, 0, "T if OBJECT is a byte-compiled function object.")
+       1, 1, 0, "Return t if OBJECT is a byte-compiled function object.")
   (object)
      Lisp_Object object;
 {
@@ -371,7 +423,7 @@ DEFUN ("byte-code-function-p", Fbyte_code_function_p, Sbyte_code_function_p,
 }
 
 DEFUN ("char-or-string-p", Fchar_or_string_p, Schar_or_string_p, 1, 1, 0,
-  "T if OBJECT is a character (an integer) or a string.")
+  "Return t if OBJECT is a character (an integer) or a string.")
   (object)
      register Lisp_Object object;
 {
@@ -380,7 +432,7 @@ DEFUN ("char-or-string-p", Fchar_or_string_p, Schar_or_string_p, 1, 1, 0,
   return Qnil;
 }
 \f
-DEFUN ("integerp", Fintegerp, Sintegerp, 1, 1, 0, "T if OBJECT is an integer.")
+DEFUN ("integerp", Fintegerp, Sintegerp, 1, 1, 0, "Return t if OBJECT is an integer.")
   (object)
      Lisp_Object object;
 {
@@ -390,7 +442,7 @@ DEFUN ("integerp", Fintegerp, Sintegerp, 1, 1, 0, "T if OBJECT is an integer.")
 }
 
 DEFUN ("integer-or-marker-p", Finteger_or_marker_p, Sinteger_or_marker_p, 1, 1, 0,
-  "T if OBJECT is an integer or a marker (editor pointer).")
+  "Return t if OBJECT is an integer or a marker (editor pointer).")
   (object)
      register Lisp_Object object;
 {
@@ -400,7 +452,7 @@ DEFUN ("integer-or-marker-p", Finteger_or_marker_p, Sinteger_or_marker_p, 1, 1,
 }
 
 DEFUN ("natnump", Fnatnump, Snatnump, 1, 1, 0,
-  "T if OBJECT is a nonnegative integer.")
+  "Return t if OBJECT is a nonnegative integer.")
   (object)
      Lisp_Object object;
 {
@@ -410,7 +462,7 @@ DEFUN ("natnump", Fnatnump, Snatnump, 1, 1, 0,
 }
 
 DEFUN ("numberp", Fnumberp, Snumberp, 1, 1, 0,
-       "T if OBJECT is a number (floating point or integer).")
+       "Return t if OBJECT is a number (floating point or integer).")
   (object)
      Lisp_Object object;
 {
@@ -422,7 +474,7 @@ DEFUN ("numberp", Fnumberp, Snumberp, 1, 1, 0,
 
 DEFUN ("number-or-marker-p", Fnumber_or_marker_p,
        Snumber_or_marker_p, 1, 1, 0,
-       "T if OBJECT is a number or a marker.")
+       "Return t if OBJECT is a number or a marker.")
   (object)
      Lisp_Object object;
 {
@@ -433,7 +485,7 @@ DEFUN ("number-or-marker-p", Fnumber_or_marker_p,
 
 #ifdef LISP_FLOAT_TYPE
 DEFUN ("floatp", Ffloatp, Sfloatp, 1, 1, 0,
-       "T if OBJECT is a floating point number.")
+       "Return t if OBJECT is a floating point number.")
   (object)
      Lisp_Object object;
 {
@@ -530,50 +582,50 @@ DEFUN ("setcdr", Fsetcdr, Ssetcdr, 2, 2, 0,
 \f
 /* Extract and set components of symbols */
 
-DEFUN ("boundp", Fboundp, Sboundp, 1, 1, 0, "T if SYMBOL's value is not void.")
-  (sym)
-     register Lisp_Object sym;
+DEFUN ("boundp", Fboundp, Sboundp, 1, 1, 0, "Return t if SYMBOL's value is not void.")
+  (symbol)
+     register Lisp_Object symbol;
 {
   Lisp_Object valcontents;
-  CHECK_SYMBOL (sym, 0);
+  CHECK_SYMBOL (symbol, 0);
 
-  valcontents = XSYMBOL (sym)->value;
+  valcontents = XSYMBOL (symbol)->value;
 
   if (BUFFER_LOCAL_VALUEP (valcontents)
       || SOME_BUFFER_LOCAL_VALUEP (valcontents))
-    valcontents = swap_in_symval_forwarding (sym, valcontents);
+    valcontents = swap_in_symval_forwarding (symbol, valcontents);
 
   return (EQ (valcontents, Qunbound) ? Qnil : Qt);
 }
 
-DEFUN ("fboundp", Ffboundp, Sfboundp, 1, 1, 0, "T if SYMBOL's function definition is not void.")
-  (sym)
-     register Lisp_Object sym;
+DEFUN ("fboundp", Ffboundp, Sfboundp, 1, 1, 0, "Return t if SYMBOL's function definition is not void.")
+  (symbol)
+     register Lisp_Object symbol;
 {
-  CHECK_SYMBOL (sym, 0);
-  return (EQ (XSYMBOL (sym)->function, Qunbound) ? Qnil : Qt);
+  CHECK_SYMBOL (symbol, 0);
+  return (EQ (XSYMBOL (symbol)->function, Qunbound) ? Qnil : Qt);
 }
 
 DEFUN ("makunbound", Fmakunbound, Smakunbound, 1, 1, 0, "Make SYMBOL's value be void.")
-  (sym)
-     register Lisp_Object sym;
+  (symbol)
+     register Lisp_Object symbol;
 {
-  CHECK_SYMBOL (sym, 0);
-  if (NILP (sym) || EQ (sym, Qt))
-    return Fsignal (Qsetting_constant, Fcons (sym, Qnil));
-  Fset (sym, Qunbound);
-  return sym;
+  CHECK_SYMBOL (symbol, 0);
+  if (NILP (symbol) || EQ (symbol, Qt))
+    return Fsignal (Qsetting_constant, Fcons (symbol, Qnil));
+  Fset (symbol, Qunbound);
+  return symbol;
 }
 
 DEFUN ("fmakunbound", Ffmakunbound, Sfmakunbound, 1, 1, 0, "Make SYMBOL's function definition be void.")
-  (sym)
-     register Lisp_Object sym;
+  (symbol)
+     register Lisp_Object symbol;
 {
-  CHECK_SYMBOL (sym, 0);
-  if (NILP (sym) || EQ (sym, Qt))
-    return Fsignal (Qsetting_constant, Fcons (sym, Qnil));
-  XSYMBOL (sym)->function = Qunbound;
-  return sym;
+  CHECK_SYMBOL (symbol, 0);
+  if (NILP (symbol) || EQ (symbol, Qt))
+    return Fsignal (Qsetting_constant, Fcons (symbol, Qnil));
+  XSYMBOL (symbol)->function = Qunbound;
+  return symbol;
 }
 
 DEFUN ("symbol-function", Fsymbol_function, Ssymbol_function, 1, 1, 0,
@@ -588,96 +640,73 @@ DEFUN ("symbol-function", Fsymbol_function, Ssymbol_function, 1, 1, 0,
 }
 
 DEFUN ("symbol-plist", Fsymbol_plist, Ssymbol_plist, 1, 1, 0, "Return SYMBOL's property list.")
-  (sym)
-     register Lisp_Object sym;
+  (symbol)
+     register Lisp_Object symbol;
 {
-  CHECK_SYMBOL (sym, 0);
-  return XSYMBOL (sym)->plist;
+  CHECK_SYMBOL (symbol, 0);
+  return XSYMBOL (symbol)->plist;
 }
 
 DEFUN ("symbol-name", Fsymbol_name, Ssymbol_name, 1, 1, 0, "Return SYMBOL's name, a string.")
-  (sym)
-     register Lisp_Object sym;
+  (symbol)
+     register Lisp_Object symbol;
 {
   register Lisp_Object name;
 
-  CHECK_SYMBOL (sym, 0);
-  XSETSTRING (name, XSYMBOL (sym)->name);
+  CHECK_SYMBOL (symbol, 0);
+  XSETSTRING (name, XSYMBOL (symbol)->name);
   return name;
 }
 
 DEFUN ("fset", Ffset, Sfset, 2, 2, 0,
-  "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.")
-  (sym, newdef)
-     register Lisp_Object sym, newdef;
-{
-  CHECK_SYMBOL (sym, 0);
-  if (NILP (sym) || EQ (sym, Qt))
-    return Fsignal (Qsetting_constant, Fcons (sym, Qnil));
-  if (!NILP (Vautoload_queue) && !EQ (XSYMBOL (sym)->function, Qunbound))
-    Vautoload_queue = Fcons (Fcons (sym, XSYMBOL (sym)->function),
-                            Vautoload_queue);
-  XSYMBOL (sym)->function = newdef;
-  /* Handle automatic advice activation */
-  if (CONSP (XSYMBOL (sym)->plist) && !NILP (Fget (sym, Qad_advice_info)))
-    {
-      call2 (Qad_activate, sym, Qnil);
-      newdef = XSYMBOL (sym)->function;
-    }
-  return newdef;
-}
-
-/* This name should be removed once it is eliminated from elsewhere.  */
-
-DEFUN ("defalias", Fdefalias, Sdefalias, 2, 2, 0,
-  "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.\n\
-Associates the function with the current load file, if any.")
-  (sym, newdef)
-     register Lisp_Object sym, newdef;
+  "Set SYMBOL's function definition to DEFINITION, and return DEFINITION.")
+  (symbol, definition)
+     register Lisp_Object symbol, definition;
 {
-  CHECK_SYMBOL (sym, 0);
-  if (!NILP (Vautoload_queue) && !EQ (XSYMBOL (sym)->function, Qunbound))
-    Vautoload_queue = Fcons (Fcons (sym, XSYMBOL (sym)->function),
+  CHECK_SYMBOL (symbol, 0);
+  if (NILP (symbol) || EQ (symbol, Qt))
+    return Fsignal (Qsetting_constant, Fcons (symbol, Qnil));
+  if (!NILP (Vautoload_queue) && !EQ (XSYMBOL (symbol)->function, Qunbound))
+    Vautoload_queue = Fcons (Fcons (symbol, XSYMBOL (symbol)->function),
                             Vautoload_queue);
-  XSYMBOL (sym)->function = newdef;
+  XSYMBOL (symbol)->function = definition;
   /* Handle automatic advice activation */
-  if (CONSP (XSYMBOL (sym)->plist) && !NILP (Fget (sym, Qad_advice_info)))
+  if (CONSP (XSYMBOL (symbol)->plist) && !NILP (Fget (symbol, Qad_advice_info)))
     {
-      call2 (Qad_activate, sym, Qnil);
-      newdef = XSYMBOL (sym)->function;
+      call2 (Qad_activate, symbol, Qnil);
+      definition = XSYMBOL (symbol)->function;
     }
-  LOADHIST_ATTACH (sym);
-  return newdef;
+  return definition;
 }
 
-DEFUN ("define-function", Fdefine_function, Sdefine_function, 2, 2, 0,
-  "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.\n\
+DEFUN ("defalias", Fdefalias, Sdefalias, 2, 2, 0,
+  "Set SYMBOL's function definition to DEFINITION, and return DEFINITION.\n\
 Associates the function with the current load file, if any.")
-  (sym, newdef)
-     register Lisp_Object sym, newdef;
+  (symbol, definition)
+     register Lisp_Object symbol, definition;
 {
-  CHECK_SYMBOL (sym, 0);
-  if (!NILP (Vautoload_queue) && !EQ (XSYMBOL (sym)->function, Qunbound))
-    Vautoload_queue = Fcons (Fcons (sym, XSYMBOL (sym)->function),
+  CHECK_SYMBOL (symbol, 0);
+  if (!NILP (Vautoload_queue) && !EQ (XSYMBOL (symbol)->function, Qunbound))
+    Vautoload_queue = Fcons (Fcons (symbol, XSYMBOL (symbol)->function),
                             Vautoload_queue);
-  XSYMBOL (sym)->function = newdef;
+  XSYMBOL (symbol)->function = definition;
   /* Handle automatic advice activation */
-  if (CONSP (XSYMBOL (sym)->plist) && !NILP (Fget (sym, Qad_advice_info)))
+  if (CONSP (XSYMBOL (symbol)->plist) && !NILP (Fget (symbol, Qad_advice_info)))
     {
-      call2 (Qad_activate, sym, Qnil);
-      newdef = XSYMBOL (sym)->function;
+      call2 (Qad_activate, symbol, Qnil);
+      definition = XSYMBOL (symbol)->function;
     }
-  LOADHIST_ATTACH (sym);
-  return newdef;
+  LOADHIST_ATTACH (symbol);
+  return definition;
 }
 
 DEFUN ("setplist", Fsetplist, Ssetplist, 2, 2, 0,
   "Set SYMBOL's property list to NEWVAL, and return NEWVAL.")
-  (sym, newplist)
-     register Lisp_Object sym, newplist;
+  (symbol, newplist)
+     register Lisp_Object symbol, newplist;
 {
-  CHECK_SYMBOL (sym, 0);
-  XSYMBOL (sym)->plist = newplist;
+  CHECK_SYMBOL (symbol, 0);
+  XSYMBOL (symbol)->plist = newplist;
   return newplist;
 }
 
@@ -719,14 +748,14 @@ do_symval_forwarding (valcontents)
   return valcontents;
 }
 
-/* Store NEWVAL into SYM, where VALCONTENTS is found in the value cell
-   of SYM.  If SYM is buffer-local, VALCONTENTS should be the
+/* Store NEWVAL into SYMBOL, where VALCONTENTS is found in the value cell
+   of SYMBOL.  If SYMBOL is buffer-local, VALCONTENTS should be the
    buffer-independent contents of the value cell: forwarded just one
    step past the buffer-localness.  */
 
 void
-store_symval_forwarding (sym, valcontents, newval)
-     Lisp_Object sym;
+store_symval_forwarding (symbol, valcontents, newval)
+     Lisp_Object symbol;
      register Lisp_Object valcontents, newval;
 {
   switch (SWITCH_ENUM_CAST (XTYPE (valcontents)))
@@ -739,7 +768,7 @@ store_symval_forwarding (sym, valcontents, newval)
          *XINTFWD (valcontents)->intvar = XINT (newval);
          if (*XINTFWD (valcontents)->intvar != XINT (newval))
            error ("Value out of range for variable `%s'",
-                  XSYMBOL (sym)->name->data);
+                  XSYMBOL (symbol)->name->data);
          break;
 
        case Lisp_Misc_Boolfwd:
@@ -756,6 +785,9 @@ store_symval_forwarding (sym, valcontents, newval)
            Lisp_Object type;
 
            type = *(Lisp_Object *)(offset + (char *)&buffer_local_types);
+           if (XINT (type) == -1)
+             error ("Variable %s is read-only", XSYMBOL (symbol)->name->data);
+
            if (! NILP (type) && ! NILP (newval)
                && XTYPE (newval) != XINT (type))
              buffer_slot_type_mismatch (offset);
@@ -777,22 +809,22 @@ store_symval_forwarding (sym, valcontents, newval)
 
     default:
     def:
-      valcontents = XSYMBOL (sym)->value;
+      valcontents = XSYMBOL (symbol)->value;
       if (BUFFER_LOCAL_VALUEP (valcontents)
          || SOME_BUFFER_LOCAL_VALUEP (valcontents))
-       XBUFFER_LOCAL_VALUE (valcontents)->car = newval;
+       XBUFFER_LOCAL_VALUE (valcontents)->realvalue = newval;
       else
-       XSYMBOL (sym)->value = newval;
+       XSYMBOL (symbol)->value = newval;
     }
 }
 
-/* Set up the buffer-local symbol SYM for validity in the current
+/* Set up the buffer-local symbol SYMBOL for validity in the current
    buffer.  VALCONTENTS is the contents of its value cell.
    Return the value forwarded one step past the buffer-local indicator.  */
 
 static Lisp_Object
-swap_in_symval_forwarding (sym, valcontents)
-     Lisp_Object sym, valcontents;
+swap_in_symval_forwarding (symbol, valcontents)
+     Lisp_Object symbol, valcontents;
 {
   /* valcontents is a pointer to a struct resembling the cons
      (REALVALUE BUFFER CURRENT-ALIST-ELEMENT . DEFAULT-VALUE)).
@@ -812,43 +844,57 @@ swap_in_symval_forwarding (sym, valcontents)
      Note that REALVALUE can be a forwarding pointer. */
 
   register Lisp_Object tem1;
-  tem1 = XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->car;
+  tem1 = XBUFFER_LOCAL_VALUE (valcontents)->buffer;
 
-  if (NILP (tem1) || current_buffer != XBUFFER (tem1))
+  if (NILP (tem1) || current_buffer != XBUFFER (tem1)
+      || selected_frame != XFRAME (XBUFFER_LOCAL_VALUE (valcontents)->frame))
     {
-      tem1 = XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr)->car;
+      tem1 = XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->car;
       Fsetcdr (tem1,
-              do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->car));
-      tem1 = assq_no_quit (sym, current_buffer->local_var_alist);
+              do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->realvalue));
+      tem1 = assq_no_quit (symbol, current_buffer->local_var_alist);
+      XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame = 0;
+      XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 0;
       if (NILP (tem1))
-       tem1 = XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr;
-      XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr)->car = tem1;
-      XSETBUFFER (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->car,
-                 current_buffer);
-      store_symval_forwarding (sym, XBUFFER_LOCAL_VALUE (valcontents)->car,
+       {
+         if (XBUFFER_LOCAL_VALUE (valcontents)->check_frame)
+           tem1 = assq_no_quit (symbol, selected_frame->param_alist);
+         if (! NILP (tem1))
+           XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame = 1;
+         else
+           tem1 = XBUFFER_LOCAL_VALUE (valcontents)->cdr;
+       }
+      else
+       XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 1;
+
+      XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->car = tem1;
+      XSETBUFFER (XBUFFER_LOCAL_VALUE (valcontents)->buffer, current_buffer);
+      XSETFRAME (XBUFFER_LOCAL_VALUE (valcontents)->frame, selected_frame);
+      store_symval_forwarding (symbol,
+                              XBUFFER_LOCAL_VALUE (valcontents)->realvalue,
                               Fcdr (tem1));
     }
-  return XBUFFER_LOCAL_VALUE (valcontents)->car;
+  return XBUFFER_LOCAL_VALUE (valcontents)->realvalue;
 }
 \f
 /* Find the value of a symbol, returning Qunbound if it's not bound.
    This is helpful for code which just wants to get a variable's value
-   if it has one, without signalling an error.
+   if it has one, without signaling an error.
    Note that it must not be possible to quit
    within this function.  Great care is required for this.  */
 
 Lisp_Object
-find_symbol_value (sym)
-     Lisp_Object sym;
+find_symbol_value (symbol)
+     Lisp_Object symbol;
 {
   register Lisp_Object valcontents, tem1;
   register Lisp_Object val;
-  CHECK_SYMBOL (sym, 0);
-  valcontents = XSYMBOL (sym)->value;
+  CHECK_SYMBOL (symbol, 0);
+  valcontents = XSYMBOL (symbol)->value;
 
   if (BUFFER_LOCAL_VALUEP (valcontents)
       || SOME_BUFFER_LOCAL_VALUEP (valcontents))
-    valcontents = swap_in_symval_forwarding (sym, valcontents);
+    valcontents = swap_in_symval_forwarding (symbol, valcontents);
 
   if (MISCP (valcontents))
     {
@@ -879,31 +925,44 @@ find_symbol_value (sym)
 
 DEFUN ("symbol-value", Fsymbol_value, Ssymbol_value, 1, 1, 0,
   "Return SYMBOL's value.  Error if that is void.")
-  (sym)
-     Lisp_Object sym;
+  (symbol)
+     Lisp_Object symbol;
 {
   Lisp_Object val;
 
-  val = find_symbol_value (sym);
+  val = find_symbol_value (symbol);
   if (EQ (val, Qunbound))
-    return Fsignal (Qvoid_variable, Fcons (sym, Qnil));
+    return Fsignal (Qvoid_variable, Fcons (symbol, Qnil));
   else
     return val;
 }
 
 DEFUN ("set", Fset, Sset, 2, 2, 0,
   "Set SYMBOL's value to NEWVAL, and return NEWVAL.")
-  (sym, newval)
-     register Lisp_Object sym, newval;
+  (symbol, newval)
+     register Lisp_Object symbol, newval;
+{
+  return set_internal (symbol, newval, 0);
+}
+
+/* Store the value NEWVAL into SYMBOL.
+   If BINDFLAG is zero, then if this symbol is supposed to become
+   local in every buffer where it is set, then we make it local.
+   If BINDFLAG is nonzero, we don't do that.  */
+
+Lisp_Object
+set_internal (symbol, newval, bindflag)
+     register Lisp_Object symbol, newval;
+     int bindflag;
 {
   int voide = EQ (newval, Qunbound);
 
   register Lisp_Object valcontents, tem1, current_alist_element;
 
-  CHECK_SYMBOL (sym, 0);
-  if (NILP (sym) || EQ (sym, Qt))
-    return Fsignal (Qsetting_constant, Fcons (sym, Qnil));
-  valcontents = XSYMBOL (sym)->value;
+  CHECK_SYMBOL (symbol, 0);
+  if (NILP (symbol) || EQ (symbol, Qt))
+    return Fsignal (Qsetting_constant, Fcons (symbol, Qnil));
+  valcontents = XSYMBOL (symbol)->value;
 
   if (BUFFER_OBJFWDP (valcontents))
     {
@@ -946,15 +1005,16 @@ DEFUN ("set", Fset, Sset, 2, 2, 0,
         it is examined or set, forwarding must be done.  */
 
       /* What value are we caching right now?  */
-      current_alist_element =
-       XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr)->car;
+      current_alist_element
+       = XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->car;
 
       /* If the current buffer is not the buffer whose binding is
         currently cached, or if it's a Lisp_Buffer_Local_Value and
         we're looking at the default value, the cache is invalid; we
         need to write it out, and find the new CURRENT-ALIST-ELEMENT.  */
-      if ((current_buffer
-          != XBUFFER (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->car))
+      if (current_buffer != XBUFFER (XBUFFER_LOCAL_VALUE (valcontents)->buffer)
+         ||
+         selected_frame != XFRAME (XBUFFER_LOCAL_VALUE (valcontents)->frame)
          || (BUFFER_LOCAL_VALUEP (valcontents)
              && EQ (XCONS (current_alist_element)->car,
                     current_alist_element)))
@@ -963,64 +1023,80 @@ DEFUN ("set", Fset, Sset, 2, 2, 0,
             back to its alist element.  This works if the current
             buffer only sees the default value, too.  */
           Fsetcdr (current_alist_element,
-                  do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->car));
+                  do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->realvalue));
 
          /* Find the new value for CURRENT-ALIST-ELEMENT.  */
-         tem1 = Fassq (sym, current_buffer->local_var_alist);
+         tem1 = Fassq (symbol, current_buffer->local_var_alist);
+         XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 1;
+         XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame = 0;
+
          if (NILP (tem1))
            {
              /* This buffer still sees the default value.  */
 
              /* If the variable is a Lisp_Some_Buffer_Local_Value,
+                or if this is `let' rather than `set',
                 make CURRENT-ALIST-ELEMENT point to itself,
                 indicating that we're seeing the default value.  */
-             if (SOME_BUFFER_LOCAL_VALUEP (valcontents))
-               tem1 = XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr;
+             if (bindflag || SOME_BUFFER_LOCAL_VALUEP (valcontents))
+               {
+                 XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 0;
 
-             /* If it's a Lisp_Buffer_Local_Value, give this buffer a
-                new assoc for a local value and set
+                 if (XBUFFER_LOCAL_VALUE (valcontents)->check_frame)
+                   tem1 = Fassq (symbol, selected_frame->param_alist);
+
+                 if (! NILP (tem1))
+                   XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame = 1;
+                 else
+                   tem1 = XBUFFER_LOCAL_VALUE (valcontents)->cdr;
+               }
+             /* If it's a Lisp_Buffer_Local_Value, being set not bound,
+                give this buffer a new assoc for a local value and set
                 CURRENT-ALIST-ELEMENT to point to that.  */
              else
                {
-                 tem1 = Fcons (sym, Fcdr (current_alist_element));
-                 current_buffer->local_var_alist =
-                   Fcons (tem1, current_buffer->local_var_alist);
+                 tem1 = Fcons (symbol, Fcdr (current_alist_element));
+                 current_buffer->local_var_alist
+                   Fcons (tem1, current_buffer->local_var_alist);
                }
            }
+
          /* Cache the new buffer's assoc in CURRENT-ALIST-ELEMENT.  */
-         XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr)->car
+         XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->car
            = tem1;
 
-         /* Set BUFFER, now that CURRENT-ALIST-ELEMENT is accurate.  */
-         XSETBUFFER (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->car,
+         /* Set BUFFER and FRAME for binding now loaded.  */
+         XSETBUFFER (XBUFFER_LOCAL_VALUE (valcontents)->buffer,
                      current_buffer);
+         XSETFRAME (XBUFFER_LOCAL_VALUE (valcontents)->frame,
+                    selected_frame);
        }
-      valcontents = XBUFFER_LOCAL_VALUE (valcontents)->car;
+      valcontents = XBUFFER_LOCAL_VALUE (valcontents)->realvalue;
     }
 
   /* If storing void (making the symbol void), forward only through
      buffer-local indicator, not through Lisp_Objfwd, etc.  */
   if (voide)
-    store_symval_forwarding (sym, Qnil, newval);
+    store_symval_forwarding (symbol, Qnil, newval);
   else
-    store_symval_forwarding (sym, valcontents, newval);
+    store_symval_forwarding (symbol, valcontents, newval);
 
   return newval;
 }
 \f
 /* Access or set a buffer-local symbol's default value.  */
 
-/* Return the default value of SYM, but don't check for voidness.
+/* Return the default value of SYMBOL, but don't check for voidness.
    Return Qunbound if it is void.  */
 
 Lisp_Object
-default_value (sym)
-     Lisp_Object sym;
+default_value (symbol)
+     Lisp_Object symbol;
 {
   register Lisp_Object valcontents;
 
-  CHECK_SYMBOL (sym, 0);
-  valcontents = XSYMBOL (sym)->value;
+  CHECK_SYMBOL (symbol, 0);
+  valcontents = XSYMBOL (symbol)->value;
 
   /* For a built-in buffer-local variable, get the default value
      rather than letting do_symval_forwarding get the current value.  */
@@ -1042,27 +1118,27 @@ default_value (sym)
         ordinary setq stores just that slot.  So use that.  */
       Lisp_Object current_alist_element, alist_element_car;
       current_alist_element
-       = XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr)->car;
+       = XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->car;
       alist_element_car = XCONS (current_alist_element)->car;
       if (EQ (alist_element_car, current_alist_element))
-       return do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->car);
+       return do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->realvalue);
       else
-       return XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr)->cdr;
+       return XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr;
     }
   /* For other variables, get the current value.  */
   return do_symval_forwarding (valcontents);
 }
 
 DEFUN ("default-boundp", Fdefault_boundp, Sdefault_boundp, 1, 1, 0,
-  "Return T if SYMBOL has a non-void default value.\n\
+  "Return t if SYMBOL has a non-void default value.\n\
 This is the value that is seen in buffers that do not have their own values\n\
 for this variable.")
-  (sym)
-     Lisp_Object sym;
+  (symbol)
+     Lisp_Object symbol;
 {
   register Lisp_Object value;
 
-  value = default_value (sym);
+  value = default_value (symbol);
   return (EQ (value, Qunbound) ? Qnil : Qt);
 }
 
@@ -1071,14 +1147,14 @@ DEFUN ("default-value", Fdefault_value, Sdefault_value, 1, 1, 0,
 This is the value that is seen in buffers that do not have their own values\n\
 for this variable.  The default value is meaningful for variables with\n\
 local bindings in certain buffers.")
-  (sym)
-     Lisp_Object sym;
+  (symbol)
+     Lisp_Object symbol;
 {
   register Lisp_Object value;
 
-  value = default_value (sym);
+  value = default_value (symbol);
   if (EQ (value, Qunbound))
-    return Fsignal (Qvoid_variable, Fcons (sym, Qnil));
+    return Fsignal (Qvoid_variable, Fcons (symbol, Qnil));
   return value;
 }
 
@@ -1086,13 +1162,13 @@ DEFUN ("set-default", Fset_default, Sset_default, 2, 2, 0,
   "Set SYMBOL's default value to VAL.  SYMBOL and VAL are evaluated.\n\
 The default value is seen in buffers that do not have their own values\n\
 for this variable.")
-  (sym, value)
-     Lisp_Object sym, value;
+  (symbol, value)
+     Lisp_Object symbol, value;
 {
   register Lisp_Object valcontents, current_alist_element, alist_element_buffer;
 
-  CHECK_SYMBOL (sym, 0);
-  valcontents = XSYMBOL (sym)->value;
+  CHECK_SYMBOL (symbol, 0);
+  valcontents = XSYMBOL (symbol)->value;
 
   /* Handle variables like case-fold-search that have special slots
      in the buffer.  Make them work apparently like Lisp_Buffer_Local_Value
@@ -1104,9 +1180,12 @@ for this variable.")
       register int mask = XINT (*((Lisp_Object *)
                                  (idx + (char *)&buffer_local_flags)));
 
+      *(Lisp_Object *)(idx + (char *) &buffer_defaults) = value;
+
+      /* If this variable is not always local in all buffers,
+        set it in the buffers that don't nominally have a local value.  */
       if (mask > 0)
        {
-         *(Lisp_Object *)(idx + (char *) &buffer_defaults) = value;
          for (b = all_buffers; b; b = b->next)
            if (!(b->local_var_flags & mask))
              *(Lisp_Object *)(idx + (char *) b) = value;
@@ -1116,17 +1195,17 @@ for this variable.")
 
   if (!BUFFER_LOCAL_VALUEP (valcontents)
       && !SOME_BUFFER_LOCAL_VALUEP (valcontents))
-    return Fset (sym, value);
+    return Fset (symbol, value);
 
   /* Store new value into the DEFAULT-VALUE slot */
-  XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr)->cdr = value;
+  XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr = value;
 
   /* If that slot is current, we must set the REALVALUE slot too */
   current_alist_element
-    = XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr)->car;
+    = XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->car;
   alist_element_buffer = Fcar (current_alist_element);
   if (EQ (alist_element_buffer, current_alist_element))
-    store_symval_forwarding (sym, XBUFFER_LOCAL_VALUE (valcontents)->car,
+    store_symval_forwarding (symbol, XBUFFER_LOCAL_VALUE (valcontents)->realvalue,
                             value);
 
   return value;
@@ -1140,15 +1219,15 @@ The default value of a variable is seen in buffers\n\
 that do not have their own values for the variable.\n\
 \n\
 More generally, you can use multiple variables and values, as in\n\
-  (setq-default SYM VALUE SYM VALUE...)\n\
-This sets each SYM's default value to the corresponding VALUE.\n\
-The VALUE for the Nth SYM can refer to the new default values\n\
+  (setq-default SYMBOL VALUE SYMBOL VALUE...)\n\
+This sets each SYMBOL's default value to the corresponding VALUE.\n\
+The VALUE for the Nth SYMBOL can refer to the new default values\n\
 of previous SYMs.")
   (args)
      Lisp_Object args;
 {
   register Lisp_Object args_left;
-  register Lisp_Object val, sym;
+  register Lisp_Object val, symbol;
   struct gcpro gcpro1;
 
   if (NILP (args))
@@ -1160,8 +1239,8 @@ of previous SYMs.")
   do
     {
       val = Feval (Fcar (Fcdr (args_left)));
-      sym = Fcar (args_left);
-      Fset_default (sym, val);
+      symbol = Fcar (args_left);
+      Fset_default (symbol, val);
       args_left = Fcdr (Fcdr (args_left));
     }
   while (!NILP (args_left));
@@ -1181,34 +1260,39 @@ set its own value.\n\
 Using `set' or `setq' to set the variable causes it to have a separate value\n\
 for the current buffer if it was previously using the default value.\n\
 The function `default-value' gets the default value and `set-default' sets it.")
-  (sym)
-     register Lisp_Object sym;
+  (variable)
+     register Lisp_Object variable;
 {
   register Lisp_Object tem, valcontents, newval;
 
-  CHECK_SYMBOL (sym, 0);
+  CHECK_SYMBOL (variable, 0);
 
-  valcontents = XSYMBOL (sym)->value;
-  if (EQ (sym, Qnil) || EQ (sym, Qt) || KBOARD_OBJFWDP (valcontents))
-    error ("Symbol %s may not be buffer-local", XSYMBOL (sym)->name->data);
+  valcontents = XSYMBOL (variable)->value;
+  if (EQ (variable, Qnil) || EQ (variable, Qt) || KBOARD_OBJFWDP (valcontents))
+    error ("Symbol %s may not be buffer-local", XSYMBOL (variable)->name->data);
 
   if (BUFFER_LOCAL_VALUEP (valcontents) || BUFFER_OBJFWDP (valcontents))
-    return sym;
+    return variable;
   if (SOME_BUFFER_LOCAL_VALUEP (valcontents))
     {
-      XMISCTYPE (XSYMBOL (sym)->value) = Lisp_Misc_Buffer_Local_Value;
-      return sym;
+      XMISCTYPE (XSYMBOL (variable)->value) = Lisp_Misc_Buffer_Local_Value;
+      return variable;
     }
   if (EQ (valcontents, Qunbound))
-    XSYMBOL (sym)->value = Qnil;
-  tem = Fcons (Qnil, Fsymbol_value (sym));
+    XSYMBOL (variable)->value = Qnil;
+  tem = Fcons (Qnil, Fsymbol_value (variable));
   XCONS (tem)->car = tem;
   newval = allocate_misc ();
   XMISCTYPE (newval) = Lisp_Misc_Buffer_Local_Value;
-  XBUFFER_LOCAL_VALUE (newval)->car = XSYMBOL (sym)->value;
-  XBUFFER_LOCAL_VALUE (newval)->cdr = Fcons (Fcurrent_buffer (), tem);
-  XSYMBOL (sym)->value = newval;
-  return sym;
+  XBUFFER_LOCAL_VALUE (newval)->realvalue = XSYMBOL (variable)->value;
+  XBUFFER_LOCAL_VALUE (newval)->buffer = Fcurrent_buffer ();
+  XBUFFER_LOCAL_VALUE (newval)->frame = Qnil;
+  XBUFFER_LOCAL_VALUE (newval)->found_for_buffer = 1;
+  XBUFFER_LOCAL_VALUE (newval)->found_for_frame = 0;
+  XBUFFER_LOCAL_VALUE (newval)->check_frame = 0;
+  XBUFFER_LOCAL_VALUE (newval)->cdr = tem;
+  XSYMBOL (variable)->value = newval;
+  return variable;
 }
 
 DEFUN ("make-local-variable", Fmake_local_variable, Smake_local_variable,
@@ -1224,27 +1308,27 @@ just as setting the variable would do.\n\
 \n\
 Do not use `make-local-variable' to make a hook variable buffer-local.\n\
 Use `make-local-hook' instead.")
-  (sym)
-     register Lisp_Object sym;
+  (variable)
+     register Lisp_Object variable;
 {
   register Lisp_Object tem, valcontents;
 
-  CHECK_SYMBOL (sym, 0);
+  CHECK_SYMBOL (variable, 0);
 
-  valcontents = XSYMBOL (sym)->value;
-  if (EQ (sym, Qnil) || EQ (sym, Qt) || KBOARD_OBJFWDP (valcontents))
-    error ("Symbol %s may not be buffer-local", XSYMBOL (sym)->name->data);
+  valcontents = XSYMBOL (variable)->value;
+  if (EQ (variable, Qnil) || EQ (variable, Qt) || KBOARD_OBJFWDP (valcontents))
+    error ("Symbol %s may not be buffer-local", XSYMBOL (variable)->name->data);
 
   if (BUFFER_LOCAL_VALUEP (valcontents) || BUFFER_OBJFWDP (valcontents))
     {
-      tem = Fboundp (sym);
+      tem = Fboundp (variable);
 
       /* Make sure the symbol has a local value in this particular buffer,
         by setting it to the same value it already has.  */
-      Fset (sym, (EQ (tem, Qt) ? Fsymbol_value (sym) : Qunbound));
-      return sym;
+      Fset (variable, (EQ (tem, Qt) ? Fsymbol_value (variable) : Qunbound));
+      return variable;
     }
-  /* Make sure sym is set up to hold per-buffer values */
+  /* Make sure symbol is set up to hold per-buffer values */
   if (!SOME_BUFFER_LOCAL_VALUEP (valcontents))
     {
       Lisp_Object newval;
@@ -1252,26 +1336,39 @@ Use `make-local-hook' instead.")
       XCONS (tem)->car = tem;
       newval = allocate_misc ();
       XMISCTYPE (newval) = Lisp_Misc_Some_Buffer_Local_Value;
-      XBUFFER_LOCAL_VALUE (newval)->car = XSYMBOL (sym)->value;
-      XBUFFER_LOCAL_VALUE (newval)->cdr = Fcons (Qnil, tem);
-      XSYMBOL (sym)->value = newval;
+      XBUFFER_LOCAL_VALUE (newval)->realvalue = XSYMBOL (variable)->value;
+      XBUFFER_LOCAL_VALUE (newval)->buffer = Qnil;
+      XBUFFER_LOCAL_VALUE (newval)->frame = Qnil;
+      XBUFFER_LOCAL_VALUE (newval)->found_for_buffer = 0;
+      XBUFFER_LOCAL_VALUE (newval)->found_for_frame = 0;
+      XBUFFER_LOCAL_VALUE (newval)->check_frame = 0;
+      XBUFFER_LOCAL_VALUE (newval)->cdr = tem;
+      XSYMBOL (variable)->value = newval;
     }
-  /* Make sure this buffer has its own value of sym */
-  tem = Fassq (sym, current_buffer->local_var_alist);
+  /* Make sure this buffer has its own value of symbol */
+  tem = Fassq (variable, current_buffer->local_var_alist);
   if (NILP (tem))
     {
+      /* Swap out any local binding for some other buffer, and make
+        sure the current value is permanently recorded, if it's the
+        default value.  */
+      find_symbol_value (variable);
+
       current_buffer->local_var_alist
-        = Fcons (Fcons (sym, XCONS (XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym)->value)->cdr)->cdr)->cdr),
+        = Fcons (Fcons (variable, XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (variable)->value)->cdr)->cdr),
                 current_buffer->local_var_alist);
 
       /* Make sure symbol does not think it is set up for this buffer;
         force it to look once again for this buffer's value */
       {
        Lisp_Object *pvalbuf;
-       valcontents = XSYMBOL (sym)->value;
-       pvalbuf = &XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->car;
+
+       valcontents = XSYMBOL (variable)->value;
+
+       pvalbuf = &XBUFFER_LOCAL_VALUE (valcontents)->buffer;
        if (current_buffer == XBUFFER (*pvalbuf))
          *pvalbuf = Qnil;
+       XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 0;
       }
     }
 
@@ -1279,25 +1376,25 @@ Use `make-local-hook' instead.")
      variable for this buffer immediately.  If C code modifies the
      variable before we swap in, then that new value will clobber the
      default value the next time we swap.  */
-  valcontents = XBUFFER_LOCAL_VALUE (XSYMBOL (sym)->value)->car;
+  valcontents = XBUFFER_LOCAL_VALUE (XSYMBOL (variable)->value)->realvalue;
   if (INTFWDP (valcontents) || BOOLFWDP (valcontents) || OBJFWDP (valcontents))
-    swap_in_symval_forwarding (sym, XSYMBOL (sym)->value);
+    swap_in_symval_forwarding (variable, XSYMBOL (variable)->value);
 
-  return sym;
+  return variable;
 }
 
 DEFUN ("kill-local-variable", Fkill_local_variable, Skill_local_variable,
   1, 1, "vKill Local Variable: ",
   "Make VARIABLE no longer have a separate value in the current buffer.\n\
 From now on the default value will apply in this buffer.")
-  (sym)
-     register Lisp_Object sym;
+  (variable)
+     register Lisp_Object variable;
 {
   register Lisp_Object tem, valcontents;
 
-  CHECK_SYMBOL (sym, 0);
+  CHECK_SYMBOL (variable, 0);
 
-  valcontents = XSYMBOL (sym)->value;
+  valcontents = XSYMBOL (variable)->value;
 
   if (BUFFER_OBJFWDP (valcontents))
     {
@@ -1311,39 +1408,88 @@ From now on the default value will apply in this buffer.")
            = *(Lisp_Object *)(idx + (char *) &buffer_defaults);
          current_buffer->local_var_flags &= ~mask;
        }
-      return sym;
+      return variable;
     }
 
   if (!BUFFER_LOCAL_VALUEP (valcontents)
       && !SOME_BUFFER_LOCAL_VALUEP (valcontents))
-    return sym;
+    return variable;
 
   /* Get rid of this buffer's alist element, if any */
 
-  tem = Fassq (sym, current_buffer->local_var_alist);
+  tem = Fassq (variable, current_buffer->local_var_alist);
   if (!NILP (tem))
     current_buffer->local_var_alist
       = Fdelq (tem, current_buffer->local_var_alist);
 
-  /* Make sure symbol does not think it is set up for this buffer;
-     force it to look once again for this buffer's value */
+  /* If the symbol is set up for the current buffer, recompute its
+     value.  We have to do it now, or else forwarded objects won't
+     work right. */
   {
     Lisp_Object *pvalbuf;
-    valcontents = XSYMBOL (sym)->value;
-    pvalbuf = &XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->car;
+    valcontents = XSYMBOL (variable)->value;
+    pvalbuf = &XBUFFER_LOCAL_VALUE (valcontents)->buffer;
     if (current_buffer == XBUFFER (*pvalbuf))
-      *pvalbuf = Qnil;
+      {
+       *pvalbuf = Qnil;
+       XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 0;
+       find_symbol_value (variable);
+      }
   }
 
-  return sym;
+  return variable;
+}
+
+/* Lisp functions for creating and removing buffer-local variables.  */
+
+DEFUN ("make-variable-frame-local", Fmake_variable_frame_local, Smake_variable_frame_local,
+  1, 1, "vMake Variable Frame Local: ",
+  "Make VARIABLE have a separate value for each buffer.\n\
+At any time, the value for the current buffer is in effect.\n\
+There is also a default value which is seen in any buffer which has not yet\n\
+set its own value.\n\
+Using `set' or `setq' to set the variable causes it to have a separate value\n\
+for the current buffer if it was previously using the default value.\n\
+The function `default-value' gets the default value and `set-default' sets it.")
+  (variable)
+     register Lisp_Object variable;
+{
+  register Lisp_Object tem, valcontents, newval;
+
+  CHECK_SYMBOL (variable, 0);
+
+  valcontents = XSYMBOL (variable)->value;
+  if (EQ (variable, Qnil) || EQ (variable, Qt) || KBOARD_OBJFWDP (valcontents)
+      || BUFFER_OBJFWDP (valcontents))
+    error ("Symbol %s may not be frame-local", XSYMBOL (variable)->name->data);
+
+  if (BUFFER_LOCAL_VALUEP (valcontents)
+      || SOME_BUFFER_LOCAL_VALUEP (valcontents))
+    return variable;
+
+  if (EQ (valcontents, Qunbound))
+    XSYMBOL (variable)->value = Qnil;
+  tem = Fcons (Qnil, Fsymbol_value (variable));
+  XCONS (tem)->car = tem;
+  newval = allocate_misc ();
+  XMISCTYPE (newval) = Lisp_Misc_Some_Buffer_Local_Value;
+  XBUFFER_LOCAL_VALUE (newval)->realvalue = XSYMBOL (variable)->value;
+  XBUFFER_LOCAL_VALUE (newval)->buffer = Qnil;
+  XBUFFER_LOCAL_VALUE (newval)->frame = Qnil;
+  XBUFFER_LOCAL_VALUE (newval)->found_for_buffer = 0;
+  XBUFFER_LOCAL_VALUE (newval)->found_for_frame = 0;
+  XBUFFER_LOCAL_VALUE (newval)->check_frame = 1;
+  XBUFFER_LOCAL_VALUE (newval)->cdr = tem;
+  XSYMBOL (variable)->value = newval;
+  return variable;
 }
 
 DEFUN ("local-variable-p", Flocal_variable_p, Slocal_variable_p,
   1, 2, 0,
   "Non-nil if VARIABLE has a local binding in buffer BUFFER.\n\
 BUFFER defaults to the current buffer.")
-  (sym, buffer)
-     register Lisp_Object sym, buffer;
+  (variable, buffer)
+     register Lisp_Object variable, buffer;
 {
   Lisp_Object valcontents;
   register struct buffer *buf;
@@ -1356,17 +1502,17 @@ BUFFER defaults to the current buffer.")
       buf = XBUFFER (buffer);
     }
 
-  CHECK_SYMBOL (sym, 0);
+  CHECK_SYMBOL (variable, 0);
 
-  valcontents = XSYMBOL (sym)->value;
+  valcontents = XSYMBOL (variable)->value;
   if (BUFFER_LOCAL_VALUEP (valcontents)
-      && SOME_BUFFER_LOCAL_VALUEP (valcontents))
+      || SOME_BUFFER_LOCAL_VALUEP (valcontents))
     {
       Lisp_Object tail, elt;
       for (tail = buf->local_var_alist; CONSP (tail); tail = XCONS (tail)->cdr)
        {
          elt = XCONS (tail)->car;
-         if (EQ (sym, XCONS (elt)->car))
+         if (EQ (variable, XCONS (elt)->car))
            return Qt;
        }
     }
@@ -1379,6 +1525,47 @@ BUFFER defaults to the current buffer.")
     }
   return Qnil;
 }
+
+DEFUN ("local-variable-if-set-p", Flocal_variable_if_set_p, Slocal_variable_if_set_p,
+  1, 2, 0,
+  "Non-nil if VARIABLE will be local in buffer BUFFER if it is set there.\n\
+BUFFER defaults to the current buffer.")
+  (variable, buffer)
+     register Lisp_Object variable, buffer;
+{
+  Lisp_Object valcontents;
+  register struct buffer *buf;
+
+  if (NILP (buffer))
+    buf = current_buffer;
+  else
+    {
+      CHECK_BUFFER (buffer, 0);
+      buf = XBUFFER (buffer);
+    }
+
+  CHECK_SYMBOL (variable, 0);
+
+  valcontents = XSYMBOL (variable)->value;
+
+  /* This means that make-variable-buffer-local was done.  */
+  if (BUFFER_LOCAL_VALUEP (valcontents))
+    return Qt;
+  /* All these slots become local if they are set.  */
+  if (BUFFER_OBJFWDP (valcontents))
+    return Qt;
+  if (SOME_BUFFER_LOCAL_VALUEP (valcontents))
+    {
+      Lisp_Object tail, elt;
+      for (tail = buf->local_var_alist; CONSP (tail); tail = XCONS (tail)->cdr)
+       {
+         elt = XCONS (tail)->car;
+         if (EQ (variable, XCONS (elt)->car))
+           return Qt;
+       }
+    }
+  return Qnil;
+}
 \f
 /* Find the function at the end of a chain of symbol function indirections.  */
 
@@ -1438,8 +1625,9 @@ function chain of symbols.")
 /* Extract and set vector and string elements */
 
 DEFUN ("aref", Faref, Saref, 2, 2, 0,
-  "Return the element of ARRAY at index INDEX.\n\
-ARRAY may be a vector or a string, or a byte-code object.  INDEX starts at 0.")
+  "Return the element of ARRAY at index IDX.\n\
+ARRAY may be a vector, a string, a char-table, a bool-vector,\n\
+or a byte-code object.  IDX starts at 0.")
   (array, idx)
      register Lisp_Object array;
      Lisp_Object idx;
@@ -1451,10 +1639,101 @@ ARRAY may be a vector or a string, or a byte-code object.  INDEX starts at 0.")
   if (STRINGP (array))
     {
       Lisp_Object val;
+      int c, idxval_byte;
+
       if (idxval < 0 || idxval >= XSTRING (array)->size)
        args_out_of_range (array, idx);
-      XSETFASTINT (val, (unsigned char) XSTRING (array)->data[idxval]);
-      return val;
+      if (! STRING_MULTIBYTE (array))
+       return make_number ((unsigned char) XSTRING (array)->data[idxval]);
+      idxval_byte = string_char_to_byte (array, idxval);
+
+      c = STRING_CHAR (&XSTRING (array)->data[idxval_byte],
+                      STRING_BYTES (XSTRING (array)) - idxval_byte);
+      return make_number (c);
+    }
+  else if (BOOL_VECTOR_P (array))
+    {
+      int val;
+
+      if (idxval < 0 || idxval >= XBOOL_VECTOR (array)->size)
+       args_out_of_range (array, idx);
+
+      val = (unsigned char) XBOOL_VECTOR (array)->data[idxval / BITS_PER_CHAR];
+      return (val & (1 << (idxval % BITS_PER_CHAR)) ? Qt : Qnil);
+    }
+  else if (CHAR_TABLE_P (array))
+    {
+      Lisp_Object val;
+
+      if (idxval < 0)
+       args_out_of_range (array, idx);
+      if (idxval < CHAR_TABLE_ORDINARY_SLOTS)
+       {
+         /* For ASCII and 8-bit European characters, the element is
+             stored in the top table.  */
+         val = XCHAR_TABLE (array)->contents[idxval];
+         if (NILP (val))
+           val = XCHAR_TABLE (array)->defalt;
+         while (NILP (val))    /* Follow parents until we find some value.  */
+           {
+             array = XCHAR_TABLE (array)->parent;
+             if (NILP (array))
+               return Qnil;
+             val = XCHAR_TABLE (array)->contents[idxval];
+             if (NILP (val))
+               val = XCHAR_TABLE (array)->defalt;
+           }
+         return val;
+       }
+      else
+       {
+         int code[4], i;
+         Lisp_Object sub_table;
+
+         SPLIT_NON_ASCII_CHAR (idxval, code[0], code[1], code[2]);
+         if (code[0] != CHARSET_COMPOSITION)
+           {
+             if (code[1] < 32) code[1] = -1;
+             else if (code[2] < 32) code[2] = -1;
+           }
+         /* Here, the possible range of CODE[0] (== charset ID) is
+           128..MAX_CHARSET.  Since the top level char table contains
+           data for multibyte characters after 256th element, we must
+           increment CODE[0] by 128 to get a correct index.  */
+         code[0] += 128;
+         code[3] = -1;         /* anchor */
+
+       try_parent_char_table:
+         sub_table = array;
+         for (i = 0; code[i] >= 0; i++)
+           {
+             val = XCHAR_TABLE (sub_table)->contents[code[i]];
+             if (SUB_CHAR_TABLE_P (val))
+               sub_table = val;
+             else
+               {
+                 if (NILP (val))
+                   val = XCHAR_TABLE (sub_table)->defalt;
+                 if (NILP (val))
+                   {
+                     array = XCHAR_TABLE (array)->parent;
+                     if (!NILP (array))
+                       goto try_parent_char_table;
+                   }
+                 return val;
+               }
+           }
+         /* Here, VAL is a sub char table.  We try the default value
+             and parent.  */
+         val = XCHAR_TABLE (val)->defalt;
+         if (NILP (val))
+           {
+             array = XCHAR_TABLE (array)->parent;
+             if (!NILP (array))
+               goto try_parent_char_table;
+           }
+         return val;
+       }
     }
   else
     {
@@ -1474,7 +1753,8 @@ ARRAY may be a vector or a string, or a byte-code object.  INDEX starts at 0.")
 
 DEFUN ("aset", Faset, Saset, 3, 3, 0,
   "Store into the element of ARRAY at index IDX the value NEWELT.\n\
-ARRAY may be a vector or a string.  IDX starts at 0.")
+ARRAY may be a vector, a string, a char-table or a bool-vector.\n\
+IDX starts at 0.")
   (array, idx, newelt)
      register Lisp_Object array;
      Lisp_Object idx, newelt;
@@ -1483,7 +1763,8 @@ ARRAY may be a vector or a string.  IDX starts at 0.")
 
   CHECK_NUMBER (idx, 1);
   idxval = XINT (idx);
-  if (!VECTORP (array) && !STRINGP (array))
+  if (!VECTORP (array) && !STRINGP (array) && !BOOL_VECTOR_P (array)
+      && ! CHAR_TABLE_P (array))
     array = wrong_type_argument (Qarrayp, array);
   CHECK_IMPURE (array);
 
@@ -1493,6 +1774,88 @@ ARRAY may be a vector or a string.  IDX starts at 0.")
        args_out_of_range (array, idx);
       XVECTOR (array)->contents[idxval] = newelt;
     }
+  else if (BOOL_VECTOR_P (array))
+    {
+      int val;
+
+      if (idxval < 0 || idxval >= XBOOL_VECTOR (array)->size)
+       args_out_of_range (array, idx);
+
+      val = (unsigned char) XBOOL_VECTOR (array)->data[idxval / BITS_PER_CHAR];
+
+      if (! NILP (newelt))
+       val |= 1 << (idxval % BITS_PER_CHAR);
+      else
+       val &= ~(1 << (idxval % BITS_PER_CHAR));
+      XBOOL_VECTOR (array)->data[idxval / BITS_PER_CHAR] = val;
+    }
+  else if (CHAR_TABLE_P (array))
+    {
+      Lisp_Object val;
+
+      if (idxval < 0)
+       args_out_of_range (array, idx);
+      if (idxval < CHAR_TABLE_ORDINARY_SLOTS)
+       XCHAR_TABLE (array)->contents[idxval] = newelt;
+      else
+       {
+         int code[4], i;
+         Lisp_Object val;
+
+         SPLIT_NON_ASCII_CHAR (idxval, code[0], code[1], code[2]);
+         if (code[0] != CHARSET_COMPOSITION)
+           {
+             if (code[1] < 32) code[1] = -1;
+             else if (code[2] < 32) code[2] = -1;
+           }
+         /* See the comment of the corresponding part in Faref.  */
+         code[0] += 128;
+         code[3] = -1;         /* anchor */
+         for (i = 0; code[i + 1] >= 0; i++)
+           {
+             val = XCHAR_TABLE (array)->contents[code[i]];
+             if (SUB_CHAR_TABLE_P (val))
+               array = val;
+             else
+               {
+                 Lisp_Object temp;
+
+                 /* VAL is a leaf.  Create a sub char table with the
+                    default value VAL or XCHAR_TABLE (array)->defalt
+                    and look into it.  */
+
+                 temp = make_sub_char_table (NILP (val)
+                                             ? XCHAR_TABLE (array)->defalt
+                                             : val);
+                 XCHAR_TABLE (array)->contents[code[i]] = temp;
+                 array = temp;
+               }
+           }
+         XCHAR_TABLE (array)->contents[code[i]] = newelt;
+       }
+    }
+  else if (STRING_MULTIBYTE (array))
+    {
+      Lisp_Object new_len;
+      int c, idxval_byte, actual_len;
+      unsigned char *p, *str;
+
+      if (idxval < 0 || idxval >= XSTRING (array)->size)
+       args_out_of_range (array, idx);
+
+      idxval_byte = string_char_to_byte (array, idxval);
+      p = &XSTRING (array)->data[idxval_byte];
+
+      actual_len
+       = MULTIBYTE_FORM_LENGTH (p, STRING_BYTES (XSTRING (array)) - idxval_byte);
+      new_len = Fchar_bytes (newelt);
+      if (actual_len != XINT (new_len))
+       error ("Attempt to change byte length of a string");
+
+      CHAR_STRING (XINT (newelt), p, str);
+      if (p != str)
+       bcopy (str, p, actual_len);
+    }
   else
     {
       if (idxval < 0 || idxval >= XSTRING (array)->size)
@@ -1569,7 +1932,7 @@ arithcompare (num1, num2, comparison)
 }
 
 DEFUN ("=", Feqlsign, Seqlsign, 2, 2, 0,
-  "T if two args, both numbers or markers, are equal.")
+  "Return t if two args, both numbers or markers, are equal.")
   (num1, num2)
      register Lisp_Object num1, num2;
 {
@@ -1577,7 +1940,7 @@ DEFUN ("=", Feqlsign, Seqlsign, 2, 2, 0,
 }
 
 DEFUN ("<", Flss, Slss, 2, 2, 0,
-  "T if first arg is less than second arg.  Both must be numbers or markers.")
+  "Return t if first arg is less than second arg.  Both must be numbers or markers.")
   (num1, num2)
      register Lisp_Object num1, num2;
 {
@@ -1585,7 +1948,7 @@ DEFUN ("<", Flss, Slss, 2, 2, 0,
 }
 
 DEFUN (">", Fgtr, Sgtr, 2, 2, 0,
-  "T if first arg is greater than second arg.  Both must be numbers or markers.")
+  "Return t if first arg is greater than second arg.  Both must be numbers or markers.")
   (num1, num2)
      register Lisp_Object num1, num2;
 {
@@ -1593,7 +1956,7 @@ DEFUN (">", Fgtr, Sgtr, 2, 2, 0,
 }
 
 DEFUN ("<=", Fleq, Sleq, 2, 2, 0,
-  "T if first arg is less than or equal to second arg.\n\
+  "Return t if first arg is less than or equal to second arg.\n\
 Both must be numbers or markers.")
   (num1, num2)
      register Lisp_Object num1, num2;
@@ -1602,7 +1965,7 @@ Both must be numbers or markers.")
 }
 
 DEFUN (">=", Fgeq, Sgeq, 2, 2, 0,
-  "T if first arg is greater than or equal to second arg.\n\
+  "Return t if first arg is greater than or equal to second arg.\n\
 Both must be numbers or markers.")
   (num1, num2)
      register Lisp_Object num1, num2;
@@ -1611,31 +1974,31 @@ Both must be numbers or markers.")
 }
 
 DEFUN ("/=", Fneq, Sneq, 2, 2, 0,
-  "T if first arg is not equal to second arg.  Both must be numbers or markers.")
+  "Return t if first arg is not equal to second arg.  Both must be numbers or markers.")
   (num1, num2)
      register Lisp_Object num1, num2;
 {
   return arithcompare (num1, num2, notequal);
 }
 
-DEFUN ("zerop", Fzerop, Szerop, 1, 1, 0, "T if NUMBER is zero.")
-  (num)
-     register Lisp_Object num;
+DEFUN ("zerop", Fzerop, Szerop, 1, 1, 0, "Return t if NUMBER is zero.")
+  (number)
+     register Lisp_Object number;
 {
 #ifdef LISP_FLOAT_TYPE
-  CHECK_NUMBER_OR_FLOAT (num, 0);
+  CHECK_NUMBER_OR_FLOAT (number, 0);
 
-  if (FLOATP (num))
+  if (FLOATP (number))
     {
-      if (XFLOAT(num)->data == 0.0)
+      if (XFLOAT(number)->data == 0.0)
        return Qt;
       return Qnil;
     }
 #else
-  CHECK_NUMBER (num, 0);
+  CHECK_NUMBER (number, 0);
 #endif /* LISP_FLOAT_TYPE */
 
-  if (!XINT (num))
+  if (!XINT (number))
     return Qt;
   return Qnil;
 }
@@ -1670,74 +2033,122 @@ cons_to_long (c)
 }
 \f
 DEFUN ("number-to-string", Fnumber_to_string, Snumber_to_string, 1, 1, 0,
-  "Convert NUM to a string by printing it in decimal.\n\
+  "Convert NUMBER to a string by printing it in decimal.\n\
 Uses a minus sign if negative.\n\
-NUM may be an integer or a floating point number.")
-  (num)
-     Lisp_Object num;
+NUMBER may be an integer or a floating point number.")
+  (number)
+     Lisp_Object number;
 {
-  char buffer[20];
+  char buffer[VALBITS];
 
 #ifndef LISP_FLOAT_TYPE
-  CHECK_NUMBER (num, 0);
+  CHECK_NUMBER (number, 0);
 #else
-  CHECK_NUMBER_OR_FLOAT (num, 0);
+  CHECK_NUMBER_OR_FLOAT (number, 0);
 
-  if (FLOATP (num))
+  if (FLOATP (number))
     {
       char pigbuf[350];        /* see comments in float_to_string */
 
-      float_to_string (pigbuf, XFLOAT(num)->data);
+      float_to_string (pigbuf, XFLOAT(number)->data);
       return build_string (pigbuf);
     }
 #endif /* LISP_FLOAT_TYPE */
 
   if (sizeof (int) == sizeof (EMACS_INT))
-    sprintf (buffer, "%d", XINT (num));
+    sprintf (buffer, "%d", XINT (number));
   else if (sizeof (long) == sizeof (EMACS_INT))
-    sprintf (buffer, "%ld", XINT (num));
+    sprintf (buffer, "%ld", XINT (number));
   else
     abort ();
   return build_string (buffer);
 }
 
-DEFUN ("string-to-number", Fstring_to_number, Sstring_to_number, 1, 1, 0,
+INLINE static int
+digit_to_number (character, base)
+     int character, base;
+{
+  int digit;
+
+  if (character >= '0' && character <= '9')
+    digit = character - '0';
+  else if (character >= 'a' && character <= 'z')
+    digit = character - 'a' + 10;
+  else if (character >= 'A' && character <= 'Z')
+    digit = character - 'A' + 10;
+  else
+    return -1;
+
+  if (digit >= base)
+    return -1;
+  else
+    return digit;
+}    
+
+DEFUN ("string-to-number", Fstring_to_number, Sstring_to_number, 1, 2, 0,
   "Convert STRING to a number by parsing it as a decimal number.\n\
 This parses both integers and floating point numbers.\n\
-It ignores leading spaces and tabs.")
-  (str)
-     register Lisp_Object str;
+It ignores leading spaces and tabs.\n\
+\n\
+If BASE, interpret STRING as a number in that base.  If BASE isn't\n\
+present, base 10 is used.  BASE must be between 2 and 16 (inclusive).\n\
+Floating point numbers always use base 10.")
+   (string, base)
+     register Lisp_Object string, base;
 {
-  Lisp_Object value;
-  unsigned char *p;
+  register unsigned char *p;
+  register int b, digit, v = 0;
+  int negative = 1;
 
-  CHECK_STRING (str, 0);
+  CHECK_STRING (string, 0);
+
+  if (NILP (base))
+    b = 10;
+  else
+    {
+      CHECK_NUMBER (base, 1);
+      b = XINT (base);
+      if (b < 2 || b > 16)
+       Fsignal (Qargs_out_of_range, Fcons (base, Qnil));
+    }
 
-  p = XSTRING (str)->data;
+  p = XSTRING (string)->data;
 
   /* Skip any whitespace at the front of the number.  Some versions of
      atoi do this anyway, so we might as well make Emacs lisp consistent.  */
   while (*p == ' ' || *p == '\t')
     p++;
 
+  if (*p == '-')
+    {
+      negative = -1;
+      p++;
+    }
+  else if (*p == '+')
+    p++;
+  
 #ifdef LISP_FLOAT_TYPE
   if (isfloat_string (p))
-    return make_float (atof (p));
+    return make_float (negative * atof (p));
 #endif /* LISP_FLOAT_TYPE */
 
-  if (sizeof (int) == sizeof (EMACS_INT))
-    XSETINT (value, atoi (p));
-  else if (sizeof (long) == sizeof (EMACS_INT))
-    XSETINT (value, atol (p));
-  else
-    abort ();
-  return value;
+  while (1)
+    {
+      int digit = digit_to_number (*p++, b);
+      if (digit < 0)
+       break;
+      v = v * b + digit;
+    }
+  
+  return make_number (negative * v);
 }
+
 \f
 enum arithop
   { Aadd, Asub, Amult, Adiv, Alogand, Alogior, Alogxor, Amax, Amin };
 
 extern Lisp_Object float_arith_driver ();
+extern Lisp_Object fmod_float ();
 
 Lisp_Object
 arith_driver (code, nargs, args)
@@ -1807,11 +2218,11 @@ arith_driver (code, nargs, args)
   return val;
 }
 
-#ifdef LISP_FLOAT_TYPE
-
 #undef isnan
 #define isnan(x) ((x) != (x))
 
+#ifdef LISP_FLOAT_TYPE
+
 Lisp_Object
 float_arith_driver (accum, argnum, code, nargs, args)
      double accum;
@@ -1855,7 +2266,7 @@ float_arith_driver (accum, argnum, code, nargs, args)
            accum = next;
          else
            {
-             if (next == 0)
+             if (! IEEE_FLOATING_POINT && next == 0)
                Fsignal (Qarith_error, Qnil);
              accum /= next;
            }
@@ -1919,20 +2330,20 @@ The arguments must be numbers or markers.")
 }
 
 DEFUN ("%", Frem, Srem, 2, 2, 0,
-  "Returns remainder of first arg divided by second.\n\
+  "Returns remainder of X divided by Y.\n\
 Both must be integers or markers.")
-  (num1, num2)
-     register Lisp_Object num1, num2;
+  (x, y)
+     register Lisp_Object x, y;
 {
   Lisp_Object val;
 
-  CHECK_NUMBER_COERCE_MARKER (num1, 0);
-  CHECK_NUMBER_COERCE_MARKER (num2, 1);
+  CHECK_NUMBER_COERCE_MARKER (x, 0);
+  CHECK_NUMBER_COERCE_MARKER (y, 1);
 
-  if (XFASTINT (num2) == 0)
+  if (XFASTINT (y) == 0)
     Fsignal (Qarith_error, Qnil);
 
-  XSETINT (val, XINT (num1) % XINT (num2));
+  XSETINT (val, XINT (x) % XINT (y));
   return val;
 }
 
@@ -1941,11 +2352,21 @@ double
 fmod (f1, f2)
      double f1, f2;
 {
-#ifdef HAVE_DREM  /* Some systems use this non-standard name.  */
-  return (drem (f1, f2));
-#else  /* Other systems don't seem to have it at all.  */
-  return (f1 - f2 * floor (f1/f2));
-#endif
+  double r = f1;
+
+  if (f2 < 0.0)
+    f2 = -f2;
+
+  /* If the magnitude of the result exceeds that of the divisor, or
+     the sign of the result does not agree with that of the dividend,
+     iterate with the reduced value.  This does not yield a
+     particularly accurate result, but at least it will be in the
+     range promised by fmod.  */
+  do
+    r -= f2 * floor (r / f2);
+  while (f2 <= (r < 0 ? -r : r) || ((r < 0) != (f1 < 0) && ! isnan (r)));
+
+  return r;
 }
 #endif /* ! HAVE_FMOD */
 
@@ -1953,38 +2374,26 @@ DEFUN ("mod", Fmod, Smod, 2, 2, 0,
   "Returns X modulo Y.\n\
 The result falls between zero (inclusive) and Y (exclusive).\n\
 Both X and Y must be numbers or markers.")
-  (num1, num2)
-     register Lisp_Object num1, num2;
+  (x, y)
+     register Lisp_Object x, y;
 {
   Lisp_Object val;
   EMACS_INT i1, i2;
 
 #ifdef LISP_FLOAT_TYPE
-  CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1, 0);
-  CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2, 1);
+  CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (x, 0);
+  CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (y, 1);
+
+  if (FLOATP (x) || FLOATP (y))
+    return fmod_float (x, y);
 
-  if (FLOATP (num1) || FLOATP (num2))
-    {
-      double f1, f2;
-
-      f1 = FLOATP (num1) ? XFLOAT (num1)->data : XINT (num1);
-      f2 = FLOATP (num2) ? XFLOAT (num2)->data : XINT (num2);
-      if (f2 == 0)
-       Fsignal (Qarith_error, Qnil);
-
-      f1 = fmod (f1, f2);
-      /* If the "remainder" comes out with the wrong sign, fix it.  */
-      if (f2 < 0 ? f1 > 0 : f1 < 0)
-       f1 += f2;
-      return (make_float (f1));
-    }
 #else /* not LISP_FLOAT_TYPE */
-  CHECK_NUMBER_COERCE_MARKER (num1, 0);
-  CHECK_NUMBER_COERCE_MARKER (num2, 1);
+  CHECK_NUMBER_COERCE_MARKER (x, 0);
+  CHECK_NUMBER_COERCE_MARKER (y, 1);
 #endif /* not LISP_FLOAT_TYPE */
 
-  i1 = XINT (num1);
-  i2 = XINT (num2);
+  i1 = XINT (x);
+  i2 = XINT (y);
 
   if (i2 == 0)
     Fsignal (Qarith_error, Qnil);
@@ -2090,49 +2499,49 @@ In this case,  zeros are shifted in on the left.")
 DEFUN ("1+", Fadd1, Sadd1, 1, 1, 0,
   "Return NUMBER plus one.  NUMBER may be a number or a marker.\n\
 Markers are converted to integers.")
-  (num)
-     register Lisp_Object num;
+  (number)
+     register Lisp_Object number;
 {
 #ifdef LISP_FLOAT_TYPE
-  CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num, 0);
+  CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number, 0);
 
-  if (FLOATP (num))
-    return (make_float (1.0 + XFLOAT (num)->data));
+  if (FLOATP (number))
+    return (make_float (1.0 + XFLOAT (number)->data));
 #else
-  CHECK_NUMBER_COERCE_MARKER (num, 0);
+  CHECK_NUMBER_COERCE_MARKER (number, 0);
 #endif /* LISP_FLOAT_TYPE */
 
-  XSETINT (num, XINT (num) + 1);
-  return num;
+  XSETINT (number, XINT (number) + 1);
+  return number;
 }
 
 DEFUN ("1-", Fsub1, Ssub1, 1, 1, 0,
   "Return NUMBER minus one.  NUMBER may be a number or a marker.\n\
 Markers are converted to integers.")
-  (num)
-     register Lisp_Object num;
+  (number)
+     register Lisp_Object number;
 {
 #ifdef LISP_FLOAT_TYPE
-  CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num, 0);
+  CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number, 0);
 
-  if (FLOATP (num))
-    return (make_float (-1.0 + XFLOAT (num)->data));
+  if (FLOATP (number))
+    return (make_float (-1.0 + XFLOAT (number)->data));
 #else
-  CHECK_NUMBER_COERCE_MARKER (num, 0);
+  CHECK_NUMBER_COERCE_MARKER (number, 0);
 #endif /* LISP_FLOAT_TYPE */
 
-  XSETINT (num, XINT (num) - 1);
-  return num;
+  XSETINT (number, XINT (number) - 1);
+  return number;
 }
 
 DEFUN ("lognot", Flognot, Slognot, 1, 1, 0,
-  "Return the bitwise complement of ARG.  ARG must be an integer.")
-  (num)
-     register Lisp_Object num;
+  "Return the bitwise complement of NUMBER.  NUMBER must be an integer.")
+  (number)
+     register Lisp_Object number;
 {
-  CHECK_NUMBER (num, 0);
-  XSETINT (num, ~XINT (num));
-  return num;
+  CHECK_NUMBER (number, 0);
+  XSETINT (number, ~XINT (number));
+  return number;
 }
 \f
 void
@@ -2191,6 +2600,9 @@ syms_of_data ()
   Qnumber_or_marker_p = intern ("number-or-marker-p");
 #endif /* LISP_FLOAT_TYPE */
 
+  Qchar_table_p = intern ("char-table-p");
+  Qvector_or_char_table_p = intern ("vector-or-char-table-p");
+
   Qcdr = intern ("cdr");
 
   /* Handle automatic advice activation */
@@ -2375,6 +2787,8 @@ syms_of_data ()
   staticpro (&Qnumberp);
   staticpro (&Qnumber_or_marker_p);
 #endif /* LISP_FLOAT_TYPE */
+  staticpro (&Qchar_table_p);
+  staticpro (&Qvector_or_char_table_p);
 
   staticpro (&Qboundp);
   staticpro (&Qfboundp);
@@ -2398,6 +2812,8 @@ syms_of_data ()
   Qbuffer = intern ("buffer");
   Qframe = intern ("frame");
   Qvector = intern ("vector");
+  Qchar_table = intern ("char-table");
+  Qbool_vector = intern ("bool-vector");
 
   staticpro (&Qinteger);
   staticpro (&Qsymbol);
@@ -2414,6 +2830,8 @@ syms_of_data ()
   staticpro (&Qbuffer);
   staticpro (&Qframe);
   staticpro (&Qvector);
+  staticpro (&Qchar_table);
+  staticpro (&Qbool_vector);
 
   defsubr (&Seq);
   defsubr (&Snull);
@@ -2432,7 +2850,11 @@ syms_of_data ()
   defsubr (&Snatnump);
   defsubr (&Ssymbolp);
   defsubr (&Sstringp);
+  defsubr (&Smultibyte_string_p);
   defsubr (&Svectorp);
+  defsubr (&Schar_table_p);
+  defsubr (&Svector_or_char_table_p);
+  defsubr (&Sbool_vector_p);
   defsubr (&Sarrayp);
   defsubr (&Ssequencep);
   defsubr (&Sbufferp);
@@ -2456,7 +2878,6 @@ syms_of_data ()
   defsubr (&Sfboundp);
   defsubr (&Sfset);
   defsubr (&Sdefalias);
-  defsubr (&Sdefine_function);
   defsubr (&Ssetplist);
   defsubr (&Ssymbol_value);
   defsubr (&Sset);
@@ -2467,7 +2888,9 @@ syms_of_data ()
   defsubr (&Smake_variable_buffer_local);
   defsubr (&Smake_local_variable);
   defsubr (&Skill_local_variable);
+  defsubr (&Smake_variable_frame_local);
   defsubr (&Slocal_variable_p);
+  defsubr (&Slocal_variable_if_set_p);
   defsubr (&Saref);
   defsubr (&Saset);
   defsubr (&Snumber_to_string);
@@ -2503,7 +2926,7 @@ SIGTYPE
 arith_error (signo)
      int signo;
 {
-#ifdef USG
+#if defined(USG) && !defined(POSIX_SIGNALS)
   /* USG systems forget handlers when they are used;
      must reestablish each time */
   signal (signo, arith_error);