aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard M. Stallman1998-04-20 03:53:06 +0000
committerRichard M. Stallman1998-04-20 03:53:06 +0000
commit69f4ef200916c22d459c1da9c9857f8397b78bab (patch)
tree0a92ad2ccd5db76fc73ef80f1f76e08e5fd401ca /src
parent0e1e9f8da50e654891b498d5f3b601857d2093cc (diff)
downloademacs-69f4ef200916c22d459c1da9c9857f8397b78bab.tar.gz
emacs-69f4ef200916c22d459c1da9c9857f8397b78bab.zip
(Ftry_completion): Use Fcompare_strings.
(Fall_completions, Fminibuffer_complete_word): Likewise.
Diffstat (limited to 'src')
-rw-r--r--src/minibuf.c125
1 files changed, 82 insertions, 43 deletions
diff --git a/src/minibuf.c b/src/minibuf.c
index 91230e6f732..83c35accb6d 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -955,8 +955,11 @@ or the symbol from the obarray.")
955 955
956 if (STRINGP (eltstring) 956 if (STRINGP (eltstring)
957 && STRING_BYTES (XSTRING (string)) <= STRING_BYTES (XSTRING (eltstring)) 957 && STRING_BYTES (XSTRING (string)) <= STRING_BYTES (XSTRING (eltstring))
958 && 0 > scmp (XSTRING (eltstring)->data, XSTRING (string)->data, 958 && (tem = Fcompare_strings (eltstring, make_number (0),
959 STRING_BYTES (XSTRING (string)))) 959 make_number (XSTRING (string)->size),
960 string, make_number (0), Qnil,
961 completion_ignore_case ?Qt : Qnil),
962 EQ (Qt, tem)))
960 { 963 {
961 /* Yes. */ 964 /* Yes. */
962 Lisp_Object regexps; 965 Lisp_Object regexps;
@@ -996,14 +999,23 @@ or the symbol from the obarray.")
996 if (NILP (bestmatch)) 999 if (NILP (bestmatch))
997 { 1000 {
998 bestmatch = eltstring; 1001 bestmatch = eltstring;
999 bestmatchsize = STRING_BYTES (XSTRING (eltstring)); 1002 bestmatchsize = XSTRING (eltstring)->size;
1000 } 1003 }
1001 else 1004 else
1002 { 1005 {
1003 compare = min (bestmatchsize, STRING_BYTES (XSTRING (eltstring))); 1006 compare = min (bestmatchsize, XSTRING (eltstring)->size);
1004 matchsize = scmp (XSTRING (bestmatch)->data, 1007 tem = Fcompare_strings (bestmatch, make_number (0),
1005 XSTRING (eltstring)->data, 1008 make_number (compare),
1006 compare); 1009 eltstring, make_number (0),
1010 make_number (compare),
1011 completion_ignore_case ? Qt : Qnil);
1012 if (EQ (tem, Qt))
1013 matchsize = compare;
1014 else if (XINT (tem) < 0)
1015 matchsize = - XINT (tem) - 1;
1016 else
1017 matchsize = XINT (tem) - 1;
1018
1007 if (matchsize < 0) 1019 if (matchsize < 0)
1008 matchsize = compare; 1020 matchsize = compare;
1009 if (completion_ignore_case) 1021 if (completion_ignore_case)
@@ -1012,8 +1024,8 @@ or the symbol from the obarray.")
1012 use it as the best match rather than one that is not an 1024 use it as the best match rather than one that is not an
1013 exact match. This way, we get the case pattern 1025 exact match. This way, we get the case pattern
1014 of the actual match. */ 1026 of the actual match. */
1015 if ((matchsize == STRING_BYTES (XSTRING (eltstring)) 1027 if ((matchsize == XSTRING (eltstring)->size
1016 && matchsize < STRING_BYTES (XSTRING (bestmatch))) 1028 && matchsize < XSTRING (bestmatch)->size)
1017 || 1029 ||
1018 /* If there is more than one exact match ignoring case, 1030 /* If there is more than one exact match ignoring case,
1019 and one of them is exact including case, 1031 and one of them is exact including case,
@@ -1021,15 +1033,21 @@ or the symbol from the obarray.")
1021 /* If there is no exact match ignoring case, 1033 /* If there is no exact match ignoring case,
1022 prefer a match that does not change the case 1034 prefer a match that does not change the case
1023 of the input. */ 1035 of the input. */
1024 ((matchsize == STRING_BYTES (XSTRING (eltstring))) 1036 ((matchsize == XSTRING (eltstring)->size)
1025 == 1037 ==
1026 (matchsize == STRING_BYTES (XSTRING (bestmatch))) 1038 (matchsize == XSTRING (bestmatch)->size)
1027 && !bcmp (XSTRING (eltstring)->data, 1039 && (tem = Fcompare_strings (eltstring, make_number (0),
1028 XSTRING (string)->data, 1040 make_number (XSTRING (string)->size),
1029 STRING_BYTES (XSTRING (string))) 1041 string, make_number (0),
1030 && bcmp (XSTRING (bestmatch)->data, 1042 Qnil,
1031 XSTRING (string)->data, 1043 Qnil),
1032 STRING_BYTES (XSTRING (string))))) 1044 EQ (Qt, tem))
1045 && (tem = Fcompare_strings (bestmatch, make_number (0),
1046 make_number (XSTRING (string)->size),
1047 string, make_number (0),
1048 Qnil,
1049 Qnil),
1050 ! EQ (Qt, tem))))
1033 bestmatch = eltstring; 1051 bestmatch = eltstring;
1034 } 1052 }
1035 bestmatchsize = matchsize; 1053 bestmatchsize = matchsize;
@@ -1042,19 +1060,21 @@ or the symbol from the obarray.")
1042 /* If we are ignoring case, and there is no exact match, 1060 /* If we are ignoring case, and there is no exact match,
1043 and no additional text was supplied, 1061 and no additional text was supplied,
1044 don't change the case of what the user typed. */ 1062 don't change the case of what the user typed. */
1045 if (completion_ignore_case && bestmatchsize == STRING_BYTES (XSTRING (string)) 1063 if (completion_ignore_case && bestmatchsize == XSTRING (string)->size
1046 && STRING_BYTES (XSTRING (bestmatch)) > bestmatchsize) 1064 && XSTRING (bestmatch)->size > bestmatchsize)
1047 return string; 1065 return string;
1048 1066
1049 /* Return t if the supplied string is an exact match (counting case); 1067 /* Return t if the supplied string is an exact match (counting case);
1050 it does not require any change to be made. */ 1068 it does not require any change to be made. */
1051 if (matchcount == 1 && bestmatchsize == STRING_BYTES (XSTRING (string)) 1069 if (matchcount == 1 && bestmatchsize == XSTRING (string)->size
1052 && !bcmp (XSTRING (bestmatch)->data, XSTRING (string)->data, 1070 && (tem = Fcompare_strings (bestmatch, make_number (0),
1053 bestmatchsize)) 1071 make_number (bestmatchsize),
1072 string, make_number (0),
1073 make_number (bestmatchsize),
1074 Qnil),
1075 EQ (Qt, tem)))
1054 return Qt; 1076 return Qt;
1055 1077
1056 bestmatchsize = string_byte_to_char (bestmatch, bestmatchsize);
1057
1058 XSETFASTINT (zero, 0); /* Else extract the part in which */ 1078 XSETFASTINT (zero, 0); /* Else extract the part in which */
1059 XSETFASTINT (end, bestmatchsize); /* all completions agree */ 1079 XSETFASTINT (end, bestmatchsize); /* all completions agree */
1060 return Fsubstring (bestmatch, zero, end); 1080 return Fsubstring (bestmatch, zero, end);
@@ -1189,8 +1209,12 @@ are ignored unless STRING itself starts with a space.")
1189 && XSTRING (string)->data[0] == ' ') 1209 && XSTRING (string)->data[0] == ' ')
1190 || XSTRING (eltstring)->data[0] != ' ' 1210 || XSTRING (eltstring)->data[0] != ' '
1191 || NILP (hide_spaces)) 1211 || NILP (hide_spaces))
1192 && 0 > scmp (XSTRING (eltstring)->data, XSTRING (string)->data, 1212 && (tem = Fcompare_strings (eltstring, make_number (0),
1193 STRING_BYTES (XSTRING (string)))) 1213 make_number (XSTRING (string)->size),
1214 string, make_number (0),
1215 make_number (XSTRING (string)->size),
1216 completion_ignore_case ? Qt : Qnil),
1217 EQ (Qt, tem)))
1194 { 1218 {
1195 /* Yes. */ 1219 /* Yes. */
1196 Lisp_Object regexps; 1220 Lisp_Object regexps;
@@ -1604,7 +1628,7 @@ is added, provided that matches some possible completion.\n\
1604Return nil if there is no valid completion, else t.") 1628Return nil if there is no valid completion, else t.")
1605 () 1629 ()
1606{ 1630{
1607 Lisp_Object completion, tem; 1631 Lisp_Object completion, tem, tem1;
1608 register int i, i_byte; 1632 register int i, i_byte;
1609 register unsigned char *completion_string; 1633 register unsigned char *completion_string;
1610 struct gcpro gcpro1, gcpro2; 1634 struct gcpro gcpro1, gcpro2;
@@ -1641,8 +1665,7 @@ Return nil if there is no valid completion, else t.")
1641 } 1665 }
1642#else /* Rewritten code */ 1666#else /* Rewritten code */
1643 { 1667 {
1644 register unsigned char *buffer_string; 1668 int buffer_nchars, completion_nchars;
1645 int buffer_nbytes, completion_nbytes;
1646 1669
1647 CHECK_STRING (completion, 0); 1670 CHECK_STRING (completion, 0);
1648 tem = Fbuffer_string (); 1671 tem = Fbuffer_string ();
@@ -1661,21 +1684,37 @@ Return nil if there is no valid completion, else t.")
1661 STRING_BYTES (XSTRING (tem)), 0); 1684 STRING_BYTES (XSTRING (tem)), 0);
1662 } 1685 }
1663 } 1686 }
1664 buffer_string = XSTRING (tem)->data; 1687 buffer_nchars = XSTRING (tem)->size; /* ie ZV - BEGV */
1665 completion_string = XSTRING (completion)->data; 1688 completion_nchars = XSTRING (completion)->size;
1666 buffer_nbytes = STRING_BYTES (XSTRING (tem)); /* ie ZV_BYTE - BEGV_BYTE */ 1689 i = buffer_nchars - completion_nchars;
1667 completion_nbytes = STRING_BYTES (XSTRING (completion)); 1690 if (i > 0
1668 i_byte = buffer_nbytes - completion_nbytes; 1691 ||
1669 if (i_byte > 0 || 1692 (tem1 = Fcompare_strings (tem, make_number (0),
1670 0 <= scmp (buffer_string, completion_string, buffer_nbytes)) 1693 make_number (buffer_nchars),
1694 completion, make_number (0),
1695 make_number (buffer_nchars),
1696 completion_ignore_case ? Qt : Qnil),
1697 ! EQ (tem1, Qt)))
1671 { 1698 {
1672 /* Set buffer to longest match of buffer tail and completion head. */ 1699 int start_pos;
1673 if (i_byte <= 0) i_byte = 1; 1700
1674 buffer_string += i_byte; 1701 /* Set buffer to longest match of buffer tail and completion head. */
1675 buffer_nbytes -= i_byte; 1702 if (i <= 0) i = 1;
1676 while (0 <= scmp (buffer_string++, completion_string, buffer_nbytes--)) 1703 start_pos= i;
1677 i_byte++; 1704 buffer_nchars -= i;
1678 del_range_byte (1, i_byte + 1, 1); 1705 while (1)
1706 {
1707 tem1 = Fcompare_strings (tem, make_number (start_pos),
1708 make_number (buffer_nchars + start_pos),
1709 completion, make_number (0),
1710 make_number (buffer_nchars),
1711 completion_ignore_case ? Qt : Qnil);
1712 start_pos++;
1713 if (EQ (tem1, Qt))
1714 break;
1715 i++;
1716 }
1717 del_range (1, i + 1);
1679 SET_PT_BOTH (ZV, ZV_BYTE); 1718 SET_PT_BOTH (ZV, ZV_BYTE);
1680 } 1719 }
1681 UNGCPRO; 1720 UNGCPRO;