(record_char): Record `help-echo' input events
[bpt/emacs.git] / src / editfns.c
index fcc5997..2fe6468 100644 (file)
@@ -1,5 +1,6 @@
 /* Lisp functions pertaining to editing.
-   Copyright (C) 1985,86,87,89,93,94,95,96,97,98, 1999 Free Software Foundation, Inc.
+   Copyright (C) 1985,86,87,89,93,94,95,96,97,98, 1999, 2000
+       Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -48,20 +49,37 @@ Boston, MA 02111-1307, USA.  */
 #define NULL 0
 #endif
 
+#ifndef USE_CRT_DLL
 extern char **environ;
-extern int use_dialog_box;
-extern Lisp_Object make_time ();
-extern void insert_from_buffer ();
-static int tm_diff ();
-static void update_buffer_properties ();
-size_t emacs_strftimeu ();
-void set_time_zone_rule ();
+#endif
+
+extern Lisp_Object make_time P_ ((time_t));
+extern size_t emacs_strftimeu P_ ((char *, size_t, const char *,
+                                  const struct tm *, int));
+static int tm_diff P_ ((struct tm *, struct tm *));
+static void find_field P_ ((Lisp_Object, Lisp_Object, int *, int *));
+static void update_buffer_properties P_ ((int, int));
+static Lisp_Object region_limit P_ ((int));
+static int lisp_time_argument P_ ((Lisp_Object, time_t *, int *));
+static size_t emacs_memftimeu P_ ((char *, size_t, const char *,
+                                  size_t, const struct tm *, int));
+static void general_insert_function P_ ((void (*) (unsigned char *, int),
+                                        void (*) (Lisp_Object, int, int, int,
+                                                  int, int),
+                                        int, int, Lisp_Object *));
+static Lisp_Object subst_char_in_region_unwind P_ ((Lisp_Object));
+static Lisp_Object subst_char_in_region_unwind_1 P_ ((Lisp_Object));
+static void transpose_markers P_ ((int, int, int, int, int, int, int, int));
+
+#ifdef HAVE_INDEX
+extern char *index P_ ((const char *, int));
+#endif
 
 Lisp_Object Vbuffer_access_fontify_functions;
 Lisp_Object Qbuffer_access_fontify_functions;
 Lisp_Object Vbuffer_access_fontified_property;
 
-Lisp_Object Fuser_full_name ();
+Lisp_Object Fuser_full_name P_ ((Lisp_Object));
 
 /* Non-nil means don't stop at field boundary in text motion commands.  */
 
@@ -74,6 +92,15 @@ Lisp_Object Vuser_real_login_name;   /* login name of current user ID */
 Lisp_Object Vuser_full_name;           /* full name of current user */
 Lisp_Object Vuser_login_name;          /* user name from LOGNAME or USER */
 
+/* Symbol for the text property used to mark fields.  */
+
+Lisp_Object Qfield;
+
+/* A special value for Qfield properties.  */
+
+Lisp_Object Qboundary;
+
+
 void
 init_editfns ()
 {
@@ -122,7 +149,7 @@ init_editfns ()
   tem = Fstring_equal (Vuser_login_name, Vuser_real_login_name);
   Vuser_full_name = Fuser_full_name (NILP (tem)? make_number (geteuid())
                                     : Vuser_login_name);
-  
+
   p = (unsigned char *) getenv ("NAME");
   if (p)
     Vuser_full_name = build_string (p);
@@ -237,35 +264,44 @@ except in the case that `enable-multibyte-characters' is nil.")
   return position;
 }
 
+
+/* Return the start or end position of the region.
+   BEGINNINGP non-zero means return the start.
+   If there is no region active, signal an error. */
+
 static Lisp_Object
 region_limit (beginningp)
      int beginningp;
 {
   extern Lisp_Object Vmark_even_if_inactive; /* Defined in callint.c. */
-  register Lisp_Object m;
-  if (!NILP (Vtransient_mark_mode) && NILP (Vmark_even_if_inactive)
+  Lisp_Object m;
+  
+  if (!NILP (Vtransient_mark_mode)
+      && NILP (Vmark_even_if_inactive)
       && NILP (current_buffer->mark_active))
     Fsignal (Qmark_inactive, Qnil);
+  
   m = Fmarker_position (current_buffer->mark);
-  if (NILP (m)) error ("There is no region now");
+  if (NILP (m))
+    error ("There is no region now");
+  
   if ((PT < XFASTINT (m)) == beginningp)
-    return (make_number (PT));
-  else
-    return (m);
+    m = make_number (PT);
+  return m;
 }
 
 DEFUN ("region-beginning", Fregion_beginning, Sregion_beginning, 0, 0, 0,
   "Return position of beginning of region, as an integer.")
   ()
 {
-  return (region_limit (1));
+  return region_limit (1);
 }
 
 DEFUN ("region-end", Fregion_end, Sregion_end, 0, 0, 0,
   "Return position of end of region, as an integer.")
   ()
 {
-  return (region_limit (0));
+  return region_limit (0);
 }
 
 DEFUN ("mark-marker", Fmark_marker, Smark_marker, 0, 0, 0,
@@ -276,19 +312,20 @@ If you set the marker not to point anywhere, the buffer will have no mark.")
 {
   return current_buffer->mark;
 }
+
 \f
 /* Return nonzero if POS1 and POS2 have the same value
    for the text property PROP.  */
 
 static int
-text_property_eq (prop, pos1, pos2)
+char_property_eq (prop, pos1, pos2)
      Lisp_Object prop;
      Lisp_Object pos1, pos2;
 {
   Lisp_Object pval1, pval2;
 
-  pval1 = Fget_text_property (pos1, prop, Qnil);
-  pval2 = Fget_text_property (pos2, prop, Qnil);
+  pval1 = Fget_char_property (pos1, prop, Qnil);
+  pval2 = Fget_char_property (pos2, prop, Qnil);
 
   return EQ (pval1, pval2);
 }
@@ -315,7 +352,7 @@ text_property_stickiness (prop, pos)
 
       if (EQ (rear_non_sticky, Qnil)
          || (CONSP (rear_non_sticky)
-             && !Fmemq (prop, rear_non_sticky)))
+             && NILP (Fmemq (prop, rear_non_sticky))))
        /* PROP is not rear-non-sticky, and since this takes precedence over
           any front-stickiness, PROP is inherited from before.  */
        return -1;
@@ -326,83 +363,148 @@ text_property_stickiness (prop, pos)
 
   if (EQ (front_sticky, Qt)
       || (CONSP (front_sticky)
-         && Fmemq (prop, front_sticky)))
+         && !NILP (Fmemq (prop, front_sticky))))
     /* PROP is inherited from after.  */
     return 1;
 
   /* PROP is not inherited from either side.  */
   return 0;
 }
-\f
-/* Symbol for the text property used to mark fields.  */
-Lisp_Object Qfield;
 
