Mercurial > emacs
comparison src/editfns.c @ 1853:8866e36c0ed5
(Fcompare_buffer_substrings): New function.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 11 Feb 1993 06:00:51 +0000 |
parents | d505599b0438 |
children | 5a18c36181fa |
comparison
equal
deleted
inserted
replaced
1852:93cf37057957 | 1853:8866e36c0ed5 |
---|---|
814 /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */ | 814 /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */ |
815 graft_intervals_into_buffer (copy_intervals (bp->intervals, start, len), | 815 graft_intervals_into_buffer (copy_intervals (bp->intervals, start, len), |
816 opoint, bp); | 816 opoint, bp); |
817 | 817 |
818 return Qnil; | 818 return Qnil; |
819 } | |
820 | |
821 DEFUN ("compare-buffer-substrings", Fcompare_buffer_substrings, Scompare_buffer_substrings, | |
822 6, 6, 0, | |
823 "Compare two substrings of two buffers; return result as number.\n\ | |
824 the value is -N if first string is less after N-1 chars,\n\ | |
825 +N if first string is greater after N-1 chars, or 0 if strings match.\n\ | |
826 Each substring is represented as three arguments: BUFFER, START and END.\n\ | |
827 That makes six args in all, three for each substring.\n\n\ | |
828 The value of `case-fold-search' in the current buffer\n\ | |
829 determines whether case is significant or ignored.") | |
830 (buffer1, start1, end1, buffer2, start2, end2) | |
831 Lisp_Object buffer1, start1, end1, buffer2, start2, end2; | |
832 { | |
833 register int begp1, endp1, begp2, endp2, temp, len1, len2, length, i; | |
834 register struct buffer *bp1, *bp2; | |
835 register unsigned char *trt | |
836 = (!NILP (current_buffer->case_fold_search) | |
837 ? XSTRING (current_buffer->case_canon_table)->data : 0); | |
838 | |
839 /* Find the first buffer and its substring. */ | |
840 | |
841 if (NILP (buffer1)) | |
842 bp1 = current_buffer; | |
843 else | |
844 { | |
845 buffer1 = Fget_buffer (buffer1); | |
846 bp1 = XBUFFER (buffer1); | |
847 } | |
848 | |
849 if (NILP (start1)) | |
850 begp1 = BUF_BEGV (bp1); | |
851 else | |
852 { | |
853 CHECK_NUMBER_COERCE_MARKER (start1, 1); | |
854 begp1 = XINT (start1); | |
855 } | |
856 if (NILP (end1)) | |
857 endp1 = BUF_ZV (bp1); | |
858 else | |
859 { | |
860 CHECK_NUMBER_COERCE_MARKER (end1, 2); | |
861 endp1 = XINT (end1); | |
862 } | |
863 | |
864 if (begp1 > endp1) | |
865 temp = begp1, begp1 = endp1, endp1 = temp; | |
866 | |
867 if (!(BUF_BEGV (bp1) <= begp1 | |
868 && begp1 <= endp1 | |
869 && endp1 <= BUF_ZV (bp1))) | |
870 args_out_of_range (start1, end1); | |
871 | |
872 /* Likewise for second substring. */ | |
873 | |
874 if (NILP (buffer2)) | |
875 bp2 = current_buffer; | |
876 else | |
877 { | |
878 buffer2 = Fget_buffer (buffer2); | |
879 bp2 = XBUFFER (buffer2); | |
880 } | |
881 | |
882 if (NILP (start2)) | |
883 begp2 = BUF_BEGV (bp2); | |
884 else | |
885 { | |
886 CHECK_NUMBER_COERCE_MARKER (start2, 4); | |
887 begp2 = XINT (start2); | |
888 } | |
889 if (NILP (end2)) | |
890 endp2 = BUF_ZV (bp2); | |
891 else | |
892 { | |
893 CHECK_NUMBER_COERCE_MARKER (end2, 5); | |
894 endp2 = XINT (end2); | |
895 } | |
896 | |
897 if (begp2 > endp2) | |
898 temp = begp2, begp2 = endp2, endp2 = temp; | |
899 | |
900 if (!(BUF_BEGV (bp2) <= begp2 | |
901 && begp2 <= endp2 | |
902 && endp2 <= BUF_ZV (bp2))) | |
903 args_out_of_range (start2, end2); | |
904 | |
905 len1 = endp1 - begp1; | |
906 len2 = endp2 - begp2; | |
907 length = len1; | |
908 if (len2 < length) | |
909 length = len2; | |
910 | |
911 for (i = 0; i < length; i++) | |
912 { | |
913 int c1 = *BUF_CHAR_ADDRESS (bp1, begp1 + i); | |
914 int c2 = *BUF_CHAR_ADDRESS (bp2, begp2 + i); | |
915 if (trt) | |
916 { | |
917 c1 = trt[c1]; | |
918 c2 = trt[c2]; | |
919 } | |
920 if (c1 < c2) | |
921 return make_number (- 1 - i); | |
922 if (c1 > c2) | |
923 return make_number (i + 1); | |
924 } | |
925 | |
926 /* The strings match as far as they go. | |
927 If one is shorter, that one is less. */ | |
928 if (length < len1) | |
929 return make_number (length + 1); | |
930 else if (length < len2) | |
931 return make_number (- length - 1); | |
932 | |
933 /* Same length too => they are equal. */ | |
934 return make_number (0); | |
819 } | 935 } |
820 | 936 |
821 DEFUN ("subst-char-in-region", Fsubst_char_in_region, | 937 DEFUN ("subst-char-in-region", Fsubst_char_in_region, |
822 Ssubst_char_in_region, 4, 5, 0, | 938 Ssubst_char_in_region, 4, 5, 0, |
823 "From START to END, replace FROMCHAR with TOCHAR each time it occurs.\n\ | 939 "From START to END, replace FROMCHAR with TOCHAR each time it occurs.\n\ |
1317 defsubr (&Ssystem_name); | 1433 defsubr (&Ssystem_name); |
1318 defsubr (&Smessage); | 1434 defsubr (&Smessage); |
1319 defsubr (&Sformat); | 1435 defsubr (&Sformat); |
1320 | 1436 |
1321 defsubr (&Sinsert_buffer_substring); | 1437 defsubr (&Sinsert_buffer_substring); |
1438 defsubr (&Scompare_buffer_substrings); | |
1322 defsubr (&Ssubst_char_in_region); | 1439 defsubr (&Ssubst_char_in_region); |
1323 defsubr (&Stranslate_region); | 1440 defsubr (&Stranslate_region); |
1324 defsubr (&Sdelete_region); | 1441 defsubr (&Sdelete_region); |
1325 defsubr (&Swiden); | 1442 defsubr (&Swiden); |
1326 defsubr (&Snarrow_to_region); | 1443 defsubr (&Snarrow_to_region); |