changeset 21135:42badfae3618

(insert_1_both, insert_from_string_1, insert_from_buffer_1): Count all of combined_after_bytes, not just 1, when correcting nchars, and in related places. (adjust_after_replace, replace_range): Likewise.
author Richard M. Stallman <rms@gnu.org>
date Tue, 10 Mar 1998 23:50:30 +0000
parents 060f95085d3d
children be04baf3d970
files src/insdel.c
diffstat 1 files changed, 26 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/insdel.c	Tue Mar 10 22:54:43 1998 +0000
+++ b/src/insdel.c	Tue Mar 10 23:50:30 1998 +0000
@@ -859,11 +859,15 @@
   combined_after_bytes = count_combining_after (string, nbytes, PT, PT_BYTE);
 
   /* This is the net amount that Z will increase from this insertion.  */
-  adjusted_nchars = nchars - !!combined_before_bytes - !!combined_after_bytes;
+  /* The combined bytes before all count as one character, because
+     they start with a leading code, but the combined bytes after
+     count as separate characters, because they are all trailing codes.  */
+
+  adjusted_nchars = nchars - !!combined_before_bytes - combined_after_bytes;
 
   if (prepare)
     prepare_to_modify_buffer (PT - !!combined_before_bytes,
-			      PT + !!combined_after_bytes,
+			      PT + combined_after_bytes,
 			      NULL);
 
   /* Record deletion of the surrounding text that combines with
@@ -874,7 +878,7 @@
      from the buffer and reinsert them.  */
 
   if (combined_after_bytes)
-    record_delete (PT, 1);
+    record_delete (PT, combined_after_bytes);
 
   if (combined_before_bytes)
     record_delete (PT - 1, 1);
@@ -891,7 +895,7 @@
 #endif
 
   GAP_SIZE -= nbytes;
-  GPT += adjusted_nchars;
+  GPT += nchars - !! combined_before_bytes - !!combined_after_bytes;
   ZV += adjusted_nchars;
   Z += adjusted_nchars;
   GPT_BYTE += nbytes;
@@ -903,7 +907,7 @@
 			     PT + adjusted_nchars, PT_BYTE + nbytes,
 			     combined_before_bytes, combined_after_bytes,
 			     before_markers);
-  adjust_point (adjusted_nchars + !!combined_after_bytes,
+  adjust_point (adjusted_nchars + combined_after_bytes,
 		nbytes + combined_after_bytes);
 
   if (combined_after_bytes)
@@ -1025,7 +1029,7 @@
 			     PT, PT_BYTE);
 
   /* This is the net amount that Z will increase from this insertion.  */
-  adjusted_nchars = nchars - !!combined_before_bytes - !!combined_after_bytes;
+  adjusted_nchars = nchars - !!combined_before_bytes - combined_after_bytes;
 
   /* Record deletion of the surrounding text that combines with
      the insertion.  This, together with recording the insertion,
@@ -1035,7 +1039,7 @@
      from the buffer and reinsert them.  */
 
   if (combined_after_bytes)
-    record_delete (PT, 1);
+    record_delete (PT, combined_after_bytes);
 
   if (combined_before_bytes)
     record_delete (PT - 1, 1);
@@ -1047,7 +1051,7 @@
   offset_intervals (current_buffer, PT, adjusted_nchars);
 
   GAP_SIZE -= outgoing_nbytes;
-  GPT += adjusted_nchars;
+  GPT += nchars - !!combined_before_bytes - !!combined_after_bytes;
   ZV += adjusted_nchars;
   Z += adjusted_nchars;
   GPT_BYTE += outgoing_nbytes;
@@ -1068,7 +1072,7 @@
 
   graft_intervals_into_buffer (XSTRING (string)->intervals, PT, nchars,
 			       current_buffer, inherit);
-  adjust_point (adjusted_nchars + !!combined_after_bytes,
+  adjust_point (adjusted_nchars + combined_after_bytes,
 		outgoing_nbytes + combined_after_bytes);
 }
 