+\f
 /* Find the field surrounding POS in *BEG and *END.  If POS is nil,
-   the value of point is used instead.
+   the value of point is used instead.  If BEG or END null,
+   means don't store the beginning or end of the field.
 
    If MERGE_AT_BOUNDARY is nonzero, then if POS is at the very first
-   position of a field, then the beginning of the previous field
-   is returned instead of the beginning of POS's field (since the end of
-   a field is actually also the beginning of the next input
-   field, this behavior is sometimes useful).
+   position of a field, then the beginning of the previous field is
+   returned instead of the beginning of POS's field (since the end of a
+   field is actually also the beginning of the next input field, this
+   behavior is sometimes useful).  Additionally in the MERGE_AT_BOUNDARY
+   true case, if two fields are separated by a field with the special
+   value `boundary', and POS lies within it, then the two separated
+   fields are considered to be adjacent, and POS between them, when
+   finding the beginning and ending of the "merged" field.
 
    Either BEG or END may be 0, in which case the corresponding value
    is not stored.  */
 
-void
+static void
 find_field (pos, merge_at_boundary, beg, end)
      Lisp_Object pos;
      Lisp_Object merge_at_boundary;
      int *beg, *end;
 {
+  /* Fields right before and after the point.  */
+  Lisp_Object before_field, after_field;
+  /* If the fields came from overlays, the associated overlays.
+     Qnil means they came from text-properties.  */
+  Lisp_Object before_overlay = Qnil, after_overlay = Qnil;
   /* 1 if POS counts as the start of a field.  */
   int at_field_start = 0;
   /* 1 if POS counts as the end of a field.  */
   int at_field_end = 0;
-  
+
   if (NILP (pos))
     XSETFASTINT (pos, PT);
   else
     CHECK_NUMBER_COERCE_MARKER (pos, 0);
 
-  if (NILP (merge_at_boundary) && XFASTINT (pos) > BEGV)
-    /* See if we need to handle the case where POS is at beginning of a
-       field, which can also be interpreted as the end of the previous
-       field.  We decide which one by seeing which field the `field'
-       property sticks to.  The case where if MERGE_AT_BOUNDARY is
-       non-nil (see function comment) is actually the more natural one;
-       then we avoid treating the beginning of a field specially.  */
-    {
-      /* First see if POS is actually *at* a boundary. */
-      Lisp_Object after_field, before_field;
-
-      after_field = Fget_text_property (pos, Qfield, Qnil);
-      before_field = Fget_text_property (make_number (XINT (pos) - 1),
-                                        Qfield, Qnil);
-
-      if (! EQ (after_field, before_field))
-       /* We are at a boundary, see which direction is inclusive.  */
+  after_field
+    = get_char_property_and_overlay (pos, Qfield, Qnil, &after_overlay);
+  before_field
+    = (XFASTINT (pos) > BEGV
+       ? get_char_property_and_overlay (make_number (XINT (pos) - 1),
+                                       Qfield, Qnil,
+                                       &before_overlay)
+       : Qnil);
+
+  /* See if we need to handle the case where MERGE_AT_BOUNDARY is nil
+     and POS is at beginning of a field, which can also be interpreted
+     as the end of the previous field.  Note that the case where if
+     MERGE_AT_BOUNDARY is non-nil (see function comment) is actually the
+     more natural one; then we avoid treating the beginning of a field
+     specially.  */
+  if (NILP (merge_at_boundary) && !EQ (after_field, before_field))
+    /* We are at a boundary, see which direction is inclusive.  We
+       decide by seeing which field the `field' property sticks to.  */
+    {
+      /* -1 means insertions go into before_field, 1 means they go
+        into after_field, 0 means neither.  */
+      int stickiness;
+      /* Whether the before/after_field come from overlays.  */
+      int bop = !NILP (before_overlay);
+      int aop = !NILP (after_overlay);
+
+      if (bop && XMARKER (OVERLAY_END (before_overlay))->insertion_type == 1)
+       /* before_field is from an overlay, which expands upon
+          end-insertions.  Note that it's possible for after_overlay to
+          also eat insertions here, but then they will overlap, and
+          there's not much we can do.  */
+       stickiness = -1;
+      else if (aop
+              && XMARKER (OVERLAY_START (after_overlay))->insertion_type == 0)
+       /* after_field is from an overlay, which expand to contain
+          start-insertions.  */
+       stickiness = 1;
+      else if (bop && aop)
+       /* Both fields come from overlays, but neither will contain any
+          insertion here.  */
+       stickiness = 0;
+      else if (bop)
+       /* before_field is an overlay that won't eat any insertion, but
+          after_field is from a text-property.  Assume that the
+          text-property continues underneath the overlay, and so will
+          be inherited by any insertion, regardless of any stickiness
+          settings.  */
+       stickiness = 1;
+      else if (aop)
+       /* Similarly, when after_field is the overlay.  */
+       stickiness = -1;
+      else
+       /* Both fields come from text-properties.  Look for explicit
+          stickiness properties.  */
+       stickiness = text_property_stickiness (Qfield, pos);
+
+      if (stickiness > 0)
+       at_field_start = 1;
+      else if (stickiness < 0)
+       at_field_end = 1;
+      else
+       /* STICKINESS == 0 means that any inserted text will get a
+          `field' char-property of nil, so check to see if that
+          matches either of the adjacent characters (this being a
+          kind of "stickiness by default").  */
        {
-         int stickiness = text_property_stickiness (Qfield, pos);
-
-         if (stickiness > 0)
-           at_field_start = 1;
-         else if (stickiness < 0)
-           at_field_end = 1;
-         else
-           /* STICKINESS == 0 means that any inserted text will get a
-              `field' text-property of nil, so check to see if that
-              matches either of the adjacent characters (this being a
-              kind of "stickiness by default").  */
-           {
-             if (NILP (before_field))
-               at_field_end = 1; /* Sticks to the left.  */
-             else if (NILP (after_field))
-               at_field_start = 1; /* Sticks to the right.  */
-           }
+         if (NILP (before_field))
+           at_field_end = 1; /* Sticks to the left.  */
+         else if (NILP (after_field))
+           at_field_start = 1; /* Sticks to the right.  */
        }
     }
 
+  /* Note about special `boundary' fields:
+
+     Consider the case where the point (`.') is between the fields `x' and `y':
+
+       xxxx.yyyy
+
+     In this situation, if merge_at_boundary is true, we consider the
+     `x' and `y' fields as forming one big merged field, and so the end
+     of the field is the end of `y'.
+
+     However, if `x' and `y' are separated by a special `boundary' field
+     (a field with a `field' char-property of 'boundary), then we ignore
+     this special field when merging adjacent fields.  Here's the same
+     situation, but with a `boundary' field between the `x' and `y' fields:
+
+       xxx.BBBByyyy
+
+     Here, if point is at the end of `x', the beginning of `y', or
+     anywhere in-between (within the `boundary' field), we merge all
+     three fields and consider the beginning as being the beginning of
+     the `x' field, and the end as being the end of the `y' field.  */
+
   if (beg)
     {
       if (at_field_start)
@@ -412,9 +514,12 @@ find_field (pos, merge_at_boundary, beg, end)
       else
        /* Find the previous field boundary.  */
        {
-         Lisp_Object prev;
-         prev = Fprevious_single_property_change (pos, Qfield, Qnil, Qnil);
-         *beg = NILP (prev) ? BEGV : XFASTINT (prev);
+         if (!NILP (merge_at_boundary) && EQ (before_field, Qboundary))
+           /* Skip a `boundary' field.  */
+           pos = Fprevious_single_char_property_change (pos, Qfield, Qnil,Qnil);
+
+         pos = Fprevious_single_char_property_change (pos, Qfield, Qnil, Qnil);
+         *beg = NILP (pos) ? BEGV : XFASTINT (pos);
        }
     }
 
@@ -427,12 +532,16 @@ find_field (pos, merge_at_boundary, beg, end)
       else
        /* Find the next field boundary.  */
        {
-         Lisp_Object next;
-         next = Fnext_single_property_change (pos, Qfield, Qnil, Qnil);
-         *end = NILP (next) ? ZV : XFASTINT (next);
+         if (!NILP (merge_at_boundary) && EQ (after_field, Qboundary))
+           /* Skip a `boundary' field.  */
+           pos = Fnext_single_char_property_change (pos, Qfield, Qnil, Qnil);
+
+         pos = Fnext_single_char_property_change (pos, Qfield, Qnil, Qnil);
+         *end = NILP (pos) ? ZV : XFASTINT (pos);
        }
     }
 }
