1 /* Minibuffer input and completion.
2 Copyright (C) 1985, 1986, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2003 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
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
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
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
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
30 #include "dispextern.h"
35 #include "intervals.h"
40 /* List of buffers for use as minibuffers.
41 The first element of the list is used for the outermost minibuffer
42 invocation, the next element is used for a recursive minibuffer
43 invocation, etc. The list is extended at the end as deeper
44 minibuffer recursions are encountered. */
46 Lisp_Object Vminibuffer_list
;
48 /* Data to remember during recursive minibuffer invocations */
50 Lisp_Object minibuf_save_list
;
52 /* Depth in minibuffer invocations. */
56 /* Nonzero means display completion help for invalid input. */
58 Lisp_Object Vcompletion_auto_help
;
60 /* The maximum length of a minibuffer history. */
62 Lisp_Object Qhistory_length
, Vhistory_length
;
64 /* Fread_minibuffer leaves the input here as a string. */
66 Lisp_Object last_minibuf_string
;
68 /* Nonzero means let functions called when within a minibuffer
69 invoke recursive minibuffers (to read arguments, or whatever) */
71 int enable_recursive_minibuffers
;
73 /* Nonzero means don't ignore text properties
74 in Fread_from_minibuffer. */
76 int minibuffer_allow_text_properties
;
78 /* help-form is bound to this while in the minibuffer. */
80 Lisp_Object Vminibuffer_help_form
;
82 /* Variable which is the history list to add minibuffer values to. */
84 Lisp_Object Vminibuffer_history_variable
;
86 /* Current position in the history list (adjusted by M-n and M-p). */
88 Lisp_Object Vminibuffer_history_position
;
90 /* Text properties that are added to minibuffer prompts.
91 These are in addition to the basic `field' property, and stickiness
94 Lisp_Object Vminibuffer_prompt_properties
;
96 Lisp_Object Qminibuffer_history
, Qbuffer_name_history
;
98 Lisp_Object Qread_file_name_internal
;
100 /* Normal hooks for entry to and exit from minibuffer. */
102 Lisp_Object Qminibuffer_setup_hook
, Vminibuffer_setup_hook
;
103 Lisp_Object Qminibuffer_exit_hook
, Vminibuffer_exit_hook
;
105 /* Function to call to read a buffer name. */
106 Lisp_Object Vread_buffer_function
;
108 /* Nonzero means completion ignores case. */
110 int completion_ignore_case
;
112 /* List of regexps that should restrict possible completions. */
114 Lisp_Object Vcompletion_regexp_list
;
116 /* Nonzero means raise the minibuffer frame when the minibuffer
119 int minibuffer_auto_raise
;
121 /* If last completion attempt reported "Complete but not unique"
122 then this is the string completed then; otherwise this is nil. */
124 static Lisp_Object last_exact_completion
;
126 extern Lisp_Object Voverriding_local_map
;
128 Lisp_Object Quser_variable_p
;
130 Lisp_Object Qminibuffer_default
;
132 Lisp_Object Qcurrent_input_method
, Qactivate_input_method
;
134 extern Lisp_Object Qmouse_face
;
136 extern Lisp_Object Qfield
;
138 /* Put minibuf on currently selected frame's minibuffer.
139 We do this whenever the user starts a new minibuffer
140 or when a minibuffer exits. */
143 choose_minibuf_frame ()
145 if (FRAMEP (selected_frame
)
146 && FRAME_LIVE_P (XFRAME (selected_frame
))
147 && !EQ (minibuf_window
, XFRAME (selected_frame
)->minibuffer_window
))
149 struct frame
*sf
= XFRAME (selected_frame
);
152 /* I don't think that any frames may validly have a null minibuffer
154 if (NILP (sf
->minibuffer_window
))
157 /* Under X, we come here with minibuf_window being the
158 minibuffer window of the unused termcap window created in
159 init_window_once. That window doesn't have a buffer. */
160 buffer
= XWINDOW (minibuf_window
)->buffer
;
161 if (BUFFERP (buffer
))
162 Fset_window_buffer (sf
->minibuffer_window
, buffer
, Qnil
);
163 minibuf_window
= sf
->minibuffer_window
;
166 /* 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
168 confusing. Only allow the selected frame to do this,
169 and that only if the minibuffer is active. */
171 Lisp_Object tail
, frame
;
173 FOR_EACH_FRAME (tail
, frame
)
174 if (MINI_WINDOW_P (XWINDOW (FRAME_SELECTED_WINDOW (XFRAME (frame
))))
175 && !(EQ (frame
, selected_frame
)
176 && minibuf_level
> 0))
177 Fset_frame_selected_window (frame
, Fframe_first_window (frame
));
182 choose_minibuf_frame_1 (ignore
)
185 choose_minibuf_frame ();
189 DEFUN ("set-minibuffer-window", Fset_minibuffer_window
,
190 Sset_minibuffer_window
, 1, 1, 0,
191 doc
: /* Specify which minibuffer window to use for the minibuffer.
192 This effects where the minibuffer is displayed if you put text in it
193 without invoking the usual minibuffer commands. */)
197 CHECK_WINDOW (window
);
198 if (! MINI_WINDOW_P (XWINDOW (window
)))
199 error ("Window is not a minibuffer window");
201 minibuf_window
= window
;
207 /* Actual minibuffer invocation. */
209 static Lisp_Object read_minibuf_unwind
P_ ((Lisp_Object
));
210 static Lisp_Object read_minibuf
P_ ((Lisp_Object
, Lisp_Object
,
211 Lisp_Object
, Lisp_Object
,
213 Lisp_Object
, Lisp_Object
,
215 static Lisp_Object read_minibuf_noninteractive
P_ ((Lisp_Object
, Lisp_Object
,
216 Lisp_Object
, Lisp_Object
,
218 Lisp_Object
, Lisp_Object
,
220 static Lisp_Object string_to_object
P_ ((Lisp_Object
, Lisp_Object
));
223 /* Read a Lisp object from VAL and return it. If VAL is an empty
224 string, and DEFALT is a string, read from DEFALT instead of VAL. */
227 string_to_object (val
, defalt
)
228 Lisp_Object val
, defalt
;
230 struct gcpro gcpro1
, gcpro2
;
231 Lisp_Object expr_and_pos
;
234 GCPRO2 (val
, defalt
);
236 if (STRINGP (val
) && SCHARS (val
) == 0
240 expr_and_pos
= Fread_from_string (val
, Qnil
, Qnil
);
241 pos
= XINT (Fcdr (expr_and_pos
));
242 if (pos
!= SCHARS (val
))
244 /* Ignore trailing whitespace; any other trailing junk
247 pos
= string_char_to_byte (val
, pos
);
248 for (i
= pos
; i
< SBYTES (val
); i
++)
250 int c
= SREF (val
, i
);
251 if (c
!= ' ' && c
!= '\t' && c
!= '\n')
252 error ("Trailing garbage following expression");
256 val
= Fcar (expr_and_pos
);
257 RETURN_UNGCPRO (val
);
261 /* Like read_minibuf but reading from stdin. This function is called
262 from read_minibuf to do the job if noninteractive. */
265 read_minibuf_noninteractive (map
, initial
, prompt
, backup_n
, expflag
,
266 histvar
, histpos
, defalt
, allow_props
,
267 inherit_input_method
)
271 Lisp_Object backup_n
;
277 int inherit_input_method
;
283 fprintf (stdout
, "%s", SDATA (prompt
));
289 line
= (char *) xmalloc (size
* sizeof *line
);
290 while ((s
= fgets (line
+ len
, size
- len
, stdin
)) != NULL
291 && (len
= strlen (line
),
292 len
== size
- 1 && line
[len
- 1] != '\n'))
295 line
= (char *) xrealloc (line
, size
);
302 if (len
> 0 && line
[len
- 1] == '\n')
305 val
= build_string (line
);
311 error ("Error reading from stdin");
314 /* If Lisp form desired instead of string, parse it. */
316 val
= string_to_object (val
, defalt
);
321 DEFUN ("minibufferp", Fminibufferp
,
322 Sminibufferp
, 0, 1, 0,
323 doc
: /* Return t if BUFFER is a minibuffer.
324 No argument or nil as argument means use current buffer as BUFFER.*/)
331 buffer
= Fcurrent_buffer ();
332 else if (STRINGP (buffer
))
333 buffer
= Fget_buffer (buffer
);
335 CHECK_BUFFER (buffer
);
337 tem
= Fmemq (buffer
, Vminibuffer_list
);
338 return ! NILP (tem
) ? Qt
: Qnil
;
341 DEFUN ("minibuffer-prompt-end", Fminibuffer_prompt_end
,
342 Sminibuffer_prompt_end
, 0, 0, 0,
343 doc
: /* Return the buffer position of the end of the minibuffer prompt.
344 Return (point-min) if current buffer is not a mini-buffer. */)
347 /* This function is written to be most efficient when there's a prompt. */
348 Lisp_Object beg
, end
, tem
;
349 beg
= make_number (BEGV
);
351 tem
= Fmemq (Fcurrent_buffer (), Vminibuffer_list
);
355 end
= Ffield_end (beg
, Qnil
, Qnil
);
357 if (XINT (end
) == ZV
&& NILP (Fget_char_property (beg
, Qfield
, Qnil
)))
363 DEFUN ("minibuffer-contents", Fminibuffer_contents
,
364 Sminibuffer_contents
, 0, 0, 0,
365 doc
: /* Return the user input in a minibuffer as a string.
366 The current buffer must be a minibuffer. */)
369 int prompt_end
= XINT (Fminibuffer_prompt_end ());
370 return make_buffer_string (prompt_end
, ZV
, 1);
373 DEFUN ("minibuffer-contents-no-properties", Fminibuffer_contents_no_properties
,
374 Sminibuffer_contents_no_properties
, 0, 0, 0,
375 doc
: /* Return the user input in a minibuffer as a string, without text-properties.
376 The current buffer must be a minibuffer. */)
379 int prompt_end
= XINT (Fminibuffer_prompt_end ());
380 return make_buffer_string (prompt_end
, ZV
, 0);
383 DEFUN ("delete-minibuffer-contents", Fdelete_minibuffer_contents
,
384 Sdelete_minibuffer_contents
, 0, 0, 0,
385 doc
: /* Delete all user input in a minibuffer.
386 The current buffer must be a minibuffer. */)
389 int prompt_end
= XINT (Fminibuffer_prompt_end ());
391 del_range (prompt_end
, ZV
);
395 /* Get the text in the minibuffer before point.
396 That is what completion commands operate on. */
399 minibuffer_completion_contents ()
401 int prompt_end
= XINT (Fminibuffer_prompt_end ());
403 error ("Cannot do completion in the prompt");
404 return make_buffer_string (prompt_end
, PT
, 1);
407 /* Read from the minibuffer using keymap MAP, initial contents INITIAL
408 (a string), putting point minus BACKUP_N bytes from the end of INITIAL,
409 prompting with PROMPT (a string), using history list HISTVAR
410 with initial position HISTPOS. (BACKUP_N should be <= 0.)
412 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.
414 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
416 the list as the string that was read.
418 DEFALT specifies the default value for the sake of history commands.
420 If ALLOW_PROPS is nonzero, we do not throw away text properties.
422 if INHERIT_INPUT_METHOD is nonzeor, the minibuffer inherit the
423 current input method. */
426 read_minibuf (map
, initial
, prompt
, backup_n
, expflag
,
427 histvar
, histpos
, defalt
, allow_props
, inherit_input_method
)
431 Lisp_Object backup_n
;
437 int inherit_input_method
;
440 int count
= SPECPDL_INDEX ();
441 Lisp_Object mini_frame
, ambient_dir
, minibuffer
, input_method
;
442 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
443 Lisp_Object enable_multibyte
;
445 /* String to add to the history. */
446 Lisp_Object histstring
;
448 extern Lisp_Object Qfront_sticky
;
449 extern Lisp_Object Qrear_nonsticky
;
451 specbind (Qminibuffer_default
, defalt
);
453 single_kboard_state ();
454 #ifdef HAVE_X_WINDOWS
455 if (display_hourglass_p
)
460 ambient_dir
= current_buffer
->directory
;
462 enable_multibyte
= Qnil
;
464 /* Don't need to protect PROMPT, HISTVAR, and HISTPOS because we
465 store them away before we can GC. Don't need to protect
466 BACKUP_N because we use the value only if it is an integer. */
467 GCPRO5 (map
, initial
, val
, ambient_dir
, input_method
);
469 if (!STRINGP (prompt
))
470 prompt
= empty_string
;
472 if (!enable_recursive_minibuffers
473 && minibuf_level
> 0)
475 if (EQ (selected_window
, minibuf_window
))
476 error ("Command attempted to use minibuffer while in minibuffer");
478 /* If we're in another window, cancel the minibuffer that's active. */
480 build_string ("Command attempted to use minibuffer while in minibuffer"));
485 val
= read_minibuf_noninteractive (map
, initial
, prompt
, backup_n
,
486 expflag
, histvar
, histpos
, defalt
,
487 allow_props
, inherit_input_method
);
489 return unbind_to (count
, val
);
492 /* Choose the minibuffer window and frame, and take action on them. */
494 choose_minibuf_frame ();
496 record_unwind_protect (choose_minibuf_frame_1
, Qnil
);
498 record_unwind_protect (Fset_window_configuration
,
499 Fcurrent_window_configuration (Qnil
));
501 /* If the minibuffer window is on a different frame, save that
502 frame's configuration too. */
503 mini_frame
= WINDOW_FRAME (XWINDOW (minibuf_window
));
504 if (!EQ (mini_frame
, selected_frame
))
505 record_unwind_protect (Fset_window_configuration
,
506 Fcurrent_window_configuration (mini_frame
));
508 /* If the minibuffer is on an iconified or invisible frame,
509 make it visible now. */
510 Fmake_frame_visible (mini_frame
);
512 if (minibuffer_auto_raise
)
513 Fraise_frame (mini_frame
);
515 /* We have to do this after saving the window configuration
516 since that is what restores the current buffer. */
518 /* Arrange to restore a number of minibuffer-related variables.
519 We could bind each variable separately, but that would use lots of
522 = Fcons (Voverriding_local_map
,
523 Fcons (minibuf_window
, minibuf_save_list
));
525 = Fcons (minibuf_prompt
,
526 Fcons (make_number (minibuf_prompt_width
),
528 Fcons (Vcurrent_prefix_arg
,
529 Fcons (Vminibuffer_history_position
,
530 Fcons (Vminibuffer_history_variable
,
531 minibuf_save_list
))))));
533 record_unwind_protect (read_minibuf_unwind
, Qnil
);
536 /* Now that we can restore all those variables, start changing them. */
538 minibuf_prompt_width
= 0;
539 minibuf_prompt
= Fcopy_sequence (prompt
);
540 Vminibuffer_history_position
= histpos
;
541 Vminibuffer_history_variable
= histvar
;
542 Vhelp_form
= Vminibuffer_help_form
;
544 if (inherit_input_method
)
546 /* `current-input-method' is buffer local. So, remember it in
547 INPUT_METHOD before changing the current buffer. */
548 input_method
= Fsymbol_value (Qcurrent_input_method
);
549 enable_multibyte
= current_buffer
->enable_multibyte_characters
;
552 /* Switch to the minibuffer. */
554 minibuffer
= get_minibuffer (minibuf_level
);
555 Fset_buffer (minibuffer
);
557 /* The current buffer's default directory is usually the right thing
558 for our minibuffer here. However, if you're typing a command at
559 a minibuffer-only frame when minibuf_level is zero, then buf IS
560 the current_buffer, so reset_buffer leaves buf's default
561 directory unchanged. This is a bummer when you've just started
562 up Emacs and buf's default directory is Qnil. Here's a hack; can
563 you think of something better to do? Find another buffer with a
564 better directory, and use that one instead. */
565 if (STRINGP (ambient_dir
))
566 current_buffer
->directory
= ambient_dir
;
569 Lisp_Object buf_list
;
571 for (buf_list
= Vbuffer_alist
;
573 buf_list
= XCDR (buf_list
))
575 Lisp_Object other_buf
;
577 other_buf
= XCDR (XCAR (buf_list
));
578 if (STRINGP (XBUFFER (other_buf
)->directory
))
580 current_buffer
->directory
= XBUFFER (other_buf
)->directory
;
586 if (!EQ (mini_frame
, selected_frame
))
587 Fredirect_frame_focus (selected_frame
, mini_frame
);
589 Vminibuf_scroll_window
= selected_window
;
590 if (minibuf_level
== 1 || !EQ (minibuf_window
, selected_window
))
591 minibuf_selected_window
= selected_window
;
592 Fset_window_buffer (minibuf_window
, Fcurrent_buffer (), Qnil
);
593 Fselect_window (minibuf_window
, Qnil
);
594 XSETFASTINT (XWINDOW (minibuf_window
)->hscroll
, 0);
596 Fmake_local_variable (Qprint_escape_newlines
);
597 print_escape_newlines
= 1;
599 /* Erase the buffer. */
601 int count1
= SPECPDL_INDEX ();
602 specbind (Qinhibit_read_only
, Qt
);
603 specbind (Qinhibit_modification_hooks
, Qt
);
605 unbind_to (count1
, Qnil
);
608 if (!NILP (current_buffer
->enable_multibyte_characters
)
609 && ! STRING_MULTIBYTE (minibuf_prompt
))
610 minibuf_prompt
= Fstring_make_multibyte (minibuf_prompt
);
612 /* Insert the prompt, record where it ends. */
613 Finsert (1, &minibuf_prompt
);
616 Fput_text_property (make_number (BEG
), make_number (PT
),
617 Qfront_sticky
, Qt
, Qnil
);
618 Fput_text_property (make_number (BEG
), make_number (PT
),
619 Qrear_nonsticky
, Qt
, Qnil
);
620 Fput_text_property (make_number (BEG
), make_number (PT
),
622 Fadd_text_properties (make_number (BEG
), make_number (PT
),
623 Vminibuffer_prompt_properties
, Qnil
);
626 minibuf_prompt_width
= (int) current_column (); /* iftc */
628 /* If appropriate, copy enable-multibyte-characters into the minibuffer. */
629 if (inherit_input_method
)
630 current_buffer
->enable_multibyte_characters
= enable_multibyte
;
632 /* Put in the initial input. */
635 Finsert (1, &initial
);
636 if (INTEGERP (backup_n
))
637 Fforward_char (backup_n
);
640 clear_message (1, 1);
641 current_buffer
->keymap
= map
;
643 /* Turn on an input method stored in INPUT_METHOD if any. */
644 if (STRINGP (input_method
) && !NILP (Ffboundp (Qactivate_input_method
)))
645 call1 (Qactivate_input_method
, input_method
);
647 /* Run our hook, but not if it is empty.
648 (run-hooks would do nothing if it is empty,
649 but it's important to save time here in the usual case.) */
650 if (!NILP (Vminibuffer_setup_hook
) && !EQ (Vminibuffer_setup_hook
, Qunbound
)
651 && !NILP (Vrun_hooks
))
652 call1 (Vrun_hooks
, Qminibuffer_setup_hook
);
654 /* Don't allow the user to undo past this point. */
655 current_buffer
->undo_list
= Qnil
;
659 /* If cursor is on the minibuffer line,
660 show the user we have exited by putting it in column 0. */
661 if (XWINDOW (minibuf_window
)->cursor
.vpos
>= 0
664 XWINDOW (minibuf_window
)->cursor
.hpos
= 0;
665 XWINDOW (minibuf_window
)->cursor
.x
= 0;
666 XWINDOW (minibuf_window
)->must_be_updated_p
= 1;
667 update_frame (XFRAME (selected_frame
), 1, 1);
668 if (rif
&& rif
->flush_display
)
669 rif
->flush_display (XFRAME (XWINDOW (minibuf_window
)->frame
));
672 /* Make minibuffer contents into a string. */
673 Fset_buffer (minibuffer
);
675 val
= Fminibuffer_contents ();
677 val
= Fminibuffer_contents_no_properties ();
679 /* VAL is the string of minibuffer text. */
681 last_minibuf_string
= val
;
683 /* Choose the string to add to the history. */
684 if (SCHARS (val
) != 0)
686 else if (STRINGP (defalt
))
691 /* Add the value to the appropriate history list, if any. */
692 if (SYMBOLP (Vminibuffer_history_variable
)
693 && !NILP (histstring
))
695 /* If the caller wanted to save the value read on a history list,
696 then do so if the value is not already the front of the list. */
699 /* If variable is unbound, make it nil. */
700 if (EQ (SYMBOL_VALUE (Vminibuffer_history_variable
), Qunbound
))
701 Fset (Vminibuffer_history_variable
, Qnil
);
703 histval
= Fsymbol_value (Vminibuffer_history_variable
);
705 /* The value of the history variable must be a cons or nil. Other
706 values are unacceptable. We silently ignore these values. */
710 /* Don't duplicate the most recent entry in the history. */
711 && NILP (Fequal (histstring
, Fcar (histval
)))))
715 histval
= Fcons (histstring
, histval
);
716 Fset (Vminibuffer_history_variable
, histval
);
718 /* Truncate if requested. */
719 length
= Fget (Vminibuffer_history_variable
, Qhistory_length
);
720 if (NILP (length
)) length
= Vhistory_length
;
721 if (INTEGERP (length
))
723 if (XINT (length
) <= 0)
724 Fset (Vminibuffer_history_variable
, Qnil
);
729 temp
= Fnthcdr (Fsub1 (length
), histval
);
730 if (CONSP (temp
)) Fsetcdr (temp
, Qnil
);
736 /* If Lisp form desired instead of string, parse it. */
738 val
= string_to_object (val
, defalt
);
740 /* The appropriate frame will get selected
741 in set-window-configuration. */
743 return unbind_to (count
, val
);
746 /* Return a buffer to be used as the minibuffer at depth `depth'.
747 depth = 0 is the lowest allowed argument, and that is the value
748 used for nonrecursive minibuffer invocations */
751 get_minibuffer (depth
)
754 Lisp_Object tail
, num
, buf
;
756 extern Lisp_Object
nconc2 ();
758 XSETFASTINT (num
, depth
);
759 tail
= Fnthcdr (num
, Vminibuffer_list
);
762 tail
= Fcons (Qnil
, Qnil
);
763 Vminibuffer_list
= nconc2 (Vminibuffer_list
, tail
);
766 if (NILP (buf
) || NILP (XBUFFER (buf
)->name
))
768 sprintf (name
, " *Minibuf-%d*", depth
);
769 buf
= Fget_buffer_create (build_string (name
));
771 /* Although the buffer's name starts with a space, undo should be
773 Fbuffer_enable_undo (buf
);
779 int count
= SPECPDL_INDEX ();
781 reset_buffer (XBUFFER (buf
));
782 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
784 Fkill_all_local_variables ();
785 unbind_to (count
, Qnil
);
791 /* This function is called on exiting minibuffer, whether normally or
792 not, and it restores the current window, buffer, etc. */
795 read_minibuf_unwind (data
)
798 Lisp_Object old_deactivate_mark
;
801 /* We are exiting the minibuffer one way or the other,
803 if (!NILP (Vminibuffer_exit_hook
) && !EQ (Vminibuffer_exit_hook
, Qunbound
)
804 && !NILP (Vrun_hooks
))
805 safe_run_hooks (Qminibuffer_exit_hook
);
807 /* If this was a recursive minibuffer,
808 tie the minibuffer window back to the outer level minibuffer buffer. */
811 window
= minibuf_window
;
812 /* To keep things predictable, in case it matters, let's be in the
813 minibuffer when we reset the relevant variables. */
814 Fset_buffer (XWINDOW (window
)->buffer
);
816 /* Restore prompt, etc, from outer minibuffer level. */
817 minibuf_prompt
= Fcar (minibuf_save_list
);
818 minibuf_save_list
= Fcdr (minibuf_save_list
);
819 minibuf_prompt_width
= XFASTINT (Fcar (minibuf_save_list
));
820 minibuf_save_list
= Fcdr (minibuf_save_list
);
821 Vhelp_form
= Fcar (minibuf_save_list
);
822 minibuf_save_list
= Fcdr (minibuf_save_list
);
823 Vcurrent_prefix_arg
= Fcar (minibuf_save_list
);
824 minibuf_save_list
= Fcdr (minibuf_save_list
);
825 Vminibuffer_history_position
= Fcar (minibuf_save_list
);
826 minibuf_save_list
= Fcdr (minibuf_save_list
);
827 Vminibuffer_history_variable
= Fcar (minibuf_save_list
);
828 minibuf_save_list
= Fcdr (minibuf_save_list
);
829 Voverriding_local_map
= Fcar (minibuf_save_list
);
830 minibuf_save_list
= Fcdr (minibuf_save_list
);
832 temp
= Fcar (minibuf_save_list
);
833 if (FRAME_LIVE_P (XFRAME (WINDOW_FRAME (XWINDOW (temp
)))))
834 minibuf_window
= temp
;
836 minibuf_save_list
= Fcdr (minibuf_save_list
);
838 /* Erase the minibuffer we were using at this level. */
840 int count
= SPECPDL_INDEX ();
841 /* Prevent error in erase-buffer. */
842 specbind (Qinhibit_read_only
, Qt
);
843 specbind (Qinhibit_modification_hooks
, Qt
);
844 old_deactivate_mark
= Vdeactivate_mark
;
846 Vdeactivate_mark
= old_deactivate_mark
;
847 unbind_to (count
, Qnil
);
850 /* When we get to the outmost level, make sure we resize the
851 mini-window back to its normal size. */
852 if (minibuf_level
== 0)
853 resize_mini_window (XWINDOW (window
), 0);
855 /* Make sure minibuffer window is erased, not ignored. */
856 windows_or_buffers_changed
++;
857 XSETFASTINT (XWINDOW (window
)->last_modified
, 0);
858 XSETFASTINT (XWINDOW (window
)->last_overlay_modified
, 0);
863 DEFUN ("read-from-minibuffer", Fread_from_minibuffer
, Sread_from_minibuffer
, 1, 7, 0,
864 doc
: /* Read a string from the minibuffer, prompting with string PROMPT.
865 If optional second arg INITIAL-CONTENTS is non-nil, it is a string
866 to be inserted into the minibuffer before reading input.
867 If INITIAL-CONTENTS is (STRING . POSITION), the initial input
868 is STRING, but point is placed at position POSITION in the minibuffer.
869 Third arg KEYMAP is a keymap to use whilst reading;
870 if omitted or nil, the default is `minibuffer-local-map'.
871 If fourth arg READ is non-nil, then interpret the result as a Lisp object
872 and return that object:
873 in other words, do `(car (read-from-string INPUT-STRING))'
874 Fifth arg HIST, if non-nil, specifies a history list
875 and optionally the initial position in the list.
876 It can be a symbol, which is the history list variable to use,
877 or it can be a cons cell (HISTVAR . HISTPOS).
878 In that case, HISTVAR is the history list variable to use,
879 and HISTPOS is the initial position (the position in the list
880 which INITIAL-CONTENTS corresponds to).
881 Positions are counted starting from 1 at the beginning of the list.
882 Sixth arg DEFAULT-VALUE is the default value. If non-nil, it is available
883 for history commands; but `read-from-minibuffer' does NOT return DEFAULT-VALUE
884 if the user enters empty input! It returns the empty string.
885 Seventh arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits
886 the current input method and the setting of `enable-multibyte-characters'.
887 If the variable `minibuffer-allow-text-properties' is non-nil,
888 then the string which is returned includes whatever text properties
889 were present in the minibuffer. Otherwise the value has no text properties. */)
890 (prompt
, initial_contents
, keymap
, read
, hist
, default_value
, inherit_input_method
)
891 Lisp_Object prompt
, initial_contents
, keymap
, read
, hist
, default_value
;
892 Lisp_Object inherit_input_method
;
895 Lisp_Object histvar
, histpos
, position
, val
;
900 CHECK_STRING (prompt
);
901 if (!NILP (initial_contents
))
903 if (CONSP (initial_contents
))
905 position
= Fcdr (initial_contents
);
906 initial_contents
= Fcar (initial_contents
);
908 CHECK_STRING (initial_contents
);
909 if (!NILP (position
))
911 CHECK_NUMBER (position
);
912 /* Convert to distance from end of input. */
913 if (XINT (position
) < 1)
914 /* A number too small means the beginning of the string. */
915 pos
= - SCHARS (initial_contents
);
917 pos
= XINT (position
) - 1 - SCHARS (initial_contents
);
922 keymap
= Vminibuffer_local_map
;
924 keymap
= get_keymap (keymap
, 1, 0);
933 histvar
= Fcar_safe (hist
);
934 histpos
= Fcdr_safe (hist
);
937 histvar
= Qminibuffer_history
;
939 XSETFASTINT (histpos
, 0);
941 GCPRO1 (default_value
);
942 val
= read_minibuf (keymap
, initial_contents
, prompt
,
943 make_number (pos
), !NILP (read
),
944 histvar
, histpos
, default_value
,
945 minibuffer_allow_text_properties
,
946 !NILP (inherit_input_method
));
951 DEFUN ("read-minibuffer", Fread_minibuffer
, Sread_minibuffer
, 1, 2, 0,
952 doc
: /* Return a Lisp object read using the minibuffer.
953 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS
954 is a string to insert in the minibuffer before reading. */)
955 (prompt
, initial_contents
)
956 Lisp_Object prompt
, initial_contents
;
958 CHECK_STRING (prompt
);
959 if (!NILP (initial_contents
))
960 CHECK_STRING (initial_contents
);
961 return read_minibuf (Vminibuffer_local_map
, initial_contents
,
962 prompt
, Qnil
, 1, Qminibuffer_history
,
963 make_number (0), Qnil
, 0, 0);
966 DEFUN ("eval-minibuffer", Feval_minibuffer
, Seval_minibuffer
, 1, 2, 0,
967 doc
: /* Return value of Lisp expression read using the minibuffer.
968 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS
969 is a string to insert in the minibuffer before reading. */)
970 (prompt
, initial_contents
)
971 Lisp_Object prompt
, initial_contents
;
973 return Feval (Fread_minibuffer (prompt
, initial_contents
));
976 /* Functions that use the minibuffer to read various things. */
978 DEFUN ("read-string", Fread_string
, Sread_string
, 1, 5, 0,
979 doc
: /* Read a string from the minibuffer, prompting with string PROMPT.
980 If non-nil, second arg INITIAL-INPUT is a string to insert before reading.
981 The third arg HISTORY, if non-nil, specifies a history list
982 and optionally the initial position in the list.
983 See `read-from-minibuffer' for details of HISTORY argument.
984 Fourth arg DEFAULT-VALUE is the default value. If non-nil, it is used
985 for history commands, and as the value to return if the user enters
987 Fifth arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits
988 the current input method and the setting of `enable-multibyte-characters'. */)
989 (prompt
, initial_input
, history
, default_value
, inherit_input_method
)
990 Lisp_Object prompt
, initial_input
, history
, default_value
;
991 Lisp_Object inherit_input_method
;
994 val
= Fread_from_minibuffer (prompt
, initial_input
, Qnil
,
995 Qnil
, history
, default_value
,
996 inherit_input_method
);
997 if (STRINGP (val
) && SCHARS (val
) == 0 && ! NILP (default_value
))
1002 DEFUN ("read-no-blanks-input", Fread_no_blanks_input
, Sread_no_blanks_input
, 1, 3, 0,
1003 doc
: /* Read a string from the terminal, not allowing blanks.
1004 Prompt with PROMPT, and provide INITIAL as an initial value of the input string.
1005 Third arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits
1006 the current input method and the setting of `enable-multibyte-characters'. */)
1007 (prompt
, initial
, inherit_input_method
)
1008 Lisp_Object prompt
, initial
, inherit_input_method
;
1010 CHECK_STRING (prompt
);
1011 if (! NILP (initial
))
1012 CHECK_STRING (initial
);
1014 return read_minibuf (Vminibuffer_local_ns_map
, initial
, prompt
, Qnil
,
1015 0, Qminibuffer_history
, make_number (0), Qnil
, 0,
1016 !NILP (inherit_input_method
));
1019 DEFUN ("read-command", Fread_command
, Sread_command
, 1, 2, 0,
1020 doc
: /* Read the name of a command and return as a symbol.
1021 Prompt with PROMPT. By default, return DEFAULT-VALUE. */)
1022 (prompt
, default_value
)
1023 Lisp_Object prompt
, default_value
;
1025 Lisp_Object name
, default_string
;
1027 if (NILP (default_value
))
1028 default_string
= Qnil
;
1029 else if (SYMBOLP (default_value
))
1030 default_string
= SYMBOL_NAME (default_value
);
1032 default_string
= default_value
;
1034 name
= Fcompleting_read (prompt
, Vobarray
, Qcommandp
, Qt
,
1035 Qnil
, Qnil
, default_string
, Qnil
);
1038 return Fintern (name
, Qnil
);
1042 DEFUN ("read-function", Fread_function
, Sread_function
, 1, 1, 0,
1043 doc
: /* One arg PROMPT, a string. Read the name of a function and return as a symbol.
1044 Prompt with PROMPT. */)
1048 return Fintern (Fcompleting_read (prompt
, Vobarray
, Qfboundp
, Qt
, Qnil
, Qnil
, Qnil
, Qnil
),
1053 DEFUN ("read-variable", Fread_variable
, Sread_variable
, 1, 2, 0,
1054 doc
: /* Read the name of a user variable and return it as a symbol.
1055 Prompt with PROMPT. By default, return DEFAULT-VALUE.
1056 A user variable is one for which `user-variable-p' returns non-nil. */)
1057 (prompt
, default_value
)
1058 Lisp_Object prompt
, default_value
;
1060 Lisp_Object name
, default_string
;
1062 if (NILP (default_value
))
1063 default_string
= Qnil
;
1064 else if (SYMBOLP (default_value
))
1065 default_string
= SYMBOL_NAME (default_value
);
1067 default_string
= default_value
;
1069 name
= Fcompleting_read (prompt
, Vobarray
,
1070 Quser_variable_p
, Qt
,
1071 Qnil
, Qnil
, default_string
, Qnil
);
1074 return Fintern (name
, Qnil
);
1077 DEFUN ("read-buffer", Fread_buffer
, Sread_buffer
, 1, 3, 0,
1078 doc
: /* Read the name of a buffer and return as a string.
1080 Optional second arg DEF is value to return if user enters an empty line.
1081 If optional third arg REQUIRE-MATCH is non-nil,
1082 only existing buffer names are allowed. */)
1083 (prompt
, def
, require_match
)
1084 Lisp_Object prompt
, def
, require_match
;
1086 Lisp_Object args
[4];
1089 def
= XBUFFER (def
)->name
;
1091 if (NILP (Vread_buffer_function
))
1095 args
[0] = build_string ("%s(default %s) ");
1098 prompt
= Fformat (3, args
);
1101 return Fcompleting_read (prompt
, Vbuffer_alist
, Qnil
,
1102 require_match
, Qnil
, Qbuffer_name_history
,
1107 args
[0] = Vread_buffer_function
;
1110 args
[3] = require_match
;
1111 return Ffuncall(4, args
);
1116 minibuf_conform_representation (string
, basis
)
1117 Lisp_Object string
, basis
;
1119 if (STRING_MULTIBYTE (string
) == STRING_MULTIBYTE (basis
))
1122 if (STRING_MULTIBYTE (string
))
1123 return Fstring_make_unibyte (string
);
1125 return Fstring_make_multibyte (string
);
1128 DEFUN ("try-completion", Ftry_completion
, Stry_completion
, 2, 3, 0,
1129 doc
: /* Return common substring of all completions of STRING in ALIST.
1130 Each car of each element of ALIST (or each element if it is not a cons cell)
1131 is tested to see if it begins with STRING.
1132 All that match are compared together; the longest initial sequence
1133 common to all matches is returned as a string.
1134 If there is no match at all, nil is returned.
1135 For a unique match which is exact, t is returned.
1137 If ALIST is a hash-table, all the string keys are the possible matches.
1138 If ALIST is an obarray, the names of all symbols in the obarray
1139 are the possible matches.
1141 ALIST can also be a function to do the completion itself.
1142 It receives three arguments: the values STRING, PREDICATE and nil.
1143 Whatever it returns becomes the value of `try-completion'.
1145 If optional third argument PREDICATE is non-nil,
1146 it is used to test each possible match.
1147 The match is a candidate only if PREDICATE returns non-nil.
1148 The argument given to PREDICATE is the alist element
1149 or the symbol from the obarray. If ALIST is a hash-table,
1150 predicate is called with two arguments: the key and the value.
1151 Additionally to this predicate, `completion-regexp-list'
1152 is used to further constrain the set of candidates. */)
1153 (string
, alist
, predicate
)
1154 Lisp_Object string
, alist
, predicate
;
1156 Lisp_Object bestmatch
, tail
, elt
, eltstring
;
1157 /* Size in bytes of BESTMATCH. */
1158 int bestmatchsize
= 0;
1159 /* These are in bytes, too. */
1160 int compare
, matchsize
;
1161 int type
= HASH_TABLE_P (alist
) ? 3
1162 : VECTORP (alist
) ? 2
1163 : NILP (alist
) || (CONSP (alist
)
1164 && (!SYMBOLP (XCAR (alist
))
1165 || NILP (XCAR (alist
))));
1166 int index
= 0, obsize
= 0;
1168 Lisp_Object bucket
, zero
, end
, tem
;
1169 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
1171 CHECK_STRING (string
);
1173 return call3 (alist
, string
, predicate
, Qnil
);
1175 bestmatch
= bucket
= Qnil
;
1177 /* If ALIST is not a list, set TAIL just for gc pro. */
1181 obsize
= XVECTOR (alist
)->size
;
1182 bucket
= XVECTOR (alist
)->contents
[index
];
1187 /* Get the next element of the alist, obarray, or hash-table. */
1188 /* Exit the loop if the elements are all used up. */
1189 /* elt gets the alist element or symbol.
1190 eltstring gets the name to check as a completion. */
1197 eltstring
= CONSP (elt
) ? XCAR (elt
) : elt
;
1202 if (XFASTINT (bucket
) != 0)
1205 eltstring
= Fsymbol_name (elt
);
1206 if (XSYMBOL (bucket
)->next
)
1207 XSETSYMBOL (bucket
, XSYMBOL (bucket
)->next
);
1209 XSETFASTINT (bucket
, 0);
1211 else if (++index
>= obsize
)
1215 bucket
= XVECTOR (alist
)->contents
[index
];
1219 else /* if (type == 3) */
1221 while (index
< HASH_TABLE_SIZE (XHASH_TABLE (alist
))
1222 && NILP (HASH_HASH (XHASH_TABLE (alist
), index
)))
1224 if (index
>= HASH_TABLE_SIZE (XHASH_TABLE (alist
)))
1227 elt
= eltstring
= HASH_KEY (XHASH_TABLE (alist
), index
++);
1230 /* Is this element a possible completion? */
1232 if (STRINGP (eltstring
)
1233 && SCHARS (string
) <= SCHARS (eltstring
)
1234 && (tem
= Fcompare_strings (eltstring
, make_number (0),
1235 make_number (SCHARS (string
)),
1236 string
, make_number (0), Qnil
,
1237 completion_ignore_case
?Qt
: Qnil
),
1241 Lisp_Object regexps
;
1243 XSETFASTINT (zero
, 0);
1245 /* Ignore this element if it fails to match all the regexps. */
1246 for (regexps
= Vcompletion_regexp_list
; CONSP (regexps
);
1247 regexps
= XCDR (regexps
))
1249 tem
= Fstring_match (XCAR (regexps
), eltstring
, zero
);
1253 if (CONSP (regexps
))
1256 /* Ignore this element if there is a predicate
1257 and the predicate doesn't like it. */
1259 if (!NILP (predicate
))
1261 if (EQ (predicate
, Qcommandp
))
1262 tem
= Fcommandp (elt
, Qnil
);
1265 GCPRO4 (tail
, string
, eltstring
, bestmatch
);
1267 ? call2 (predicate
, elt
,
1268 HASH_VALUE (XHASH_TABLE (alist
), index
- 1))
1269 : call1 (predicate
, elt
);
1272 if (NILP (tem
)) continue;
1275 /* Update computation of how much all possible completions match */
1277 if (NILP (bestmatch
))
1280 bestmatch
= eltstring
;
1281 bestmatchsize
= SCHARS (eltstring
);
1285 compare
= min (bestmatchsize
, SCHARS (eltstring
));
1286 tem
= Fcompare_strings (bestmatch
, make_number (0),
1287 make_number (compare
),
1288 eltstring
, make_number (0),
1289 make_number (compare
),
1290 completion_ignore_case
? Qt
: Qnil
);
1292 matchsize
= compare
;
1293 else if (XINT (tem
) < 0)
1294 matchsize
= - XINT (tem
) - 1;
1296 matchsize
= XINT (tem
) - 1;
1299 /* When can this happen ? -stef */
1300 matchsize
= compare
;
1301 if (completion_ignore_case
)
1303 /* If this is an exact match except for case,
1304 use it as the best match rather than one that is not an
1305 exact match. This way, we get the case pattern
1306 of the actual match. */
1307 if ((matchsize
== SCHARS (eltstring
)
1308 && matchsize
< SCHARS (bestmatch
))
1310 /* If there is more than one exact match ignoring case,
1311 and one of them is exact including case,
1313 /* If there is no exact match ignoring case,
1314 prefer a match that does not change the case
1316 ((matchsize
== SCHARS (eltstring
))
1318 (matchsize
== SCHARS (bestmatch
))
1319 && (tem
= Fcompare_strings (eltstring
, make_number (0),
1320 make_number (SCHARS (string
)),
1321 string
, make_number (0),
1325 && (tem
= Fcompare_strings (bestmatch
, make_number (0),
1326 make_number (SCHARS (string
)),
1327 string
, make_number (0),
1331 bestmatch
= eltstring
;
1333 if (bestmatchsize
!= SCHARS (eltstring
)
1334 || bestmatchsize
!= matchsize
)
1335 /* Don't count the same string multiple times. */
1337 bestmatchsize
= matchsize
;
1338 if (matchsize
<= SCHARS (string
)
1340 /* No need to look any further. */
1346 if (NILP (bestmatch
))
1347 return Qnil
; /* No completions found */
1348 /* If we are ignoring case, and there is no exact match,
1349 and no additional text was supplied,
1350 don't change the case of what the user typed. */
1351 if (completion_ignore_case
&& bestmatchsize
== SCHARS (string
)
1352 && SCHARS (bestmatch
) > bestmatchsize
)
1353 return minibuf_conform_representation (string
, bestmatch
);
1355 /* Return t if the supplied string is an exact match (counting case);
1356 it does not require any change to be made. */
1357 if (matchcount
== 1 && bestmatchsize
== SCHARS (string
)
1358 && (tem
= Fcompare_strings (bestmatch
, make_number (0),
1359 make_number (bestmatchsize
),
1360 string
, make_number (0),
1361 make_number (bestmatchsize
),
1366 XSETFASTINT (zero
, 0); /* Else extract the part in which */
1367 XSETFASTINT (end
, bestmatchsize
); /* all completions agree */
1368 return Fsubstring (bestmatch
, zero
, end
);
1371 DEFUN ("all-completions", Fall_completions
, Sall_completions
, 2, 4, 0,
1372 doc
: /* Search for partial matches to STRING in ALIST.
1373 Each car of each element of ALIST (or each element if it is not a cons cell)
1374 is tested to see if it begins with STRING.
1375 The value is a list of all the strings from ALIST that match.
1377 If ALIST is a hash-table, all the string keys are the possible matches.
1378 If ALIST is an obarray, the names of all symbols in the obarray
1379 are the possible matches.
1381 ALIST can also be a function to do the completion itself.
1382 It receives three arguments: the values STRING, PREDICATE and t.
1383 Whatever it returns becomes the value of `all-completions'.
1385 If optional third argument PREDICATE is non-nil,
1386 it is used to test each possible match.
1387 The match is a candidate only if PREDICATE returns non-nil.
1388 The argument given to PREDICATE is the alist element
1389 or the symbol from the obarray. If ALIST is a hash-table,
1390 predicate is called with two arguments: the key and the value.
1391 Additionally to this predicate, `completion-regexp-list'
1392 is used to further constrain the set of candidates.
1394 If the optional fourth argument HIDE-SPACES is non-nil,
1395 strings in ALIST that start with a space
1396 are ignored unless STRING itself starts with a space. */)
1397 (string
, alist
, predicate
, hide_spaces
)
1398 Lisp_Object string
, alist
, predicate
, hide_spaces
;
1400 Lisp_Object tail
, elt
, eltstring
;
1401 Lisp_Object allmatches
;
1402 int type
= HASH_TABLE_P (alist
) ? 3
1403 : VECTORP (alist
) ? 2
1404 : NILP (alist
) || (CONSP (alist
)
1405 && (!SYMBOLP (XCAR (alist
))
1406 || NILP (XCAR (alist
))));
1407 int index
= 0, obsize
= 0;
1408 Lisp_Object bucket
, tem
;
1409 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
1411 CHECK_STRING (string
);
1413 return call3 (alist
, string
, predicate
, Qt
);
1414 allmatches
= bucket
= Qnil
;
1416 /* If ALIST is not a list, set TAIL just for gc pro. */
1420 obsize
= XVECTOR (alist
)->size
;
1421 bucket
= XVECTOR (alist
)->contents
[index
];
1426 /* Get the next element of the alist, obarray, or hash-table. */
1427 /* Exit the loop if the elements are all used up. */
1428 /* elt gets the alist element or symbol.
1429 eltstring gets the name to check as a completion. */
1436 eltstring
= CONSP (elt
) ? XCAR (elt
) : elt
;
1441 if (XFASTINT (bucket
) != 0)
1444 eltstring
= Fsymbol_name (elt
);
1445 if (XSYMBOL (bucket
)->next
)
1446 XSETSYMBOL (bucket
, XSYMBOL (bucket
)->next
);
1448 XSETFASTINT (bucket
, 0);
1450 else if (++index
>= obsize
)
1454 bucket
= XVECTOR (alist
)->contents
[index
];
1458 else /* if (type == 3) */
1460 while (index
< HASH_TABLE_SIZE (XHASH_TABLE (alist
))
1461 && NILP (HASH_HASH (XHASH_TABLE (alist
), index
)))
1463 if (index
>= HASH_TABLE_SIZE (XHASH_TABLE (alist
)))
1466 elt
= eltstring
= HASH_KEY (XHASH_TABLE (alist
), index
++);
1469 /* Is this element a possible completion? */
1471 if (STRINGP (eltstring
)
1472 && SCHARS (string
) <= SCHARS (eltstring
)
1473 /* If HIDE_SPACES, reject alternatives that start with space
1474 unless the input starts with space. */
1475 && ((SBYTES (string
) > 0
1476 && SREF (string
, 0) == ' ')
1477 || SREF (eltstring
, 0) != ' '
1478 || NILP (hide_spaces
))
1479 && (tem
= Fcompare_strings (eltstring
, make_number (0),
1480 make_number (SCHARS (string
)),
1481 string
, make_number (0),
1482 make_number (SCHARS (string
)),
1483 completion_ignore_case
? Qt
: Qnil
),
1487 Lisp_Object regexps
;
1489 XSETFASTINT (zero
, 0);
1491 /* Ignore this element if it fails to match all the regexps. */
1492 for (regexps
= Vcompletion_regexp_list
; CONSP (regexps
);
1493 regexps
= XCDR (regexps
))
1495 tem
= Fstring_match (XCAR (regexps
), eltstring
, zero
);
1499 if (CONSP (regexps
))
1502 /* Ignore this element if there is a predicate
1503 and the predicate doesn't like it. */
1505 if (!NILP (predicate
))
1507 if (EQ (predicate
, Qcommandp
))
1508 tem
= Fcommandp (elt
, Qnil
);
1511 GCPRO4 (tail
, eltstring
, allmatches
, string
);
1513 ? call2 (predicate
, elt
,
1514 HASH_VALUE (XHASH_TABLE (alist
), index
- 1))
1515 : call1 (predicate
, elt
);
1518 if (NILP (tem
)) continue;
1520 /* Ok => put it on the list. */
1521 allmatches
= Fcons (eltstring
, allmatches
);
1525 return Fnreverse (allmatches
);
1528 Lisp_Object Vminibuffer_completion_table
, Qminibuffer_completion_table
;
1529 Lisp_Object Vminibuffer_completion_predicate
, Qminibuffer_completion_predicate
;
1530 Lisp_Object Vminibuffer_completion_confirm
, Qminibuffer_completion_confirm
;
1531 Lisp_Object Vminibuffer_completing_file_name
;
1533 DEFUN ("completing-read", Fcompleting_read
, Scompleting_read
, 2, 8, 0,
1534 doc
: /* Read a string in the minibuffer, with completion.
1535 PROMPT is a string to prompt with; normally it ends in a colon and a space.
1536 TABLE is an alist whose elements' cars are strings, or an obarray.
1537 TABLE can also be a function to do the completion itself.
1538 PREDICATE limits completion to a subset of TABLE.
1539 See `try-completion' and `all-completions' for more details
1540 on completion, TABLE, and PREDICATE.
1542 If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless
1543 the input is (or completes to) an element of TABLE or is null.
1544 If it is also not t, typing RET does not exit if it does non-null completion.
1545 If the input is null, `completing-read' returns an empty string,
1546 regardless of the value of REQUIRE-MATCH.
1548 If INITIAL-INPUT is non-nil, insert it in the minibuffer initially.
1549 If it is (STRING . POSITION), the initial input
1550 is STRING, but point is placed POSITION characters into the string.
1551 This feature is deprecated--it is best to pass nil for INITIAL-INPUT
1552 and supply the default value DEF instead. The user can yank the
1553 default value into the minibuffer easily using \\[next-history-element].
1555 HIST, if non-nil, specifies a history list
1556 and optionally the initial position in the list.
1557 It can be a symbol, which is the history list variable to use,
1558 or it can be a cons cell (HISTVAR . HISTPOS).
1559 In that case, HISTVAR is the history list variable to use,
1560 and HISTPOS is the initial position (the position in the list
1561 which INITIAL-INPUT corresponds to).
1562 Positions are counted starting from 1 at the beginning of the list.
1563 The variable `history-length' controls the maximum length of a
1566 DEF, if non-nil, is the default value.
1568 If INHERIT-INPUT-METHOD is non-nil, the minibuffer inherits
1569 the current input method and the setting of `enable-multibyte-characters'.
1571 Completion ignores case if the ambient value of
1572 `completion-ignore-case' is non-nil. */)
1573 (prompt
, table
, predicate
, require_match
, initial_input
, hist
, def
, inherit_input_method
)
1574 Lisp_Object prompt
, table
, predicate
, require_match
, initial_input
;
1575 Lisp_Object hist
, def
, inherit_input_method
;
1577 Lisp_Object val
, histvar
, histpos
, position
;
1580 int count
= SPECPDL_INDEX ();
1581 struct gcpro gcpro1
;
1583 init
= initial_input
;
1586 specbind (Qminibuffer_completion_table
, table
);
1587 specbind (Qminibuffer_completion_predicate
, predicate
);
1588 specbind (Qminibuffer_completion_confirm
,
1589 EQ (require_match
, Qt
) ? Qnil
: require_match
);
1590 last_exact_completion
= Qnil
;
1597 position
= Fcdr (init
);
1600 CHECK_STRING (init
);
1601 if (!NILP (position
))
1603 CHECK_NUMBER (position
);
1604 /* Convert to distance from end of input. */
1605 pos
= XINT (position
) - SCHARS (init
);
1616 histvar
= Fcar_safe (hist
);
1617 histpos
= Fcdr_safe (hist
);
1620 histvar
= Qminibuffer_history
;
1622 XSETFASTINT (histpos
, 0);
1624 val
= read_minibuf (NILP (require_match
)
1625 ? Vminibuffer_local_completion_map
1626 : Vminibuffer_local_must_match_map
,
1627 init
, prompt
, make_number (pos
), 0,
1628 histvar
, histpos
, def
, 0,
1629 !NILP (inherit_input_method
));
1631 if (STRINGP (val
) && SCHARS (val
) == 0 && ! NILP (def
))
1634 RETURN_UNGCPRO (unbind_to (count
, val
));
1637 Lisp_Object
Fminibuffer_completion_help ();
1638 Lisp_Object
Fassoc_string ();
1640 /* Test whether TXT is an exact completion. */
1641 DEFUN ("test-completion", Ftest_completion
, Stest_completion
, 2, 3, 0,
1642 doc
: /* Return non-nil if STRING is a valid completion.
1643 Takes the same arguments as `all-completions' and `try-completion'.
1644 If ALIST is a function, it is called with three arguments:
1645 the values STRING, PREDICATE and `lambda'. */)
1646 (string
, alist
, predicate
)
1647 Lisp_Object string
, alist
, predicate
;
1649 Lisp_Object regexps
, tem
= Qnil
;
1652 CHECK_STRING (string
);
1654 if ((CONSP (alist
) && (!SYMBOLP (XCAR (alist
)) || NILP (XCAR (alist
))))
1657 tem
= Fassoc_string (string
, alist
, completion_ignore_case
? Qt
: Qnil
);
1661 else if (VECTORP (alist
))
1663 /* Bypass intern-soft as that loses for nil. */
1664 tem
= oblookup (alist
,
1670 if (STRING_MULTIBYTE (string
))
1671 string
= Fstring_make_unibyte (string
);
1673 string
= Fstring_make_multibyte (string
);
1675 tem
= oblookup (Vminibuffer_completion_table
,
1683 else if (HASH_TABLE_P (alist
))
1685 i
= hash_lookup (XHASH_TABLE (alist
), string
, NULL
);
1687 tem
= HASH_KEY (XHASH_TABLE (alist
), i
);
1692 return call3 (alist
, string
, predicate
, Qlambda
);
1694 /* Reject this element if it fails to match all the regexps. */
1695 for (regexps
= Vcompletion_regexp_list
; CONSP (regexps
);
1696 regexps
= XCDR (regexps
))
1698 if (NILP (Fstring_match (XCAR (regexps
),
1699 SYMBOLP (tem
) ? string
: tem
,
1704 /* Finally, check the predicate. */
1705 if (!NILP (predicate
))
1706 return HASH_TABLE_P (alist
)
1707 ? call2 (predicate
, tem
, HASH_VALUE (XHASH_TABLE (alist
), i
))
1708 : call1 (predicate
, tem
);
1714 * 0 no possible completion
1715 * 1 was already an exact and unique completion
1716 * 3 was already an exact completion
1717 * 4 completed to an exact completion
1718 * 5 some completion happened
1719 * 6 no completion happened
1724 Lisp_Object completion
, string
, tem
;
1727 struct gcpro gcpro1
, gcpro2
;
1729 completion
= Ftry_completion (minibuffer_completion_contents (),
1730 Vminibuffer_completion_table
,
1731 Vminibuffer_completion_predicate
);
1732 last
= last_exact_completion
;
1733 last_exact_completion
= Qnil
;
1735 GCPRO2 (completion
, last
);
1737 if (NILP (completion
))
1740 temp_echo_area_glyphs (build_string (" [No match]"));
1745 if (EQ (completion
, Qt
)) /* exact and unique match */
1751 string
= minibuffer_completion_contents ();
1753 /* COMPLETEDP should be true if some completion was done, which
1754 doesn't include simply changing the case of the entered string.
1755 However, for appearance, the string is rewritten if the case
1757 tem
= Fcompare_strings (completion
, Qnil
, Qnil
, string
, Qnil
, Qnil
, Qt
);
1758 completedp
= !EQ (tem
, Qt
);
1760 tem
= Fcompare_strings (completion
, Qnil
, Qnil
, string
, Qnil
, Qnil
, Qnil
);
1762 /* Rewrite the user's input. */
1764 int prompt_end
= XINT (Fminibuffer_prompt_end ());
1765 /* Some completion happened */
1767 if (! NILP (Vminibuffer_completing_file_name
)
1768 && SREF (completion
, SBYTES (completion
) - 1) == '/'
1770 && FETCH_CHAR (PT_BYTE
) == '/')
1772 del_range (prompt_end
, PT
+ 1);
1775 del_range (prompt_end
, PT
);
1777 Finsert (1, &completion
);
1780 /* The case of the string changed, but that's all. We're not
1781 sure whether this is a unique completion or not, so try again
1782 using the real case (this shouldn't recurse again, because
1783 the next time try-completion will return either `t' or the
1787 return do_completion ();
1791 /* It did find a match. Do we match some possibility exactly now? */
1792 tem
= Ftest_completion (Fminibuffer_contents (),
1793 Vminibuffer_completion_table
,
1794 Vminibuffer_completion_predicate
);
1797 /* not an exact match */
1801 else if (!NILP (Vcompletion_auto_help
))
1802 Fminibuffer_completion_help ();
1804 temp_echo_area_glyphs (build_string (" [Next char not unique]"));
1807 else if (completedp
)
1812 /* If the last exact completion and this one were the same,
1813 it means we've already given a "Complete but not unique"
1814 message and the user's hit TAB again, so now we give him help. */
1815 last_exact_completion
= completion
;
1818 tem
= minibuffer_completion_contents ();
1819 if (!NILP (Fequal (tem
, last
)))
1820 Fminibuffer_completion_help ();
1826 /* Like assoc but assumes KEY is a string, and ignores case if appropriate. */
1828 DEFUN ("assoc-string", Fassoc_string
, Sassoc_string
, 2, 3, 0,
1829 doc
: /* Like `assoc' but specifically for strings.
1830 Unibyte strings are converted to multibyte for comparison.
1831 And case is ignored if CASE-FOLD is non-nil.
1832 As opposed to `assoc', it will also match an entry consisting of a single
1833 string rather than a cons cell whose car is a string. */)
1834 (key
, list
, case_fold
)
1835 register Lisp_Object key
;
1836 Lisp_Object list
, case_fold
;
1838 register Lisp_Object tail
;
1840 for (tail
= list
; !NILP (tail
); tail
= Fcdr (tail
))
1842 register Lisp_Object elt
, tem
, thiscar
;
1844 thiscar
= CONSP (elt
) ? XCAR (elt
) : elt
;
1845 if (!STRINGP (thiscar
))
1847 tem
= Fcompare_strings (thiscar
, make_number (0), Qnil
,
1848 key
, make_number (0), Qnil
,
1857 DEFUN ("minibuffer-complete", Fminibuffer_complete
, Sminibuffer_complete
, 0, 0, "",
1858 doc
: /* Complete the minibuffer contents as far as possible.
1859 Return nil if there is no valid completion, else t.
1860 If no characters can be completed, display a list of possible completions.
1861 If you repeat this command after it displayed such a list,
1862 scroll the window of possible completions. */)
1866 Lisp_Object window
, tem
;
1868 /* If the previous command was not this,
1869 mark the completion buffer obsolete. */
1870 if (! EQ (current_kboard
->Vlast_command
, Vthis_command
))
1871 Vminibuf_scroll_window
= Qnil
;
1873 window
= Vminibuf_scroll_window
;
1874 /* If there's a fresh completion window with a live buffer,
1875 and this command is repeated, scroll that window. */
1876 if (! NILP (window
) && ! NILP (XWINDOW (window
)->buffer
)
1877 && !NILP (XBUFFER (XWINDOW (window
)->buffer
)->name
))
1879 struct buffer
*obuf
= current_buffer
;
1881 Fset_buffer (XWINDOW (window
)->buffer
);
1882 tem
= Fpos_visible_in_window_p (make_number (ZV
), window
, Qnil
);
1884 /* If end is in view, scroll up to the beginning. */
1885 Fset_window_start (window
, make_number (BEGV
), Qnil
);
1887 /* Else scroll down one screen. */
1888 Fscroll_other_window (Qnil
);
1890 set_buffer_internal (obuf
);
1894 i
= do_completion ();
1902 Fgoto_char (make_number (ZV
));
1903 temp_echo_area_glyphs (build_string (" [Sole completion]"));
1908 Fgoto_char (make_number (ZV
));
1909 temp_echo_area_glyphs (build_string (" [Complete, but not unique]"));
1916 /* Subroutines of Fminibuffer_complete_and_exit. */
1918 /* This one is called by internal_condition_case to do the real work. */
1921 complete_and_exit_1 ()
1923 return make_number (do_completion ());
1926 /* This one is called by internal_condition_case if an error happens.
1927 Pretend the current value is an exact match. */
1930 complete_and_exit_2 (ignore
)
1933 return make_number (1);
1936 DEFUN ("minibuffer-complete-and-exit", Fminibuffer_complete_and_exit
,
1937 Sminibuffer_complete_and_exit
, 0, 0, "",
1938 doc
: /* If the minibuffer contents is a valid completion then exit.
1939 Otherwise try to complete it. If completion leads to a valid completion,
1940 a repetition of this command will exit. */)
1946 /* Allow user to specify null string */
1947 if (XINT (Fminibuffer_prompt_end ()) == ZV
)
1950 if (!NILP (Ftest_completion (Fminibuffer_contents (),
1951 Vminibuffer_completion_table
,
1952 Vminibuffer_completion_predicate
)))
1955 /* Call do_completion, but ignore errors. */
1957 val
= internal_condition_case (complete_and_exit_1
, Qerror
,
1958 complete_and_exit_2
);
1968 if (!NILP (Vminibuffer_completion_confirm
))
1970 temp_echo_area_glyphs (build_string (" [Confirm]"));
1980 return Fthrow (Qexit
, Qnil
);
1984 DEFUN ("minibuffer-complete-word", Fminibuffer_complete_word
, Sminibuffer_complete_word
,
1986 doc
: /* Complete the minibuffer contents at most a single word.
1987 After one word is completed as much as possible, a space or hyphen
1988 is added, provided that matches some possible completion.
1989 Return nil if there is no valid completion, else t. */)
1992 Lisp_Object completion
, tem
, tem1
;
1993 register int i
, i_byte
;
1994 register const unsigned char *completion_string
;
1995 struct gcpro gcpro1
, gcpro2
;
1996 int prompt_end_charpos
= XINT (Fminibuffer_prompt_end ());
1998 /* We keep calling Fbuffer_string rather than arrange for GC to
1999 hold onto a pointer to one of the strings thus made. */
2001 completion
= Ftry_completion (minibuffer_completion_contents (),
2002 Vminibuffer_completion_table
,
2003 Vminibuffer_completion_predicate
);
2004 if (NILP (completion
))
2007 temp_echo_area_glyphs (build_string (" [No match]"));
2010 if (EQ (completion
, Qt
))
2013 #if 0 /* How the below code used to look, for reference. */
2014 tem
= Fminibuffer_contents ();
2016 i
= ZV
- 1 - SCHARS (completion
);
2017 p
= SDATA (completion
);
2019 0 <= scmp (b
, p
, ZV
- 1))
2022 /* Set buffer to longest match of buffer tail and completion head. */
2023 while (0 <= scmp (b
+ i
, p
, ZV
- 1 - i
))
2025 del_range (1, i
+ 1);
2028 #else /* Rewritten code */
2030 int buffer_nchars
, completion_nchars
;
2032 CHECK_STRING (completion
);
2033 tem
= minibuffer_completion_contents ();
2034 GCPRO2 (completion
, tem
);
2035 /* If reading a file name,
2036 expand any $ENVVAR refs in the buffer and in TEM. */
2037 if (! NILP (Vminibuffer_completing_file_name
))
2039 Lisp_Object substituted
;
2040 substituted
= Fsubstitute_in_file_name (tem
);
2041 if (! EQ (substituted
, tem
))
2044 del_range (prompt_end_charpos
, PT
);
2048 buffer_nchars
= SCHARS (tem
); /* # chars in what we completed. */
2049 completion_nchars
= SCHARS (completion
);
2050 i
= buffer_nchars
- completion_nchars
;
2053 (tem1
= Fcompare_strings (tem
, make_number (0),
2054 make_number (buffer_nchars
),
2055 completion
, make_number (0),
2056 make_number (buffer_nchars
),
2057 completion_ignore_case
? Qt
: Qnil
),
2062 /* Make buffer (before point) contain the longest match
2063 of TEM's tail and COMPLETION's head. */
2069 tem1
= Fcompare_strings (tem
, make_number (start_pos
), Qnil
,
2070 completion
, make_number (0),
2071 make_number (buffer_nchars
),
2072 completion_ignore_case
? Qt
: Qnil
);
2079 del_range (start_pos
, start_pos
+ buffer_nchars
);
2083 #endif /* Rewritten code */
2086 int prompt_end_bytepos
;
2087 prompt_end_bytepos
= CHAR_TO_BYTE (prompt_end_charpos
);
2088 i
= PT
- prompt_end_charpos
;
2089 i_byte
= PT_BYTE
- prompt_end_bytepos
;
2092 /* If completion finds next char not unique,
2093 consider adding a space or a hyphen. */
2094 if (i
== SCHARS (completion
))
2096 GCPRO1 (completion
);
2097 tem
= Ftry_completion (concat2 (minibuffer_completion_contents (),
2098 build_string (" ")),
2099 Vminibuffer_completion_table
,
2100 Vminibuffer_completion_predicate
);
2107 GCPRO1 (completion
);
2109 Ftry_completion (concat2 (minibuffer_completion_contents (),
2110 build_string ("-")),
2111 Vminibuffer_completion_table
,
2112 Vminibuffer_completion_predicate
);
2120 /* Now find first word-break in the stuff found by completion.
2121 i gets index in string of where to stop completing. */
2124 int bytes
= SBYTES (completion
);
2125 completion_string
= SDATA (completion
);
2126 for (; i_byte
< SBYTES (completion
); i_byte
+= len
, i
++)
2128 c
= STRING_CHAR_AND_LENGTH (completion_string
+ i_byte
,
2131 if (SYNTAX (c
) != Sword
)
2140 /* If got no characters, print help for user. */
2142 if (i
== PT
- prompt_end_charpos
)
2144 if (!NILP (Vcompletion_auto_help
))
2145 Fminibuffer_completion_help ();
2149 /* Otherwise insert in minibuffer the chars we got */
2151 if (! NILP (Vminibuffer_completing_file_name
)
2152 && SREF (completion
, SBYTES (completion
) - 1) == '/'
2154 && FETCH_CHAR (PT_BYTE
) == '/')
2156 del_range (prompt_end_charpos
, PT
+ 1);
2159 del_range (prompt_end_charpos
, PT
);
2161 insert_from_string (completion
, 0, 0, i
, i_byte
, 1);
2165 DEFUN ("display-completion-list", Fdisplay_completion_list
, Sdisplay_completion_list
,
2167 doc
: /* Display the list of completions, COMPLETIONS, using `standard-output'.
2168 Each element may be just a symbol or string
2169 or may be a list of two strings to be printed as if concatenated.
2170 `standard-output' must be a buffer.
2171 The actual completion alternatives, as inserted, are given `mouse-face'
2172 properties of `highlight'.
2173 At the end, this runs the normal hook `completion-setup-hook'.
2174 It can find the completion buffer in `standard-output'. */)
2176 Lisp_Object completions
;
2178 Lisp_Object tail
, elt
;
2181 struct gcpro gcpro1
, gcpro2
;
2182 struct buffer
*old
= current_buffer
;
2185 /* Note that (when it matters) every variable
2186 points to a non-string that is pointed to by COMPLETIONS,
2187 except for ELT. ELT can be pointing to a string
2188 when terpri or Findent_to calls a change hook. */
2190 GCPRO2 (completions
, elt
);
2192 if (BUFFERP (Vstandard_output
))
2193 set_buffer_internal (XBUFFER (Vstandard_output
));
2195 if (NILP (completions
))
2196 write_string ("There are no possible completions of what you have typed.",
2200 write_string ("Possible completions are:", -1);
2201 for (tail
= completions
, i
= 0; !NILP (tail
); tail
= Fcdr (tail
), i
++)
2203 Lisp_Object tem
, string
;
2205 Lisp_Object startpos
, endpos
;
2210 /* Compute the length of this element. */
2215 length
= SCHARS (tem
);
2217 tem
= Fcar (XCDR (elt
));
2219 length
+= SCHARS (tem
);
2224 length
= SCHARS (elt
);
2227 /* This does a bad job for narrower than usual windows.
2228 Sadly, the window it will appear in is not known
2229 until after the text has been made. */
2231 if (BUFFERP (Vstandard_output
))
2232 XSETINT (startpos
, BUF_PT (XBUFFER (Vstandard_output
)));
2234 /* If the previous completion was very wide,
2235 or we have two on this line already,
2236 don't put another on the same line. */
2237 if (column
> 33 || first
2238 /* If this is really wide, don't put it second on a line. */
2239 || (column
> 0 && length
> 45))
2244 /* Otherwise advance to column 35. */
2247 if (BUFFERP (Vstandard_output
))
2249 tem
= Findent_to (make_number (35), make_number (2));
2251 column
= XINT (tem
);
2257 write_string (" ", -1);
2260 while (column
< 35);
2264 if (BUFFERP (Vstandard_output
))
2266 XSETINT (endpos
, BUF_PT (XBUFFER (Vstandard_output
)));
2267 Fset_text_properties (startpos
, endpos
,
2268 Qnil
, Vstandard_output
);
2271 /* Output this element.
2272 If necessary, convert it to unibyte or to multibyte first. */
2274 string
= Fcar (elt
);
2277 if (NILP (current_buffer
->enable_multibyte_characters
)
2278 && STRING_MULTIBYTE (string
))
2279 string
= Fstring_make_unibyte (string
);
2280 else if (!NILP (current_buffer
->enable_multibyte_characters
)
2281 && !STRING_MULTIBYTE (string
))
2282 string
= Fstring_make_multibyte (string
);
2284 if (BUFFERP (Vstandard_output
))
2286 XSETINT (startpos
, BUF_PT (XBUFFER (Vstandard_output
)));
2288 Fprinc (string
, Qnil
);
2290 XSETINT (endpos
, BUF_PT (XBUFFER (Vstandard_output
)));
2292 Fput_text_property (startpos
, endpos
,
2293 Qmouse_face
, intern ("highlight"),
2298 Fprinc (string
, Qnil
);
2301 /* Output the annotation for this element. */
2304 if (BUFFERP (Vstandard_output
))
2306 XSETINT (startpos
, BUF_PT (XBUFFER (Vstandard_output
)));
2308 Fprinc (Fcar (Fcdr (elt
)), Qnil
);
2310 XSETINT (endpos
, BUF_PT (XBUFFER (Vstandard_output
)));
2312 Fset_text_properties (startpos
, endpos
, Qnil
,
2317 Fprinc (Fcar (Fcdr (elt
)), Qnil
);
2322 /* Update COLUMN for what we have output. */
2325 /* If output is to a buffer, recompute COLUMN in a way
2326 that takes account of character widths. */
2327 if (BUFFERP (Vstandard_output
))
2329 tem
= Fcurrent_column ();
2330 column
= XINT (tem
);
2339 if (BUFFERP (Vstandard_output
))
2340 set_buffer_internal (old
);
2342 if (!NILP (Vrun_hooks
))
2343 call1 (Vrun_hooks
, intern ("completion-setup-hook"));
2348 DEFUN ("minibuffer-completion-help", Fminibuffer_completion_help
, Sminibuffer_completion_help
,
2350 doc
: /* Display a list of possible completions of the current minibuffer contents. */)
2353 Lisp_Object completions
;
2355 message ("Making completion list...");
2356 completions
= Fall_completions (minibuffer_completion_contents (),
2357 Vminibuffer_completion_table
,
2358 Vminibuffer_completion_predicate
,
2360 clear_message (1, 0);
2362 if (NILP (completions
))
2365 temp_echo_area_glyphs (build_string (" [No completions]"));
2368 internal_with_output_to_temp_buffer ("*Completions*",
2369 Fdisplay_completion_list
,
2370 Fsort (completions
, Qstring_lessp
));
2374 DEFUN ("self-insert-and-exit", Fself_insert_and_exit
, Sself_insert_and_exit
, 0, 0, "",
2375 doc
: /* Terminate minibuffer input. */)
2378 if (INTEGERP (last_command_char
))
2379 internal_self_insert (XINT (last_command_char
), 0);
2383 return Fthrow (Qexit
, Qnil
);
2386 DEFUN ("exit-minibuffer", Fexit_minibuffer
, Sexit_minibuffer
, 0, 0, "",
2387 doc
: /* Terminate this minibuffer argument. */)
2390 return Fthrow (Qexit
, Qnil
);
2393 DEFUN ("minibuffer-depth", Fminibuffer_depth
, Sminibuffer_depth
, 0, 0, 0,
2394 doc
: /* Return current depth of activations of minibuffer, a nonnegative integer. */)
2397 return make_number (minibuf_level
);
2400 DEFUN ("minibuffer-prompt", Fminibuffer_prompt
, Sminibuffer_prompt
, 0, 0, 0,
2401 doc
: /* Return the prompt string of the currently-active minibuffer.
2402 If no minibuffer is active, return nil. */)
2405 return Fcopy_sequence (minibuf_prompt
);
2409 /* Temporarily display STRING at the end of the current
2410 minibuffer contents. This is used to display things like
2411 "[No Match]" when the user requests a completion for a prefix
2412 that has no possible completions, and other quick, unobtrusive
2416 temp_echo_area_glyphs (string
)
2420 int osize_byte
= ZV_BYTE
;
2422 int opoint_byte
= PT_BYTE
;
2423 Lisp_Object oinhibit
;
2424 oinhibit
= Vinhibit_quit
;
2426 /* Clear out any old echo-area message to make way for our new thing. */
2429 SET_PT_BOTH (osize
, osize_byte
);
2430 insert_from_string (string
, 0, 0, SCHARS (string
), SBYTES (string
), 0);
2431 SET_PT_BOTH (opoint
, opoint_byte
);
2433 Fsit_for (make_number (2), Qnil
, Qnil
);
2434 del_range_both (osize
, osize_byte
, ZV
, ZV_BYTE
, 1);
2435 SET_PT_BOTH (opoint
, opoint_byte
);
2436 if (!NILP (Vquit_flag
))
2439 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
2441 Vinhibit_quit
= oinhibit
;
2444 DEFUN ("minibuffer-message", Fminibuffer_message
, Sminibuffer_message
,
2446 doc
: /* Temporarily display STRING at the end of the minibuffer.
2447 The text is displayed for two seconds,
2448 or until the next input event arrives, whichever comes first. */)
2452 CHECK_STRING (string
);
2453 temp_echo_area_glyphs (string
);
2458 init_minibuf_once ()
2460 Vminibuffer_list
= Qnil
;
2461 staticpro (&Vminibuffer_list
);
2468 minibuf_prompt
= Qnil
;
2469 staticpro (&minibuf_prompt
);
2471 minibuf_save_list
= Qnil
;
2472 staticpro (&minibuf_save_list
);
2474 Qread_file_name_internal
= intern ("read-file-name-internal");
2475 staticpro (&Qread_file_name_internal
);
2477 Qminibuffer_default
= intern ("minibuffer-default");
2478 staticpro (&Qminibuffer_default
);
2479 Fset (Qminibuffer_default
, Qnil
);
2481 Qminibuffer_completion_table
= intern ("minibuffer-completion-table");
2482 staticpro (&Qminibuffer_completion_table
);
2484 Qminibuffer_completion_confirm
= intern ("minibuffer-completion-confirm");
2485 staticpro (&Qminibuffer_completion_confirm
);
2487 Qminibuffer_completion_predicate
= intern ("minibuffer-completion-predicate");
2488 staticpro (&Qminibuffer_completion_predicate
);
2490 staticpro (&last_exact_completion
);
2491 last_exact_completion
= Qnil
;
2493 staticpro (&last_minibuf_string
);
2494 last_minibuf_string
= Qnil
;
2496 Quser_variable_p
= intern ("user-variable-p");
2497 staticpro (&Quser_variable_p
);
2499 Qminibuffer_history
= intern ("minibuffer-history");
2500 staticpro (&Qminibuffer_history
);
2502 Qbuffer_name_history
= intern ("buffer-name-history");
2503 staticpro (&Qbuffer_name_history
);
2504 Fset (Qbuffer_name_history
, Qnil
);
2506 Qminibuffer_setup_hook
= intern ("minibuffer-setup-hook");
2507 staticpro (&Qminibuffer_setup_hook
);
2509 Qminibuffer_exit_hook
= intern ("minibuffer-exit-hook");
2510 staticpro (&Qminibuffer_exit_hook
);
2512 Qhistory_length
= intern ("history-length");
2513 staticpro (&Qhistory_length
);
2515 Qcurrent_input_method
= intern ("current-input-method");
2516 staticpro (&Qcurrent_input_method
);
2518 Qactivate_input_method
= intern ("activate-input-method");
2519 staticpro (&Qactivate_input_method
);
2521 DEFVAR_LISP ("read-buffer-function", &Vread_buffer_function
,
2522 doc
: /* If this is non-nil, `read-buffer' does its work by calling this function. */);
2523 Vread_buffer_function
= Qnil
;
2525 DEFVAR_LISP ("minibuffer-setup-hook", &Vminibuffer_setup_hook
,
2526 doc
: /* Normal hook run just after entry to minibuffer. */);
2527 Vminibuffer_setup_hook
= Qnil
;
2529 DEFVAR_LISP ("minibuffer-exit-hook", &Vminibuffer_exit_hook
,
2530 doc
: /* Normal hook run just after exit from minibuffer. */);
2531 Vminibuffer_exit_hook
= Qnil
;
2533 DEFVAR_LISP ("history-length", &Vhistory_length
,
2534 doc
: /* *Maximum length for history lists before truncation takes place.
2535 A number means that length; t means infinite. Truncation takes place
2536 just after a new element is inserted. Setting the history-length
2537 property of a history variable overrides this default. */);
2538 XSETFASTINT (Vhistory_length
, 30);
2540 DEFVAR_LISP ("completion-auto-help", &Vcompletion_auto_help
,
2541 doc
: /* *Non-nil means automatically provide help for invalid completion input. */);
2542 Vcompletion_auto_help
= Qt
;
2544 DEFVAR_BOOL ("completion-ignore-case", &completion_ignore_case
,
2545 doc
: /* Non-nil means don't consider case significant in completion. */);
2546 completion_ignore_case
= 0;
2548 DEFVAR_BOOL ("enable-recursive-minibuffers", &enable_recursive_minibuffers
,
2549 doc
: /* *Non-nil means to allow minibuffer commands while in the minibuffer.
2550 This variable makes a difference whenever the minibuffer window is active. */);
2551 enable_recursive_minibuffers
= 0;
2553 DEFVAR_LISP ("minibuffer-completion-table", &Vminibuffer_completion_table
,
2554 doc
: /* Alist or obarray used for completion in the minibuffer.
2555 This becomes the ALIST argument to `try-completion' and `all-completion'.
2557 The value may alternatively be a function, which is given three arguments:
2558 STRING, the current buffer contents;
2559 PREDICATE, the predicate for filtering possible matches;
2560 CODE, which says what kind of things to do.
2561 CODE can be nil, t or `lambda'.
2562 nil means to return the best completion of STRING, or nil if there is none.
2563 t means to return a list of all possible completions of STRING.
2564 `lambda' means to return t if STRING is a valid completion as it stands. */);
2565 Vminibuffer_completion_table
= Qnil
;
2567 DEFVAR_LISP ("minibuffer-completion-predicate", &Vminibuffer_completion_predicate
,
2568 doc
: /* Within call to `completing-read', this holds the PREDICATE argument. */);
2569 Vminibuffer_completion_predicate
= Qnil
;
2571 DEFVAR_LISP ("minibuffer-completion-confirm", &Vminibuffer_completion_confirm
,
2572 doc
: /* Non-nil means to demand confirmation of completion before exiting minibuffer. */);
2573 Vminibuffer_completion_confirm
= Qnil
;
2575 DEFVAR_LISP ("minibuffer-completing-file-name",
2576 &Vminibuffer_completing_file_name
,
2577 doc
: /* Non-nil means completing file names. */);
2578 Vminibuffer_completing_file_name
= Qnil
;
2580 DEFVAR_LISP ("minibuffer-help-form", &Vminibuffer_help_form
,
2581 doc
: /* Value that `help-form' takes on inside the minibuffer. */);
2582 Vminibuffer_help_form
= Qnil
;
2584 DEFVAR_LISP ("minibuffer-history-variable", &Vminibuffer_history_variable
,
2585 doc
: /* History list symbol to add minibuffer values to.
2586 Each string of minibuffer input, as it appears on exit from the minibuffer,
2588 (set minibuffer-history-variable
2589 (cons STRING (symbol-value minibuffer-history-variable))) */);
2590 XSETFASTINT (Vminibuffer_history_variable
, 0);
2592 DEFVAR_LISP ("minibuffer-history-position", &Vminibuffer_history_position
,
2593 doc
: /* Current position of redoing in the history list. */);
2594 Vminibuffer_history_position
= Qnil
;
2596 DEFVAR_BOOL ("minibuffer-auto-raise", &minibuffer_auto_raise
,
2597 doc
: /* *Non-nil means entering the minibuffer raises the minibuffer's frame.
2598 Some uses of the echo area also raise that frame (since they use it too). */);
2599 minibuffer_auto_raise
= 0;
2601 DEFVAR_LISP ("completion-regexp-list", &Vcompletion_regexp_list
,
2602 doc
: /* List of regexps that should restrict possible completions. */);
2603 Vcompletion_regexp_list
= Qnil
;
2605 DEFVAR_BOOL ("minibuffer-allow-text-properties",
2606 &minibuffer_allow_text_properties
,
2607 doc
: /* Non-nil means `read-from-minibuffer' should not discard text properties.
2608 This also affects `read-string', but it does not affect `read-minibuffer',
2609 `read-no-blanks-input', or any of the functions that do minibuffer input
2610 with completion; they always discard text properties. */);
2611 minibuffer_allow_text_properties
= 0;
2613 DEFVAR_LISP ("minibuffer-prompt-properties", &Vminibuffer_prompt_properties
,
2614 doc
: /* Text properties that are added to minibuffer prompts.
2615 These are in addition to the basic `field' property, and stickiness
2617 /* We use `intern' here instead of Qread_only to avoid
2618 initialization-order problems. */
2619 Vminibuffer_prompt_properties
2620 = Fcons (intern ("read-only"), Fcons (Qt
, Qnil
));
2622 defsubr (&Sset_minibuffer_window
);
2623 defsubr (&Sread_from_minibuffer
);
2624 defsubr (&Seval_minibuffer
);
2625 defsubr (&Sread_minibuffer
);
2626 defsubr (&Sread_string
);
2627 defsubr (&Sread_command
);
2628 defsubr (&Sread_variable
);
2629 defsubr (&Sread_buffer
);
2630 defsubr (&Sread_no_blanks_input
);
2631 defsubr (&Sminibuffer_depth
);
2632 defsubr (&Sminibuffer_prompt
);
2634 defsubr (&Sminibufferp
);
2635 defsubr (&Sminibuffer_prompt_end
);
2636 defsubr (&Sminibuffer_contents
);
2637 defsubr (&Sminibuffer_contents_no_properties
);
2638 defsubr (&Sdelete_minibuffer_contents
);
2640 defsubr (&Stry_completion
);
2641 defsubr (&Sall_completions
);
2642 defsubr (&Stest_completion
);
2643 defsubr (&Sassoc_string
);
2644 defsubr (&Scompleting_read
);
2645 defsubr (&Sminibuffer_complete
);
2646 defsubr (&Sminibuffer_complete_word
);
2647 defsubr (&Sminibuffer_complete_and_exit
);
2648 defsubr (&Sdisplay_completion_list
);
2649 defsubr (&Sminibuffer_completion_help
);
2651 defsubr (&Sself_insert_and_exit
);
2652 defsubr (&Sexit_minibuffer
);
2654 defsubr (&Sminibuffer_message
);
2660 initial_define_key (Vminibuffer_local_map
, Ctl ('g'),
2661 "abort-recursive-edit");
2662 initial_define_key (Vminibuffer_local_map
, Ctl ('m'),
2664 initial_define_key (Vminibuffer_local_map
, Ctl ('j'),
2667 initial_define_key (Vminibuffer_local_ns_map
, ' ',
2669 initial_define_key (Vminibuffer_local_ns_map
, '\t',
2671 initial_define_key (Vminibuffer_local_ns_map
, '?',
2672 "self-insert-and-exit");
2674 initial_define_key (Vminibuffer_local_completion_map
, '\t',
2675 "minibuffer-complete");
2676 initial_define_key (Vminibuffer_local_completion_map
, ' ',
2677 "minibuffer-complete-word");
2678 initial_define_key (Vminibuffer_local_completion_map
, '?',
2679 "minibuffer-completion-help");
2681 initial_define_key (Vminibuffer_local_must_match_map
, Ctl ('m'),
2682 "minibuffer-complete-and-exit");
2683 initial_define_key (Vminibuffer_local_must_match_map
, Ctl ('j'),
2684 "minibuffer-complete-and-exit");