XEmacs 21.4.15
[chise/xemacs-chise.git.1] / src / buffer.c
index 3be44f8..bd44a47 100644 (file)
@@ -70,6 +70,7 @@ Boston, MA 02111-1307, USA.  */
 
 #include "buffer.h"
 #include "chartab.h"
+#include "casetab.h"
 #include "commands.h"
 #include "elhash.h"
 #include "extents.h"
@@ -84,6 +85,7 @@ Boston, MA 02111-1307, USA.  */
 #ifdef REGION_CACHE_NEEDS_WORK
 #include "region-cache.h"
 #endif
+#include "select.h"     /* for select_notify_buffer_kill */
 #include "specifier.h"
 #include "syntax.h"
 #include "sysdep.h"    /* for getwd */
@@ -195,7 +197,6 @@ Lisp_Object QSscratch;          /* "*scratch*" */
 Lisp_Object Qdefault_directory;
 
 Lisp_Object Qkill_buffer_hook;
-Lisp_Object Qrecord_buffer_hook;
 
 Lisp_Object Qrename_auto_save_file;
 
@@ -207,8 +208,8 @@ Lisp_Object Qfind_file_compare_truenames;
 Lisp_Object Qswitch_to_buffer;
 
 /* Two thresholds controlling how much undo information to keep.  */
-int undo_threshold;
-int undo_high_threshold;
+Fixnum undo_threshold;
+Fixnum undo_high_threshold;
 
 int find_file_compare_truenames;
 int find_file_use_truenames;
@@ -355,7 +356,7 @@ get_buffer (Lisp_Object name, int error_if_deleted_or_does_not_exist)
 struct buffer *
 decode_buffer (Lisp_Object buffer, int allow_string)
 {
-  if (NILP (buffer))
+  if (NILP (buffer) || (!POINTER_TYPE_P( XTYPE(buffer))))
     return current_buffer;
 
   if (allow_string && STRINGP (buffer))
@@ -402,11 +403,10 @@ assoc_ignore_text_properties (REGISTER Lisp_Object key, Lisp_Object list)
 #endif /* FSFmacs */
 
 DEFUN ("get-buffer", Fget_buffer, 1, 1, 0, /*
-Return the buffer named NAME (a string).
-If there is no live buffer named NAME, return nil.
-NAME may also be a buffer; if so, the value is that buffer.
+Return the buffer named BUFFER-NAME (a string), or nil if there is none.
+BUFFER-NAME may also be a buffer; if so, the value is that buffer.
 */
-       (name))
+       (buffer_name))
 {
 #ifdef I18N3
   /* #### Doc string should indicate that the buffer name will get
@@ -415,9 +415,9 @@ NAME may also be a buffer; if so, the value is that buffer.
 
   /* #### This might return a dead buffer.  This is gross.  This is
      called FSF compatibility. */
-  if (BUFFERP (name))
-    return name;
-  return get_buffer (name, 0);
+  if (BUFFERP (buffer_name))
+    return buffer_name;
+  return get_buffer (buffer_name, 0);
   /* FSFmacs 19.29 calls assoc_ignore_text_properties() here.
      Bleagh!! */
 }
@@ -439,7 +439,7 @@ the search will still be done on `buffer-file-name'.
 */
        (filename))
 {
-  /* This function can GC.  GC checked 1997.04.06. */
+  /* This function can GC.  GC checked and fixed 7-11-2000 ben. */
   REGISTER Lisp_Object buf;
   struct gcpro gcpro1;
 
@@ -474,15 +474,17 @@ the search will still be done on `buffer-file-name'.
          dn = Ffile_name_directory (filename);
          fn = Ffile_truename (dn, Qnil);
          if (! NILP (fn)) dn = fn;
