comparison src/minibuf.c @ 26059:2a7f35e0072b

(Fminibuffer_complete_and_exit): Supply value for new ESCAPE_FROM_EDGE parameter to Ffield_beginning. (Fminibuffer_complete_word): Use Ffield_beginning to find the prompt end. (Fminibuffer_complete_and_exit): Test for an empty input string by seeing where the field begins, instead of looking at text-properties. (read_minibuf): Don't save minibuffer prompt length on minibuf_save_list. Don't initialize minibuffer prompt length. Wrap prompt text-properties around the entire prompt. Add 'prompt text-property to prompt. Get final value with Ffield_string instead of make_buffer_string. (read_minibuf_unwind): Don't restore minibuffer prompt length from minibuf_save_list. (do_completion): Get minibuffer input with Ffield_string instead of Fbuffer_string. Erase minibuffer input with Ferase_field instead of erase_buffer. (Fminibuffer_complete_and_exit): Likewise. Test whether buffer is empty by looking for the 'prompt text property at the end. Set prompt length by looking for the end of the prompt text property, and save prompt length for later use (since there is no longer a buffer variable to get it from). (Fminibuffer_prompt_width, Fminibuffer_prompt_end): Functions removed. (syms_of_minibuf): Remove initializations of Sminibuffer_prompt_width and Sminibuffer_prompt_end.
author Gerd Moellmann <gerd@gnu.org>
date Sun, 17 Oct 1999 12:55:49 +0000
parents f540e1508f05
children d39ec0a27081
comparison
equal deleted inserted replaced
26058:c11f0832a7c5 26059:2a7f35e0072b
1 /* Minibuffer input and completion. 1 /* Minibuffer input and completion.
2 Copyright (C) 1985, 1986, 1993, 1994, 1995, 1996, 1997, 1998 2 Copyright (C) 1985, 1986, 1993, 1994, 1995, 1996, 1997, 1998, 1999
3 Free Software Foundation, Inc. 3 Free Software Foundation, Inc.
4 4
5 This file is part of GNU Emacs. 5 This file is part of GNU Emacs.
6 6
7 GNU Emacs is free software; you can redistribute it and/or modify 7 GNU Emacs is free software; you can redistribute it and/or modify
129 129
130 Lisp_Object Qcurrent_input_method, Qactivate_input_method; 130 Lisp_Object Qcurrent_input_method, Qactivate_input_method;
131 131
132 extern Lisp_Object Qmouse_face; 132 extern Lisp_Object Qmouse_face;
133 133
134 extern Lisp_Object Qfield;
134 135
135 /* Put minibuf on currently selected frame's minibuffer. 136 /* Put minibuf on currently selected frame's minibuffer.
136 We do this whenever the user starts a new minibuffer 137 We do this whenever the user starts a new minibuffer
137 or when a minibuffer exits. */ 138 or when a minibuffer exits. */
138 139
316 Fcons (Vhelp_form, 317 Fcons (Vhelp_form,
317 Fcons (Vcurrent_prefix_arg, 318 Fcons (Vcurrent_prefix_arg,
318 Fcons (Vminibuffer_history_position, 319 Fcons (Vminibuffer_history_position,
319 Fcons (Vminibuffer_history_variable, 320 Fcons (Vminibuffer_history_variable,
320 minibuf_save_list)))))); 321 minibuf_save_list))))));
321 minibuf_save_list
322 = Fcons (current_buffer->prompt_end_charpos,
323 minibuf_save_list);
324 322
325 record_unwind_protect (read_minibuf_unwind, Qnil); 323 record_unwind_protect (read_minibuf_unwind, Qnil);
326 minibuf_level++; 324 minibuf_level++;
327 325
328 /* Now that we can restore all those variables, start changing them. */ 326 /* Now that we can restore all those variables, start changing them. */
383 Fselect_window (minibuf_window); 381 Fselect_window (minibuf_window);
384 XSETFASTINT (XWINDOW (minibuf_window)->hscroll, 0); 382 XSETFASTINT (XWINDOW (minibuf_window)->hscroll, 0);
385 383
386 Fmake_local_variable (Qprint_escape_newlines); 384 Fmake_local_variable (Qprint_escape_newlines);
387 print_escape_newlines = 1; 385 print_escape_newlines = 1;
388 XSETFASTINT (current_buffer->prompt_end_charpos, 0);
389 386
390 /* Erase the buffer. */ 387 /* Erase the buffer. */
391 { 388 {
392 int count1 = specpdl_ptr - specpdl; 389 int count1 = specpdl_ptr - specpdl;
393 specbind (Qinhibit_read_only, Qt); 390 specbind (Qinhibit_read_only, Qt);
399 && ! STRING_MULTIBYTE (minibuf_prompt)) 396 && ! STRING_MULTIBYTE (minibuf_prompt))
400 minibuf_prompt = Fstring_make_multibyte (minibuf_prompt); 397 minibuf_prompt = Fstring_make_multibyte (minibuf_prompt);
401 398
402 /* Insert the prompt, record where it ends. */ 399 /* Insert the prompt, record where it ends. */
403 Finsert (1, &minibuf_prompt); 400 Finsert (1, &minibuf_prompt);
404 XSETFASTINT (current_buffer->prompt_end_charpos, PT);
405 if (PT > BEG) 401 if (PT > BEG)
406 { 402 {
407 Fput_text_property (make_number (BEG), make_number (PT), 403 Fput_text_property (make_number (BEG), make_number (PT),
408 Qfront_sticky, Qt, Qnil); 404 Qfront_sticky, Qt, Qnil);
409 Fput_text_property (make_number (BEG), make_number (PT), 405 Fput_text_property (make_number (BEG), make_number (PT),
410 Qrear_nonsticky, Qt, Qnil); 406 Qrear_nonsticky, Qt, Qnil);
407 Fput_text_property (make_number (BEG), make_number (PT),
408 Qfield, Qt, Qnil);
411 Fput_text_property (make_number (BEG), make_number (PT), 409 Fput_text_property (make_number (BEG), make_number (PT),
412 Qread_only, Qt, Qnil); 410 Qread_only, Qt, Qnil);
413 } 411 }
414 412
415 minibuf_prompt_width = current_column (); 413 minibuf_prompt_width = current_column ();
455 rif->flush_display (XFRAME (XWINDOW (minibuf_window)->frame)); 453 rif->flush_display (XFRAME (XWINDOW (minibuf_window)->frame));
456 } 454 }
457 455
458 /* Make minibuffer contents into a string. */ 456 /* Make minibuffer contents into a string. */
459 Fset_buffer (minibuffer); 457 Fset_buffer (minibuffer);
460 val = make_buffer_string (current_buffer->prompt_end_charpos, 458 val = Ffield_string (make_number (ZV), allow_props ? Qt : Qnil);
461 Z, allow_props);
462 459
463 /* VAL is the string of minibuffer text. */ 460 /* VAL is the string of minibuffer text. */
464 461
465 last_minibuf_string = val; 462 last_minibuf_string = val;
466 463
608 /* To keep things predictable, in case it matters, let's be in the 605 /* To keep things predictable, in case it matters, let's be in the
609 minibuffer when we reset the relevant variables. */ 606 minibuffer when we reset the relevant variables. */
610 Fset_buffer (XWINDOW (window)->buffer); 607 Fset_buffer (XWINDOW (window)->buffer);
611 608
612 /* Restore prompt, etc, from outer minibuffer level. */ 609 /* Restore prompt, etc, from outer minibuffer level. */
613 current_buffer->prompt_end_charpos = Fcar (minibuf_save_list);
614 minibuf_save_list = Fcdr (minibuf_save_list);
615
616 minibuf_prompt = Fcar (minibuf_save_list); 610 minibuf_prompt = Fcar (minibuf_save_list);
617 minibuf_save_list = Fcdr (minibuf_save_list); 611 minibuf_save_list = Fcdr (minibuf_save_list);
618 minibuf_prompt_width = XFASTINT (Fcar (minibuf_save_list)); 612 minibuf_prompt_width = XFASTINT (Fcar (minibuf_save_list));
619 minibuf_save_list = Fcdr (minibuf_save_list); 613 minibuf_save_list = Fcdr (minibuf_save_list);
620 Vhelp_form = Fcar (minibuf_save_list); 614 Vhelp_form = Fcar (minibuf_save_list);
1482 Lisp_Object completion, tem; 1476 Lisp_Object completion, tem;
1483 int completedp; 1477 int completedp;
1484 Lisp_Object last; 1478 Lisp_Object last;
1485 struct gcpro gcpro1, gcpro2; 1479 struct gcpro gcpro1, gcpro2;
1486 1480
1487 completion = Ftry_completion (Fbuffer_string (), Vminibuffer_completion_table, 1481 completion = Ftry_completion (Ffield_string (ZV),
1482 Vminibuffer_completion_table,
1488 Vminibuffer_completion_predicate); 1483 Vminibuffer_completion_predicate);
1489 last = last_exact_completion; 1484 last = last_exact_completion;
1490 last_exact_completion = Qnil; 1485 last_exact_completion = Qnil;
1491 1486
1492 GCPRO2 (completion, last); 1487 GCPRO2 (completion, last);
1504 UNGCPRO; 1499 UNGCPRO;
1505 return 1; 1500 return 1;
1506 } 1501 }
1507 1502
1508 /* compiler bug */ 1503 /* compiler bug */
1509 tem = Fstring_equal (completion, Fbuffer_string()); 1504 tem = Fstring_equal (completion, Ffield_string(ZV));
1510 completedp = NILP (tem); 1505 completedp = NILP (tem);
1511 if (completedp) 1506 if (completedp)
1512 { 1507 {
1513 Ferase_buffer (); /* Some completion happened */ 1508 Ferase_field (make_number (ZV)); /* Some completion happened */
1514 Finsert (1, &completion); 1509 Finsert (1, &completion);
1515 } 1510 }
1516 1511
1517 /* It did find a match. Do we match some possibility exactly now? */ 1512 /* It did find a match. Do we match some possibility exactly now? */
1518 tem = test_completion (Fbuffer_string ()); 1513 tem = test_completion (Ffield_string(ZV));
1519 if (NILP (tem)) 1514 if (NILP (tem))
1520 { 1515 {
1521 /* not an exact match */ 1516 /* not an exact match */
1522 UNGCPRO; 1517 UNGCPRO;
1523 if (completedp) 1518 if (completedp)
1537 it means we've already given a "Complete but not unique" 1532 it means we've already given a "Complete but not unique"
1538 message and the user's hit TAB again, so now we give him help. */ 1533 message and the user's hit TAB again, so now we give him help. */
1539 last_exact_completion = completion; 1534 last_exact_completion = completion;
1540 if (!NILP (last)) 1535 if (!NILP (last))
1541 { 1536 {
1542 tem = Fbuffer_string (); 1537 tem = Ffield_string (ZV);
1543 if (!NILP (Fequal (tem, last))) 1538 if (!NILP (Fequal (tem, last)))
1544 Fminibuffer_completion_help (); 1539 Fminibuffer_completion_help ();
1545 } 1540 }
1546 UNGCPRO; 1541 UNGCPRO;
1547 return 3; 1542 return 3;
1658 { 1653 {
1659 register int i; 1654 register int i;
1660 Lisp_Object val; 1655 Lisp_Object val;
1661 1656
1662 /* Allow user to specify null string */ 1657 /* Allow user to specify null string */
1663 if (XFASTINT (current_buffer->prompt_end_charpos) == ZV) 1658 if (Ffield_beginning (ZV, Qnil) == ZV)
1664 goto exit; 1659 goto exit;
1665 1660
1666 if (!NILP (test_completion (Fbuffer_string ()))) 1661 if (!NILP (test_completion (Ffield_string (ZV))))
1667 goto exit; 1662 goto exit;
1668 1663
1669 /* Call do_completion, but ignore errors. */ 1664 /* Call do_completion, but ignore errors. */
1670 val = internal_condition_case (complete_and_exit_1, Qerror, 1665 val = internal_condition_case (complete_and_exit_1, Qerror,
1671 complete_and_exit_2); 1666 complete_and_exit_2);
1704 { 1699 {
1705 Lisp_Object completion, tem, tem1; 1700 Lisp_Object completion, tem, tem1;
1706 register int i, i_byte; 1701 register int i, i_byte;
1707 register unsigned char *completion_string; 1702 register unsigned char *completion_string;
1708 struct gcpro gcpro1, gcpro2; 1703 struct gcpro gcpro1, gcpro2;
1704 int prompt_end_charpos;
1709 1705
1710 /* We keep calling Fbuffer_string rather than arrange for GC to 1706 /* We keep calling Fbuffer_string rather than arrange for GC to
1711 hold onto a pointer to one of the strings thus made. */ 1707 hold onto a pointer to one of the strings thus made. */
1712 1708
1713 completion = Ftry_completion (Fbuffer_string (), 1709 completion = Ftry_completion (Ffield_string (ZV),
1714 Vminibuffer_completion_table, 1710 Vminibuffer_completion_table,
1715 Vminibuffer_completion_predicate); 1711 Vminibuffer_completion_predicate);
1716 if (NILP (completion)) 1712 if (NILP (completion))
1717 { 1713 {
1718 bitch_at_user (); 1714 bitch_at_user ();
1721 } 1717 }
1722 if (EQ (completion, Qt)) 1718 if (EQ (completion, Qt))
1723 return Qnil; 1719 return Qnil;
1724 1720
1725 #if 0 /* How the below code used to look, for reference. */ 1721 #if 0 /* How the below code used to look, for reference. */
1726 tem = Fbuffer_string (); 1722 tem = Ffield_string (ZV);
1727 b = XSTRING (tem)->data; 1723 b = XSTRING (tem)->data;
1728 i = ZV - 1 - XSTRING (completion)->size; 1724 i = ZV - 1 - XSTRING (completion)->size;
1729 p = XSTRING (completion)->data; 1725 p = XSTRING (completion)->data;
1730 if (i > 0 || 1726 if (i > 0 ||
1731 0 <= scmp (b, p, ZV - 1)) 1727 0 <= scmp (b, p, ZV - 1))
1740 #else /* Rewritten code */ 1736 #else /* Rewritten code */
1741 { 1737 {
1742 int buffer_nchars, completion_nchars; 1738 int buffer_nchars, completion_nchars;
1743 1739
1744 CHECK_STRING (completion, 0); 1740 CHECK_STRING (completion, 0);
1745 tem = Fbuffer_string (); 1741 tem = Ffield_string (ZV);
1746 GCPRO2 (completion, tem); 1742 GCPRO2 (completion, tem);
1747 /* If reading a file name, 1743 /* If reading a file name,
1748 expand any $ENVVAR refs in the buffer and in TEM. */ 1744 expand any $ENVVAR refs in the buffer and in TEM. */
1749 if (! NILP (Vminibuffer_completing_file_name)) 1745 if (! NILP (Vminibuffer_completing_file_name))
1750 { 1746 {
1751 Lisp_Object substituted; 1747 Lisp_Object substituted;
1752 substituted = Fsubstitute_in_file_name (tem); 1748 substituted = Fsubstitute_in_file_name (tem);
1753 if (! EQ (substituted, tem)) 1749 if (! EQ (substituted, tem))
1754 { 1750 {
1755 tem = substituted; 1751 tem = substituted;
1756 Ferase_buffer (); 1752 Ferase_field (make_number (ZV));
1757 insert_from_string (tem, 0, 0, XSTRING (tem)->size, 1753 insert_from_string (tem, 0, 0, XSTRING (tem)->size,
1758 STRING_BYTES (XSTRING (tem)), 0); 1754 STRING_BYTES (XSTRING (tem)), 0);
1759 } 1755 }
1760 } 1756 }
1761 buffer_nchars = XSTRING (tem)->size; /* ie ZV - BEGV */ 1757 buffer_nchars = XSTRING (tem)->size; /* ie ZV - BEGV */
1793 } 1789 }
1794 UNGCPRO; 1790 UNGCPRO;
1795 } 1791 }
1796 #endif /* Rewritten code */ 1792 #endif /* Rewritten code */
1797 1793
1794 prompt_end_charpos = Ffield_beginning (make_number (ZV), Qnil);
1795
1798 { 1796 {
1799 int prompt_end_charpos, prompt_end_bytepos; 1797 int prompt_end_bytepos;
1800 prompt_end_charpos = XFASTINT (current_buffer->prompt_end_charpos);
1801 prompt_end_bytepos = CHAR_TO_BYTE (prompt_end_charpos); 1798 prompt_end_bytepos = CHAR_TO_BYTE (prompt_end_charpos);
1802 i = ZV - prompt_end_charpos; 1799 i = ZV - prompt_end_charpos;
1803 i_byte = ZV_BYTE - prompt_end_bytepos; 1800 i_byte = ZV_BYTE - prompt_end_bytepos;
1804 } 1801 }
1805 1802
1806 /* If completion finds next char not unique, 1803 /* If completion finds next char not unique,
1807 consider adding a space or a hyphen. */ 1804 consider adding a space or a hyphen. */
1808 if (i == XSTRING (completion)->size) 1805 if (i == XSTRING (completion)->size)
1809 { 1806 {
1810 GCPRO1 (completion); 1807 GCPRO1 (completion);
1811 tem = Ftry_completion (concat2 (Fbuffer_string (), build_string (" ")), 1808 tem = Ftry_completion (concat2 (Ffield_string (ZV), build_string (" ")),
1812 Vminibuffer_completion_table, 1809 Vminibuffer_completion_table,
1813 Vminibuffer_completion_predicate); 1810 Vminibuffer_completion_predicate);
1814 UNGCPRO; 1811 UNGCPRO;
1815 1812
1816 if (STRINGP (tem)) 1813 if (STRINGP (tem))
1817 completion = tem; 1814 completion = tem;
1818 else 1815 else
1819 { 1816 {
1820 GCPRO1 (completion); 1817 GCPRO1 (completion);
1821 tem = 1818 tem =
1822 Ftry_completion (concat2 (Fbuffer_string (), build_string ("-")), 1819 Ftry_completion (concat2 (Ffield_string (ZV), build_string ("-")),
1823 Vminibuffer_completion_table, 1820 Vminibuffer_completion_table,
1824 Vminibuffer_completion_predicate); 1821 Vminibuffer_completion_predicate);
1825 UNGCPRO; 1822 UNGCPRO;
1826 1823
1827 if (STRINGP (tem)) 1824 if (STRINGP (tem))
1849 } 1846 }
1850 } 1847 }
1851 1848
1852 /* If got no characters, print help for user. */ 1849 /* If got no characters, print help for user. */
1853 1850
1854 if (i == ZV - XFASTINT (current_buffer->prompt_end_charpos)) 1851 if (i == ZV - prompt_end_charpos)
1855 { 1852 {
1856 if (auto_help) 1853 if (auto_help)
1857 Fminibuffer_completion_help (); 1854 Fminibuffer_completion_help ();
1858 return Qnil; 1855 return Qnil;
1859 } 1856 }
1860 1857
1861 /* Otherwise insert in minibuffer the chars we got */ 1858 /* Otherwise insert in minibuffer the chars we got */
1862 1859
1863 Ferase_buffer (); 1860 Ferase_field (make_number (ZV));
1864 insert_from_string (completion, 0, 0, i, i_byte, 1); 1861 insert_from_string (completion, 0, 0, i, i_byte, 1);
1865 return Qt; 1862 return Qt;
1866 } 1863 }
1867 1864
1868 DEFUN ("display-completion-list", Fdisplay_completion_list, Sdisplay_completion_list, 1865 DEFUN ("display-completion-list", Fdisplay_completion_list, Sdisplay_completion_list,
2052 () 2049 ()
2053 { 2050 {
2054 Lisp_Object completions; 2051 Lisp_Object completions;
2055 2052
2056 message ("Making completion list..."); 2053 message ("Making completion list...");
2057 completions = Fall_completions (Fbuffer_string (), 2054 completions = Fall_completions (Ffield_string (ZV),
2058 Vminibuffer_completion_table, 2055 Vminibuffer_completion_table,
2059 Vminibuffer_completion_predicate, 2056 Vminibuffer_completion_predicate,
2060 Qt); 2057 Qt);
2061 clear_message (1, 0); 2058 clear_message (1, 0);
2062 2059
2103 If no minibuffer is active, return nil.") 2100 If no minibuffer is active, return nil.")
2104 () 2101 ()
2105 { 2102 {
2106 return Fcopy_sequence (minibuf_prompt); 2103 return Fcopy_sequence (minibuf_prompt);
2107 } 2104 }
2108
2109 DEFUN ("minibuffer-prompt-width", Fminibuffer_prompt_width,
2110 Sminibuffer_prompt_width, 0, 0, 0,
2111 "Return the display width of the minibuffer prompt.")
2112 ()
2113 {
2114 return make_number (minibuf_prompt_width);
2115 }
2116
2117
2118 DEFUN ("minibuffer-prompt-end", Fminibuffer_prompt_end,
2119 Sminibuffer_prompt_end, 0, 0, 0,
2120 "Return the end buffer position of the mini-buffer prompt.\n\
2121 Value is 0 if current buffer is not a mini-buffer.")
2122 ()
2123 {
2124 return (NILP (current_buffer->prompt_end_charpos)
2125 ? make_number (0)
2126 : make_number (current_buffer->prompt_end_charpos));
2127 }
2128
2129 2105
2130 2106
2131 /* Temporarily display the string M at the end of the current 2107 /* Temporarily display the string M at the end of the current
2132 minibuffer contents. This is used to display things like 2108 minibuffer contents. This is used to display things like
2133 "[No Match]" when the user requests a completion for a prefix 2109 "[No Match]" when the user requests a completion for a prefix
2340 defsubr (&Sread_variable); 2316 defsubr (&Sread_variable);
2341 defsubr (&Sread_buffer); 2317 defsubr (&Sread_buffer);
2342 defsubr (&Sread_no_blanks_input); 2318 defsubr (&Sread_no_blanks_input);
2343 defsubr (&Sminibuffer_depth); 2319 defsubr (&Sminibuffer_depth);
2344 defsubr (&Sminibuffer_prompt); 2320 defsubr (&Sminibuffer_prompt);
2345 defsubr (&Sminibuffer_prompt_width);
2346 defsubr (&Sminibuffer_prompt_end);
2347 2321
2348 defsubr (&Stry_completion); 2322 defsubr (&Stry_completion);
2349 defsubr (&Sall_completions); 2323 defsubr (&Sall_completions);
2350 defsubr (&Scompleting_read); 2324 defsubr (&Scompleting_read);
2351 defsubr (&Sminibuffer_complete); 2325 defsubr (&Sminibuffer_complete);