+
 \f
 DEFUN ("delete-field", Fdelete_field, Sdelete_field, 0, 1, 0,
   "Delete the field surrounding POS.\n\
@@ -500,8 +609,9 @@ then the end of the *following* field is returned.")
   return make_number (end);
 }
 
-DEFUN ("constrain-to-field", Fconstrain_to_field, Sconstrain_to_field, 2, 4, 0,
+DEFUN ("constrain-to-field", Fconstrain_to_field, Sconstrain_to_field, 2, 5, 0,
   "Return the position closest to NEW-POS that is in the same field as OLD-POS.\n\
+\n\
 A field is a region of text with the same `field' property.\n\
 If NEW-POS is nil, then the current point is used instead, and set to the\n\
 constrained position if that is is different.\n\
@@ -509,10 +619,12 @@ constrained position if that is is different.\n\
 If OLD-POS is at the boundary of two fields, then the allowable\n\
 positions for NEW-POS depends on the value of the optional argument\n\
 ESCAPE-FROM-EDGE: If ESCAPE-FROM-EDGE is nil, then NEW-POS is\n\
-constrained to the field that has the same `field' text-property\n\
+constrained to the field that has the same `field' char-property\n\
 as any new characters inserted at OLD-POS, whereas if ESCAPE-FROM-EDGE\n\
 is non-nil, NEW-POS is constrained to the union of the two adjacent\n\
-fields.\n\
+fields.  Additionally, if two fields are separated by another field with\n\
+the special value `boundary', then any point within this special field is\n\
+also considered to be `on the boundary'.\n\
 \n\
 If the optional argument ONLY-IN-LINE is non-nil and constraining\n\
 NEW-POS would move it to a different line, NEW-POS is returned\n\
@@ -520,9 +632,13 @@ unconstrained.  This useful for commands that move by line, like\n\
 \\[next-line] or \\[beginning-of-line], which should generally respect field boundaries\n\
 only in the case where they can still move to the right line.\n\
 \n\
+If the optional argument INHIBIT-CAPTURE-PROPERTY is non-nil, and OLD-POS has\n\
+a non-nil property of that name, then any field boundaries are ignored.\n\
+\n\
 Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil.")
-  (new_pos, old_pos, escape_from_edge, only_in_line)
-     Lisp_Object new_pos, old_pos, escape_from_edge, only_in_line;
+  (new_pos, old_pos, escape_from_edge, only_in_line, inhibit_capture_property)
+     Lisp_Object new_pos, old_pos;
+     Lisp_Object escape_from_edge, only_in_line, inhibit_capture_property;
 {
   /* If non-zero, then the original point, before re-positioning.  */
   int orig_point = 0;
@@ -536,11 +652,14 @@ Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil.")
 
   if (NILP (Vinhibit_field_text_motion)
       && !EQ (new_pos, old_pos)
-      && !text_property_eq (Qfield, new_pos, old_pos))
+      && (!NILP (Fget_char_property (new_pos, Qfield, Qnil))
+         || !NILP (Fget_char_property (old_pos, Qfield, Qnil)))
+      && (NILP (inhibit_capture_property)
+         || NILP (Fget_char_property(old_pos, inhibit_capture_property, Qnil))))
     /* NEW_POS is not within the same field as OLD_POS; try to
        move NEW_POS so that it is.  */
     {
-      int fwd;
+      int fwd, shortage;
       Lisp_Object field_bound;
 
       CHECK_NUMBER_COERCE_MARKER (new_pos, 0);
@@ -553,20 +672,23 @@ Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil.")
       else
        field_bound = Ffield_beginning (old_pos, escape_from_edge);
 
-      if (/* If ONLY_IN_LINE is non-nil, we only constrain NEW_POS if doing
-            so would remain within the same line.  */
-         NILP (only_in_line)
-         /* In that case, see if ESCAPE_FROM_EDGE caused FIELD_BOUND
-             to jump to the other side of NEW_POS, which would mean
-             that NEW_POS is already acceptable, and that we don't
-             have to do the line-check.  */
-         || ((XFASTINT (field_bound) < XFASTINT (new_pos)) ? !fwd : fwd)
-         /* If not, see if there's no newline intervening between
-             NEW_POS and FIELD_BOUND.  */
-         || (find_before_next_newline (XFASTINT (new_pos),
-                                       XFASTINT (field_bound),
-                                       fwd ? -1 : 1)
-             == XFASTINT (field_bound)))
+      if (/* See if ESCAPE_FROM_EDGE caused FIELD_BOUND to jump to the
+             other side of NEW_POS, which would mean that NEW_POS is
+             already acceptable, and it's not necessary to constrain it
+             to FIELD_BOUND.  */
+         ((XFASTINT (field_bound) < XFASTINT (new_pos)) ? fwd : !fwd)
+         /* NEW_POS should be constrained, but only if either
+            ONLY_IN_LINE is nil (in which case any constraint is OK),
+            or NEW_POS and FIELD_BOUND are on the same line (in which
+            case the constraint is OK even if ONLY_IN_LINE is non-nil). */
+         && (NILP (only_in_line)
+             /* This is the ONLY_IN_LINE case, check that NEW_POS and
+                FIELD_BOUND are on the same line by seeing whether
+                there's an intervening newline or not.  */
+             || (scan_buffer ('\n',
+                              XFASTINT (new_pos), XFASTINT (field_bound),
+                              fwd ? -1 : 1, &shortage, 1),
+                 shortage != 0)))
        /* Constrain NEW_POS to FIELD_BOUND.  */
        new_pos = field_bound;
 
@@ -577,6 +699,7 @@ Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil.")
 
   return new_pos;
 }
+
 \f
 DEFUN ("line-beginning-position", Fline_beginning_position, Sline_beginning_position,
   0, 1, 0,
@@ -592,7 +715,7 @@ This function does not move point.")
   (n)
      Lisp_Object n;
 {
-  register int orig, orig_byte, end;
+  int orig, orig_byte, end;
 
   if (NILP (n))
     XSETFASTINT (n, 1);
@@ -609,7 +732,7 @@ This function does not move point.")
   /* Return END constrained to the current input field.  */
   return Fconstrain_to_field (make_number (end), make_number (orig),
                              XINT (n) != 1 ? Qt : Qnil,
-                             Qt);
+                             Qt, Qnil);
 }
 
 DEFUN ("line-end-position", Fline_end_position, Sline_end_position,
@@ -622,7 +745,7 @@ This function does not move point.")
      Lisp_Object n;
 {
   int end_pos;
-  register int orig = PT;
+  int orig = PT;
 
   if (NILP (n))
     XSETFASTINT (n, 1);
@@ -633,19 +756,20 @@ This function does not move point.")
 
   /* Return END_POS constrained to the current input field.  */
   return Fconstrain_to_field (make_number (end_pos), make_number (orig),
-                             Qnil, Qt);
+                             Qnil, Qt, Qnil);
 }
 \f
 Lisp_Object
 save_excursion_save ()
 {
-  register int visible = (XBUFFER (XWINDOW (selected_window)->buffer)
-                         == current_buffer);
+  int visible = (XBUFFER (XWINDOW (selected_window)->buffer)
+                == current_buffer);
 
   return Fcons (Fpoint_marker (),
                Fcons (Fcopy_marker (current_buffer->mark, Qnil),
                       Fcons (visible ? Qt : Qnil,
-                             current_buffer->mark_active)));                  
+                             Fcons (current_buffer->mark_active,
+                                    selected_window))));
 }
 
 Lisp_Object
