diff options
| author | Richard M. Stallman | 1998-01-05 06:58:06 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-01-05 06:58:06 +0000 |
| commit | af2b7cd5d652bb09d8d97208900cbfe8a7bbe41f (patch) | |
| tree | e1bc19de17debf88d078631ac6d1c845dc9e38fe /src | |
| parent | e4191987516d37563610bc014a1723f6bbf30550 (diff) | |
| download | emacs-af2b7cd5d652bb09d8d97208900cbfe8a7bbe41f.tar.gz emacs-af2b7cd5d652bb09d8d97208900cbfe8a7bbe41f.zip | |
(test_completion): Pass both kinds of size to oblookup.
(Fminibuffer_complete_word): Scan string bytes and chars.
Pass new args to insert_from_string.
(Ftry_completion): Use size_byte while comparing.
(Fall_completions): Use size_byte while comparing.
Diffstat (limited to 'src')
| -rw-r--r-- | src/minibuf.c | 96 |
1 files changed, 56 insertions, 40 deletions
diff --git a/src/minibuf.c b/src/minibuf.c index 5d0ce1def74..583fc2ac7da 100644 --- a/src/minibuf.c +++ b/src/minibuf.c | |||
| @@ -183,9 +183,12 @@ without invoking the usual minibuffer commands.") | |||
| 183 | 183 | ||
| 184 | /* Actual minibuffer invocation. */ | 184 | /* Actual minibuffer invocation. */ |
| 185 | 185 | ||
| 186 | static Lisp_Object read_minibuf_unwind (); | 186 | static Lisp_Object read_minibuf_unwind P_ ((Lisp_Object)); |
| 187 | Lisp_Object get_minibuffer (); | 187 | static Lisp_Object read_minibuf P_ ((Lisp_Object, Lisp_Object, |
| 188 | static Lisp_Object read_minibuf (); | 188 | Lisp_Object, Lisp_Object, |
| 189 | int, Lisp_Object, | ||
| 190 | Lisp_Object, Lisp_Object, | ||
| 191 | int, int)); | ||
| 189 | 192 | ||
| 190 | /* Read from the minibuffer using keymap MAP, initial contents INITIAL | 193 | /* Read from the minibuffer using keymap MAP, initial contents INITIAL |
| 191 | (a string), putting point minus BACKUP_N bytes from the end of INITIAL, | 194 | (a string), putting point minus BACKUP_N bytes from the end of INITIAL, |
| @@ -216,6 +219,7 @@ read_minibuf (map, initial, prompt, backup_n, expflag, | |||
| 216 | Lisp_Object histvar; | 219 | Lisp_Object histvar; |
| 217 | Lisp_Object histpos; | 220 | Lisp_Object histpos; |
| 218 | Lisp_Object defalt; | 221 | Lisp_Object defalt; |
| 222 | int allow_props; | ||
| 219 | int inherit_input_method; | 223 | int inherit_input_method; |
| 220 | { | 224 | { |
| 221 | Lisp_Object val; | 225 | Lisp_Object val; |
| @@ -869,7 +873,9 @@ or the symbol from the obarray.") | |||
| 869 | Lisp_Object string, alist, predicate; | 873 | Lisp_Object string, alist, predicate; |
| 870 | { | 874 | { |
| 871 | Lisp_Object bestmatch, tail, elt, eltstring; | 875 | Lisp_Object bestmatch, tail, elt, eltstring; |
| 876 | /* Size in bytes of BESTMATCH. */ | ||
| 872 | int bestmatchsize; | 877 | int bestmatchsize; |
| 878 | /* These are in bytes, too. */ | ||
| 873 | int compare, matchsize; | 879 | int compare, matchsize; |
| 874 | int list = CONSP (alist) || NILP (alist); | 880 | int list = CONSP (alist) || NILP (alist); |
| 875 | int index, obsize; | 881 | int index, obsize; |
| @@ -930,9 +936,9 @@ or the symbol from the obarray.") | |||
| 930 | /* Is this element a possible completion? */ | 936 | /* Is this element a possible completion? */ |
| 931 | 937 | ||
| 932 | if (STRINGP (eltstring) | 938 | if (STRINGP (eltstring) |
| 933 | && XSTRING (string)->size <= XSTRING (eltstring)->size | 939 | && XSTRING (string)->size_byte <= XSTRING (eltstring)->size_byte |
| 934 | && 0 > scmp (XSTRING (eltstring)->data, XSTRING (string)->data, | 940 | && 0 > scmp (XSTRING (eltstring)->data, XSTRING (string)->data, |
| 935 | XSTRING (string)->size)) | 941 | XSTRING (string)->size_byte)) |
| 936 | { | 942 | { |
| 937 | /* Yes. */ | 943 | /* Yes. */ |
| 938 | Lisp_Object regexps; | 944 | Lisp_Object regexps; |
| @@ -970,10 +976,13 @@ or the symbol from the obarray.") | |||
| 970 | 976 | ||
| 971 | matchcount++; | 977 | matchcount++; |
| 972 | if (NILP (bestmatch)) | 978 | if (NILP (bestmatch)) |
| 973 | bestmatch = eltstring, bestmatchsize = XSTRING (eltstring)->size; | 979 | { |
| 980 | bestmatch = eltstring; | ||
| 981 | bestmatchsize = XSTRING (eltstring)->size_byte; | ||
| 982 | } | ||
| 974 | else | 983 | else |
| 975 | { | 984 | { |
| 976 | compare = min (bestmatchsize, XSTRING (eltstring)->size); | 985 | compare = min (bestmatchsize, XSTRING (eltstring)->size_byte); |
| 977 | matchsize = scmp (XSTRING (bestmatch)->data, | 986 | matchsize = scmp (XSTRING (bestmatch)->data, |
| 978 | XSTRING (eltstring)->data, | 987 | XSTRING (eltstring)->data, |
| 979 | compare); | 988 | compare); |
| @@ -985,8 +994,8 @@ or the symbol from the obarray.") | |||
| 985 | use it as the best match rather than one that is not an | 994 | use it as the best match rather than one that is not an |
| 986 | exact match. This way, we get the case pattern | 995 | exact match. This way, we get the case pattern |
| 987 | of the actual match. */ | 996 | of the actual match. */ |
| 988 | if ((matchsize == XSTRING (eltstring)->size | 997 | if ((matchsize == XSTRING (eltstring)->size_byte |
| 989 | && matchsize < XSTRING (bestmatch)->size) | 998 | && matchsize < XSTRING (bestmatch)->size_byte) |
| 990 | || | 999 | || |
| 991 | /* If there is more than one exact match ignoring case, | 1000 | /* If there is more than one exact match ignoring case, |
| 992 | and one of them is exact including case, | 1001 | and one of them is exact including case, |
| @@ -994,13 +1003,15 @@ or the symbol from the obarray.") | |||
| 994 | /* If there is no exact match ignoring case, | 1003 | /* If there is no exact match ignoring case, |
| 995 | prefer a match that does not change the case | 1004 | prefer a match that does not change the case |
| 996 | of the input. */ | 1005 | of the input. */ |
| 997 | ((matchsize == XSTRING (eltstring)->size) | 1006 | ((matchsize == XSTRING (eltstring)->size_byte) |
| 998 | == | 1007 | == |
| 999 | (matchsize == XSTRING (bestmatch)->size) | 1008 | (matchsize == XSTRING (bestmatch)->size_byte) |
| 1000 | && !bcmp (XSTRING (eltstring)->data, | 1009 | && !bcmp (XSTRING (eltstring)->data, |
| 1001 | XSTRING (string)->data, XSTRING (string)->size) | 1010 | XSTRING (string)->data, |
| 1011 | XSTRING (string)->size_byte) | ||
| 1002 | && bcmp (XSTRING (bestmatch)->data, | 1012 | && bcmp (XSTRING (bestmatch)->data, |
| 1003 | XSTRING (string)->data, XSTRING (string)->size))) | 1013 | XSTRING (string)->data, |
| 1014 | XSTRING (string)->size_byte))) | ||
| 1004 | bestmatch = eltstring; | 1015 | bestmatch = eltstring; |
| 1005 | } | 1016 | } |
| 1006 | bestmatchsize = matchsize; | 1017 | bestmatchsize = matchsize; |
| @@ -1013,17 +1024,19 @@ or the symbol from the obarray.") | |||
| 1013 | /* If we are ignoring case, and there is no exact match, | 1024 | /* If we are ignoring case, and there is no exact match, |
| 1014 | and no additional text was supplied, | 1025 | and no additional text was supplied, |
| 1015 | don't change the case of what the user typed. */ | 1026 | don't change the case of what the user typed. */ |
| 1016 | if (completion_ignore_case && bestmatchsize == XSTRING (string)->size | 1027 | if (completion_ignore_case && bestmatchsize == XSTRING (string)->size_byte |
| 1017 | && XSTRING (bestmatch)->size > bestmatchsize) | 1028 | && XSTRING (bestmatch)->size_byte > bestmatchsize) |
| 1018 | return string; | 1029 | return string; |
| 1019 | 1030 | ||
| 1020 | /* Return t if the supplied string is an exact match (counting case); | 1031 | /* Return t if the supplied string is an exact match (counting case); |
| 1021 | it does not require any change to be made. */ | 1032 | it does not require any change to be made. */ |
| 1022 | if (matchcount == 1 && bestmatchsize == XSTRING (string)->size | 1033 | if (matchcount == 1 && bestmatchsize == XSTRING (string)->size_byte |
| 1023 | && !bcmp (XSTRING (bestmatch)->data, XSTRING (string)->data, | 1034 | && !bcmp (XSTRING (bestmatch)->data, XSTRING (string)->data, |
| 1024 | bestmatchsize)) | 1035 | bestmatchsize)) |
| 1025 | return Qt; | 1036 | return Qt; |
| 1026 | 1037 | ||
| 1038 | bestmatchsize = string_byte_to_char (bestmatch, bestmatchsize); | ||
| 1039 | |||
| 1027 | XSETFASTINT (zero, 0); /* Else extract the part in which */ | 1040 | XSETFASTINT (zero, 0); /* Else extract the part in which */ |
| 1028 | XSETFASTINT (end, bestmatchsize); /* all completions agree */ | 1041 | XSETFASTINT (end, bestmatchsize); /* all completions agree */ |
| 1029 | return Fsubstring (bestmatch, zero, end); | 1042 | return Fsubstring (bestmatch, zero, end); |
| @@ -1151,14 +1164,15 @@ are ignored unless STRING itself starts with a space.") | |||
| 1151 | /* Is this element a possible completion? */ | 1164 | /* Is this element a possible completion? */ |
| 1152 | 1165 | ||
| 1153 | if (STRINGP (eltstring) | 1166 | if (STRINGP (eltstring) |
| 1154 | && XSTRING (string)->size <= XSTRING (eltstring)->size | 1167 | && XSTRING (string)->size_byte <= XSTRING (eltstring)->size_byte |
| 1155 | /* If HIDE_SPACES, reject alternatives that start with space | 1168 | /* If HIDE_SPACES, reject alternatives that start with space |
| 1156 | unless the input starts with space. */ | 1169 | unless the input starts with space. */ |
| 1157 | && ((XSTRING (string)->size > 0 && XSTRING (string)->data[0] == ' ') | 1170 | && ((XSTRING (string)->size_byte > 0 |
| 1171 | && XSTRING (string)->data[0] == ' ') | ||
| 1158 | || XSTRING (eltstring)->data[0] != ' ' | 1172 | || XSTRING (eltstring)->data[0] != ' ' |
| 1159 | || NILP (hide_spaces)) | 1173 | || NILP (hide_spaces)) |
| 1160 | && 0 > scmp (XSTRING (eltstring)->data, XSTRING (string)->data, | 1174 | && 0 > scmp (XSTRING (eltstring)->data, XSTRING (string)->data, |
| 1161 | XSTRING (string)->size)) | 1175 | XSTRING (string)->size_byte)) |
| 1162 | { | 1176 | { |
| 1163 | /* Yes. */ | 1177 | /* Yes. */ |
| 1164 | Lisp_Object regexps; | 1178 | Lisp_Object regexps; |
| @@ -1303,9 +1317,6 @@ DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 8, 0, | |||
| 1303 | 1317 | ||
| 1304 | Lisp_Object Fminibuffer_completion_help (); | 1318 | Lisp_Object Fminibuffer_completion_help (); |
| 1305 | Lisp_Object assoc_for_completion (); | 1319 | Lisp_Object assoc_for_completion (); |
| 1306 | /* A subroutine of Fintern_soft. */ | ||
| 1307 | extern Lisp_Object oblookup (); | ||
| 1308 | |||
| 1309 | 1320 | ||
| 1310 | /* Test whether TXT is an exact completion. */ | 1321 | /* Test whether TXT is an exact completion. */ |
| 1311 | Lisp_Object | 1322 | Lisp_Object |
| @@ -1321,7 +1332,9 @@ test_completion (txt) | |||
| 1321 | { | 1332 | { |
| 1322 | /* Bypass intern-soft as that loses for nil */ | 1333 | /* Bypass intern-soft as that loses for nil */ |
| 1323 | tem = oblookup (Vminibuffer_completion_table, | 1334 | tem = oblookup (Vminibuffer_completion_table, |
| 1324 | XSTRING (txt)->data, XSTRING (txt)->size); | 1335 | XSTRING (txt)->data, |
| 1336 | XSTRING (txt)->size, | ||
| 1337 | XSTRING (txt)->size_byte); | ||
| 1325 | if (!SYMBOLP (tem)) | 1338 | if (!SYMBOLP (tem)) |
| 1326 | return Qnil; | 1339 | return Qnil; |
| 1327 | else if (!NILP (Vminibuffer_completion_predicate)) | 1340 | else if (!NILP (Vminibuffer_completion_predicate)) |
| @@ -1570,7 +1583,7 @@ Return nil if there is no valid completion, else t.") | |||
| 1570 | () | 1583 | () |
| 1571 | { | 1584 | { |
| 1572 | Lisp_Object completion, tem; | 1585 | Lisp_Object completion, tem; |
| 1573 | register int i; | 1586 | register int i, i_byte; |
| 1574 | register unsigned char *completion_string; | 1587 | register unsigned char *completion_string; |
| 1575 | struct gcpro gcpro1, gcpro2; | 1588 | struct gcpro gcpro1, gcpro2; |
| 1576 | 1589 | ||
| @@ -1622,30 +1635,32 @@ Return nil if there is no valid completion, else t.") | |||
| 1622 | { | 1635 | { |
| 1623 | tem = substituted; | 1636 | tem = substituted; |
| 1624 | Ferase_buffer (); | 1637 | Ferase_buffer (); |
| 1625 | insert_from_string (tem, 0, XSTRING (tem)->size, 0); | 1638 | insert_from_string (tem, 0, 0, XSTRING (tem)->size, |
| 1639 | XSTRING (tem)->size_byte, 0); | ||
| 1626 | } | 1640 | } |
| 1627 | } | 1641 | } |
| 1628 | buffer_string = XSTRING (tem)->data; | 1642 | buffer_string = XSTRING (tem)->data; |
| 1629 | completion_string = XSTRING (completion)->data; | 1643 | completion_string = XSTRING (completion)->data; |
| 1630 | buffer_nbytes = XSTRING (tem)->size; /* ie ZV_BYTE - BEGV_BYTE */ | 1644 | buffer_nbytes = XSTRING (tem)->size_byte; /* ie ZV_BYTE - BEGV_BYTE */ |
| 1631 | completion_nbytes = XSTRING (completion)->size; | 1645 | completion_nbytes = XSTRING (completion)->size_byte; |
| 1632 | i = buffer_nbytes - completion_nbytes; | 1646 | i_byte = buffer_nbytes - completion_nbytes; |
| 1633 | if (i > 0 || | 1647 | if (i > 0 || |
| 1634 | 0 <= scmp (buffer_string, completion_string, buffer_nbytes)) | 1648 | 0 <= scmp (buffer_string, completion_string, buffer_nbytes)) |
| 1635 | { | 1649 | { |
| 1636 | /* Set buffer to longest match of buffer tail and completion head. */ | 1650 | /* Set buffer to longest match of buffer tail and completion head. */ |
| 1637 | if (i <= 0) i = 1; | 1651 | if (i_byte <= 0) i_byte = 1; |
| 1638 | buffer_string += i; | 1652 | buffer_string += i_byte; |
| 1639 | buffer_nbytes -= i; | 1653 | buffer_nbytes -= i_byte; |
| 1640 | while (0 <= scmp (buffer_string++, completion_string, buffer_nbytes--)) | 1654 | while (0 <= scmp (buffer_string++, completion_string, buffer_nbytes--)) |
| 1641 | i++; | 1655 | i_byte++; |
| 1642 | del_range_byte (1, i + 1, 1); | 1656 | del_range_byte (1, i_byte + 1, 1); |
| 1643 | SET_PT_BOTH (ZV, ZV_BYTE); | 1657 | SET_PT_BOTH (ZV, ZV_BYTE); |
| 1644 | } | 1658 | } |
| 1645 | UNGCPRO; | 1659 | UNGCPRO; |
| 1646 | } | 1660 | } |
| 1647 | #endif /* Rewritten code */ | 1661 | #endif /* Rewritten code */ |
| 1648 | i = ZV_BYTE - BEGV_BYTE; | 1662 | i_byte = ZV_BYTE - BEGV_BYTE; |
| 1663 | i = ZV - BEGV; | ||
| 1649 | 1664 | ||
| 1650 | /* If completion finds next char not unique, | 1665 | /* If completion finds next char not unique, |
| 1651 | consider adding a space or a hyphen. */ | 1666 | consider adding a space or a hyphen. */ |
| @@ -1679,14 +1694,15 @@ Return nil if there is no valid completion, else t.") | |||
| 1679 | int len, c; | 1694 | int len, c; |
| 1680 | 1695 | ||
| 1681 | completion_string = XSTRING (completion)->data; | 1696 | completion_string = XSTRING (completion)->data; |
| 1682 | for (; i < XSTRING (completion)->size; i += len) | 1697 | for (; i_byte < XSTRING (completion)->size_byte; i_byte += len, i++) |
| 1683 | { | 1698 | { |
| 1684 | c = STRING_CHAR_AND_LENGTH (completion_string + i, | 1699 | c = STRING_CHAR_AND_LENGTH (completion_string + i_byte, |
| 1685 | XSTRING (completion)->size - i, | 1700 | XSTRING (completion)->size - i_byte, |
| 1686 | len); | 1701 | len); |
| 1687 | if (SYNTAX (c) != Sword) | 1702 | if (SYNTAX (c) != Sword) |
| 1688 | { | 1703 | { |
| 1689 | i += len; | 1704 | i_byte += len; |
| 1705 | i++; | ||
| 1690 | break; | 1706 | break; |
| 1691 | } | 1707 | } |
| 1692 | } | 1708 | } |
| @@ -1694,7 +1710,7 @@ Return nil if there is no valid completion, else t.") | |||
| 1694 | 1710 | ||
| 1695 | /* If got no characters, print help for user. */ | 1711 | /* If got no characters, print help for user. */ |
| 1696 | 1712 | ||
| 1697 | if (i == ZV_BYTE - BEGV_BYTE) | 1713 | if (i_byte == ZV_BYTE - BEGV_BYTE) |
| 1698 | { | 1714 | { |
| 1699 | if (auto_help) | 1715 | if (auto_help) |
| 1700 | Fminibuffer_completion_help (); | 1716 | Fminibuffer_completion_help (); |
| @@ -1704,7 +1720,7 @@ Return nil if there is no valid completion, else t.") | |||
| 1704 | /* Otherwise insert in minibuffer the chars we got */ | 1720 | /* Otherwise insert in minibuffer the chars we got */ |
| 1705 | 1721 | ||
| 1706 | Ferase_buffer (); | 1722 | Ferase_buffer (); |
| 1707 | insert_from_string (completion, 0, i, 1); | 1723 | insert_from_string (completion, 0, 0, i, i_byte, 1); |
| 1708 | return Qt; | 1724 | return Qt; |
| 1709 | } | 1725 | } |
| 1710 | 1726 | ||