1 /* Minibuffer input and completion.
2 Copyright (C) 1985, 1986, 1993, 1994 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
25 #include "dispextern.h"
30 #define min(a, b) ((a) < (b) ? (a) : (b))
34 /* List of buffers for use as minibuffers.
35 The first element of the list is used for the outermost minibuffer
36 invocation, the next element is used for a recursive minibuffer
37 invocation, etc. The list is extended at the end as deeper
38 minibuffer recursions are encountered. */
39 Lisp_Object Vminibuffer_list
;
41 /* Data to remember during recursive minibuffer invocations */
42 Lisp_Object minibuf_save_list
;
44 /* Depth in minibuffer invocations. */
47 /* Nonzero means display completion help for invalid input */
50 /* Fread_minibuffer leaves the input here as a string. */
51 Lisp_Object last_minibuf_string
;
53 /* Nonzero means let functions called when within a minibuffer
54 invoke recursive minibuffers (to read arguments, or whatever) */
55 int enable_recursive_minibuffers
;
57 /* help-form is bound to this while in the minibuffer. */
59 Lisp_Object Vminibuffer_help_form
;
61 /* Variable which is the history list to add minibuffer values to. */
63 Lisp_Object Vminibuffer_history_variable
;
65 /* Current position in the history list (adjusted by M-n and M-p). */
67 Lisp_Object Vminibuffer_history_position
;
69 Lisp_Object Qminibuffer_history
;
71 Lisp_Object Qread_file_name_internal
;
73 /* Normal hooks for entry to and exit from minibuffer. */
75 Lisp_Object Qminibuffer_setup_hook
, Vminibuffer_setup_hook
;
76 Lisp_Object Qminibuffer_exit_hook
, Vminibuffer_exit_hook
;
78 /* Nonzero means completion ignores case. */
80 int completion_ignore_case
;
82 /* List of regexps that should restrict possible completions. */
84 Lisp_Object Vcompletion_regexp_list
;
86 /* Nonzero means raise the minibuffer frame when the minibuffer
89 int minibuffer_auto_raise
;
91 /* If last completion attempt reported "Complete but not unique"
92 then this is the string completed then; otherwise this is nil. */
94 static Lisp_Object last_exact_completion
;
96 Lisp_Object Quser_variable_p
;
98 /* Non-nil means it is the window for C-M-v to scroll
99 when the minibuffer is selected. */
100 extern Lisp_Object Vminibuf_scroll_window
;
102 /* Actual minibuffer invocation. */
104 void read_minibuf_unwind ();
105 Lisp_Object
get_minibuffer ();
106 Lisp_Object
read_minibuf ();
108 /* Read from the minibuffer using keymap MAP, initial contents INITIAL
109 (a string), putting point minus BACKUP_N chars from the end of INITIAL,
110 prompting with PROMPT (a string), using history list HISTVAR
111 with initial position HISTPOS. (BACKUP_N should be <= 0.)
113 Normally return the result as a string (the text that was read),
114 but if EXPFLAG is nonzero, read it and return the object read.
115 If HISTVAR is given, save the value read on that history only if it doesn't
116 match the front of that history list exactly. The value is pushed onto
117 the list as the string that was read. */
120 read_minibuf (map
, initial
, prompt
, backup_n
, expflag
, histvar
, histpos
)
124 Lisp_Object backup_n
;
130 int count
= specpdl_ptr
- specpdl
;
131 Lisp_Object mini_frame
;
132 struct gcpro gcpro1
, gcpro2
, gcpro3
;
135 /* Don't need to protect PROMPT, HISTVAR, and HISTPOS because we
136 store them away before we can GC. Don't need to protect
137 BACKUP_N because we use the value only if it is an integer. */
138 GCPRO3 (map
, initial
, val
);
140 if (!STRINGP (prompt
))
141 prompt
= build_string ("");
143 /* Emacs in -batch mode calls minibuffer: print the prompt. */
144 if (noninteractive
&& STRINGP (prompt
))
145 printf ("%s", XSTRING (prompt
)->data
);
147 if (!enable_recursive_minibuffers
149 && (EQ (selected_window
, minibuf_window
)))
151 || selected_frame
!= XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window
)))
153 error ("Command attempted to use minibuffer while in minibuffer");
155 /* Could we simply bind these variables instead? */
157 = Fcons (minibuf_prompt
,
158 Fcons (make_number (minibuf_prompt_width
),
160 Fcons (Vcurrent_prefix_arg
,
161 Fcons (Vminibuffer_history_position
,
162 Fcons (Vminibuffer_history_variable
,
163 minibuf_save_list
))))));
164 minibuf_prompt_width
= 0; /* xdisp.c puts in the right value. */
165 minibuf_prompt
= Fcopy_sequence (prompt
);
166 Vminibuffer_history_position
= histpos
;
167 Vminibuffer_history_variable
= histvar
;
169 record_unwind_protect (Fset_window_configuration
,
170 Fcurrent_window_configuration (Qnil
));
172 /* If the minibuffer window is on a different frame, save that
173 frame's configuration too. */
175 mini_frame
= WINDOW_FRAME (XWINDOW (minibuf_window
));
176 if (XFRAME (mini_frame
) != selected_frame
)
177 record_unwind_protect (Fset_window_configuration
,
178 Fcurrent_window_configuration (mini_frame
));
180 /* If the minibuffer is on an iconified or invisible frame,
181 make it visible now. */
182 Fmake_frame_visible (mini_frame
);
184 if (minibuffer_auto_raise
)
185 Fraise_frame (mini_frame
);
188 val
= current_buffer
->directory
;
189 Fset_buffer (get_minibuffer (minibuf_level
));
191 /* The current buffer's default directory is usually the right thing
192 for our minibuffer here. However, if you're typing a command at
193 a minibuffer-only frame when minibuf_level is zero, then buf IS
194 the current_buffer, so reset_buffer leaves buf's default
195 directory unchanged. This is a bummer when you've just started
196 up Emacs and buf's default directory is Qnil. Here's a hack; can
197 you think of something better to do? Find another buffer with a
198 better directory, and use that one instead. */
200 current_buffer
->directory
= val
;
203 Lisp_Object buf_list
;
205 for (buf_list
= Vbuffer_alist
;
207 buf_list
= XCONS (buf_list
)->cdr
)
209 Lisp_Object other_buf
;
211 other_buf
= XCONS (XCONS (buf_list
)->car
)->cdr
;
212 if (STRINGP (XBUFFER (other_buf
)->directory
))
214 current_buffer
->directory
= XBUFFER (other_buf
)->directory
;
221 if (XFRAME (mini_frame
) != selected_frame
)
222 Fredirect_frame_focus (Fselected_frame (), mini_frame
);
224 Fmake_local_variable (Qprint_escape_newlines
);
225 print_escape_newlines
= 1;
227 record_unwind_protect (read_minibuf_unwind
, Qnil
);
229 Vminibuf_scroll_window
= selected_window
;
230 Fset_window_buffer (minibuf_window
, Fcurrent_buffer ());
231 Fselect_window (minibuf_window
);
232 XSETFASTINT (XWINDOW (minibuf_window
)->hscroll
, 0);
239 Finsert (1, &initial
);
240 if (!NILP (backup_n
) && INTEGERP (backup_n
))
241 Fforward_char (backup_n
);
244 echo_area_glyphs
= 0;
245 /* This is in case the minibuffer-setup-hook calls Fsit_for. */
246 previous_echo_glyphs
= 0;
248 Vhelp_form
= Vminibuffer_help_form
;
249 current_buffer
->keymap
= map
;
251 /* Run our hook, but not if it is empty.
252 (run-hooks would do nothing if it is empty,
253 but it's important to save time here in the usual case. */
254 if (!NILP (Vminibuffer_setup_hook
) && !EQ (Vminibuffer_setup_hook
, Qunbound
)
255 && !NILP (Vrun_hooks
))
256 call1 (Vrun_hooks
, Qminibuffer_setup_hook
);
258 /* ??? MCC did redraw_screen here if switching screens. */
261 /* If cursor is on the minibuffer line,
262 show the user we have exited by putting it in column 0. */
263 if ((FRAME_CURSOR_Y (selected_frame
)
264 >= XFASTINT (XWINDOW (minibuf_window
)->top
))
267 FRAME_CURSOR_X (selected_frame
) = 0;
268 update_frame (selected_frame
, 1, 1);
271 /* Make minibuffer contents into a string */
272 val
= make_buffer_string (1, Z
);
273 bcopy (GAP_END_ADDR
, XSTRING (val
)->data
+ GPT
- BEG
, Z
- GPT
);
275 /* VAL is the string of minibuffer text. */
276 last_minibuf_string
= val
;
278 /* Add the value to the appropriate history list unless it is empty. */
279 if (XSTRING (val
)->size
!= 0
280 && SYMBOLP (Vminibuffer_history_variable
)
281 && ! EQ (XSYMBOL (Vminibuffer_history_variable
)->value
, Qunbound
))
283 /* If the caller wanted to save the value read on a history list,
284 then do so if the value is not already the front of the list. */
286 histval
= Fsymbol_value (Vminibuffer_history_variable
);
288 /* The value of the history variable must be a cons or nil. Other
289 values are unacceptable. We silently ignore these values. */
292 && NILP (Fequal (last_minibuf_string
, Fcar (histval
)))))
293 Fset (Vminibuffer_history_variable
,
294 Fcons (last_minibuf_string
, histval
));
297 /* If Lisp form desired instead of string, parse it. */
300 Lisp_Object expr_and_pos
;
303 expr_and_pos
= Fread_from_string (val
, Qnil
, Qnil
);
304 /* Ignore trailing whitespace; any other trailing junk is an error. */
305 for (p
= XSTRING (val
)->data
+ XINT (Fcdr (expr_and_pos
)); *p
; p
++)
306 if (*p
!= ' ' && *p
!= '\t' && *p
!= '\n')
307 error ("Trailing garbage following expression");
308 val
= Fcar (expr_and_pos
);
311 /* The appropriate frame will get selected
312 in set-window-configuration. */
313 RETURN_UNGCPRO (unbind_to (count
, val
));
316 /* Return a buffer to be used as the minibuffer at depth `depth'.
317 depth = 0 is the lowest allowed argument, and that is the value
318 used for nonrecursive minibuffer invocations */
321 get_minibuffer (depth
)
324 Lisp_Object tail
, num
, buf
;
326 extern Lisp_Object
nconc2 ();
328 XSETFASTINT (num
, depth
);
329 tail
= Fnthcdr (num
, Vminibuffer_list
);
332 tail
= Fcons (Qnil
, Qnil
);
333 Vminibuffer_list
= nconc2 (Vminibuffer_list
, tail
);
336 if (NILP (buf
) || NILP (XBUFFER (buf
)->name
))
338 sprintf (name
, " *Minibuf-%d*", depth
);
339 buf
= Fget_buffer_create (build_string (name
));
341 /* Although the buffer's name starts with a space, undo should be
343 Fbuffer_enable_undo (buf
);
345 XCONS (tail
)->car
= buf
;
349 int count
= specpdl_ptr
- specpdl
;
351 reset_buffer (XBUFFER (buf
));
352 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
354 Fkill_all_local_variables ();
355 unbind_to (count
, Qnil
);
361 /* This function is called on exiting minibuffer, whether normally or not,
362 and it restores the current window, buffer, etc. */
365 read_minibuf_unwind (data
)
368 Lisp_Object old_deactivate_mark
;
370 /* We are exiting the minibuffer one way or the other,
372 if (!NILP (Vminibuffer_exit_hook
) && !EQ (Vminibuffer_exit_hook
, Qunbound
)
373 && !NILP (Vrun_hooks
))
374 call1 (Vrun_hooks
, Qminibuffer_exit_hook
);
376 /* Erase the minibuffer we were using at this level. */
377 Fset_buffer (XWINDOW (minibuf_window
)->buffer
);
379 /* Prevent error in erase-buffer. */
380 current_buffer
->read_only
= Qnil
;
382 old_deactivate_mark
= Vdeactivate_mark
;
384 Vdeactivate_mark
= old_deactivate_mark
;
386 /* If this was a recursive minibuffer,
387 tie the minibuffer window back to the outer level minibuffer buffer */
389 /* Make sure minibuffer window is erased, not ignored */
390 windows_or_buffers_changed
++;
391 XSETFASTINT (XWINDOW (minibuf_window
)->last_modified
, 0);
393 /* Restore prompt, etc from outer minibuffer */
394 minibuf_prompt
= Fcar (minibuf_save_list
);
395 minibuf_save_list
= Fcdr (minibuf_save_list
);
396 minibuf_prompt_width
= XFASTINT (Fcar (minibuf_save_list
));
397 minibuf_save_list
= Fcdr (minibuf_save_list
);
398 Vhelp_form
= Fcar (minibuf_save_list
);
399 minibuf_save_list
= Fcdr (minibuf_save_list
);
400 Vcurrent_prefix_arg
= Fcar (minibuf_save_list
);
401 minibuf_save_list
= Fcdr (minibuf_save_list
);
402 Vminibuffer_history_position
= Fcar (minibuf_save_list
);
403 minibuf_save_list
= Fcdr (minibuf_save_list
);
404 Vminibuffer_history_variable
= Fcar (minibuf_save_list
);
405 minibuf_save_list
= Fcdr (minibuf_save_list
);
409 /* This comment supplies the doc string for read-from-minibuffer,
410 for make-docfile to see. We cannot put this in the real DEFUN
411 due to limits in the Unix cpp.
413 DEFUN ("read-from-minibuffer", Fread_from_minibuffer, Sread_from_minibuffer, 1, 5, 0,
414 "Read a string from the minibuffer, prompting with string PROMPT.\n\
415 If optional second arg INITIAL-CONTENTS is non-nil, it is a string\n\
416 to be inserted into the minibuffer before reading input.\n\
417 If INITIAL-CONTENTS is (STRING . POSITION), the initial input\n\
418 is STRING, but point is placed POSITION characters into the string.\n\
419 Third arg KEYMAP is a keymap to use whilst reading;\n\
420 if omitted or nil, the default is `minibuffer-local-map'.\n\
421 If fourth arg READ is non-nil, then interpret the result as a lisp object\n\
422 and return that object:\n\
423 in other words, do `(car (read-from-string INPUT-STRING))'\n\
424 Fifth arg HIST, if non-nil, specifies a history list\n\
425 and optionally the initial position in the list.\n\
426 It can be a symbol, which is the history list variable to use,\n\
427 or it can be a cons cell (HISTVAR . HISTPOS).\n\
428 In that case, HISTVAR is the history list variable to use,\n\
429 and HISTPOS is the initial position (the position in the list\n\
430 which INITIAL-CONTENTS corresponds to).\n\
431 Positions are counted starting from 1 at the beginning of the list."
434 DEFUN ("read-from-minibuffer", Fread_from_minibuffer
, Sread_from_minibuffer
, 1, 5, 0,
435 0 /* See immediately above */)
436 (prompt
, initial_contents
, keymap
, read
, hist
)
437 Lisp_Object prompt
, initial_contents
, keymap
, read
, hist
;
440 Lisp_Object histvar
, histpos
, position
;
443 CHECK_STRING (prompt
, 0);
444 if (!NILP (initial_contents
))
446 if (CONSP (initial_contents
))
448 position
= Fcdr (initial_contents
);
449 initial_contents
= Fcar (initial_contents
);
451 CHECK_STRING (initial_contents
, 1);
452 if (!NILP (position
))
454 CHECK_NUMBER (position
, 0);
455 /* Convert to distance from end of input. */
456 pos
= XINT (position
) - 1 - XSTRING (initial_contents
)->size
;
461 keymap
= Vminibuffer_local_map
;
463 keymap
= get_keymap (keymap
,2);
472 histvar
= Fcar_safe (hist
);
473 histpos
= Fcdr_safe (hist
);
476 histvar
= Qminibuffer_history
;
478 XSETFASTINT (histpos
, 0);
480 return read_minibuf (keymap
, initial_contents
, prompt
,
481 make_number (pos
), !NILP (read
), histvar
, histpos
);
484 DEFUN ("read-minibuffer", Fread_minibuffer
, Sread_minibuffer
, 1, 2, 0,
485 "Return a Lisp object read using the minibuffer.\n\
486 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS\n\
487 is a string to insert in the minibuffer before reading.")
488 (prompt
, initial_contents
)
489 Lisp_Object prompt
, initial_contents
;
491 CHECK_STRING (prompt
, 0);
492 if (!NILP (initial_contents
))
493 CHECK_STRING (initial_contents
, 1);
494 return read_minibuf (Vminibuffer_local_map
, initial_contents
,
495 prompt
, Qnil
, 1, Qminibuffer_history
, make_number (0));
498 DEFUN ("eval-minibuffer", Feval_minibuffer
, Seval_minibuffer
, 1, 2, 0,
499 "Return value of Lisp expression read using the minibuffer.\n\
500 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS\n\
501 is a string to insert in the minibuffer before reading.")
502 (prompt
, initial_contents
)
503 Lisp_Object prompt
, initial_contents
;
505 return Feval (Fread_minibuffer (prompt
, initial_contents
));
508 /* Functions that use the minibuffer to read various things. */
510 DEFUN ("read-string", Fread_string
, Sread_string
, 1, 2, 0,
511 "Read a string from the minibuffer, prompting with string PROMPT.\n\
512 If non-nil second arg INITIAL-INPUT is a string to insert before reading.")
513 (prompt
, initial_input
)
514 Lisp_Object prompt
, initial_input
;
516 return Fread_from_minibuffer (prompt
, initial_input
, Qnil
, Qnil
, Qnil
);
519 DEFUN ("read-no-blanks-input", Fread_no_blanks_input
, Sread_no_blanks_input
, 1, 2, 0,
520 "Args PROMPT and INIT, strings. Read a string from the terminal, not allowing blanks.\n\
521 Prompt with PROMPT, and provide INIT as an initial value of the input string.")
523 Lisp_Object prompt
, init
;
525 CHECK_STRING (prompt
, 0);
527 CHECK_STRING (init
, 1);
529 return read_minibuf (Vminibuffer_local_ns_map
, init
, prompt
, Qnil
, 0,
530 Qminibuffer_history
, make_number (0));
533 DEFUN ("read-command", Fread_command
, Sread_command
, 1, 1, 0,
534 "One arg PROMPT, a string. Read the name of a command and return as a symbol.\n\
535 Prompts with PROMPT.")
539 return Fintern (Fcompleting_read (prompt
, Vobarray
, Qcommandp
, Qt
, Qnil
, Qnil
),
544 DEFUN ("read-function", Fread_function
, Sread_function
, 1, 1, 0,
545 "One arg PROMPT, a string. Read the name of a function and return as a symbol.\n\
546 Prompts with PROMPT.")
550 return Fintern (Fcompleting_read (prompt
, Vobarray
, Qfboundp
, Qt
, Qnil
, Qnil
),
555 DEFUN ("read-variable", Fread_variable
, Sread_variable
, 1, 1, 0,
556 "One arg PROMPT, a string. Read the name of a user variable and return\n\
557 it as a symbol. Prompts with PROMPT.\n\
558 A user variable is one whose documentation starts with a `*' character.")
562 return Fintern (Fcompleting_read (prompt
, Vobarray
,
563 Quser_variable_p
, Qt
, Qnil
, Qnil
),
567 DEFUN ("read-buffer", Fread_buffer
, Sread_buffer
, 1, 3, 0,
568 "One arg PROMPT, a string. Read the name of a buffer and return as a string.\n\
569 Prompts with PROMPT.\n\
570 Optional second arg is value to return if user enters an empty line.\n\
571 If optional third arg REQUIRE-MATCH is non-nil, only existing buffer names are allowed.")
572 (prompt
, def
, require_match
)
573 Lisp_Object prompt
, def
, require_match
;
580 def
= XBUFFER (def
)->name
;
583 args
[0] = build_string ("%s(default %s) ");
586 prompt
= Fformat (3, args
);
589 tem
= Fcompleting_read (prompt
, Vbuffer_alist
, Qnil
, require_match
, Qnil
, Qnil
);
591 if (XSTRING (tem
)->size
)
596 DEFUN ("try-completion", Ftry_completion
, Stry_completion
, 2, 3, 0,
597 "Return common substring of all completions of STRING in ALIST.\n\
598 Each car of each element of ALIST is tested to see if it begins with STRING.\n\
599 All that match are compared together; the longest initial sequence\n\
600 common to all matches is returned as a string.\n\
601 If there is no match at all, nil is returned.\n\
602 For an exact match, t is returned.\n\
604 ALIST can be an obarray instead of an alist.\n\
605 Then the print names of all symbols in the obarray are the possible matches.\n\
607 ALIST can also be a function to do the completion itself.\n\
608 It receives three arguments: the values STRING, PREDICATE and nil.\n\
609 Whatever it returns becomes the value of `try-completion'.\n\
611 If optional third argument PREDICATE is non-nil,\n\
612 it is used to test each possible match.\n\
613 The match is a candidate only if PREDICATE returns non-nil.\n\
614 The argument given to PREDICATE is the alist element\n\
615 or the symbol from the obarray.")
616 (string
, alist
, pred
)
617 Lisp_Object string
, alist
, pred
;
619 Lisp_Object bestmatch
, tail
, elt
, eltstring
;
621 int compare
, matchsize
;
622 int list
= CONSP (alist
) || NILP (alist
);
625 Lisp_Object bucket
, zero
, end
, tem
;
626 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
628 CHECK_STRING (string
, 0);
629 if (!list
&& !VECTORP (alist
))
630 return call3 (alist
, string
, pred
, Qnil
);
634 /* If ALIST is not a list, set TAIL just for gc pro. */
639 obsize
= XVECTOR (alist
)->size
;
640 bucket
= XVECTOR (alist
)->contents
[index
];
645 /* Get the next element of the alist or obarray. */
646 /* Exit the loop if the elements are all used up. */
647 /* elt gets the alist element or symbol.
648 eltstring gets the name to check as a completion. */
655 eltstring
= Fcar (elt
);
660 if (XFASTINT (bucket
) != 0)
663 eltstring
= Fsymbol_name (elt
);
664 if (XSYMBOL (bucket
)->next
)
665 XSETSYMBOL (bucket
, XSYMBOL (bucket
)->next
);
667 XSETFASTINT (bucket
, 0);
669 else if (++index
>= obsize
)
673 bucket
= XVECTOR (alist
)->contents
[index
];
678 /* Is this element a possible completion? */
680 if (STRINGP (eltstring
)
681 && XSTRING (string
)->size
<= XSTRING (eltstring
)->size
682 && 0 > scmp (XSTRING (eltstring
)->data
, XSTRING (string
)->data
,
683 XSTRING (string
)->size
))
688 XSETFASTINT (zero
, 0);
690 /* Ignore this element if it fails to match all the regexps. */
691 for (regexps
= Vcompletion_regexp_list
; CONSP (regexps
);
692 regexps
= XCONS (regexps
)->cdr
)
694 tem
= Fstring_match (XCONS (regexps
)->car
, eltstring
, zero
);
701 /* Ignore this element if there is a predicate
702 and the predicate doesn't like it. */
706 if (EQ (pred
, Qcommandp
))
707 tem
= Fcommandp (elt
);
710 GCPRO4 (tail
, string
, eltstring
, bestmatch
);
711 tem
= call1 (pred
, elt
);
714 if (NILP (tem
)) continue;
717 /* Update computation of how much all possible completions match */
720 if (NILP (bestmatch
))
721 bestmatch
= eltstring
, bestmatchsize
= XSTRING (eltstring
)->size
;
724 compare
= min (bestmatchsize
, XSTRING (eltstring
)->size
);
725 matchsize
= scmp (XSTRING (bestmatch
)->data
,
726 XSTRING (eltstring
)->data
,
730 if (completion_ignore_case
)
732 /* If this is an exact match except for case,
733 use it as the best match rather than one that is not an
734 exact match. This way, we get the case pattern
735 of the actual match. */
736 if ((matchsize
== XSTRING (eltstring
)->size
737 && matchsize
< XSTRING (bestmatch
)->size
)
739 /* If there is more than one exact match ignoring case,
740 and one of them is exact including case,
742 /* If there is no exact match ignoring case,
743 prefer a match that does not change the case
745 ((matchsize
== XSTRING (eltstring
)->size
)
747 (matchsize
== XSTRING (bestmatch
)->size
)
748 && !bcmp (XSTRING (eltstring
)->data
,
749 XSTRING (string
)->data
, XSTRING (string
)->size
)
750 && bcmp (XSTRING (bestmatch
)->data
,
751 XSTRING (string
)->data
, XSTRING (string
)->size
)))
752 bestmatch
= eltstring
;
754 bestmatchsize
= matchsize
;
759 if (NILP (bestmatch
))
760 return Qnil
; /* No completions found */
761 /* If we are ignoring case, and there is no exact match,
762 and no additional text was supplied,
763 don't change the case of what the user typed. */
764 if (completion_ignore_case
&& bestmatchsize
== XSTRING (string
)->size
765 && XSTRING (bestmatch
)->size
> bestmatchsize
)
768 /* Return t if the supplied string is an exact match (counting case);
769 it does not require any change to be made. */
770 if (matchcount
== 1 && bestmatchsize
== XSTRING (string
)->size
771 && !bcmp (XSTRING (bestmatch
)->data
, XSTRING (string
)->data
,
775 XSETFASTINT (zero
, 0); /* Else extract the part in which */
776 XSETFASTINT (end
, bestmatchsize
); /* all completions agree */
777 return Fsubstring (bestmatch
, zero
, end
);
780 /* Compare exactly LEN chars of strings at S1 and S2,
781 ignoring case if appropriate.
782 Return -1 if strings match,
783 else number of chars that match at the beginning. */
787 register unsigned char *s1
, *s2
;
790 register int l
= len
;
792 if (completion_ignore_case
)
794 while (l
&& DOWNCASE (*s1
++) == DOWNCASE (*s2
++))
799 while (l
&& *s1
++ == *s2
++)
808 DEFUN ("all-completions", Fall_completions
, Sall_completions
, 2, 4, 0,
809 "Search for partial matches to STRING in ALIST.\n\
810 Each car of each element of ALIST is tested to see if it begins with STRING.\n\
811 The value is a list of all the strings from ALIST that match.\n\
813 ALIST can be an obarray instead of an alist.\n\
814 Then the print names of all symbols in the obarray are the possible matches.\n\
816 ALIST can also be a function to do the completion itself.\n\
817 It receives three arguments: the values STRING, PREDICATE and t.\n\
818 Whatever it returns becomes the value of `all-completion'.\n\
820 If optional third argument PREDICATE is non-nil,\n\
821 it is used to test each possible match.\n\
822 The match is a candidate only if PREDICATE returns non-nil.\n\
823 The argument given to PREDICATE is the alist element\n\
824 or the symbol from the obarray.\n\
826 If the optional fourth argument HIDE-SPACES is non-nil,\n\
827 strings in ALIST that start with a space\n\
828 are ignored unless STRING itself starts with a space.")
829 (string
, alist
, pred
, hide_spaces
)
830 Lisp_Object string
, alist
, pred
, hide_spaces
;
832 Lisp_Object tail
, elt
, eltstring
;
833 Lisp_Object allmatches
;
834 int list
= CONSP (alist
) || NILP (alist
);
836 Lisp_Object bucket
, tem
;
837 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
839 CHECK_STRING (string
, 0);
840 if (!list
&& !VECTORP (alist
))
842 return call3 (alist
, string
, pred
, Qt
);
846 /* If ALIST is not a list, set TAIL just for gc pro. */
851 obsize
= XVECTOR (alist
)->size
;
852 bucket
= XVECTOR (alist
)->contents
[index
];
857 /* Get the next element of the alist or obarray. */
858 /* Exit the loop if the elements are all used up. */
859 /* elt gets the alist element or symbol.
860 eltstring gets the name to check as a completion. */
867 eltstring
= Fcar (elt
);
872 if (XFASTINT (bucket
) != 0)
875 eltstring
= Fsymbol_name (elt
);
876 if (XSYMBOL (bucket
)->next
)
877 XSETSYMBOL (bucket
, XSYMBOL (bucket
)->next
);
879 XSETFASTINT (bucket
, 0);
881 else if (++index
>= obsize
)
885 bucket
= XVECTOR (alist
)->contents
[index
];
890 /* Is this element a possible completion? */
892 if (STRINGP (eltstring
)
893 && XSTRING (string
)->size
<= XSTRING (eltstring
)->size
894 /* If HIDE_SPACES, reject alternatives that start with space
895 unless the input starts with space. */
896 && ((XSTRING (string
)->size
> 0 && XSTRING (string
)->data
[0] == ' ')
897 || XSTRING (eltstring
)->data
[0] != ' '
898 || NILP (hide_spaces
))
899 && 0 > scmp (XSTRING (eltstring
)->data
, XSTRING (string
)->data
,
900 XSTRING (string
)->size
))
905 XSETFASTINT (zero
, 0);
907 /* Ignore this element if it fails to match all the regexps. */
908 for (regexps
= Vcompletion_regexp_list
; CONSP (regexps
);
909 regexps
= XCONS (regexps
)->cdr
)
911 tem
= Fstring_match (XCONS (regexps
)->car
, eltstring
, zero
);
918 /* Ignore this element if there is a predicate
919 and the predicate doesn't like it. */
923 if (EQ (pred
, Qcommandp
))
924 tem
= Fcommandp (elt
);
927 GCPRO4 (tail
, eltstring
, allmatches
, string
);
928 tem
= call1 (pred
, elt
);
931 if (NILP (tem
)) continue;
933 /* Ok => put it on the list. */
934 allmatches
= Fcons (eltstring
, allmatches
);
938 return Fnreverse (allmatches
);
941 Lisp_Object Vminibuffer_completion_table
, Qminibuffer_completion_table
;
942 Lisp_Object Vminibuffer_completion_predicate
, Qminibuffer_completion_predicate
;
943 Lisp_Object Vminibuffer_completion_confirm
, Qminibuffer_completion_confirm
;
945 /* This comment supplies the doc string for completing-read,
946 for make-docfile to see. We cannot put this in the real DEFUN
947 due to limits in the Unix cpp.
949 DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 6, 0,
950 "Read a string in the minibuffer, with completion.\n\
951 Args: PROMPT, TABLE, PREDICATE, REQUIRE-MATCH, INITIAL-INPUT, HIST.\n\
952 PROMPT is a string to prompt with; normally it ends in a colon and a space.\n\
953 TABLE is an alist whose elements' cars are strings, or an obarray.\n\
954 PREDICATE limits completion to a subset of TABLE.\n\
955 See `try-completion' and `all-completions' for more details
956 on completion, TABLE, and PREDICATE.\n\
958 If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless\n\
959 the input is (or completes to) an element of TABLE or is null.\n\
960 If it is also not t, Return does not exit if it does non-null completion.\n\
961 If the input is null, `completing-read' returns nil,\n\
962 regardless of the value of REQUIRE-MATCH.\n\
964 If INITIAL-INPUT is non-nil, insert it in the minibuffer initially.\n\
965 If it is (STRING . POSITION), the initial input\n\
966 is STRING, but point is placed POSITION characters into the string.\n\
967 HIST, if non-nil, specifies a history list\n\
968 and optionally the initial position in the list.\n\
969 It can be a symbol, which is the history list variable to use,\n\
970 or it can be a cons cell (HISTVAR . HISTPOS).\n\
971 In that case, HISTVAR is the history list variable to use,\n\
972 and HISTPOS is the initial position (the position in the list\n\
973 which INITIAL-CONTENTS corresponds to).\n\
974 Positions are counted starting from 1 at the beginning of the list.\n\
975 Completion ignores case if the ambient value of\n\
976 `completion-ignore-case' is non-nil."
978 DEFUN ("completing-read", Fcompleting_read
, Scompleting_read
, 2, 6, 0,
979 0 /* See immediately above */)
980 (prompt
, table
, pred
, require_match
, init
, hist
)
981 Lisp_Object prompt
, table
, pred
, require_match
, init
, hist
;
983 Lisp_Object val
, histvar
, histpos
, position
;
985 int count
= specpdl_ptr
- specpdl
;
986 specbind (Qminibuffer_completion_table
, table
);
987 specbind (Qminibuffer_completion_predicate
, pred
);
988 specbind (Qminibuffer_completion_confirm
,
989 EQ (require_match
, Qt
) ? Qnil
: Qt
);
990 last_exact_completion
= Qnil
;
997 position
= Fcdr (init
);
1000 CHECK_STRING (init
, 0);
1001 if (!NILP (position
))
1003 CHECK_NUMBER (position
, 0);
1004 /* Convert to distance from end of input. */
1005 pos
= XINT (position
) - XSTRING (init
)->size
;
1016 histvar
= Fcar_safe (hist
);
1017 histpos
= Fcdr_safe (hist
);
1020 histvar
= Qminibuffer_history
;
1022 XSETFASTINT (histpos
, 0);
1024 val
= read_minibuf (NILP (require_match
)
1025 ? Vminibuffer_local_completion_map
1026 : Vminibuffer_local_must_match_map
,
1027 init
, prompt
, make_number (pos
), 0,
1029 return unbind_to (count
, val
);
1032 /* Temporarily display the string M at the end of the current
1033 minibuffer contents. This is used to display things like
1034 "[No Match]" when the user requests a completion for a prefix
1035 that has no possible completions, and other quick, unobtrusive
1038 temp_echo_area_glyphs (m
)
1042 Lisp_Object oinhibit
;
1043 oinhibit
= Vinhibit_quit
;
1045 /* Clear out any old echo-area message to make way for our new thing. */
1052 Fsit_for (make_number (2), Qnil
, Qnil
);
1054 if (!NILP (Vquit_flag
))
1057 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1059 Vinhibit_quit
= oinhibit
;
1062 Lisp_Object
Fminibuffer_completion_help ();
1063 Lisp_Object
assoc_for_completion ();
1064 /* A subroutine of Fintern_soft. */
1065 extern Lisp_Object
oblookup ();
1068 /* Test whether TXT is an exact completion. */
1070 test_completion (txt
)
1075 if (CONSP (Vminibuffer_completion_table
)
1076 || NILP (Vminibuffer_completion_table
))
1077 return assoc_for_completion (txt
, Vminibuffer_completion_table
);
1078 else if (VECTORP (Vminibuffer_completion_table
))
1080 /* Bypass intern-soft as that loses for nil */
1081 tem
= oblookup (Vminibuffer_completion_table
,
1082 XSTRING (txt
)->data
, XSTRING (txt
)->size
);
1085 else if (!NILP (Vminibuffer_completion_predicate
))
1086 return call1 (Vminibuffer_completion_predicate
, tem
);
1091 return call3 (Vminibuffer_completion_table
, txt
,
1092 Vminibuffer_completion_predicate
, Qlambda
);
1096 * 0 no possible completion
1097 * 1 was already an exact and unique completion
1098 * 3 was already an exact completion
1099 * 4 completed to an exact completion
1100 * 5 some completion happened
1101 * 6 no completion happened
1106 Lisp_Object completion
, tem
;
1109 struct gcpro gcpro1
, gcpro2
;
1111 completion
= Ftry_completion (Fbuffer_string (), Vminibuffer_completion_table
,
1112 Vminibuffer_completion_predicate
);
1113 last
= last_exact_completion
;
1114 last_exact_completion
= Qnil
;
1116 GCPRO2 (completion
, last
);
1118 if (NILP (completion
))
1121 temp_echo_area_glyphs (" [No match]");
1126 if (EQ (completion
, Qt
)) /* exact and unique match */
1133 tem
= Fstring_equal (completion
, Fbuffer_string());
1134 if (completedp
= NILP (tem
))
1136 Ferase_buffer (); /* Some completion happened */
1137 Finsert (1, &completion
);
1140 /* It did find a match. Do we match some possibility exactly now? */
1141 tem
= test_completion (Fbuffer_string ());
1144 /* not an exact match */
1149 Fminibuffer_completion_help ();
1151 temp_echo_area_glyphs (" [Next char not unique]");
1154 else if (completedp
)
1159 /* If the last exact completion and this one were the same,
1160 it means we've already given a "Complete but not unique"
1161 message and the user's hit TAB again, so now we give him help. */
1162 last_exact_completion
= completion
;
1165 tem
= Fbuffer_string ();
1166 if (!NILP (Fequal (tem
, last
)))
1167 Fminibuffer_completion_help ();
1173 /* Like assoc but assumes KEY is a string, and ignores case if appropriate. */
1176 assoc_for_completion (key
, list
)
1177 register Lisp_Object key
;
1180 register Lisp_Object tail
;
1182 if (completion_ignore_case
)
1183 key
= Fupcase (key
);
1185 for (tail
= list
; !NILP (tail
); tail
= Fcdr (tail
))
1187 register Lisp_Object elt
, tem
, thiscar
;
1189 if (!CONSP (elt
)) continue;
1190 thiscar
= Fcar (elt
);
1191 if (!STRINGP (thiscar
))
1193 if (completion_ignore_case
)
1194 thiscar
= Fupcase (thiscar
);
1195 tem
= Fequal (thiscar
, key
);
1196 if (!NILP (tem
)) return elt
;
1202 DEFUN ("minibuffer-complete", Fminibuffer_complete
, Sminibuffer_complete
, 0, 0, "",
1203 "Complete the minibuffer contents as far as possible.\n\
1204 Return nil if there is no valid completion, else t.\n\
1205 If no characters can be completed, display a list of possible completions.\n\
1206 If you repeat this command after it displayed such a list,\n\
1207 scroll the window of possible completions.")
1211 Lisp_Object window
, tem
;
1213 /* If the previous command was not this, then mark the completion
1215 if (! EQ (last_command
, this_command
))
1216 Vminibuf_scroll_window
= Qnil
;
1218 window
= Vminibuf_scroll_window
;
1219 /* If there's a fresh completion window with a live buffer,
1220 and this command is repeated, scroll that window. */
1221 if (! NILP (window
) && ! NILP (XWINDOW (window
)->buffer
)
1222 && !NILP (XBUFFER (XWINDOW (window
)->buffer
)->name
))
1224 struct buffer
*obuf
= current_buffer
;
1226 Fset_buffer (XWINDOW (window
)->buffer
);
1227 tem
= Fpos_visible_in_window_p (make_number (ZV
), window
);
1229 /* If end is in view, scroll up to the beginning. */
1230 Fset_window_start (window
, BEGV
, Qnil
);
1232 /* Else scroll down one screen. */
1233 Fscroll_other_window (Qnil
);
1235 set_buffer_internal (obuf
);
1239 i
= do_completion ();
1246 temp_echo_area_glyphs (" [Sole completion]");
1250 temp_echo_area_glyphs (" [Complete, but not unique]");
1257 /* Subroutines of Fminibuffer_complete_and_exit. */
1259 /* This one is called by internal_condition_case to do the real work. */
1262 complete_and_exit_1 ()
1264 return make_number (do_completion ());
1267 /* This one is called by internal_condition_case if an error happens.
1268 Pretend the current value is an exact match. */
1271 complete_and_exit_2 (ignore
)
1274 return make_number (1);
1277 DEFUN ("minibuffer-complete-and-exit", Fminibuffer_complete_and_exit
,
1278 Sminibuffer_complete_and_exit
, 0, 0, "",
1279 "If the minibuffer contents is a valid completion then exit.\n\
1280 Otherwise try to complete it. If completion leads to a valid completion,\n\
1281 a repetition of this command will exit.")
1287 /* Allow user to specify null string */
1291 if (!NILP (test_completion (Fbuffer_string ())))
1294 /* Call do_completion, but ignore errors. */
1295 val
= internal_condition_case (complete_and_exit_1
, Qerror
,
1296 complete_and_exit_2
);
1306 if (!NILP (Vminibuffer_completion_confirm
))
1308 temp_echo_area_glyphs (" [Confirm]");
1318 Fthrow (Qexit
, Qnil
);
1322 DEFUN ("minibuffer-complete-word", Fminibuffer_complete_word
, Sminibuffer_complete_word
,
1324 "Complete the minibuffer contents at most a single word.\n\
1325 After one word is completed as much as possible, a space or hyphen\n\
1326 is added, provided that matches some possible completion.\n\
1327 Return nil if there is no valid completion, else t.")
1330 Lisp_Object completion
, tem
;
1332 register unsigned char *completion_string
;
1333 struct gcpro gcpro1
, gcpro2
;
1335 /* We keep calling Fbuffer_string rather than arrange for GC to
1336 hold onto a pointer to one of the strings thus made. */
1338 completion
= Ftry_completion (Fbuffer_string (),
1339 Vminibuffer_completion_table
,
1340 Vminibuffer_completion_predicate
);
1341 if (NILP (completion
))
1344 temp_echo_area_glyphs (" [No match]");
1347 if (EQ (completion
, Qt
))
1350 #if 0 /* How the below code used to look, for reference. */
1351 tem
= Fbuffer_string ();
1352 b
= XSTRING (tem
)->data
;
1353 i
= ZV
- 1 - XSTRING (completion
)->size
;
1354 p
= XSTRING (completion
)->data
;
1356 0 <= scmp (b
, p
, ZV
- 1))
1359 /* Set buffer to longest match of buffer tail and completion head. */
1360 while (0 <= scmp (b
+ i
, p
, ZV
- 1 - i
))
1362 del_range (1, i
+ 1);
1365 #else /* Rewritten code */
1367 register unsigned char *buffer_string
;
1368 int buffer_length
, completion_length
;
1370 tem
= Fbuffer_string ();
1371 GCPRO2 (completion
, tem
);
1372 /* If reading a file name,
1373 expand any $ENVVAR refs in the buffer and in TEM. */
1374 if (EQ (Vminibuffer_completion_table
, Qread_file_name_internal
))
1376 Lisp_Object substituted
;
1377 substituted
= Fsubstitute_in_file_name (tem
);
1378 if (! EQ (substituted
, tem
))
1382 insert_from_string (tem
, 0, XSTRING (tem
)->size
, 0);
1385 buffer_string
= XSTRING (tem
)->data
;
1386 completion_string
= XSTRING (completion
)->data
;
1387 buffer_length
= XSTRING (tem
)->size
; /* ie ZV - BEGV */
1388 completion_length
= XSTRING (completion
)->size
;
1389 i
= buffer_length
- completion_length
;
1390 /* Mly: I don't understand what this is supposed to do AT ALL */
1392 0 <= scmp (buffer_string
, completion_string
, buffer_length
))
1394 /* Set buffer to longest match of buffer tail and completion head. */
1398 while (0 <= scmp (buffer_string
++, completion_string
, buffer_length
--))
1400 del_range (1, i
+ 1);
1405 #endif /* Rewritten code */
1408 /* If completion finds next char not unique,
1409 consider adding a space or a hyphen. */
1410 if (i
== XSTRING (completion
)->size
)
1412 GCPRO1 (completion
);
1413 tem
= Ftry_completion (concat2 (Fbuffer_string (), build_string (" ")),
1414 Vminibuffer_completion_table
,
1415 Vminibuffer_completion_predicate
);
1422 GCPRO1 (completion
);
1424 Ftry_completion (concat2 (Fbuffer_string (), build_string ("-")),
1425 Vminibuffer_completion_table
,
1426 Vminibuffer_completion_predicate
);
1434 /* Now find first word-break in the stuff found by completion.
1435 i gets index in string of where to stop completing. */
1437 completion_string
= XSTRING (completion
)->data
;
1439 for (; i
< XSTRING (completion
)->size
; i
++)
1440 if (SYNTAX (completion_string
[i
]) != Sword
) break;
1441 if (i
< XSTRING (completion
)->size
)
1444 /* If got no characters, print help for user. */
1449 Fminibuffer_completion_help ();
1453 /* Otherwise insert in minibuffer the chars we got */
1456 insert_from_string (completion
, 0, i
, 1);
1460 DEFUN ("display-completion-list", Fdisplay_completion_list
, Sdisplay_completion_list
,
1462 "Display the list of completions, COMPLETIONS, using `standard-output'.\n\
1463 Each element may be just a symbol or string\n\
1464 or may be a list of two strings to be printed as if concatenated.\n\
1465 `standard-output' must be a buffer.\n\
1466 At the end, run the normal hook `completion-setup-hook'.\n\
1467 It can find the completion buffer in `standard-output'.")
1469 Lisp_Object completions
;
1471 register Lisp_Object tail
, elt
;
1474 struct gcpro gcpro1
;
1475 struct buffer
*old
= current_buffer
;
1478 /* Note that (when it matters) every variable
1479 points to a non-string that is pointed to by COMPLETIONS. */
1480 GCPRO1 (completions
);
1482 if (BUFFERP (Vstandard_output
))
1483 set_buffer_internal (XBUFFER (Vstandard_output
));
1485 if (NILP (completions
))
1486 write_string ("There are no possible completions of what you have typed.",
1490 write_string ("Possible completions are:", -1);
1491 for (tail
= completions
, i
= 0; !NILP (tail
); tail
= Fcdr (tail
), i
++)
1497 /* Compute the length of this element. */
1501 CHECK_STRING (tem
, 0);
1502 length
= XINT (XSTRING (tem
)->size
);
1504 tem
= Fcar (Fcdr (elt
));
1505 CHECK_STRING (tem
, 0);
1506 length
+= XINT (XSTRING (tem
)->size
);
1510 CHECK_STRING (elt
, 0);
1511 length
= XINT (XSTRING (elt
)->size
);
1514 /* This does a bad job for narrower than usual windows.
1515 Sadly, the window it will appear in is not known
1516 until after the text has been made. */
1518 /* If the previous completion was very wide,
1519 or we have two on this line already,
1520 don't put another on the same line. */
1521 if (column
> 33 || first
1522 /* If this is really wide, don't put it second on a line. */
1523 || column
> 0 && length
> 45)
1528 /* Otherwise advance to column 35. */
1531 if (BUFFERP (Vstandard_output
))
1533 tem
= Findent_to (make_number (35), make_number (2));
1534 column
= XINT (tem
);
1540 write_string (" ", -1);
1543 while (column
< 35);
1547 /* Output this element and update COLUMN. */
1550 Fprinc (Fcar (elt
), Qnil
);
1551 Fprinc (Fcar (Fcdr (elt
)), Qnil
);
1558 /* If output is to a buffer, recompute COLUMN in a way
1559 that takes account of character widths. */
1560 if (BUFFERP (Vstandard_output
))
1562 tem
= Fcurrent_column ();
1563 column
= XINT (tem
);
1572 if (BUFFERP (Vstandard_output
))
1573 set_buffer_internal (old
);
1575 if (!NILP (Vrun_hooks
))
1576 call1 (Vrun_hooks
, intern ("completion-setup-hook"));
1581 DEFUN ("minibuffer-completion-help", Fminibuffer_completion_help
, Sminibuffer_completion_help
,
1583 "Display a list of possible completions of the current minibuffer contents.")
1586 Lisp_Object completions
;
1588 message ("Making completion list...");
1589 completions
= Fall_completions (Fbuffer_string (),
1590 Vminibuffer_completion_table
,
1591 Vminibuffer_completion_predicate
,
1593 echo_area_glyphs
= 0;
1595 if (NILP (completions
))
1598 temp_echo_area_glyphs (" [No completions]");
1601 internal_with_output_to_temp_buffer ("*Completions*",
1602 Fdisplay_completion_list
,
1603 Fsort (completions
, Qstring_lessp
));
1607 DEFUN ("self-insert-and-exit", Fself_insert_and_exit
, Sself_insert_and_exit
, 0, 0, "",
1608 "Terminate minibuffer input.")
1611 if (INTEGERP (last_command_char
))
1612 internal_self_insert (last_command_char
, 0);
1616 Fthrow (Qexit
, Qnil
);
1619 DEFUN ("exit-minibuffer", Fexit_minibuffer
, Sexit_minibuffer
, 0, 0, "",
1620 "Terminate this minibuffer argument.")
1623 Fthrow (Qexit
, Qnil
);
1626 DEFUN ("minibuffer-depth", Fminibuffer_depth
, Sminibuffer_depth
, 0, 0, 0,
1627 "Return current depth of activations of minibuffer, a nonnegative integer.")
1630 return make_number (minibuf_level
);
1633 DEFUN ("minibuffer-prompt", Fminibuffer_prompt
, Sminibuffer_prompt
, 0, 0, 0,
1634 "Return the prompt string of the currently-active minibuffer.\n\
1635 If no minibuffer is active, return nil.")
1638 return Fcopy_sequence (minibuf_prompt
);
1641 DEFUN ("minibuffer-prompt-width", Fminibuffer_prompt_width
,
1642 Sminibuffer_prompt_width
, 0, 0, 0,
1643 "Return the display width of the minibuffer prompt.")
1647 XSETFASTINT (width
, minibuf_prompt_width
);
1651 init_minibuf_once ()
1653 Vminibuffer_list
= Qnil
;
1654 staticpro (&Vminibuffer_list
);
1660 minibuf_prompt
= Qnil
;
1661 staticpro (&minibuf_prompt
);
1663 minibuf_save_list
= Qnil
;
1664 staticpro (&minibuf_save_list
);
1666 Qread_file_name_internal
= intern ("read-file-name-internal");
1667 staticpro (&Qread_file_name_internal
);
1669 Qminibuffer_completion_table
= intern ("minibuffer-completion-table");
1670 staticpro (&Qminibuffer_completion_table
);
1672 Qminibuffer_completion_confirm
= intern ("minibuffer-completion-confirm");
1673 staticpro (&Qminibuffer_completion_confirm
);
1675 Qminibuffer_completion_predicate
= intern ("minibuffer-completion-predicate");
1676 staticpro (&Qminibuffer_completion_predicate
);
1678 staticpro (&last_exact_completion
);
1679 last_exact_completion
= Qnil
;
1681 staticpro (&last_minibuf_string
);
1682 last_minibuf_string
= Qnil
;
1684 Quser_variable_p
= intern ("user-variable-p");
1685 staticpro (&Quser_variable_p
);
1687 Qminibuffer_history
= intern ("minibuffer-history");
1688 staticpro (&Qminibuffer_history
);
1690 Qminibuffer_setup_hook
= intern ("minibuffer-setup-hook");
1691 staticpro (&Qminibuffer_setup_hook
);
1693 Qminibuffer_exit_hook
= intern ("minibuffer-exit-hook");
1694 staticpro (&Qminibuffer_exit_hook
);
1696 DEFVAR_LISP ("minibuffer-setup-hook", &Vminibuffer_setup_hook
,
1697 "Normal hook run just after entry to minibuffer.");
1698 Vminibuffer_setup_hook
= Qnil
;
1700 DEFVAR_LISP ("minibuffer-exit-hook", &Vminibuffer_exit_hook
,
1701 "Normal hook run just after exit from minibuffer.");
1702 Vminibuffer_exit_hook
= Qnil
;
1704 DEFVAR_BOOL ("completion-auto-help", &auto_help
,
1705 "*Non-nil means automatically provide help for invalid completion input.");
1708 DEFVAR_BOOL ("completion-ignore-case", &completion_ignore_case
,
1709 "Non-nil means don't consider case significant in completion.");
1710 completion_ignore_case
= 0;
1712 DEFVAR_BOOL ("enable-recursive-minibuffers", &enable_recursive_minibuffers
,
1713 "*Non-nil means to allow minibuffer commands while in the minibuffer.\n\
1714 More precisely, this variable makes a difference when the minibuffer window\n\
1715 is the selected window. If you are in some other window, minibuffer commands\n\
1716 are allowed even if a minibuffer is active.");
1717 enable_recursive_minibuffers
= 0;
1719 DEFVAR_LISP ("minibuffer-completion-table", &Vminibuffer_completion_table
,
1720 "Alist or obarray used for completion in the minibuffer.\n\
1721 This becomes the ALIST argument to `try-completion' and `all-completion'.\n\
1723 The value may alternatively be a function, which is given three arguments:\n\
1724 STRING, the current buffer contents;\n\
1725 PREDICATE, the predicate for filtering possible matches;\n\
1726 CODE, which says what kind of things to do.\n\
1727 CODE can be nil, t or `lambda'.\n\
1728 nil means to return the best completion of STRING, or nil if there is none.\n\
1729 t means to return a list of all possible completions of STRING.\n\
1730 `lambda' means to return t if STRING is a valid completion as it stands.");
1731 Vminibuffer_completion_table
= Qnil
;
1733 DEFVAR_LISP ("minibuffer-completion-predicate", &Vminibuffer_completion_predicate
,
1734 "Within call to `completing-read', this holds the PREDICATE argument.");
1735 Vminibuffer_completion_predicate
= Qnil
;
1737 DEFVAR_LISP ("minibuffer-completion-confirm", &Vminibuffer_completion_confirm
,
1738 "Non-nil => demand confirmation of completion before exiting minibuffer.");
1739 Vminibuffer_completion_confirm
= Qnil
;
1741 DEFVAR_LISP ("minibuffer-help-form", &Vminibuffer_help_form
,
1742 "Value that `help-form' takes on inside the minibuffer.");
1743 Vminibuffer_help_form
= Qnil
;
1745 DEFVAR_LISP ("minibuffer-history-variable", &Vminibuffer_history_variable
,
1746 "History list symbol to add minibuffer values to.\n\
1747 Each minibuffer output is added with\n\
1748 (set minibuffer-history-variable\n\
1749 (cons STRING (symbol-value minibuffer-history-variable)))");
1750 XSETFASTINT (Vminibuffer_history_variable
, 0);
1752 DEFVAR_LISP ("minibuffer-history-position", &Vminibuffer_history_position
,
1753 "Current position of redoing in the history list.");
1754 Vminibuffer_history_position
= Qnil
;
1756 DEFVAR_BOOL ("minibuffer-auto-raise", &minibuffer_auto_raise
,
1757 "*Non-nil means entering the minibuffer raises the minibuffer's frame.");
1758 minibuffer_auto_raise
= 0;
1760 DEFVAR_LISP ("completion-regexp-list", &Vcompletion_regexp_list
,
1761 "List of regexps that should restrict possible completions.");
1762 Vcompletion_regexp_list
= Qnil
;
1764 defsubr (&Sread_from_minibuffer
);
1765 defsubr (&Seval_minibuffer
);
1766 defsubr (&Sread_minibuffer
);
1767 defsubr (&Sread_string
);
1768 defsubr (&Sread_command
);
1769 defsubr (&Sread_variable
);
1770 defsubr (&Sread_buffer
);
1771 defsubr (&Sread_no_blanks_input
);
1772 defsubr (&Sminibuffer_depth
);
1773 defsubr (&Sminibuffer_prompt
);
1774 defsubr (&Sminibuffer_prompt_width
);
1776 defsubr (&Stry_completion
);
1777 defsubr (&Sall_completions
);
1778 defsubr (&Scompleting_read
);
1779 defsubr (&Sminibuffer_complete
);
1780 defsubr (&Sminibuffer_complete_word
);
1781 defsubr (&Sminibuffer_complete_and_exit
);
1782 defsubr (&Sdisplay_completion_list
);
1783 defsubr (&Sminibuffer_completion_help
);
1785 defsubr (&Sself_insert_and_exit
);
1786 defsubr (&Sexit_minibuffer
);
1792 initial_define_key (Vminibuffer_local_map
, Ctl ('g'),
1793 "abort-recursive-edit");
1794 initial_define_key (Vminibuffer_local_map
, Ctl ('m'),
1796 initial_define_key (Vminibuffer_local_map
, Ctl ('j'),
1799 initial_define_key (Vminibuffer_local_ns_map
, Ctl ('g'),
1800 "abort-recursive-edit");
1801 initial_define_key (Vminibuffer_local_ns_map
, Ctl ('m'),
1803 initial_define_key (Vminibuffer_local_ns_map
, Ctl ('j'),
1806 initial_define_key (Vminibuffer_local_ns_map
, ' ',
1808 initial_define_key (Vminibuffer_local_ns_map
, '\t',
1810 initial_define_key (Vminibuffer_local_ns_map
, '?',
1811 "self-insert-and-exit");
1813 initial_define_key (Vminibuffer_local_completion_map
, Ctl ('g'),
1814 "abort-recursive-edit");
1815 initial_define_key (Vminibuffer_local_completion_map
, Ctl ('m'),
1817 initial_define_key (Vminibuffer_local_completion_map
, Ctl ('j'),
1820 initial_define_key (Vminibuffer_local_completion_map
, '\t',
1821 "minibuffer-complete");
1822 initial_define_key (Vminibuffer_local_completion_map
, ' ',
1823 "minibuffer-complete-word");
1824 initial_define_key (Vminibuffer_local_completion_map
, '?',
1825 "minibuffer-completion-help");
1827 initial_define_key (Vminibuffer_local_must_match_map
, Ctl ('g'),
1828 "abort-recursive-edit");
1829 initial_define_key (Vminibuffer_local_must_match_map
, Ctl ('m'),
1830 "minibuffer-complete-and-exit");
1831 initial_define_key (Vminibuffer_local_must_match_map
, Ctl ('j'),
1832 "minibuffer-complete-and-exit");
1833 initial_define_key (Vminibuffer_local_must_match_map
, '\t',
1834 "minibuffer-complete");
1835 initial_define_key (Vminibuffer_local_must_match_map
, ' ',
1836 "minibuffer-complete-word");
1837 initial_define_key (Vminibuffer_local_must_match_map
, '?',
1838 "minibuffer-completion-help");