]> code.delx.au - gnu-emacs/blobdiff - src/insdel.c
(modify-face): New function.
[gnu-emacs] / src / insdel.c
index 5cee99f89cd8c299edaf71162329a96ae2a6157a..74f8503422bd120939f871775ddef43c71ea3127 100644 (file)
@@ -27,6 +27,10 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 static void insert_1 ();
 static void insert_from_string_1 ();
+static void gap_left ();
+static void gap_right ();
+static void adjust_markers ();
+static void adjust_point ();
 
 /* Move gap to position `pos'.
    Note that this can quit!  */
@@ -43,6 +47,7 @@ move_gap (pos)
 /* Move the gap to POS, which is less than the current GPT.
    If NEWGAP is nonzero, then don't update beg_unchanged and end_unchanged.  */
 
+static void
 gap_left (pos, newgap)
      register int pos;
      int newgap;
@@ -125,6 +130,7 @@ gap_left (pos, newgap)
   QUIT;
 }
 
+static void
 gap_right (pos)
      register int pos;
 {
@@ -206,6 +212,7 @@ gap_right (pos)
    of adjustment, are first moved back to the near end of the interval
    and then adjusted by `amount'.  */
 
+static void
 adjust_markers (from, to, amount)
      register int from, to, amount;
 {
@@ -235,6 +242,19 @@ adjust_markers (from, to, amount)
       marker = m->chain;
     }
 }
+
+/* Add the specified amount to point.  This is used only when the value
+   of point changes due to an insert or delete; it does not represent
+   a conceptual change in point as a marker.  In particular, point is
+   not crossing any interval boundaries, so there's no need to use the
+   usual SET_PT macro.  In fact it would be incorrect to do so, because
+   either the old or the new value of point is out of synch with the
+   current set of intervals.  */
+static void
+adjust_point (amount)
+{
+  current_buffer->text.pt += amount;
+}
 \f
 /* Make the gap INCREMENT characters longer.  */
 
@@ -289,15 +309,27 @@ insert (string, length)
 {
   if (length > 0)
     {
-      insert_1 (string, length);
-      signal_after_change (point-length, 0, length);
+      insert_1 (string, length, 0);
+      signal_after_change (PT-length, 0, length);
+    }
+}
+
+insert_and_inherit (string, length)
+     register unsigned char *string;
+     register length;
+{
+  if (length > 0)
+    {
+      insert_1 (string, length, 1);
+      signal_after_change (PT-length, 0, length);
     }
 }
 
 static void
-insert_1 (string, length)
+insert_1 (string, length, inherit)
      register unsigned char *string;
      register length;
+     int inherit;
 {
   register Lisp_Object temp;
 
@@ -306,26 +338,35 @@ insert_1 (string, length)
   if (length + Z != XINT (temp))
     error ("maximum buffer size exceeded");
 
-  prepare_to_modify_buffer (point, point);
+  prepare_to_modify_buffer (PT, PT);
 
-  if (point != GPT)
-    move_gap (point);
+  if (PT != GPT)
+    move_gap (PT);
   if (GAP_SIZE < length)
     make_gap (length - GAP_SIZE);
 
-  record_insert (point, length);
+  record_insert (PT, length);
   MODIFF++;
 
   bcopy (string, GPT_ADDR, length);
 
-  /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
-  offset_intervals (current_buffer, point, length);
+#ifdef USE_TEXT_PROPERTIES
+  if (current_buffer->intervals != 0)
+    /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES.  */
+    offset_intervals (current_buffer, PT, length);
+#endif
 
   GAP_SIZE -= length;
   GPT += length;
   ZV += length;
   Z += length;
-  SET_PT (point + length);
+  adjust_point (length);
+
+#ifdef USE_TEXT_PROPERTIES
+  if (!inherit && current_buffer->intervals != 0)
+    Fset_text_properties (make_number (PT - length), make_number (PT),
+                         Qnil, Qnil);
+#endif
 }
 
 /* Insert the part of the text of STRING, a Lisp object assumed to be
@@ -345,7 +386,7 @@ insert_from_string (string, pos, length, inherit)
   if (length > 0)
     {
       insert_from_string_1 (string, pos, length, inherit);
-      signal_after_change (point-length, 0, length);
+      signal_after_change (PT-length, 0, length);
     }
 }
 
@@ -364,21 +405,21 @@ insert_from_string_1 (string, pos, length, inherit)
     error ("maximum buffer size exceeded");
 
   GCPRO1 (string);
-  prepare_to_modify_buffer (point, point);
+  prepare_to_modify_buffer (PT, PT);
 
-  if (point != GPT)
-    move_gap (point);
+  if (PT != GPT)
+    move_gap (PT);
   if (GAP_SIZE < length)
     make_gap (length - GAP_SIZE);
 
-  record_insert (point, length);
+  record_insert (PT, length);
   MODIFF++;
   UNGCPRO;
 
   bcopy (XSTRING (string)->data, GPT_ADDR, length);
 
   /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
-  offset_intervals (current_buffer, point, length);
+  offset_intervals (current_buffer, PT, length);
 
   GAP_SIZE -= length;
   GPT += length;
@@ -386,10 +427,10 @@ insert_from_string_1 (string, pos, length, inherit)
   Z += length;
 
   /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
-  graft_intervals_into_buffer (XSTRING (string)->intervals, point, length,
+  graft_intervals_into_buffer (XSTRING (string)->intervals, PT, length,
                               current_buffer, inherit);
 
-  SET_PT (point + length);
+  adjust_point (length);
 }
 
 /* Insert the character C before point */
@@ -421,10 +462,23 @@ insert_before_markers (string, length)
 {
   if (length > 0)
     {
-      register int opoint = point;
-      insert_1 (string, length);
+      register int opoint = PT;
+      insert_1 (string, length, 1);
+      adjust_markers (opoint - 1, opoint, length);
+      signal_after_change (PT-length, 0, length);
+    }
+}
+
+insert_before_markers_and_inherit (string, length)
+     unsigned char *string;
+     register int length;
+{
+  if (length > 0)
+    {
+      register int opoint = PT;
+      insert_1 (string, length, 1);
       adjust_markers (opoint - 1, opoint, length);
-      signal_after_change (point-length, 0, length);
+      signal_after_change (PT-length, 0, length);
     }
 }
 
@@ -437,10 +491,10 @@ insert_from_string_before_markers (string, pos, length, inherit)
 {
   if (length > 0)
     {
-      register int opoint = point;
+      register int opoint = PT;
       insert_from_string_1 (string, pos, length, inherit);
       adjust_markers (opoint - 1, opoint, length);
-      signal_after_change (point-length, 0, length);
+      signal_after_change (PT-length, 0, length);
     }
 }
 \f
@@ -482,13 +536,8 @@ del_range_1 (from, to, prepare)
   MODIFF++;
 
   /* Relocate point as if it were a marker.  */
-  if (from < point)
-    {
-      if (point < to)
-       SET_PT (from);
-      else
-       SET_PT (point - numdel);
-    }
+  if (from < PT)
+    adjust_point (from - (PT < to ? PT : to));
 
   /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
   offset_intervals (current_buffer, from, - numdel);
@@ -507,6 +556,7 @@ del_range_1 (from, to, prepare)
   if (Z - GPT < end_unchanged)
     end_unchanged = Z - GPT;
 
+  evaporate_overlays (from);
   signal_after_change (from, numdel, 0);
 }
 \f
@@ -551,9 +601,12 @@ prepare_to_modify_buffer (start, end)
     Fbarf_if_buffer_read_only ();
 
   /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
-  verify_interval_modification (current_buffer, start, end);
+  if (current_buffer->intervals != 0)
+    verify_interval_modification (current_buffer, start, end);
 
-  verify_overlay_modification (start, end);
+  if (!NILP (current_buffer->overlays_before)
+      || !NILP (current_buffer->overlays_after))
+    verify_overlay_modification (start, end);
 
 #ifdef CLASH_DETECTION
   if (!NILP (current_buffer->filename)