Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-15
[bpt/emacs.git] / src / data.c
index c397bc1..935c434 100644 (file)
@@ -1,5 +1,5 @@
 /* Primitive operations on Lisp data types for GNU Emacs Lisp interpreter.
-   Copyright (C) 1985,86,88,93,94,95,97,98,99, 2000, 2001, 2003
+   Copyright (C) 1985,86,88,93,94,95,97,98,99, 2000, 2001, 03, 2004
    Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -25,7 +25,7 @@ Boston, MA 02111-1307, USA.  */
 #include <stdio.h>
 #include "lisp.h"
 #include "puresize.h"
-#include "charset.h"
+#include "character.h"
 #include "buffer.h"
 #include "keyboard.h"
 #include "frame.h"
@@ -71,6 +71,7 @@ Lisp_Object Qinvalid_function, Qwrong_number_of_arguments, Qno_catch;
 Lisp_Object Qend_of_file, Qarith_error, Qmark_inactive;
 Lisp_Object Qbeginning_of_buffer, Qend_of_buffer, Qbuffer_read_only;
 Lisp_Object Qtext_read_only;
+
 Lisp_Object Qintegerp, Qnatnump, Qwholenump, Qsymbolp, Qlistp, Qconsp;
 Lisp_Object Qstringp, Qarrayp, Qsequencep, Qbufferp;
 Lisp_Object Qchar_or_string_p, Qmarkerp, Qinteger_or_marker_p, Qvectorp;
@@ -87,7 +88,8 @@ Lisp_Object Qoverflow_error, Qunderflow_error;
 Lisp_Object Qfloatp;
 Lisp_Object Qnumberp, Qnumber_or_marker_p;
 
-static Lisp_Object Qinteger, Qsymbol, Qstring, Qcons, Qmarker, Qoverlay;
+Lisp_Object Qinteger;
+static Lisp_Object Qsymbol, Qstring, Qcons, Qmarker, Qoverlay;
 static Lisp_Object Qfloat, Qwindow_configuration, Qwindow;
 Lisp_Object Qprocess;
 static Lisp_Object Qcompiled_function, Qbuffer, Qframe, Qvector;
@@ -447,7 +449,7 @@ DEFUN ("char-or-string-p", Fchar_or_string_p, Schar_or_string_p, 1, 1, 0,
      (object)
      register Lisp_Object object;
 {
-  if (INTEGERP (object) || STRINGP (object))
+  if (CHARACTERP (object) || STRINGP (object))
     return Qt;
   return Qnil;
 }
@@ -759,17 +761,52 @@ function with `&rest' args, or `unevalled' for a special form.  */)
     return Fcons (make_number (minargs), make_number (maxargs));
 }
 
-DEFUN ("subr-interactive-form", Fsubr_interactive_form, Ssubr_interactive_form, 1, 1, 0,
-       doc: /* Return the interactive form of SUBR or nil if none.
-SUBR must be a built-in function.  Value, if non-nil, is a list
-\(interactive SPEC).  */)
+DEFUN ("subr-name", Fsubr_name, Ssubr_name, 1, 1, 0,
+       doc: /* Return name of subroutine SUBR.
+SUBR must be a built-in function.  */)
      (subr)
      Lisp_Object subr;
 {
+  const char *name;
   if (!SUBRP (subr))
     wrong_type_argument (Qsubrp, subr);
-  if (XSUBR (subr)->prompt)
-    return list2 (Qinteractive, build_string (XSUBR (subr)->prompt));
+  name = XSUBR (subr)->symbol_name;
+  return make_string (name, strlen (name));
+}
+
+DEFUN ("interactive-form", Finteractive_form, Sinteractive_form, 1, 1, 0,
+       doc: /* Return the interactive form of CMD or nil if none.
+CMD must be a command.  Value, if non-nil, is a list
+\(interactive SPEC).  */)
+     (cmd)
+     Lisp_Object cmd;
+{
+  Lisp_Object fun = indirect_function (cmd);
+
+  if (SUBRP (fun))
+    {
+      if (XSUBR (fun)->prompt)
+       return list2 (Qinteractive, build_string (XSUBR (fun)->prompt));
+    }
+  else if (COMPILEDP (fun))
+    {
+      if ((ASIZE (fun) & PSEUDOVECTOR_SIZE_MASK) > COMPILED_INTERACTIVE)
+       return list2 (Qinteractive, AREF (fun, COMPILED_INTERACTIVE));
+    }
+  else if (CONSP (fun))
+    {
+      Lisp_Object funcar = XCAR (fun);
+      if (EQ (funcar, Qlambda))
+       return Fassq (Qinteractive, Fcdr (XCDR (fun)));
+      else if (EQ (funcar, Qautoload))
+       {
+         struct gcpro gcpro1;
+         GCPRO1 (cmd);
+         do_autoload (fun, cmd);
+         UNGCPRO;
+         return Finteractive_form (cmd);
+       }
+    }
   return Qnil;
 }
 
