Mercurial > emacs
comparison src/intervals.c @ 47942:080b4586492b
Fix typo in comment.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Fri, 18 Oct 2002 10:09:43 +0000 |
parents | 48b292c584a6 |
children | dc1f6aa29285 d7ddb3e565de |
comparison
equal
deleted
inserted
replaced
47941:df5fb1f2c113 | 47942:080b4586492b |
---|---|
345 return B; | 345 return B; |
346 } | 346 } |
347 | 347 |
348 /* Assuming that a right child exists, perform the following operation: | 348 /* Assuming that a right child exists, perform the following operation: |
349 | 349 |
350 A B | 350 A B |
351 / \ / \ | 351 / \ / \ |
352 B => A | 352 B => A |
353 / \ / \ | 353 / \ / \ |
354 c c | 354 c c |
355 */ | 355 */ |
356 | 356 |
357 static INLINE INTERVAL | 357 static INLINE INTERVAL |
358 rotate_left (interval) | 358 rotate_left (interval) |
522 SET_INTERVAL_PARENT (interval->right, new); | 522 SET_INTERVAL_PARENT (interval->right, new); |
523 interval->right = new; | 523 interval->right = new; |
524 new->total_length = new_length + new->right->total_length; | 524 new->total_length = new_length + new->right->total_length; |
525 balance_an_interval (new); | 525 balance_an_interval (new); |
526 } | 526 } |
527 | 527 |
528 balance_possible_root_interval (interval); | 528 balance_possible_root_interval (interval); |
529 | 529 |
530 return new; | 530 return new; |
531 } | 531 } |
532 | 532 |
567 SET_INTERVAL_PARENT (new->left, new); | 567 SET_INTERVAL_PARENT (new->left, new); |
568 interval->left = new; | 568 interval->left = new; |
569 new->total_length = new_length + new->left->total_length; | 569 new->total_length = new_length + new->left->total_length; |
570 balance_an_interval (new); | 570 balance_an_interval (new); |
571 } | 571 } |
572 | 572 |
573 balance_possible_root_interval (interval); | 573 balance_possible_root_interval (interval); |
574 | 574 |
575 return new; | 575 return new; |
576 } | 576 } |
577 | 577 |
752 int pos; | 752 int pos; |
753 { | 753 { |
754 if (NULL_INTERVAL_P (i)) | 754 if (NULL_INTERVAL_P (i)) |
755 return NULL_INTERVAL; | 755 return NULL_INTERVAL; |
756 | 756 |
757 while (1) | 757 while (1) |
758 { | 758 { |
759 if (pos < i->position) | 759 if (pos < i->position) |
760 { | 760 { |
761 /* Move left. */ | 761 /* Move left. */ |
762 if (pos >= i->position - TOTAL_LENGTH (i->left)) | 762 if (pos >= i->position - TOTAL_LENGTH (i->left)) |
763 { | 763 { |
764 i->left->position = i->position - TOTAL_LENGTH (i->left) | 764 i->left->position = i->position - TOTAL_LENGTH (i->left) |
765 + LEFT_TOTAL_LENGTH (i->left); | 765 + LEFT_TOTAL_LENGTH (i->left); |
766 i = i->left; /* Move to the left child */ | 766 i = i->left; /* Move to the left child */ |
767 } | 767 } |
768 else if (NULL_PARENT (i)) | 768 else if (NULL_PARENT (i)) |
769 error ("Point before start of properties"); | 769 error ("Point before start of properties"); |
770 else | 770 else |
771 i = INTERVAL_PARENT (i); | 771 i = INTERVAL_PARENT (i); |
772 continue; | 772 continue; |
773 } | 773 } |
774 else if (pos >= INTERVAL_LAST_POS (i)) | 774 else if (pos >= INTERVAL_LAST_POS (i)) |
775 { | 775 { |
776 /* Move right. */ | 776 /* Move right. */ |
777 if (pos < INTERVAL_LAST_POS (i) + TOTAL_LENGTH (i->right)) | 777 if (pos < INTERVAL_LAST_POS (i) + TOTAL_LENGTH (i->right)) |
778 { | 778 { |
779 i->right->position = INTERVAL_LAST_POS (i) + | 779 i->right->position = INTERVAL_LAST_POS (i) + |
780 LEFT_TOTAL_LENGTH (i->right); | 780 LEFT_TOTAL_LENGTH (i->right); |
781 i = i->right; /* Move to the right child */ | 781 i = i->right; /* Move to the right child */ |
782 } | 782 } |
783 else if (NULL_PARENT (i)) | 783 else if (NULL_PARENT (i)) |
784 error ("Point after end of properties"); | 784 error ("Point after end of properties"); |
785 else | 785 else |
786 i = INTERVAL_PARENT (i); | 786 i = INTERVAL_PARENT (i); |
787 continue; | 787 continue; |
788 } | 788 } |
789 else | 789 else |
790 return i; | 790 return i; |
791 } | 791 } |
792 } | 792 } |
793 | 793 |
794 | 794 |
872 register INTERVAL i; | 872 register INTERVAL i; |
873 register INTERVAL temp; | 873 register INTERVAL temp; |
874 int eobp = 0; | 874 int eobp = 0; |
875 Lisp_Object parent; | 875 Lisp_Object parent; |
876 int offset; | 876 int offset; |
877 | 877 |
878 if (TOTAL_LENGTH (tree) == 0) /* Paranoia */ | 878 if (TOTAL_LENGTH (tree) == 0) /* Paranoia */ |
879 abort (); | 879 abort (); |
880 | 880 |
881 GET_INTERVAL_OBJECT (parent, tree); | 881 GET_INTERVAL_OBJECT (parent, tree); |
882 offset = (BUFFERP (parent) ? BUF_BEG (XBUFFER (parent)) : 0); | 882 offset = (BUFFERP (parent) ? BUF_BEG (XBUFFER (parent)) : 0); |
987 for (temp = prev ? prev : i; temp; temp = INTERVAL_PARENT_OR_NULL (temp)) | 987 for (temp = prev ? prev : i; temp; temp = INTERVAL_PARENT_OR_NULL (temp)) |
988 { | 988 { |
989 temp->total_length += length; | 989 temp->total_length += length; |
990 temp = balance_possible_root_interval (temp); | 990 temp = balance_possible_root_interval (temp); |
991 } | 991 } |
992 | 992 |
993 /* If at least one interval has sticky properties, | 993 /* If at least one interval has sticky properties, |
994 we check the stickiness property by property. | 994 we check the stickiness property by property. |
995 | 995 |
996 Originally, the if condition here was this: | 996 Originally, the if condition here was this: |
997 (END_NONSTICKY_P (prev) || FRONT_STICKY_P (i)) | 997 (END_NONSTICKY_P (prev) || FRONT_STICKY_P (i)) |
1044 { | 1044 { |
1045 temp->total_length += length; | 1045 temp->total_length += length; |
1046 temp = balance_possible_root_interval (temp); | 1046 temp = balance_possible_root_interval (temp); |
1047 } | 1047 } |
1048 } | 1048 } |
1049 | 1049 |
1050 return tree; | 1050 return tree; |
1051 } | 1051 } |
1052 | 1052 |
1053 /* Any property might be front-sticky on the left, rear-sticky on the left, | 1053 /* Any property might be front-sticky on the left, rear-sticky on the left, |
1054 front-sticky on the right, or rear-sticky on the right; the 16 combinations | 1054 front-sticky on the right, or rear-sticky on the right; the 16 combinations |
1210 if (! NILP (rear)) | 1210 if (! NILP (rear)) |
1211 props = Fcons (Qrear_nonsticky, Fcons (Fnreverse (rear), props)); | 1211 props = Fcons (Qrear_nonsticky, Fcons (Fnreverse (rear), props)); |
1212 | 1212 |
1213 cat = textget (props, Qcategory); | 1213 cat = textget (props, Qcategory); |
1214 if (! NILP (front) | 1214 if (! NILP (front) |
1215 && | 1215 && |
1216 /* If we have inherited a front-stick category property that is t, | 1216 /* If we have inherited a front-stick category property that is t, |
1217 we don't need to set up a detailed one. */ | 1217 we don't need to set up a detailed one. */ |
1218 ! (! NILP (cat) && SYMBOLP (cat) | 1218 ! (! NILP (cat) && SYMBOLP (cat) |
1219 && EQ (Fget (cat, Qfront_sticky), Qt))) | 1219 && EQ (Fget (cat, Qfront_sticky), Qt))) |
1220 props = Fcons (Qfront_sticky, Fcons (Fnreverse (front), props)); | 1220 props = Fcons (Qfront_sticky, Fcons (Fnreverse (front), props)); |
1221 return props; | 1221 return props; |
1222 } | 1222 } |
1223 | 1223 |
1224 | 1224 |
1225 /* Delete an node I from its interval tree by merging its subtrees | 1225 /* Delete a node I from its interval tree by merging its subtrees |
1226 into one subtree which is then returned. Caller is responsible for | 1226 into one subtree which is then returned. Caller is responsible for |
1227 storing the resulting subtree into its parent. */ | 1227 storing the resulting subtree into its parent. */ |
1228 | 1228 |
1229 static INTERVAL | 1229 static INTERVAL |
1230 delete_node (i) | 1230 delete_node (i) |
1349 } | 1349 } |
1350 /* Here -- this node. */ | 1350 /* Here -- this node. */ |
1351 else | 1351 else |
1352 { | 1352 { |
1353 /* How much can we delete from this interval? */ | 1353 /* How much can we delete from this interval? */ |
1354 int my_amount = ((tree->total_length | 1354 int my_amount = ((tree->total_length |
1355 - RIGHT_TOTAL_LENGTH (tree)) | 1355 - RIGHT_TOTAL_LENGTH (tree)) |
1356 - relative_position); | 1356 - relative_position); |
1357 | 1357 |
1358 if (amount > my_amount) | 1358 if (amount > my_amount) |
1359 amount = my_amount; | 1359 amount = my_amount; |
1360 | 1360 |
1361 tree->total_length -= amount; | 1361 tree->total_length -= amount; |
1362 if (LENGTH (tree) == 0) | 1362 if (LENGTH (tree) == 0) |
1363 delete_interval (tree); | 1363 delete_interval (tree); |
1364 | 1364 |
1365 return amount; | 1365 return amount; |
1366 } | 1366 } |
1367 | 1367 |
1368 /* Never reach here. */ | 1368 /* Never reach here. */ |
1369 } | 1369 } |
1778 /* The inserted text "sticks" to the interval `under', | 1778 /* The inserted text "sticks" to the interval `under', |
1779 which means it gets those properties. | 1779 which means it gets those properties. |
1780 The properties of under are the result of | 1780 The properties of under are the result of |
1781 adjust_intervals_for_insertion, so stickiness has | 1781 adjust_intervals_for_insertion, so stickiness has |
1782 already been taken care of. */ | 1782 already been taken care of. */ |
1783 | 1783 |
1784 while (! NULL_INTERVAL_P (over)) | 1784 while (! NULL_INTERVAL_P (over)) |
1785 { | 1785 { |
1786 if (LENGTH (over) < LENGTH (under)) | 1786 if (LENGTH (over) < LENGTH (under)) |
1787 { | 1787 { |
1788 this = split_interval_left (under, LENGTH (over)); | 1788 this = split_interval_left (under, LENGTH (over)); |
1803 return; | 1803 return; |
1804 } | 1804 } |
1805 | 1805 |
1806 /* Get the value of property PROP from PLIST, | 1806 /* Get the value of property PROP from PLIST, |
1807 which is the plist of an interval. | 1807 which is the plist of an interval. |
1808 We check for direct properties, for categories with property PROP, | 1808 We check for direct properties, for categories with property PROP, |
1809 and for PROP appearing on the default-text-properties list. */ | 1809 and for PROP appearing on the default-text-properties list. */ |
1810 | 1810 |
1811 Lisp_Object | 1811 Lisp_Object |
1812 textget (plist, prop) | 1812 textget (plist, prop) |
1813 Lisp_Object plist; | 1813 Lisp_Object plist; |
1885 | 1885 |
1886 BUF_PT_BYTE (buffer) = bytepos; | 1886 BUF_PT_BYTE (buffer) = bytepos; |
1887 BUF_PT (buffer) = charpos; | 1887 BUF_PT (buffer) = charpos; |
1888 } | 1888 } |
1889 | 1889 |
1890 /* Set point in BUFFER to CHARPOS. If the target position is | 1890 /* Set point in BUFFER to CHARPOS. If the target position is |
1891 before an intangible character, move to an ok place. */ | 1891 before an intangible character, move to an ok place. */ |
1892 | 1892 |
1893 void | 1893 void |
1894 set_point (buffer, charpos) | 1894 set_point (buffer, charpos) |
1895 register struct buffer *buffer; | 1895 register struct buffer *buffer; |
1905 then intangibility is required as well as invisibleness. | 1905 then intangibility is required as well as invisibleness. |
1906 | 1906 |
1907 TEST_OFFS should be either 0 or -1, and ADJ should be either 1 or -1. | 1907 TEST_OFFS should be either 0 or -1, and ADJ should be either 1 or -1. |
1908 | 1908 |
1909 Note that `stickiness' is determined by overlay marker insertion types, | 1909 Note that `stickiness' is determined by overlay marker insertion types, |
1910 if the invisible property comes from an overlay. */ | 1910 if the invisible property comes from an overlay. */ |
1911 | 1911 |
1912 static int | 1912 static int |
1913 adjust_for_invis_intang (pos, test_offs, adj, test_intang) | 1913 adjust_for_invis_intang (pos, test_offs, adj, test_intang) |
1914 int pos, test_offs, adj, test_intang; | 1914 int pos, test_offs, adj, test_intang; |
1915 { | 1915 { |
1943 | 1943 |
1944 return pos; | 1944 return pos; |
1945 } | 1945 } |
1946 | 1946 |
1947 /* Set point in BUFFER to CHARPOS, which corresponds to byte | 1947 /* Set point in BUFFER to CHARPOS, which corresponds to byte |
1948 position BYTEPOS. If the target position is | 1948 position BYTEPOS. If the target position is |
1949 before an intangible character, move to an ok place. */ | 1949 before an intangible character, move to an ok place. */ |
1950 | 1950 |
1951 void | 1951 void |
1952 set_point_both (buffer, charpos, bytepos) | 1952 set_point_both (buffer, charpos, bytepos) |
1953 register struct buffer *buffer; | 1953 register struct buffer *buffer; |
2216 intangible_propval)) | 2216 intangible_propval)) |
2217 pos = Fnext_char_property_change (pos, Qnil); | 2217 pos = Fnext_char_property_change (pos, Qnil); |
2218 | 2218 |
2219 } | 2219 } |
2220 | 2220 |
2221 /* If the whole stretch between PT and POSITION isn't intangible, | 2221 /* If the whole stretch between PT and POSITION isn't intangible, |
2222 try moving to POSITION (which means we actually move farther | 2222 try moving to POSITION (which means we actually move farther |
2223 if POSITION is inside of intangible text). */ | 2223 if POSITION is inside of intangible text). */ |
2224 | 2224 |
2225 if (XINT (pos) != PT) | 2225 if (XINT (pos) != PT) |
2226 SET_PT (position); | 2226 SET_PT (position); |
2263 && EQ (*val, textget (prev->plist, prop))) | 2263 && EQ (*val, textget (prev->plist, prop))) |
2264 i = prev, prev = previous_interval (prev); | 2264 i = prev, prev = previous_interval (prev); |
2265 *start = i->position; | 2265 *start = i->position; |
2266 | 2266 |
2267 next = next_interval (i); | 2267 next = next_interval (i); |
2268 while (! NULL_INTERVAL_P (next) | 2268 while (! NULL_INTERVAL_P (next) |
2269 && EQ (*val, textget (next->plist, prop))) | 2269 && EQ (*val, textget (next->plist, prop))) |
2270 i = next, next = next_interval (next); | 2270 i = next, next = next_interval (next); |
2271 *end = i->position + LENGTH (i); | 2271 *end = i->position + LENGTH (i); |
2272 | 2272 |
2273 return 1; | 2273 return 1; |