diff options
| author | Joseph Arceneaux | 1992-09-19 01:11:21 +0000 |
|---|---|---|
| committer | Joseph Arceneaux | 1992-09-19 01:11:21 +0000 |
| commit | 90ba40fc70903dbf33dc131c767a0e00c6fc1dd6 (patch) | |
| tree | e351f47d56422736f7b638aef7c85946448a72d5 /src/intervals.c | |
| parent | cfe158ab3463c1ed31e78719daaafaedb875bea1 (diff) | |
| download | emacs-90ba40fc70903dbf33dc131c767a0e00c6fc1dd6.tar.gz emacs-90ba40fc70903dbf33dc131c767a0e00c6fc1dd6.zip | |
entered into RCS
Diffstat (limited to 'src/intervals.c')
| -rw-r--r-- | src/intervals.c | 147 |
1 files changed, 105 insertions, 42 deletions
diff --git a/src/intervals.c b/src/intervals.c index 8a985199f8e..0a653748da9 100644 --- a/src/intervals.c +++ b/src/intervals.c | |||
| @@ -345,24 +345,28 @@ rotate_left (interval) | |||
| 345 | return B; | 345 | return B; |
| 346 | } | 346 | } |
| 347 | 347 | ||
| 348 | /* Split an interval into two. The second (RIGHT) half is returned as | 348 | /* Split INTERVAL into two pieces, starting the second piece at character |
| 349 | the new interval. The size and position of the interval being split are | 349 | position OFFSET (counting from 1), relative to INTERVAL. The right-hand |
| 350 | stored within it, having been found by find_interval (). The properties | 350 | piece (second, lexicographically) is returned. |
| 351 | are reset; it is up to the caller to do the right thing. | 351 | |
| 352 | The size and position fields of the two intervals are set based upon | ||
| 353 | those of the original interval. The property list of the new interval | ||
| 354 | is reset, thus it is up to the caller to do the right thing with the | ||
| 355 | result. | ||
| 352 | 356 | ||
| 353 | Note that this does not change the position of INTERVAL; if it is a root, | 357 | Note that this does not change the position of INTERVAL; if it is a root, |
| 354 | it is still a root after this operation. */ | 358 | it is still a root after this operation. */ |
| 355 | 359 | ||
| 356 | INTERVAL | 360 | INTERVAL |
| 357 | split_interval_right (interval, relative_position) | 361 | split_interval_right (interval, offset) |
| 358 | INTERVAL interval; | 362 | INTERVAL interval; |
| 359 | int relative_position; | 363 | int offset; |
| 360 | { | 364 | { |
| 361 | INTERVAL new = make_interval (); | 365 | INTERVAL new = make_interval (); |
| 362 | int position = interval->position; | 366 | int position = interval->position; |
| 363 | int new_length = LENGTH (interval) - relative_position + 1; | 367 | int new_length = LENGTH (interval) - offset + 1; |
| 364 | 368 | ||
| 365 | new->position = position + relative_position - 1; | 369 | new->position = position + offset - 1; |
| 366 | new->parent = interval; | 370 | new->parent = interval; |
| 367 | #if 0 | 371 | #if 0 |
| 368 | copy_properties (interval, new); | 372 | copy_properties (interval, new); |
| @@ -386,22 +390,26 @@ split_interval_right (interval, relative_position) | |||
| 386 | return new; | 390 | return new; |
| 387 | } | 391 | } |
| 388 | 392 | ||
| 389 | /* Split an interval into two. The first (LEFT) half is returned as | 393 | /* Split INTERVAL into two pieces, starting the second piece at character |
| 390 | the new interval. The size and position of the interval being split | 394 | position OFFSET (counting from 1), relative to INTERVAL. The left-hand |
| 391 | are stored within it, having been found by find_interval (). The | 395 | piece (first, lexicographically) is returned. |
| 392 | properties are reset; it is up to the caller to do the right thing. | ||
| 393 | 396 | ||
| 394 | Note that this does not change the position of INTERVAL in the tree; if it | 397 | The size and position fields of the two intervals are set based upon |
| 395 | is a root, it is still a root after this operation. */ | 398 | those of the original interval. The property list of the new interval |
| 399 | is reset, thus it is up to the caller to do the right thing with the | ||
| 400 | result. | ||
| 401 | |||
| 402 | Note that this does not change the position of INTERVAL; if it is a root, | ||
| 403 | it is still a root after this operation. */ | ||
| 396 | 404 | ||
| 397 | INTERVAL | 405 | INTERVAL |
| 398 | split_interval_left (interval, relative_position) | 406 | split_interval_left (interval, offset) |
| 399 | INTERVAL interval; | 407 | INTERVAL interval; |
| 400 | int relative_position; | 408 | int offset; |
| 401 | { | 409 | { |
| 402 | INTERVAL new = make_interval (); | 410 | INTERVAL new = make_interval (); |
| 403 | int position = interval->position; | 411 | int position = interval->position; |
| 404 | int new_length = relative_position - 1; | 412 | int new_length = offset - 1; |
| 405 | 413 | ||
| 406 | #if 0 | 414 | #if 0 |
| 407 | copy_properties (interval, new); | 415 | copy_properties (interval, new); |
| @@ -409,7 +417,7 @@ split_interval_left (interval, relative_position) | |||
| 409 | 417 | ||
| 410 | new->position = interval->position; | 418 | new->position = interval->position; |
| 411 | 419 | ||
| 412 | interval->position = interval->position + relative_position - 1; | 420 | interval->position = interval->position + offset - 1; |
| 413 | new->parent = interval; | 421 | new->parent = interval; |
| 414 | 422 | ||
| 415 | if (NULL_LEFT_CHILD (interval)) | 423 | if (NULL_LEFT_CHILD (interval)) |
| @@ -429,10 +437,15 @@ split_interval_left (interval, relative_position) | |||
| 429 | return new; | 437 | return new; |
| 430 | } | 438 | } |
| 431 | 439 | ||
| 432 | /* Find the interval containing POSITION in TREE. POSITION is relative | 440 | /* Find the interval containing text position POSITION in the text |
| 433 | to the start of TREE. */ | 441 | represented by the interval tree TREE. POSITION is relative to |
| 442 | the beginning of that text. | ||
| 434 | 443 | ||
| 435 | INTERVAL | 444 | The `position' field, which is a cache of an interval's position, |
| 445 | is updated in the interval found. Other functions (e.g., next_interval) | ||
| 446 | will update this cache based on the result of find_interval. */ | ||
| 447 | |||
| 448 | INLINE INTERVAL | ||
| 436 | find_interval (tree, position) | 449 | find_interval (tree, position) |
| 437 | register INTERVAL tree; | 450 | register INTERVAL tree; |
| 438 | register int position; | 451 | register int position; |
| @@ -471,10 +484,8 @@ find_interval (tree, position) | |||
| 471 | } | 484 | } |
| 472 | 485 | ||
| 473 | /* Find the succeeding interval (lexicographically) to INTERVAL. | 486 | /* Find the succeeding interval (lexicographically) to INTERVAL. |
| 474 | Sets the `position' field based on that of INTERVAL. | 487 | Sets the `position' field based on that of INTERVAL (see |
| 475 | 488 | find_interval). */ | |
| 476 | Note that those values are only correct if they were also correct | ||
| 477 | in INTERVAL. */ | ||
| 478 | 489 | ||
| 479 | INTERVAL | 490 | INTERVAL |
| 480 | next_interval (interval) | 491 | next_interval (interval) |
| @@ -513,10 +524,8 @@ next_interval (interval) | |||
| 513 | } | 524 | } |
| 514 | 525 | ||
| 515 | /* Find the preceding interval (lexicographically) to INTERVAL. | 526 | /* Find the preceding interval (lexicographically) to INTERVAL. |
| 516 | Sets the `position' field based on that of INTERVAL. | 527 | Sets the `position' field based on that of INTERVAL (see |
| 517 | 528 | find_interval). */ | |
| 518 | Note that those values are only correct if they were also correct | ||
| 519 | in INTERVAL. */ | ||
| 520 | 529 | ||
| 521 | INTERVAL | 530 | INTERVAL |
| 522 | previous_interval (interval) | 531 | previous_interval (interval) |
| @@ -554,6 +563,7 @@ previous_interval (interval) | |||
| 554 | return NULL_INTERVAL; | 563 | return NULL_INTERVAL; |
| 555 | } | 564 | } |
| 556 | 565 | ||
| 566 | #if 0 | ||
| 557 | /* Traverse a path down the interval tree TREE to the interval | 567 | /* Traverse a path down the interval tree TREE to the interval |
| 558 | containing POSITION, adjusting all nodes on the path for | 568 | containing POSITION, adjusting all nodes on the path for |
| 559 | an addition of LENGTH characters. Insertion between two intervals | 569 | an addition of LENGTH characters. Insertion between two intervals |
| @@ -610,6 +620,59 @@ adjust_intervals_for_insertion (tree, position, length) | |||
| 610 | } | 620 | } |
| 611 | } | 621 | } |
| 612 | } | 622 | } |
| 623 | #endif | ||
| 624 | |||
| 625 | /* Effect an adjustment corresponding to the addition of LENGTH characters | ||
| 626 | of text. Do this by finding the interval containing POSITION in the | ||
| 627 | interval tree TREE, and then adjusting all of it's ancestors by adding | ||
| 628 | LENGTH to them. | ||
| 629 | |||
| 630 | If POSITION is the first character of an interval, meaning that point | ||
| 631 | is actually between the two intervals, make the new text belong to | ||
| 632 | the interval which is "sticky". | ||
| 633 | |||
| 634 | If both intervals are "stick", then make them belong to the left-most | ||
| 635 | interval. Another possibility would be to create a new interval for | ||
| 636 | this text, and make it have the merged properties of both ends. */ | ||
| 637 | |||
| 638 | static INTERVAL | ||
| 639 | adjust_intervals_for_insertion (tree, position, length) | ||
| 640 | INTERVAL tree; | ||
| 641 | int position, length; | ||
| 642 | { | ||
| 643 | register INTERVAL i; | ||
| 644 | |||
| 645 | if (TOTAL_LENGTH (tree) == 0) /* Paranoia */ | ||
| 646 | abort (); | ||
| 647 | |||
| 648 | /* If inserting at point-max of a buffer, that position | ||
| 649 | will be out of range. */ | ||
| 650 | if (position > TOTAL_LENGTH (tree)) | ||
| 651 | position = TOTAL_LENGTH (tree); | ||
| 652 | |||
| 653 | i = find_interval (tree, position); | ||
| 654 | /* If we are positioned between intervals, check the stickiness of | ||
| 655 | both of them. */ | ||
| 656 | if (position == i->position | ||
| 657 | && position != 1) | ||
| 658 | { | ||
| 659 | register prev = previous_interval (i); | ||
| 660 | |||
| 661 | /* If both intervals are sticky here, then default to the | ||
| 662 | left-most one. But perhaps we should create a new | ||
| 663 | interval here instead... */ | ||
| 664 | if (END_STICKY (prev)) | ||
| 665 | i = prev; | ||
| 666 | } | ||
| 667 | |||
| 668 | while (! NULL_INTERVAL_P (i)) | ||
| 669 | { | ||
| 670 | i->total_length += length; | ||
| 671 | i = i->parent | ||
| 672 | } | ||
| 673 | |||
| 674 | return tree; | ||
| 675 | } | ||
| 613 | 676 | ||
| 614 | /* Merge interval I with its lexicographic successor. Note that | 677 | /* Merge interval I with its lexicographic successor. Note that |
| 615 | this does not deal with the properties, or delete I. */ | 678 | this does not deal with the properties, or delete I. */ |
| @@ -697,8 +760,8 @@ merge_interval_left (i) | |||
| 697 | return NULL_INTERVAL; | 760 | return NULL_INTERVAL; |
| 698 | } | 761 | } |
| 699 | 762 | ||
| 700 | /* Delete an interval node from its btree by merging its subtrees | 763 | /* Delete an node I from its interval tree by merging its subtrees |
| 701 | into one subtree which is returned. Caller is responsible for | 764 | into one subtree which is then returned. Caller is responsible for |
| 702 | storing the resulting subtree into its parent. */ | 765 | storing the resulting subtree into its parent. */ |
| 703 | 766 | ||
| 704 | static INTERVAL | 767 | static INTERVAL |
| @@ -1002,7 +1065,7 @@ map_intervals (source, destination, position) | |||
| 1002 | 1065 | ||
| 1003 | If the inserted text had no intervals associated, this function | 1066 | If the inserted text had no intervals associated, this function |
| 1004 | simply returns -- offset_intervals should handle placing the | 1067 | simply returns -- offset_intervals should handle placing the |
| 1005 | text in the correct interval, depending on the hungry bits. | 1068 | text in the correct interval, depending on the sticky bits. |
| 1006 | 1069 | ||
| 1007 | If the inserted text had properties (intervals), then there are two | 1070 | If the inserted text had properties (intervals), then there are two |
| 1008 | cases -- either insertion happened in the middle of some interval, | 1071 | cases -- either insertion happened in the middle of some interval, |
| @@ -1015,12 +1078,12 @@ map_intervals (source, destination, position) | |||
| 1015 | of the text into which it was inserted. | 1078 | of the text into which it was inserted. |
| 1016 | 1079 | ||
| 1017 | If the text goes between two intervals, then if neither interval | 1080 | If the text goes between two intervals, then if neither interval |
| 1018 | had its appropriate hungry property set (front_hungry, rear_hungry), | 1081 | had its appropriate sticky property set (front_sticky, rear_sticky), |
| 1019 | the new text has only its properties. If one of the hungry properties | 1082 | the new text has only its properties. If one of the sticky properties |
| 1020 | is set, then the new text "sticks" to that region and its properties | 1083 | is set, then the new text "sticks" to that region and its properties |
| 1021 | depend on merging as above. If both the preceding and succeding | 1084 | depend on merging as above. If both the preceding and succeding |
| 1022 | intervals to the new text are "hungry", then the new text retains | 1085 | intervals to the new text are "sticky", then the new text retains |
| 1023 | only its properties, as if neither hungry property were set. Perhaps | 1086 | only its properties, as if neither sticky property were set. Perhaps |
| 1024 | we should consider merging all three sets of properties onto the new | 1087 | we should consider merging all three sets of properties onto the new |
| 1025 | text... */ | 1088 | text... */ |
| 1026 | 1089 | ||
| @@ -1088,7 +1151,7 @@ graft_intervals_into_buffer (new_tree, position, b) | |||
| 1088 | /* First interval -- none precede it. */ | 1151 | /* First interval -- none precede it. */ |
| 1089 | if (position == 1) | 1152 | if (position == 1) |
| 1090 | { | 1153 | { |
| 1091 | if (! under->front_hungry) | 1154 | if (! FRONT_STICKY (under)) |
| 1092 | /* The inserted string keeps its own properties. */ | 1155 | /* The inserted string keeps its own properties. */ |
| 1093 | while (! NULL_INTERVAL_P (over)) | 1156 | while (! NULL_INTERVAL_P (over)) |
| 1094 | { | 1157 | { |
| @@ -1115,10 +1178,10 @@ graft_intervals_into_buffer (new_tree, position, b) | |||
| 1115 | if (NULL_INTERVAL_P (prev)) | 1178 | if (NULL_INTERVAL_P (prev)) |
| 1116 | abort (); | 1179 | abort (); |
| 1117 | 1180 | ||
| 1118 | if (prev->rear_hungry) | 1181 | if (END_STICKY (prev)) |
| 1119 | { | 1182 | { |
| 1120 | if (under->front_hungry) | 1183 | if (FRONT_STICKY (under)) |
| 1121 | /* The intervals go inbetween as the two hungry | 1184 | /* The intervals go inbetween as the two sticky |
| 1122 | properties cancel each other. Should we change | 1185 | properties cancel each other. Should we change |
| 1123 | this policy? */ | 1186 | this policy? */ |
| 1124 | while (! NULL_INTERVAL_P (over)) | 1187 | while (! NULL_INTERVAL_P (over)) |
| @@ -1142,7 +1205,7 @@ graft_intervals_into_buffer (new_tree, position, b) | |||
| 1142 | } | 1205 | } |
| 1143 | else | 1206 | else |
| 1144 | { | 1207 | { |
| 1145 | if (under->front_hungry) | 1208 | if (FRONT_STICKY (under)) |
| 1146 | /* The intervals stick to under */ | 1209 | /* The intervals stick to under */ |
| 1147 | while (! NULL_INTERVAL_P (over)) | 1210 | while (! NULL_INTERVAL_P (over)) |
| 1148 | { | 1211 | { |
| @@ -1334,7 +1397,7 @@ verify_interval_modification (buf, start, end) | |||
| 1334 | abort (); | 1397 | abort (); |
| 1335 | 1398 | ||
| 1336 | i = find_interval (intervals, start - 1); | 1399 | i = find_interval (intervals, start - 1); |
| 1337 | if (! END_HUNGRY_P (i)) | 1400 | if (! END_STICKY_P (i)) |
| 1338 | return; | 1401 | return; |
| 1339 | } | 1402 | } |
| 1340 | else | 1403 | else |