@@ -1161,7 +1165,7 @@
 			     PT, PT_BYTE);
 
   /* This is the net amount that Z will increase from this insertion.  */
-  adjusted_nchars = nchars - !!combined_before_bytes - !!combined_after_bytes;
+  adjusted_nchars = nchars - !!combined_before_bytes - combined_after_bytes;
 
   /* Record deletion of the surrounding text that combines with
      the insertion.  This, together with recording the insertion,
@@ -1171,7 +1175,7 @@
      from the buffer and reinsert them.  */
 
   if (combined_after_bytes)
-    record_delete (PT, 1);
+    record_delete (PT, combined_after_bytes);
 
   if (combined_before_bytes)
     record_delete (PT - 1, 1);
@@ -1185,7 +1189,7 @@
 #endif
 
   GAP_SIZE -= outgoing_nbytes;
-  GPT += adjusted_nchars;
+  GPT += nchars - !!combined_before_bytes - !!combined_after_bytes;
   ZV += adjusted_nchars;
   Z += adjusted_nchars;
   GPT_BYTE += outgoing_nbytes;
@@ -1196,7 +1200,7 @@
   adjust_markers_for_insert (PT, PT_BYTE, PT + adjusted_nchars,
 			     PT_BYTE + outgoing_nbytes,
 			     combined_before_bytes, combined_after_bytes, 0);
-  adjust_point (adjusted_nchars + !!combined_after_bytes,
+  adjust_point (adjusted_nchars + combined_after_bytes,
 		outgoing_nbytes + combined_after_bytes);
 
   if (combined_after_bytes)
@@ -1237,10 +1241,10 @@
      int from, from_byte, to, to_byte, len, len_byte;
      int combined_before_bytes, combined_after_bytes;
 {
-  int adjusted_nchars = len - !!combined_before_bytes - !!combined_after_bytes;
+  int adjusted_nchars = len - !!combined_before_bytes - combined_after_bytes;
   record_insert (from - !!combined_before_bytes, len);
   if (from < PT)
-    adjust_point (len - (to - from) + !!combined_after_bytes,
+    adjust_point (len - (to - from) + combined_after_bytes,
 		  len_byte - (to_byte - from_byte) + combined_after_bytes);
 #ifdef USE_TEXT_PROPERTIES
   offset_intervals (current_buffer, PT, adjusted_nchars - (to - from));
@@ -1359,7 +1363,7 @@
 
   /* This is the net amount that Z will increase from this insertion.  */
   adjusted_inschars
-    = inschars - !!combined_before_bytes - !!combined_after_bytes;
+    = inschars - !!combined_before_bytes - combined_after_bytes;
 
   /* Record deletion of the surrounding text that combines with
      the insertion.  This, together with recording the insertion,
@@ -1369,7 +1373,7 @@
      from the buffer and reinsert them.  */
 
   if (combined_after_bytes)
-    record_delete (PT, 1);
+    record_delete (PT, combined_after_bytes);
 
   if (combined_before_bytes)
     record_delete (PT - 1, 1);
@@ -1381,7 +1385,7 @@
   /* Relocate point as if it were a marker.  */
   if (from < PT)
     adjust_point ((from + adjusted_inschars - (PT < to ? PT : to)
-		   + !!combined_after_bytes),
+		   + combined_after_bytes),
 		  (from_byte + insbytes
 		   - (PT_BYTE < to_byte ? PT_BYTE : to_byte)
 		   + combined_after_bytes));
@@ -1391,7 +1395,7 @@
 #endif
 
   GAP_SIZE -= insbytes;
-  GPT += adjusted_inschars;
+  GPT += inschars - !!combined_before_bytes - !!combined_after_bytes;
   ZV += adjusted_inschars;
   Z += adjusted_inschars;
   GPT_BYTE += insbytes;
@@ -1419,6 +1423,9 @@
   if (insbytes == 0)
     evaporate_overlays (from);
 
+  if (combined_after_bytes)
+    move_gap_both (GPT + 1, GPT_BYTE + combined_after_bytes);
+
   MODIFF++;
   UNGCPRO;