-         fn = Fexpand_file_name (Ffile_name_nondirectory (filename),
-                                 dn);
+         /* Formerly the two calls below were combined, but that is
+            not GC-safe because the first call returns unprotected
+            data and the second call can GC. --ben */
+         fn = Ffile_name_nondirectory (filename);
+         fn = Fexpand_file_name (fn, dn);
        }
       filename = fn;
       NUNGCPRO;
     }
 
   {
-    Lisp_Object elt;
     LIST_LOOP_2 (elt, Vbuffer_alist)
       {
        buf = Fcdr (elt);
@@ -534,6 +536,7 @@ delete_from_buffer_alist (Lisp_Object buf)
 Lisp_Object
 get_truename_buffer (REGISTER Lisp_Object filename)
 {
+  /* This function can GC.  GC correct 7-11-00 ben */
   /* FSFmacs has its own code here and doesn't call get-file-buffer.
      That's because their equivalent of find-file-compare-truenames
      (find-file-existing-other-name) isn't looked at in get-file-buffer.
@@ -567,7 +570,7 @@ finish_init_buffer (struct buffer *b, Lisp_Object name)
      local_var_alist is set to Qnil at the same point, in
      nuke_all_buffer_slots(). */
   reset_buffer_local_variables (b, 1);
-  b->directory = ((current_buffer) ? current_buffer->directory : Qnil);
+  b->directory = current_buffer ? current_buffer->directory : Qnil;
 
   b->last_window_start = 1;
 
@@ -630,10 +633,11 @@ The value is never nil.
 
 DEFUN ("make-indirect-buffer", Fmake_indirect_buffer, 2, 2,
        "bMake indirect buffer (to buffer): \nBName of indirect buffer: ", /*
-Create and return an indirect buffer for buffer BASE, named NAME.
-BASE should be an existing buffer (or buffer name).
+Create and return an indirect buffer for buffer BASE-BUFFER, named NAME.
+BASE-BUFFER should be an existing buffer (or buffer name).
 NAME should be a string which is not the name of an existing buffer.
-If BASE is an indirect buffer itself, the base buffer for that buffer
+
+If BASE-BUFFER is itself an indirect buffer, the base buffer for that buffer
  is made the base buffer for the newly created buffer. (Thus, there will
  never be indirect buffers whose base buffers are themselves indirect.)
 */
@@ -694,28 +698,6 @@ reset_buffer_local_variables (struct buffer *b, int first_time)
   }
 #include "bufslots.h"
 #undef MARKED_SLOT
-#if 0
-#define STRING256_P(obj) \
-  (STRINGP (obj) && XSTRING_CHAR_LENGTH (obj) == 256)
-  /* If the standard case table has been altered and invalidated,
-     fix up its insides first.  */
-  if (!(STRING256_P(Vascii_upcase_table) &&
-       STRING256_P(Vascii_canon_table) &&
-       STRING256_P(Vascii_eqv_table)))
-    {
-      Fset_standard_case_table (Vascii_downcase_table);
-    }
-  b->downcase_table = Vascii_downcase_table;
-  b->upcase_table = Vascii_upcase_table;
-  b->case_canon_table = Vascii_canon_table;
-  b->case_eqv_table = Vascii_eqv_table;
-#ifdef MULE
-  b->mirror_downcase_table = Vmirror_ascii_downcase_table;
-  b->mirror_upcase_table = Vmirror_ascii_upcase_table;
-  b->mirror_case_canon_table = Vmirror_ascii_canon_table;
-  b->mirror_case_eqv_table = Vmirror_ascii_eqv_table;
-#endif
-#endif
 }
 
 \f
@@ -869,37 +851,6 @@ No argument or nil as argument means use current buffer as BUFFER.
   return result;
 }
 
-DEFUN ("buffer-dedicated-frame", Fbuffer_dedicated_frame, 0, 1, 0, /*
-Return the frame dedicated to this BUFFER, or nil if there is none.
-No argument or nil as argument means use current buffer as BUFFER.
-*/
-       (buffer))
-{
-  struct buffer *buf = decode_buffer (buffer, 0);
-
-  /* XEmacs addition: if the frame is dead, silently make it go away. */
-  if (!NILP (buf->dedicated_frame) &&
-      !FRAME_LIVE_P (XFRAME (buf->dedicated_frame)))
-    buf->dedicated_frame = Qnil;
-
-  return buf->dedicated_frame;
-}
-
-DEFUN ("set-buffer-dedicated-frame", Fset_buffer_dedicated_frame, 2, 2, 0, /*
-For this BUFFER, set the FRAME dedicated to it.
-FRAME must be a frame or nil.
-*/
-       (buffer, frame))
-{
-  struct buffer *buf = decode_buffer (buffer, 0);
-
-  if (!NILP (frame))
-    CHECK_LIVE_FRAME (frame); /* XEmacs change */
-
-  return buf->dedicated_frame = frame;
-}
-
-
 \f
 DEFUN ("buffer-modified-p", Fbuffer_modified_p, 0, 1, 0, /*
 Return t if BUFFER was modified since its file was last read or saved.
@@ -952,7 +903,7 @@ as BUFFER means use current buffer.
      display).  We still need to make sure redisplay realizes that the
      contents have potentially altered and it needs to do some
      work. */
-  buf = decode_buffer(buffer, 0);
+  buf = decode_buffer (buffer, 0);
   BUF_MODIFF (buf)++;
   BUF_SAVE_MODIFF (buf) = NILP (flag) ? BUF_MODIFF (buf) : 0;
   MARK_MODELINE_CHANGED;
@@ -1027,6 +978,7 @@ This does not change the name of the visited file (if any).
   /* The aconses in the Vbuffer_alist are shared with frame->buffer_alist,
      so this will change it in the per-frame ordering as well. */
   Fsetcar (Frassq (buf, Vbuffer_alist), newname);
+
   if (NILP (current_buffer->filename)
       && !NILP (current_buffer->auto_save_file_name))
     call0 (Qrename_auto_save_file);
@@ -1046,8 +998,8 @@ The ordering is for this frame; If second optional argument FRAME
 is provided, then the ordering is for that frame.  If the second arg
 is t, then the global ordering is returned.
 
-Note: In FSF Emacs, this function takes two arguments: BUFFER and
-VISIBLE-OK.
+Note: In FSF Emacs, this function takes the arguments in the order of
+BUFFER, VISIBLE-OK and FRAME.
 */
        (buffer, frame, visible_ok))
 {
@@ -1105,7 +1057,7 @@ VISIBLE-OK.
 }
 \f
 DEFUN ("buffer-disable-undo", Fbuffer_disable_undo, 0, 1, "", /*
-Make BUFFER stop keeping undo information.
+Stop keeping undo information for BUFFER.
 Any undo records it already has are discarded.
 No argument or nil as argument means do this for the current buffer.
 */
@@ -1118,7 +1070,7 @@ No argument or nil as argument means do this for the current buffer.
 }
 
 DEFUN ("buffer-enable-undo", Fbuffer_enable_undo, 0, 1, "", /*
-Start keeping undo information for buffer BUFFER.
+Start keeping undo information for BUFFER.
 No argument or nil as argument means do this for the current buffer.
 */
        (buffer))
@@ -1220,15 +1172,13 @@ with `delete-process'.
 
       /* Then run the hooks.  */
       run_hook (Qkill_buffer_hook);
-#ifdef HAVE_X_WINDOWS
-      /* If an X selection was in this buffer, disown it.
-        We could have done this by simply adding this function to the
-        kill-buffer-hook, but the user might mess that up.
-        */
-      if (EQ (Vwindow_system, Qx))
-       call0 (intern ("xselect-kill-buffer-hook"));
-      /* #### generalize me! */
-#endif /* HAVE_X_WINDOWS */
+
+      /* Inform the selection code that a buffer just got killed.
+        We do this in C because (a) it's faster, and (b) it needs
+         to access data internal to select.c that can't be seen from
+         Lisp (so the Lisp code would just call into C anyway. */
+      select_notify_buffer_kill (buf);
+
       unbind_to (speccount, Qnil);
       UNGCPRO;
       b = XBUFFER (buf);        /* Hypothetical relocating GC. */
@@ -1304,13 +1254,17 @@ with `delete-process'.
 
     kill_buffer_processes (buf);
 
-    /* #### This is a problem if this buffer is in a dedicated window.
-       Need to undedicate any windows of this buffer first (and delete them?)
-       */
-    Freplace_buffer_in_windows (buf);
-
     delete_from_buffer_alist (buf);
 
+    /* Undedicate any windows of this buffer, and make sure no windows
+       show it.  */
+
+    undedicate_windows (buf, Qt);
+    
+    GCPRO1 (buf);
+    Freplace_buffer_in_windows (buf, Qnil, Qall);
+    UNGCPRO;
+
     font_lock_buffer_was_killed (b);
 
     /* Delete any auto-save file, if we saved it in this session.  */
@@ -1413,8 +1367,6 @@ buffer.  See `other-buffer' for more information.
   XCDR (lynk) = f->buffer_alist;
   f->buffer_alist = lynk;
 
-  va_run_hook_with_args (Qrecord_buffer_hook, 1, buffer);
-
   return Qnil;
 }
 
@@ -1483,20 +1435,6 @@ set_buffer_internal (struct buffer *b)
   current_buffer = b;
   invalidate_current_column ();   /* invalidate indentation cache */
 
-#ifdef HAVE_FEP
-  if (!noninteractive && initialized)
-    {
-      extern Lisp_Object Ffep_force_on (), Ffep_force_off (), Ffep_get_mode ();
-
-      old_buf->fep_mode = Ffep_get_mode ();
-
-      if (!NILP (current_buffer->fep_mode))
-       Ffep_force_on ();
-      else
-       Ffep_force_off ();
-  }
-#endif /* HAVE_FEP */
-
   if (old_buf)
     {
       /* Put the undo list back in the base buffer, so that it appears
@@ -1569,7 +1507,7 @@ Use `switch-to-buffer' or `pop-to-buffer' to switch buffers permanently.
 
 \f
 DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only, 0, 3, 0, /*
-Signal a `buffer-read-only' error if the buffer is read-only.
+Signal a `buffer-read-only' error if BUFFER is read-only.
 Optional argument BUFFER defaults to the current buffer.
 
 If optional argument START is non-nil, all extents in the buffer
@@ -1688,7 +1626,6 @@ BUFFER defaults to the current buffer if omitted.
      implies that the future text is not really related to the past text.  */
   b->saved_size = Qzero;
 
-  zmacs_region_stays = 0;
   return Qnil;
 }
 
