comparison src/minibuf.c @ 46019:8f82bf8a959e

(do_completion, Fminibuffer_complete_word) (Fminibuffer_completion_help): Complete just the text before point. (minibuffer_completion_contents): New function.
author Richard M. Stallman <rms@gnu.org>
date Wed, 26 Jun 2002 08:42:22 +0000
parents 1ae71892eb5f
children f27ef978fa8c
comparison
equal deleted inserted replaced
46018:9c3e541afa23 46019:8f82bf8a959e
315 if (expflag) 315 if (expflag)
316 val = string_to_object (val, defalt); 316 val = string_to_object (val, defalt);
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.
325 Return (point-min) if current buffer is not a mini-buffer. */) 324 Return (point-min) if current buffer is not a mini-buffer. */)
326 () 325 ()
365 if (prompt_end < ZV) 364 if (prompt_end < ZV)
366 del_range (prompt_end, ZV); 365 del_range (prompt_end, ZV);
367 return Qnil; 366 return Qnil;
368 } 367 }
369 368
370 369 /* Get the text in the minibuffer before point.
370 That is what completion commands operate on. */
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
374 with initial position HISTPOS. (BACKUP_N should be <= 0.) 381 with initial position HISTPOS. (BACKUP_N should be <= 0.)
375 382
1624 Lisp_Object completion, string, tem; 1631 Lisp_Object completion, string, tem;
1625 int completedp; 1632 int completedp;
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;
1633 last_exact_completion = Qnil; 1640 last_exact_completion = Qnil;
1634 1641
1646 { 1653 {
1647 UNGCPRO; 1654 UNGCPRO;
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.
1655 However, for appearance, the string is rewritten if the case 1662 However, for appearance, the string is rewritten if the case
1656 changes. */ 1663 changes. */
1659 1666
1660 tem = Fcompare_strings (completion, Qnil, Qnil, string, Qnil, Qnil, Qnil); 1667 tem = Fcompare_strings (completion, Qnil, Qnil, string, Qnil, Qnil, Qnil);
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)
1668 /* The case of the string changed, but that's all. We're not 1687 /* The case of the string changed, but that's all. We're not
1669 sure whether this is a unique completion or not, so try again 1688 sure whether this is a unique completion or not, so try again
1701 it means we've already given a "Complete but not unique" 1720 it means we've already given a "Complete but not unique"
1702 message and the user's hit TAB again, so now we give him help. */ 1721 message and the user's hit TAB again, so now we give him help. */
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 }
1710 UNGCPRO; 1729 UNGCPRO;
1711 return 3; 1730 return 3;
1878 { 1897 {
1879 Lisp_Object completion, tem, tem1; 1898 Lisp_Object completion, tem, tem1;
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))
1892 { 1911 {
1893 bitch_at_user (); 1912 bitch_at_user ();
1915 #else /* Rewritten code */ 1934 #else /* Rewritten code */
1916 { 1935 {
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. */
1924 if (! NILP (Vminibuffer_completing_file_name)) 1943 if (! NILP (Vminibuffer_completing_file_name))
1925 { 1944 {
1926 Lisp_Object substituted; 1945 Lisp_Object substituted;
1927 substituted = Fsubstitute_in_file_name (tem); 1946 substituted = Fsubstitute_in_file_name (tem);
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
1940 || 1958 ||
1941 (tem1 = Fcompare_strings (tem, make_number (0), 1959 (tem1 = Fcompare_strings (tem, make_number (0),
1945 completion_ignore_case ? Qt : Qnil), 1963 completion_ignore_case ? Qt : Qnil),
1946 ! EQ (tem1, Qt))) 1964 ! EQ (tem1, Qt)))
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;
1954 while (i > 0) 1973 while (i > 0)
1955 { 1974 {
1962 break; 1981 break;
1963 i++; 1982 i++;
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,
1983 consider adding a space or a hyphen. */ 1999 consider adding a space or a hyphen. */
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;
1991 2008
1992 if (STRINGP (tem)) 2009 if (STRINGP (tem))
1993 completion = tem; 2010 completion = tem;
1994 else 2011 else
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;
2002 2020
2003 if (STRINGP (tem)) 2021 if (STRINGP (tem))
2025 } 2043 }
2026 } 2044 }
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 ();
2034 return Qnil; 2052 return Qnil;
2035 } 2053 }
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 }
2043 2070
2044 DEFUN ("display-completion-list", Fdisplay_completion_list, Sdisplay_completion_list, 2071 DEFUN ("display-completion-list", Fdisplay_completion_list, Sdisplay_completion_list,
2230 () 2257 ()
2231 { 2258 {
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);
2239 clear_message (1, 0); 2266 clear_message (1, 0);
2240 2267