@@ -871,6 +908,8 @@ store_symval_forwarding (symbol, valcontents, newval, buf)
      register Lisp_Object valcontents, newval;
      struct buffer *buf;
 {
+  int offset;
+
   switch (SWITCH_ENUM_CAST (XTYPE (valcontents)))
     {
     case Lisp_Misc:
@@ -890,6 +929,36 @@ store_symval_forwarding (symbol, valcontents, newval, buf)
 
        case Lisp_Misc_Objfwd:
          *XOBJFWD (valcontents)->objvar = newval;
+
+         /* If this variable is a default for something stored
+            in the buffer itself, such as default-fill-column,
+            find the buffers that don't have local values for it
+            and update them.  */
+         if (XOBJFWD (valcontents)->objvar > (Lisp_Object *) &buffer_defaults
+             && XOBJFWD (valcontents)->objvar < (Lisp_Object *) (&buffer_defaults + 1))
+           {
+             int offset = ((char *) XOBJFWD (valcontents)->objvar
+                           - (char *) &buffer_defaults);
+             int idx = PER_BUFFER_IDX (offset);
+
+             Lisp_Object tail, buf;
+
+             if (idx <= 0)
+               break;
+
+             for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail))
+               {
+                 Lisp_Object buf;
+                 struct buffer *b;
+
+                 buf = Fcdr (XCAR (tail));
+                 if (!BUFFERP (buf)) continue;
+                 b = XBUFFER (buf);
+
+                 if (! PER_BUFFER_VALUE_P (b, idx))
+                   PER_BUFFER_VALUE (b, offset) = newval;
+               }
+           }
          break;
 
        case Lisp_Misc_Buffer_Objfwd:
@@ -1338,7 +1407,7 @@ local bindings in certain buffers.  */)
 }
 
 DEFUN ("set-default", Fset_default, Sset_default, 2, 2, 0,
-       doc: /* Set SYMBOL's default value to VAL.  SYMBOL and VAL are evaluated.
+       doc: /* Set SYMBOL's default value to VALUE.  SYMBOL and VALUE are evaluated.
 The default value is seen in buffers that do not have their own values
 for this variable.  */)
      (symbol, value)
@@ -1399,11 +1468,11 @@ The default value of a variable is seen in buffers
 that do not have their own values for the variable.
 
 More generally, you can use multiple variables and values, as in
-  (setq-default SYMBOL VALUE SYMBOL VALUE...)
-This sets each SYMBOL's default value to the corresponding VALUE.
-The VALUE for the Nth SYMBOL can refer to the new default values
-of previous SYMs.
-usage: (setq-default SYMBOL VALUE [SYMBOL VALUE...])  */)
+  (setq-default VAR VALUE VAR VALUE...)
+This sets each VAR's default value to the corresponding VALUE.
+The VALUE for the Nth VAR can refer to the new default values
+of previous VARs.
+usage: (setq-default VAR VALUE [VAR VALUE...])  */)
      (args)
      Lisp_Object args;
 {
@@ -1890,82 +1959,13 @@ or a byte-code object.  IDX starts at 0.  */)
       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);
