Mercurial > emacs
comparison src/minibuf.c @ 83554:b8d9a391daf3
Merged from emacs@sv.gnu.org
Patches applied:
* emacs@sv.gnu.org/emacs--devo--0--patch-599
Merge from erc--main--0
* emacs@sv.gnu.org/emacs--devo--0--patch-600
Merge from erc--main--0
* emacs@sv.gnu.org/emacs--devo--0--patch-601
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-602
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-603
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-604
Merge from gnus--rel--5.10
* emacs@sv.gnu.org/emacs--devo--0--patch-605
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-606
Merge from gnus--rel--5.10
* emacs@sv.gnu.org/emacs--devo--0--patch-607
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-608
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-609
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-610
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-611
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-612
Merge from gnus--rel--5.10
* emacs@sv.gnu.org/emacs--devo--0--patch-613
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-614
Make byte compiler correctly write circular constants
* emacs@sv.gnu.org/emacs--devo--0--patch-615
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-616
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-617
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-618
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-192
Merge from emacs--devo--0
* emacs@sv.gnu.org/gnus--rel--5.10--patch-193
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-194
Merge from emacs--devo--0
* emacs@sv.gnu.org/gnus--rel--5.10--patch-195
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-196
Update from CVS
git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-594
author | Karoly Lorentey <lorentey@elte.hu> |
---|---|
date | Mon, 29 Jan 2007 22:21:19 +0000 |
parents | d3099204c799 688a9d290d4d |
children | 07774e5c3ff5 |
comparison
equal
deleted
inserted
replaced
83553:32073cbc5eb6 | 83554:b8d9a391daf3 |
---|---|
1 /* Minibuffer input and completion. | 1 /* Minibuffer input and completion. |
2 Copyright (C) 1985, 1986, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, | 2 Copyright (C) 1985, 1986, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, |
3 2001, 2002, 2003, 2004, 2005, | 3 2001, 2002, 2003, 2004, 2005, |
4 2006 Free Software Foundation, Inc. | 4 2006, 2007 Free Software Foundation, Inc. |
5 | 5 |
6 This file is part of GNU Emacs. | 6 This file is part of GNU Emacs. |
7 | 7 |
8 GNU Emacs is free software; you can redistribute it and/or modify | 8 GNU Emacs is free software; you can redistribute it and/or modify |
9 it under the terms of the GNU General Public License as published by | 9 it under the terms of the GNU General Public License as published by |
1234 else | 1234 else |
1235 return Fstring_make_multibyte (string); | 1235 return Fstring_make_multibyte (string); |
1236 } | 1236 } |
1237 | 1237 |
1238 DEFUN ("try-completion", Ftry_completion, Stry_completion, 2, 3, 0, | 1238 DEFUN ("try-completion", Ftry_completion, Stry_completion, 2, 3, 0, |
1239 doc: /* Return common substring of all completions of STRING in ALIST. | 1239 doc: /* Return common substring of all completions of STRING in COLLECTION. |
1240 Each car of each element of ALIST (or each element if it is not a cons cell) | 1240 Test each possible completion specified by COLLECTION |
1241 is tested to see if it begins with STRING. The possible matches may be | 1241 to see if it begins with STRING. The possible completions may be |
1242 strings or symbols. Symbols are converted to strings before testing, | 1242 strings or symbols. Symbols are converted to strings before testing, |
1243 see `symbol-name'. | 1243 see `symbol-name'. |
1244 All that match are compared together; the longest initial sequence | 1244 All that match STRING are compared together; the longest initial sequence |
1245 common to all matches is returned as a string. | 1245 common to all these matches is the return value. |
1246 If there is no match at all, nil is returned. | 1246 If there is no match at all, the return value is nil. |
1247 For a unique match which is exact, t is returned. | 1247 For a unique match which is exact, the return value is t. |
1248 | 1248 |
1249 If ALIST is a hash-table, all the string and symbol keys are the | 1249 If COLLECTION is an alist, the keys (cars of elements) are the |
1250 possible matches. | 1250 possible completions. If an element is not a cons cell, then the |
1251 If ALIST is an obarray, the names of all symbols in the obarray | 1251 element itself is the possible completion. |
1252 are the possible matches. | 1252 If COLLECTION is a hash-table, all the keys that are strings or symbols |
1253 | 1253 are the possible completions. |
1254 ALIST can also be a function to do the completion itself. | 1254 If COLLECTION is an obarray, the names of all symbols in the obarray |
1255 are the possible completions. | |
1256 | |
1257 COLLECTION can also be a function to do the completion itself. | |
1255 It receives three arguments: the values STRING, PREDICATE and nil. | 1258 It receives three arguments: the values STRING, PREDICATE and nil. |
1256 Whatever it returns becomes the value of `try-completion'. | 1259 Whatever it returns becomes the value of `try-completion'. |
1257 | 1260 |
1258 If optional third argument PREDICATE is non-nil, | 1261 If optional third argument PREDICATE is non-nil, |
1259 it is used to test each possible match. | 1262 it is used to test each possible match. |
1260 The match is a candidate only if PREDICATE returns non-nil. | 1263 The match is a candidate only if PREDICATE returns non-nil. |
1261 The argument given to PREDICATE is the alist element | 1264 The argument given to PREDICATE is the alist element |
1262 or the symbol from the obarray. If ALIST is a hash-table, | 1265 or the symbol from the obarray. If COLLECTION is a hash-table, |
1263 predicate is called with two arguments: the key and the value. | 1266 predicate is called with two arguments: the key and the value. |
1264 Additionally to this predicate, `completion-regexp-list' | 1267 Additionally to this predicate, `completion-regexp-list' |
1265 is used to further constrain the set of candidates. */) | 1268 is used to further constrain the set of candidates. */) |
1266 (string, alist, predicate) | 1269 (string, collection, predicate) |
1267 Lisp_Object string, alist, predicate; | 1270 Lisp_Object string, collection, predicate; |
1268 { | 1271 { |
1269 Lisp_Object bestmatch, tail, elt, eltstring; | 1272 Lisp_Object bestmatch, tail, elt, eltstring; |
1270 /* Size in bytes of BESTMATCH. */ | 1273 /* Size in bytes of BESTMATCH. */ |
1271 int bestmatchsize = 0; | 1274 int bestmatchsize = 0; |
1272 /* These are in bytes, too. */ | 1275 /* These are in bytes, too. */ |
1273 int compare, matchsize; | 1276 int compare, matchsize; |
1274 int type = (HASH_TABLE_P (alist) ? 3 | 1277 int type = (HASH_TABLE_P (collection) ? 3 |
1275 : VECTORP (alist) ? 2 | 1278 : VECTORP (collection) ? 2 |
1276 : NILP (alist) || (CONSP (alist) | 1279 : NILP (collection) || (CONSP (collection) |
1277 && (!SYMBOLP (XCAR (alist)) | 1280 && (!SYMBOLP (XCAR (collection)) |
1278 || NILP (XCAR (alist))))); | 1281 || NILP (XCAR (collection))))); |
1279 int index = 0, obsize = 0; | 1282 int index = 0, obsize = 0; |
1280 int matchcount = 0; | 1283 int matchcount = 0; |
1281 int bindcount = -1; | 1284 int bindcount = -1; |
1282 Lisp_Object bucket, zero, end, tem; | 1285 Lisp_Object bucket, zero, end, tem; |
1283 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | 1286 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
1284 | 1287 |
1285 CHECK_STRING (string); | 1288 CHECK_STRING (string); |
1286 if (type == 0) | 1289 if (type == 0) |
1287 return call3 (alist, string, predicate, Qnil); | 1290 return call3 (collection, string, predicate, Qnil); |
1288 | 1291 |
1289 bestmatch = bucket = Qnil; | 1292 bestmatch = bucket = Qnil; |
1290 zero = make_number (0); | 1293 zero = make_number (0); |
1291 | 1294 |
1292 /* If ALIST is not a list, set TAIL just for gc pro. */ | 1295 /* If COLLECTION is not a list, set TAIL just for gc pro. */ |
1293 tail = alist; | 1296 tail = collection; |
1294 if (type == 2) | 1297 if (type == 2) |
1295 { | 1298 { |
1296 alist = check_obarray (alist); | 1299 collection = check_obarray (collection); |
1297 obsize = XVECTOR (alist)->size; | 1300 obsize = XVECTOR (collection)->size; |
1298 bucket = XVECTOR (alist)->contents[index]; | 1301 bucket = XVECTOR (collection)->contents[index]; |
1299 } | 1302 } |
1300 | 1303 |
1301 while (1) | 1304 while (1) |
1302 { | 1305 { |
1303 /* Get the next element of the alist, obarray, or hash-table. */ | 1306 /* Get the next element of the alist, obarray, or hash-table. */ |
1328 } | 1331 } |
1329 else if (++index >= obsize) | 1332 else if (++index >= obsize) |
1330 break; | 1333 break; |
1331 else | 1334 else |
1332 { | 1335 { |
1333 bucket = XVECTOR (alist)->contents[index]; | 1336 bucket = XVECTOR (collection)->contents[index]; |
1334 continue; | 1337 continue; |
1335 } | 1338 } |
1336 } | 1339 } |
1337 else /* if (type == 3) */ | 1340 else /* if (type == 3) */ |
1338 { | 1341 { |
1339 while (index < HASH_TABLE_SIZE (XHASH_TABLE (alist)) | 1342 while (index < HASH_TABLE_SIZE (XHASH_TABLE (collection)) |
1340 && NILP (HASH_HASH (XHASH_TABLE (alist), index))) | 1343 && NILP (HASH_HASH (XHASH_TABLE (collection), index))) |
1341 index++; | 1344 index++; |
1342 if (index >= HASH_TABLE_SIZE (XHASH_TABLE (alist))) | 1345 if (index >= HASH_TABLE_SIZE (XHASH_TABLE (collection))) |
1343 break; | 1346 break; |
1344 else | 1347 else |
1345 elt = eltstring = HASH_KEY (XHASH_TABLE (alist), index++); | 1348 elt = eltstring = HASH_KEY (XHASH_TABLE (collection), index++); |
1346 } | 1349 } |
1347 | 1350 |
1348 /* Is this element a possible completion? */ | 1351 /* Is this element a possible completion? */ |
1349 | 1352 |
1350 if (SYMBOLP (eltstring)) | 1353 if (SYMBOLP (eltstring)) |
1393 bindcount = -1; | 1396 bindcount = -1; |
1394 } | 1397 } |
1395 GCPRO4 (tail, string, eltstring, bestmatch); | 1398 GCPRO4 (tail, string, eltstring, bestmatch); |
1396 tem = type == 3 | 1399 tem = type == 3 |
1397 ? call2 (predicate, elt, | 1400 ? call2 (predicate, elt, |
1398 HASH_VALUE (XHASH_TABLE (alist), index - 1)) | 1401 HASH_VALUE (XHASH_TABLE (collection), index - 1)) |
1399 : call1 (predicate, elt); | 1402 : call1 (predicate, elt); |
1400 UNGCPRO; | 1403 UNGCPRO; |
1401 } | 1404 } |
1402 if (NILP (tem)) continue; | 1405 if (NILP (tem)) continue; |
1403 } | 1406 } |
1502 XSETFASTINT (end, bestmatchsize); /* all completions agree */ | 1505 XSETFASTINT (end, bestmatchsize); /* all completions agree */ |
1503 return Fsubstring (bestmatch, zero, end); | 1506 return Fsubstring (bestmatch, zero, end); |
1504 } | 1507 } |
1505 | 1508 |
1506 DEFUN ("all-completions", Fall_completions, Sall_completions, 2, 4, 0, | 1509 DEFUN ("all-completions", Fall_completions, Sall_completions, 2, 4, 0, |
1507 doc: /* Search for partial matches to STRING in ALIST. | 1510 doc: /* Search for partial matches to STRING in COLLECTION. |
1508 Each car of each element of ALIST (or each element if it is not a cons cell) | 1511 Test each of the possible completions specified by COLLECTION |
1509 is tested to see if it begins with STRING. The possible matches may be | 1512 to see if it begins with STRING. The possible completions may be |
1510 strings or symbols. Symbols are converted to strings before testing, | 1513 strings or symbols. Symbols are converted to strings before testing, |
1511 see `symbol-name'. | 1514 see `symbol-name'. |
1512 The value is a list of all the strings from ALIST that match. | 1515 The value is a list of all the possible completions that match STRING. |
1513 | 1516 |
1514 If ALIST is a hash-table, all the string and symbol keys are the | 1517 If COLLECTION is an alist, the keys (cars of elements) are the |
1515 possible matches. | 1518 possible completions. If an element is not a cons cell, then the |
1516 If ALIST is an obarray, the names of all symbols in the obarray | 1519 element itself is the possible completion. |
1517 are the possible matches. | 1520 If COLLECTION is a hash-table, all the keys that are strings or symbols |
1518 | 1521 are the possible completions. |
1519 ALIST can also be a function to do the completion itself. | 1522 If COLLECTION is an obarray, the names of all symbols in the obarray |
1523 are the possible completions. | |
1524 | |
1525 COLLECTION can also be a function to do the completion itself. | |
1520 It receives three arguments: the values STRING, PREDICATE and t. | 1526 It receives three arguments: the values STRING, PREDICATE and t. |
1521 Whatever it returns becomes the value of `all-completions'. | 1527 Whatever it returns becomes the value of `all-completions'. |
1522 | 1528 |
1523 If optional third argument PREDICATE is non-nil, | 1529 If optional third argument PREDICATE is non-nil, |
1524 it is used to test each possible match. | 1530 it is used to test each possible match. |
1525 The match is a candidate only if PREDICATE returns non-nil. | 1531 The match is a candidate only if PREDICATE returns non-nil. |
1526 The argument given to PREDICATE is the alist element | 1532 The argument given to PREDICATE is the alist element |
1527 or the symbol from the obarray. If ALIST is a hash-table, | 1533 or the symbol from the obarray. If COLLECTION is a hash-table, |
1528 predicate is called with two arguments: the key and the value. | 1534 predicate is called with two arguments: the key and the value. |
1529 Additionally to this predicate, `completion-regexp-list' | 1535 Additionally to this predicate, `completion-regexp-list' |
1530 is used to further constrain the set of candidates. | 1536 is used to further constrain the set of candidates. |
1531 | 1537 |
1532 If the optional fourth argument HIDE-SPACES is non-nil, | 1538 If the optional fourth argument HIDE-SPACES is non-nil, |
1533 strings in ALIST that start with a space | 1539 strings in COLLECTION that start with a space |
1534 are ignored unless STRING itself starts with a space. */) | 1540 are ignored unless STRING itself starts with a space. */) |
1535 (string, alist, predicate, hide_spaces) | 1541 (string, collection, predicate, hide_spaces) |
1536 Lisp_Object string, alist, predicate, hide_spaces; | 1542 Lisp_Object string, collection, predicate, hide_spaces; |
1537 { | 1543 { |
1538 Lisp_Object tail, elt, eltstring; | 1544 Lisp_Object tail, elt, eltstring; |
1539 Lisp_Object allmatches; | 1545 Lisp_Object allmatches; |
1540 int type = HASH_TABLE_P (alist) ? 3 | 1546 int type = HASH_TABLE_P (collection) ? 3 |
1541 : VECTORP (alist) ? 2 | 1547 : VECTORP (collection) ? 2 |
1542 : NILP (alist) || (CONSP (alist) | 1548 : NILP (collection) || (CONSP (collection) |
1543 && (!SYMBOLP (XCAR (alist)) | 1549 && (!SYMBOLP (XCAR (collection)) |
1544 || NILP (XCAR (alist)))); | 1550 || NILP (XCAR (collection)))); |
1545 int index = 0, obsize = 0; | 1551 int index = 0, obsize = 0; |
1546 int bindcount = -1; | 1552 int bindcount = -1; |
1547 Lisp_Object bucket, tem, zero; | 1553 Lisp_Object bucket, tem, zero; |
1548 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | 1554 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
1549 | 1555 |
1550 CHECK_STRING (string); | 1556 CHECK_STRING (string); |
1551 if (type == 0) | 1557 if (type == 0) |
1552 return call3 (alist, string, predicate, Qt); | 1558 return call3 (collection, string, predicate, Qt); |
1553 allmatches = bucket = Qnil; | 1559 allmatches = bucket = Qnil; |
1554 zero = make_number (0); | 1560 zero = make_number (0); |
1555 | 1561 |
1556 /* If ALIST is not a list, set TAIL just for gc pro. */ | 1562 /* If COLLECTION is not a list, set TAIL just for gc pro. */ |
1557 tail = alist; | 1563 tail = collection; |
1558 if (type == 2) | 1564 if (type == 2) |
1559 { | 1565 { |
1560 obsize = XVECTOR (alist)->size; | 1566 obsize = XVECTOR (collection)->size; |
1561 bucket = XVECTOR (alist)->contents[index]; | 1567 bucket = XVECTOR (collection)->contents[index]; |
1562 } | 1568 } |
1563 | 1569 |
1564 while (1) | 1570 while (1) |
1565 { | 1571 { |
1566 /* Get the next element of the alist, obarray, or hash-table. */ | 1572 /* Get the next element of the alist, obarray, or hash-table. */ |
1589 } | 1595 } |
1590 else if (++index >= obsize) | 1596 else if (++index >= obsize) |
1591 break; | 1597 break; |
1592 else | 1598 else |
1593 { | 1599 { |
1594 bucket = XVECTOR (alist)->contents[index]; | 1600 bucket = XVECTOR (collection)->contents[index]; |
1595 continue; | 1601 continue; |
1596 } | 1602 } |
1597 } | 1603 } |
1598 else /* if (type == 3) */ | 1604 else /* if (type == 3) */ |
1599 { | 1605 { |
1600 while (index < HASH_TABLE_SIZE (XHASH_TABLE (alist)) | 1606 while (index < HASH_TABLE_SIZE (XHASH_TABLE (collection)) |
1601 && NILP (HASH_HASH (XHASH_TABLE (alist), index))) | 1607 && NILP (HASH_HASH (XHASH_TABLE (collection), index))) |
1602 index++; | 1608 index++; |
1603 if (index >= HASH_TABLE_SIZE (XHASH_TABLE (alist))) | 1609 if (index >= HASH_TABLE_SIZE (XHASH_TABLE (collection))) |
1604 break; | 1610 break; |
1605 else | 1611 else |
1606 elt = eltstring = HASH_KEY (XHASH_TABLE (alist), index++); | 1612 elt = eltstring = HASH_KEY (XHASH_TABLE (collection), index++); |
1607 } | 1613 } |
1608 | 1614 |
1609 /* Is this element a possible completion? */ | 1615 /* Is this element a possible completion? */ |
1610 | 1616 |
1611 if (SYMBOLP (eltstring)) | 1617 if (SYMBOLP (eltstring)) |
1663 bindcount = -1; | 1669 bindcount = -1; |
1664 } | 1670 } |
1665 GCPRO4 (tail, eltstring, allmatches, string); | 1671 GCPRO4 (tail, eltstring, allmatches, string); |
1666 tem = type == 3 | 1672 tem = type == 3 |
1667 ? call2 (predicate, elt, | 1673 ? call2 (predicate, elt, |
1668 HASH_VALUE (XHASH_TABLE (alist), index - 1)) | 1674 HASH_VALUE (XHASH_TABLE (collection), index - 1)) |
1669 : call1 (predicate, elt); | 1675 : call1 (predicate, elt); |
1670 UNGCPRO; | 1676 UNGCPRO; |
1671 } | 1677 } |
1672 if (NILP (tem)) continue; | 1678 if (NILP (tem)) continue; |
1673 } | 1679 } |
1690 Lisp_Object Vminibuffer_completing_file_name; | 1696 Lisp_Object Vminibuffer_completing_file_name; |
1691 | 1697 |
1692 DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 8, 0, | 1698 DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 8, 0, |
1693 doc: /* Read a string in the minibuffer, with completion. | 1699 doc: /* Read a string in the minibuffer, with completion. |
1694 PROMPT is a string to prompt with; normally it ends in a colon and a space. | 1700 PROMPT is a string to prompt with; normally it ends in a colon and a space. |
1695 TABLE can be a list of strings, an alist, an obarray or a hash table. | 1701 COLLECTION can be a list of strings, an alist, an obarray or a hash table. |
1696 TABLE can also be a function to do the completion itself. | 1702 COLLECTION can also be a function to do the completion itself. |
1697 PREDICATE limits completion to a subset of TABLE. | 1703 PREDICATE limits completion to a subset of COLLECTION. |
1698 See `try-completion' and `all-completions' for more details | 1704 See `try-completion' and `all-completions' for more details |
1699 on completion, TABLE, and PREDICATE. | 1705 on completion, COLLECTION, and PREDICATE. |
1700 | 1706 |
1701 If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless | 1707 If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless |
1702 the input is (or completes to) an element of TABLE or is null. | 1708 the input is (or completes to) an element of COLLECTION or is null. |
1703 If it is also not t, typing RET does not exit if it does non-null completion. | 1709 If it is also not t, typing RET does not exit if it does non-null completion. |
1704 If the input is null, `completing-read' returns DEF, or an empty string | 1710 If the input is null, `completing-read' returns DEF, or an empty string |
1705 if DEF is nil, regardless of the value of REQUIRE-MATCH. | 1711 if DEF is nil, regardless of the value of REQUIRE-MATCH. |
1706 | 1712 |
1707 If INITIAL-INPUT is non-nil, insert it in the minibuffer initially, | 1713 If INITIAL-INPUT is non-nil, insert it in the minibuffer initially, |
1731 If INHERIT-INPUT-METHOD is non-nil, the minibuffer inherits | 1737 If INHERIT-INPUT-METHOD is non-nil, the minibuffer inherits |
1732 the current input method and the setting of `enable-multibyte-characters'. | 1738 the current input method and the setting of `enable-multibyte-characters'. |
1733 | 1739 |
1734 Completion ignores case if the ambient value of | 1740 Completion ignores case if the ambient value of |
1735 `completion-ignore-case' is non-nil. */) | 1741 `completion-ignore-case' is non-nil. */) |
1736 (prompt, table, predicate, require_match, initial_input, hist, def, inherit_input_method) | 1742 (prompt, collection, predicate, require_match, initial_input, hist, def, inherit_input_method) |
1737 Lisp_Object prompt, table, predicate, require_match, initial_input; | 1743 Lisp_Object prompt, collection, predicate, require_match, initial_input; |
1738 Lisp_Object hist, def, inherit_input_method; | 1744 Lisp_Object hist, def, inherit_input_method; |
1739 { | 1745 { |
1740 Lisp_Object val, histvar, histpos, position; | 1746 Lisp_Object val, histvar, histpos, position; |
1741 Lisp_Object init; | 1747 Lisp_Object init; |
1742 int pos = 0; | 1748 int pos = 0; |
1744 struct gcpro gcpro1; | 1750 struct gcpro gcpro1; |
1745 | 1751 |
1746 init = initial_input; | 1752 init = initial_input; |
1747 GCPRO1 (def); | 1753 GCPRO1 (def); |
1748 | 1754 |
1749 specbind (Qminibuffer_completion_table, table); | 1755 specbind (Qminibuffer_completion_table, collection); |
1750 specbind (Qminibuffer_completion_predicate, predicate); | 1756 specbind (Qminibuffer_completion_predicate, predicate); |
1751 specbind (Qminibuffer_completion_confirm, | 1757 specbind (Qminibuffer_completion_confirm, |
1752 EQ (require_match, Qt) ? Qnil : require_match); | 1758 EQ (require_match, Qt) ? Qnil : require_match); |
1753 last_exact_completion = Qnil; | 1759 last_exact_completion = Qnil; |
1754 | 1760 |
1806 | 1812 |
1807 /* Test whether TXT is an exact completion. */ | 1813 /* Test whether TXT is an exact completion. */ |
1808 DEFUN ("test-completion", Ftest_completion, Stest_completion, 2, 3, 0, | 1814 DEFUN ("test-completion", Ftest_completion, Stest_completion, 2, 3, 0, |
1809 doc: /* Return non-nil if STRING is a valid completion. | 1815 doc: /* Return non-nil if STRING is a valid completion. |
1810 Takes the same arguments as `all-completions' and `try-completion'. | 1816 Takes the same arguments as `all-completions' and `try-completion'. |
1811 If ALIST is a function, it is called with three arguments: | 1817 If COLLECTION is a function, it is called with three arguments: |
1812 the values STRING, PREDICATE and `lambda'. */) | 1818 the values STRING, PREDICATE and `lambda'. */) |
1813 (string, alist, predicate) | 1819 (string, collection, predicate) |
1814 Lisp_Object string, alist, predicate; | 1820 Lisp_Object string, collection, predicate; |
1815 { | 1821 { |
1816 Lisp_Object regexps, tail, tem = Qnil; | 1822 Lisp_Object regexps, tail, tem = Qnil; |
1817 int i = 0; | 1823 int i = 0; |
1818 | 1824 |
1819 CHECK_STRING (string); | 1825 CHECK_STRING (string); |
1820 | 1826 |
1821 if ((CONSP (alist) && (!SYMBOLP (XCAR (alist)) || NILP (XCAR (alist)))) | 1827 if ((CONSP (collection) |
1822 || NILP (alist)) | 1828 && (!SYMBOLP (XCAR (collection)) || NILP (XCAR (collection)))) |
1823 { | 1829 || NILP (collection)) |
1824 tem = Fassoc_string (string, alist, completion_ignore_case ? Qt : Qnil); | 1830 { |
1831 tem = Fassoc_string (string, collection, completion_ignore_case ? Qt : Qnil); | |
1825 if (NILP (tem)) | 1832 if (NILP (tem)) |
1826 return Qnil; | 1833 return Qnil; |
1827 } | 1834 } |
1828 else if (VECTORP (alist)) | 1835 else if (VECTORP (collection)) |
1829 { | 1836 { |
1830 /* Bypass intern-soft as that loses for nil. */ | 1837 /* Bypass intern-soft as that loses for nil. */ |
1831 tem = oblookup (alist, | 1838 tem = oblookup (collection, |
1832 SDATA (string), | 1839 SDATA (string), |
1833 SCHARS (string), | 1840 SCHARS (string), |
1834 SBYTES (string)); | 1841 SBYTES (string)); |
1835 if (!SYMBOLP (tem)) | 1842 if (!SYMBOLP (tem)) |
1836 { | 1843 { |
1837 if (STRING_MULTIBYTE (string)) | 1844 if (STRING_MULTIBYTE (string)) |
1838 string = Fstring_make_unibyte (string); | 1845 string = Fstring_make_unibyte (string); |
1839 else | 1846 else |
1840 string = Fstring_make_multibyte (string); | 1847 string = Fstring_make_multibyte (string); |
1841 | 1848 |
1842 tem = oblookup (alist, | 1849 tem = oblookup (collection, |
1843 SDATA (string), | 1850 SDATA (string), |
1844 SCHARS (string), | 1851 SCHARS (string), |
1845 SBYTES (string)); | 1852 SBYTES (string)); |
1846 } | 1853 } |
1847 | 1854 |
1848 if (completion_ignore_case && !SYMBOLP (tem)) | 1855 if (completion_ignore_case && !SYMBOLP (tem)) |
1849 { | 1856 { |
1850 for (i = XVECTOR (alist)->size - 1; i >= 0; i--) | 1857 for (i = XVECTOR (collection)->size - 1; i >= 0; i--) |
1851 { | 1858 { |
1852 tail = XVECTOR (alist)->contents[i]; | 1859 tail = XVECTOR (collection)->contents[i]; |
1853 if (SYMBOLP (tail)) | 1860 if (SYMBOLP (tail)) |
1854 while (1) | 1861 while (1) |
1855 { | 1862 { |
1856 if (EQ((Fcompare_strings (string, make_number (0), Qnil, | 1863 if (EQ((Fcompare_strings (string, make_number (0), Qnil, |
1857 Fsymbol_name (tail), | 1864 Fsymbol_name (tail), |
1869 } | 1876 } |
1870 | 1877 |
1871 if (!SYMBOLP (tem)) | 1878 if (!SYMBOLP (tem)) |
1872 return Qnil; | 1879 return Qnil; |
1873 } | 1880 } |
1874 else if (HASH_TABLE_P (alist)) | 1881 else if (HASH_TABLE_P (collection)) |
1875 { | 1882 { |
1876 struct Lisp_Hash_Table *h = XHASH_TABLE (alist); | 1883 struct Lisp_Hash_Table *h = XHASH_TABLE (collection); |
1877 i = hash_lookup (h, string, NULL); | 1884 i = hash_lookup (h, string, NULL); |
1878 if (i >= 0) | 1885 if (i >= 0) |
1879 tem = HASH_KEY (h, i); | 1886 tem = HASH_KEY (h, i); |
1880 else | 1887 else |
1881 for (i = 0; i < HASH_TABLE_SIZE (h); ++i) | 1888 for (i = 0; i < HASH_TABLE_SIZE (h); ++i) |
1890 } | 1897 } |
1891 if (!STRINGP (tem)) | 1898 if (!STRINGP (tem)) |
1892 return Qnil; | 1899 return Qnil; |
1893 } | 1900 } |
1894 else | 1901 else |
1895 return call3 (alist, string, predicate, Qlambda); | 1902 return call3 (collection, string, predicate, Qlambda); |
1896 | 1903 |
1897 /* Reject this element if it fails to match all the regexps. */ | 1904 /* Reject this element if it fails to match all the regexps. */ |
1898 if (CONSP (Vcompletion_regexp_list)) | 1905 if (CONSP (Vcompletion_regexp_list)) |
1899 { | 1906 { |
1900 int count = SPECPDL_INDEX (); | 1907 int count = SPECPDL_INDEX (); |
1911 } | 1918 } |
1912 | 1919 |
1913 /* Finally, check the predicate. */ | 1920 /* Finally, check the predicate. */ |
1914 if (!NILP (predicate)) | 1921 if (!NILP (predicate)) |
1915 { | 1922 { |
1916 return HASH_TABLE_P (alist) | 1923 return HASH_TABLE_P (collection) |
1917 ? call2 (predicate, tem, HASH_VALUE (XHASH_TABLE (alist), i)) | 1924 ? call2 (predicate, tem, HASH_VALUE (XHASH_TABLE (collection), i)) |
1918 : call1 (predicate, tem); | 1925 : call1 (predicate, tem); |
1919 } | 1926 } |
1920 else | 1927 else |
1921 return Qt; | 1928 return Qt; |
1922 } | 1929 } |