aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJim Blandy1993-07-18 06:24:25 +0000
committerJim Blandy1993-07-18 06:24:25 +0000
commit2bc7a79bdc1e9bbbe8d50583313068e7db272a97 (patch)
tree20ea7984b0eb9a21b05476583faa978dee96c643 /src
parentc02e3004672b0a09de44e55b083afc93b137a7a4 (diff)
downloademacs-2bc7a79bdc1e9bbbe8d50583313068e7db272a97.tar.gz
emacs-2bc7a79bdc1e9bbbe8d50583313068e7db272a97.zip
* intervals.c (split_interval_left, split_interval_right): Change
OFFSET argument of these functions to be origin 0, not origin 1. This is what all the callers currently want. * intervals.c, textprop.c: All callers changed. * intervals.c (graft_intervals_into_buffer): Properly compute length of buffer.
Diffstat (limited to 'src')
-rw-r--r--src/intervals.c53
1 files changed, 28 insertions, 25 deletions
diff --git a/src/intervals.c b/src/intervals.c
index c21078019e2..0922a074a96 100644
--- a/src/intervals.c
+++ b/src/intervals.c
@@ -62,7 +62,8 @@ create_root_interval (parent)
62 62
63 if (XTYPE (parent) == Lisp_Buffer) 63 if (XTYPE (parent) == Lisp_Buffer)
64 { 64 {
65 new->total_length = BUF_Z (XBUFFER (parent)) - 1; 65 new->total_length = (BUF_Z (XBUFFER (parent))
66 - BUF_BEG (XBUFFER (parent)));
66 XBUFFER (parent)->intervals = new; 67 XBUFFER (parent)->intervals = new;
67 } 68 }
68 else if (XTYPE (parent) == Lisp_String) 69 else if (XTYPE (parent) == Lisp_String)
@@ -347,9 +348,10 @@ rotate_left (interval)
347 return B; 348 return B;
348} 349}
349 350
350/* Split INTERVAL into two pieces, starting the second piece at character 351/* Split INTERVAL into two pieces, starting the second piece at
351 position OFFSET (counting from 1), relative to INTERVAL. The right-hand 352 character position OFFSET (counting from 0), relative to INTERVAL.
352 piece (second, lexicographically) is returned. 353 INTERVAL becomes the left-hand piece, and the right-hand piece
354 (second, lexicographically) is returned.
353 355
354 The size and position fields of the two intervals are set based upon 356 The size and position fields of the two intervals are set based upon
355 those of the original interval. The property list of the new interval 357 those of the original interval. The property list of the new interval
@@ -366,9 +368,9 @@ split_interval_right (interval, offset)
366{ 368{
367 INTERVAL new = make_interval (); 369 INTERVAL new = make_interval ();
368 int position = interval->position; 370 int position = interval->position;
369 int new_length = LENGTH (interval) - offset + 1; 371 int new_length = LENGTH (interval) - offset;
370 372
371 new->position = position + offset - 1; 373 new->position = position + offset;
372 new->parent = interval; 374 new->parent = interval;
373 375
374 if (LEAF_INTERVAL_P (interval) || NULL_RIGHT_CHILD (interval)) 376 if (LEAF_INTERVAL_P (interval) || NULL_RIGHT_CHILD (interval))
@@ -389,9 +391,10 @@ split_interval_right (interval, offset)
389 return new; 391 return new;
390} 392}
391 393
392/* Split INTERVAL into two pieces, starting the second piece at character 394/* Split INTERVAL into two pieces, starting the second piece at
393 position OFFSET (counting from 1), relative to INTERVAL. The left-hand 395 character position OFFSET (counting from 0), relative to INTERVAL.
394 piece (first, lexicographically) is returned. 396 INTERVAL becomes the right-hand piece, and the left-hand piece
397 (first, lexicographically) is returned.
395 398
396 The size and position fields of the two intervals are set based upon 399 The size and position fields of the two intervals are set based upon
397 those of the original interval. The property list of the new interval 400 those of the original interval. The property list of the new interval
@@ -408,10 +411,10 @@ split_interval_left (interval, offset)
408{ 411{
409 INTERVAL new = make_interval (); 412 INTERVAL new = make_interval ();
410 int position = interval->position; 413 int position = interval->position;
411 int new_length = offset - 1; 414 int new_length = offset;
412 415
413 new->position = interval->position; 416 new->position = interval->position;
414 interval->position = interval->position + offset - 1; 417 interval->position = interval->position + offset;
415 new->parent = interval; 418 new->parent = interval;
416 419
417 if (NULL_LEFT_CHILD (interval)) 420 if (NULL_LEFT_CHILD (interval))
@@ -1040,30 +1043,31 @@ make_new_interval (intervals, start, length)
1040 if (slot->position == start) 1043 if (slot->position == start)
1041 { 1044 {
1042 /* New right node. */ 1045 /* New right node. */
1043 split_interval_right (slot, length + 1); 1046 split_interval_right (slot, length);
1044 return slot; 1047 return slot;
1045 } 1048 }
1046 1049
1047 if (slot->position + LENGTH (slot) == start + length) 1050 if (slot->position + LENGTH (slot) == start + length)
1048 { 1051 {
1049 /* New left node. */ 1052 /* New left node. */
1050 split_interval_left (slot, LENGTH (slot) - length + 1); 1053 split_interval_left (slot, LENGTH (slot) - length);
1051 return slot; 1054 return slot;
1052 } 1055 }
1053 1056
1054 /* Convert interval SLOT into three intervals. */ 1057 /* Convert interval SLOT into three intervals. */
1055 split_interval_left (slot, start - slot->position + 1); 1058 split_interval_left (slot, start - slot->position);
1056 split_interval_right (slot, length + 1); 1059 split_interval_right (slot, length);
1057 return slot; 1060 return slot;
1058} 1061}
1059#endif 1062#endif
1060 1063
1061/* Insert the intervals of SOURCE into BUFFER at POSITION. 1064/* Insert the intervals of SOURCE into BUFFER at POSITION.
1062 1065
1063 This is used in insdel.c when inserting Lisp_Strings into 1066 This is used in insdel.c when inserting Lisp_Strings into the
1064 the buffer. The text corresponding to SOURCE is already in 1067 buffer. The text corresponding to SOURCE is already in the buffer
1065 the buffer when this is called. The intervals of new tree are 1068 when this is called. The intervals of new tree are a copy of those
1066 those belonging to the string being inserted; a copy is not made. 1069 belonging to the string being inserted; intervals are never
1070 shared.
1067 1071
1068 If the inserted text had no intervals associated, this function 1072 If the inserted text had no intervals associated, this function
1069 simply returns -- offset_intervals should handle placing the 1073 simply returns -- offset_intervals should handle placing the
@@ -1108,7 +1112,7 @@ graft_intervals_into_buffer (source, position, buffer)
1108 { 1112 {
1109 /* The inserted text constitutes the whole buffer, so 1113 /* The inserted text constitutes the whole buffer, so
1110 simply copy over the interval structure. */ 1114 simply copy over the interval structure. */
1111 if (BUF_Z (buffer) == TOTAL_LENGTH (source)) 1115 if ((BUF_Z (buffer) - BUF_BEG (buffer)) == TOTAL_LENGTH (source))
1112 { 1116 {
1113 buffer->intervals = reproduce_tree (source, tree->parent); 1117 buffer->intervals = reproduce_tree (source, tree->parent);
1114 /* Explicitly free the old tree here. */ 1118 /* Explicitly free the old tree here. */
@@ -1154,7 +1158,7 @@ graft_intervals_into_buffer (source, position, buffer)
1154 if (position > under->position) 1158 if (position > under->position)
1155 { 1159 {
1156 INTERVAL end_unchanged 1160 INTERVAL end_unchanged
1157 = split_interval_left (this, position - under->position + 1); 1161 = split_interval_left (this, position - under->position);
1158 copy_properties (under, end_unchanged); 1162 copy_properties (under, end_unchanged);
1159 under->position = position; 1163 under->position = position;
1160 prev = 0; 1164 prev = 0;
@@ -1173,9 +1177,8 @@ graft_intervals_into_buffer (source, position, buffer)
1173 which means it gets those properties. */ 1177 which means it gets those properties. */
1174 while (! NULL_INTERVAL_P (over)) 1178 while (! NULL_INTERVAL_P (over))
1175 { 1179 {
1176 position = LENGTH (over) + 1; 1180 if (LENGTH (over) + 1 < LENGTH (under))
1177 if (position < LENGTH (under)) 1181 this = split_interval_left (under, LENGTH (over));
1178 this = split_interval_left (under, position);
1179 else 1182 else
1180 this = under; 1183 this = under;
1181 copy_properties (over, this); 1184 copy_properties (over, this);
@@ -1619,7 +1622,7 @@ copy_intervals (tree, start, length)
1619 while (got < length) 1622 while (got < length)
1620 { 1623 {
1621 i = next_interval (i); 1624 i = next_interval (i);
1622 t = split_interval_right (t, prevlen + 1); 1625 t = split_interval_right (t, prevlen);
1623 copy_properties (i, t); 1626 copy_properties (i, t);
1624 prevlen = LENGTH (i); 1627 prevlen = LENGTH (i);
1625 got += prevlen; 1628 got += prevlen;