+      val = (unsigned char) XBOOL_VECTOR (array)->data[idxval / BOOL_VECTOR_BITS_PER_CHAR];
+      return (val & (1 << (idxval % BOOL_VECTOR_BITS_PER_CHAR)) ? Qt : Qnil);
     }
   else if (CHAR_TABLE_P (array))
     {
-      Lisp_Object val;
-
-      val = Qnil;
-
-      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_CHAR (idxval, code[0], code[1], code[2]);
-         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;
-       }
+      CHECK_CHARACTER (idx);
+      return CHAR_TABLE_REF (array, idxval);
     }
   else
     {
@@ -2018,54 +2018,18 @@ bool-vector.  IDX starts at 0.  */)
       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];
+      val = (unsigned char) XBOOL_VECTOR (array)->data[idxval / BOOL_VECTOR_BITS_PER_CHAR];
 
       if (! NILP (newelt))
-       val |= 1 << (idxval % BITS_PER_CHAR);
+       val |= 1 << (idxval % BOOL_VECTOR_BITS_PER_CHAR);
       else
-       val &= ~(1 << (idxval % BITS_PER_CHAR));
-      XBOOL_VECTOR (array)->data[idxval / BITS_PER_CHAR] = val;
+       val &= ~(1 << (idxval % BOOL_VECTOR_BITS_PER_CHAR));
+      XBOOL_VECTOR (array)->data[idxval / BOOL_VECTOR_BITS_PER_CHAR] = val;
     }
   else if (CHAR_TABLE_P (array))
     {
-      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_CHAR (idxval, code[0], code[1], code[2]);
-         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;
-       }
+      CHECK_CHARACTER (idx);
+      CHAR_TABLE_SET (array, idxval, newelt);
     }
   else if (STRING_MULTIBYTE (array))
     {
@@ -2074,7 +2038,7 @@ bool-vector.  IDX starts at 0.  */)
 
       if (idxval < 0 || idxval >= SCHARS (array))
        args_out_of_range (array, idx);
-      CHECK_NUMBER (newelt);
+      CHECK_CHARACTER (newelt);
 
       nbytes = SBYTES (array);
 
@@ -2111,7 +2075,8 @@ bool-vector.  IDX starts at 0.  */)
        args_out_of_range (array, idx);
       CHECK_NUMBER (newelt);
 
-      if (XINT (newelt) < 0 || SINGLE_BYTE_CHAR_P (XINT (newelt)))
+      if (XINT (newelt) < 0 || ASCII_CHAR_P (XINT (newelt))
+         || CHAR_BYTE8_P (XINT (newelt)))
        SSET (array, idxval, XINT (newelt));
       else
        {
@@ -2629,6 +2594,10 @@ usage: (/ DIVIDEND DIVISOR &rest DIVISORS)  */)
      int nargs;
      Lisp_Object *args;
 {
+  int argnum;
+  for (argnum = 2; argnum < nargs; argnum++)
+    if (FLOATP (args[argnum]))
+      return float_arith_driver (0, 0, Adiv, nargs, args);
   return arith_driver (Adiv, nargs, args);
 }
 
@@ -2845,6 +2814,20 @@ DEFUN ("lognot", Flognot, Slognot, 1, 1, 0,
   XSETINT (number, ~XINT (number));
   return number;
 }
+
+DEFUN ("byteorder", Fbyteorder, Sbyteorder, 0, 0, 0,
+       doc: /* Return the byteorder for the machine.
+Returns 66 (ASCII uppercase B) for big endian machines or 108 (ASCII
+lowercase l) for small endian machines.  */)
+     ()
+{
+  unsigned i = 0x04030201;
+  int order = *(char *)&i == 1 ? 108 : 66;
+
+  return make_number (order);
+}
+
+
 \f
 void
 syms_of_data ()
@@ -3161,7 +3144,7 @@ syms_of_data ()
   staticpro (&Qhash_table);
 
   defsubr (&Sindirect_variable);
-  defsubr (&Ssubr_interactive_form);
+  defsubr (&Sinteractive_form);
   defsubr (&Seq);
   defsubr (&Snull);
   defsubr (&Stype_of);
@@ -3247,7 +3230,9 @@ syms_of_data ()
   defsubr (&Sadd1);
   defsubr (&Ssub1);
   defsubr (&Slognot);
+  defsubr (&Sbyteorder);
   defsubr (&Ssubr_arity);
+  defsubr (&Ssubr_name);
 
   XSYMBOL (Qwholenump)->function = XSYMBOL (Qnatnump)->function;