diff options
| author | Richard M. Stallman | 2006-05-14 21:55:34 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2006-05-14 21:55:34 +0000 |
| commit | 85cc6738ed6d07b13ad749de80e47170a1df0d7a (patch) | |
| tree | 7abc2af8166d7deb5067cce3764a1c9e01d28cc1 /src | |
| parent | 1b0440ed041cd311eb7e59cbe6219f7ffa26a909 (diff) | |
| download | emacs-85cc6738ed6d07b13ad749de80e47170a1df0d7a.tar.gz emacs-85cc6738ed6d07b13ad749de80e47170a1df0d7a.zip | |
(Fnext_single_char_property_change)
(Fprevious_single_char_property_change):
Don't allow returning value beyond LIMIT in any cases.
(Fnext_char_property_change, Fprevious_char_property_change): Doc fix.
Diffstat (limited to 'src')
| -rw-r--r-- | src/textprop.c | 68 |
1 files changed, 44 insertions, 24 deletions
diff --git a/src/textprop.c b/src/textprop.c index e2f9c531735..87fa6742919 100644 --- a/src/textprop.c +++ b/src/textprop.c | |||
| @@ -717,10 +717,11 @@ DEFUN ("next-char-property-change", Fnext_char_property_change, | |||
| 717 | This scans characters forward in the current buffer from POSITION till | 717 | This scans characters forward in the current buffer from POSITION till |
| 718 | it finds a change in some text property, or the beginning or end of an | 718 | it finds a change in some text property, or the beginning or end of an |
| 719 | overlay, and returns the position of that. | 719 | overlay, and returns the position of that. |
| 720 | If none is found, the function returns (point-max). | 720 | If none is found up to (point-max), the function returns (point-max). |
| 721 | 721 | ||
| 722 | If the optional second argument LIMIT is non-nil, don't search | 722 | If the optional second argument LIMIT is non-nil, don't search |
| 723 | past position LIMIT; return LIMIT if nothing is found before LIMIT. */) | 723 | past position LIMIT; return LIMIT if nothing is found before LIMIT. |
| 724 | LIMIT is a no-op if it is greater than (point-max). */) | ||
| 724 | (position, limit) | 725 | (position, limit) |
| 725 | Lisp_Object position, limit; | 726 | Lisp_Object position, limit; |
| 726 | { | 727 | { |
| @@ -742,10 +743,11 @@ DEFUN ("previous-char-property-change", Fprevious_char_property_change, | |||
| 742 | Scans characters backward in the current buffer from POSITION till it | 743 | Scans characters backward in the current buffer from POSITION till it |
| 743 | finds a change in some text property, or the beginning or end of an | 744 | finds a change in some text property, or the beginning or end of an |
| 744 | overlay, and returns the position of that. | 745 | overlay, and returns the position of that. |
| 745 | If none is found, the function returns (point-max). | 746 | If none is found since (point-min), the function returns (point-min). |
| 746 | 747 | ||
| 747 | If the optional second argument LIMIT is non-nil, don't search | 748 | If the optional second argument LIMIT is non-nil, don't search |
| 748 | past position LIMIT; return LIMIT if nothing is found before LIMIT. */) | 749 | past position LIMIT; return LIMIT if nothing is found before LIMIT. |
| 750 | LIMIT is a no-op if it is less than (point-min). */) | ||
| 749 | (position, limit) | 751 | (position, limit) |
| 750 | Lisp_Object position, limit; | 752 | Lisp_Object position, limit; |
| 751 | { | 753 | { |
| @@ -771,6 +773,9 @@ If the optional third argument OBJECT is a buffer (or nil, which means | |||
| 771 | the current buffer), POSITION is a buffer position (integer or marker). | 773 | the current buffer), POSITION is a buffer position (integer or marker). |
| 772 | If OBJECT is a string, POSITION is a 0-based index into it. | 774 | If OBJECT is a string, POSITION is a 0-based index into it. |
| 773 | 775 | ||
| 776 | In a string, scan runs to the end of the string. | ||
| 777 | In a buffer, it runs to (point-max), and the value cannot exceed that. | ||
| 778 | |||
| 774 | The property values are compared with `eq'. | 779 | The property values are compared with `eq'. |
| 775 | If the property is constant all the way to the end of OBJECT, return the | 780 | If the property is constant all the way to the end of OBJECT, return the |
| 776 | last valid position in OBJECT. | 781 | last valid position in OBJECT. |
| @@ -812,22 +817,30 @@ past position LIMIT; return LIMIT if nothing is found before LIMIT. */) | |||
| 812 | initial_value = Fget_char_property (position, prop, object); | 817 | initial_value = Fget_char_property (position, prop, object); |
| 813 | 818 | ||
| 814 | if (NILP (limit)) | 819 | if (NILP (limit)) |
| 815 | XSETFASTINT (limit, BUF_ZV (current_buffer)); | 820 | XSETFASTINT (limit, ZV); |
| 816 | else | 821 | else |
| 817 | CHECK_NUMBER_COERCE_MARKER (limit); | 822 | CHECK_NUMBER_COERCE_MARKER (limit); |
| 818 | 823 | ||
| 819 | for (;;) | 824 | if (XFASTINT (position) >= XFASTINT (limit)) |
| 820 | { | 825 | { |
| 821 | position = Fnext_char_property_change (position, limit); | 826 | position = limit; |
| 822 | if (XFASTINT (position) >= XFASTINT (limit)) { | 827 | if (XFASTINT (position) > ZV) |
| 823 | position = limit; | 828 | XSETFASTINT (position, ZV); |
| 824 | break; | ||
| 825 | } | ||
| 826 | |||
| 827 | value = Fget_char_property (position, prop, object); | ||
| 828 | if (!EQ (value, initial_value)) | ||
| 829 | break; | ||
| 830 | } | 829 | } |
| 830 | else | ||
| 831 | while (1) | ||
| 832 | { | ||
| 833 | position = Fnext_char_property_change (position, limit); | ||
| 834 | if (XFASTINT (position) >= XFASTINT (limit)) | ||
| 835 | { | ||
| 836 | position = limit; | ||
| 837 | break; | ||
| 838 | } | ||
| 839 | |||
| 840 | value = Fget_char_property (position, prop, object); | ||
| 841 | if (!EQ (value, initial_value)) | ||
| 842 | break; | ||
| 843 | } | ||
| 831 | 844 | ||
| 832 | unbind_to (count, Qnil); | 845 | unbind_to (count, Qnil); |
| 833 | } | 846 | } |
| @@ -845,6 +858,9 @@ If the optional third argument OBJECT is a buffer (or nil, which means | |||
| 845 | the current buffer), POSITION is a buffer position (integer or marker). | 858 | the current buffer), POSITION is a buffer position (integer or marker). |
| 846 | If OBJECT is a string, POSITION is a 0-based index into it. | 859 | If OBJECT is a string, POSITION is a 0-based index into it. |
| 847 | 860 | ||
| 861 | In a string, scan runs to the start of the string. | ||
| 862 | In a buffer, it runs to (point-min), and the value cannot be less than that. | ||
| 863 | |||
| 848 | The property values are compared with `eq'. | 864 | The property values are compared with `eq'. |
| 849 | If the property is constant all the way to the start of OBJECT, return the | 865 | If the property is constant all the way to the start of OBJECT, return the |
| 850 | first valid position in OBJECT. | 866 | first valid position in OBJECT. |
| @@ -883,19 +899,23 @@ back past position LIMIT; return LIMIT if nothing is found before LIMIT. */) | |||
| 883 | CHECK_NUMBER_COERCE_MARKER (position); | 899 | CHECK_NUMBER_COERCE_MARKER (position); |
| 884 | 900 | ||
| 885 | if (NILP (limit)) | 901 | if (NILP (limit)) |
| 886 | XSETFASTINT (limit, BUF_BEGV (current_buffer)); | 902 | XSETFASTINT (limit, BEGV); |
| 887 | else | 903 | else |
| 888 | CHECK_NUMBER_COERCE_MARKER (limit); | 904 | CHECK_NUMBER_COERCE_MARKER (limit); |
| 889 | 905 | ||
| 890 | if (XFASTINT (position) <= XFASTINT (limit)) | 906 | if (XFASTINT (position) <= XFASTINT (limit)) |
| 891 | position = limit; | 907 | { |
| 908 | position = limit; | ||
| 909 | if (XFASTINT (position) < BEGV) | ||
| 910 | XSETFASTINT (position, BEGV); | ||
| 911 | } | ||
| 892 | else | 912 | else |
| 893 | { | 913 | { |
| 894 | Lisp_Object initial_value = | 914 | Lisp_Object initial_value |
| 895 | Fget_char_property (make_number (XFASTINT (position) - 1), | 915 | = Fget_char_property (make_number (XFASTINT (position) - 1), |
| 896 | prop, object); | 916 | prop, object); |
| 897 | 917 | ||
| 898 | for (;;) | 918 | while (1) |
| 899 | { | 919 | { |
| 900 | position = Fprevious_char_property_change (position, limit); | 920 | position = Fprevious_char_property_change (position, limit); |
| 901 | 921 | ||
| @@ -906,9 +926,9 @@ back past position LIMIT; return LIMIT if nothing is found before LIMIT. */) | |||
| 906 | } | 926 | } |
| 907 | else | 927 | else |
| 908 | { | 928 | { |
| 909 | Lisp_Object value = | 929 | Lisp_Object value |
| 910 | Fget_char_property (make_number (XFASTINT (position) - 1), | 930 | = Fget_char_property (make_number (XFASTINT (position) - 1), |
| 911 | prop, object); | 931 | prop, object); |
| 912 | 932 | ||
| 913 | if (!EQ (value, initial_value)) | 933 | if (!EQ (value, initial_value)) |
| 914 | break; | 934 | break; |