(record_char): Record `help-echo' input events
[bpt/emacs.git] / src / editfns.c
index d469a99..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 ()
 {
@@ -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,6 +312,7 @@ 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.  */
@@ -293,13 +330,13 @@ char_property_eq (prop, pos1, pos2)
   return EQ (pval1, pval2);
 }
 
-/* Return the direction from which the char-property PROP would be
+/* Return the direction from which the text-property PROP would be
    inherited by any new text inserted at POS: 1 if it would be
    inherited from the char after POS, -1 if it would be inherited from
    the char before POS, and 0 if from neither.  */
 
 static int
-char_property_stickiness (prop, pos)
+text_property_stickiness (prop, pos)
      Lisp_Object prop;
      Lisp_Object pos;
 {
@@ -311,7 +348,7 @@ char_property_stickiness (prop, pos)
       Lisp_Object prev_pos, rear_non_sticky;
 
       prev_pos = make_number (XINT (pos) - 1);
-      rear_non_sticky = Fget_char_property (prev_pos, Qrear_nonsticky, Qnil);
+      rear_non_sticky = Fget_text_property (prev_pos, Qrear_nonsticky, Qnil);
 
       if (EQ (rear_non_sticky, Qnil)
          || (CONSP (rear_non_sticky)
@@ -322,7 +359,7 @@ char_property_stickiness (prop, pos)
     }
 
   /* Consider following character.  */
-  front_sticky = Fget_char_property (pos, Qfront_sticky, Qnil);
+  front_sticky = Fget_text_property (pos, Qfront_sticky, Qnil);
 
   if (EQ (front_sticky, Qt)
       || (CONSP (front_sticky)
@@ -333,15 +370,11 @@ char_property_stickiness (prop, pos)
   /* PROP is not inherited from either side.  */
   return 0;
 }
-\f
-/* Symbol for the text property used to mark fields.  */
-Lisp_Object Qfield;
-
-/* A special value for Qfield properties.  */
-Lisp_Object Qboundary;
 
+\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
@@ -356,7 +389,7 @@ Lisp_Object Qboundary;
    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;
@@ -364,6 +397,9 @@ find_field (pos, merge_at_boundary, 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.  */
@@ -374,12 +410,14 @@ find_field (pos, merge_at_boundary, beg, end)
   else
     CHECK_NUMBER_COERCE_MARKER (pos, 0);
 
-  after_field =
-    Fget_char_property (pos, Qfield, Qnil);
-  before_field =
-    (XFASTINT (pos) > BEGV
-     ? Fget_char_property (make_number (XINT (pos) - 1), Qfield, Qnil)
-     : Qnil);
+  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
@@ -391,7 +429,42 @@ find_field (pos, merge_at_boundary, beg, end)
     /* We are at a boundary, see which direction is inclusive.  We
        decide by seeing which field the `field' property sticks to.  */
     {
-      int stickiness = char_property_stickiness (Qfield, pos);
+      /* -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;
@@ -433,37 +506,42 @@ find_field (pos, merge_at_boundary, beg, end)
      the `x' field, and the end as being the end of the `y' field.  */
 
   if (beg)
-    if (at_field_start)
-      /* POS is at the edge of a field, and we should consider it as
-        the beginning of the following field.  */
-      *beg = XFASTINT (pos);
-    else
-      /* Find the previous field boundary.  */
-      {
-       if (!NILP (merge_at_boundary) && before_field == Qboundary)
-         /* Skip a `boundary' field.  */
-         pos = Fprevious_single_char_property_change (pos, Qfield, Qnil,Qnil);
+    {
+      if (at_field_start)
+       /* POS is at the edge of a field, and we should consider it as
+          the beginning of the following field.  */
+       *beg = XFASTINT (pos);
+      else
+       /* Find the previous field boundary.  */
+       {
+         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);
-      }
+         pos = Fprevious_single_char_property_change (pos, Qfield, Qnil, Qnil);
+         *beg = NILP (pos) ? BEGV : XFASTINT (pos);
+       }
+    }
 
   if (end)
-    if (at_field_end)
-      /* POS is at the edge of a field, and we should consider it as
-        the end of the previous field.  */
-      *end = XFASTINT (pos);
-    else
-      /* Find the next field boundary.  */
-      {
-       if (!NILP (merge_at_boundary) && after_field == Qboundary)
-         /* Skip a `boundary' field.  */
-         pos = Fnext_single_char_property_change (pos, Qfield, Qnil, Qnil);
+    {
+      if (at_field_end)
+       /* POS is at the edge of a field, and we should consider it as
+          the end of the previous field.  */
+       *end = XFASTINT (pos);
+      else
+       /* Find the next field boundary.  */
+       {
+         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);
-      }
+         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\
@@ -574,7 +652,8 @@ Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil.")
 
   if (NILP (Vinhibit_field_text_motion)
       && !EQ (new_pos, old_pos)
-      && !char_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
@@ -620,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,
@@ -635,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);
@@ -665,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);
@@ -682,13 +762,14 @@ This function does not move point.")
 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
@@ -697,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 */
@@ -710,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
@@ -729,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
@@ -744,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;
 }
@@ -777,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 ());
@@ -1103,7 +1208,6 @@ 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))
@@ -1154,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 ()
 {
@@ -1710,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;
@@ -1791,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));
@@ -2118,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);
@@ -2365,7 +2470,7 @@ 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);
@@ -2681,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;
-    }
-
-  obegv = BUF_BEGV (buf);
-  ozv = BUF_ZV (buf);
+      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. */
 
-  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;
 }
@@ -2744,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 ...))")
@@ -2854,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\
@@ -2967,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.  */
 
@@ -3372,7 +3490,7 @@ Case is ignored if `case-fold-search' is non-nil in the current buffer.")
 
    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;
@@ -3590,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.  */
@@ -3605,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);
@@ -3643,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,
@@ -3673,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,
@@ -3705,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,