Mercurial > emacs
comparison src/textprop.c @ 30242:6af73af0f1ef
(Fnext_single_char_property_change):
Made a subr (was `next_single_char_property_change').
Do more error checking, and cleanup limit behavior.
(Fprevious_single_char_property_change): New function.
(syms_of_textprop): Initialize new subrs.
author | Miles Bader <miles@gnu.org> |
---|---|
date | Sat, 15 Jul 2000 14:59:26 +0000 |
parents | 1b4cce65b60f |
children | 836d2e058c70 |
comparison
equal
deleted
inserted
replaced
30241:6d37357647d2 | 30242:6af73af0f1ef |
---|---|
674 } | 674 } |
675 return Fprevious_property_change (position, Qnil, temp); | 675 return Fprevious_property_change (position, Qnil, temp); |
676 } | 676 } |
677 | 677 |
678 | 678 |
679 /* Value is the position in OBJECT after POS where the value of | 679 DEFUN ("next-single-char-property-change", Fnext_single_char_property_change, |
680 property PROP changes. OBJECT must be a string or buffer. If | 680 Snext_single_char_property_change, 2, 4, 0, |
681 OBJECT is nil, use the current buffer. LIMIT if not nil limits the | 681 "Return the position of next text property or overlay change for a specific property.\n\ |
682 search. */ | 682 Scans characters forward from POSITION till it finds\n\ |
683 | 683 a change in the PROP property, then returns the position of the change.\n\ |
684 Lisp_Object | 684 The optional third argument OBJECT is the string or buffer to scan.\n\ |
685 next_single_char_property_change (pos, prop, object, limit) | 685 The property values are compared with `eq'.\n\ |
686 Lisp_Object prop, pos, object, limit; | 686 Return nil if the property is constant all the way to the end of OBJECT.\n\ |
687 If the value is non-nil, it is a position greater than POSITION, never equal.\n\n\ | |
688 If the optional fourth argument LIMIT is non-nil, don't search\n\ | |
689 past position LIMIT; return LIMIT if nothing is found before LIMIT.") | |
690 (position, prop, object, limit) | |
691 Lisp_Object prop, position, object, limit; | |
687 { | 692 { |
688 if (STRINGP (object)) | 693 if (STRINGP (object)) |
689 { | 694 { |
690 pos = Fnext_single_property_change (pos, prop, object, limit); | 695 position = Fnext_single_property_change (position, prop, object, limit); |
691 if (NILP (pos)) | 696 if (NILP (position)) |
692 { | 697 { |
693 if (NILP (limit)) | 698 if (NILP (limit)) |
694 pos = make_number (XSTRING (object)->size); | 699 position = make_number (XSTRING (object)->size); |
695 else | 700 else |
696 pos = limit; | 701 position = limit; |
697 } | 702 } |
698 } | 703 } |
699 else | 704 else |
700 { | 705 { |
701 Lisp_Object initial_value, value; | 706 Lisp_Object initial_value, value; |
702 int count = specpdl_ptr - specpdl; | 707 int count = specpdl_ptr - specpdl; |
703 | 708 |
704 if (!NILP (object)) | 709 if (! NILP (object)) |
705 CHECK_BUFFER (object, 0); | 710 CHECK_BUFFER (object, 0); |
706 | 711 |
707 if (BUFFERP (object) && current_buffer != XBUFFER (object)) | 712 if (BUFFERP (object) && current_buffer != XBUFFER (object)) |
708 { | 713 { |
709 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); | 714 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); |
710 Fset_buffer (object); | 715 Fset_buffer (object); |
711 } | 716 } |
712 | 717 |
713 initial_value = Fget_char_property (pos, prop, object); | 718 initial_value = Fget_char_property (position, prop, object); |
714 | 719 |
715 while (XFASTINT (pos) < XFASTINT (limit)) | 720 if (NILP (limit)) |
716 { | 721 XSETFASTINT (limit, BUF_ZV (current_buffer)); |
717 pos = Fnext_char_property_change (pos, limit); | 722 else |
718 value = Fget_char_property (pos, prop, object); | 723 CHECK_NUMBER_COERCE_MARKER (limit, 0); |
724 | |
725 for (;;) | |
726 { | |
727 position = Fnext_char_property_change (position, limit); | |
728 if (XFASTINT (position) >= XFASTINT (limit)) { | |
729 position = limit; | |
730 break; | |
731 } | |
732 | |
733 value = Fget_char_property (position, prop, object); | |
719 if (!EQ (value, initial_value)) | 734 if (!EQ (value, initial_value)) |
720 break; | 735 break; |
721 } | 736 } |
722 | 737 |
723 unbind_to (count, Qnil); | 738 unbind_to (count, Qnil); |
724 } | 739 } |
725 | 740 |
726 return pos; | 741 return position; |
727 } | 742 } |
728 | 743 |
729 | 744 DEFUN ("previous-single-char-property-change", |
745 Fprevious_single_char_property_change, | |
746 Sprevious_single_char_property_change, 2, 4, 0, | |
747 "Return the position of previous text property or overlay change for a specific property.\n\ | |
748 Scans characters backward from POSITION till it finds\n\ | |
749 a change in the PROP property, then returns the position of the change.\n\ | |
750 The optional third argument OBJECT is the string or buffer to scan.\n\ | |
751 The property values are compared with `eq'.\n\ | |
752 Return nil if the property is constant all the way to the start of OBJECT.\n\ | |
753 If the value is non-nil, it is a position less than POSITION, never equal.\n\n\ | |
754 If the optional fourth argument LIMIT is non-nil, don't search\n\ | |
755 back past position LIMIT; return LIMIT if nothing is found before LIMIT.") | |
756 (position, prop, object, limit) | |
757 Lisp_Object prop, position, object, limit; | |
758 { | |
759 if (STRINGP (object)) | |
760 { | |
761 position = Fprevious_single_property_change (position, prop, object, limit); | |
762 if (NILP (position)) | |
763 { | |
764 if (NILP (limit)) | |
765 position = make_number (XSTRING (object)->size); | |
766 else | |
767 position = limit; | |
768 } | |
769 } | |
770 else | |
771 { | |
772 Lisp_Object initial_value, value; | |
773 int count = specpdl_ptr - specpdl; | |
774 | |
775 if (! NILP (object)) | |
776 CHECK_BUFFER (object, 0); | |
777 | |
778 if (BUFFERP (object) && current_buffer != XBUFFER (object)) | |
779 { | |
780 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); | |
781 Fset_buffer (object); | |
782 } | |
783 | |
784 if (NILP (limit)) | |
785 XSETFASTINT (limit, BUF_BEGV (current_buffer)); | |
786 else | |
787 CHECK_NUMBER_COERCE_MARKER (limit, 0); | |
788 | |
789 initial_value = Fget_char_property (position, prop, object); | |
790 | |
791 for (;;) | |
792 { | |
793 position = Fprevious_char_property_change (position, limit); | |
794 if (XFASTINT (position) <= XFASTINT (limit)) { | |
795 position = limit; | |
796 break; | |
797 } | |
798 | |
799 value = Fget_char_property (position - 1, prop, object); | |
800 if (!EQ (value, initial_value)) | |
801 break; | |
802 } | |
803 | |
804 unbind_to (count, Qnil); | |
805 } | |
806 | |
807 return position; | |
808 } | |
730 | 809 |
731 DEFUN ("next-property-change", Fnext_property_change, | 810 DEFUN ("next-property-change", Fnext_property_change, |
732 Snext_property_change, 1, 3, 0, | 811 Snext_property_change, 1, 3, 0, |
733 "Return the position of next property change.\n\ | 812 "Return the position of next property change.\n\ |
734 Scans characters forward from POSITION in OBJECT till it finds\n\ | 813 Scans characters forward from POSITION in OBJECT till it finds\n\ |
1890 defsubr (&Stext_properties_at); | 1969 defsubr (&Stext_properties_at); |
1891 defsubr (&Sget_text_property); | 1970 defsubr (&Sget_text_property); |
1892 defsubr (&Sget_char_property); | 1971 defsubr (&Sget_char_property); |
1893 defsubr (&Snext_char_property_change); | 1972 defsubr (&Snext_char_property_change); |
1894 defsubr (&Sprevious_char_property_change); | 1973 defsubr (&Sprevious_char_property_change); |
1974 defsubr (&Snext_single_char_property_change); | |
1975 defsubr (&Sprevious_single_char_property_change); | |
1895 defsubr (&Snext_property_change); | 1976 defsubr (&Snext_property_change); |
1896 defsubr (&Snext_single_property_change); | 1977 defsubr (&Snext_single_property_change); |
1897 defsubr (&Sprevious_property_change); | 1978 defsubr (&Sprevious_property_change); |
1898 defsubr (&Sprevious_single_property_change); | 1979 defsubr (&Sprevious_single_property_change); |
1899 defsubr (&Sadd_text_properties); | 1980 defsubr (&Sadd_text_properties); |