@@ -1832,8 +1769,18 @@ coding_system_is_binary (Lisp_Object coding_system)
 #define coding_system_is_binary(coding_system) 1
 #endif
 
-static Extbyte_dynarr *conversion_out_dynarr;
-static Bufbyte_dynarr *conversion_in_dynarr;
+typedef struct
+{
+  Dynarr_declare (Bufbyte_dynarr *);
+} Bufbyte_dynarr_dynarr;
+
+typedef struct
+{
+  Dynarr_declare (Extbyte_dynarr *);
+} Extbyte_dynarr_dynarr;
+
+static Extbyte_dynarr_dynarr *conversion_out_dynarr_list;
+static Bufbyte_dynarr_dynarr *conversion_in_dynarr_list;
 
 static int dfc_convert_to_external_format_in_use;
 static int dfc_convert_to_internal_format_in_use;
@@ -1862,6 +1809,7 @@ dfc_convert_to_external_format (dfc_conversion_type source_type,
                                dfc_conversion_data *sink)
 {
   int count = specpdl_depth ();
+  Extbyte_dynarr *conversion_out_dynarr;
 
   type_checking_assert
     (((source_type == DFC_TYPE_DATA) ||
@@ -1871,20 +1819,20 @@ dfc_convert_to_external_format (dfc_conversion_type source_type,
      ((sink_type == DFC_TYPE_DATA) ||
       (sink_type == DFC_TYPE_LISP_LSTREAM && LSTREAMP (source->lisp_object))));
 
-  if (dfc_convert_to_external_format_in_use != 0)
-    error ("Can't call a conversion function from a conversion function");
-  else
-    dfc_convert_to_external_format_in_use = 1;
-
   record_unwind_protect (dfc_convert_to_external_format_reset_in_use,
-                        Qzero);
+                        make_int (dfc_convert_to_external_format_in_use));
+  if (Dynarr_length (conversion_out_dynarr_list) <=
+      dfc_convert_to_external_format_in_use)
+    Dynarr_add (conversion_out_dynarr_list, Dynarr_new (Extbyte));
+  conversion_out_dynarr = Dynarr_at (conversion_out_dynarr_list,
+                                    dfc_convert_to_external_format_in_use);
+  dfc_convert_to_external_format_in_use++;
+  Dynarr_reset (conversion_out_dynarr);
 
 #ifdef FILE_CODING
   coding_system = Fget_coding_system (coding_system);
 #endif
 
-  Dynarr_reset (conversion_out_dynarr);
-
   /* Here we optimize in the case where the coding system does no
      conversion. However, we don't want to optimize in case the source
      or sink is an lstream, since writing to an lstream can cause a
@@ -1971,7 +1919,7 @@ dfc_convert_to_external_format (dfc_conversion_type source_type,
 
       while (1)
         {
-          ssize_t size_in_bytes;
+          Lstream_data_count size_in_bytes;
          char tempbuf[1024]; /* some random amount */
 
          size_in_bytes = Lstream_read (reader, tempbuf, sizeof (tempbuf));
@@ -2002,7 +1950,7 @@ dfc_convert_to_external_format (dfc_conversion_type source_type,
   if (sink_type != DFC_TYPE_LISP_LSTREAM)
     {
       sink->data.len = Dynarr_length (conversion_out_dynarr);
-      Dynarr_add (conversion_out_dynarr, 0);
+      Dynarr_add (conversion_out_dynarr, '\0');        /* NUL-terminate! */
       sink->data.ptr = Dynarr_atp (conversion_out_dynarr, 0);
     }
 }
@@ -2017,6 +1965,7 @@ dfc_convert_to_internal_format (dfc_conversion_type source_type,
                                dfc_conversion_data *sink)
 {
   int count = specpdl_depth ();
+  Bufbyte_dynarr *conversion_in_dynarr;
 
   type_checking_assert
     ((source_type == DFC_TYPE_DATA ||
@@ -2025,20 +1974,20 @@ dfc_convert_to_internal_format (dfc_conversion_type source_type,
     (sink_type   == DFC_TYPE_DATA ||
      sink_type   == DFC_TYPE_LISP_LSTREAM));
 
-  if (dfc_convert_to_internal_format_in_use != 0)
-    error ("Can't call a conversion function from a conversion function");
-  else
-    dfc_convert_to_internal_format_in_use = 1;
-
   record_unwind_protect (dfc_convert_to_internal_format_reset_in_use,
-                        Qzero);
+                        make_int (dfc_convert_to_internal_format_in_use));
+  if (Dynarr_length (conversion_in_dynarr_list) <=
+      dfc_convert_to_internal_format_in_use)
+    Dynarr_add (conversion_in_dynarr_list, Dynarr_new (Bufbyte));
+  conversion_in_dynarr = Dynarr_at (conversion_in_dynarr_list,
+                                   dfc_convert_to_internal_format_in_use);
+  dfc_convert_to_internal_format_in_use++;
+  Dynarr_reset (conversion_in_dynarr);
 
 #ifdef FILE_CODING
   coding_system = Fget_coding_system (coding_system);
 #endif
 
-  Dynarr_reset (conversion_in_dynarr);
-
   if (source_type != DFC_TYPE_LISP_LSTREAM &&
       sink_type   != DFC_TYPE_LISP_LSTREAM &&
       coding_system_is_binary (coding_system))
@@ -2050,7 +1999,7 @@ dfc_convert_to_internal_format (dfc_conversion_type source_type,
 
       for (; ptr < end; ptr++)
         {
-          Extbyte c = *ptr;
+          Bufbyte c = *ptr;
 
          if (BYTE_ASCII_P (c))
            Dynarr_add (conversion_in_dynarr, c);
@@ -2108,7 +2057,7 @@ dfc_convert_to_internal_format (dfc_conversion_type source_type,
 
       while (1)
         {
-          ssize_t size_in_bytes;
+          Lstream_data_count size_in_bytes;
          char tempbuf[1024]; /* some random amount */
 
          size_in_bytes = Lstream_read (reader, tempbuf, sizeof (tempbuf));
@@ -2139,7 +2088,7 @@ dfc_convert_to_internal_format (dfc_conversion_type source_type,
   if (sink_type != DFC_TYPE_LISP_LSTREAM)
     {
       sink->data.len = Dynarr_length (conversion_in_dynarr);
-      Dynarr_add (conversion_in_dynarr, 0); /* remember to zero-terminate! */
+      Dynarr_add (conversion_in_dynarr, '\0'); /* NUL-terminate! */
       sink->data.ptr = Dynarr_atp (conversion_in_dynarr, 0);
     }
 }
@@ -2148,12 +2097,13 @@ dfc_convert_to_internal_format (dfc_conversion_type source_type,
 void
 syms_of_buffer (void)
 {
+  INIT_LRECORD_IMPLEMENTATION (buffer);
+
   defsymbol (&Qbuffer_live_p, "buffer-live-p");
   defsymbol (&Qbuffer_or_string_p, "buffer-or-string-p");
   defsymbol (&Qmode_class, "mode-class");
   defsymbol (&Qrename_auto_save_file, "rename-auto-save-file");
   defsymbol (&Qkill_buffer_hook, "kill-buffer-hook");
-  defsymbol (&Qrecord_buffer_hook, "record-buffer-hook");
   defsymbol (&Qpermanent_local, "permanent-local");
 
   defsymbol (&Qfirst_change_hook, "first-change-hook");
@@ -2190,8 +2140,6 @@ syms_of_buffer (void)
   DEFSUBR (Fbuffer_base_buffer);
   DEFSUBR (Fbuffer_indirect_children);
   DEFSUBR (Fbuffer_local_variables);
-  DEFSUBR (Fbuffer_dedicated_frame);
-  DEFSUBR (Fset_buffer_dedicated_frame);
   DEFSUBR (Fbuffer_modified_p);
   DEFSUBR (Fset_buffer_modified_p);
   DEFSUBR (Fbuffer_modified_tick);
@@ -2212,15 +2160,17 @@ syms_of_buffer (void)
   DEFSUBR (Fbuffer_memory_usage);
 #endif
 
-  deferror (&Qprotected_field, "protected-field",
-           "Attempt to modify a protected field", Qerror);
+  DEFERROR (Qprotected_field, "Attempt to modify a protected field",
+           Qinvalid_change);
 }
 
 void
 reinit_vars_of_buffer (void)
 {
-  conversion_in_dynarr  = Dynarr_new (Bufbyte);
-  conversion_out_dynarr = Dynarr_new (Extbyte);
+  conversion_in_dynarr_list = Dynarr_new2 (Bufbyte_dynarr_dynarr,
+                                          Bufbyte_dynarr *);
+  conversion_out_dynarr_list = Dynarr_new2 (Extbyte_dynarr_dynarr,
+                                           Extbyte_dynarr *);
 
   staticpro_nodump (&Vbuffer_alist);
   Vbuffer_alist = Qnil;
@@ -2248,18 +2198,22 @@ the read-only state of the buffer.  See also `kill-all-local-variables'.
   Vchange_major_mode_hook = Qnil;
 
   DEFVAR_BOOL ("find-file-compare-truenames", &find_file_compare_truenames /*
-If this is true, then the find-file command will check the truenames
+If this is true, then the `find-file' command will check the truenames
 of all visited files when deciding whether a given file is already in
-a buffer, instead of just the buffer-file-name.  This means that if you
-attempt to visit another file which is a symbolic-link to a file which is
-already in a buffer, the existing buffer will be found instead of a newly-
-created one.  This works if any component of the pathname (including a non-
-terminal component) is a symbolic link as well, but doesn't work with hard
-links (nothing does).
-
-See also the variable find-file-use-truenames.
+a buffer, instead of just `buffer-file-name'.  This means that if you
+attempt to visit another file which is a symbolic link to a file which
+is already in a buffer, the existing buffer will be found instead of a
+newly-created one.  This works if any component of the pathname
+(including a non-terminal component) is a symbolic link as well, but
+doesn't work with hard links (nothing does).
+
+See also the variable `find-file-use-truenames'.
 */ );
+#if defined(CYGWIN) || defined(WIN32_NATIVE)
+  find_file_compare_truenames = 1;
+#else
   find_file_compare_truenames = 0;
+#endif
 
   DEFVAR_BOOL ("find-file-use-truenames", &find_file_use_truenames /*
 If this is true, then a buffer's visited file-name will always be
@@ -2268,7 +2222,7 @@ will never be a symbolic link anywhere in its directory path.
 That is, the buffer-file-name and buffer-file-truename will be equal.
 This doesn't work with hard links.
 
-See also the variable find-file-compare-truenames.
+See also the variable `find-file-compare-truenames'.
 */ );
   find_file_use_truenames = 0;
 
@@ -2373,20 +2327,16 @@ List of functions called with no args to query before killing a buffer.
 
 /* Renamed from DEFVAR_PER_BUFFER because FSFmacs D_P_B takes
    a bogus extra arg, which confuses an otherwise identical make-docfile.c */
-
-/* Declaring this stuff as const produces 'Cannot reinitialize' messages
-   from SunPro C's fix-and-continue feature (a way neato feature that
-   makes debugging unbelievably more bearable) */
 #define DEFVAR_BUFFER_LOCAL_1(lname, field_name, forward_type, magicfun) do {  \
-  static CONST_IF_NOT_DEBUG struct symbol_value_forward I_hate_C =             \
+  static const struct symbol_value_forward I_hate_C =                          \
   { /* struct symbol_value_forward */                                          \
     { /* struct symbol_value_magic */                                          \
       { /* struct lcrecord_header */                                           \
        { /* struct lrecord_header */                                           \
-         1, /* type - index into lrecord_implementations_table */              \
-         0, /* mark bit */                                                     \
-         0, /* c_readonly bit */                                               \
-         0  /* lisp_readonly bit */                                            \
+         lrecord_type_symbol_value_forward, /* lrecord_type_index */           \
+         1, /* mark bit */                                                     \
+         1, /* c_readonly bit */                                               \
+         1  /* lisp_readonly bit */                                            \
        },                                                                      \
        0, /* next */                                                           \
        0, /* uid  */                                                           \
@@ -2463,16 +2413,8 @@ common_init_complex_vars_of_buffer (void)
   defs->mode_name = QSFundamental;
   defs->abbrev_table = Qnil;    /* real default setup by Lisp code */
 
-  defs->downcase_table  = Vascii_downcase_table;
-  defs->upcase_table    = Vascii_upcase_table;
-  defs->case_canon_table = Vascii_canon_table;
-  defs->case_eqv_table  = Vascii_eqv_table;
+  defs->case_table = Vstandard_case_table;
 #ifdef MULE
-  defs->mirror_downcase_table  = Vmirror_ascii_downcase_table;
-  defs->mirror_upcase_table    = Vmirror_ascii_upcase_table;
-  defs->mirror_case_canon_table = Vmirror_ascii_canon_table;
-  defs->mirror_case_eqv_table  = Vmirror_ascii_eqv_table;
-
   defs->category_table = Vstandard_category_table;
 #endif /* MULE */
   defs->syntax_table = Vstandard_syntax_table;
@@ -2490,6 +2432,7 @@ common_init_complex_vars_of_buffer (void)
   defs->auto_save_modified = 0;
   defs->auto_save_failure_time = -1;
   defs->invisibility_spec = Qt;
+  defs->buffer_local_face_property = 0;
 
   defs->indirect_children = Qnil;
   syms->indirect_children = Qnil;
@@ -2535,10 +2478,7 @@ common_init_complex_vars_of_buffer (void)
     buffer_local_flags.generated_modeline_string = always_local_no_default;
 
     buffer_local_flags.keymap          = resettable;
-    buffer_local_flags.downcase_table  = resettable;
-    buffer_local_flags.upcase_table    = resettable;
-    buffer_local_flags.case_canon_table = resettable;
-    buffer_local_flags.case_eqv_table  = resettable;
+    buffer_local_flags.case_table      = resettable;
     buffer_local_flags.syntax_table    = resettable;
 #ifdef MULE
     buffer_local_flags.category_table  = resettable;
@@ -2566,7 +2506,9 @@ common_init_complex_vars_of_buffer (void)
 
     /* #### Warning: 1<<31 is the largest number currently allowable
        due to the XINT() handling of this value.  With some
-       rearrangement you can get 3 more bits. */
+       rearrangement you can get 3 more bits.
+
+       #### 3 more?  34 bits???? -ben */
   }
 }
 
@@ -2612,8 +2554,8 @@ complex_vars_of_buffer (void)
   syms = XBUFFER (Vbuffer_local_symbols);
   buffer_defaults_saved_slots      = &defs->BUFFER_SLOTS_FIRST_NAME;
   buffer_local_symbols_saved_slots = &syms->BUFFER_SLOTS_FIRST_NAME;
-  dumpstruct (&buffer_defaults_saved_slots,      &buffer_slots_description);
-  dumpstruct (&buffer_local_symbols_saved_slots, &buffer_slots_description);
+  dump_add_root_struct_ptr (&buffer_defaults_saved_slots,      &buffer_slots_description);
+  dump_add_root_struct_ptr (&buffer_local_symbols_saved_slots, &buffer_slots_description);
 
   DEFVAR_BUFFER_DEFAULTS ("default-modeline-format", modeline_format /*
 Default value of `modeline-format' for buffers that don't override it.
@@ -2666,31 +2608,31 @@ This is the same as (default-value 'case-fold-search).
   DEFVAR_BUFFER_LOCAL ("modeline-format", modeline_format /*
 Template for displaying modeline for current buffer.
 Each buffer has its own value of this variable.
-Value may be a string, a symbol or a list or cons cell.
-For a symbol, its value is used (but it is ignored if t or nil).
+Value may be a string, symbol, glyph, generic specifier, list or cons cell.
+For a symbol, its value is processed (but it is ignored if t or nil).
  A string appearing directly as the value of a symbol is processed verbatim
  in that the %-constructs below are not recognized.
 For a glyph, it is inserted as is.
+For a generic specifier (i.e. a specifier of type `generic'), its instance
+ is computed in the current window using the equivalent of `specifier-instance'
+ and the value is processed.
 For a list whose car is a symbol, the symbol's value is taken,
  and if that is non-nil, the cadr of the list is processed recursively.
  Otherwise, the caddr of the list (if there is one) is processed.
 For a list whose car is a string or list, each element is processed
  recursively and the results are effectively concatenated.
 For a list whose car is an integer, the cdr of the list is processed
-  and padded (if the number is positive) or truncated (if negative)
-  to the width specified by that number.
+ and padded (if the number is positive) or truncated (if negative)
+ to the width specified by that number.
 For a list whose car is an extent, the cdr of the list is processed
  normally but the results are displayed using the face of the
  extent, and mouse clicks over this section are processed using the
  keymap of the extent. (In addition, if the extent has a help-echo
  property, that string will be echoed when the mouse moves over this
- section.) See `generated-modeline-string' for more information.
-For a list whose car is a face, the cdr of the list is processed
- normally but the results will be displayed using the face in the car.
-For a list whose car is a keymap, the cdr of the list is processed
- normally but the keymap will apply for mouse clicks over the results,
- in addition to `modeline-map'.  Nested keymap specifications are
- handled properly.
+ section.) If extents are nested, all keymaps are properly consulted
+ when processing mouse clicks, but multiple faces are not correctly
+ merged (only the first face is used), and lists of faces are not
+ correctly handled.  See `generated-modeline-string' for more information.
 A string is printed verbatim in the modeline except for %-constructs:
   (%-constructs are processed when the string is the entire modeline-format
    or when it is found in a cons-cell or a list)
@@ -2736,12 +2678,6 @@ Automatically becomes buffer-local when set in any fashion.
   DEFVAR_BUFFER_LOCAL ("case-fold-search", case_fold_search /*
 *Non-nil if searches should ignore case.
 Automatically becomes buffer-local when set in any fashion.
-
-BUG: Under XEmacs/Mule, translations to or from non-ASCII characters
- (this includes chars in the range 128 - 255) are ignored by
- the string/buffer-searching routines.  Thus, `case-fold-search'
- will not correctly conflate a-umlaut and A-umlaut even if the
- case tables call for this.
 */ );
 
   DEFVAR_BUFFER_LOCAL ("fill-column", fill_column /*
@@ -2956,8 +2892,8 @@ and VALUE is the old value.
 List of undo entries in current buffer.
 Recent changes come first; older changes follow newer.
 
-An entry (BEG . END) represents an insertion which begins at
-position BEG and ends at position END.
+An entry (START . END) represents an insertion which begins at
+position START and ends at position END.
 
 An entry (TEXT . POSITION) represents the deletion of the string TEXT
 from (abs POSITION).  If POSITION is positive, point was at the front
@@ -3041,8 +2977,8 @@ The default is t, which means that text is invisible
 if it has (or is covered by an extent with) a non-nil `invisible' property.
 If the value is a list, a text character is invisible if its `invisible'
 property is an element in that list.
-If an element is a cons cell of the form (PROP . ELLIPSIS),
-then characters with property value PROP are invisible,
+If an element is a cons cell of the form (PROPERTY . ELLIPSIS),
+then characters with property value PROPERTY are invisible,
 and they have an ellipsis as well if ELLIPSIS is non-nil.
 Note that the actual characters used for the ellipsis are controllable
 using `invisible-text-glyph', and default to "...".
@@ -3105,6 +3041,7 @@ handled:
   }
 }
 
+#ifndef WIN32_NATIVE
 /* Is PWD another name for `.' ? */
 static int
 directory_is_current_directory (Extbyte *pwd)
@@ -3118,29 +3055,35 @@ directory_is_current_directory (Extbyte *pwd)
                      Qfile_name);
 
   return (IS_DIRECTORY_SEP (*pwd_internal)
-         && stat ((char *) pwd_internal, &pwdstat) == 0
-         && stat (".", &dotstat) == 0
+         && xemacs_stat ((char *) pwd_internal, &pwdstat) == 0
+         && xemacs_stat (".", &dotstat) == 0
          && dotstat.st_ino == pwdstat.st_ino
          && dotstat.st_dev == pwdstat.st_dev
          && pwd_internal_len < MAXPATHLEN);
 }
+#endif
 
 void
 init_initial_directory (void)
 {
   /* This function can GC */
 
+#ifndef WIN32_NATIVE
   Extbyte *pwd;
+#endif
 
   initial_directory[0] = 0;
 
   /* If PWD is accurate, use it instead of calling getcwd.  This is faster
      when PWD is right, and may avoid a fatal error.  */
+#ifndef WIN32_NATIVE
   if ((pwd = (Extbyte *) getenv ("PWD")) != NULL
       && directory_is_current_directory (pwd))
     strcpy (initial_directory, (char *) pwd);
-  else if (getcwd (initial_directory, MAXPATHLEN) == NULL)
-    fatal ("`getcwd' failed: %s\n", strerror (errno));
+  else
+#endif
+    if (getcwd (initial_directory, MAXPATHLEN) == NULL)
+      fatal ("`getcwd' failed: %s\n", strerror (errno));
 
   /* Make sure pwd is DIRECTORY_SEP-terminated.
      Maybe this should really use some standard subroutine
@@ -3155,16 +3098,8 @@ init_initial_directory (void)
       }
   }
 
-  /* XEmacs change: store buffer's default directory
-     using preferred (i.e. as defined at compile-time)
-     directory separator. --marcpa */
-#ifdef DOS_NT
-#define CORRECT_DIR_SEPS(s) \
-  do { if ('/' == DIRECTORY_SEP) dostounix_filename (s); \
-       else unixtodos_filename (s); \
-  } while (0)
-
-  CORRECT_DIR_SEPS(initial_directory);
+#ifdef CORRECT_DIR_SEPS
+  CORRECT_DIR_SEPS (initial_directory);
 #endif
 }