diff options
| author | Luc Teirlinck | 2003-12-23 22:22:49 +0000 |
|---|---|---|
| committer | Luc Teirlinck | 2003-12-23 22:22:49 +0000 |
| commit | adb0708c03a9e9a2478f3eaa9fea47f2674d9deb (patch) | |
| tree | 70219f172ff8c7dac94903a039b94ce8dd151b6c /src | |
| parent | 79148a5ba3081ac307a8ea378460517fbf5d7af5 (diff) | |
| download | emacs-adb0708c03a9e9a2478f3eaa9fea47f2674d9deb.tar.gz emacs-adb0708c03a9e9a2478f3eaa9fea47f2674d9deb.zip | |
(read_minibuf): Allow INITIAL to be a cons of a string and an integer.
Adapt the docstring accordingly.
(Fread_from_minibuffer): Delete code moved into read_minibuf.
Doc fix.
(Fread_minibuffer, Fread_no_blanks_input): Adapt to changes in
read_minibuf.
(Fcompleting_read): Delete code moved into read_minibuf.
(Ftest_completion): Make it handle obarrays and hash tables correctly.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 12 | ||||
| -rw-r--r-- | src/minibuf.c | 150 |
2 files changed, 95 insertions, 67 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index ba399ce927a..c9da7bc57a1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,15 @@ | |||
| 1 | 2003-12-23 Luc Teirlinck <teirllm@auburn.edu> | ||
| 2 | |||
| 3 | * minibuf.c (read_minibuf): Allow INITIAL to be a cons of a | ||
| 4 | string and an integer. Adapt the docstring accordingly. | ||
| 5 | (Fread_from_minibuffer): Delete code moved into read_minibuf. | ||
| 6 | Doc fix. | ||
| 7 | (Fread_minibuffer, Fread_no_blanks_input): Adapt to changes in | ||
| 8 | read_minibuf. | ||
| 9 | (Fcompleting_read): Delete code moved into read_minibuf. | ||
| 10 | (Ftest_completion): Make it handle obarrays and hash tables | ||
| 11 | correctly. | ||
| 12 | |||
| 1 | 2003-12-03 Kenichi Handa <handa@m17n.org> | 13 | 2003-12-03 Kenichi Handa <handa@m17n.org> |
| 2 | 14 | ||
| 3 | * coding.c (decode_coding_iso2022): Fix for preserving UTF-8 | 15 | * coding.c (decode_coding_iso2022): Fix for preserving UTF-8 |
diff --git a/src/minibuf.c b/src/minibuf.c index 542fdd54f1d..4c98f7ba708 100644 --- a/src/minibuf.c +++ b/src/minibuf.c | |||
| @@ -404,10 +404,15 @@ minibuffer_completion_contents () | |||
| 404 | return make_buffer_string (prompt_end, PT, 1); | 404 | return make_buffer_string (prompt_end, PT, 1); |
| 405 | } | 405 | } |
| 406 | 406 | ||
| 407 | /* Read from the minibuffer using keymap MAP, initial contents INITIAL | 407 | /* Read from the minibuffer using keymap MAP and initial contents INITIAL, |
| 408 | (a string), putting point minus BACKUP_N bytes from the end of INITIAL, | 408 | putting point minus BACKUP_N bytes from the end of INITIAL, |
| 409 | prompting with PROMPT (a string), using history list HISTVAR | 409 | prompting with PROMPT (a string), using history list HISTVAR |
| 410 | with initial position HISTPOS. (BACKUP_N should be <= 0.) | 410 | with initial position HISTPOS. INITIAL should be a string or a |
| 411 | cons of a string and an integer. BACKUP_N should be <= 0, or | ||
| 412 | Qnil, which is equivalent to 0. If INITIAL is a cons, BACKUP_N is | ||
| 413 | ignored and replaced with an integer that puts point N characters | ||
| 414 | from the beginning of INITIAL, where N is the CDR of INITIAL, or at | ||
| 415 | the beginning of INITIAL if N <= 0. | ||
| 411 | 416 | ||
| 412 | Normally return the result as a string (the text that was read), | 417 | Normally return the result as a string (the text that was read), |
| 413 | but if EXPFLAG is nonzero, read it and return the object read. | 418 | but if EXPFLAG is nonzero, read it and return the object read. |
| @@ -419,7 +424,7 @@ minibuffer_completion_contents () | |||
| 419 | 424 | ||
| 420 | If ALLOW_PROPS is nonzero, we do not throw away text properties. | 425 | If ALLOW_PROPS is nonzero, we do not throw away text properties. |
| 421 | 426 | ||
| 422 | if INHERIT_INPUT_METHOD is nonzeor, the minibuffer inherit the | 427 | if INHERIT_INPUT_METHOD is nonzero, the minibuffer inherits the |
| 423 | current input method. */ | 428 | current input method. */ |
| 424 | 429 | ||
| 425 | static Lisp_Object | 430 | static Lisp_Object |
| @@ -441,6 +446,7 @@ read_minibuf (map, initial, prompt, backup_n, expflag, | |||
| 441 | Lisp_Object mini_frame, ambient_dir, minibuffer, input_method; | 446 | Lisp_Object mini_frame, ambient_dir, minibuffer, input_method; |
| 442 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; | 447 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; |
| 443 | Lisp_Object enable_multibyte; | 448 | Lisp_Object enable_multibyte; |
| 449 | int pos = INTEGERP (backup_n) ? XINT (backup_n) : 0; | ||
| 444 | 450 | ||
| 445 | /* String to add to the history. */ | 451 | /* String to add to the history. */ |
| 446 | Lisp_Object histstring; | 452 | Lisp_Object histstring; |
| @@ -456,6 +462,27 @@ read_minibuf (map, initial, prompt, backup_n, expflag, | |||
| 456 | cancel_hourglass (); | 462 | cancel_hourglass (); |
| 457 | #endif | 463 | #endif |
| 458 | 464 | ||
| 465 | if (!NILP (initial)) | ||
| 466 | { | ||
| 467 | if (CONSP (initial)) | ||
| 468 | { | ||
| 469 | backup_n = Fcdr (initial); | ||
| 470 | initial = Fcar (initial); | ||
| 471 | CHECK_STRING (initial); | ||
| 472 | if (!NILP (backup_n)) | ||
| 473 | { | ||
| 474 | CHECK_NUMBER (backup_n); | ||
| 475 | /* Convert to distance from end of input. */ | ||
| 476 | if (XINT (backup_n) < 1) | ||
| 477 | /* A number too small means the beginning of the string. */ | ||
| 478 | pos = - SCHARS (initial); | ||
| 479 | else | ||
| 480 | pos = XINT (backup_n) - 1 - SCHARS (initial); | ||
| 481 | } | ||
| 482 | } | ||
| 483 | else | ||
| 484 | CHECK_STRING (initial); | ||
| 485 | } | ||
| 459 | val = Qnil; | 486 | val = Qnil; |
| 460 | ambient_dir = current_buffer->directory; | 487 | ambient_dir = current_buffer->directory; |
| 461 | input_method = Qnil; | 488 | input_method = Qnil; |
| @@ -482,7 +509,8 @@ read_minibuf (map, initial, prompt, backup_n, expflag, | |||
| 482 | 509 | ||
| 483 | if (noninteractive) | 510 | if (noninteractive) |
| 484 | { | 511 | { |
| 485 | val = read_minibuf_noninteractive (map, initial, prompt, backup_n, | 512 | val = read_minibuf_noninteractive (map, initial, prompt, |
| 513 | make_number (pos), | ||
| 486 | expflag, histvar, histpos, defalt, | 514 | expflag, histvar, histpos, defalt, |
| 487 | allow_props, inherit_input_method); | 515 | allow_props, inherit_input_method); |
| 488 | UNGCPRO; | 516 | UNGCPRO; |
| @@ -633,8 +661,7 @@ read_minibuf (map, initial, prompt, backup_n, expflag, | |||
| 633 | if (!NILP (initial)) | 661 | if (!NILP (initial)) |
| 634 | { | 662 | { |
| 635 | Finsert (1, &initial); | 663 | Finsert (1, &initial); |
| 636 | if (INTEGERP (backup_n)) | 664 | Fforward_char (make_number (pos)); |
| 637 | Fforward_char (backup_n); | ||
| 638 | } | 665 | } |
| 639 | 666 | ||
| 640 | clear_message (1, 1); | 667 | clear_message (1, 1); |
| @@ -884,8 +911,9 @@ Fifth arg HIST, if non-nil, specifies a history list | |||
| 884 | which INITIAL-CONTENTS corresponds to). | 911 | which INITIAL-CONTENTS corresponds to). |
| 885 | Positions are counted starting from 1 at the beginning of the list. | 912 | Positions are counted starting from 1 at the beginning of the list. |
| 886 | Sixth arg DEFAULT-VALUE is the default value. If non-nil, it is available | 913 | Sixth arg DEFAULT-VALUE is the default value. If non-nil, it is available |
| 887 | for history commands; but `read-from-minibuffer' does NOT return DEFAULT-VALUE | 914 | for history commands; but, unless READ is non-nil, `read-from-minibuffer' |
| 888 | if the user enters empty input! It returns the empty string. | 915 | does NOT return DEFAULT-VALUE if the user enters empty input! It returns |
| 916 | the empty string. | ||
| 889 | Seventh arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits | 917 | Seventh arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits |
| 890 | the current input method and the setting of `enable-multibyte-characters'. | 918 | the current input method and the setting of `enable-multibyte-characters'. |
| 891 | If the variable `minibuffer-allow-text-properties' is non-nil, | 919 | If the variable `minibuffer-allow-text-properties' is non-nil, |
| @@ -895,33 +923,10 @@ If the variable `minibuffer-allow-text-properties' is non-nil, | |||
| 895 | Lisp_Object prompt, initial_contents, keymap, read, hist, default_value; | 923 | Lisp_Object prompt, initial_contents, keymap, read, hist, default_value; |
| 896 | Lisp_Object inherit_input_method; | 924 | Lisp_Object inherit_input_method; |
| 897 | { | 925 | { |
| 898 | int pos = 0; | 926 | Lisp_Object histvar, histpos, val; |
| 899 | Lisp_Object histvar, histpos, position, val; | ||
| 900 | struct gcpro gcpro1; | 927 | struct gcpro gcpro1; |
| 901 | 928 | ||
| 902 | position = Qnil; | ||
| 903 | |||
| 904 | CHECK_STRING (prompt); | 929 | CHECK_STRING (prompt); |
| 905 | if (!NILP (initial_contents)) | ||
| 906 | { | ||
| 907 | if (CONSP (initial_contents)) | ||
| 908 | { | ||
| 909 | position = Fcdr (initial_contents); | ||
| 910 | initial_contents = Fcar (initial_contents); | ||
| 911 | } | ||
| 912 | CHECK_STRING (initial_contents); | ||
| 913 | if (!NILP (position)) | ||
| 914 | { | ||
| 915 | CHECK_NUMBER (position); | ||
| 916 | /* Convert to distance from end of input. */ | ||
| 917 | if (XINT (position) < 1) | ||
| 918 | /* A number too small means the beginning of the string. */ | ||
| 919 | pos = - SCHARS (initial_contents); | ||
| 920 | else | ||
| 921 | pos = XINT (position) - 1 - SCHARS (initial_contents); | ||
| 922 | } | ||
| 923 | } | ||
| 924 | |||
| 925 | if (NILP (keymap)) | 930 | if (NILP (keymap)) |
| 926 | keymap = Vminibuffer_local_map; | 931 | keymap = Vminibuffer_local_map; |
| 927 | else | 932 | else |
| @@ -944,7 +949,7 @@ If the variable `minibuffer-allow-text-properties' is non-nil, | |||
| 944 | 949 | ||
| 945 | GCPRO1 (default_value); | 950 | GCPRO1 (default_value); |
| 946 | val = read_minibuf (keymap, initial_contents, prompt, | 951 | val = read_minibuf (keymap, initial_contents, prompt, |
| 947 | make_number (pos), !NILP (read), | 952 | Qnil, !NILP (read), |
| 948 | histvar, histpos, default_value, | 953 | histvar, histpos, default_value, |
| 949 | minibuffer_allow_text_properties, | 954 | minibuffer_allow_text_properties, |
| 950 | !NILP (inherit_input_method)); | 955 | !NILP (inherit_input_method)); |
| @@ -960,8 +965,6 @@ is a string to insert in the minibuffer before reading. */) | |||
| 960 | Lisp_Object prompt, initial_contents; | 965 | Lisp_Object prompt, initial_contents; |
| 961 | { | 966 | { |
| 962 | CHECK_STRING (prompt); | 967 | CHECK_STRING (prompt); |
| 963 | if (!NILP (initial_contents)) | ||
| 964 | CHECK_STRING (initial_contents); | ||
| 965 | return read_minibuf (Vminibuffer_local_map, initial_contents, | 968 | return read_minibuf (Vminibuffer_local_map, initial_contents, |
| 966 | prompt, Qnil, 1, Qminibuffer_history, | 969 | prompt, Qnil, 1, Qminibuffer_history, |
| 967 | make_number (0), Qnil, 0, 0); | 970 | make_number (0), Qnil, 0, 0); |
| @@ -1012,9 +1015,6 @@ the current input method and the setting of `enable-multibyte-characters'. */) | |||
| 1012 | Lisp_Object prompt, initial, inherit_input_method; | 1015 | Lisp_Object prompt, initial, inherit_input_method; |
| 1013 | { | 1016 | { |
| 1014 | CHECK_STRING (prompt); | 1017 | CHECK_STRING (prompt); |
| 1015 | if (! NILP (initial)) | ||
| 1016 | CHECK_STRING (initial); | ||
| 1017 | |||
| 1018 | return read_minibuf (Vminibuffer_local_ns_map, initial, prompt, Qnil, | 1018 | return read_minibuf (Vminibuffer_local_ns_map, initial, prompt, Qnil, |
| 1019 | 0, Qminibuffer_history, make_number (0), Qnil, 0, | 1019 | 0, Qminibuffer_history, make_number (0), Qnil, 0, |
| 1020 | !NILP (inherit_input_method)); | 1020 | !NILP (inherit_input_method)); |
| @@ -1578,13 +1578,10 @@ Completion ignores case if the ambient value of | |||
| 1578 | Lisp_Object prompt, table, predicate, require_match, initial_input; | 1578 | Lisp_Object prompt, table, predicate, require_match, initial_input; |
| 1579 | Lisp_Object hist, def, inherit_input_method; | 1579 | Lisp_Object hist, def, inherit_input_method; |
| 1580 | { | 1580 | { |
| 1581 | Lisp_Object val, histvar, histpos, position; | 1581 | Lisp_Object val, histvar, histpos; |
| 1582 | Lisp_Object init; | ||
| 1583 | int pos = 0; | ||
| 1584 | int count = SPECPDL_INDEX (); | 1582 | int count = SPECPDL_INDEX (); |
| 1585 | struct gcpro gcpro1; | 1583 | struct gcpro gcpro1; |
| 1586 | 1584 | ||
| 1587 | init = initial_input; | ||
| 1588 | GCPRO1 (def); | 1585 | GCPRO1 (def); |
| 1589 | 1586 | ||
| 1590 | specbind (Qminibuffer_completion_table, table); | 1587 | specbind (Qminibuffer_completion_table, table); |
| @@ -1593,23 +1590,6 @@ Completion ignores case if the ambient value of | |||
| 1593 | EQ (require_match, Qt) ? Qnil : require_match); | 1590 | EQ (require_match, Qt) ? Qnil : require_match); |
| 1594 | last_exact_completion = Qnil; | 1591 | last_exact_completion = Qnil; |
| 1595 | 1592 | ||
| 1596 | position = Qnil; | ||
| 1597 | if (!NILP (init)) | ||
| 1598 | { | ||
| 1599 | if (CONSP (init)) | ||
| 1600 | { | ||
| 1601 | position = Fcdr (init); | ||
| 1602 | init = Fcar (init); | ||
| 1603 | } | ||
| 1604 | CHECK_STRING (init); | ||
| 1605 | if (!NILP (position)) | ||
| 1606 | { | ||
| 1607 | CHECK_NUMBER (position); | ||
| 1608 | /* Convert to distance from end of input. */ | ||
| 1609 | pos = XINT (position) - SCHARS (init); | ||
| 1610 | } | ||
| 1611 | } | ||
| 1612 | |||
| 1613 | if (SYMBOLP (hist)) | 1593 | if (SYMBOLP (hist)) |
| 1614 | { | 1594 | { |
| 1615 | histvar = hist; | 1595 | histvar = hist; |
| @@ -1628,7 +1608,7 @@ Completion ignores case if the ambient value of | |||
| 1628 | val = read_minibuf (NILP (require_match) | 1608 | val = read_minibuf (NILP (require_match) |
| 1629 | ? Vminibuffer_local_completion_map | 1609 | ? Vminibuffer_local_completion_map |
| 1630 | : Vminibuffer_local_must_match_map, | 1610 | : Vminibuffer_local_must_match_map, |
| 1631 | init, prompt, make_number (pos), 0, | 1611 | initial_input, prompt, Qnil, 0, |
| 1632 | histvar, histpos, def, 0, | 1612 | histvar, histpos, def, 0, |
| 1633 | !NILP (inherit_input_method)); | 1613 | !NILP (inherit_input_method)); |
| 1634 | 1614 | ||
| @@ -1650,7 +1630,7 @@ the values STRING, PREDICATE and `lambda'. */) | |||
| 1650 | (string, alist, predicate) | 1630 | (string, alist, predicate) |
| 1651 | Lisp_Object string, alist, predicate; | 1631 | Lisp_Object string, alist, predicate; |
| 1652 | { | 1632 | { |
| 1653 | Lisp_Object regexps, tem = Qnil; | 1633 | Lisp_Object regexps, tail, tem = Qnil; |
| 1654 | int i = 0; | 1634 | int i = 0; |
| 1655 | 1635 | ||
| 1656 | CHECK_STRING (string); | 1636 | CHECK_STRING (string); |
| @@ -1676,20 +1656,56 @@ the values STRING, PREDICATE and `lambda'. */) | |||
| 1676 | else | 1656 | else |
| 1677 | string = Fstring_make_multibyte (string); | 1657 | string = Fstring_make_multibyte (string); |
| 1678 | 1658 | ||
| 1679 | tem = oblookup (Vminibuffer_completion_table, | 1659 | tem = oblookup (alist, |
| 1680 | SDATA (string), | 1660 | SDATA (string), |
| 1681 | SCHARS (string), | 1661 | SCHARS (string), |
| 1682 | SBYTES (string)); | 1662 | SBYTES (string)); |
| 1683 | if (!SYMBOLP (tem)) | ||
| 1684 | return Qnil; | ||
| 1685 | } | 1663 | } |
| 1664 | |||
| 1665 | if (completion_ignore_case && !SYMBOLP (tem)) | ||
| 1666 | { | ||
| 1667 | for (i = XVECTOR (alist)->size - 1; i >= 0; i--) | ||
| 1668 | { | ||
| 1669 | tail = XVECTOR (alist)->contents[i]; | ||
| 1670 | if (SYMBOLP (tail)) | ||
| 1671 | while (1) | ||
| 1672 | { | ||
| 1673 | if (EQ((Fcompare_strings (string, make_number (0), Qnil, | ||
| 1674 | Fsymbol_name (tail), | ||
| 1675 | make_number (0) , Qnil, Qt)), | ||
| 1676 | Qt)) | ||
| 1677 | { | ||
| 1678 | tem = tail; | ||
| 1679 | break; | ||
| 1680 | } | ||
| 1681 | if (XSYMBOL (tail)->next == 0) | ||
| 1682 | break; | ||
| 1683 | XSETSYMBOL (tail, XSYMBOL (tail)->next); | ||
| 1684 | } | ||
| 1685 | } | ||
| 1686 | } | ||
| 1687 | |||
| 1688 | if (!SYMBOLP (tem)) | ||
| 1689 | return Qnil; | ||
| 1686 | } | 1690 | } |
| 1687 | else if (HASH_TABLE_P (alist)) | 1691 | else if (HASH_TABLE_P (alist)) |
| 1688 | { | 1692 | { |
| 1689 | i = hash_lookup (XHASH_TABLE (alist), string, NULL); | 1693 | struct Lisp_Hash_Table *h = XHASH_TABLE (alist); |
| 1694 | i = hash_lookup (h, string, NULL); | ||
| 1690 | if (i >= 0) | 1695 | if (i >= 0) |
| 1691 | tem = HASH_KEY (XHASH_TABLE (alist), i); | 1696 | tem = HASH_KEY (h, i); |
| 1692 | else | 1697 | else |
| 1698 | for (i = 0; i < HASH_TABLE_SIZE (h); ++i) | ||
| 1699 | if (!NILP (HASH_HASH (h, i)) && | ||
| 1700 | EQ (Fcompare_strings (string, make_number (0), Qnil, | ||
| 1701 | HASH_KEY (h, i), make_number (0) , Qnil, | ||
| 1702 | completion_ignore_case ? Qt : Qnil), | ||
| 1703 | Qt)) | ||
| 1704 | { | ||
| 1705 | tem = HASH_KEY (h, i); | ||
| 1706 | break; | ||
| 1707 | } | ||
| 1708 | if (!STRINGP (tem)) | ||
| 1693 | return Qnil; | 1709 | return Qnil; |
| 1694 | } | 1710 | } |
| 1695 | else | 1711 | else |