1089 |
If there is no match at all, nil is returned. |
If there is no match at all, nil is returned. |
1090 |
For a unique match which is exact, t is returned. |
For a unique match which is exact, t is returned. |
1091 |
|
|
1092 |
ALIST can be an obarray instead of an alist. |
If ALIST is a hash-table, all the string keys are the possible matches. |
1093 |
Then the print names of all symbols in the obarray are the possible matches. |
If ALIST is an obarray, the names of all symbols in the obarray |
1094 |
|
are the possible matches. |
1095 |
|
|
1096 |
ALIST can also be a function to do the completion itself. |
ALIST can also be a function to do the completion itself. |
1097 |
It receives three arguments: the values STRING, PREDICATE and nil. |
It receives three arguments: the values STRING, PREDICATE and nil. |
1101 |
it is used to test each possible match. |
it is used to test each possible match. |
1102 |
The match is a candidate only if PREDICATE returns non-nil. |
The match is a candidate only if PREDICATE returns non-nil. |
1103 |
The argument given to PREDICATE is the alist element |
The argument given to PREDICATE is the alist element |
1104 |
or the symbol from the obarray. |
or the symbol from the obarray. If ALIST is a hash-table, |
1105 |
|
predicate is called with two arguments: the key and the value. |
1106 |
Additionally to this predicate, `completion-regexp-list' |
Additionally to this predicate, `completion-regexp-list' |
1107 |
is used to further constrain the set of candidates. */) |
is used to further constrain the set of candidates. */) |
1108 |
(string, alist, predicate) |
(string, alist, predicate) |
1113 |
int bestmatchsize = 0; |
int bestmatchsize = 0; |
1114 |
/* These are in bytes, too. */ |
/* These are in bytes, too. */ |
1115 |
int compare, matchsize; |
int compare, matchsize; |
1116 |
int list = NILP (alist) || (CONSP (alist) |
int type = HASH_TABLE_P (alist) ? 3 |
1117 |
&& (!SYMBOLP (XCAR (alist)) |
: VECTORP (alist) ? 2 |
1118 |
|| NILP (XCAR (alist)))); |
: NILP (alist) || (CONSP (alist) |
1119 |
|
&& (!SYMBOLP (XCAR (alist)) |
1120 |
|
|| NILP (XCAR (alist)))); |
1121 |
int index = 0, obsize = 0; |
int index = 0, obsize = 0; |
1122 |
int matchcount = 0; |
int matchcount = 0; |
1123 |
Lisp_Object bucket, zero, end, tem; |
Lisp_Object bucket, zero, end, tem; |
1124 |
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
1125 |
|
|
1126 |
CHECK_STRING (string); |
CHECK_STRING (string); |
1127 |
if (!list && !VECTORP (alist)) |
if (type == 0) |
1128 |
return call3 (alist, string, predicate, Qnil); |
return call3 (alist, string, predicate, Qnil); |
1129 |
|
|
1130 |
bestmatch = bucket = Qnil; |
bestmatch = bucket = Qnil; |
1131 |
|
|
1132 |
/* If ALIST is not a list, set TAIL just for gc pro. */ |
/* If ALIST is not a list, set TAIL just for gc pro. */ |
1133 |
tail = alist; |
tail = alist; |
1134 |
if (! list) |
if (type == 2) |
1135 |
{ |
{ |
|
index = 0; |
|
1136 |
obsize = XVECTOR (alist)->size; |
obsize = XVECTOR (alist)->size; |
1137 |
bucket = XVECTOR (alist)->contents[index]; |
bucket = XVECTOR (alist)->contents[index]; |
1138 |
} |
} |
1139 |
|
|
1140 |
while (1) |
while (1) |
1141 |
{ |
{ |
1142 |
/* Get the next element of the alist or obarray. */ |
/* Get the next element of the alist, obarray, or hash-table. */ |
1143 |
/* Exit the loop if the elements are all used up. */ |
/* Exit the loop if the elements are all used up. */ |
1144 |
/* elt gets the alist element or symbol. |
/* elt gets the alist element or symbol. |
1145 |
eltstring gets the name to check as a completion. */ |
eltstring gets the name to check as a completion. */ |
1146 |
|
|
1147 |
if (list) |
if (type == 1) |
1148 |
{ |
{ |
1149 |
if (!CONSP (tail)) |
if (!CONSP (tail)) |
1150 |
break; |
break; |
1152 |
eltstring = CONSP (elt) ? XCAR (elt) : elt; |
eltstring = CONSP (elt) ? XCAR (elt) : elt; |
1153 |
tail = XCDR (tail); |
tail = XCDR (tail); |
1154 |
} |
} |
1155 |
else |
else if (type == 2) |
1156 |
{ |
{ |
1157 |
if (XFASTINT (bucket) != 0) |
if (XFASTINT (bucket) != 0) |
1158 |
{ |
{ |
1171 |
continue; |
continue; |
1172 |
} |
} |
1173 |
} |
} |
1174 |
|
else /* if (type == 3) */ |
1175 |
|
{ |
1176 |
|
while (index < HASH_TABLE_SIZE (XHASH_TABLE (alist)) |
1177 |
|
&& NILP (HASH_HASH (XHASH_TABLE (alist), index))) |
1178 |
|
index++; |
1179 |
|
if (index >= HASH_TABLE_SIZE (XHASH_TABLE (alist))) |
1180 |
|
break; |
1181 |
|
else |
1182 |
|
elt = eltstring = HASH_KEY (XHASH_TABLE (alist), index++); |
1183 |
|
} |
1184 |
|
|
1185 |
/* Is this element a possible completion? */ |
/* Is this element a possible completion? */ |
1186 |
|
|
1218 |
else |
else |
1219 |
{ |
{ |
1220 |
GCPRO4 (tail, string, eltstring, bestmatch); |
GCPRO4 (tail, string, eltstring, bestmatch); |
1221 |
tem = call1 (predicate, elt); |
tem = type == 3 |
1222 |
|
? call2 (predicate, elt, |
1223 |
|
HASH_VALUE (XHASH_TABLE (alist), index - 1)) |
1224 |
|
: call1 (predicate, elt); |
1225 |
UNGCPRO; |
UNGCPRO; |
1226 |
} |
} |
1227 |
if (NILP (tem)) continue; |
if (NILP (tem)) continue; |
1229 |
|
|
1230 |
/* Update computation of how much all possible completions match */ |
/* Update computation of how much all possible completions match */ |
1231 |
|
|
|
matchcount++; |
|
1232 |
if (NILP (bestmatch)) |
if (NILP (bestmatch)) |
1233 |
{ |
{ |
1234 |
|
matchcount = 1; |
1235 |
bestmatch = eltstring; |
bestmatch = eltstring; |
1236 |
bestmatchsize = XSTRING (eltstring)->size; |
bestmatchsize = XSTRING (eltstring)->size; |
1237 |
} |
} |
1285 |
! EQ (Qt, tem)))) |
! EQ (Qt, tem)))) |
1286 |
bestmatch = eltstring; |
bestmatch = eltstring; |
1287 |
} |
} |
1288 |
|
if (bestmatchsize != XSTRING (eltstring)->size |
1289 |
|
|| bestmatchsize != matchsize) |
1290 |
|
/* Don't count the same string multiple times. */ |
1291 |
|
matchcount++; |
1292 |
bestmatchsize = matchsize; |
bestmatchsize = matchsize; |
1293 |
if (matchsize <= XSTRING (string)->size |
if (matchsize <= XSTRING (string)->size |
1294 |
&& matchcount > 1) |
&& matchcount > 1) |
1328 |
Each car of each element of ALIST is tested to see if it begins with STRING. |
Each car of each element of ALIST is tested to see if it begins with STRING. |
1329 |
The value is a list of all the strings from ALIST that match. |
The value is a list of all the strings from ALIST that match. |
1330 |
|
|
1331 |
ALIST can be an obarray instead of an alist. |
If ALIST is a hash-table, all the string keys are the possible matches. |
1332 |
Then the print names of all symbols in the obarray are the possible matches. |
If ALIST is an obarray, the names of all symbols in the obarray |
1333 |
|
are the possible matches. |
1334 |
|
|
1335 |
ALIST can also be a function to do the completion itself. |
ALIST can also be a function to do the completion itself. |
1336 |
It receives three arguments: the values STRING, PREDICATE and t. |
It receives three arguments: the values STRING, PREDICATE and t. |
1340 |
it is used to test each possible match. |
it is used to test each possible match. |
1341 |
The match is a candidate only if PREDICATE returns non-nil. |
The match is a candidate only if PREDICATE returns non-nil. |
1342 |
The argument given to PREDICATE is the alist element |
The argument given to PREDICATE is the alist element |
1343 |
or the symbol from the obarray. |
or the symbol from the obarray. If ALIST is a hash-table, |
1344 |
|
predicate is called with two arguments: the key and the value. |
1345 |
Additionally to this predicate, `completion-regexp-list' |
Additionally to this predicate, `completion-regexp-list' |
1346 |
is used to further constrain the set of candidates. |
is used to further constrain the set of candidates. |
1347 |
|
|
1353 |
{ |
{ |
1354 |
Lisp_Object tail, elt, eltstring; |
Lisp_Object tail, elt, eltstring; |
1355 |
Lisp_Object allmatches; |
Lisp_Object allmatches; |
1356 |
int list = NILP (alist) || (CONSP (alist) |
int type = HASH_TABLE_P (alist) ? 3 |
1357 |
&& (!SYMBOLP (XCAR (alist)) |
: VECTORP (alist) ? 2 |
1358 |
|| NILP (XCAR (alist)))); |
: NILP (alist) || (CONSP (alist) |
1359 |
|
&& (!SYMBOLP (XCAR (alist)) |
1360 |
|
|| NILP (XCAR (alist)))); |
1361 |
int index = 0, obsize = 0; |
int index = 0, obsize = 0; |
1362 |
Lisp_Object bucket, tem; |
Lisp_Object bucket, tem; |
1363 |
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
1364 |
|
|
1365 |
CHECK_STRING (string); |
CHECK_STRING (string); |
1366 |
if (!list && !VECTORP (alist)) |
if (type == 0) |
1367 |
{ |
return call3 (alist, string, predicate, Qt); |
|
return call3 (alist, string, predicate, Qt); |
|
|
} |
|
1368 |
allmatches = bucket = Qnil; |
allmatches = bucket = Qnil; |
1369 |
|
|
1370 |
/* If ALIST is not a list, set TAIL just for gc pro. */ |
/* If ALIST is not a list, set TAIL just for gc pro. */ |
1371 |
tail = alist; |
tail = alist; |
1372 |
if (! list) |
if (type == 2) |
1373 |
{ |
{ |
|
index = 0; |
|
1374 |
obsize = XVECTOR (alist)->size; |
obsize = XVECTOR (alist)->size; |
1375 |
bucket = XVECTOR (alist)->contents[index]; |
bucket = XVECTOR (alist)->contents[index]; |
1376 |
} |
} |
1377 |
|
|
1378 |
while (1) |
while (1) |
1379 |
{ |
{ |
1380 |
/* Get the next element of the alist or obarray. */ |
/* Get the next element of the alist, obarray, or hash-table. */ |
1381 |
/* Exit the loop if the elements are all used up. */ |
/* Exit the loop if the elements are all used up. */ |
1382 |
/* elt gets the alist element or symbol. |
/* elt gets the alist element or symbol. |
1383 |
eltstring gets the name to check as a completion. */ |
eltstring gets the name to check as a completion. */ |
1384 |
|
|
1385 |
if (list) |
if (type == 1) |
1386 |
{ |
{ |
1387 |
if (!CONSP (tail)) |
if (!CONSP (tail)) |
1388 |
break; |
break; |
1390 |
eltstring = CONSP (elt) ? XCAR (elt) : elt; |
eltstring = CONSP (elt) ? XCAR (elt) : elt; |
1391 |
tail = XCDR (tail); |
tail = XCDR (tail); |
1392 |
} |
} |
1393 |
else |
else if (type == 2) |
1394 |
{ |
{ |
1395 |
if (XFASTINT (bucket) != 0) |
if (XFASTINT (bucket) != 0) |
1396 |
{ |
{ |
1409 |
continue; |
continue; |
1410 |
} |
} |
1411 |
} |
} |
1412 |
|
else /* if (type == 3) */ |
1413 |
|
{ |
1414 |
|
while (index < HASH_TABLE_SIZE (XHASH_TABLE (alist)) |
1415 |
|
&& NILP (HASH_HASH (XHASH_TABLE (alist), index))) |
1416 |
|
index++; |
1417 |
|
if (index >= HASH_TABLE_SIZE (XHASH_TABLE (alist))) |
1418 |
|
break; |
1419 |
|
else |
1420 |
|
elt = eltstring = HASH_KEY (XHASH_TABLE (alist), index++); |
1421 |
|
} |
1422 |
|
|
1423 |
/* Is this element a possible completion? */ |
/* Is this element a possible completion? */ |
1424 |
|
|
1463 |
else |
else |
1464 |
{ |
{ |
1465 |
GCPRO4 (tail, eltstring, allmatches, string); |
GCPRO4 (tail, eltstring, allmatches, string); |
1466 |
tem = call1 (predicate, elt); |
tem = type == 3 |
1467 |
|
? call2 (predicate, elt, |
1468 |
|
HASH_VALUE (XHASH_TABLE (alist), index - 1)) |
1469 |
|
: call1 (predicate, elt); |
1470 |
UNGCPRO; |
UNGCPRO; |
1471 |
} |
} |
1472 |
if (NILP (tem)) continue; |
if (NILP (tem)) continue; |
1598 |
Lisp_Object string, alist, predicate; |
Lisp_Object string, alist, predicate; |
1599 |
{ |
{ |
1600 |
Lisp_Object regexps, tem = Qnil; |
Lisp_Object regexps, tem = Qnil; |
1601 |
|
int i = 0; |
1602 |
|
|
1603 |
CHECK_STRING (string); |
CHECK_STRING (string); |
1604 |
|
|
1606 |
|| NILP (alist)) |
|| NILP (alist)) |
1607 |
{ |
{ |
1608 |
tem = Fassoc_string (string, alist, completion_ignore_case ? Qt : Qnil); |
tem = Fassoc_string (string, alist, completion_ignore_case ? Qt : Qnil); |
1609 |
if (CONSP (tem)) |
if NILP (tem) |
|
tem = XCAR (tem); |
|
|
else |
|
1610 |
return Qnil; |
return Qnil; |
1611 |
} |
} |
1612 |
else if (VECTORP (alist)) |
else if (VECTORP (alist)) |
1631 |
return Qnil; |
return Qnil; |
1632 |
} |
} |
1633 |
} |
} |
1634 |
|
else if (HASH_TABLE_P (alist)) |
1635 |
|
{ |
1636 |
|
i = hash_lookup (XHASH_TABLE (alist), string, NULL); |
1637 |
|
if (i >= 0) |
1638 |
|
tem = HASH_KEY (XHASH_TABLE (alist), i); |
1639 |
|
else |
1640 |
|
return Qnil; |
1641 |
|
} |
1642 |
else |
else |
1643 |
return call3 (alist, string, predicate, Qlambda); |
return call3 (alist, string, predicate, Qlambda); |
1644 |
|
|
1654 |
|
|
1655 |
/* Finally, check the predicate. */ |
/* Finally, check the predicate. */ |
1656 |
if (!NILP (predicate)) |
if (!NILP (predicate)) |
1657 |
return call1 (predicate, tem); |
return HASH_TABLE_P (alist) |
1658 |
|
? call2 (predicate, tem, HASH_VALUE (XHASH_TABLE (alist), i)) |
1659 |
|
: call1 (predicate, tem); |
1660 |
else |
else |
1661 |
return Qt; |
return Qt; |
1662 |
} |
} |