comparison src/minibuf.c @ 88155:d7ddb3e565de

sync with trunk
author Henrik Enberg <henrik.enberg@telia.com>
date Mon, 16 Jan 2006 00:03:54 +0000
parents 2123804d2bca
children
comparison
equal deleted inserted replaced
88154:8ce476d3ba36 88155:d7ddb3e565de
1 /* Minibuffer input and completion. 1 /* Minibuffer input and completion.
2 Copyright (C) 1985, 1986, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2 Copyright (C) 1985, 1986, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2000, 2001, 2003 Free Software Foundation, Inc. 3 2001, 2002, 2003, 2004, 2005 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
8 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 15 GNU General Public License for more details.
16 16
17 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to 18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02111-1307, USA. */ 20 Boston, MA 02110-1301, USA. */
21 21
22 22
23 #include <config.h> 23 #include <config.h>
24 #include <stdio.h> 24 #include <stdio.h>
25 25
59 59
60 /* The maximum length of a minibuffer history. */ 60 /* The maximum length of a minibuffer history. */
61 61
62 Lisp_Object Qhistory_length, Vhistory_length; 62 Lisp_Object Qhistory_length, Vhistory_length;
63 63
64 /* No duplicates in history. */
65
66 int history_delete_duplicates;
67
64 /* Fread_minibuffer leaves the input here as a string. */ 68 /* Fread_minibuffer leaves the input here as a string. */
65 69
66 Lisp_Object last_minibuf_string; 70 Lisp_Object last_minibuf_string;
67 71
68 /* Nonzero means let functions called when within a minibuffer 72 /* Nonzero means let functions called when within a minibuffer
128 Lisp_Object Quser_variable_p; 132 Lisp_Object Quser_variable_p;
129 133
130 Lisp_Object Qminibuffer_default; 134 Lisp_Object Qminibuffer_default;
131 135
132 Lisp_Object Qcurrent_input_method, Qactivate_input_method; 136 Lisp_Object Qcurrent_input_method, Qactivate_input_method;
137
138 Lisp_Object Qcase_fold_search;
133 139
134 extern Lisp_Object Qmouse_face; 140 extern Lisp_Object Qmouse_face;
135 141
136 extern Lisp_Object Qfield; 142 extern Lisp_Object Qfield;
137 143
157 /* Under X, we come here with minibuf_window being the 163 /* Under X, we come here with minibuf_window being the
158 minibuffer window of the unused termcap window created in 164 minibuffer window of the unused termcap window created in
159 init_window_once. That window doesn't have a buffer. */ 165 init_window_once. That window doesn't have a buffer. */
160 buffer = XWINDOW (minibuf_window)->buffer; 166 buffer = XWINDOW (minibuf_window)->buffer;
161 if (BUFFERP (buffer)) 167 if (BUFFERP (buffer))
162 Fset_window_buffer (sf->minibuffer_window, buffer); 168 Fset_window_buffer (sf->minibuffer_window, buffer, Qnil);
163 minibuf_window = sf->minibuffer_window; 169 minibuf_window = sf->minibuffer_window;
164 } 170 }
165 171
166 /* Make sure no other frame has a minibuffer as its selected window, 172 /* Make sure no other frame has a minibuffer as its selected window,
167 because the text would not be displayed in it, and that would be 173 because the text would not be displayed in it, and that would be
187 } 193 }
188 194
189 DEFUN ("set-minibuffer-window", Fset_minibuffer_window, 195 DEFUN ("set-minibuffer-window", Fset_minibuffer_window,
190 Sset_minibuffer_window, 1, 1, 0, 196 Sset_minibuffer_window, 1, 1, 0,
191 doc: /* Specify which minibuffer window to use for the minibuffer. 197 doc: /* Specify which minibuffer window to use for the minibuffer.
192 This effects where the minibuffer is displayed if you put text in it 198 This affects where the minibuffer is displayed if you put text in it
193 without invoking the usual minibuffer commands. */) 199 without invoking the usual minibuffer commands. */)
194 (window) 200 (window)
195 Lisp_Object window; 201 Lisp_Object window;
196 { 202 {
197 CHECK_WINDOW (window); 203 CHECK_WINDOW (window);
205 211
206 212
207 /* Actual minibuffer invocation. */ 213 /* Actual minibuffer invocation. */
208 214
209 static Lisp_Object read_minibuf_unwind P_ ((Lisp_Object)); 215 static Lisp_Object read_minibuf_unwind P_ ((Lisp_Object));
216 static Lisp_Object run_exit_minibuf_hook P_ ((Lisp_Object));
210 static Lisp_Object read_minibuf P_ ((Lisp_Object, Lisp_Object, 217 static Lisp_Object read_minibuf P_ ((Lisp_Object, Lisp_Object,
211 Lisp_Object, Lisp_Object, 218 Lisp_Object, Lisp_Object,
212 int, Lisp_Object, 219 int, Lisp_Object,
213 Lisp_Object, Lisp_Object, 220 Lisp_Object, Lisp_Object,
214 int, int)); 221 int, int, int));
215 static Lisp_Object read_minibuf_noninteractive P_ ((Lisp_Object, Lisp_Object, 222 static Lisp_Object read_minibuf_noninteractive P_ ((Lisp_Object, Lisp_Object,
216 Lisp_Object, Lisp_Object, 223 Lisp_Object, Lisp_Object,
217 int, Lisp_Object, 224 int, Lisp_Object,
218 Lisp_Object, Lisp_Object, 225 Lisp_Object, Lisp_Object,
219 int, int)); 226 int, int));
319 } 326 }
320 327
321 DEFUN ("minibufferp", Fminibufferp, 328 DEFUN ("minibufferp", Fminibufferp,
322 Sminibufferp, 0, 1, 0, 329 Sminibufferp, 0, 1, 0,
323 doc: /* Return t if BUFFER is a minibuffer. 330 doc: /* Return t if BUFFER is a minibuffer.
324 No argument or nil as argument means use current buffer as BUFFER.*/) 331 No argument or nil as argument means use current buffer as BUFFER.
332 BUFFER can be a buffer or a buffer name. */)
325 (buffer) 333 (buffer)
326 Lisp_Object buffer; 334 Lisp_Object buffer;
327 { 335 {
328 Lisp_Object tem; 336 Lisp_Object tem;
329 337
339 } 347 }
340 348
341 DEFUN ("minibuffer-prompt-end", Fminibuffer_prompt_end, 349 DEFUN ("minibuffer-prompt-end", Fminibuffer_prompt_end,
342 Sminibuffer_prompt_end, 0, 0, 0, 350 Sminibuffer_prompt_end, 0, 0, 0,
343 doc: /* Return the buffer position of the end of the minibuffer prompt. 351 doc: /* Return the buffer position of the end of the minibuffer prompt.
344 Return (point-min) if current buffer is not a mini-buffer. */) 352 Return (point-min) if current buffer is not a minibuffer. */)
345 () 353 ()
346 { 354 {
347 /* This function is written to be most efficient when there's a prompt. */ 355 /* This function is written to be most efficient when there's a prompt. */
348 Lisp_Object beg, end, tem; 356 Lisp_Object beg, end, tem;
349 beg = make_number (BEGV); 357 beg = make_number (BEGV);
378 { 386 {
379 int prompt_end = XINT (Fminibuffer_prompt_end ()); 387 int prompt_end = XINT (Fminibuffer_prompt_end ());
380 return make_buffer_string (prompt_end, ZV, 0); 388 return make_buffer_string (prompt_end, ZV, 0);
381 } 389 }
382 390
391 DEFUN ("minibuffer-completion-contents", Fminibuffer_completion_contents,
392 Sminibuffer_completion_contents, 0, 0, 0,
393 doc: /* Return the user input in a minibuffer before point as a string.
394 That is what completion commands operate on.
395 The current buffer must be a minibuffer. */)
396 ()
397 {
398 int prompt_end = XINT (Fminibuffer_prompt_end ());
399 if (PT < prompt_end)
400 error ("Cannot do completion in the prompt");
401 return make_buffer_string (prompt_end, PT, 1);
402 }
403
383 DEFUN ("delete-minibuffer-contents", Fdelete_minibuffer_contents, 404 DEFUN ("delete-minibuffer-contents", Fdelete_minibuffer_contents,
384 Sdelete_minibuffer_contents, 0, 0, 0, 405 Sdelete_minibuffer_contents, 0, 0, 0,
385 doc: /* Delete all user input in a minibuffer. 406 doc: /* Delete all user input in a minibuffer.
386 The current buffer must be a minibuffer. */) 407 The current buffer must be a minibuffer. */)
387 () 408 ()
390 if (prompt_end < ZV) 411 if (prompt_end < ZV)
391 del_range (prompt_end, ZV); 412 del_range (prompt_end, ZV);
392 return Qnil; 413 return Qnil;
393 } 414 }
394 415
395 /* Get the text in the minibuffer before point.
396 That is what completion commands operate on. */
397
398 Lisp_Object
399 minibuffer_completion_contents ()
400 {
401 int prompt_end = XINT (Fminibuffer_prompt_end ());
402 if (PT < prompt_end)
403 error ("Cannot do completion in the prompt");
404 return make_buffer_string (prompt_end, PT, 1);
405 }
406 416
407 /* Read from the minibuffer using keymap MAP, initial contents INITIAL 417 /* 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, 418 putting point minus BACKUP_N bytes from the end of INITIAL,
409 prompting with PROMPT (a string), using history list HISTVAR 419 prompting with PROMPT (a string), using history list HISTVAR
410 with initial position HISTPOS. (BACKUP_N should be <= 0.) 420 with initial position HISTPOS. INITIAL should be a string or a
421 cons of a string and an integer. BACKUP_N should be <= 0, or
422 Qnil, which is equivalent to 0. If INITIAL is a cons, BACKUP_N is
423 ignored and replaced with an integer that puts point at one-indexed
424 position N in INITIAL, where N is the CDR of INITIAL, or at the
425 beginning of INITIAL if N <= 0.
411 426
412 Normally return the result as a string (the text that was read), 427 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. 428 but if EXPFLAG is nonzero, read it and return the object read.
414 If HISTVAR is given, save the value read on that history only if it doesn't 429 If HISTVAR is given, save the value read on that history only if it doesn't
415 match the front of that history list exactly. The value is pushed onto 430 match the front of that history list exactly. The value is pushed onto
416 the list as the string that was read. 431 the list as the string that was read.
417 432
418 DEFALT specifies te default value for the sake of history commands. 433 DEFALT specifies the default value for the sake of history commands.
419 434
420 If ALLOW_PROPS is nonzero, we do not throw away text properties. 435 If ALLOW_PROPS is nonzero, we do not throw away text properties.
421 436
422 if INHERIT_INPUT_METHOD is nonzeor, the minibuffer inherit the 437 if INHERIT_INPUT_METHOD is nonzero, the minibuffer inherits the
423 current input method. */ 438 current input method. */
424 439
425 static Lisp_Object 440 static Lisp_Object
426 read_minibuf (map, initial, prompt, backup_n, expflag, 441 read_minibuf (map, initial, prompt, backup_n, expflag,
427 histvar, histpos, defalt, allow_props, inherit_input_method) 442 histvar, histpos, defalt, allow_props, inherit_input_method,
443 keep_all)
428 Lisp_Object map; 444 Lisp_Object map;
429 Lisp_Object initial; 445 Lisp_Object initial;
430 Lisp_Object prompt; 446 Lisp_Object prompt;
431 Lisp_Object backup_n; 447 Lisp_Object backup_n;
432 int expflag; 448 int expflag;
433 Lisp_Object histvar; 449 Lisp_Object histvar;
434 Lisp_Object histpos; 450 Lisp_Object histpos;
435 Lisp_Object defalt; 451 Lisp_Object defalt;
436 int allow_props; 452 int allow_props;
437 int inherit_input_method; 453 int inherit_input_method;
454 int keep_all;
438 { 455 {
439 Lisp_Object val; 456 Lisp_Object val;
440 int count = SPECPDL_INDEX (); 457 int count = SPECPDL_INDEX ();
441 Lisp_Object mini_frame, ambient_dir, minibuffer, input_method; 458 Lisp_Object mini_frame, ambient_dir, minibuffer, input_method;
442 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 459 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
443 Lisp_Object enable_multibyte; 460 Lisp_Object enable_multibyte;
461 int pos = INTEGERP (backup_n) ? XINT (backup_n) : 0;
462
463 /* String to add to the history. */
464 Lisp_Object histstring;
465
466 Lisp_Object empty_minibuf;
467 Lisp_Object dummy, frame;
468
444 extern Lisp_Object Qfront_sticky; 469 extern Lisp_Object Qfront_sticky;
445 extern Lisp_Object Qrear_nonsticky; 470 extern Lisp_Object Qrear_nonsticky;
446 471
447 specbind (Qminibuffer_default, defalt); 472 specbind (Qminibuffer_default, defalt);
448 473
450 #ifdef HAVE_X_WINDOWS 475 #ifdef HAVE_X_WINDOWS
451 if (display_hourglass_p) 476 if (display_hourglass_p)
452 cancel_hourglass (); 477 cancel_hourglass ();
453 #endif 478 #endif
454 479
480 if (!NILP (initial))
481 {
482 if (CONSP (initial))
483 {
484 backup_n = Fcdr (initial);
485 initial = Fcar (initial);
486 CHECK_STRING (initial);
487 if (!NILP (backup_n))
488 {
489 CHECK_NUMBER (backup_n);
490 /* Convert to distance from end of input. */
491 if (XINT (backup_n) < 1)
492 /* A number too small means the beginning of the string. */
493 pos = - SCHARS (initial);
494 else
495 pos = XINT (backup_n) - 1 - SCHARS (initial);
496 }
497 }
498 else
499 CHECK_STRING (initial);
500 }
455 val = Qnil; 501 val = Qnil;
456 ambient_dir = current_buffer->directory; 502 ambient_dir = current_buffer->directory;
457 input_method = Qnil; 503 input_method = Qnil;
458 enable_multibyte = Qnil; 504 enable_multibyte = Qnil;
459 505
476 build_string ("Command attempted to use minibuffer while in minibuffer")); 522 build_string ("Command attempted to use minibuffer while in minibuffer"));
477 } 523 }
478 524
479 if (noninteractive) 525 if (noninteractive)
480 { 526 {
481 val = read_minibuf_noninteractive (map, initial, prompt, backup_n, 527 val = read_minibuf_noninteractive (map, initial, prompt,
528 make_number (pos),
482 expflag, histvar, histpos, defalt, 529 expflag, histvar, histpos, defalt,
483 allow_props, inherit_input_method); 530 allow_props, inherit_input_method);
531 UNGCPRO;
484 return unbind_to (count, val); 532 return unbind_to (count, val);
485 } 533 }
486 534
487 /* Choose the minibuffer window and frame, and take action on them. */ 535 /* Choose the minibuffer window and frame, and take action on them. */
488 536
525 Fcons (Vminibuffer_history_variable, 573 Fcons (Vminibuffer_history_variable,
526 minibuf_save_list)))))); 574 minibuf_save_list))))));
527 575
528 record_unwind_protect (read_minibuf_unwind, Qnil); 576 record_unwind_protect (read_minibuf_unwind, Qnil);
529 minibuf_level++; 577 minibuf_level++;
578 /* We are exiting the minibuffer one way or the other, so run the hook.
579 It should be run before unwinding the minibuf settings. Do it
580 separately from read_minibuf_unwind because we need to make sure that
581 read_minibuf_unwind is fully executed even if exit-minibuffer-hook
582 signals an error. --Stef */
583 record_unwind_protect (run_exit_minibuf_hook, Qnil);
530 584
531 /* Now that we can restore all those variables, start changing them. */ 585 /* Now that we can restore all those variables, start changing them. */
532 586
533 minibuf_prompt_width = 0; 587 minibuf_prompt_width = 0;
534 minibuf_prompt = Fcopy_sequence (prompt); 588 minibuf_prompt = Fcopy_sequence (prompt);
546 600
547 /* Switch to the minibuffer. */ 601 /* Switch to the minibuffer. */
548 602
549 minibuffer = get_minibuffer (minibuf_level); 603 minibuffer = get_minibuffer (minibuf_level);
550 Fset_buffer (minibuffer); 604 Fset_buffer (minibuffer);
605
606 /* If appropriate, copy enable-multibyte-characters into the minibuffer. */
607 if (inherit_input_method)
608 current_buffer->enable_multibyte_characters = enable_multibyte;
551 609
552 /* The current buffer's default directory is usually the right thing 610 /* The current buffer's default directory is usually the right thing
553 for our minibuffer here. However, if you're typing a command at 611 for our minibuffer here. However, if you're typing a command at
554 a minibuffer-only frame when minibuf_level is zero, then buf IS 612 a minibuffer-only frame when minibuf_level is zero, then buf IS
555 the current_buffer, so reset_buffer leaves buf's default 613 the current_buffer, so reset_buffer leaves buf's default
582 Fredirect_frame_focus (selected_frame, mini_frame); 640 Fredirect_frame_focus (selected_frame, mini_frame);
583 641
584 Vminibuf_scroll_window = selected_window; 642 Vminibuf_scroll_window = selected_window;
585 if (minibuf_level == 1 || !EQ (minibuf_window, selected_window)) 643 if (minibuf_level == 1 || !EQ (minibuf_window, selected_window))
586 minibuf_selected_window = selected_window; 644 minibuf_selected_window = selected_window;
587 Fset_window_buffer (minibuf_window, Fcurrent_buffer ()); 645
588 Fselect_window (minibuf_window); 646 /* Empty out the minibuffers of all frames other than the one
647 where we are going to display one now.
648 Set them to point to ` *Minibuf-0*', which is always empty. */
649 empty_minibuf = Fget_buffer (build_string (" *Minibuf-0*"));
650
651 FOR_EACH_FRAME (dummy, frame)
652 {
653 Lisp_Object root_window = Fframe_root_window (frame);
654 Lisp_Object mini_window = XWINDOW (root_window)->next;
655
656 if (! NILP (mini_window) && !NILP (Fwindow_minibuffer_p (mini_window)))
657 Fset_window_buffer (mini_window, empty_minibuf, Qnil);
658 }
659
660 /* Display this minibuffer in the proper window. */
661 Fset_window_buffer (minibuf_window, Fcurrent_buffer (), Qnil);
662 Fselect_window (minibuf_window, Qnil);
589 XSETFASTINT (XWINDOW (minibuf_window)->hscroll, 0); 663 XSETFASTINT (XWINDOW (minibuf_window)->hscroll, 0);
590 664
591 Fmake_local_variable (Qprint_escape_newlines); 665 Fmake_local_variable (Qprint_escape_newlines);
592 print_escape_newlines = 1; 666 print_escape_newlines = 1;
593 667
618 Vminibuffer_prompt_properties, Qnil); 692 Vminibuffer_prompt_properties, Qnil);
619 } 693 }
620 694
621 minibuf_prompt_width = (int) current_column (); /* iftc */ 695 minibuf_prompt_width = (int) current_column (); /* iftc */
622 696
623 /* If appropriate, copy enable-multibyte-characters into the minibuffer. */
624 if (inherit_input_method)
625 current_buffer->enable_multibyte_characters = enable_multibyte;
626
627 /* Put in the initial input. */ 697 /* Put in the initial input. */
628 if (!NILP (initial)) 698 if (!NILP (initial))
629 { 699 {
630 Finsert (1, &initial); 700 Finsert (1, &initial);
631 if (INTEGERP (backup_n)) 701 Fforward_char (make_number (pos));
632 Fforward_char (backup_n);
633 } 702 }
634 703
635 clear_message (1, 1); 704 clear_message (1, 1);
636 current_buffer->keymap = map; 705 current_buffer->keymap = map;
637 706
673 742
674 /* VAL is the string of minibuffer text. */ 743 /* VAL is the string of minibuffer text. */
675 744
676 last_minibuf_string = val; 745 last_minibuf_string = val;
677 746
678 /* Add the value to the appropriate history list unless it is empty. */ 747 /* Choose the string to add to the history. */
679 if (SCHARS (val) != 0 748 if (SCHARS (val) != 0 || keep_all)
680 && SYMBOLP (Vminibuffer_history_variable)) 749 histstring = val;
750 else if (STRINGP (defalt))
751 histstring = defalt;
752 else
753 histstring = Qnil;
754
755 /* Add the value to the appropriate history list, if any. */
756 if (SYMBOLP (Vminibuffer_history_variable)
757 && !NILP (histstring))
681 { 758 {
682 /* If the caller wanted to save the value read on a history list, 759 /* If the caller wanted to save the value read on a history list,
683 then do so if the value is not already the front of the list. */ 760 then do so if the value is not already the front of the list. */
684 Lisp_Object histval; 761 Lisp_Object histval;
685 762
689 766
690 histval = Fsymbol_value (Vminibuffer_history_variable); 767 histval = Fsymbol_value (Vminibuffer_history_variable);
691 768
692 /* The value of the history variable must be a cons or nil. Other 769 /* The value of the history variable must be a cons or nil. Other
693 values are unacceptable. We silently ignore these values. */ 770 values are unacceptable. We silently ignore these values. */
771
694 if (NILP (histval) 772 if (NILP (histval)
695 || (CONSP (histval) 773 || (CONSP (histval)
696 && NILP (Fequal (last_minibuf_string, Fcar (histval))))) 774 /* Don't duplicate the most recent entry in the history. */
775 && (keep_all
776 || NILP (Fequal (histstring, Fcar (histval))))))
697 { 777 {
698 Lisp_Object length; 778 Lisp_Object length;
699 779
700 histval = Fcons (last_minibuf_string, histval); 780 if (history_delete_duplicates) Fdelete (histstring, histval);
781 histval = Fcons (histstring, histval);
701 Fset (Vminibuffer_history_variable, histval); 782 Fset (Vminibuffer_history_variable, histval);
702 783
703 /* Truncate if requested. */ 784 /* Truncate if requested. */
704 length = Fget (Vminibuffer_history_variable, Qhistory_length); 785 length = Fget (Vminibuffer_history_variable, Qhistory_length);
705 if (NILP (length)) length = Vhistory_length; 786 if (NILP (length)) length = Vhistory_length;
722 if (expflag) 803 if (expflag)
723 val = string_to_object (val, defalt); 804 val = string_to_object (val, defalt);
724 805
725 /* The appropriate frame will get selected 806 /* The appropriate frame will get selected
726 in set-window-configuration. */ 807 in set-window-configuration. */
727 RETURN_UNGCPRO (unbind_to (count, val)); 808 UNGCPRO;
809 return unbind_to (count, val);
728 } 810 }
729 811
730 /* Return a buffer to be used as the minibuffer at depth `depth'. 812 /* Return a buffer to be used as the minibuffer at depth `depth'.
731 depth = 0 is the lowest allowed argument, and that is the value 813 depth = 0 is the lowest allowed argument, and that is the value
732 used for nonrecursive minibuffer invocations */ 814 used for nonrecursive minibuffer invocations */
759 XSETCAR (tail, buf); 841 XSETCAR (tail, buf);
760 } 842 }
761 else 843 else
762 { 844 {
763 int count = SPECPDL_INDEX (); 845 int count = SPECPDL_INDEX ();
764 846 /* `reset_buffer' blindly sets the list of overlays to NULL, so we
847 have to empty the list, otherwise we end up with overlays that
848 think they belong to this buffer while the buffer doesn't know about
849 them any more. */
850 delete_all_overlays (XBUFFER (buf));
765 reset_buffer (XBUFFER (buf)); 851 reset_buffer (XBUFFER (buf));
766 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); 852 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
767 Fset_buffer (buf); 853 Fset_buffer (buf);
768 Fkill_all_local_variables (); 854 Fkill_all_local_variables ();
769 unbind_to (count, Qnil); 855 unbind_to (count, Qnil);
770 } 856 }
771 857
772 return buf; 858 return buf;
773 } 859 }
774 860
861 static Lisp_Object
862 run_exit_minibuf_hook (data)
863 Lisp_Object data;
864 {
865 if (!NILP (Vminibuffer_exit_hook) && !EQ (Vminibuffer_exit_hook, Qunbound)
866 && !NILP (Vrun_hooks))
867 safe_run_hooks (Qminibuffer_exit_hook);
868
869 return Qnil;
870 }
871
775 /* This function is called on exiting minibuffer, whether normally or 872 /* This function is called on exiting minibuffer, whether normally or
776 not, and it restores the current window, buffer, etc. */ 873 not, and it restores the current window, buffer, etc. */
777 874
778 static Lisp_Object 875 static Lisp_Object
779 read_minibuf_unwind (data) 876 read_minibuf_unwind (data)
780 Lisp_Object data; 877 Lisp_Object data;
781 { 878 {
782 Lisp_Object old_deactivate_mark; 879 Lisp_Object old_deactivate_mark;
783 Lisp_Object window; 880 Lisp_Object window;
784
785 /* We are exiting the minibuffer one way or the other,
786 so run the hook. */
787 if (!NILP (Vminibuffer_exit_hook) && !EQ (Vminibuffer_exit_hook, Qunbound)
788 && !NILP (Vrun_hooks))
789 safe_run_hooks (Qminibuffer_exit_hook);
790 881
791 /* If this was a recursive minibuffer, 882 /* If this was a recursive minibuffer,
792 tie the minibuffer window back to the outer level minibuffer buffer. */ 883 tie the minibuffer window back to the outer level minibuffer buffer. */
793 minibuf_level--; 884 minibuf_level--;
794 885
842 XSETFASTINT (XWINDOW (window)->last_overlay_modified, 0); 933 XSETFASTINT (XWINDOW (window)->last_overlay_modified, 0);
843 return Qnil; 934 return Qnil;
844 } 935 }
845 936
846 937
847 DEFUN ("read-from-minibuffer", Fread_from_minibuffer, Sread_from_minibuffer, 1, 7, 0, 938 DEFUN ("read-from-minibuffer", Fread_from_minibuffer, Sread_from_minibuffer, 1, 8, 0,
848 doc: /* Read a string from the minibuffer, prompting with string PROMPT. 939 doc: /* Read a string from the minibuffer, prompting with string PROMPT.
849 If optional second arg INITIAL-CONTENTS is non-nil, it is a string 940 The optional second arg INITIAL-CONTENTS is an obsolete alternative to
850 to be inserted into the minibuffer before reading input. 941 DEFAULT-VALUE. It normally should be nil in new code, except when
851 If INITIAL-CONTENTS is (STRING . POSITION), the initial input 942 HIST is a cons. It is discussed in more detail below.
852 is STRING, but point is placed at position POSITION in the minibuffer.
853 Third arg KEYMAP is a keymap to use whilst reading; 943 Third arg KEYMAP is a keymap to use whilst reading;
854 if omitted or nil, the default is `minibuffer-local-map'. 944 if omitted or nil, the default is `minibuffer-local-map'.
855 If fourth arg READ is non-nil, then interpret the result as a Lisp object 945 If fourth arg READ is non-nil, then interpret the result as a Lisp object
856 and return that object: 946 and return that object:
857 in other words, do `(car (read-from-string INPUT-STRING))' 947 in other words, do `(car (read-from-string INPUT-STRING))'
858 Fifth arg HIST, if non-nil, specifies a history list 948 Fifth arg HIST, if non-nil, specifies a history list and optionally
859 and optionally the initial position in the list. 949 the initial position in the list. It can be a symbol, which is the
860 It can be a symbol, which is the history list variable to use, 950 history list variable to use, or it can be a cons cell
861 or it can be a cons cell (HISTVAR . HISTPOS). 951 (HISTVAR . HISTPOS). In that case, HISTVAR is the history list variable
862 In that case, HISTVAR is the history list variable to use, 952 to use, and HISTPOS is the initial position for use by the minibuffer
863 and HISTPOS is the initial position (the position in the list 953 history commands. For consistency, you should also specify that
864 which INITIAL-CONTENTS corresponds to). 954 element of the history as the value of INITIAL-CONTENTS. Positions
865 Positions are counted starting from 1 at the beginning of the list. 955 are counted starting from 1 at the beginning of the list.
866 Sixth arg DEFAULT-VALUE is the default value. If non-nil, it is available 956 Sixth arg DEFAULT-VALUE is the default value. If non-nil, it is available
867 for history commands; but `read-from-minibuffer' does NOT return DEFAULT-VALUE 957 for history commands; but, unless READ is non-nil, `read-from-minibuffer'
868 if the user enters empty input! It returns the empty string. 958 does NOT return DEFAULT-VALUE if the user enters empty input! It returns
959 the empty string.
869 Seventh arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits 960 Seventh arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits
870 the current input method and the setting of `enable-multibyte-characters'. 961 the current input method and the setting of `enable-multibyte-characters'.
962 Eight arg KEEP-ALL, if non-nil, says to put all inputs in the history list,
963 even empty or duplicate inputs.
871 If the variable `minibuffer-allow-text-properties' is non-nil, 964 If the variable `minibuffer-allow-text-properties' is non-nil,
872 then the string which is returned includes whatever text properties 965 then the string which is returned includes whatever text properties
873 were present in the minibuffer. Otherwise the value has no text properties. */) 966 were present in the minibuffer. Otherwise the value has no text properties.
874 (prompt, initial_contents, keymap, read, hist, default_value, inherit_input_method) 967
968 The remainder of this documentation string describes the
969 INITIAL-CONTENTS argument in more detail. It is only relevant when
970 studying existing code, or when HIST is a cons. If non-nil,
971 INITIAL-CONTENTS is a string to be inserted into the minibuffer before
972 reading input. Normally, point is put at the end of that string.
973 However, if INITIAL-CONTENTS is \(STRING . POSITION), the initial
974 input is STRING, but point is placed at _one-indexed_ position
975 POSITION in the minibuffer. Any integer value less than or equal to
976 one puts point at the beginning of the string. *Note* that this
977 behavior differs from the way such arguments are used in `completing-read'
978 and some related functions, which use zero-indexing for POSITION. */)
979 (prompt, initial_contents, keymap, read, hist, default_value, inherit_input_method, keep_all)
875 Lisp_Object prompt, initial_contents, keymap, read, hist, default_value; 980 Lisp_Object prompt, initial_contents, keymap, read, hist, default_value;
876 Lisp_Object inherit_input_method; 981 Lisp_Object inherit_input_method, keep_all;
877 { 982 {
878 int pos = 0; 983 Lisp_Object histvar, histpos, val;
879 Lisp_Object histvar, histpos, position, val;
880 struct gcpro gcpro1; 984 struct gcpro gcpro1;
881 985
882 position = Qnil;
883
884 CHECK_STRING (prompt); 986 CHECK_STRING (prompt);
885 if (!NILP (initial_contents))
886 {
887 if (CONSP (initial_contents))
888 {
889 position = Fcdr (initial_contents);
890 initial_contents = Fcar (initial_contents);
891 }
892 CHECK_STRING (initial_contents);
893 if (!NILP (position))
894 {
895 CHECK_NUMBER (position);
896 /* Convert to distance from end of input. */
897 if (XINT (position) < 1)
898 /* A number too small means the beginning of the string. */
899 pos = - SCHARS (initial_contents);
900 else
901 pos = XINT (position) - 1 - SCHARS (initial_contents);
902 }
903 }
904
905 if (NILP (keymap)) 987 if (NILP (keymap))
906 keymap = Vminibuffer_local_map; 988 keymap = Vminibuffer_local_map;
907 else 989 else
908 keymap = get_keymap (keymap, 1, 0); 990 keymap = get_keymap (keymap, 1, 0);
909 991
922 if (NILP (histpos)) 1004 if (NILP (histpos))
923 XSETFASTINT (histpos, 0); 1005 XSETFASTINT (histpos, 0);
924 1006
925 GCPRO1 (default_value); 1007 GCPRO1 (default_value);
926 val = read_minibuf (keymap, initial_contents, prompt, 1008 val = read_minibuf (keymap, initial_contents, prompt,
927 make_number (pos), !NILP (read), 1009 Qnil, !NILP (read),
928 histvar, histpos, default_value, 1010 histvar, histpos, default_value,
929 minibuffer_allow_text_properties, 1011 minibuffer_allow_text_properties,
930 !NILP (inherit_input_method)); 1012 !NILP (inherit_input_method),
1013 !NILP (keep_all));
931 UNGCPRO; 1014 UNGCPRO;
932 return val; 1015 return val;
933 } 1016 }
934 1017
935 DEFUN ("read-minibuffer", Fread_minibuffer, Sread_minibuffer, 1, 2, 0, 1018 DEFUN ("read-minibuffer", Fread_minibuffer, Sread_minibuffer, 1, 2, 0,
936 doc: /* Return a Lisp object read using the minibuffer. 1019 doc: /* Return a Lisp object read using the minibuffer, unevaluated.
937 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS 1020 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS
938 is a string to insert in the minibuffer before reading. */) 1021 is a string to insert in the minibuffer before reading.
1022 \(INITIAL-CONTENTS can also be a cons of a string and an integer. Such
1023 arguments are used as in `read-from-minibuffer') */)
939 (prompt, initial_contents) 1024 (prompt, initial_contents)
940 Lisp_Object prompt, initial_contents; 1025 Lisp_Object prompt, initial_contents;
941 { 1026 {
942 CHECK_STRING (prompt); 1027 CHECK_STRING (prompt);
943 if (!NILP (initial_contents))
944 CHECK_STRING (initial_contents);
945 return read_minibuf (Vminibuffer_local_map, initial_contents, 1028 return read_minibuf (Vminibuffer_local_map, initial_contents,
946 prompt, Qnil, 1, Qminibuffer_history, 1029 prompt, Qnil, 1, Qminibuffer_history,
947 make_number (0), Qnil, 0, 0); 1030 make_number (0), Qnil, 0, 0, 0);
948 } 1031 }
949 1032
950 DEFUN ("eval-minibuffer", Feval_minibuffer, Seval_minibuffer, 1, 2, 0, 1033 DEFUN ("eval-minibuffer", Feval_minibuffer, Seval_minibuffer, 1, 2, 0,
951 doc: /* Return value of Lisp expression read using the minibuffer. 1034 doc: /* Return value of Lisp expression read using the minibuffer.
952 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS 1035 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS
953 is a string to insert in the minibuffer before reading. */) 1036 is a string to insert in the minibuffer before reading.
1037 \(INITIAL-CONTENTS can also be a cons of a string and an integer. Such
1038 arguments are used as in `read-from-minibuffer'.) */)
954 (prompt, initial_contents) 1039 (prompt, initial_contents)
955 Lisp_Object prompt, initial_contents; 1040 Lisp_Object prompt, initial_contents;
956 { 1041 {
957 return Feval (Fread_minibuffer (prompt, initial_contents)); 1042 return Feval (Fread_minibuffer (prompt, initial_contents));
958 } 1043 }
960 /* Functions that use the minibuffer to read various things. */ 1045 /* Functions that use the minibuffer to read various things. */
961 1046
962 DEFUN ("read-string", Fread_string, Sread_string, 1, 5, 0, 1047 DEFUN ("read-string", Fread_string, Sread_string, 1, 5, 0,
963 doc: /* Read a string from the minibuffer, prompting with string PROMPT. 1048 doc: /* Read a string from the minibuffer, prompting with string PROMPT.
964 If non-nil, second arg INITIAL-INPUT is a string to insert before reading. 1049 If non-nil, second arg INITIAL-INPUT is a string to insert before reading.
1050 This argument has been superseded by DEFAULT-VALUE and should normally
1051 be nil in new code. It behaves as in `read-from-minibuffer'. See the
1052 documentation string of that function for details.
965 The third arg HISTORY, if non-nil, specifies a history list 1053 The third arg HISTORY, if non-nil, specifies a history list
966 and optionally the initial position in the list. 1054 and optionally the initial position in the list.
967 See `read-from-minibuffer' for details of HISTORY argument. 1055 See `read-from-minibuffer' for details of HISTORY argument.
968 Fourth arg DEFAULT-VALUE is the default value. If non-nil, it is used 1056 Fourth arg DEFAULT-VALUE is the default value. If non-nil, it is used
969 for history commands, and as the value to return if the user enters 1057 for history commands, and as the value to return if the user enters
975 Lisp_Object inherit_input_method; 1063 Lisp_Object inherit_input_method;
976 { 1064 {
977 Lisp_Object val; 1065 Lisp_Object val;
978 val = Fread_from_minibuffer (prompt, initial_input, Qnil, 1066 val = Fread_from_minibuffer (prompt, initial_input, Qnil,
979 Qnil, history, default_value, 1067 Qnil, history, default_value,
980 inherit_input_method); 1068 inherit_input_method, Qnil);
981 if (STRINGP (val) && SCHARS (val) == 0 && ! NILP (default_value)) 1069 if (STRINGP (val) && SCHARS (val) == 0 && ! NILP (default_value))
982 val = default_value; 1070 val = default_value;
983 return val; 1071 return val;
984 } 1072 }
985 1073
986 DEFUN ("read-no-blanks-input", Fread_no_blanks_input, Sread_no_blanks_input, 1, 3, 0, 1074 DEFUN ("read-no-blanks-input", Fread_no_blanks_input, Sread_no_blanks_input, 1, 3, 0,
987 doc: /* Read a string from the terminal, not allowing blanks. 1075 doc: /* Read a string from the terminal, not allowing blanks.
988 Prompt with PROMPT, and provide INITIAL as an initial value of the input string. 1076 Prompt with PROMPT. Whitespace terminates the input. If INITIAL is
1077 non-nil, it should be a string, which is used as initial input, with
1078 point positioned at the end, so that SPACE will accept the input.
1079 \(Actually, INITIAL can also be a cons of a string and an integer.
1080 Such values are treated as in `read-from-minibuffer', but are normally
1081 not useful in this function.)
989 Third arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits 1082 Third arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits
990 the current input method and the setting of `enable-multibyte-characters'. */) 1083 the current input method and the setting of`enable-multibyte-characters'. */)
991 (prompt, initial, inherit_input_method) 1084 (prompt, initial, inherit_input_method)
992 Lisp_Object prompt, initial, inherit_input_method; 1085 Lisp_Object prompt, initial, inherit_input_method;
993 { 1086 {
994 CHECK_STRING (prompt); 1087 CHECK_STRING (prompt);
995 if (! NILP (initial))
996 CHECK_STRING (initial);
997
998 return read_minibuf (Vminibuffer_local_ns_map, initial, prompt, Qnil, 1088 return read_minibuf (Vminibuffer_local_ns_map, initial, prompt, Qnil,
999 0, Qminibuffer_history, make_number (0), Qnil, 0, 1089 0, Qminibuffer_history, make_number (0), Qnil, 0,
1000 !NILP (inherit_input_method)); 1090 !NILP (inherit_input_method), 0);
1001 } 1091 }
1002 1092
1003 DEFUN ("read-command", Fread_command, Sread_command, 1, 2, 0, 1093 DEFUN ("read-command", Fread_command, Sread_command, 1, 2, 0,
1004 doc: /* Read the name of a command and return as a symbol. 1094 doc: /* Read the name of a command and return as a symbol.
1005 Prompt with PROMPT. By default, return DEFAULT-VALUE. */) 1095 Prompt with PROMPT. By default, return DEFAULT-VALUE. */)
1061 DEFUN ("read-buffer", Fread_buffer, Sread_buffer, 1, 3, 0, 1151 DEFUN ("read-buffer", Fread_buffer, Sread_buffer, 1, 3, 0,
1062 doc: /* Read the name of a buffer and return as a string. 1152 doc: /* Read the name of a buffer and return as a string.
1063 Prompt with PROMPT. 1153 Prompt with PROMPT.
1064 Optional second arg DEF is value to return if user enters an empty line. 1154 Optional second arg DEF is value to return if user enters an empty line.
1065 If optional third arg REQUIRE-MATCH is non-nil, 1155 If optional third arg REQUIRE-MATCH is non-nil,
1066 only existing buffer names are allowed. */) 1156 only existing buffer names are allowed.
1157 The argument PROMPT should be a string ending with a colon and a space. */)
1067 (prompt, def, require_match) 1158 (prompt, def, require_match)
1068 Lisp_Object prompt, def, require_match; 1159 Lisp_Object prompt, def, require_match;
1069 { 1160 {
1070 Lisp_Object args[4]; 1161 Lisp_Object args[4];
1162 unsigned char *s;
1163 int len;
1071 1164
1072 if (BUFFERP (def)) 1165 if (BUFFERP (def))
1073 def = XBUFFER (def)->name; 1166 def = XBUFFER (def)->name;
1074 1167
1075 if (NILP (Vread_buffer_function)) 1168 if (NILP (Vread_buffer_function))
1076 { 1169 {
1077 if (!NILP (def)) 1170 if (!NILP (def))
1078 { 1171 {
1079 args[0] = build_string ("%s(default %s) "); 1172 /* A default value was provided: we must change PROMPT,
1173 editing the default value in before the colon. To achieve
1174 this, we replace PROMPT with a substring that doesn't
1175 contain the terminal space and colon (if present). They
1176 are then added back using Fformat. */
1177
1178 if (STRINGP (prompt))
1179 {
1180 s = SDATA (prompt);
1181 len = strlen (s);
1182 if (len >= 2 && s[len - 2] == ':' && s[len - 1] == ' ')
1183 len = len - 2;
1184 else if (len >= 1 && (s[len - 1] == ':' || s[len - 1] == ' '))
1185 len--;
1186
1187 prompt = make_specified_string (s, -1, len,
1188 STRING_MULTIBYTE (prompt));
1189 }
1190
1191 args[0] = build_string ("%s (default %s): ");
1080 args[1] = prompt; 1192 args[1] = prompt;
1081 args[2] = def; 1193 args[2] = def;
1082 prompt = Fformat (3, args); 1194 prompt = Fformat (3, args);
1083 } 1195 }
1084 1196
1109 return Fstring_make_multibyte (string); 1221 return Fstring_make_multibyte (string);
1110 } 1222 }
1111 1223
1112 DEFUN ("try-completion", Ftry_completion, Stry_completion, 2, 3, 0, 1224 DEFUN ("try-completion", Ftry_completion, Stry_completion, 2, 3, 0,
1113 doc: /* Return common substring of all completions of STRING in ALIST. 1225 doc: /* Return common substring of all completions of STRING in ALIST.
1114 Each car of each element of ALIST is tested to see if it begins with STRING. 1226 Each car of each element of ALIST (or each element if it is not a cons cell)
1227 is tested to see if it begins with STRING. The possible matches may be
1228 strings or symbols. Symbols are converted to strings before testing,
1229 see `symbol-name'.
1115 All that match are compared together; the longest initial sequence 1230 All that match are compared together; the longest initial sequence
1116 common to all matches is returned as a string. 1231 common to all matches is returned as a string.
1117 If there is no match at all, nil is returned. 1232 If there is no match at all, nil is returned.
1118 For a unique match which is exact, t is returned. 1233 For a unique match which is exact, t is returned.
1119 1234
1120 If ALIST is a hash-table, all the string keys are the possible matches. 1235 If ALIST is a hash-table, all the string and symbol keys are the
1236 possible matches.
1121 If ALIST is an obarray, the names of all symbols in the obarray 1237 If ALIST is an obarray, the names of all symbols in the obarray
1122 are the possible matches. 1238 are the possible matches.
1123 1239
1124 ALIST can also be a function to do the completion itself. 1240 ALIST can also be a function to do the completion itself.
1125 It receives three arguments: the values STRING, PREDICATE and nil. 1241 It receives three arguments: the values STRING, PREDICATE and nil.
1139 Lisp_Object bestmatch, tail, elt, eltstring; 1255 Lisp_Object bestmatch, tail, elt, eltstring;
1140 /* Size in bytes of BESTMATCH. */ 1256 /* Size in bytes of BESTMATCH. */
1141 int bestmatchsize = 0; 1257 int bestmatchsize = 0;
1142 /* These are in bytes, too. */ 1258 /* These are in bytes, too. */
1143 int compare, matchsize; 1259 int compare, matchsize;
1144 int type = HASH_TABLE_P (alist) ? 3 1260 int type = (HASH_TABLE_P (alist) ? 3
1145 : VECTORP (alist) ? 2 1261 : VECTORP (alist) ? 2
1146 : NILP (alist) || (CONSP (alist) 1262 : NILP (alist) || (CONSP (alist)
1147 && (!SYMBOLP (XCAR (alist)) 1263 && (!SYMBOLP (XCAR (alist))
1148 || NILP (XCAR (alist)))); 1264 || NILP (XCAR (alist)))));
1149 int index = 0, obsize = 0; 1265 int index = 0, obsize = 0;
1150 int matchcount = 0; 1266 int matchcount = 0;
1267 int bindcount = -1;
1151 Lisp_Object bucket, zero, end, tem; 1268 Lisp_Object bucket, zero, end, tem;
1152 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 1269 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
1153 1270
1154 CHECK_STRING (string); 1271 CHECK_STRING (string);
1155 if (type == 0) 1272 if (type == 0)
1156 return call3 (alist, string, predicate, Qnil); 1273 return call3 (alist, string, predicate, Qnil);
1157 1274
1158 bestmatch = bucket = Qnil; 1275 bestmatch = bucket = Qnil;
1276 zero = make_number (0);
1159 1277
1160 /* If ALIST is not a list, set TAIL just for gc pro. */ 1278 /* If ALIST is not a list, set TAIL just for gc pro. */
1161 tail = alist; 1279 tail = alist;
1162 if (type == 2) 1280 if (type == 2)
1163 { 1281 {
1180 eltstring = CONSP (elt) ? XCAR (elt) : elt; 1298 eltstring = CONSP (elt) ? XCAR (elt) : elt;
1181 tail = XCDR (tail); 1299 tail = XCDR (tail);
1182 } 1300 }
1183 else if (type == 2) 1301 else if (type == 2)
1184 { 1302 {
1185 if (XFASTINT (bucket) != 0) 1303 if (!EQ (bucket, zero))
1186 { 1304 {
1187 elt = bucket; 1305 elt = bucket;
1188 eltstring = Fsymbol_name (elt); 1306 eltstring = elt;
1189 if (XSYMBOL (bucket)->next) 1307 if (XSYMBOL (bucket)->next)
1190 XSETSYMBOL (bucket, XSYMBOL (bucket)->next); 1308 XSETSYMBOL (bucket, XSYMBOL (bucket)->next);
1191 else 1309 else
1192 XSETFASTINT (bucket, 0); 1310 XSETFASTINT (bucket, 0);
1193 } 1311 }
1210 elt = eltstring = HASH_KEY (XHASH_TABLE (alist), index++); 1328 elt = eltstring = HASH_KEY (XHASH_TABLE (alist), index++);
1211 } 1329 }
1212 1330
1213 /* Is this element a possible completion? */ 1331 /* Is this element a possible completion? */
1214 1332
1333 if (SYMBOLP (eltstring))
1334 eltstring = Fsymbol_name (eltstring);
1335
1215 if (STRINGP (eltstring) 1336 if (STRINGP (eltstring)
1216 && SCHARS (string) <= SCHARS (eltstring) 1337 && SCHARS (string) <= SCHARS (eltstring)
1217 && (tem = Fcompare_strings (eltstring, make_number (0), 1338 && (tem = Fcompare_strings (eltstring, zero,
1218 make_number (SCHARS (string)), 1339 make_number (SCHARS (string)),
1219 string, make_number (0), Qnil, 1340 string, zero, Qnil,
1220 completion_ignore_case ?Qt : Qnil), 1341 completion_ignore_case ? Qt : Qnil),
1221 EQ (Qt, tem))) 1342 EQ (Qt, tem)))
1222 { 1343 {
1223 /* Yes. */ 1344 /* Yes. */
1224 Lisp_Object regexps; 1345 Lisp_Object regexps;
1225 Lisp_Object zero;
1226 XSETFASTINT (zero, 0);
1227 1346
1228 /* Ignore this element if it fails to match all the regexps. */ 1347 /* Ignore this element if it fails to match all the regexps. */
1229 for (regexps = Vcompletion_regexp_list; CONSP (regexps); 1348 {
1230 regexps = XCDR (regexps)) 1349 for (regexps = Vcompletion_regexp_list; CONSP (regexps);
1231 { 1350 regexps = XCDR (regexps))
1232 tem = Fstring_match (XCAR (regexps), eltstring, zero); 1351 {
1233 if (NILP (tem)) 1352 if (bindcount < 0) {
1234 break; 1353 bindcount = SPECPDL_INDEX ();
1235 } 1354 specbind (Qcase_fold_search,
1236 if (CONSP (regexps)) 1355 completion_ignore_case ? Qt : Qnil);
1237 continue; 1356 }
1357 tem = Fstring_match (XCAR (regexps), eltstring, zero);
1358 if (NILP (tem))
1359 break;
1360 }
1361 if (CONSP (regexps))
1362 continue;
1363 }
1238 1364
1239 /* Ignore this element if there is a predicate 1365 /* Ignore this element if there is a predicate
1240 and the predicate doesn't like it. */ 1366 and the predicate doesn't like it. */
1241 1367
1242 if (!NILP (predicate)) 1368 if (!NILP (predicate))
1243 { 1369 {
1244 if (EQ (predicate, Qcommandp)) 1370 if (EQ (predicate, Qcommandp))
1245 tem = Fcommandp (elt, Qnil); 1371 tem = Fcommandp (elt, Qnil);
1246 else 1372 else
1247 { 1373 {
1374 if (bindcount >= 0) {
1375 unbind_to (bindcount, Qnil);
1376 bindcount = -1;
1377 }
1248 GCPRO4 (tail, string, eltstring, bestmatch); 1378 GCPRO4 (tail, string, eltstring, bestmatch);
1249 tem = type == 3 1379 tem = type == 3
1250 ? call2 (predicate, elt, 1380 ? call2 (predicate, elt,
1251 HASH_VALUE (XHASH_TABLE (alist), index - 1)) 1381 HASH_VALUE (XHASH_TABLE (alist), index - 1))
1252 : call1 (predicate, elt); 1382 : call1 (predicate, elt);
1264 bestmatchsize = SCHARS (eltstring); 1394 bestmatchsize = SCHARS (eltstring);
1265 } 1395 }
1266 else 1396 else
1267 { 1397 {
1268 compare = min (bestmatchsize, SCHARS (eltstring)); 1398 compare = min (bestmatchsize, SCHARS (eltstring));
1269 tem = Fcompare_strings (bestmatch, make_number (0), 1399 tem = Fcompare_strings (bestmatch, zero,
1270 make_number (compare), 1400 make_number (compare),
1271 eltstring, make_number (0), 1401 eltstring, zero,
1272 make_number (compare), 1402 make_number (compare),
1273 completion_ignore_case ? Qt : Qnil); 1403 completion_ignore_case ? Qt : Qnil);
1274 if (EQ (tem, Qt)) 1404 if (EQ (tem, Qt))
1275 matchsize = compare; 1405 matchsize = compare;
1276 else if (XINT (tem) < 0) 1406 else if (XINT (tem) < 0)
1297 prefer a match that does not change the case 1427 prefer a match that does not change the case
1298 of the input. */ 1428 of the input. */
1299 ((matchsize == SCHARS (eltstring)) 1429 ((matchsize == SCHARS (eltstring))
1300 == 1430 ==
1301 (matchsize == SCHARS (bestmatch)) 1431 (matchsize == SCHARS (bestmatch))
1302 && (tem = Fcompare_strings (eltstring, make_number (0), 1432 && (tem = Fcompare_strings (eltstring, zero,
1303 make_number (SCHARS (string)), 1433 make_number (SCHARS (string)),
1304 string, make_number (0), 1434 string, zero,
1305 Qnil, 1435 Qnil,
1306 Qnil), 1436 Qnil),
1307 EQ (Qt, tem)) 1437 EQ (Qt, tem))
1308 && (tem = Fcompare_strings (bestmatch, make_number (0), 1438 && (tem = Fcompare_strings (bestmatch, zero,
1309 make_number (SCHARS (string)), 1439 make_number (SCHARS (string)),
1310 string, make_number (0), 1440 string, zero,
1311 Qnil, 1441 Qnil,
1312 Qnil), 1442 Qnil),
1313 ! EQ (Qt, tem)))) 1443 ! EQ (Qt, tem))))
1314 bestmatch = eltstring; 1444 bestmatch = eltstring;
1315 } 1445 }
1324 break; 1454 break;
1325 } 1455 }
1326 } 1456 }
1327 } 1457 }
1328 1458
1459 if (bindcount >= 0) {
1460 unbind_to (bindcount, Qnil);
1461 bindcount = -1;
1462 }
1463
1329 if (NILP (bestmatch)) 1464 if (NILP (bestmatch))
1330 return Qnil; /* No completions found */ 1465 return Qnil; /* No completions found */
1331 /* If we are ignoring case, and there is no exact match, 1466 /* If we are ignoring case, and there is no exact match,
1332 and no additional text was supplied, 1467 and no additional text was supplied,
1333 don't change the case of what the user typed. */ 1468 don't change the case of what the user typed. */
1351 return Fsubstring (bestmatch, zero, end); 1486 return Fsubstring (bestmatch, zero, end);
1352 } 1487 }
1353 1488
1354 DEFUN ("all-completions", Fall_completions, Sall_completions, 2, 4, 0, 1489 DEFUN ("all-completions", Fall_completions, Sall_completions, 2, 4, 0,
1355 doc: /* Search for partial matches to STRING in ALIST. 1490 doc: /* Search for partial matches to STRING in ALIST.
1356 Each car of each element of ALIST is tested to see if it begins with STRING. 1491 Each car of each element of ALIST (or each element if it is not a cons cell)
1492 is tested to see if it begins with STRING. The possible matches may be
1493 strings or symbols. Symbols are converted to strings before testing,
1494 see `symbol-name'.
1357 The value is a list of all the strings from ALIST that match. 1495 The value is a list of all the strings from ALIST that match.
1358 1496
1359 If ALIST is a hash-table, all the string keys are the possible matches. 1497 If ALIST is a hash-table, all the string and symbol keys are the
1498 possible matches.
1360 If ALIST is an obarray, the names of all symbols in the obarray 1499 If ALIST is an obarray, the names of all symbols in the obarray
1361 are the possible matches. 1500 are the possible matches.
1362 1501
1363 ALIST can also be a function to do the completion itself. 1502 ALIST can also be a function to do the completion itself.
1364 It receives three arguments: the values STRING, PREDICATE and t. 1503 It receives three arguments: the values STRING, PREDICATE and t.
1385 : VECTORP (alist) ? 2 1524 : VECTORP (alist) ? 2
1386 : NILP (alist) || (CONSP (alist) 1525 : NILP (alist) || (CONSP (alist)
1387 && (!SYMBOLP (XCAR (alist)) 1526 && (!SYMBOLP (XCAR (alist))
1388 || NILP (XCAR (alist)))); 1527 || NILP (XCAR (alist))));
1389 int index = 0, obsize = 0; 1528 int index = 0, obsize = 0;
1390 Lisp_Object bucket, tem; 1529 int bindcount = -1;
1530 Lisp_Object bucket, tem, zero;
1391 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 1531 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
1392 1532
1393 CHECK_STRING (string); 1533 CHECK_STRING (string);
1394 if (type == 0) 1534 if (type == 0)
1395 return call3 (alist, string, predicate, Qt); 1535 return call3 (alist, string, predicate, Qt);
1396 allmatches = bucket = Qnil; 1536 allmatches = bucket = Qnil;
1537 zero = make_number (0);
1397 1538
1398 /* If ALIST is not a list, set TAIL just for gc pro. */ 1539 /* If ALIST is not a list, set TAIL just for gc pro. */
1399 tail = alist; 1540 tail = alist;
1400 if (type == 2) 1541 if (type == 2)
1401 { 1542 {
1418 eltstring = CONSP (elt) ? XCAR (elt) : elt; 1559 eltstring = CONSP (elt) ? XCAR (elt) : elt;
1419 tail = XCDR (tail); 1560 tail = XCDR (tail);
1420 } 1561 }
1421 else if (type == 2) 1562 else if (type == 2)
1422 { 1563 {
1423 if (XFASTINT (bucket) != 0) 1564 if (!EQ (bucket, zero))
1424 { 1565 {
1425 elt = bucket; 1566 elt = bucket;
1426 eltstring = Fsymbol_name (elt); 1567 eltstring = elt;
1427 if (XSYMBOL (bucket)->next) 1568 if (XSYMBOL (bucket)->next)
1428 XSETSYMBOL (bucket, XSYMBOL (bucket)->next); 1569 XSETSYMBOL (bucket, XSYMBOL (bucket)->next);
1429 else 1570 else
1430 XSETFASTINT (bucket, 0); 1571 XSETFASTINT (bucket, 0);
1431 } 1572 }
1448 elt = eltstring = HASH_KEY (XHASH_TABLE (alist), index++); 1589 elt = eltstring = HASH_KEY (XHASH_TABLE (alist), index++);
1449 } 1590 }
1450 1591
1451 /* Is this element a possible completion? */ 1592 /* Is this element a possible completion? */
1452 1593
1594 if (SYMBOLP (eltstring))
1595 eltstring = Fsymbol_name (eltstring);
1596
1453 if (STRINGP (eltstring) 1597 if (STRINGP (eltstring)
1454 && SCHARS (string) <= SCHARS (eltstring) 1598 && SCHARS (string) <= SCHARS (eltstring)
1455 /* If HIDE_SPACES, reject alternatives that start with space 1599 /* If HIDE_SPACES, reject alternatives that start with space
1456 unless the input starts with space. */ 1600 unless the input starts with space. */
1457 && ((SBYTES (string) > 0 1601 && ((SBYTES (string) > 0
1458 && SREF (string, 0) == ' ') 1602 && SREF (string, 0) == ' ')
1459 || SREF (eltstring, 0) != ' ' 1603 || SREF (eltstring, 0) != ' '
1460 || NILP (hide_spaces)) 1604 || NILP (hide_spaces))
1461 && (tem = Fcompare_strings (eltstring, make_number (0), 1605 && (tem = Fcompare_strings (eltstring, zero,
1462 make_number (SCHARS (string)), 1606 make_number (SCHARS (string)),
1463 string, make_number (0), 1607 string, zero,
1464 make_number (SCHARS (string)), 1608 make_number (SCHARS (string)),
1465 completion_ignore_case ? Qt : Qnil), 1609 completion_ignore_case ? Qt : Qnil),
1466 EQ (Qt, tem))) 1610 EQ (Qt, tem)))
1467 { 1611 {
1468 /* Yes. */ 1612 /* Yes. */
1469 Lisp_Object regexps; 1613 Lisp_Object regexps;
1470 Lisp_Object zero; 1614 Lisp_Object zero;
1471 XSETFASTINT (zero, 0); 1615 XSETFASTINT (zero, 0);
1472 1616
1473 /* Ignore this element if it fails to match all the regexps. */ 1617 /* Ignore this element if it fails to match all the regexps. */
1474 for (regexps = Vcompletion_regexp_list; CONSP (regexps); 1618 {
1475 regexps = XCDR (regexps)) 1619 for (regexps = Vcompletion_regexp_list; CONSP (regexps);
1476 { 1620 regexps = XCDR (regexps))
1477 tem = Fstring_match (XCAR (regexps), eltstring, zero); 1621 {
1478 if (NILP (tem)) 1622 if (bindcount < 0) {
1479 break; 1623 bindcount = SPECPDL_INDEX ();
1480 } 1624 specbind (Qcase_fold_search,
1481 if (CONSP (regexps)) 1625 completion_ignore_case ? Qt : Qnil);
1482 continue; 1626 }
1627 tem = Fstring_match (XCAR (regexps), eltstring, zero);
1628 if (NILP (tem))
1629 break;
1630 }
1631 if (CONSP (regexps))
1632 continue;
1633 }
1483 1634
1484 /* Ignore this element if there is a predicate 1635 /* Ignore this element if there is a predicate
1485 and the predicate doesn't like it. */ 1636 and the predicate doesn't like it. */
1486 1637
1487 if (!NILP (predicate)) 1638 if (!NILP (predicate))
1488 { 1639 {
1489 if (EQ (predicate, Qcommandp)) 1640 if (EQ (predicate, Qcommandp))
1490 tem = Fcommandp (elt, Qnil); 1641 tem = Fcommandp (elt, Qnil);
1491 else 1642 else
1492 { 1643 {
1644 if (bindcount >= 0) {
1645 unbind_to (bindcount, Qnil);
1646 bindcount = -1;
1647 }
1493 GCPRO4 (tail, eltstring, allmatches, string); 1648 GCPRO4 (tail, eltstring, allmatches, string);
1494 tem = type == 3 1649 tem = type == 3
1495 ? call2 (predicate, elt, 1650 ? call2 (predicate, elt,
1496 HASH_VALUE (XHASH_TABLE (alist), index - 1)) 1651 HASH_VALUE (XHASH_TABLE (alist), index - 1))
1497 : call1 (predicate, elt); 1652 : call1 (predicate, elt);
1502 /* Ok => put it on the list. */ 1657 /* Ok => put it on the list. */
1503 allmatches = Fcons (eltstring, allmatches); 1658 allmatches = Fcons (eltstring, allmatches);
1504 } 1659 }
1505 } 1660 }
1506 1661
1662 if (bindcount >= 0) {
1663 unbind_to (bindcount, Qnil);
1664 bindcount = -1;
1665 }
1666
1507 return Fnreverse (allmatches); 1667 return Fnreverse (allmatches);
1508 } 1668 }
1509 1669
1510 Lisp_Object Vminibuffer_completion_table, Qminibuffer_completion_table; 1670 Lisp_Object Vminibuffer_completion_table, Qminibuffer_completion_table;
1511 Lisp_Object Vminibuffer_completion_predicate, Qminibuffer_completion_predicate; 1671 Lisp_Object Vminibuffer_completion_predicate, Qminibuffer_completion_predicate;
1513 Lisp_Object Vminibuffer_completing_file_name; 1673 Lisp_Object Vminibuffer_completing_file_name;
1514 1674
1515 DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 8, 0, 1675 DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 8, 0,
1516 doc: /* Read a string in the minibuffer, with completion. 1676 doc: /* Read a string in the minibuffer, with completion.
1517 PROMPT is a string to prompt with; normally it ends in a colon and a space. 1677 PROMPT is a string to prompt with; normally it ends in a colon and a space.
1518 TABLE is an alist whose elements' cars are strings, or an obarray. 1678 TABLE can be an list of strings, an alist, an obarray or a hash table.
1519 TABLE can also be a function to do the completion itself. 1679 TABLE can also be a function to do the completion itself.
1520 PREDICATE limits completion to a subset of TABLE. 1680 PREDICATE limits completion to a subset of TABLE.
1521 See `try-completion' and `all-completions' for more details 1681 See `try-completion' and `all-completions' for more details
1522 on completion, TABLE, and PREDICATE. 1682 on completion, TABLE, and PREDICATE.
1523 1683
1524 If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless 1684 If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless
1525 the input is (or completes to) an element of TABLE or is null. 1685 the input is (or completes to) an element of TABLE or is null.
1526 If it is also not t, typing RET does not exit if it does non-null completion. 1686 If it is also not t, typing RET does not exit if it does non-null completion.
1527 If the input is null, `completing-read' returns an empty string, 1687 If the input is null, `completing-read' returns DEF, or an empty string
1528 regardless of the value of REQUIRE-MATCH. 1688 if DEF is nil, regardless of the value of REQUIRE-MATCH.
1529 1689
1530 If INITIAL-INPUT is non-nil, insert it in the minibuffer initially. 1690 If INITIAL-INPUT is non-nil, insert it in the minibuffer initially,
1531 If it is (STRING . POSITION), the initial input 1691 with point positioned at the end.
1532 is STRING, but point is placed POSITION characters into the string. 1692 If it is (STRING . POSITION), the initial input is STRING, but point
1533 This feature is deprecated--it is best to pass nil for INITIAL-INPUT 1693 is placed at _zero-indexed_ position POSITION in STRING. (*Note*
1534 and supply the default value DEF instead. The user can yank the 1694 that this is different from `read-from-minibuffer' and related
1535 default value into the minibuffer easily using \\[next-history-element]. 1695 functions, which use one-indexing for POSITION.) This feature is
1536 1696 deprecated--it is best to pass nil for INITIAL-INPUT and supply the
1537 HIST, if non-nil, specifies a history list 1697 default value DEF instead. The user can yank the default value into
1538 and optionally the initial position in the list. 1698 the minibuffer easily using \\[next-history-element].
1539 It can be a symbol, which is the history list variable to use, 1699
1540 or it can be a cons cell (HISTVAR . HISTPOS). 1700 HIST, if non-nil, specifies a history list and optionally the initial
1541 In that case, HISTVAR is the history list variable to use, 1701 position in the list. It can be a symbol, which is the history list
1542 and HISTPOS is the initial position (the position in the list 1702 variable to use, or it can be a cons cell (HISTVAR . HISTPOS). In
1543 which INITIAL-INPUT corresponds to). 1703 that case, HISTVAR is the history list variable to use, and HISTPOS
1544 Positions are counted starting from 1 at the beginning of the list. 1704 is the initial position (the position in the list used by the
1545 The variable `history-length' controls the maximum length of a 1705 minibuffer history commands). For consistency, you should also
1546 history list. 1706 specify that element of the history as the value of
1707 INITIAL-INPUT. (This is the only case in which you should use
1708 INITIAL-INPUT instead of DEF.) Positions are counted starting from
1709 1 at the beginning of the list. The variable `history-length'
1710 controls the maximum length of a history list.
1547 1711
1548 DEF, if non-nil, is the default value. 1712 DEF, if non-nil, is the default value.
1549 1713
1550 If INHERIT-INPUT-METHOD is non-nil, the minibuffer inherits 1714 If INHERIT-INPUT-METHOD is non-nil, the minibuffer inherits
1551 the current input method and the setting of `enable-multibyte-characters'. 1715 the current input method and the setting of `enable-multibyte-characters'.
1602 histvar = Qminibuffer_history; 1766 histvar = Qminibuffer_history;
1603 if (NILP (histpos)) 1767 if (NILP (histpos))
1604 XSETFASTINT (histpos, 0); 1768 XSETFASTINT (histpos, 0);
1605 1769
1606 val = read_minibuf (NILP (require_match) 1770 val = read_minibuf (NILP (require_match)
1607 ? Vminibuffer_local_completion_map 1771 ? (NILP (Vminibuffer_completing_file_name)
1608 : Vminibuffer_local_must_match_map, 1772 ? Vminibuffer_local_completion_map
1773 : Vminibuffer_local_filename_completion_map)
1774 : (NILP (Vminibuffer_completing_file_name)
1775 ? Vminibuffer_local_must_match_map
1776 : Vminibuffer_local_must_match_filename_map),
1609 init, prompt, make_number (pos), 0, 1777 init, prompt, make_number (pos), 0,
1610 histvar, histpos, def, 0, 1778 histvar, histpos, def, 0,
1611 !NILP (inherit_input_method)); 1779 !NILP (inherit_input_method), 0);
1612 1780
1613 if (STRINGP (val) && SCHARS (val) == 0 && ! NILP (def)) 1781 if (STRINGP (val) && SCHARS (val) == 0 && ! NILP (def))
1614 val = def; 1782 val = def;
1615 1783
1616 RETURN_UNGCPRO (unbind_to (count, val)); 1784 RETURN_UNGCPRO (unbind_to (count, val));
1626 If ALIST is a function, it is called with three arguments: 1794 If ALIST is a function, it is called with three arguments:
1627 the values STRING, PREDICATE and `lambda'. */) 1795 the values STRING, PREDICATE and `lambda'. */)
1628 (string, alist, predicate) 1796 (string, alist, predicate)
1629 Lisp_Object string, alist, predicate; 1797 Lisp_Object string, alist, predicate;
1630 { 1798 {
1631 Lisp_Object regexps, tem = Qnil; 1799 Lisp_Object regexps, tail, tem = Qnil;
1632 int i = 0; 1800 int i = 0;
1633 1801
1634 CHECK_STRING (string); 1802 CHECK_STRING (string);
1635 1803
1636 if ((CONSP (alist) && (!SYMBOLP (XCAR (alist)) || NILP (XCAR (alist)))) 1804 if ((CONSP (alist) && (!SYMBOLP (XCAR (alist)) || NILP (XCAR (alist))))
1637 || NILP (alist)) 1805 || NILP (alist))
1638 { 1806 {
1639 tem = Fassoc_string (string, alist, completion_ignore_case ? Qt : Qnil); 1807 tem = Fassoc_string (string, alist, completion_ignore_case ? Qt : Qnil);
1640 if NILP (tem) 1808 if (NILP (tem))
1641 return Qnil; 1809 return Qnil;
1642 } 1810 }
1643 else if (VECTORP (alist)) 1811 else if (VECTORP (alist))
1644 { 1812 {
1645 /* Bypass intern-soft as that loses for nil. */ 1813 /* Bypass intern-soft as that loses for nil. */
1652 if (STRING_MULTIBYTE (string)) 1820 if (STRING_MULTIBYTE (string))
1653 string = Fstring_make_unibyte (string); 1821 string = Fstring_make_unibyte (string);
1654 else 1822 else
1655 string = Fstring_make_multibyte (string); 1823 string = Fstring_make_multibyte (string);
1656 1824
1657 tem = oblookup (Vminibuffer_completion_table, 1825 tem = oblookup (alist,
1658 SDATA (string), 1826 SDATA (string),
1659 SCHARS (string), 1827 SCHARS (string),
1660 SBYTES (string)); 1828 SBYTES (string));
1661 if (!SYMBOLP (tem))
1662 return Qnil;
1663 } 1829 }
1830
1831 if (completion_ignore_case && !SYMBOLP (tem))
1832 {
1833 for (i = XVECTOR (alist)->size - 1; i >= 0; i--)
1834 {
1835 tail = XVECTOR (alist)->contents[i];
1836 if (SYMBOLP (tail))
1837 while (1)
1838 {
1839 if (EQ((Fcompare_strings (string, make_number (0), Qnil,
1840 Fsymbol_name (tail),
1841 make_number (0) , Qnil, Qt)),
1842 Qt))
1843 {
1844 tem = tail;
1845 break;
1846 }
1847 if (XSYMBOL (tail)->next == 0)
1848 break;
1849 XSETSYMBOL (tail, XSYMBOL (tail)->next);
1850 }
1851 }
1852 }
1853
1854 if (!SYMBOLP (tem))
1855 return Qnil;
1664 } 1856 }
1665 else if (HASH_TABLE_P (alist)) 1857 else if (HASH_TABLE_P (alist))
1666 { 1858 {
1667 i = hash_lookup (XHASH_TABLE (alist), string, NULL); 1859 struct Lisp_Hash_Table *h = XHASH_TABLE (alist);
1860 i = hash_lookup (h, string, NULL);
1668 if (i >= 0) 1861 if (i >= 0)
1669 tem = HASH_KEY (XHASH_TABLE (alist), i); 1862 tem = HASH_KEY (h, i);
1670 else 1863 else
1864 for (i = 0; i < HASH_TABLE_SIZE (h); ++i)
1865 if (!NILP (HASH_HASH (h, i)) &&
1866 EQ (Fcompare_strings (string, make_number (0), Qnil,
1867 HASH_KEY (h, i), make_number (0) , Qnil,
1868 completion_ignore_case ? Qt : Qnil),
1869 Qt))
1870 {
1871 tem = HASH_KEY (h, i);
1872 break;
1873 }
1874 if (!STRINGP (tem))
1671 return Qnil; 1875 return Qnil;
1672 } 1876 }
1673 else 1877 else
1674 return call3 (alist, string, predicate, Qlambda); 1878 return call3 (alist, string, predicate, Qlambda);
1675 1879
1676 /* Reject this element if it fails to match all the regexps. */ 1880 /* Reject this element if it fails to match all the regexps. */
1677 for (regexps = Vcompletion_regexp_list; CONSP (regexps); 1881 if (CONSP (Vcompletion_regexp_list))
1678 regexps = XCDR (regexps)) 1882 {
1679 { 1883 int count = SPECPDL_INDEX ();
1680 if (NILP (Fstring_match (XCAR (regexps), 1884 specbind (Qcase_fold_search, completion_ignore_case ? Qt : Qnil);
1681 SYMBOLP (tem) ? string : tem, 1885 for (regexps = Vcompletion_regexp_list; CONSP (regexps);
1682 Qnil))) 1886 regexps = XCDR (regexps))
1683 return Qnil; 1887 {
1888 if (NILP (Fstring_match (XCAR (regexps),
1889 SYMBOLP (tem) ? string : tem,
1890 Qnil)))
1891 return unbind_to (count, Qnil);
1892 }
1893 unbind_to (count, Qnil);
1684 } 1894 }
1685 1895
1686 /* Finally, check the predicate. */ 1896 /* Finally, check the predicate. */
1687 if (!NILP (predicate)) 1897 if (!NILP (predicate))
1688 return HASH_TABLE_P (alist) 1898 {
1689 ? call2 (predicate, tem, HASH_VALUE (XHASH_TABLE (alist), i)) 1899 return HASH_TABLE_P (alist)
1690 : call1 (predicate, tem); 1900 ? call2 (predicate, tem, HASH_VALUE (XHASH_TABLE (alist), i))
1901 : call1 (predicate, tem);
1902 }
1691 else 1903 else
1692 return Qt; 1904 return Qt;
1693 } 1905 }
1694 1906
1695 /* returns: 1907 /* returns:
1706 Lisp_Object completion, string, tem; 1918 Lisp_Object completion, string, tem;
1707 int completedp; 1919 int completedp;
1708 Lisp_Object last; 1920 Lisp_Object last;
1709 struct gcpro gcpro1, gcpro2; 1921 struct gcpro gcpro1, gcpro2;
1710 1922
1711 completion = Ftry_completion (minibuffer_completion_contents (), 1923 completion = Ftry_completion (Fminibuffer_completion_contents (),
1712 Vminibuffer_completion_table, 1924 Vminibuffer_completion_table,
1713 Vminibuffer_completion_predicate); 1925 Vminibuffer_completion_predicate);
1714 last = last_exact_completion; 1926 last = last_exact_completion;
1715 last_exact_completion = Qnil; 1927 last_exact_completion = Qnil;
1716 1928
1717 GCPRO2 (completion, last); 1929 GCPRO2 (completion, last);
1718 1930
1719 if (NILP (completion)) 1931 if (NILP (completion))
1720 { 1932 {
1721 bitch_at_user (); 1933 bitch_at_user ();
1722 temp_echo_area_glyphs (" [No match]"); 1934 temp_echo_area_glyphs (build_string (" [No match]"));
1723 UNGCPRO; 1935 UNGCPRO;
1724 return 0; 1936 return 0;
1725 } 1937 }
1726 1938
1727 if (EQ (completion, Qt)) /* exact and unique match */ 1939 if (EQ (completion, Qt)) /* exact and unique match */
1728 { 1940 {
1729 UNGCPRO; 1941 UNGCPRO;
1730 return 1; 1942 return 1;
1731 } 1943 }
1732 1944
1733 string = minibuffer_completion_contents (); 1945 string = Fminibuffer_completion_contents ();
1734 1946
1735 /* COMPLETEDP should be true if some completion was done, which 1947 /* COMPLETEDP should be true if some completion was done, which
1736 doesn't include simply changing the case of the entered string. 1948 doesn't include simply changing the case of the entered string.
1737 However, for appearance, the string is rewritten if the case 1949 However, for appearance, the string is rewritten if the case
1738 changes. */ 1950 changes. */
1781 if (completedp) 1993 if (completedp)
1782 return 5; 1994 return 5;
1783 else if (!NILP (Vcompletion_auto_help)) 1995 else if (!NILP (Vcompletion_auto_help))
1784 Fminibuffer_completion_help (); 1996 Fminibuffer_completion_help ();
1785 else 1997 else
1786 temp_echo_area_glyphs (" [Next char not unique]"); 1998 temp_echo_area_glyphs (build_string (" [Next char not unique]"));
1787 return 6; 1999 return 6;
1788 } 2000 }
1789 else if (completedp) 2001 else if (completedp)
1790 { 2002 {
1791 UNGCPRO; 2003 UNGCPRO;
1795 it means we've already given a "Complete but not unique" 2007 it means we've already given a "Complete but not unique"
1796 message and the user's hit TAB again, so now we give him help. */ 2008 message and the user's hit TAB again, so now we give him help. */
1797 last_exact_completion = completion; 2009 last_exact_completion = completion;
1798 if (!NILP (last)) 2010 if (!NILP (last))
1799 { 2011 {
1800 tem = minibuffer_completion_contents (); 2012 tem = Fminibuffer_completion_contents ();
1801 if (!NILP (Fequal (tem, last))) 2013 if (!NILP (Fequal (tem, last)))
1802 Fminibuffer_completion_help (); 2014 Fminibuffer_completion_help ();
1803 } 2015 }
1804 UNGCPRO; 2016 UNGCPRO;
1805 return 3; 2017 return 3;
1880 return Qnil; 2092 return Qnil;
1881 2093
1882 case 1: 2094 case 1:
1883 if (PT != ZV) 2095 if (PT != ZV)
1884 Fgoto_char (make_number (ZV)); 2096 Fgoto_char (make_number (ZV));
1885 temp_echo_area_glyphs (" [Sole completion]"); 2097 temp_echo_area_glyphs (build_string (" [Sole completion]"));
1886 break; 2098 break;
1887 2099
1888 case 3: 2100 case 3:
1889 if (PT != ZV) 2101 if (PT != ZV)
1890 Fgoto_char (make_number (ZV)); 2102 Fgoto_char (make_number (ZV));
1891 temp_echo_area_glyphs (" [Complete, but not unique]"); 2103 temp_echo_area_glyphs (build_string (" [Complete, but not unique]"));
1892 break; 2104 break;
1893 } 2105 }
1894 2106
1895 return Qt; 2107 return Qt;
1896 } 2108 }
1912 complete_and_exit_2 (ignore) 2124 complete_and_exit_2 (ignore)
1913 Lisp_Object ignore; 2125 Lisp_Object ignore;
1914 { 2126 {
1915 return make_number (1); 2127 return make_number (1);
1916 } 2128 }
2129
2130 EXFUN (Fexit_minibuffer, 0) NO_RETURN;
1917 2131
1918 DEFUN ("minibuffer-complete-and-exit", Fminibuffer_complete_and_exit, 2132 DEFUN ("minibuffer-complete-and-exit", Fminibuffer_complete_and_exit,
1919 Sminibuffer_complete_and_exit, 0, 0, "", 2133 Sminibuffer_complete_and_exit, 0, 0, "",
1920 doc: /* If the minibuffer contents is a valid completion then exit. 2134 doc: /* If the minibuffer contents is a valid completion then exit.
1921 Otherwise try to complete it. If completion leads to a valid completion, 2135 Otherwise try to complete it. If completion leads to a valid completion,
1922 a repetition of this command will exit. */) 2136 a repetition of this command will exit. */)
1923 () 2137 ()
1924 { 2138 {
1925 register int i; 2139 register int i;
1926 Lisp_Object val; 2140 Lisp_Object val, tem;
1927 2141
1928 /* Allow user to specify null string */ 2142 /* Allow user to specify null string */
1929 if (XINT (Fminibuffer_prompt_end ()) == ZV) 2143 if (XINT (Fminibuffer_prompt_end ()) == ZV)
1930 goto exit; 2144 goto exit;
1931 2145
1932 if (!NILP (Ftest_completion (Fminibuffer_contents (), 2146 val = Fminibuffer_contents ();
2147 tem = Ftest_completion (val,
2148 Vminibuffer_completion_table,
2149 Vminibuffer_completion_predicate);
2150 if (!NILP (tem))
2151 {
2152 if (completion_ignore_case)
2153 { /* Fixup case of the field, if necessary. */
2154 Lisp_Object compl
2155 = Ftry_completion (val,
1933 Vminibuffer_completion_table, 2156 Vminibuffer_completion_table,
1934 Vminibuffer_completion_predicate))) 2157 Vminibuffer_completion_predicate);
1935 goto exit; 2158 if (STRINGP (compl)
2159 /* If it weren't for this piece of paranoia, I'd replace
2160 the whole thing with a call to do_completion. */
2161 && EQ (Flength (val), Flength (compl)))
2162 {
2163 del_range (XINT (Fminibuffer_prompt_end ()), ZV);
2164 Finsert (1, &compl);
2165 }
2166 }
2167 goto exit;
2168 }
1936 2169
1937 /* Call do_completion, but ignore errors. */ 2170 /* Call do_completion, but ignore errors. */
1938 SET_PT (ZV); 2171 SET_PT (ZV);
1939 val = internal_condition_case (complete_and_exit_1, Qerror, 2172 val = internal_condition_case (complete_and_exit_1, Qerror,
1940 complete_and_exit_2); 2173 complete_and_exit_2);
1947 goto exit; 2180 goto exit;
1948 2181
1949 case 4: 2182 case 4:
1950 if (!NILP (Vminibuffer_completion_confirm)) 2183 if (!NILP (Vminibuffer_completion_confirm))
1951 { 2184 {
1952 temp_echo_area_glyphs (" [Confirm]"); 2185 temp_echo_area_glyphs (build_string (" [Confirm]"));
1953 return Qnil; 2186 return Qnil;
1954 } 2187 }
1955 else 2188 else
1956 goto exit; 2189 goto exit;
1957 2190
1958 default: 2191 default:
1959 return Qnil; 2192 return Qnil;
1960 } 2193 }
1961 exit: 2194 exit:
1962 return Fthrow (Qexit, Qnil); 2195 return Fexit_minibuffer ();
1963 /* NOTREACHED */ 2196 /* NOTREACHED */
1964 } 2197 }
1965 2198
1966 DEFUN ("minibuffer-complete-word", Fminibuffer_complete_word, Sminibuffer_complete_word, 2199 DEFUN ("minibuffer-complete-word", Fminibuffer_complete_word, Sminibuffer_complete_word,
1967 0, 0, "", 2200 0, 0, "",
1971 Return nil if there is no valid completion, else t. */) 2204 Return nil if there is no valid completion, else t. */)
1972 () 2205 ()
1973 { 2206 {
1974 Lisp_Object completion, tem, tem1; 2207 Lisp_Object completion, tem, tem1;
1975 register int i, i_byte; 2208 register int i, i_byte;
1976 register const unsigned char *completion_string;
1977 struct gcpro gcpro1, gcpro2; 2209 struct gcpro gcpro1, gcpro2;
1978 int prompt_end_charpos = XINT (Fminibuffer_prompt_end ()); 2210 int prompt_end_charpos = XINT (Fminibuffer_prompt_end ());
1979 2211
1980 /* We keep calling Fbuffer_string rather than arrange for GC to 2212 /* We keep calling Fbuffer_string rather than arrange for GC to
1981 hold onto a pointer to one of the strings thus made. */ 2213 hold onto a pointer to one of the strings thus made. */
1982 2214
1983 completion = Ftry_completion (minibuffer_completion_contents (), 2215 completion = Ftry_completion (Fminibuffer_completion_contents (),
1984 Vminibuffer_completion_table, 2216 Vminibuffer_completion_table,
1985 Vminibuffer_completion_predicate); 2217 Vminibuffer_completion_predicate);
1986 if (NILP (completion)) 2218 if (NILP (completion))
1987 { 2219 {
1988 bitch_at_user (); 2220 bitch_at_user ();
1989 temp_echo_area_glyphs (" [No match]"); 2221 temp_echo_area_glyphs (build_string (" [No match]"));
1990 return Qnil; 2222 return Qnil;
1991 } 2223 }
1992 if (EQ (completion, Qt)) 2224 if (EQ (completion, Qt))
1993 return Qnil; 2225 return Qnil;
1994 2226
2010 #else /* Rewritten code */ 2242 #else /* Rewritten code */
2011 { 2243 {
2012 int buffer_nchars, completion_nchars; 2244 int buffer_nchars, completion_nchars;
2013 2245
2014 CHECK_STRING (completion); 2246 CHECK_STRING (completion);
2015 tem = minibuffer_completion_contents (); 2247 tem = Fminibuffer_completion_contents ();
2016 GCPRO2 (completion, tem); 2248 GCPRO2 (completion, tem);
2017 /* If reading a file name, 2249 /* If reading a file name,
2018 expand any $ENVVAR refs in the buffer and in TEM. */ 2250 expand any $ENVVAR refs in the buffer and in TEM. */
2019 if (! NILP (Vminibuffer_completing_file_name)) 2251 if (! NILP (Vminibuffer_completing_file_name))
2020 { 2252 {
2056 if (EQ (tem1, Qt)) 2288 if (EQ (tem1, Qt))
2057 break; 2289 break;
2058 i++; 2290 i++;
2059 buffer_nchars--; 2291 buffer_nchars--;
2060 } 2292 }
2061 del_range (1, i + 1); 2293 del_range (start_pos, start_pos + buffer_nchars);
2062 } 2294 }
2063 UNGCPRO; 2295 UNGCPRO;
2064 } 2296 }
2065 #endif /* Rewritten code */ 2297 #endif /* Rewritten code */
2066 2298
2074 /* If completion finds next char not unique, 2306 /* If completion finds next char not unique,
2075 consider adding a space or a hyphen. */ 2307 consider adding a space or a hyphen. */
2076 if (i == SCHARS (completion)) 2308 if (i == SCHARS (completion))
2077 { 2309 {
2078 GCPRO1 (completion); 2310 GCPRO1 (completion);
2079 tem = Ftry_completion (concat2 (minibuffer_completion_contents (), 2311 tem = Ftry_completion (concat2 (Fminibuffer_completion_contents (),
2080 build_string (" ")), 2312 build_string (" ")),
2081 Vminibuffer_completion_table, 2313 Vminibuffer_completion_table,
2082 Vminibuffer_completion_predicate); 2314 Vminibuffer_completion_predicate);
2083 UNGCPRO; 2315 UNGCPRO;
2084 2316
2086 completion = tem; 2318 completion = tem;
2087 else 2319 else
2088 { 2320 {
2089 GCPRO1 (completion); 2321 GCPRO1 (completion);
2090 tem = 2322 tem =
2091 Ftry_completion (concat2 (minibuffer_completion_contents (), 2323 Ftry_completion (concat2 (Fminibuffer_completion_contents (),
2092 build_string ("-")), 2324 build_string ("-")),
2093 Vminibuffer_completion_table, 2325 Vminibuffer_completion_table,
2094 Vminibuffer_completion_predicate); 2326 Vminibuffer_completion_predicate);
2095 UNGCPRO; 2327 UNGCPRO;
2096 2328
2102 /* Now find first word-break in the stuff found by completion. 2334 /* Now find first word-break in the stuff found by completion.
2103 i gets index in string of where to stop completing. */ 2335 i gets index in string of where to stop completing. */
2104 { 2336 {
2105 int len, c; 2337 int len, c;
2106 int bytes = SBYTES (completion); 2338 int bytes = SBYTES (completion);
2107 completion_string = SDATA (completion); 2339 register const unsigned char *completion_string = SDATA (completion);
2108 for (; i_byte < SBYTES (completion); i_byte += len, i++) 2340 for (; i_byte < SBYTES (completion); i_byte += len, i++)
2109 { 2341 {
2110 c = STRING_CHAR_AND_LENGTH (completion_string + i_byte, 2342 c = STRING_CHAR_AND_LENGTH (completion_string + i_byte,
2111 bytes - i_byte, 2343 bytes - i_byte,
2112 len); 2344 len);
2143 insert_from_string (completion, 0, 0, i, i_byte, 1); 2375 insert_from_string (completion, 0, 0, i, i_byte, 1);
2144 return Qt; 2376 return Qt;
2145 } 2377 }
2146 2378
2147 DEFUN ("display-completion-list", Fdisplay_completion_list, Sdisplay_completion_list, 2379 DEFUN ("display-completion-list", Fdisplay_completion_list, Sdisplay_completion_list,
2148 1, 1, 0, 2380 1, 2, 0,
2149 doc: /* Display the list of completions, COMPLETIONS, using `standard-output'. 2381 doc: /* Display the list of completions, COMPLETIONS, using `standard-output'.
2150 Each element may be just a symbol or string 2382 Each element may be just a symbol or string
2151 or may be a list of two strings to be printed as if concatenated. 2383 or may be a list of two strings to be printed as if concatenated.
2384 If it is a list of two strings, the first is the actual completion
2385 alternative, the second serves as annotation.
2152 `standard-output' must be a buffer. 2386 `standard-output' must be a buffer.
2153 The actual completion alternatives, as inserted, are given `mouse-face' 2387 The actual completion alternatives, as inserted, are given `mouse-face'
2154 properties of `highlight'. 2388 properties of `highlight'.
2155 At the end, this runs the normal hook `completion-setup-hook'. 2389 At the end, this runs the normal hook `completion-setup-hook'.
2156 It can find the completion buffer in `standard-output'. */) 2390 It can find the completion buffer in `standard-output'.
2157 (completions) 2391 The optional second arg COMMON-SUBSTRING is a string.
2392 It is used to put faces, `completions-first-difference' and
2393 `completions-common-part' on the completion buffer. The
2394 `completions-common-part' face is put on the common substring
2395 specified by COMMON-SUBSTRING. If COMMON-SUBSTRING is nil
2396 and the current buffer is not the minibuffer, the faces are not put.
2397 Internally, COMMON-SUBSTRING is bound to `completion-common-substring'
2398 during running `completion-setup-hook'. */)
2399 (completions, common_substring)
2158 Lisp_Object completions; 2400 Lisp_Object completions;
2401 Lisp_Object common_substring;
2159 { 2402 {
2160 Lisp_Object tail, elt; 2403 Lisp_Object tail, elt;
2161 register int i; 2404 register int i;
2162 int column = 0; 2405 int column = 0;
2163 struct gcpro gcpro1, gcpro2; 2406 struct gcpro gcpro1, gcpro2, gcpro3;
2164 struct buffer *old = current_buffer; 2407 struct buffer *old = current_buffer;
2165 int first = 1; 2408 int first = 1;
2166 2409
2167 /* Note that (when it matters) every variable 2410 /* Note that (when it matters) every variable
2168 points to a non-string that is pointed to by COMPLETIONS, 2411 points to a non-string that is pointed to by COMPLETIONS,
2169 except for ELT. ELT can be pointing to a string 2412 except for ELT. ELT can be pointing to a string
2170 when terpri or Findent_to calls a change hook. */ 2413 when terpri or Findent_to calls a change hook. */
2171 elt = Qnil; 2414 elt = Qnil;
2172 GCPRO2 (completions, elt); 2415 GCPRO3 (completions, elt, common_substring);
2173 2416
2174 if (BUFFERP (Vstandard_output)) 2417 if (BUFFERP (Vstandard_output))
2175 set_buffer_internal (XBUFFER (Vstandard_output)); 2418 set_buffer_internal (XBUFFER (Vstandard_output));
2176 2419
2177 if (NILP (completions)) 2420 if (NILP (completions))
2178 write_string ("There are no possible completions of what you have typed.", 2421 write_string ("There are no possible completions of what you have typed.",
2179 -1); 2422 -1);
2180 else 2423 else
2181 { 2424 {
2182 write_string ("Possible completions are:", -1); 2425 write_string ("Possible completions are:", -1);
2183 for (tail = completions, i = 0; !NILP (tail); tail = Fcdr (tail), i++) 2426 for (tail = completions, i = 0; CONSP (tail); tail = XCDR (tail), i++)
2184 { 2427 {
2185 Lisp_Object tem, string; 2428 Lisp_Object tem, string;
2186 int length; 2429 int length;
2187 Lisp_Object startpos, endpos; 2430 Lisp_Object startpos, endpos;
2188 2431
2189 startpos = Qnil; 2432 startpos = Qnil;
2190 2433
2191 elt = Fcar (tail); 2434 elt = XCAR (tail);
2435 if (SYMBOLP (elt))
2436 elt = SYMBOL_NAME (elt);
2192 /* Compute the length of this element. */ 2437 /* Compute the length of this element. */
2193 if (CONSP (elt)) 2438 if (CONSP (elt))
2194 { 2439 {
2195 tem = XCAR (elt); 2440 tem = XCAR (elt);
2196 CHECK_STRING (tem); 2441 CHECK_STRING (tem);
2314 2559
2315 first = 0; 2560 first = 0;
2316 } 2561 }
2317 } 2562 }
2318 2563
2319 UNGCPRO;
2320
2321 if (BUFFERP (Vstandard_output)) 2564 if (BUFFERP (Vstandard_output))
2322 set_buffer_internal (old); 2565 set_buffer_internal (old);
2323 2566
2324 if (!NILP (Vrun_hooks)) 2567 if (!NILP (Vrun_hooks))
2325 call1 (Vrun_hooks, intern ("completion-setup-hook")); 2568 {
2569 int count1 = SPECPDL_INDEX ();
2570
2571 specbind (intern ("completion-common-substring"), common_substring);
2572 call1 (Vrun_hooks, intern ("completion-setup-hook"));
2573
2574 unbind_to (count1, Qnil);
2575 }
2576
2577 UNGCPRO;
2326 2578
2327 return Qnil; 2579 return Qnil;
2580 }
2581
2582
2583 static Lisp_Object
2584 display_completion_list_1 (list)
2585 Lisp_Object list;
2586 {
2587 return Fdisplay_completion_list (list, Qnil);
2328 } 2588 }
2329 2589
2330 DEFUN ("minibuffer-completion-help", Fminibuffer_completion_help, Sminibuffer_completion_help, 2590 DEFUN ("minibuffer-completion-help", Fminibuffer_completion_help, Sminibuffer_completion_help,
2331 0, 0, "", 2591 0, 0, "",
2332 doc: /* Display a list of possible completions of the current minibuffer contents. */) 2592 doc: /* Display a list of possible completions of the current minibuffer contents. */)
2333 () 2593 ()
2334 { 2594 {
2335 Lisp_Object completions; 2595 Lisp_Object completions;
2336 2596
2337 message ("Making completion list..."); 2597 message ("Making completion list...");
2338 completions = Fall_completions (minibuffer_completion_contents (), 2598 completions = Fall_completions (Fminibuffer_completion_contents (),
2339 Vminibuffer_completion_table, 2599 Vminibuffer_completion_table,
2340 Vminibuffer_completion_predicate, 2600 Vminibuffer_completion_predicate,
2341 Qt); 2601 Qt);
2342 clear_message (1, 0); 2602 clear_message (1, 0);
2343 2603
2344 if (NILP (completions)) 2604 if (NILP (completions))
2345 { 2605 {
2346 bitch_at_user (); 2606 bitch_at_user ();
2347 temp_echo_area_glyphs (" [No completions]"); 2607 temp_echo_area_glyphs (build_string (" [No completions]"));
2348 } 2608 }
2349 else 2609 else
2350 internal_with_output_to_temp_buffer ("*Completions*", 2610 {
2351 Fdisplay_completion_list, 2611 /* Sort and remove duplicates. */
2352 Fsort (completions, Qstring_lessp)); 2612 Lisp_Object tmp = completions = Fsort (completions, Qstring_lessp);
2613 while (CONSP (tmp))
2614 {
2615 if (CONSP (XCDR (tmp))
2616 && !NILP (Fequal (XCAR (tmp), XCAR (XCDR (tmp)))))
2617 XSETCDR (tmp, XCDR (XCDR (tmp)));
2618 else
2619 tmp = XCDR (tmp);
2620 }
2621 internal_with_output_to_temp_buffer ("*Completions*",
2622 display_completion_list_1,
2623 completions);
2624 }
2353 return Qnil; 2625 return Qnil;
2354 } 2626 }
2355 2627
2356 DEFUN ("self-insert-and-exit", Fself_insert_and_exit, Sself_insert_and_exit, 0, 0, "", 2628 DEFUN ("self-insert-and-exit", Fself_insert_and_exit, Sself_insert_and_exit, 0, 0, "",
2357 doc: /* Terminate minibuffer input. */) 2629 doc: /* Terminate minibuffer input. */)
2360 if (INTEGERP (last_command_char)) 2632 if (INTEGERP (last_command_char))
2361 internal_self_insert (XINT (last_command_char), 0); 2633 internal_self_insert (XINT (last_command_char), 0);
2362 else 2634 else
2363 bitch_at_user (); 2635 bitch_at_user ();
2364 2636
2365 return Fthrow (Qexit, Qnil); 2637 return Fexit_minibuffer ();
2366 } 2638 }
2367 2639
2368 DEFUN ("exit-minibuffer", Fexit_minibuffer, Sexit_minibuffer, 0, 0, "", 2640 DEFUN ("exit-minibuffer", Fexit_minibuffer, Sexit_minibuffer, 0, 0, "",
2369 doc: /* Terminate this minibuffer argument. */) 2641 doc: /* Terminate this minibuffer argument. */)
2370 () 2642 ()
2371 { 2643 {
2372 return Fthrow (Qexit, Qnil); 2644 /* If the command that uses this has made modifications in the minibuffer,
2645 we don't want them to cause deactivation of the mark in the original
2646 buffer.
2647 A better solution would be to make deactivate-mark buffer-local
2648 (or to turn it into a list of buffers, ...), but in the mean time,
2649 this should do the trick in most cases. */
2650 Vdeactivate_mark = Qnil;
2651 Fthrow (Qexit, Qnil);
2373 } 2652 }
2374 2653
2375 DEFUN ("minibuffer-depth", Fminibuffer_depth, Sminibuffer_depth, 0, 0, 0, 2654 DEFUN ("minibuffer-depth", Fminibuffer_depth, Sminibuffer_depth, 0, 0, 0,
2376 doc: /* Return current depth of activations of minibuffer, a nonnegative integer. */) 2655 doc: /* Return current depth of activations of minibuffer, a nonnegative integer. */)
2377 () 2656 ()
2386 { 2665 {
2387 return Fcopy_sequence (minibuf_prompt); 2666 return Fcopy_sequence (minibuf_prompt);
2388 } 2667 }
2389 2668
2390 2669
2391 /* Temporarily display the string M at the end of the current 2670 /* Temporarily display STRING at the end of the current
2392 minibuffer contents. This is used to display things like 2671 minibuffer contents. This is used to display things like
2393 "[No Match]" when the user requests a completion for a prefix 2672 "[No Match]" when the user requests a completion for a prefix
2394 that has no possible completions, and other quick, unobtrusive 2673 that has no possible completions, and other quick, unobtrusive
2395 messages. */ 2674 messages. */
2396 2675
2397 void 2676 void
2398 temp_echo_area_glyphs (m) 2677 temp_echo_area_glyphs (string)
2399 const char *m; 2678 Lisp_Object string;
2400 { 2679 {
2401 int osize = ZV; 2680 int osize = ZV;
2402 int osize_byte = ZV_BYTE; 2681 int osize_byte = ZV_BYTE;
2403 int opoint = PT; 2682 int opoint = PT;
2404 int opoint_byte = PT_BYTE; 2683 int opoint_byte = PT_BYTE;
2407 2686
2408 /* Clear out any old echo-area message to make way for our new thing. */ 2687 /* Clear out any old echo-area message to make way for our new thing. */
2409 message (0); 2688 message (0);
2410 2689
2411 SET_PT_BOTH (osize, osize_byte); 2690 SET_PT_BOTH (osize, osize_byte);
2412 insert_string (m); 2691 insert_from_string (string, 0, 0, SCHARS (string), SBYTES (string), 0);
2413 SET_PT_BOTH (opoint, opoint_byte); 2692 SET_PT_BOTH (opoint, opoint_byte);
2414 Vinhibit_quit = Qt; 2693 Vinhibit_quit = Qt;
2415 Fsit_for (make_number (2), Qnil, Qnil); 2694 Fsit_for (make_number (2), Qnil, Qnil);
2416 del_range_both (osize, osize_byte, ZV, ZV_BYTE, 1); 2695 del_range_both (osize, osize_byte, ZV, ZV_BYTE, 1);
2417 SET_PT_BOTH (opoint, opoint_byte); 2696 SET_PT_BOTH (opoint, opoint_byte);
2424 } 2703 }
2425 2704
2426 DEFUN ("minibuffer-message", Fminibuffer_message, Sminibuffer_message, 2705 DEFUN ("minibuffer-message", Fminibuffer_message, Sminibuffer_message,
2427 1, 1, 0, 2706 1, 1, 0,
2428 doc: /* Temporarily display STRING at the end of the minibuffer. 2707 doc: /* Temporarily display STRING at the end of the minibuffer.
2429 The text is displayed for two seconds, 2708 The text is displayed for a period controlled by `minibuffer-message-timeout',
2430 or until the next input event arrives, whichever comes first. */) 2709 or until the next input event arrives, whichever comes first. */)
2431 (string) 2710 (string)
2432 Lisp_Object string; 2711 Lisp_Object string;
2433 { 2712 {
2434 CHECK_STRING (string); 2713 CHECK_STRING (string);
2435 temp_echo_area_glyphs (SDATA (string)); 2714 temp_echo_area_glyphs (string);
2436 return Qnil; 2715 return Qnil;
2437 } 2716 }
2438 2717
2439 void 2718 void
2440 init_minibuf_once () 2719 init_minibuf_once ()
2497 Qcurrent_input_method = intern ("current-input-method"); 2776 Qcurrent_input_method = intern ("current-input-method");
2498 staticpro (&Qcurrent_input_method); 2777 staticpro (&Qcurrent_input_method);
2499 2778
2500 Qactivate_input_method = intern ("activate-input-method"); 2779 Qactivate_input_method = intern ("activate-input-method");
2501 staticpro (&Qactivate_input_method); 2780 staticpro (&Qactivate_input_method);
2781
2782 Qcase_fold_search = intern ("case-fold-search");
2783 staticpro (&Qcase_fold_search);
2502 2784
2503 DEFVAR_LISP ("read-buffer-function", &Vread_buffer_function, 2785 DEFVAR_LISP ("read-buffer-function", &Vread_buffer_function,
2504 doc: /* If this is non-nil, `read-buffer' does its work by calling this function. */); 2786 doc: /* If this is non-nil, `read-buffer' does its work by calling this function. */);
2505 Vread_buffer_function = Qnil; 2787 Vread_buffer_function = Qnil;
2506 2788
2517 A number means that length; t means infinite. Truncation takes place 2799 A number means that length; t means infinite. Truncation takes place
2518 just after a new element is inserted. Setting the history-length 2800 just after a new element is inserted. Setting the history-length
2519 property of a history variable overrides this default. */); 2801 property of a history variable overrides this default. */);
2520 XSETFASTINT (Vhistory_length, 30); 2802 XSETFASTINT (Vhistory_length, 30);
2521 2803
2804 DEFVAR_BOOL ("history-delete-duplicates", &history_delete_duplicates,
2805 doc: /* *Non-nil means to delete duplicates in history.
2806 If set to t when adding a new history element, all previous identical
2807 elements are deleted. */);
2808 history_delete_duplicates = 0;
2809
2522 DEFVAR_LISP ("completion-auto-help", &Vcompletion_auto_help, 2810 DEFVAR_LISP ("completion-auto-help", &Vcompletion_auto_help,
2523 doc: /* *Non-nil means automatically provide help for invalid completion input. */); 2811 doc: /* *Non-nil means automatically provide help for invalid completion input.
2812 Under Partial Completion mode, a non-nil, non-t value has a special meaning;
2813 see the doc string of `partial-completion-mode' for more details. */);
2524 Vcompletion_auto_help = Qt; 2814 Vcompletion_auto_help = Qt;
2525 2815
2526 DEFVAR_BOOL ("completion-ignore-case", &completion_ignore_case, 2816 DEFVAR_BOOL ("completion-ignore-case", &completion_ignore_case,
2527 doc: /* Non-nil means don't consider case significant in completion. */); 2817 doc: /* Non-nil means don't consider case significant in completion.
2818
2819 For file-name completion, the variable `read-file-name-completion-ignore-case'
2820 controls the behavior, rather than this variable. */);
2528 completion_ignore_case = 0; 2821 completion_ignore_case = 0;
2529 2822
2530 DEFVAR_BOOL ("enable-recursive-minibuffers", &enable_recursive_minibuffers, 2823 DEFVAR_BOOL ("enable-recursive-minibuffers", &enable_recursive_minibuffers,
2531 doc: /* *Non-nil means to allow minibuffer commands while in the minibuffer. 2824 doc: /* *Non-nil means to allow minibuffer commands while in the minibuffer.
2532 This variable makes a difference whenever the minibuffer window is active. */); 2825 This variable makes a difference whenever the minibuffer window is active. */);
2533 enable_recursive_minibuffers = 0; 2826 enable_recursive_minibuffers = 0;
2534 2827
2535 DEFVAR_LISP ("minibuffer-completion-table", &Vminibuffer_completion_table, 2828 DEFVAR_LISP ("minibuffer-completion-table", &Vminibuffer_completion_table,
2536 doc: /* Alist or obarray used for completion in the minibuffer. 2829 doc: /* Alist or obarray used for completion in the minibuffer.
2537 This becomes the ALIST argument to `try-completion' and `all-completion'. 2830 This becomes the ALIST argument to `try-completion' and `all-completions'.
2831 The value can also be a list of strings or a hash table.
2538 2832
2539 The value may alternatively be a function, which is given three arguments: 2833 The value may alternatively be a function, which is given three arguments:
2540 STRING, the current buffer contents; 2834 STRING, the current buffer contents;
2541 PREDICATE, the predicate for filtering possible matches; 2835 PREDICATE, the predicate for filtering possible matches;
2542 CODE, which says what kind of things to do. 2836 CODE, which says what kind of things to do.
2579 doc: /* *Non-nil means entering the minibuffer raises the minibuffer's frame. 2873 doc: /* *Non-nil means entering the minibuffer raises the minibuffer's frame.
2580 Some uses of the echo area also raise that frame (since they use it too). */); 2874 Some uses of the echo area also raise that frame (since they use it too). */);
2581 minibuffer_auto_raise = 0; 2875 minibuffer_auto_raise = 0;
2582 2876
2583 DEFVAR_LISP ("completion-regexp-list", &Vcompletion_regexp_list, 2877 DEFVAR_LISP ("completion-regexp-list", &Vcompletion_regexp_list,
2584 doc: /* List of regexps that should restrict possible completions. */); 2878 doc: /* List of regexps that should restrict possible completions.
2879 The basic completion functions only consider a completion acceptable
2880 if it matches all regular expressions in this list, with
2881 `case-fold-search' bound to the value of `completion-ignore-case'.
2882 See Info node `(elisp)Basic Completion', for a description of these
2883 functions. */);
2585 Vcompletion_regexp_list = Qnil; 2884 Vcompletion_regexp_list = Qnil;
2586 2885
2587 DEFVAR_BOOL ("minibuffer-allow-text-properties", 2886 DEFVAR_BOOL ("minibuffer-allow-text-properties",
2588 &minibuffer_allow_text_properties, 2887 &minibuffer_allow_text_properties,
2589 doc: /* Non-nil means `read-from-minibuffer' should not discard text properties. 2888 doc: /* Non-nil means `read-from-minibuffer' should not discard text properties.
2615 2914
2616 defsubr (&Sminibufferp); 2915 defsubr (&Sminibufferp);
2617 defsubr (&Sminibuffer_prompt_end); 2916 defsubr (&Sminibuffer_prompt_end);
2618 defsubr (&Sminibuffer_contents); 2917 defsubr (&Sminibuffer_contents);
2619 defsubr (&Sminibuffer_contents_no_properties); 2918 defsubr (&Sminibuffer_contents_no_properties);
2919 defsubr (&Sminibuffer_completion_contents);
2620 defsubr (&Sdelete_minibuffer_contents); 2920 defsubr (&Sdelete_minibuffer_contents);
2621 2921
2622 defsubr (&Stry_completion); 2922 defsubr (&Stry_completion);
2623 defsubr (&Sall_completions); 2923 defsubr (&Sall_completions);
2624 defsubr (&Stest_completion); 2924 defsubr (&Stest_completion);
2658 initial_define_key (Vminibuffer_local_completion_map, ' ', 2958 initial_define_key (Vminibuffer_local_completion_map, ' ',
2659 "minibuffer-complete-word"); 2959 "minibuffer-complete-word");
2660 initial_define_key (Vminibuffer_local_completion_map, '?', 2960 initial_define_key (Vminibuffer_local_completion_map, '?',
2661 "minibuffer-completion-help"); 2961 "minibuffer-completion-help");
2662 2962
2963 Fdefine_key (Vminibuffer_local_filename_completion_map,
2964 build_string (" "), Qnil);
2965
2663 initial_define_key (Vminibuffer_local_must_match_map, Ctl ('m'), 2966 initial_define_key (Vminibuffer_local_must_match_map, Ctl ('m'),
2664 "minibuffer-complete-and-exit"); 2967 "minibuffer-complete-and-exit");
2665 initial_define_key (Vminibuffer_local_must_match_map, Ctl ('j'), 2968 initial_define_key (Vminibuffer_local_must_match_map, Ctl ('j'),
2666 "minibuffer-complete-and-exit"); 2969 "minibuffer-complete-and-exit");
2667 } 2970
2971 Fdefine_key (Vminibuffer_local_must_match_filename_map,
2972 build_string (" "), Qnil);
2973 }
2974
2975 /* arch-tag: 8f69b601-fba3-484c-a6dd-ceaee54a7a73
2976 (do not change this comment) */