diff options
| author | Richard M. Stallman | 2002-06-26 08:42:22 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2002-06-26 08:42:22 +0000 |
| commit | 1011edb5d85cd8a181a69cad8bd77fea274f6176 (patch) | |
| tree | dfee8f9161dd0161b86d8d53ae8beccaf1c88d60 /src | |
| parent | 8f6490b8df1e8846d0c62faae0654cadca003b0b (diff) | |
| download | emacs-1011edb5d85cd8a181a69cad8bd77fea274f6176.tar.gz emacs-1011edb5d85cd8a181a69cad8bd77fea274f6176.zip | |
(do_completion, Fminibuffer_complete_word)
(Fminibuffer_completion_help): Complete just the text before point.
(minibuffer_completion_contents): New function.
Diffstat (limited to 'src')
| -rw-r--r-- | src/minibuf.c | 75 |
1 files changed, 51 insertions, 24 deletions
diff --git a/src/minibuf.c b/src/minibuf.c index 1df7515bc7b..dc0e16c7ba2 100644 --- a/src/minibuf.c +++ b/src/minibuf.c | |||
| @@ -317,8 +317,7 @@ read_minibuf_noninteractive (map, initial, prompt, backup_n, expflag, | |||
| 317 | 317 | ||
| 318 | return val; | 318 | return val; |
| 319 | } | 319 | } |
| 320 | 320 | ||
| 321 | |||
| 322 | DEFUN ("minibuffer-prompt-end", Fminibuffer_prompt_end, | 321 | DEFUN ("minibuffer-prompt-end", Fminibuffer_prompt_end, |
| 323 | Sminibuffer_prompt_end, 0, 0, 0, | 322 | Sminibuffer_prompt_end, 0, 0, 0, |
| 324 | doc: /* Return the buffer position of the end of the minibuffer prompt. | 323 | doc: /* Return the buffer position of the end of the minibuffer prompt. |
| @@ -367,7 +366,15 @@ The current buffer must be a minibuffer. */) | |||
| 367 | return Qnil; | 366 | return Qnil; |
| 368 | } | 367 | } |
| 369 | 368 | ||
| 369 | /* Get the text in the minibuffer before point. | ||
| 370 | That is what completion commands operate on. */ | ||
| 370 | 371 | ||
| 372 | minibuffer_completion_contents () | ||
| 373 | { | ||
| 374 | int prompt_end = XINT (Fminibuffer_prompt_end ()); | ||
| 375 | return make_buffer_string (prompt_end, PT, 1); | ||
| 376 | } | ||
| 377 | |||
| 371 | /* Read from the minibuffer using keymap MAP, initial contents INITIAL | 378 | /* Read from the minibuffer using keymap MAP, initial contents INITIAL |
| 372 | (a string), putting point minus BACKUP_N bytes from the end of INITIAL, | 379 | (a string), putting point minus BACKUP_N bytes from the end of INITIAL, |
| 373 | prompting with PROMPT (a string), using history list HISTVAR | 380 | prompting with PROMPT (a string), using history list HISTVAR |
| @@ -1626,7 +1633,7 @@ do_completion () | |||
| 1626 | Lisp_Object last; | 1633 | Lisp_Object last; |
| 1627 | struct gcpro gcpro1, gcpro2; | 1634 | struct gcpro gcpro1, gcpro2; |
| 1628 | 1635 | ||
| 1629 | completion = Ftry_completion (Fminibuffer_contents (), | 1636 | completion = Ftry_completion (minibuffer_completion_contents (), |
| 1630 | Vminibuffer_completion_table, | 1637 | Vminibuffer_completion_table, |
| 1631 | Vminibuffer_completion_predicate); | 1638 | Vminibuffer_completion_predicate); |
| 1632 | last = last_exact_completion; | 1639 | last = last_exact_completion; |
| @@ -1648,7 +1655,7 @@ do_completion () | |||
| 1648 | return 1; | 1655 | return 1; |
| 1649 | } | 1656 | } |
| 1650 | 1657 | ||
| 1651 | string = Fminibuffer_contents (); | 1658 | string = minibuffer_completion_contents (); |
| 1652 | 1659 | ||
| 1653 | /* COMPLETEDP should be true if some completion was done, which | 1660 | /* COMPLETEDP should be true if some completion was done, which |
| 1654 | doesn't include simply changing the case of the entered string. | 1661 | doesn't include simply changing the case of the entered string. |
| @@ -1661,7 +1668,19 @@ do_completion () | |||
| 1661 | if (!EQ (tem, Qt)) | 1668 | if (!EQ (tem, Qt)) |
| 1662 | /* Rewrite the user's input. */ | 1669 | /* Rewrite the user's input. */ |
| 1663 | { | 1670 | { |
| 1664 | Fdelete_minibuffer_contents (); /* Some completion happened */ | 1671 | int prompt_end = XINT (Fminibuffer_prompt_end ()); |
| 1672 | /* Some completion happened */ | ||
| 1673 | |||
| 1674 | if (! NILP (Vminibuffer_completing_file_name) | ||
| 1675 | && XSTRING (completion)->data[STRING_BYTES (XSTRING (completion)) - 1] == '/' | ||
| 1676 | && PT < ZV | ||
| 1677 | && FETCH_CHAR (PT_BYTE) == '/') | ||
| 1678 | { | ||
| 1679 | del_range (prompt_end, PT + 1); | ||
| 1680 | } | ||
| 1681 | else | ||
| 1682 | del_range (prompt_end, PT); | ||
| 1683 | |||
| 1665 | Finsert (1, &completion); | 1684 | Finsert (1, &completion); |
| 1666 | 1685 | ||
| 1667 | if (! completedp) | 1686 | if (! completedp) |
| @@ -1703,7 +1722,7 @@ do_completion () | |||
| 1703 | last_exact_completion = completion; | 1722 | last_exact_completion = completion; |
| 1704 | if (!NILP (last)) | 1723 | if (!NILP (last)) |
| 1705 | { | 1724 | { |
| 1706 | tem = Fminibuffer_contents (); | 1725 | tem = minibuffer_completion_contents (); |
| 1707 | if (!NILP (Fequal (tem, last))) | 1726 | if (!NILP (Fequal (tem, last))) |
| 1708 | Fminibuffer_completion_help (); | 1727 | Fminibuffer_completion_help (); |
| 1709 | } | 1728 | } |
| @@ -1880,12 +1899,12 @@ Return nil if there is no valid completion, else t. */) | |||
| 1880 | register int i, i_byte; | 1899 | register int i, i_byte; |
| 1881 | register unsigned char *completion_string; | 1900 | register unsigned char *completion_string; |
| 1882 | struct gcpro gcpro1, gcpro2; | 1901 | struct gcpro gcpro1, gcpro2; |
| 1883 | int prompt_end_charpos; | 1902 | int prompt_end_charpos = XINT (Fminibuffer_prompt_end ()); |
| 1884 | 1903 | ||
| 1885 | /* We keep calling Fbuffer_string rather than arrange for GC to | 1904 | /* We keep calling Fbuffer_string rather than arrange for GC to |
| 1886 | hold onto a pointer to one of the strings thus made. */ | 1905 | hold onto a pointer to one of the strings thus made. */ |
| 1887 | 1906 | ||
| 1888 | completion = Ftry_completion (Fminibuffer_contents (), | 1907 | completion = Ftry_completion (minibuffer_completion_contents (), |
| 1889 | Vminibuffer_completion_table, | 1908 | Vminibuffer_completion_table, |
| 1890 | Vminibuffer_completion_predicate); | 1909 | Vminibuffer_completion_predicate); |
| 1891 | if (NILP (completion)) | 1910 | if (NILP (completion)) |
| @@ -1917,7 +1936,7 @@ Return nil if there is no valid completion, else t. */) | |||
| 1917 | int buffer_nchars, completion_nchars; | 1936 | int buffer_nchars, completion_nchars; |
| 1918 | 1937 | ||
| 1919 | CHECK_STRING (completion); | 1938 | CHECK_STRING (completion); |
| 1920 | tem = Fminibuffer_contents (); | 1939 | tem = minibuffer_completion_contents (); |
| 1921 | GCPRO2 (completion, tem); | 1940 | GCPRO2 (completion, tem); |
| 1922 | /* If reading a file name, | 1941 | /* If reading a file name, |
| 1923 | expand any $ENVVAR refs in the buffer and in TEM. */ | 1942 | expand any $ENVVAR refs in the buffer and in TEM. */ |
| @@ -1928,12 +1947,11 @@ Return nil if there is no valid completion, else t. */) | |||
| 1928 | if (! EQ (substituted, tem)) | 1947 | if (! EQ (substituted, tem)) |
| 1929 | { | 1948 | { |
| 1930 | tem = substituted; | 1949 | tem = substituted; |
| 1931 | Fdelete_minibuffer_contents (); | 1950 | del_range (prompt_end_charpos, PT); |
| 1932 | insert_from_string (tem, 0, 0, XSTRING (tem)->size, | 1951 | Finsert (1, &tem); |
| 1933 | STRING_BYTES (XSTRING (tem)), 0); | ||
| 1934 | } | 1952 | } |
| 1935 | } | 1953 | } |
| 1936 | buffer_nchars = XSTRING (tem)->size; /* ie ZV - BEGV */ | 1954 | buffer_nchars = XSTRING (tem)->size; /* # chars in what we completed. */ |
| 1937 | completion_nchars = XSTRING (completion)->size; | 1955 | completion_nchars = XSTRING (completion)->size; |
| 1938 | i = buffer_nchars - completion_nchars; | 1956 | i = buffer_nchars - completion_nchars; |
| 1939 | if (i > 0 | 1957 | if (i > 0 |
| @@ -1947,7 +1965,8 @@ Return nil if there is no valid completion, else t. */) | |||
| 1947 | { | 1965 | { |
| 1948 | int start_pos; | 1966 | int start_pos; |
| 1949 | 1967 | ||
| 1950 | /* Set buffer to longest match of buffer tail and completion head. */ | 1968 | /* Make buffer (before point) contain the longest match |
| 1969 | of TEM's tail and COMPLETION's head. */ | ||
| 1951 | if (i <= 0) i = 1; | 1970 | if (i <= 0) i = 1; |
| 1952 | start_pos= i; | 1971 | start_pos= i; |
| 1953 | buffer_nchars -= i; | 1972 | buffer_nchars -= i; |
| @@ -1964,19 +1983,16 @@ Return nil if there is no valid completion, else t. */) | |||
| 1964 | buffer_nchars--; | 1983 | buffer_nchars--; |
| 1965 | } | 1984 | } |
| 1966 | del_range (1, i + 1); | 1985 | del_range (1, i + 1); |
| 1967 | SET_PT_BOTH (ZV, ZV_BYTE); | ||
| 1968 | } | 1986 | } |
| 1969 | UNGCPRO; | 1987 | UNGCPRO; |
| 1970 | } | 1988 | } |
| 1971 | #endif /* Rewritten code */ | 1989 | #endif /* Rewritten code */ |
| 1972 | 1990 | ||
| 1973 | prompt_end_charpos = XINT (Fminibuffer_prompt_end ()); | ||
| 1974 | |||
| 1975 | { | 1991 | { |
| 1976 | int prompt_end_bytepos; | 1992 | int prompt_end_bytepos; |
| 1977 | prompt_end_bytepos = CHAR_TO_BYTE (prompt_end_charpos); | 1993 | prompt_end_bytepos = CHAR_TO_BYTE (prompt_end_charpos); |
| 1978 | i = ZV - prompt_end_charpos; | 1994 | i = PT - prompt_end_charpos; |
| 1979 | i_byte = ZV_BYTE - prompt_end_bytepos; | 1995 | i_byte = PT_BYTE - prompt_end_bytepos; |
| 1980 | } | 1996 | } |
| 1981 | 1997 | ||
| 1982 | /* If completion finds next char not unique, | 1998 | /* If completion finds next char not unique, |
| @@ -1984,7 +2000,8 @@ Return nil if there is no valid completion, else t. */) | |||
| 1984 | if (i == XSTRING (completion)->size) | 2000 | if (i == XSTRING (completion)->size) |
| 1985 | { | 2001 | { |
| 1986 | GCPRO1 (completion); | 2002 | GCPRO1 (completion); |
| 1987 | tem = Ftry_completion (concat2 (Fminibuffer_contents (), build_string (" ")), | 2003 | tem = Ftry_completion (concat2 (minibuffer_completion_contents (), |
| 2004 | build_string (" ")), | ||
| 1988 | Vminibuffer_completion_table, | 2005 | Vminibuffer_completion_table, |
| 1989 | Vminibuffer_completion_predicate); | 2006 | Vminibuffer_completion_predicate); |
| 1990 | UNGCPRO; | 2007 | UNGCPRO; |
| @@ -1995,7 +2012,8 @@ Return nil if there is no valid completion, else t. */) | |||
| 1995 | { | 2012 | { |
| 1996 | GCPRO1 (completion); | 2013 | GCPRO1 (completion); |
| 1997 | tem = | 2014 | tem = |
| 1998 | Ftry_completion (concat2 (Fminibuffer_contents (), build_string ("-")), | 2015 | Ftry_completion (concat2 (minibuffer_completion_contents (), |
| 2016 | build_string ("-")), | ||
| 1999 | Vminibuffer_completion_table, | 2017 | Vminibuffer_completion_table, |
| 2000 | Vminibuffer_completion_predicate); | 2018 | Vminibuffer_completion_predicate); |
| 2001 | UNGCPRO; | 2019 | UNGCPRO; |
| @@ -2027,7 +2045,7 @@ Return nil if there is no valid completion, else t. */) | |||
| 2027 | 2045 | ||
| 2028 | /* If got no characters, print help for user. */ | 2046 | /* If got no characters, print help for user. */ |
| 2029 | 2047 | ||
| 2030 | if (i == ZV - prompt_end_charpos) | 2048 | if (i == PT - prompt_end_charpos) |
| 2031 | { | 2049 | { |
| 2032 | if (!NILP (Vcompletion_auto_help)) | 2050 | if (!NILP (Vcompletion_auto_help)) |
| 2033 | Fminibuffer_completion_help (); | 2051 | Fminibuffer_completion_help (); |
| @@ -2036,7 +2054,16 @@ Return nil if there is no valid completion, else t. */) | |||
| 2036 | 2054 | ||
| 2037 | /* Otherwise insert in minibuffer the chars we got */ | 2055 | /* Otherwise insert in minibuffer the chars we got */ |
| 2038 | 2056 | ||
| 2039 | Fdelete_minibuffer_contents (); | 2057 | if (! NILP (Vminibuffer_completing_file_name) |
| 2058 | && XSTRING (completion)->data[STRING_BYTES (XSTRING (completion)) - 1] == '/' | ||
| 2059 | && PT < ZV | ||
| 2060 | && FETCH_CHAR (PT_BYTE) == '/') | ||
| 2061 | { | ||
| 2062 | del_range (prompt_end_charpos, PT + 1); | ||
| 2063 | } | ||
| 2064 | else | ||
| 2065 | del_range (prompt_end_charpos, PT); | ||
| 2066 | |||
| 2040 | insert_from_string (completion, 0, 0, i, i_byte, 1); | 2067 | insert_from_string (completion, 0, 0, i, i_byte, 1); |
| 2041 | return Qt; | 2068 | return Qt; |
| 2042 | } | 2069 | } |
| @@ -2232,7 +2259,7 @@ DEFUN ("minibuffer-completion-help", Fminibuffer_completion_help, Sminibuffer_co | |||
| 2232 | Lisp_Object completions; | 2259 | Lisp_Object completions; |
| 2233 | 2260 | ||
| 2234 | message ("Making completion list..."); | 2261 | message ("Making completion list..."); |
| 2235 | completions = Fall_completions (Fminibuffer_contents (), | 2262 | completions = Fall_completions (minibuffer_completion_contents (), |
| 2236 | Vminibuffer_completion_table, | 2263 | Vminibuffer_completion_table, |
| 2237 | Vminibuffer_completion_predicate, | 2264 | Vminibuffer_completion_predicate, |
| 2238 | Qt); | 2265 | Qt); |