1 /* Minibuffer input and completion.
2 Copyright (C) 1985, 1986, 1993, 1994, 1995, 1996, 1997, 1998
3 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. */
28 #include "dispextern.h"
34 #define min(a, b) ((a) < (b) ? (a) : (b))
38 /* List of buffers for use as minibuffers.
39 The first element of the list is used for the outermost minibuffer
40 invocation, the next element is used for a recursive minibuffer
41 invocation, etc. The list is extended at the end as deeper
42 minibuffer recursions are encountered. */
44 Lisp_Object Vminibuffer_list
;
46 /* Data to remember during recursive minibuffer invocations */
48 Lisp_Object minibuf_save_list
;
50 /* Depth in minibuffer invocations. */
54 /* Nonzero means display completion help for invalid input. */
58 /* The maximum length of a minibuffer history. */
60 Lisp_Object Qhistory_length
, Vhistory_length
;
62 /* Fread_minibuffer leaves the input here as a string. */
64 Lisp_Object last_minibuf_string
;
66 /* Nonzero means let functions called when within a minibuffer
67 invoke recursive minibuffers (to read arguments, or whatever) */
69 int enable_recursive_minibuffers
;
71 /* Nonzero means don't ignore text properties
72 in Fread_from_minibuffer. */
74 int minibuffer_allow_text_properties
;
76 /* help-form is bound to this while in the minibuffer. */
78 Lisp_Object Vminibuffer_help_form
;
80 /* Variable which is the history list to add minibuffer values to. */
82 Lisp_Object Vminibuffer_history_variable
;
84 /* Current position in the history list (adjusted by M-n and M-p). */
86 Lisp_Object Vminibuffer_history_position
;
88 Lisp_Object Qminibuffer_history
, Qbuffer_name_history
;
90 Lisp_Object Qread_file_name_internal
;
92 /* Normal hooks for entry to and exit from minibuffer. */
94 Lisp_Object Qminibuffer_setup_hook
, Vminibuffer_setup_hook
;
95 Lisp_Object Qminibuffer_exit_hook
, Vminibuffer_exit_hook
;
97 /* Function to call to read a buffer name. */
98 Lisp_Object Vread_buffer_function
;
100 /* Nonzero means completion ignores case. */
102 int completion_ignore_case
;
104 /* List of regexps that should restrict possible completions. */
106 Lisp_Object Vcompletion_regexp_list
;
108 /* Nonzero means raise the minibuffer frame when the minibuffer
111 int minibuffer_auto_raise
;
113 /* If last completion attempt reported "Complete but not unique"
114 then this is the string completed then; otherwise this is nil. */
116 static Lisp_Object last_exact_completion
;
118 /* Non-nil means it is the window for C-M-v to scroll
119 when the minibuffer is selected. */
121 extern Lisp_Object Vminibuf_scroll_window
;
123 extern Lisp_Object Voverriding_local_map
;
125 Lisp_Object Quser_variable_p
;
127 Lisp_Object Qminibuffer_default
;
129 Lisp_Object Qcurrent_input_method
, Qactivate_input_method
;
131 extern Lisp_Object Qmouse_face
;
134 /* Put minibuf on currently selected frame's minibuffer.
135 We do this whenever the user starts a new minibuffer
136 or when a minibuffer exits. */
139 choose_minibuf_frame ()
141 if (FRAMEP (selected_frame
)
142 && FRAME_LIVE_P (XFRAME (selected_frame
))
143 && !EQ (minibuf_window
, XFRAME (selected_frame
)->minibuffer_window
))
145 struct frame
*sf
= XFRAME (selected_frame
);
148 /* I don't think that any frames may validly have a null minibuffer
150 if (NILP (sf
->minibuffer_window
))
153 /* Under X, we come here with minibuf_window being the
154 minibuffer window of the unused termcap window created in
155 init_window_once. That window doesn't have a buffer. */
156 buffer
= XWINDOW (minibuf_window
)->buffer
;
157 if (BUFFERP (buffer
))
158 Fset_window_buffer (sf
->minibuffer_window
, buffer
);
159 minibuf_window
= sf
->minibuffer_window
;
162 /* Make sure no other frame has a minibuffer as its selected window,
163 because the text would not be displayed in it, and that would be
164 confusing. Only allow the selected frame to do this,
165 and that only if the minibuffer is active. */
167 Lisp_Object tail
, frame
;
169 FOR_EACH_FRAME (tail
, frame
)
170 if (MINI_WINDOW_P (XWINDOW (FRAME_SELECTED_WINDOW (XFRAME (frame
))))
171 && !(EQ (frame
, selected_frame
)
172 && minibuf_level
> 0))
173 Fset_frame_selected_window (frame
, Fframe_first_window (frame
));
178 choose_minibuf_frame_1 (ignore
)
181 choose_minibuf_frame ();
185 DEFUN ("set-minibuffer-window", Fset_minibuffer_window
,
186 Sset_minibuffer_window
, 1, 1, 0,
187 "Specify which minibuffer window to use for the minibuffer.\n\
188 This effects where the minibuffer is displayed if you put text in it\n\
189 without invoking the usual minibuffer commands.")
193 CHECK_WINDOW (window
, 1);
194 if (! MINI_WINDOW_P (XWINDOW (window
)))
195 error ("Window is not a minibuffer window");
197 minibuf_window
= window
;
205 /* Actual minibuffer invocation. */
207 static Lisp_Object read_minibuf_unwind
P_ ((Lisp_Object
));
208 static Lisp_Object read_minibuf
P_ ((Lisp_Object
, Lisp_Object
,
209 Lisp_Object
, Lisp_Object
,
211 Lisp_Object
, Lisp_Object
,
214 /* Read from the minibuffer using keymap MAP, initial contents INITIAL
215 (a string), putting point minus BACKUP_N bytes from the end of INITIAL,
216 prompting with PROMPT (a string), using history list HISTVAR
217 with initial position HISTPOS. (BACKUP_N should be <= 0.)
219 Normally return the result as a string (the text that was read),
220 but if EXPFLAG is nonzero, read it and return the object read.
221 If HISTVAR is given, save the value read on that history only if it doesn't
222 match the front of that history list exactly. The value is pushed onto
223 the list as the string that was read.
225 DEFALT specifies te default value for the sake of history commands.
227 If ALLOW_PROPS is nonzero, we do not throw away text properties.
229 if INHERIT_INPUT_METHOD is nonzeor, the minibuffer inherit the
230 current input method. */
233 read_minibuf (map
, initial
, prompt
, backup_n
, expflag
,
234 histvar
, histpos
, defalt
, allow_props
, inherit_input_method
)
238 Lisp_Object backup_n
;
244 int inherit_input_method
;
247 int count
= specpdl_ptr
- specpdl
;
248 Lisp_Object mini_frame
, ambient_dir
, minibuffer
, input_method
;
249 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
250 Lisp_Object enable_multibyte
;
251 extern Lisp_Object Qread_only
, Qfront_sticky
;
252 extern Lisp_Object Qrear_nonsticky
;
254 specbind (Qminibuffer_default
, defalt
);
256 single_kboard_state ();
259 ambient_dir
= current_buffer
->directory
;
261 enable_multibyte
= Qnil
;
263 /* Don't need to protect PROMPT, HISTVAR, and HISTPOS because we
264 store them away before we can GC. Don't need to protect
265 BACKUP_N because we use the value only if it is an integer. */
266 GCPRO5 (map
, initial
, val
, ambient_dir
, input_method
);
268 if (!STRINGP (prompt
))
269 prompt
= build_string ("");
271 if (!enable_recursive_minibuffers
272 && minibuf_level
> 0)
274 if (EQ (selected_window
, minibuf_window
))
275 error ("Command attempted to use minibuffer while in minibuffer");
277 /* If we're in another window, cancel the minibuffer that's active. */
279 build_string ("Command attempted to use minibuffer while in minibuffer"));
282 /* Choose the minibuffer window and frame, and take action on them. */
284 choose_minibuf_frame ();
286 record_unwind_protect (choose_minibuf_frame_1
, Qnil
);
288 record_unwind_protect (Fset_window_configuration
,
289 Fcurrent_window_configuration (Qnil
));
291 /* If the minibuffer window is on a different frame, save that
292 frame's configuration too. */
293 mini_frame
= WINDOW_FRAME (XWINDOW (minibuf_window
));
294 if (!EQ (mini_frame
, selected_frame
))
295 record_unwind_protect (Fset_window_configuration
,
296 Fcurrent_window_configuration (mini_frame
));
298 /* If the minibuffer is on an iconified or invisible frame,
299 make it visible now. */
300 Fmake_frame_visible (mini_frame
);
302 if (minibuffer_auto_raise
)
303 Fraise_frame (mini_frame
);
305 /* We have to do this after saving the window configuration
306 since that is what restores the current buffer. */
308 /* Arrange to restore a number of minibuffer-related variables.
309 We could bind each variable separately, but that would use lots of
312 = Fcons (Voverriding_local_map
,
313 Fcons (minibuf_window
, minibuf_save_list
));
315 = Fcons (minibuf_prompt
,
316 Fcons (make_number (minibuf_prompt_width
),
318 Fcons (Vcurrent_prefix_arg
,
319 Fcons (Vminibuffer_history_position
,
320 Fcons (Vminibuffer_history_variable
,
321 minibuf_save_list
))))));
323 = Fcons (current_buffer
->prompt_end_charpos
,
326 record_unwind_protect (read_minibuf_unwind
, Qnil
);
329 /* Now that we can restore all those variables, start changing them. */
331 minibuf_prompt_width
= 0;
332 minibuf_prompt
= Fcopy_sequence (prompt
);
333 Vminibuffer_history_position
= histpos
;
334 Vminibuffer_history_variable
= histvar
;
335 Vhelp_form
= Vminibuffer_help_form
;
337 if (inherit_input_method
)
339 /* `current-input-method' is buffer local. So, remeber it in
340 INPUT_METHOD before changing the current buffer. */
341 input_method
= Fsymbol_value (Qcurrent_input_method
);
342 enable_multibyte
= current_buffer
->enable_multibyte_characters
;
345 /* Switch to the minibuffer. */
347 minibuffer
= get_minibuffer (minibuf_level
);
348 Fset_buffer (minibuffer
);
350 /* The current buffer's default directory is usually the right thing
351 for our minibuffer here. However, if you're typing a command at
352 a minibuffer-only frame when minibuf_level is zero, then buf IS
353 the current_buffer, so reset_buffer leaves buf's default
354 directory unchanged. This is a bummer when you've just started
355 up Emacs and buf's default directory is Qnil. Here's a hack; can
356 you think of something better to do? Find another buffer with a
357 better directory, and use that one instead. */
358 if (STRINGP (ambient_dir
))
359 current_buffer
->directory
= ambient_dir
;
362 Lisp_Object buf_list
;
364 for (buf_list
= Vbuffer_alist
;
366 buf_list
= XCONS (buf_list
)->cdr
)
368 Lisp_Object other_buf
;
370 other_buf
= XCONS (XCONS (buf_list
)->car
)->cdr
;
371 if (STRINGP (XBUFFER (other_buf
)->directory
))
373 current_buffer
->directory
= XBUFFER (other_buf
)->directory
;
379 if (!EQ (mini_frame
, selected_frame
))
380 Fredirect_frame_focus (selected_frame
, mini_frame
);
382 Vminibuf_scroll_window
= selected_window
;
383 Fset_window_buffer (minibuf_window
, Fcurrent_buffer ());
384 Fselect_window (minibuf_window
);
385 XSETFASTINT (XWINDOW (minibuf_window
)->hscroll
, 0);
387 Fmake_local_variable (Qprint_escape_newlines
);
388 print_escape_newlines
= 1;
389 XSETFASTINT (current_buffer
->prompt_end_charpos
, 0);
391 /* Erase the buffer. */
393 int count1
= specpdl_ptr
- specpdl
;
394 specbind (Qinhibit_read_only
, Qt
);
396 unbind_to (count1
, Qnil
);
399 if (!NILP (current_buffer
->enable_multibyte_characters
)
400 && ! STRING_MULTIBYTE (minibuf_prompt
))
401 minibuf_prompt
= Fstring_make_multibyte (minibuf_prompt
);
403 /* Insert the prompt, record where it ends. */
404 Finsert (1, &minibuf_prompt
);
405 XSETFASTINT (current_buffer
->prompt_end_charpos
, PT
);
408 Fput_text_property (make_number (BEG
), make_number (PT
),
409 Qfront_sticky
, Qt
, Qnil
);
410 Fput_text_property (make_number (BEG
), make_number (PT
),
411 Qrear_nonsticky
, Qt
, Qnil
);
412 Fput_text_property (make_number (BEG
), make_number (PT
),
413 Qread_only
, Qt
, Qnil
);
416 minibuf_prompt_width
= current_column ();
418 /* If appropriate, copy enable-multibyte-characters into the minibuffer. */
419 if (inherit_input_method
)
420 current_buffer
->enable_multibyte_characters
= enable_multibyte
;
422 /* Put in the initial input. */
425 Finsert (1, &initial
);
426 if (INTEGERP (backup_n
))
427 Fforward_char (backup_n
);
430 clear_message (1, 1);
431 current_buffer
->keymap
= map
;
433 /* Turn on an input method stored in INPUT_METHOD if any. */
434 if (STRINGP (input_method
) && !NILP (Ffboundp (Qactivate_input_method
)))
435 call1 (Qactivate_input_method
, input_method
);
437 /* Run our hook, but not if it is empty.
438 (run-hooks would do nothing if it is empty,
439 but it's important to save time here in the usual case). */
440 if (!NILP (Vminibuffer_setup_hook
) && !EQ (Vminibuffer_setup_hook
, Qunbound
)
441 && !NILP (Vrun_hooks
))
442 call1 (Vrun_hooks
, Qminibuffer_setup_hook
);
446 /* If cursor is on the minibuffer line,
447 show the user we have exited by putting it in column 0. */
448 if (XWINDOW (minibuf_window
)->cursor
.vpos
>= 0
451 XWINDOW (minibuf_window
)->cursor
.hpos
= 0;
452 XWINDOW (minibuf_window
)->cursor
.x
= 0;
453 XWINDOW (minibuf_window
)->must_be_updated_p
= 1;
454 update_frame (XFRAME (selected_frame
), 1, 1);
455 if (rif
&& rif
->flush_display
)
456 rif
->flush_display (XFRAME (XWINDOW (minibuf_window
)->frame
));
459 /* Make minibuffer contents into a string. */
460 Fset_buffer (minibuffer
);
461 val
= make_buffer_string (current_buffer
->prompt_end_charpos
,
464 /* VAL is the string of minibuffer text. */
466 last_minibuf_string
= val
;
468 /* Add the value to the appropriate history list unless it is empty. */
469 if (XSTRING (val
)->size
!= 0
470 && SYMBOLP (Vminibuffer_history_variable
))
472 /* If the caller wanted to save the value read on a history list,
473 then do so if the value is not already the front of the list. */
476 /* If variable is unbound, make it nil. */
477 if (EQ (XSYMBOL (Vminibuffer_history_variable
)->value
, Qunbound
))
478 Fset (Vminibuffer_history_variable
, Qnil
);
480 histval
= Fsymbol_value (Vminibuffer_history_variable
);
482 /* The value of the history variable must be a cons or nil. Other
483 values are unacceptable. We silently ignore these values. */
486 && NILP (Fequal (last_minibuf_string
, Fcar (histval
)))))
490 histval
= Fcons (last_minibuf_string
, histval
);
491 Fset (Vminibuffer_history_variable
, histval
);
493 /* Truncate if requested. */
494 length
= Fget (Vminibuffer_history_variable
, Qhistory_length
);
495 if (NILP (length
)) length
= Vhistory_length
;
496 if (INTEGERP (length
))
498 if (XINT (length
) <= 0)
499 Fset (Vminibuffer_history_variable
, Qnil
);
504 temp
= Fnthcdr (Fsub1 (length
), histval
);
505 if (CONSP (temp
)) Fsetcdr (temp
, Qnil
);
511 /* If Lisp form desired instead of string, parse it. */
514 Lisp_Object expr_and_pos
;
517 if (STRINGP (val
) && XSTRING (val
)->size
== 0
521 expr_and_pos
= Fread_from_string (val
, Qnil
, Qnil
);
522 pos
= XINT (Fcdr (expr_and_pos
));
523 if (pos
!= XSTRING (val
)->size
)
525 /* Ignore trailing whitespace; any other trailing junk is an error. */
527 pos
= string_char_to_byte (val
, pos
);
528 for (i
= pos
; i
< STRING_BYTES (XSTRING (val
)); i
++)
530 int c
= XSTRING (val
)->data
[i
];
531 if (c
!= ' ' && c
!= '\t' && c
!= '\n')
532 error ("Trailing garbage following expression");
535 val
= Fcar (expr_and_pos
);
538 /* The appropriate frame will get selected
539 in set-window-configuration. */
540 RETURN_UNGCPRO (unbind_to (count
, val
));
543 /* Return a buffer to be used as the minibuffer at depth `depth'.
544 depth = 0 is the lowest allowed argument, and that is the value
545 used for nonrecursive minibuffer invocations */
548 get_minibuffer (depth
)
551 Lisp_Object tail
, num
, buf
;
553 extern Lisp_Object
nconc2 ();
555 XSETFASTINT (num
, depth
);
556 tail
= Fnthcdr (num
, Vminibuffer_list
);
559 tail
= Fcons (Qnil
, Qnil
);
560 Vminibuffer_list
= nconc2 (Vminibuffer_list
, tail
);
563 if (NILP (buf
) || NILP (XBUFFER (buf
)->name
))
565 sprintf (name
, " *Minibuf-%d*", depth
);
566 buf
= Fget_buffer_create (build_string (name
));
568 /* Although the buffer's name starts with a space, undo should be
570 Fbuffer_enable_undo (buf
);
572 XCONS (tail
)->car
= buf
;
576 int count
= specpdl_ptr
- specpdl
;
578 reset_buffer (XBUFFER (buf
));
579 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
581 Fkill_all_local_variables ();
582 unbind_to (count
, Qnil
);
588 /* This function is called on exiting minibuffer, whether normally or
589 not, and it restores the current window, buffer, etc. */
592 read_minibuf_unwind (data
)
595 Lisp_Object old_deactivate_mark
;
598 /* We are exiting the minibuffer one way or the other,
600 if (!NILP (Vminibuffer_exit_hook
) && !EQ (Vminibuffer_exit_hook
, Qunbound
)
601 && !NILP (Vrun_hooks
))
602 safe_run_hooks (Qminibuffer_exit_hook
);
604 /* If this was a recursive minibuffer,
605 tie the minibuffer window back to the outer level minibuffer buffer. */
608 window
= minibuf_window
;
609 /* To keep things predictable, in case it matters, let's be in the
610 minibuffer when we reset the relevant variables. */
611 Fset_buffer (XWINDOW (window
)->buffer
);
613 /* Restore prompt, etc, from outer minibuffer level. */
614 current_buffer
->prompt_end_charpos
= Fcar (minibuf_save_list
);
615 minibuf_save_list
= Fcdr (minibuf_save_list
);
617 minibuf_prompt
= Fcar (minibuf_save_list
);
618 minibuf_save_list
= Fcdr (minibuf_save_list
);
619 minibuf_prompt_width
= XFASTINT (Fcar (minibuf_save_list
));
620 minibuf_save_list
= Fcdr (minibuf_save_list
);
621 Vhelp_form
= Fcar (minibuf_save_list
);
622 minibuf_save_list
= Fcdr (minibuf_save_list
);
623 Vcurrent_prefix_arg
= Fcar (minibuf_save_list
);
624 minibuf_save_list
= Fcdr (minibuf_save_list
);
625 Vminibuffer_history_position
= Fcar (minibuf_save_list
);
626 minibuf_save_list
= Fcdr (minibuf_save_list
);
627 Vminibuffer_history_variable
= Fcar (minibuf_save_list
);
628 minibuf_save_list
= Fcdr (minibuf_save_list
);
629 Voverriding_local_map
= Fcar (minibuf_save_list
);
630 minibuf_save_list
= Fcdr (minibuf_save_list
);
632 temp
= Fcar (minibuf_save_list
);
633 if (FRAME_LIVE_P (XFRAME (WINDOW_FRAME (XWINDOW (temp
)))))
634 minibuf_window
= temp
;
636 minibuf_save_list
= Fcdr (minibuf_save_list
);
638 /* Erase the minibuffer we were using at this level. */
640 int count
= specpdl_ptr
- specpdl
;
641 /* Prevent error in erase-buffer. */
642 specbind (Qinhibit_read_only
, Qt
);
643 old_deactivate_mark
= Vdeactivate_mark
;
645 Vdeactivate_mark
= old_deactivate_mark
;
646 unbind_to (count
, Qnil
);
649 /* When we get to the outmost level, make sure we resize the
650 mini-window back to its normal size. */
651 if (minibuf_level
== 0)
652 resize_mini_window (XWINDOW (window
), 0);
654 /* Make sure minibuffer window is erased, not ignored. */
655 windows_or_buffers_changed
++;
656 XSETFASTINT (XWINDOW (window
)->last_modified
, 0);
657 XSETFASTINT (XWINDOW (window
)->last_overlay_modified
, 0);
662 /* This comment supplies the doc string for read-from-minibuffer,
663 for make-docfile to see. We cannot put this in the real DEFUN
664 due to limits in the Unix cpp.
666 DEFUN ("read-from-minibuffer", Fread_from_minibuffer, Sread_from_minibuffer, 1, 7, 0,
667 "Read a string from the minibuffer, prompting with string PROMPT.\n\
668 If optional second arg INITIAL-CONTENTS is non-nil, it is a string\n\
669 to be inserted into the minibuffer before reading input.\n\
670 If INITIAL-CONTENTS is (STRING . POSITION), the initial input\n\
671 is STRING, but point is placed at position POSITION in the minibuffer.\n\
672 Third arg KEYMAP is a keymap to use whilst reading;\n\
673 if omitted or nil, the default is `minibuffer-local-map'.\n\
674 If fourth arg READ is non-nil, then interpret the result as a lisp object\n\
675 and return that object:\n\
676 in other words, do `(car (read-from-string INPUT-STRING))'\n\
677 Fifth arg HIST, if non-nil, specifies a history list\n\
678 and optionally the initial position in the list.\n\
679 It can be a symbol, which is the history list variable to use,\n\
680 or it can be a cons cell (HISTVAR . HISTPOS).\n\
681 In that case, HISTVAR is the history list variable to use,\n\
682 and HISTPOS is the initial position (the position in the list\n\
683 which INITIAL-CONTENTS corresponds to).\n\
684 Positions are counted starting from 1 at the beginning of the list.\n\
685 Sixth arg DEFAULT-VALUE is the default value. If non-nil, it is available\n\
686 for history commands; but `read-from-minibuffer' does NOT return DEFAULT-VALUE\n\
687 if the user enters empty input! It returns the empty string.\n\
688 Seventh arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits\n\
689 the current input method and the setting of enable-multibyte-characters.\n\
690 If the variable `minibuffer-allow-text-properties' is non-nil,\n\
691 then the string which is returned includes whatever text properties\n\
692 were present in the minibuffer. Otherwise the value has no text properties.")
693 (prompt, initial_contents, keymap, read, hist, default_value, inherit_input_method)
696 DEFUN ("read-from-minibuffer", Fread_from_minibuffer
, Sread_from_minibuffer
, 1, 7, 0,
697 0 /* See immediately above */)
698 (prompt
, initial_contents
, keymap
, read
, hist
, default_value
, inherit_input_method
)
699 Lisp_Object prompt
, initial_contents
, keymap
, read
, hist
, default_value
;
700 Lisp_Object inherit_input_method
;
703 Lisp_Object histvar
, histpos
, position
, val
;
708 CHECK_STRING (prompt
, 0);
709 if (!NILP (initial_contents
))
711 if (CONSP (initial_contents
))
713 position
= Fcdr (initial_contents
);
714 initial_contents
= Fcar (initial_contents
);
716 CHECK_STRING (initial_contents
, 1);
717 if (!NILP (position
))
719 CHECK_NUMBER (position
, 0);
720 /* Convert to distance from end of input. */
721 if (XINT (position
) < 1)
722 /* A number too small means the beginning of the string. */
723 pos
= - XSTRING (initial_contents
)->size
;
725 pos
= XINT (position
) - 1 - XSTRING (initial_contents
)->size
;
730 keymap
= Vminibuffer_local_map
;
732 keymap
= get_keymap (keymap
);
741 histvar
= Fcar_safe (hist
);
742 histpos
= Fcdr_safe (hist
);
745 histvar
= Qminibuffer_history
;
747 XSETFASTINT (histpos
, 0);
749 GCPRO1 (default_value
);
750 val
= read_minibuf (keymap
, initial_contents
, prompt
,
751 make_number (pos
), !NILP (read
),
752 histvar
, histpos
, default_value
,
753 minibuffer_allow_text_properties
,
754 !NILP (inherit_input_method
));
759 DEFUN ("read-minibuffer", Fread_minibuffer
, Sread_minibuffer
, 1, 2, 0,
760 "Return a Lisp object read using the minibuffer.\n\
761 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS\n\
762 is a string to insert in the minibuffer before reading.")
763 (prompt
, initial_contents
)
764 Lisp_Object prompt
, initial_contents
;
766 CHECK_STRING (prompt
, 0);
767 if (!NILP (initial_contents
))
768 CHECK_STRING (initial_contents
, 1);
769 return read_minibuf (Vminibuffer_local_map
, initial_contents
,
770 prompt
, Qnil
, 1, Qminibuffer_history
,
771 make_number (0), Qnil
, 0, 0);
774 DEFUN ("eval-minibuffer", Feval_minibuffer
, Seval_minibuffer
, 1, 2, 0,
775 "Return value of Lisp expression read using the minibuffer.\n\
776 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS\n\
777 is a string to insert in the minibuffer before reading.")
778 (prompt
, initial_contents
)
779 Lisp_Object prompt
, initial_contents
;
781 return Feval (Fread_minibuffer (prompt
, initial_contents
));
784 /* Functions that use the minibuffer to read various things. */
786 DEFUN ("read-string", Fread_string
, Sread_string
, 1, 5, 0,
787 "Read a string from the minibuffer, prompting with string PROMPT.\n\
788 If non-nil, second arg INITIAL-INPUT is a string to insert before reading.\n\
789 The third arg HISTORY, if non-nil, specifies a history list\n\
790 and optionally the initial position in the list.\n\
791 See `read-from-minibuffer' for details of HISTORY argument.\n\
792 Fourth arg DEFAULT-VALUE is the default value. If non-nil, it is used\n\
793 for history commands, and as the value to return if the user enters\n\
795 Fifth arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits\n\
796 the current input method and the setting of enable-multibyte-characters.")
797 (prompt
, initial_input
, history
, default_value
, inherit_input_method
)
798 Lisp_Object prompt
, initial_input
, history
, default_value
;
799 Lisp_Object inherit_input_method
;
802 val
= Fread_from_minibuffer (prompt
, initial_input
, Qnil
,
803 Qnil
, history
, default_value
,
804 inherit_input_method
);
805 if (STRINGP (val
) && XSTRING (val
)->size
== 0 && ! NILP (default_value
))
810 DEFUN ("read-no-blanks-input", Fread_no_blanks_input
, Sread_no_blanks_input
, 1, 3, 0,
811 "Read a string from the terminal, not allowing blanks.\n\
812 Prompt with PROMPT, and provide INITIAL as an initial value of the input string.\n\
813 Third arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits\n\
814 the current input method and the setting of enable-multibyte-characters.")
815 (prompt
, initial
, inherit_input_method
)
816 Lisp_Object prompt
, initial
, inherit_input_method
;
818 CHECK_STRING (prompt
, 0);
819 if (! NILP (initial
))
820 CHECK_STRING (initial
, 1);
822 return read_minibuf (Vminibuffer_local_ns_map
, initial
, prompt
, Qnil
,
823 0, Qminibuffer_history
, make_number (0), Qnil
, 0,
824 !NILP (inherit_input_method
));
827 DEFUN ("read-command", Fread_command
, Sread_command
, 1, 2, 0,
828 "Read the name of a command and return as a symbol.\n\
829 Prompts with PROMPT. By default, return DEFAULT-VALUE.")
830 (prompt
, default_value
)
831 Lisp_Object prompt
, default_value
;
833 Lisp_Object name
, default_string
;
835 if (NILP (default_value
))
836 default_string
= Qnil
;
837 else if (SYMBOLP (default_value
))
838 XSETSTRING (default_string
, XSYMBOL (default_value
)->name
);
840 default_string
= default_value
;
842 name
= Fcompleting_read (prompt
, Vobarray
, Qcommandp
, Qt
,
843 Qnil
, Qnil
, default_string
, Qnil
);
846 return Fintern (name
, Qnil
);
850 DEFUN ("read-function", Fread_function
, Sread_function
, 1, 1, 0,
851 "One arg PROMPT, a string. Read the name of a function and return as a symbol.\n\
852 Prompts with PROMPT.")
856 return Fintern (Fcompleting_read (prompt
, Vobarray
, Qfboundp
, Qt
, Qnil
, Qnil
, Qnil
, Qnil
),
861 DEFUN ("read-variable", Fread_variable
, Sread_variable
, 1, 2, 0,
862 "Read the name of a user variable and return it as a symbol.\n\
863 Prompts with PROMPT. By default, return DEFAULT-VALUE.\n\
864 A user variable is one whose documentation starts with a `*' character.")
865 (prompt
, default_value
)
866 Lisp_Object prompt
, default_value
;
868 Lisp_Object name
, default_string
;
870 if (NILP (default_value
))
871 default_string
= Qnil
;
872 else if (SYMBOLP (default_value
))
873 XSETSTRING (default_string
, XSYMBOL (default_value
)->name
);
875 default_string
= default_value
;
877 name
= Fcompleting_read (prompt
, Vobarray
,
878 Quser_variable_p
, Qt
,
879 Qnil
, Qnil
, default_string
, Qnil
);
882 return Fintern (name
, Qnil
);
885 DEFUN ("read-buffer", Fread_buffer
, Sread_buffer
, 1, 3, 0,
886 "One arg PROMPT, a string. Read the name of a buffer and return as a string.\n\
887 Prompts with PROMPT.\n\
888 Optional second arg DEF is value to return if user enters an empty line.\n\
889 If optional third arg REQUIRE-MATCH is non-nil, only existing buffer names are allowed.")
890 (prompt
, def
, require_match
)
891 Lisp_Object prompt
, def
, require_match
;
896 def
= XBUFFER (def
)->name
;
898 if (NILP (Vread_buffer_function
))
902 args
[0] = build_string ("%s(default %s) ");
905 prompt
= Fformat (3, args
);
908 return Fcompleting_read (prompt
, Vbuffer_alist
, Qnil
,
909 require_match
, Qnil
, Qbuffer_name_history
,
914 args
[0] = Vread_buffer_function
;
917 args
[3] = require_match
;
918 return Ffuncall(4, args
);
923 minibuf_conform_representation (string
, basis
)
924 Lisp_Object string
, basis
;
926 if (STRING_MULTIBYTE (string
) == STRING_MULTIBYTE (basis
))
929 if (STRING_MULTIBYTE (string
))
930 return Fstring_make_unibyte (string
);
932 return Fstring_make_multibyte (string
);
935 DEFUN ("try-completion", Ftry_completion
, Stry_completion
, 2, 3, 0,
936 "Return common substring of all completions of STRING in ALIST.\n\
937 Each car of each element of ALIST is tested to see if it begins with STRING.\n\
938 All that match are compared together; the longest initial sequence\n\
939 common to all matches is returned as a string.\n\
940 If there is no match at all, nil is returned.\n\
941 For an exact match, t is returned.\n\
943 ALIST can be an obarray instead of an alist.\n\
944 Then the print names of all symbols in the obarray are the possible matches.\n\
946 ALIST can also be a function to do the completion itself.\n\
947 It receives three arguments: the values STRING, PREDICATE and nil.\n\
948 Whatever it returns becomes the value of `try-completion'.\n\
950 If optional third argument PREDICATE is non-nil,\n\
951 it is used to test each possible match.\n\
952 The match is a candidate only if PREDICATE returns non-nil.\n\
953 The argument given to PREDICATE is the alist element\n\
954 or the symbol from the obarray.")
955 (string
, alist
, predicate
)
956 Lisp_Object string
, alist
, predicate
;
958 Lisp_Object bestmatch
, tail
, elt
, eltstring
;
959 /* Size in bytes of BESTMATCH. */
961 /* These are in bytes, too. */
962 int compare
, matchsize
;
963 int list
= CONSP (alist
) || NILP (alist
);
966 Lisp_Object bucket
, zero
, end
, tem
;
967 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
969 CHECK_STRING (string
, 0);
970 if (!list
&& !VECTORP (alist
))
971 return call3 (alist
, string
, predicate
, Qnil
);
975 /* If ALIST is not a list, set TAIL just for gc pro. */
980 obsize
= XVECTOR (alist
)->size
;
981 bucket
= XVECTOR (alist
)->contents
[index
];
986 /* Get the next element of the alist or obarray. */
987 /* Exit the loop if the elements are all used up. */
988 /* elt gets the alist element or symbol.
989 eltstring gets the name to check as a completion. */
996 eltstring
= Fcar (elt
);
1001 if (XFASTINT (bucket
) != 0)
1004 eltstring
= Fsymbol_name (elt
);
1005 if (XSYMBOL (bucket
)->next
)
1006 XSETSYMBOL (bucket
, XSYMBOL (bucket
)->next
);
1008 XSETFASTINT (bucket
, 0);
1010 else if (++index
>= obsize
)
1014 bucket
= XVECTOR (alist
)->contents
[index
];
1019 /* Is this element a possible completion? */
1021 if (STRINGP (eltstring
)
1022 && XSTRING (string
)->size
<= XSTRING (eltstring
)->size
1023 && (tem
= Fcompare_strings (eltstring
, make_number (0),
1024 make_number (XSTRING (string
)->size
),
1025 string
, make_number (0), Qnil
,
1026 completion_ignore_case
?Qt
: Qnil
),
1030 Lisp_Object regexps
;
1032 XSETFASTINT (zero
, 0);
1034 /* Ignore this element if it fails to match all the regexps. */
1035 for (regexps
= Vcompletion_regexp_list
; CONSP (regexps
);
1036 regexps
= XCONS (regexps
)->cdr
)
1038 tem
= Fstring_match (XCONS (regexps
)->car
, eltstring
, zero
);
1042 if (CONSP (regexps
))
1045 /* Ignore this element if there is a predicate
1046 and the predicate doesn't like it. */
1048 if (!NILP (predicate
))
1050 if (EQ (predicate
, Qcommandp
))
1051 tem
= Fcommandp (elt
);
1054 GCPRO4 (tail
, string
, eltstring
, bestmatch
);
1055 tem
= call1 (predicate
, elt
);
1058 if (NILP (tem
)) continue;
1061 /* Update computation of how much all possible completions match */
1064 if (NILP (bestmatch
))
1066 bestmatch
= eltstring
;
1067 bestmatchsize
= XSTRING (eltstring
)->size
;
1071 compare
= min (bestmatchsize
, XSTRING (eltstring
)->size
);
1072 tem
= Fcompare_strings (bestmatch
, make_number (0),
1073 make_number (compare
),
1074 eltstring
, make_number (0),
1075 make_number (compare
),
1076 completion_ignore_case
? Qt
: Qnil
);
1078 matchsize
= compare
;
1079 else if (XINT (tem
) < 0)
1080 matchsize
= - XINT (tem
) - 1;
1082 matchsize
= XINT (tem
) - 1;
1085 matchsize
= compare
;
1086 if (completion_ignore_case
)
1088 /* If this is an exact match except for case,
1089 use it as the best match rather than one that is not an
1090 exact match. This way, we get the case pattern
1091 of the actual match. */
1092 if ((matchsize
== XSTRING (eltstring
)->size
1093 && matchsize
< XSTRING (bestmatch
)->size
)
1095 /* If there is more than one exact match ignoring case,
1096 and one of them is exact including case,
1098 /* If there is no exact match ignoring case,
1099 prefer a match that does not change the case
1101 ((matchsize
== XSTRING (eltstring
)->size
)
1103 (matchsize
== XSTRING (bestmatch
)->size
)
1104 && (tem
= Fcompare_strings (eltstring
, make_number (0),
1105 make_number (XSTRING (string
)->size
),
1106 string
, make_number (0),
1110 && (tem
= Fcompare_strings (bestmatch
, make_number (0),
1111 make_number (XSTRING (string
)->size
),
1112 string
, make_number (0),
1116 bestmatch
= eltstring
;
1118 bestmatchsize
= matchsize
;
1123 if (NILP (bestmatch
))
1124 return Qnil
; /* No completions found */
1125 /* If we are ignoring case, and there is no exact match,
1126 and no additional text was supplied,
1127 don't change the case of what the user typed. */
1128 if (completion_ignore_case
&& bestmatchsize
== XSTRING (string
)->size
1129 && XSTRING (bestmatch
)->size
> bestmatchsize
)
1130 return minibuf_conform_representation (string
, bestmatch
);
1132 /* Return t if the supplied string is an exact match (counting case);
1133 it does not require any change to be made. */
1134 if (matchcount
== 1 && bestmatchsize
== XSTRING (string
)->size
1135 && (tem
= Fcompare_strings (bestmatch
, make_number (0),
1136 make_number (bestmatchsize
),
1137 string
, make_number (0),
1138 make_number (bestmatchsize
),
1143 XSETFASTINT (zero
, 0); /* Else extract the part in which */
1144 XSETFASTINT (end
, bestmatchsize
); /* all completions agree */
1145 return Fsubstring (bestmatch
, zero
, end
);
1148 /* Compare exactly LEN chars of strings at S1 and S2,
1149 ignoring case if appropriate.
1150 Return -1 if strings match,
1151 else number of chars that match at the beginning. */
1155 register unsigned char *s1
, *s2
;
1158 register int l
= len
;
1160 if (completion_ignore_case
)
1162 while (l
&& DOWNCASE (*s1
++) == DOWNCASE (*s2
++))
1167 while (l
&& *s1
++ == *s2
++)
1174 int match
= len
- l
;
1176 /* Now *--S1 is the unmatching byte. If it is in the middle of
1177 multi-byte form, we must say that the multi-byte character
1178 there doesn't match. */
1179 while (match
&& *--s1
>= 0xA0) match
--;
1184 DEFUN ("all-completions", Fall_completions
, Sall_completions
, 2, 4, 0,
1185 "Search for partial matches to STRING in ALIST.\n\
1186 Each car of each element of ALIST is tested to see if it begins with STRING.\n\
1187 The value is a list of all the strings from ALIST that match.\n\
1189 ALIST can be an obarray instead of an alist.\n\
1190 Then the print names of all symbols in the obarray are the possible matches.\n\
1192 ALIST can also be a function to do the completion itself.\n\
1193 It receives three arguments: the values STRING, PREDICATE and t.\n\
1194 Whatever it returns becomes the value of `all-completion'.\n\
1196 If optional third argument PREDICATE is non-nil,\n\
1197 it is used to test each possible match.\n\
1198 The match is a candidate only if PREDICATE returns non-nil.\n\
1199 The argument given to PREDICATE is the alist element\n\
1200 or the symbol from the obarray.\n\
1202 If the optional fourth argument HIDE-SPACES is non-nil,\n\
1203 strings in ALIST that start with a space\n\
1204 are ignored unless STRING itself starts with a space.")
1205 (string
, alist
, predicate
, hide_spaces
)
1206 Lisp_Object string
, alist
, predicate
, hide_spaces
;
1208 Lisp_Object tail
, elt
, eltstring
;
1209 Lisp_Object allmatches
;
1210 int list
= CONSP (alist
) || NILP (alist
);
1212 Lisp_Object bucket
, tem
;
1213 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
1215 CHECK_STRING (string
, 0);
1216 if (!list
&& !VECTORP (alist
))
1218 return call3 (alist
, string
, predicate
, Qt
);
1222 /* If ALIST is not a list, set TAIL just for gc pro. */
1227 obsize
= XVECTOR (alist
)->size
;
1228 bucket
= XVECTOR (alist
)->contents
[index
];
1233 /* Get the next element of the alist or obarray. */
1234 /* Exit the loop if the elements are all used up. */
1235 /* elt gets the alist element or symbol.
1236 eltstring gets the name to check as a completion. */
1243 eltstring
= Fcar (elt
);
1248 if (XFASTINT (bucket
) != 0)
1251 eltstring
= Fsymbol_name (elt
);
1252 if (XSYMBOL (bucket
)->next
)
1253 XSETSYMBOL (bucket
, XSYMBOL (bucket
)->next
);
1255 XSETFASTINT (bucket
, 0);
1257 else if (++index
>= obsize
)
1261 bucket
= XVECTOR (alist
)->contents
[index
];
1266 /* Is this element a possible completion? */
1268 if (STRINGP (eltstring
)
1269 && XSTRING (string
)->size
<= XSTRING (eltstring
)->size
1270 /* If HIDE_SPACES, reject alternatives that start with space
1271 unless the input starts with space. */
1272 && ((STRING_BYTES (XSTRING (string
)) > 0
1273 && XSTRING (string
)->data
[0] == ' ')
1274 || XSTRING (eltstring
)->data
[0] != ' '
1275 || NILP (hide_spaces
))
1276 && (tem
= Fcompare_strings (eltstring
, make_number (0),
1277 make_number (XSTRING (string
)->size
),
1278 string
, make_number (0),
1279 make_number (XSTRING (string
)->size
),
1280 completion_ignore_case
? Qt
: Qnil
),
1284 Lisp_Object regexps
;
1286 XSETFASTINT (zero
, 0);
1288 /* Ignore this element if it fails to match all the regexps. */
1289 for (regexps
= Vcompletion_regexp_list
; CONSP (regexps
);
1290 regexps
= XCONS (regexps
)->cdr
)
1292 tem
= Fstring_match (XCONS (regexps
)->car
, eltstring
, zero
);
1296 if (CONSP (regexps
))
1299 /* Ignore this element if there is a predicate
1300 and the predicate doesn't like it. */
1302 if (!NILP (predicate
))
1304 if (EQ (predicate
, Qcommandp
))
1305 tem
= Fcommandp (elt
);
1308 GCPRO4 (tail
, eltstring
, allmatches
, string
);
1309 tem
= call1 (predicate
, elt
);
1312 if (NILP (tem
)) continue;
1314 /* Ok => put it on the list. */
1315 allmatches
= Fcons (eltstring
, allmatches
);
1319 return Fnreverse (allmatches
);
1322 Lisp_Object Vminibuffer_completion_table
, Qminibuffer_completion_table
;
1323 Lisp_Object Vminibuffer_completion_predicate
, Qminibuffer_completion_predicate
;
1324 Lisp_Object Vminibuffer_completion_confirm
, Qminibuffer_completion_confirm
;
1325 Lisp_Object Vminibuffer_completing_file_name
;
1327 /* This comment supplies the doc string for completing-read,
1328 for make-docfile to see. We cannot put this in the real DEFUN
1329 due to limits in the Unix cpp.
1331 DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 8, 0,
1332 "Read a string in the minibuffer, with completion.\n\
1333 PROMPT is a string to prompt with; normally it ends in a colon and a space.\n\
1334 TABLE is an alist whose elements' cars are strings, or an obarray.\n\
1335 PREDICATE limits completion to a subset of TABLE.\n\
1336 See `try-completion' and `all-completions' for more details\n\
1337 on completion, TABLE, and PREDICATE.\n\
1339 If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless\n\
1340 the input is (or completes to) an element of TABLE or is null.\n\
1341 If it is also not t, Return does not exit if it does non-null completion.\n\
1342 If the input is null, `completing-read' returns an empty string,\n\
1343 regardless of the value of REQUIRE-MATCH.\n\
1345 If INITIAL-INPUT is non-nil, insert it in the minibuffer initially.\n\
1346 If it is (STRING . POSITION), the initial input\n\
1347 is STRING, but point is placed POSITION characters into the string.\n\
1348 HIST, if non-nil, specifies a history list\n\
1349 and optionally the initial position in the list.\n\
1350 It can be a symbol, which is the history list variable to use,\n\
1351 or it can be a cons cell (HISTVAR . HISTPOS).\n\
1352 In that case, HISTVAR is the history list variable to use,\n\
1353 and HISTPOS is the initial position (the position in the list\n\
1354 which INITIAL-INPUT corresponds to).\n\
1355 Positions are counted starting from 1 at the beginning of the list.\n\
1356 DEF, if non-nil, is the default value.\n\
1358 If INHERIT-INPUT-METHOD is non-nil, the minibuffer inherits\n\
1359 the current input method and the setting of enable-multibyte-characters.\n\
1361 Completion ignores case if the ambient value of\n\
1362 `completion-ignore-case' is non-nil."
1364 DEFUN ("completing-read", Fcompleting_read
, Scompleting_read
, 2, 8, 0,
1365 0 /* See immediately above */)
1366 (prompt
, table
, predicate
, require_match
, init
, hist
, def
, inherit_input_method
)
1367 Lisp_Object prompt
, table
, predicate
, require_match
, init
, hist
, def
;
1368 Lisp_Object inherit_input_method
;
1370 Lisp_Object val
, histvar
, histpos
, position
;
1372 int count
= specpdl_ptr
- specpdl
;
1373 struct gcpro gcpro1
;
1377 specbind (Qminibuffer_completion_table
, table
);
1378 specbind (Qminibuffer_completion_predicate
, predicate
);
1379 specbind (Qminibuffer_completion_confirm
,
1380 EQ (require_match
, Qt
) ? Qnil
: Qt
);
1381 last_exact_completion
= Qnil
;
1388 position
= Fcdr (init
);
1391 CHECK_STRING (init
, 0);
1392 if (!NILP (position
))
1394 CHECK_NUMBER (position
, 0);
1395 /* Convert to distance from end of input. */
1396 pos
= XINT (position
) - XSTRING (init
)->size
;
1407 histvar
= Fcar_safe (hist
);
1408 histpos
= Fcdr_safe (hist
);
1411 histvar
= Qminibuffer_history
;
1413 XSETFASTINT (histpos
, 0);
1415 val
= read_minibuf (NILP (require_match
)
1416 ? Vminibuffer_local_completion_map
1417 : Vminibuffer_local_must_match_map
,
1418 init
, prompt
, make_number (pos
), 0,
1419 histvar
, histpos
, def
, 0,
1420 !NILP (inherit_input_method
));
1422 if (STRINGP (val
) && XSTRING (val
)->size
== 0 && ! NILP (def
))
1425 RETURN_UNGCPRO (unbind_to (count
, val
));
1428 Lisp_Object
Fminibuffer_completion_help ();
1429 Lisp_Object
assoc_for_completion ();
1431 /* Test whether TXT is an exact completion. */
1433 test_completion (txt
)
1438 if (CONSP (Vminibuffer_completion_table
)
1439 || NILP (Vminibuffer_completion_table
))
1440 return assoc_for_completion (txt
, Vminibuffer_completion_table
);
1441 else if (VECTORP (Vminibuffer_completion_table
))
1443 /* Bypass intern-soft as that loses for nil */
1444 tem
= oblookup (Vminibuffer_completion_table
,
1445 XSTRING (txt
)->data
,
1446 XSTRING (txt
)->size
,
1447 STRING_BYTES (XSTRING (txt
)));
1450 if (STRING_MULTIBYTE (txt
))
1451 txt
= Fstring_make_unibyte (txt
);
1453 txt
= Fstring_make_multibyte (txt
);
1455 tem
= oblookup (Vminibuffer_completion_table
,
1456 XSTRING (txt
)->data
,
1457 XSTRING (txt
)->size
,
1458 STRING_BYTES (XSTRING (txt
)));
1462 if (!NILP (Vminibuffer_completion_predicate
))
1463 return call1 (Vminibuffer_completion_predicate
, tem
);
1468 return call3 (Vminibuffer_completion_table
, txt
,
1469 Vminibuffer_completion_predicate
, Qlambda
);
1473 * 0 no possible completion
1474 * 1 was already an exact and unique completion
1475 * 3 was already an exact completion
1476 * 4 completed to an exact completion
1477 * 5 some completion happened
1478 * 6 no completion happened
1483 Lisp_Object completion
, tem
;
1486 struct gcpro gcpro1
, gcpro2
;
1488 completion
= Ftry_completion (Fbuffer_string (), Vminibuffer_completion_table
,
1489 Vminibuffer_completion_predicate
);
1490 last
= last_exact_completion
;
1491 last_exact_completion
= Qnil
;
1493 GCPRO2 (completion
, last
);
1495 if (NILP (completion
))
1498 temp_echo_area_glyphs (" [No match]");
1503 if (EQ (completion
, Qt
)) /* exact and unique match */
1510 tem
= Fstring_equal (completion
, Fbuffer_string());
1511 completedp
= NILP (tem
);
1514 Ferase_buffer (); /* Some completion happened */
1515 Finsert (1, &completion
);
1518 /* It did find a match. Do we match some possibility exactly now? */
1519 tem
= test_completion (Fbuffer_string ());
1522 /* not an exact match */
1527 Fminibuffer_completion_help ();
1529 temp_echo_area_glyphs (" [Next char not unique]");
1532 else if (completedp
)
1537 /* If the last exact completion and this one were the same,
1538 it means we've already given a "Complete but not unique"
1539 message and the user's hit TAB again, so now we give him help. */
1540 last_exact_completion
= completion
;
1543 tem
= Fbuffer_string ();
1544 if (!NILP (Fequal (tem
, last
)))
1545 Fminibuffer_completion_help ();
1551 /* Like assoc but assumes KEY is a string, and ignores case if appropriate. */
1554 assoc_for_completion (key
, list
)
1555 register Lisp_Object key
;
1558 register Lisp_Object tail
;
1560 for (tail
= list
; !NILP (tail
); tail
= Fcdr (tail
))
1562 register Lisp_Object elt
, tem
, thiscar
;
1564 if (!CONSP (elt
)) continue;
1565 thiscar
= Fcar (elt
);
1566 if (!STRINGP (thiscar
))
1568 tem
= Fcompare_strings (thiscar
, make_number (0), Qnil
,
1569 key
, make_number (0), Qnil
,
1570 completion_ignore_case
? Qt
: Qnil
);
1578 DEFUN ("minibuffer-complete", Fminibuffer_complete
, Sminibuffer_complete
, 0, 0, "",
1579 "Complete the minibuffer contents as far as possible.\n\
1580 Return nil if there is no valid completion, else t.\n\
1581 If no characters can be completed, display a list of possible completions.\n\
1582 If you repeat this command after it displayed such a list,\n\
1583 scroll the window of possible completions.")
1587 Lisp_Object window
, tem
;
1589 /* If the previous command was not this,
1590 mark the completion buffer obsolete. */
1591 if (! EQ (current_kboard
->Vlast_command
, Vthis_command
))
1592 Vminibuf_scroll_window
= Qnil
;
1594 window
= Vminibuf_scroll_window
;
1595 /* If there's a fresh completion window with a live buffer,
1596 and this command is repeated, scroll that window. */
1597 if (! NILP (window
) && ! NILP (XWINDOW (window
)->buffer
)
1598 && !NILP (XBUFFER (XWINDOW (window
)->buffer
)->name
))
1600 struct buffer
*obuf
= current_buffer
;
1602 Fset_buffer (XWINDOW (window
)->buffer
);
1603 tem
= Fpos_visible_in_window_p (make_number (ZV
), window
);
1605 /* If end is in view, scroll up to the beginning. */
1606 Fset_window_start (window
, make_number (BEGV
), Qnil
);
1608 /* Else scroll down one screen. */
1609 Fscroll_other_window (Qnil
);
1611 set_buffer_internal (obuf
);
1615 i
= do_completion ();
1622 temp_echo_area_glyphs (" [Sole completion]");
1626 temp_echo_area_glyphs (" [Complete, but not unique]");
1633 /* Subroutines of Fminibuffer_complete_and_exit. */
1635 /* This one is called by internal_condition_case to do the real work. */
1638 complete_and_exit_1 ()
1640 return make_number (do_completion ());
1643 /* This one is called by internal_condition_case if an error happens.
1644 Pretend the current value is an exact match. */
1647 complete_and_exit_2 (ignore
)
1650 return make_number (1);
1653 DEFUN ("minibuffer-complete-and-exit", Fminibuffer_complete_and_exit
,
1654 Sminibuffer_complete_and_exit
, 0, 0, "",
1655 "If the minibuffer contents is a valid completion then exit.\n\
1656 Otherwise try to complete it. If completion leads to a valid completion,\n\
1657 a repetition of this command will exit.")
1663 /* Allow user to specify null string */
1664 if (XFASTINT (current_buffer
->prompt_end_charpos
) == ZV
)
1667 if (!NILP (test_completion (Fbuffer_string ())))
1670 /* Call do_completion, but ignore errors. */
1671 val
= internal_condition_case (complete_and_exit_1
, Qerror
,
1672 complete_and_exit_2
);
1682 if (!NILP (Vminibuffer_completion_confirm
))
1684 temp_echo_area_glyphs (" [Confirm]");
1694 Fthrow (Qexit
, Qnil
);
1698 DEFUN ("minibuffer-complete-word", Fminibuffer_complete_word
, Sminibuffer_complete_word
,
1700 "Complete the minibuffer contents at most a single word.\n\
1701 After one word is completed as much as possible, a space or hyphen\n\
1702 is added, provided that matches some possible completion.\n\
1703 Return nil if there is no valid completion, else t.")
1706 Lisp_Object completion
, tem
, tem1
;
1707 register int i
, i_byte
;
1708 register unsigned char *completion_string
;
1709 struct gcpro gcpro1
, gcpro2
;
1711 /* We keep calling Fbuffer_string rather than arrange for GC to
1712 hold onto a pointer to one of the strings thus made. */
1714 completion
= Ftry_completion (Fbuffer_string (),
1715 Vminibuffer_completion_table
,
1716 Vminibuffer_completion_predicate
);
1717 if (NILP (completion
))
1720 temp_echo_area_glyphs (" [No match]");
1723 if (EQ (completion
, Qt
))
1726 #if 0 /* How the below code used to look, for reference. */
1727 tem
= Fbuffer_string ();
1728 b
= XSTRING (tem
)->data
;
1729 i
= ZV
- 1 - XSTRING (completion
)->size
;
1730 p
= XSTRING (completion
)->data
;
1732 0 <= scmp (b
, p
, ZV
- 1))
1735 /* Set buffer to longest match of buffer tail and completion head. */
1736 while (0 <= scmp (b
+ i
, p
, ZV
- 1 - i
))
1738 del_range (1, i
+ 1);
1741 #else /* Rewritten code */
1743 int buffer_nchars
, completion_nchars
;
1745 CHECK_STRING (completion
, 0);
1746 tem
= Fbuffer_string ();
1747 GCPRO2 (completion
, tem
);
1748 /* If reading a file name,
1749 expand any $ENVVAR refs in the buffer and in TEM. */
1750 if (! NILP (Vminibuffer_completing_file_name
))
1752 Lisp_Object substituted
;
1753 substituted
= Fsubstitute_in_file_name (tem
);
1754 if (! EQ (substituted
, tem
))
1758 insert_from_string (tem
, 0, 0, XSTRING (tem
)->size
,
1759 STRING_BYTES (XSTRING (tem
)), 0);
1762 buffer_nchars
= XSTRING (tem
)->size
; /* ie ZV - BEGV */
1763 completion_nchars
= XSTRING (completion
)->size
;
1764 i
= buffer_nchars
- completion_nchars
;
1767 (tem1
= Fcompare_strings (tem
, make_number (0),
1768 make_number (buffer_nchars
),
1769 completion
, make_number (0),
1770 make_number (buffer_nchars
),
1771 completion_ignore_case
? Qt
: Qnil
),
1776 /* Set buffer to longest match of buffer tail and completion head. */
1782 tem1
= Fcompare_strings (tem
, make_number (start_pos
), Qnil
,
1783 completion
, make_number (0),
1784 make_number (buffer_nchars
),
1785 completion_ignore_case
? Qt
: Qnil
);
1792 del_range (1, i
+ 1);
1793 SET_PT_BOTH (ZV
, ZV_BYTE
);
1797 #endif /* Rewritten code */
1800 int prompt_end_charpos
, prompt_end_bytepos
;
1801 prompt_end_charpos
= XFASTINT (current_buffer
->prompt_end_charpos
);
1802 prompt_end_bytepos
= CHAR_TO_BYTE (prompt_end_charpos
);
1803 i
= ZV
- prompt_end_charpos
;
1804 i_byte
= ZV_BYTE
- prompt_end_bytepos
;
1807 /* If completion finds next char not unique,
1808 consider adding a space or a hyphen. */
1809 if (i
== XSTRING (completion
)->size
)
1811 GCPRO1 (completion
);
1812 tem
= Ftry_completion (concat2 (Fbuffer_string (), build_string (" ")),
1813 Vminibuffer_completion_table
,
1814 Vminibuffer_completion_predicate
);
1821 GCPRO1 (completion
);
1823 Ftry_completion (concat2 (Fbuffer_string (), build_string ("-")),
1824 Vminibuffer_completion_table
,
1825 Vminibuffer_completion_predicate
);
1833 /* Now find first word-break in the stuff found by completion.
1834 i gets index in string of where to stop completing. */
1838 completion_string
= XSTRING (completion
)->data
;
1839 for (; i_byte
< STRING_BYTES (XSTRING (completion
)); i_byte
+= len
, i
++)
1841 c
= STRING_CHAR_AND_LENGTH (completion_string
+ i_byte
,
1842 XSTRING (completion
)->size
- i_byte
,
1844 if (SYNTAX (c
) != Sword
)
1853 /* If got no characters, print help for user. */
1855 if (i
== ZV
- XFASTINT (current_buffer
->prompt_end_charpos
))
1858 Fminibuffer_completion_help ();
1862 /* Otherwise insert in minibuffer the chars we got */
1865 insert_from_string (completion
, 0, 0, i
, i_byte
, 1);
1869 DEFUN ("display-completion-list", Fdisplay_completion_list
, Sdisplay_completion_list
,
1871 "Display the list of completions, COMPLETIONS, using `standard-output'.\n\
1872 Each element may be just a symbol or string\n\
1873 or may be a list of two strings to be printed as if concatenated.\n\
1874 `standard-output' must be a buffer.\n\
1875 The actual completion alternatives, as inserted, are given `mouse-face'\n\
1876 properties of `highlight'.\n\
1877 At the end, this runs the normal hook `completion-setup-hook'.\n\
1878 It can find the completion buffer in `standard-output'.")
1880 Lisp_Object completions
;
1882 Lisp_Object tail
, elt
;
1885 struct gcpro gcpro1
, gcpro2
;
1886 struct buffer
*old
= current_buffer
;
1889 /* Note that (when it matters) every variable
1890 points to a non-string that is pointed to by COMPLETIONS,
1891 except for ELT. ELT can be pointing to a string
1892 when terpri or Findent_to calls a change hook. */
1894 GCPRO2 (completions
, elt
);
1896 if (BUFFERP (Vstandard_output
))
1897 set_buffer_internal (XBUFFER (Vstandard_output
));
1899 if (NILP (completions
))
1900 write_string ("There are no possible completions of what you have typed.",
1904 write_string ("Possible completions are:", -1);
1905 for (tail
= completions
, i
= 0; !NILP (tail
); tail
= Fcdr (tail
), i
++)
1907 Lisp_Object tem
, string
;
1909 Lisp_Object startpos
, endpos
;
1912 /* Compute the length of this element. */
1916 CHECK_STRING (tem
, 0);
1917 length
= XSTRING (tem
)->size
;
1919 tem
= Fcar (XCDR (elt
));
1920 CHECK_STRING (tem
, 0);
1921 length
+= XSTRING (tem
)->size
;
1925 CHECK_STRING (elt
, 0);
1926 length
= XSTRING (elt
)->size
;
1929 /* This does a bad job for narrower than usual windows.
1930 Sadly, the window it will appear in is not known
1931 until after the text has been made. */
1933 if (BUFFERP (Vstandard_output
))
1934 XSETINT (startpos
, BUF_PT (XBUFFER (Vstandard_output
)));
1936 /* If the previous completion was very wide,
1937 or we have two on this line already,
1938 don't put another on the same line. */
1939 if (column
> 33 || first
1940 /* If this is really wide, don't put it second on a line. */
1941 || (column
> 0 && length
> 45))
1946 /* Otherwise advance to column 35. */
1949 if (BUFFERP (Vstandard_output
))
1951 tem
= Findent_to (make_number (35), make_number (2));
1953 column
= XINT (tem
);
1959 write_string (" ", -1);
1962 while (column
< 35);
1966 if (BUFFERP (Vstandard_output
))
1968 XSETINT (endpos
, BUF_PT (XBUFFER (Vstandard_output
)));
1969 Fset_text_properties (startpos
, endpos
,
1970 Qnil
, Vstandard_output
);
1973 /* Output this element.
1974 If necessary, convert it to unibyte or to multibyte first. */
1976 string
= Fcar (elt
);
1979 if (NILP (current_buffer
->enable_multibyte_characters
)
1980 && STRING_MULTIBYTE (string
))
1981 string
= Fstring_make_unibyte (string
);
1982 else if (!NILP (current_buffer
->enable_multibyte_characters
)
1983 && !STRING_MULTIBYTE (string
))
1984 string
= Fstring_make_multibyte (string
);
1986 if (BUFFERP (Vstandard_output
))
1988 XSETINT (startpos
, BUF_PT (XBUFFER (Vstandard_output
)));
1990 Fprinc (string
, Qnil
);
1992 XSETINT (endpos
, BUF_PT (XBUFFER (Vstandard_output
)));
1994 Fput_text_property (startpos
, endpos
,
1995 Qmouse_face
, intern ("highlight"),
2000 Fprinc (string
, Qnil
);
2003 /* Output the annotation for this element. */
2006 if (BUFFERP (Vstandard_output
))
2008 XSETINT (startpos
, BUF_PT (XBUFFER (Vstandard_output
)));
2010 Fprinc (Fcar (Fcdr (elt
)), Qnil
);
2012 XSETINT (endpos
, BUF_PT (XBUFFER (Vstandard_output
)));
2014 Fset_text_properties (startpos
, endpos
, Qnil
,
2019 Fprinc (Fcar (Fcdr (elt
)), Qnil
);
2024 /* Update COLUMN for what we have output. */
2027 /* If output is to a buffer, recompute COLUMN in a way
2028 that takes account of character widths. */
2029 if (BUFFERP (Vstandard_output
))
2031 tem
= Fcurrent_column ();
2032 column
= XINT (tem
);
2041 if (BUFFERP (Vstandard_output
))
2042 set_buffer_internal (old
);
2044 if (!NILP (Vrun_hooks
))
2045 call1 (Vrun_hooks
, intern ("completion-setup-hook"));
2050 DEFUN ("minibuffer-completion-help", Fminibuffer_completion_help
, Sminibuffer_completion_help
,
2052 "Display a list of possible completions of the current minibuffer contents.")
2055 Lisp_Object completions
;
2057 message ("Making completion list...");
2058 completions
= Fall_completions (Fbuffer_string (),
2059 Vminibuffer_completion_table
,
2060 Vminibuffer_completion_predicate
,
2062 clear_message (1, 0);
2064 if (NILP (completions
))
2067 temp_echo_area_glyphs (" [No completions]");
2070 internal_with_output_to_temp_buffer ("*Completions*",
2071 Fdisplay_completion_list
,
2072 Fsort (completions
, Qstring_lessp
));
2076 DEFUN ("self-insert-and-exit", Fself_insert_and_exit
, Sself_insert_and_exit
, 0, 0, "",
2077 "Terminate minibuffer input.")
2080 if (INTEGERP (last_command_char
))
2081 internal_self_insert (XINT (last_command_char
), 0);
2085 Fthrow (Qexit
, Qnil
);
2088 DEFUN ("exit-minibuffer", Fexit_minibuffer
, Sexit_minibuffer
, 0, 0, "",
2089 "Terminate this minibuffer argument.")
2092 Fthrow (Qexit
, Qnil
);
2095 DEFUN ("minibuffer-depth", Fminibuffer_depth
, Sminibuffer_depth
, 0, 0, 0,
2096 "Return current depth of activations of minibuffer, a nonnegative integer.")
2099 return make_number (minibuf_level
);
2102 DEFUN ("minibuffer-prompt", Fminibuffer_prompt
, Sminibuffer_prompt
, 0, 0, 0,
2103 "Return the prompt string of the currently-active minibuffer.\n\
2104 If no minibuffer is active, return nil.")
2107 return Fcopy_sequence (minibuf_prompt
);
2110 DEFUN ("minibuffer-prompt-width", Fminibuffer_prompt_width
,
2111 Sminibuffer_prompt_width
, 0, 0, 0,
2112 "Return the display width of the minibuffer prompt.")
2115 return make_number (minibuf_prompt_width
);
2119 DEFUN ("minibuffer-prompt-end", Fminibuffer_prompt_end
,
2120 Sminibuffer_prompt_end
, 0, 0, 0,
2121 "Return the end buffer position of the mini-buffer prompt.\n\
2122 Value is 0 if current buffer is not a mini-buffer.")
2125 return (NILP (current_buffer
->prompt_end_charpos
)
2127 : make_number (current_buffer
->prompt_end_charpos
));
2132 /* Temporarily display the string M at the end of the current
2133 minibuffer contents. This is used to display things like
2134 "[No Match]" when the user requests a completion for a prefix
2135 that has no possible completions, and other quick, unobtrusive
2139 temp_echo_area_glyphs (m
)
2143 int osize_byte
= ZV_BYTE
;
2145 int opoint_byte
= PT_BYTE
;
2146 Lisp_Object oinhibit
;
2147 oinhibit
= Vinhibit_quit
;
2149 /* Clear out any old echo-area message to make way for our new thing. */
2152 SET_PT_BOTH (osize
, osize_byte
);
2154 SET_PT_BOTH (opoint
, opoint_byte
);
2156 Fsit_for (make_number (2), Qnil
, Qnil
);
2157 del_range_both (osize
, osize_byte
, ZV
, ZV_BYTE
, 1);
2158 SET_PT_BOTH (opoint
, opoint_byte
);
2159 if (!NILP (Vquit_flag
))
2162 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
2164 Vinhibit_quit
= oinhibit
;
2167 DEFUN ("minibuffer-message", Fminibuffer_message
, Sminibuffer_message
,
2169 "Temporarily display STRING at the end of the minibuffer.\n\
2170 The text is displayed for two seconds,\n\
2171 or until the next input event arrives, whichever comes first.")
2175 temp_echo_area_glyphs (XSTRING (string
)->data
);
2180 init_minibuf_once ()
2182 Vminibuffer_list
= Qnil
;
2183 staticpro (&Vminibuffer_list
);
2190 minibuf_prompt
= Qnil
;
2191 staticpro (&minibuf_prompt
);
2193 minibuf_save_list
= Qnil
;
2194 staticpro (&minibuf_save_list
);
2196 Qread_file_name_internal
= intern ("read-file-name-internal");
2197 staticpro (&Qread_file_name_internal
);
2199 Qminibuffer_default
= intern ("minibuffer-default");
2200 staticpro (&Qminibuffer_default
);
2201 Fset (Qminibuffer_default
, Qnil
);
2203 Qminibuffer_completion_table
= intern ("minibuffer-completion-table");
2204 staticpro (&Qminibuffer_completion_table
);
2206 Qminibuffer_completion_confirm
= intern ("minibuffer-completion-confirm");
2207 staticpro (&Qminibuffer_completion_confirm
);
2209 Qminibuffer_completion_predicate
= intern ("minibuffer-completion-predicate");
2210 staticpro (&Qminibuffer_completion_predicate
);
2212 staticpro (&last_exact_completion
);
2213 last_exact_completion
= Qnil
;
2215 staticpro (&last_minibuf_string
);
2216 last_minibuf_string
= Qnil
;
2218 Quser_variable_p
= intern ("user-variable-p");
2219 staticpro (&Quser_variable_p
);
2221 Qminibuffer_history
= intern ("minibuffer-history");
2222 staticpro (&Qminibuffer_history
);
2224 Qbuffer_name_history
= intern ("buffer-name-history");
2225 staticpro (&Qbuffer_name_history
);
2226 Fset (Qbuffer_name_history
, Qnil
);
2228 Qminibuffer_setup_hook
= intern ("minibuffer-setup-hook");
2229 staticpro (&Qminibuffer_setup_hook
);
2231 Qminibuffer_exit_hook
= intern ("minibuffer-exit-hook");
2232 staticpro (&Qminibuffer_exit_hook
);
2234 Qhistory_length
= intern ("history-length");
2235 staticpro (&Qhistory_length
);
2237 Qcurrent_input_method
= intern ("current-input-method");
2238 staticpro (&Qcurrent_input_method
);
2240 Qactivate_input_method
= intern ("activate-input-method");
2241 staticpro (&Qactivate_input_method
);
2243 DEFVAR_LISP ("read-buffer-function", &Vread_buffer_function
,
2244 "If this is non-nil, `read-buffer' does its work by calling this function.");
2245 Vread_buffer_function
= Qnil
;
2247 DEFVAR_LISP ("minibuffer-setup-hook", &Vminibuffer_setup_hook
,
2248 "Normal hook run just after entry to minibuffer.");
2249 Vminibuffer_setup_hook
= Qnil
;
2251 DEFVAR_LISP ("minibuffer-exit-hook", &Vminibuffer_exit_hook
,
2252 "Normal hook run just after exit from minibuffer.");
2253 Vminibuffer_exit_hook
= Qnil
;
2255 DEFVAR_LISP ("history-length", &Vhistory_length
,
2256 "*Maximum length for history lists before truncation takes place.\n\
2257 A number means that length; t means infinite. Truncation takes place\n\
2258 just after a new element is inserted. Setting the history-length\n\
2259 property of a history variable overrides this default.");
2260 XSETFASTINT (Vhistory_length
, 30);
2262 DEFVAR_BOOL ("completion-auto-help", &auto_help
,
2263 "*Non-nil means automatically provide help for invalid completion input.");
2266 DEFVAR_BOOL ("completion-ignore-case", &completion_ignore_case
,
2267 "Non-nil means don't consider case significant in completion.");
2268 completion_ignore_case
= 0;
2270 DEFVAR_BOOL ("enable-recursive-minibuffers", &enable_recursive_minibuffers
,
2271 "*Non-nil means to allow minibuffer commands while in the minibuffer.\n\
2272 This variable makes a difference whenever the minibuffer window is active.");
2273 enable_recursive_minibuffers
= 0;
2275 DEFVAR_LISP ("minibuffer-completion-table", &Vminibuffer_completion_table
,
2276 "Alist or obarray used for completion in the minibuffer.\n\
2277 This becomes the ALIST argument to `try-completion' and `all-completion'.\n\
2279 The value may alternatively be a function, which is given three arguments:\n\
2280 STRING, the current buffer contents;\n\
2281 PREDICATE, the predicate for filtering possible matches;\n\
2282 CODE, which says what kind of things to do.\n\
2283 CODE can be nil, t or `lambda'.\n\
2284 nil means to return the best completion of STRING, or nil if there is none.\n\
2285 t means to return a list of all possible completions of STRING.\n\
2286 `lambda' means to return t if STRING is a valid completion as it stands.");
2287 Vminibuffer_completion_table
= Qnil
;
2289 DEFVAR_LISP ("minibuffer-completion-predicate", &Vminibuffer_completion_predicate
,
2290 "Within call to `completing-read', this holds the PREDICATE argument.");
2291 Vminibuffer_completion_predicate
= Qnil
;
2293 DEFVAR_LISP ("minibuffer-completion-confirm", &Vminibuffer_completion_confirm
,
2294 "Non-nil => demand confirmation of completion before exiting minibuffer.");
2295 Vminibuffer_completion_confirm
= Qnil
;
2297 DEFVAR_LISP ("minibuffer-completing-file-name",
2298 &Vminibuffer_completing_file_name
,
2299 "Non-nil means completing file names.");
2300 Vminibuffer_completing_file_name
= Qnil
;
2302 DEFVAR_LISP ("minibuffer-help-form", &Vminibuffer_help_form
,
2303 "Value that `help-form' takes on inside the minibuffer.");
2304 Vminibuffer_help_form
= Qnil
;
2306 DEFVAR_LISP ("minibuffer-history-variable", &Vminibuffer_history_variable
,
2307 "History list symbol to add minibuffer values to.\n\
2308 Each string of minibuffer input, as it appears on exit from the minibuffer,\n\
2310 (set minibuffer-history-variable\n\
2311 (cons STRING (symbol-value minibuffer-history-variable)))");
2312 XSETFASTINT (Vminibuffer_history_variable
, 0);
2314 DEFVAR_LISP ("minibuffer-history-position", &Vminibuffer_history_position
,
2315 "Current position of redoing in the history list.");
2316 Vminibuffer_history_position
= Qnil
;
2318 DEFVAR_BOOL ("minibuffer-auto-raise", &minibuffer_auto_raise
,
2319 "*Non-nil means entering the minibuffer raises the minibuffer's frame.\n\
2320 Some uses of the echo area also raise that frame (since they use it too).");
2321 minibuffer_auto_raise
= 0;
2323 DEFVAR_LISP ("completion-regexp-list", &Vcompletion_regexp_list
,
2324 "List of regexps that should restrict possible completions.");
2325 Vcompletion_regexp_list
= Qnil
;
2327 DEFVAR_BOOL ("minibuffer-allow-text-properties",
2328 &minibuffer_allow_text_properties
,
2329 "Non-nil means `read-from-minibuffer' should not discard text properties.\n\
2330 This also affects `read-string', but it does not affect `read-minibuffer',\n\
2331 `read-no-blanks-input', or any of the functions that do minibuffer input\n\
2332 with completion; they always discard text properties.");
2333 minibuffer_allow_text_properties
= 0;
2335 defsubr (&Sset_minibuffer_window
);
2336 defsubr (&Sread_from_minibuffer
);
2337 defsubr (&Seval_minibuffer
);
2338 defsubr (&Sread_minibuffer
);
2339 defsubr (&Sread_string
);
2340 defsubr (&Sread_command
);
2341 defsubr (&Sread_variable
);
2342 defsubr (&Sread_buffer
);
2343 defsubr (&Sread_no_blanks_input
);
2344 defsubr (&Sminibuffer_depth
);
2345 defsubr (&Sminibuffer_prompt
);
2346 defsubr (&Sminibuffer_prompt_width
);
2347 defsubr (&Sminibuffer_prompt_end
);
2349 defsubr (&Stry_completion
);
2350 defsubr (&Sall_completions
);
2351 defsubr (&Scompleting_read
);
2352 defsubr (&Sminibuffer_complete
);
2353 defsubr (&Sminibuffer_complete_word
);
2354 defsubr (&Sminibuffer_complete_and_exit
);
2355 defsubr (&Sdisplay_completion_list
);
2356 defsubr (&Sminibuffer_completion_help
);
2358 defsubr (&Sself_insert_and_exit
);
2359 defsubr (&Sexit_minibuffer
);
2361 defsubr (&Sminibuffer_message
);
2367 initial_define_key (Vminibuffer_local_map
, Ctl ('g'),
2368 "abort-recursive-edit");
2369 initial_define_key (Vminibuffer_local_map
, Ctl ('m'),
2371 initial_define_key (Vminibuffer_local_map
, Ctl ('j'),
2374 initial_define_key (Vminibuffer_local_ns_map
, Ctl ('g'),
2375 "abort-recursive-edit");
2376 initial_define_key (Vminibuffer_local_ns_map
, Ctl ('m'),
2378 initial_define_key (Vminibuffer_local_ns_map
, Ctl ('j'),
2381 initial_define_key (Vminibuffer_local_ns_map
, ' ',
2383 initial_define_key (Vminibuffer_local_ns_map
, '\t',
2385 initial_define_key (Vminibuffer_local_ns_map
, '?',
2386 "self-insert-and-exit");
2388 initial_define_key (Vminibuffer_local_completion_map
, Ctl ('g'),
2389 "abort-recursive-edit");
2390 initial_define_key (Vminibuffer_local_completion_map
, Ctl ('m'),
2392 initial_define_key (Vminibuffer_local_completion_map
, Ctl ('j'),
2395 initial_define_key (Vminibuffer_local_completion_map
, '\t',
2396 "minibuffer-complete");
2397 initial_define_key (Vminibuffer_local_completion_map
, ' ',
2398 "minibuffer-complete-word");
2399 initial_define_key (Vminibuffer_local_completion_map
, '?',
2400 "minibuffer-completion-help");
2402 initial_define_key (Vminibuffer_local_must_match_map
, Ctl ('g'),
2403 "abort-recursive-edit");
2404 initial_define_key (Vminibuffer_local_must_match_map
, Ctl ('m'),
2405 "minibuffer-complete-and-exit");
2406 initial_define_key (Vminibuffer_local_must_match_map
, Ctl ('j'),
2407 "minibuffer-complete-and-exit");
2408 initial_define_key (Vminibuffer_local_must_match_map
, '\t',
2409 "minibuffer-complete");
2410 initial_define_key (Vminibuffer_local_must_match_map
, ' ',
2411 "minibuffer-complete-word");
2412 initial_define_key (Vminibuffer_local_must_match_map
, '?',
2413 "minibuffer-completion-help");