@@ -654,8 +778,9 @@ save_excursion_restore (info)
 {
   Lisp_Object tem, tem1, omark, nmark;
   struct gcpro gcpro1, gcpro2, gcpro3;
+  int visible_p;
 
-  tem = Fmarker_buffer (Fcar (info));
+  tem = Fmarker_buffer (XCAR (info));
   /* If buffer being returned to is now deleted, avoid error */
   /* Otherwise could get error here while unwinding to top level
      and crash */
@@ -667,15 +792,24 @@ save_excursion_restore (info)
   GCPRO3 (info, omark, nmark);
 
   Fset_buffer (tem);
-  tem = Fcar (info);
+
+  /* Point marker.  */
+  tem = XCAR (info);
   Fgoto_char (tem);
   unchain_marker (tem);
-  tem = Fcar (Fcdr (info));
+
+  /* Mark marker.  */
+  info = XCDR (info);
+  tem = XCAR (info);
   omark = Fmarker_position (current_buffer->mark);
   Fset_marker (current_buffer->mark, tem, Fcurrent_buffer ());
   nmark = Fmarker_position (tem);
   unchain_marker (tem);
-  tem = Fcdr (Fcdr (info));
+
+  /* visible */
+  info = XCDR (info);
+  visible_p = !NILP (XCAR (info));
+  
 #if 0 /* We used to make the current buffer visible in the selected window
         if that was true previously.  That avoids some anomalies.
         But it creates others, and it wasn't documented, and it is simpler
@@ -686,8 +820,12 @@ save_excursion_restore (info)
     Fswitch_to_buffer (Fcurrent_buffer (), Qnil);
 #endif /* 0 */
 
+  /* Mark active */
+  info = XCDR (info);
+  tem = XCAR (info);
   tem1 = current_buffer->mark_active;
-  current_buffer->mark_active = Fcdr (tem);
+  current_buffer->mark_active = tem;
+
   if (!NILP (Vrun_hooks))
     {
       /* If mark is active now, and either was not active
@@ -701,6 +839,16 @@ save_excursion_restore (info)
       else if (! NILP (tem1))
        call1 (Vrun_hooks, intern ("deactivate-mark-hook"));
     }
+
+  /* If buffer was visible in a window, and a different window was
+     selected, and the old selected window is still live, restore
+     point in that window.  */
+  tem = XCDR (info);
+  if (visible_p
+      && !EQ (tem, selected_window)
+      && !NILP (Fwindow_live_p (tem)))
+    Fset_window_point (tem, make_number (PT));
+
   UNGCPRO;
   return Qnil;
 }
@@ -734,7 +882,7 @@ Executes BODY just like `progn'.")
   (args)
      Lisp_Object args;
 {
-  register Lisp_Object val;
+  Lisp_Object val;
   int count = specpdl_ptr - specpdl;
 
   record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ());
@@ -843,10 +991,7 @@ If BYTEPOS is out of range, the value is nil.")
 \f
 DEFUN ("following-char", Ffollowing_char, Sfollowing_char, 0, 0, 0,
   "Return the character following point, as a number.\n\
-At the end of the buffer or accessible region, return 0.\n\
-If `enable-multibyte-characters' is nil or point is not\n\
- at character boundary,  multibyte form is ignored,\n\
- and only one byte following point is returned as a character.")
+At the end of the buffer or accessible region, return 0.")
   ()
 {
   Lisp_Object temp;
@@ -859,10 +1004,7 @@ If `enable-multibyte-characters' is nil or point is not\n\
 
 DEFUN ("preceding-char", Fprevious_char, Sprevious_char, 0, 0, 0,
   "Return the character preceding point, as a number.\n\
-At the beginning of the buffer or accessible region, return 0.\n\
-If `enable-multibyte-characters' is nil or point is not\n\
- at character boundary, multi-byte form is ignored,\n\
- and only one byte preceding point is returned as a character.")
+At the beginning of the buffer or accessible region, return 0.")
   ()
 {
   Lisp_Object temp;
@@ -944,7 +1086,7 @@ If POS is out of range, the value is nil.")
       CHECK_NUMBER_COERCE_MARKER (pos, 0);
       if (XINT (pos) < BEGV || XINT (pos) >= ZV)
        return Qnil;
-      
+
       pos_byte = CHAR_TO_BYTE (XINT (pos));
     }
 
@@ -1066,26 +1208,25 @@ name, or nil if there is no such user.")
 {
   struct passwd *pw;
   register unsigned char *p, *q;
-  extern char *index ();
   Lisp_Object full;
 
   if (NILP (uid))
-    return Vuser_full_name; 
+    return Vuser_full_name;
   else if (NUMBERP (uid))
     pw = (struct passwd *) getpwuid (XINT (uid));
-  else if (STRINGP (uid)) 
+  else if (STRINGP (uid))
     pw = (struct passwd *) getpwnam (XSTRING (uid)->data);
   else
     error ("Invalid UID specification");
 
   if (!pw)
     return Qnil;
-  
+
   p = (unsigned char *) USER_FULL_NAME;
   /* Chop off everything after the first comma. */
   q = (unsigned char *) index (p, ',');
   full = make_string (p, q ? q - p : strlen (p));
-  
+
 #ifdef AMPERSAND_FULL_NAME
   p = XSTRING (full)->data;
   q = (unsigned char *) index (p, '&');
@@ -1117,6 +1258,7 @@ DEFUN ("system-name", Fsystem_name, Ssystem_name, 0, 0, 0,
 }
 
 /* For the benefit of callers who don't want to include lisp.h */
+
 char *
 get_system_name ()
 {
@@ -1157,12 +1299,25 @@ resolution finer than a second.")
 \f
 
 static int
-lisp_time_argument (specified_time, result)
+lisp_time_argument (specified_time, result, usec)
      Lisp_Object specified_time;
      time_t *result;
+     int *usec;
 {
   if (NILP (specified_time))
-    return time (result) != -1;
+    {
+      if (usec)
+        {
+          EMACS_TIME t;
+
+          EMACS_GET_TIME (t);
+          *usec = EMACS_USECS (t);
+          *result = EMACS_SECS (t);
+          return 1;
+        }
+      else
+        return time (result) != -1;
+    }
   else
     {
       Lisp_Object high, low;
@@ -1170,13 +1325,49 @@ lisp_time_argument (specified_time, result)
       CHECK_NUMBER (high, 0);
       low = Fcdr (specified_time);
       if (CONSP (low))
-       low = Fcar (low);
+        {
+          if (usec)
+            {
+              Lisp_Object usec_l = Fcdr (low);
+              if (CONSP (usec_l))
+                usec_l = Fcar (usec_l);
+              if (NILP (usec_l))
+                *usec = 0;
+              else
+                {
+                  CHECK_NUMBER (usec_l, 0);
+                  *usec = XINT (usec_l);
+                }
+            }
+          low = Fcar (low);
+        }
+      else if (usec)
+        *usec = 0;
       CHECK_NUMBER (low, 0);
       *result = (XINT (high) << 16) + (XINT (low) & 0xffff);
       return *result >> 16 == XINT (high);
     }
 }
 
+DEFUN ("float-time", Ffloat_time, Sfloat_time, 0, 1, 0,
+  "Return the current time, as a float number of seconds since the epoch.\n\
+If an argument is given, it specifies a time to convert to float\n\
+instead of the current time.  The argument should have the forms:\n\
+ (HIGH . LOW) or (HIGH LOW USEC) or (HIGH LOW . USEC).\n\
+Thus, you can use times obtained from `current-time'\n\
+and from `file-attributes'.")
+  (specified_time)
+     Lisp_Object specified_time;
+{
+  time_t sec;
+  int usec;
+
+  if (! lisp_time_argument (specified_time, &sec, &usec))
+    error ("Invalid time specification");
+
+  return make_float (sec + usec * 0.0000001);
+}
+
 /* Write information into buffer S of size MAXSIZE, according to the
    FORMAT of length FORMAT_LEN, using time information taken from *TP.
    Default to Universal Time if UT is nonzero, local time otherwise.
@@ -1294,7 +1485,7 @@ DEFUN ("format-time-string", Fformat_time_string, Sformat_time_string, 1, 3, 0,
 
   CHECK_STRING (format_string, 1);
 
-  if (! lisp_time_argument (time, &value))
+  if (! lisp_time_argument (time, &value, NULL))
     error ("Invalid time specification");
 
   format_string = code_convert_string_norecord (format_string,
@@ -1351,8 +1542,8 @@ ZONE is an integer indicating the number of seconds east of Greenwich.\n\
   struct tm save_tm;
   struct tm *decoded_time;
   Lisp_Object list_args[9];
-  
-  if (! lisp_time_argument (specified_time, &time_spec))
+
+  if (! lisp_time_argument (specified_time, &time_spec, NULL))
     error ("Invalid time specification");
 
   decoded_time = localtime (&time_spec);
@@ -1426,7 +1617,7 @@ If you want them to stand for years in this century, you must do that yourself."
       char tzbuf[100];
       char *tzstring;
       char **oldenv = environ, **newenv;
-      
+
       if (EQ (zone, Qt))
        tzstring = "UTC0";
       else if (STRINGP (zone))
@@ -1441,7 +1632,7 @@ If you want them to stand for years in this century, you must do that yourself."
       else
        error ("Invalid time zone specification");
 
-      /* Set TZ before calling mktime; merely adjusting mktime's returned 
+      /* Set TZ before calling mktime; merely adjusting mktime's returned
         value doesn't suffice, since that would mishandle leap seconds.  */
       set_time_zone_rule (tzstring);
 
@@ -1484,7 +1675,7 @@ and from `file-attributes'.")
   char buf[30];
   register char *tem;
 
-  if (! lisp_time_argument (specified_time, &value))
+  if (! lisp_time_argument (specified_time, &value, NULL))
     value = -1;
   tem = (char *) ctime (&value);
 
@@ -1544,7 +1735,7 @@ the data it can't find.")
   struct tm *t;
   struct tm gmt;
 
-  if (lisp_time_argument (specified_time, &value)
+  if (lisp_time_argument (specified_time, &value, NULL)
       && (t = gmtime (&value)) != 0
       && (gmt = *t, t = localtime (&value)) != 0)
     {
@@ -1610,7 +1801,7 @@ If TZ is t, use Universal Time.")
 /* These two values are known to load tz files in buggy implementations,
    i.e. Solaris 1 executables running under either Solaris 1 or Solaris 2.
    Their values shouldn't matter in non-buggy implementations.
-   We don't use string literals for these strings, 
+   We don't use string literals for these strings,
    since if a string in the environment is in readonly
    storage, it runs afoul of bugs in SVR4 and Solaris 2.3.
    See Sun bugs 1113095 and 1114114, ``Timezone routines
@@ -1624,6 +1815,7 @@ static char set_time_zone_rule_tz2[] = "TZ=GMT+1";
 /* Set the local time zone rule to TZSTRING.
    This allocates memory into `environ', which it is the caller's
    responsibility to free.  */
+
 void
 set_time_zone_rule (tzstring)
      char *tzstring;
@@ -1705,7 +1897,7 @@ set_time_zone_rule (tzstring)
    type of object is Lisp_String).  INHERIT is passed to
    INSERT_FROM_STRING_FUNC as the last argument.  */
 
-void
+static void
 general_insert_function (insert_func, insert_from_string_func,
                         inherit, nargs, args)
      void (*insert_func) P_ ((unsigned char *, int));
@@ -2032,8 +2224,7 @@ they can be in either order.")
 DEFUN ("buffer-string", Fbuffer_string, Sbuffer_string, 0, 0, 0,
   "Return the contents of the current buffer as a string.\n\
 If narrowing is in effect, this function returns only the visible part\n\
-of the buffer.  If in a mini-buffer, don't include the prompt in the\n\
-string returned.")
+of the buffer.")
   ()
 {
   return make_buffer_string (BEGV, ZV, 1);
@@ -2279,13 +2470,14 @@ Both characters must have the same length of multi-byte form.")
 #define COMBINING_AFTER  2
 #define COMBINING_BOTH (COMBINING_BEFORE | COMBINING_AFTER)
   int maybe_byte_combining = COMBINING_NO;
-  int last_changed;
+  int last_changed = 0;
+  int multibyte_p = !NILP (current_buffer->enable_multibyte_characters);
 
   validate_region (&start, &end);
   CHECK_NUMBER (fromchar, 2);
   CHECK_NUMBER (tochar, 3);
 
-  if (! NILP (current_buffer->enable_multibyte_characters))
+  if (multibyte_p)
     {
       len = CHAR_STRING (XFASTINT (fromchar), fromstr);
       if (CHAR_STRING (XFASTINT (tochar), tostr) != len)
@@ -2341,7 +2533,10 @@ Both characters must have the same length of multi-byte form.")
          stop = end_byte;
        }
       p = BYTE_POS_ADDR (pos_byte);
-      INC_POS (pos_byte_next);
+      if (multibyte_p)
+       INC_POS (pos_byte_next);
+      else
+       ++pos_byte_next;
       if (pos_byte_next - pos_byte == len
          && p[0] == fromstr[0]
          && (len == 1
@@ -2364,7 +2559,7 @@ Both characters must have the same length of multi-byte form.")
            }
 
          /* Take care of the case where the new character
-            combines with neighboring bytes.  */ 
+            combines with neighboring bytes.  */
          if (maybe_byte_combining
              && (maybe_byte_combining == COMBINING_AFTER
                  ? (pos_byte_next < Z_BYTE
@@ -2395,7 +2590,7 @@ Both characters must have the same length of multi-byte form.")
                pos--;
              else
                INC_POS (pos_byte_next);
-               
+
              if (! NILP (noundo))
                current_buffer->undo_list = tem;
 
@@ -2473,7 +2668,7 @@ It returns the number of characters changed.")
          if (nc != oc)
            {
              /* Take care of the case where the new character
-                combines with neighboring bytes.  */ 
+                combines with neighboring bytes.  */
              if (!ASCII_BYTE_P (nc)
                  && (CHAR_HEAD_P (nc)
                      ? ! CHAR_HEAD_P (FETCH_BYTE (pos_byte + 1))
@@ -2591,53 +2786,71 @@ or markers) bounding the text that should remain visible.")
 Lisp_Object
 save_restriction_save ()
 {
-  register Lisp_Object bottom, top;
-  /* Note: I tried using markers here, but it does not win
-     because insertion at the end of the saved region
-     does not advance mh and is considered "outside" the saved region. */
-  XSETFASTINT (bottom, BEGV - BEG);
-  XSETFASTINT (top, Z - ZV);
+  if (BEGV == BEG && ZV == Z)
+    /* The common case that the buffer isn't narrowed.
+       We return just the buffer object, which save_restriction_restore
+       recognizes as meaning `no restriction'.  */
+    return Fcurrent_buffer ();
+  else
+    /* We have to save a restriction, so return a pair of markers, one
+       for the beginning and one for the end.  */
+    {
+      Lisp_Object beg, end;
+
+      beg = buildmark (BEGV, BEGV_BYTE);
+      end = buildmark (ZV, ZV_BYTE);
 
-  return Fcons (Fcurrent_buffer (), Fcons (bottom, top));
+      /* END must move forward if text is inserted at its exact location.  */
+      XMARKER(end)->insertion_type = 1;
+
+      return Fcons (beg, end);
+    }
 }
 
 Lisp_Object
 save_restriction_restore (data)
      Lisp_Object data;
 {
-  register struct buffer *buf;
-  register int newhead, newtail;
-  register Lisp_Object tem;
-  int obegv, ozv;
-
-  buf = XBUFFER (XCAR (data));
-
-  data = XCDR (data);
-
-  tem = XCAR (data);
-  newhead = XINT (tem);
-  tem = XCDR (data);
-  newtail = XINT (tem);
-  if (newhead + newtail > BUF_Z (buf) - BUF_BEG (buf))
+  if (CONSP (data))
+    /* A pair of marks bounding a saved restriction.  */
     {
-      newhead = 0;
-      newtail = 0;
-    }
+      struct Lisp_Marker *beg = XMARKER (XCAR (data));
+      struct Lisp_Marker *end = XMARKER (XCDR (data));
+      struct buffer *buf = beg->buffer; /* END should have the same buffer. */
 
-  obegv = BUF_BEGV (buf);
-  ozv = BUF_ZV (buf);
-
-  SET_BUF_BEGV (buf, BUF_BEG (buf) + newhead);
-  SET_BUF_ZV (buf, BUF_Z (buf) - newtail);
+      if (beg->charpos != BUF_BEGV(buf) || end->charpos != BUF_ZV(buf))
+       /* The restriction has changed from the saved one, so restore
+          the saved restriction.  */
+       {
+         int pt = BUF_PT (buf);
+
+         SET_BUF_BEGV_BOTH (buf, beg->charpos, beg->bytepos);
+         SET_BUF_ZV_BOTH (buf, end->charpos, end->bytepos);
+
+         if (pt < beg->charpos || pt > end->charpos)
+           /* The point is outside the new visible range, move it inside. */
+           SET_BUF_PT_BOTH (buf,
+                            clip_to_bounds (beg->charpos, pt, end->charpos),
+                            clip_to_bounds (beg->bytepos, BUF_PT_BYTE(buf),
+                                            end->bytepos));
+         
+         buf->clip_changed = 1; /* Remember that the narrowing changed. */
+       }
+    }
+  else
+    /* A buffer, which means that there was no old restriction.  */
+    {
+      struct buffer *buf = XBUFFER (data);
 
-  if (obegv != BUF_BEGV (buf) || ozv != BUF_ZV (buf))
-    current_buffer->clip_changed = 1;
+      if (BUF_BEGV(buf) != BUF_BEG(buf) || BUF_ZV(buf) != BUF_Z(buf))
+       /* The buffer has been narrowed, get rid of the narrowing.  */
+       {
+         SET_BUF_BEGV_BOTH (buf, BUF_BEG(buf), BUF_BEG_BYTE(buf));
+         SET_BUF_ZV_BOTH (buf, BUF_Z(buf), BUF_Z_BYTE(buf));
 
-  /* If point is outside the new visible range, move it inside. */
-  SET_BUF_PT_BOTH (buf,
-                  clip_to_bounds (BUF_BEGV (buf), BUF_PT (buf), BUF_ZV (buf)),
-                  clip_to_bounds (BUF_BEGV_BYTE (buf), BUF_PT_BYTE (buf),
-                                  BUF_ZV_BYTE (buf)));
+         buf->clip_changed = 1; /* Remember that the narrowing changed. */
+       }
+    }
 
   return Qnil;
 }
@@ -2654,10 +2867,6 @@ even in case of abnormal exit (throw or error).\n\
 \n\
 The value returned is the value of the last form in BODY.\n\
 \n\
-`save-restriction' can get confused if, within the BODY, you widen\n\
-and then make changes outside the area within the saved restrictions.\n\
-See Info node `(elisp)Narrowing' for details and an appropriate technique.\n\
-\n\
 Note: if you are using both `save-excursion' and `save-restriction',\n\
 use `save-excursion' outermost:\n\
     (save-excursion (save-restriction ...))")
@@ -2764,7 +2973,8 @@ extern Lisp_Object last_nonmenu_event;
 
 DEFUN ("message-or-box", Fmessage_or_box, Smessage_or_box, 1, MANY, 0,
   "Display a message in a dialog box or in the echo area.\n\
-If this command was invoked with the mouse, use a dialog box.\n\
+If this command was invoked with the mouse, use a dialog box if\n\
+`use-dialog-box' is non-nil.\n\
 Otherwise, use the echo area.\n\
 The first argument is a format control string, and the rest are data\n\
 to be formatted under control of the string.  See `format' for details.\n\
@@ -2777,7 +2987,7 @@ minibuffer contents show.")
 {
 #ifdef HAVE_MENUS
   if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event))
-      && NILP (use_dialog_box))
+      && use_dialog_box)
     return Fmessage_box (nargs, args);
 #endif
   return Fmessage (nargs, args);
@@ -2810,7 +3020,7 @@ properties to add to the result ")
 
   properties = string = Qnil;
   GCPRO2 (properties, string);
-  
+
   /* First argument must be a string.  */
   CHECK_STRING (args[0], 0);
   string = Fcopy_sequence (args[0]);
@@ -2877,8 +3087,6 @@ Use %% to put a single % into the output.")
     int start, end;
   } *info = 0;
 
-  extern char *index ();
-
   /* It should not be necessary to GCPRO ARGS, because
      the caller in the interpreter should take care of that.  */
 
@@ -2945,7 +3153,10 @@ Use %% to put a single % into the output.")
          }
        else if (SYMBOLP (args[n]))
          {
-           XSETSTRING (args[n], XSYMBOL (args[n])->name);
+           /* Use a temp var to avoid problems when ENABLE_CHECKING
+              is turned on.  */
+           struct Lisp_String *t = XSYMBOL (args[n])->name;
+           XSETSTRING (args[n], t);
            if (STRING_MULTIBYTE (args[n]) && ! multibyte)
              {
                multibyte = 1;
@@ -2963,7 +3174,6 @@ Use %% to put a single % into the output.")
        /* Would get MPV otherwise, since Lisp_Int's `point' to low memory.  */
        else if (INTEGERP (args[n]) && *format != 's')
          {
-#ifdef LISP_FLOAT_TYPE
            /* The following loop assumes the Lisp type indicates
               the proper way to pass the argument.
               So make sure we have a flonum if the argument should
@@ -2971,12 +3181,11 @@ Use %% to put a single % into the output.")
            if (*format == 'e' || *format == 'f' || *format == 'g')
              args[n] = Ffloat (args[n]);
            else
-#endif
              if (*format != 'd' && *format != 'o' && *format != 'x'
                  && *format != 'i' && *format != 'X' && *format != 'c')
                error ("Invalid format operation %%%c", *format);
 
-           thissize = 30;      
+           thissize = 30;
            if (*format == 'c'
                && (! SINGLE_BYTE_CHAR_P (XINT (args[n]))
                    || XINT (args[n]) == 0))
@@ -2990,14 +3199,12 @@ Use %% to put a single % into the output.")
                thissize = STRING_BYTES (XSTRING (args[n]));
              }
          }
-#ifdef LISP_FLOAT_TYPE
        else if (FLOATP (args[n]) && *format != 's')
          {
            if (! (*format == 'e' || *format == 'f' || *format == 'g'))
              args[n] = Ftruncate (args[n], Qnil);
            thissize = 200;
          }
-#endif
        else
          {
            /* Anything but a string, convert to a string using princ.  */
@@ -3011,7 +3218,7 @@ Use %% to put a single % into the output.")
            args[n] = tem;
            goto string;
          }
-       
+
        if (thissize < minlen)
          thissize = minlen;
 
@@ -3110,7 +3317,7 @@ Use %% to put a single % into the output.")
                      info = (struct info *) alloca (nbytes);
                      bzero (info, nbytes);
                    }
-                 
+
                  info[n].start = start;
                  info[n].end = nchars;
                }
@@ -3134,7 +3341,10 @@ Use %% to put a single % into the output.")
                  && !CHAR_HEAD_P (*((unsigned char *) p)))
                maybe_combine_byte = 1;
              this_nchars = strlen (p);
-             p += this_nchars;
+             if (multibyte)
+               p += str_to_multibyte (p, buf + total - p, this_nchars);
+             else
+               p += this_nchars;
              nchars += this_nchars;
            }
        }
@@ -3174,17 +3384,17 @@ Use %% to put a single % into the output.")
   /* If the format string has text properties, or any of the string
      arguments has text properties, set up text properties of the
      result string.  */
-  
+
   if (XSTRING (args[0])->intervals || info)
     {
       Lisp_Object len, new_len, props;
       struct gcpro gcpro1;
-      
+
       /* Add text properties from the format string.  */
       len = make_number (XSTRING (args[0])->size);
       props = text_property_list (args[0], make_number (0), len, Qnil);
       GCPRO1 (props);
-      
+
       if (CONSP (props))
        {
          new_len = make_number (XSTRING (val)->size);
@@ -3201,6 +3411,10 @@ Use %% to put a single % into the output.")
              new_len = make_number (info[n].end - info[n].start);
              props = text_property_list (args[n], make_number (0), len, Qnil);
              extend_property_ranges (props, len, new_len);
+             /* If successive arguments have properites, be sure that
+                the value of `composition' property be the copy.  */
+             if (n > 1 && info[n - 1].end)
+               make_composition_value_copy (props);
              add_text_properties_from_list (val, props,
                                             make_number (info[n].start));
            }
@@ -3273,10 +3487,10 @@ Case is ignored if `case-fold-search' is non-nil in the current buffer.")
    Traverses the entire marker list of the buffer to do so, adding an
    appropriate amount to some, subtracting from some, and leaving the
    rest untouched.  Most of this is copied from adjust_markers in insdel.c.
-  
+
    It's the caller's job to ensure that START1 <= END1 <= START2 <= END2.  */
 
-void
+static void
 transpose_markers (start1, end1, start2, end2,
                   start1_byte, end1_byte, start2_byte, end2_byte)
      register int start1, end1, start2, end2;
@@ -3310,7 +3524,7 @@ transpose_markers (start1, end1, start2, end2,
   /* The difference between the region's lengths */
   diff = (end2 - start2) - (end1 - start1);
   diff_byte = (end2_byte - start2_byte) - (end1_byte - start1_byte);
-  
+
   /* For shifting each marker in a region by the length of the other
      region plus the distance between the regions.  */
   amt1 = (end2 - start2) + (start2 - end1);
@@ -3362,8 +3576,6 @@ Transposing beyond buffer boundaries is an error.")
   int start1_byte, start2_byte, len1_byte, len2_byte;
   int gap, len1, len_mid, len2;
   unsigned char *start1_addr, *start2_addr, *temp;
-  int combined_before_bytes_1, combined_after_bytes_1;
-  int combined_before_bytes_2, combined_after_bytes_2;
   struct gcpro gcpro1, gcpro2;
 
   INTERVAL cur_intv, tmp_interval1, tmp_interval_mid, tmp_interval2;
@@ -3401,7 +3613,7 @@ Transposing beyond buffer boundaries is an error.")
      1. Adjacent (contiguous) regions, or separate but equal regions
      (no, really equal, in this case!), or
      2. Separate regions of unequal size.
-     
+
      The worst case is usually No. 2.  It means that (aside from
      potential need for getting the gap out of the way), there also
      needs to be a shifting of the text between the two regions.  So
@@ -3434,61 +3646,31 @@ Transposing beyond buffer boundaries is an error.")
   len1_byte = CHAR_TO_BYTE (end1) - start1_byte;
   len2_byte = CHAR_TO_BYTE (end2) - start2_byte;
 
+#ifdef BYTE_COMBINING_DEBUG
   if (end1 == start2)
     {
-      combined_before_bytes_2
-       = count_combining_before (BYTE_POS_ADDR (start2_byte),
-                                 len2_byte, start1, start1_byte);
-      combined_before_bytes_1
-       = count_combining_before (BYTE_POS_ADDR (start1_byte),
-                                 len1_byte, end2, start2_byte + len2_byte);
-      combined_after_bytes_1
-       = count_combining_after (BYTE_POS_ADDR (start1_byte),
-                                len1_byte, end2, start2_byte + len2_byte);
-      combined_after_bytes_2 = 0;
+      if (count_combining_before (BYTE_POS_ADDR (start2_byte),
+                                 len2_byte, start1, start1_byte)
+         || count_combining_before (BYTE_POS_ADDR (start1_byte),
+                                    len1_byte, end2, start2_byte + len2_byte)
+         || count_combining_after (BYTE_POS_ADDR (start1_byte),
+                                   len1_byte, end2, start2_byte + len2_byte))
+       abort ();
     }
   else
     {
-      combined_before_bytes_2
-       = count_combining_before (BYTE_POS_ADDR (start2_byte),
-                                 len2_byte, start1, start1_byte);
-      combined_before_bytes_1
-       = count_combining_before (BYTE_POS_ADDR (start1_byte),
-                                 len1_byte, start2, start2_byte);
-      combined_after_bytes_2
-       = count_combining_after (BYTE_POS_ADDR (start2_byte),
-                                len2_byte, end1, start1_byte + len1_byte);
-      combined_after_bytes_1
-       = count_combining_after (BYTE_POS_ADDR (start1_byte),
-                                len1_byte, end2, start2_byte + len2_byte);
+      if (count_combining_before (BYTE_POS_ADDR (start2_byte),
+                                 len2_byte, start1, start1_byte)
+         || count_combining_before (BYTE_POS_ADDR (start1_byte),
+                                    len1_byte, start2, start2_byte)
+         || count_combining_after (BYTE_POS_ADDR (start2_byte),
+                                   len2_byte, end1, start1_byte + len1_byte)
+         || count_combining_after (BYTE_POS_ADDR (start1_byte),
+                                   len1_byte, end2, start2_byte + len2_byte))
+       abort ();
     }
+#endif
 
-  /* If any combining is going to happen, do this the stupid way,
-     because replace handles combining properly.  */
-  if (combined_before_bytes_1 || combined_before_bytes_2
-      || combined_after_bytes_1 || combined_after_bytes_2)
-    {
-      Lisp_Object text1, text2;
-
-      text1 = text2 = Qnil;
-      GCPRO2 (text1, text2);
-
-      text1 = make_buffer_string_both (start1, start1_byte,
-                                      end1, start1_byte + len1_byte, 1);
-      text2 = make_buffer_string_both (start2, start2_byte,
-                                      end2, start2_byte + len2_byte, 1);
-
-      transpose_markers (start1, end1, start2, end2,
-                        start1_byte, start1_byte + len1_byte,
-                        start2_byte, start2_byte + len2_byte);
-
-      replace_range (start2, end2, text1, 1, 0, 0);
-      replace_range (start1, end1, text2, 1, 0, 0);
-
-      UNGCPRO;
-      return Qnil;
-    }
-      
   /* Hmmm... how about checking to see if the gap is large
      enough to use as the temporary storage?  That would avoid an
      allocation... interesting.  Later, don't fool with it now.  */
@@ -3526,7 +3708,7 @@ Transposing beyond buffer boundaries is an error.")
           bcopy (start1_addr, start1_addr + len2_byte, len1_byte);
           bcopy (temp, start1_addr, len2_byte);
          if (len2_byte > 20000)
-           free (temp);
+           xfree (temp);
         }
       else
        /* First region not smaller than second.  */
@@ -3541,7 +3723,7 @@ Transposing beyond buffer boundaries is an error.")
           bcopy (start2_addr, start1_addr, len2_byte);
           bcopy (temp, start1_addr + len2_byte, len1_byte);
          if (len1_byte > 20000)
-           free (temp);
+           xfree (temp);
         }
       graft_intervals_into_buffer (tmp_interval1, start1 + len2,
                                    len1, current_buffer, 0);
@@ -3579,7 +3761,7 @@ Transposing beyond buffer boundaries is an error.")
           bcopy (start2_addr, start1_addr, len2_byte);
           bcopy (temp, start2_addr, len1_byte);
          if (len1_byte > 20000)
-           free (temp);
+           xfree (temp);
           graft_intervals_into_buffer (tmp_interval1, start2,
                                        len1, current_buffer, 0);
           graft_intervals_into_buffer (tmp_interval2, start1,
@@ -3609,7 +3791,7 @@ Transposing beyond buffer boundaries is an error.")
           safe_bcopy (start1_addr + len1_byte, start1_addr + len2_byte, len_mid);
           bcopy (temp, start1_addr, len2_byte);
          if (len2_byte > 20000)
-           free (temp);
+           xfree (temp);
           graft_intervals_into_buffer (tmp_interval1, end2 - len1,
                                        len1, current_buffer, 0);
           graft_intervals_into_buffer (tmp_interval_mid, start1 + len2,
@@ -3641,7 +3823,7 @@ Transposing beyond buffer boundaries is an error.")
           bcopy (start1_addr + len1_byte, start1_addr + len2_byte, len_mid);
           bcopy (temp, start1_addr + len2_byte + len_mid, len1_byte);
          if (len1_byte > 20000)
-           free (temp);
+           xfree (temp);
           graft_intervals_into_buffer (tmp_interval1, end2 - len1,
                                        len1, current_buffer, 0);
           graft_intervals_into_buffer (tmp_interval_mid, start1 + len2,
@@ -3710,7 +3892,7 @@ functions if all the text being accessed has this property.");
 
   DEFVAR_LISP ("system-name", &Vsystem_name,
               "The name of the machine Emacs is running on.");
-  
+
   DEFVAR_LISP ("user-full-name", &Vuser_full_name,
               "The full name of the user logged in.");
 
@@ -3737,6 +3919,8 @@ functions if all the text being accessed has this property.");
 
   staticpro (&Qfield);
   Qfield = intern ("field");
+  staticpro (&Qboundary);
+  Qboundary = intern ("boundary");
   defsubr (&Sfield_beginning);
   defsubr (&Sfield_end);
   defsubr (&Sfield_string);
@@ -3784,6 +3968,7 @@ functions if all the text being accessed has this property.");
   defsubr (&Semacs_pid);
   defsubr (&Scurrent_time);
   defsubr (&Sformat_time_string);
+  defsubr (&Sfloat_time);
   defsubr (&Sdecode_time);
   defsubr (&Sencode_time);
   defsubr (&Scurrent_time_string);