(VALBITS, GCTYPEBITS): Deleted; default is better.
[bpt/emacs.git] / src / minibuf.c
CommitLineData
f927c5ae 1/* Minibuffer input and completion.
3a22ee35 2 Copyright (C) 1985, 1986, 1993, 1994 Free Software Foundation, Inc.
f927c5ae
JB
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
ffd56f97 8the Free Software Foundation; either version 2, or (at your option)
f927c5ae
JB
9any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs; see the file COPYING. If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20
18160b98 21#include <config.h>
f927c5ae
JB
22#include "lisp.h"
23#include "commands.h"
24#include "buffer.h"
25#include "dispextern.h"
ff11dfa1 26#include "frame.h"
f927c5ae
JB
27#include "window.h"
28#include "syntax.h"
29
30#define min(a, b) ((a) < (b) ? (a) : (b))
31
a4e71d81
KH
32extern int quit_char;
33
f927c5ae 34/* List of buffers for use as minibuffers.
4d04c1f1
KH
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. */
f927c5ae
JB
39Lisp_Object Vminibuffer_list;
40
4d04c1f1
KH
41/* Data to remember during recursive minibuffer invocations */
42Lisp_Object minibuf_save_list;
f927c5ae
JB
43
44/* Depth in minibuffer invocations. */
45int minibuf_level;
46
47/* Nonzero means display completion help for invalid input */
48int auto_help;
49
b278606c 50/* Fread_minibuffer leaves the input here as a string. */
f927c5ae
JB
51Lisp_Object last_minibuf_string;
52
53/* Nonzero means let functions called when within a minibuffer
54 invoke recursive minibuffers (to read arguments, or whatever) */
55int enable_recursive_minibuffers;
56
57/* help-form is bound to this while in the minibuffer. */
58
59Lisp_Object Vminibuffer_help_form;
60
770970cb
RS
61/* Variable which is the history list to add minibuffer values to. */
62
63Lisp_Object Vminibuffer_history_variable;
64
65/* Current position in the history list (adjusted by M-n and M-p). */
66
67Lisp_Object Vminibuffer_history_position;
68
69Lisp_Object Qminibuffer_history;
70
719b4a40
RS
71Lisp_Object Qread_file_name_internal;
72
177aecf9 73/* Normal hooks for entry to and exit from minibuffer. */
5c781212
RS
74
75Lisp_Object Qminibuffer_setup_hook, Vminibuffer_setup_hook;
177aecf9 76Lisp_Object Qminibuffer_exit_hook, Vminibuffer_exit_hook;
5c781212 77
f927c5ae
JB
78/* Nonzero means completion ignores case. */
79
80int completion_ignore_case;
81
42006772
RS
82/* List of regexps that should restrict possible completions. */
83
84Lisp_Object Vcompletion_regexp_list;
85
6a9ee000
RS
86/* Nonzero means raise the minibuffer frame when the minibuffer
87 is entered. */
88
89int minibuffer_auto_raise;
90
f927c5ae
JB
91/* If last completion attempt reported "Complete but not unique"
92 then this is the string completed then; otherwise this is nil. */
93
94static Lisp_Object last_exact_completion;
95
96Lisp_Object Quser_variable_p;
2cb6da5c
RS
97
98/* Non-nil means it is the window for C-M-v to scroll
99 when the minibuffer is selected. */
100extern Lisp_Object Vminibuf_scroll_window;
f927c5ae
JB
101\f
102/* Actual minibuffer invocation. */
103
104void read_minibuf_unwind ();
105Lisp_Object get_minibuffer ();
106Lisp_Object read_minibuf ();
107
770970cb 108/* Read from the minibuffer using keymap MAP, initial contents INITIAL
85b5fe07 109 (a string), putting point minus BACKUP_N chars from the end of INITIAL,
770970cb 110 prompting with PROMPT (a string), using history list HISTVAR
85b5fe07 111 with initial position HISTPOS. (BACKUP_N should be <= 0.)
770970cb
RS
112
113 Normally return the result as a string (the text that was read),
3ab14176 114 but if EXPFLAG is nonzero, read it and return the object read.
b278606c
BF
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
be765114 117 the list as the string that was read. */
770970cb 118
f927c5ae 119Lisp_Object
770970cb 120read_minibuf (map, initial, prompt, backup_n, expflag, histvar, histpos)
f927c5ae
JB
121 Lisp_Object map;
122 Lisp_Object initial;
123 Lisp_Object prompt;
5061d9c3 124 Lisp_Object backup_n;
f927c5ae 125 int expflag;
770970cb
RS
126 Lisp_Object histvar;
127 Lisp_Object histpos;
f927c5ae 128{
00a34088 129 Lisp_Object val;
f927c5ae 130 int count = specpdl_ptr - specpdl;
5061d9c3 131 Lisp_Object mini_frame;
00a34088
RS
132 struct gcpro gcpro1, gcpro2, gcpro3;
133
134 val = Qnil;
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);
f927c5ae 139
7510b296 140 if (!STRINGP (prompt))
f927c5ae
JB
141 prompt = build_string ("");
142
143 /* Emacs in -batch mode calls minibuffer: print the prompt. */
7510b296 144 if (noninteractive && STRINGP (prompt))
f927c5ae
JB
145 printf ("%s", XSTRING (prompt)->data);
146
147 if (!enable_recursive_minibuffers
148 && minibuf_level > 0
149 && (EQ (selected_window, minibuf_window)))
150#if 0
ff11dfa1 151 || selected_frame != XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window)))
f927c5ae
JB
152#endif
153 error ("Command attempted to use minibuffer while in minibuffer");
154
4d04c1f1
KH
155 /* Could we simply bind these variables instead? */
156 minibuf_save_list
157 = Fcons (minibuf_prompt,
158 Fcons (make_number (minibuf_prompt_width),
159 Fcons (Vhelp_form,
160 Fcons (Vcurrent_prefix_arg,
161 Fcons (Vminibuffer_history_position,
162 Fcons (Vminibuffer_history_variable,
163 minibuf_save_list))))));
00a34088
RS
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;
f927c5ae
JB
168
169 record_unwind_protect (Fset_window_configuration,
b2b2c677
JB
170 Fcurrent_window_configuration (Qnil));
171
ff11dfa1
JB
172 /* If the minibuffer window is on a different frame, save that
173 frame's configuration too. */
5061d9c3 174#ifdef MULTI_FRAME
75f00e72 175 mini_frame = WINDOW_FRAME (XWINDOW (minibuf_window));
ff11dfa1 176 if (XFRAME (mini_frame) != selected_frame)
5061d9c3
RS
177 record_unwind_protect (Fset_window_configuration,
178 Fcurrent_window_configuration (mini_frame));
5563e8e8
KH
179
180 /* If the minibuffer is on an iconified or invisible frame,
181 make it visible now. */
182 Fmake_frame_visible (mini_frame);
183
6a9ee000
RS
184 if (minibuffer_auto_raise)
185 Fraise_frame (mini_frame);
5061d9c3 186#endif
f927c5ae
JB
187
188 val = current_buffer->directory;
189 Fset_buffer (get_minibuffer (minibuf_level));
64a3a3c0
JB
190
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. */
7510b296 199 if (STRINGP (val))
64a3a3c0
JB
200 current_buffer->directory = val;
201 else
202 {
203 Lisp_Object buf_list;
204
205 for (buf_list = Vbuffer_alist;
206 CONSP (buf_list);
207 buf_list = XCONS (buf_list)->cdr)
208 {
1e62748e 209 Lisp_Object other_buf;
64a3a3c0 210
1e62748e 211 other_buf = XCONS (XCONS (buf_list)->car)->cdr;
7510b296 212 if (STRINGP (XBUFFER (other_buf)->directory))
64a3a3c0
JB
213 {
214 current_buffer->directory = XBUFFER (other_buf)->directory;
215 break;
216 }
217 }
218 }
219
33b1baf6 220#ifdef MULTI_FRAME
0abbff13
KH
221 if (XFRAME (mini_frame) != selected_frame)
222 Fredirect_frame_focus (Fselected_frame (), mini_frame);
33b1baf6 223#endif
f927c5ae
JB
224 Fmake_local_variable (Qprint_escape_newlines);
225 print_escape_newlines = 1;
226
43bad991 227 record_unwind_protect (read_minibuf_unwind, Qnil);
43bad991 228
f927c5ae
JB
229 Vminibuf_scroll_window = selected_window;
230 Fset_window_buffer (minibuf_window, Fcurrent_buffer ());
f927c5ae 231 Fselect_window (minibuf_window);
5a866662 232 XSETFASTINT (XWINDOW (minibuf_window)->hscroll, 0);
f927c5ae
JB
233
234 Ferase_buffer ();
235 minibuf_level++;
f927c5ae 236
56a98455 237 if (!NILP (initial))
f927c5ae
JB
238 {
239 Finsert (1, &initial);
7510b296 240 if (!NILP (backup_n) && INTEGERP (backup_n))
f927c5ae
JB
241 Fforward_char (backup_n);
242 }
243
f927c5ae 244 echo_area_glyphs = 0;
73168c8b
RS
245 /* This is in case the minibuffer-setup-hook calls Fsit_for. */
246 previous_echo_glyphs = 0;
f927c5ae
JB
247
248 Vhelp_form = Vminibuffer_help_form;
249 current_buffer->keymap = map;
250
5c781212
RS
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. */
92d3b06e
RS
254 if (!NILP (Vminibuffer_setup_hook) && !EQ (Vminibuffer_setup_hook, Qunbound)
255 && !NILP (Vrun_hooks))
5c781212
RS
256 call1 (Vrun_hooks, Qminibuffer_setup_hook);
257
f927c5ae
JB
258/* ??? MCC did redraw_screen here if switching screens. */
259 recursive_edit_1 ();
260
261 /* If cursor is on the minibuffer line,
262 show the user we have exited by putting it in column 0. */
ff11dfa1 263 if ((FRAME_CURSOR_Y (selected_frame)
f927c5ae
JB
264 >= XFASTINT (XWINDOW (minibuf_window)->top))
265 && !noninteractive)
266 {
ff11dfa1
JB
267 FRAME_CURSOR_X (selected_frame) = 0;
268 update_frame (selected_frame, 1, 1);
f927c5ae
JB
269 }
270
271 /* Make minibuffer contents into a string */
ffd56f97 272 val = make_buffer_string (1, Z);
f927c5ae 273 bcopy (GAP_END_ADDR, XSTRING (val)->data + GPT - BEG, Z - GPT);
770970cb 274
b278606c
BF
275 /* VAL is the string of minibuffer text. */
276 last_minibuf_string = val;
277
3ab14176 278 /* Add the value to the appropriate history list unless it is empty. */
9f6131cf 279 if (XSTRING (val)->size != 0
3ab14176
KH
280 && SYMBOLP (Vminibuffer_history_variable)
281 && ! EQ (XSYMBOL (Vminibuffer_history_variable)->value, Qunbound))
282 {
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. */
285 Lisp_Object histval;
286 histval = Fsymbol_value (Vminibuffer_history_variable);
287
288 /* The value of the history variable must be a cons or nil. Other
289 values are unacceptable. We silently ignore these values. */
290 if (NILP (histval)
9f6131cf
RS
291 || (CONSP (histval)
292 && NILP (Fequal (last_minibuf_string, Fcar (histval)))))
293 Fset (Vminibuffer_history_variable,
294 Fcons (last_minibuf_string, histval));
295 }
296
297 /* If Lisp form desired instead of string, parse it. */
298 if (expflag)
299 {
300 Lisp_Object expr_and_pos;
301 unsigned char *p;
302
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);
3ab14176
KH
309 }
310
00a34088
RS
311 /* The appropriate frame will get selected
312 in set-window-configuration. */
313 RETURN_UNGCPRO (unbind_to (count, val));
f927c5ae
JB
314}
315
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 */
319
320Lisp_Object
321get_minibuffer (depth)
322 int depth;
323{
324 Lisp_Object tail, num, buf;
9f6c23bc 325 char name[24];
f927c5ae
JB
326 extern Lisp_Object nconc2 ();
327
5a866662 328 XSETFASTINT (num, depth);
f927c5ae 329 tail = Fnthcdr (num, Vminibuffer_list);
56a98455 330 if (NILP (tail))
f927c5ae
JB
331 {
332 tail = Fcons (Qnil, Qnil);
333 Vminibuffer_list = nconc2 (Vminibuffer_list, tail);
334 }
335 buf = Fcar (tail);
56a98455 336 if (NILP (buf) || NILP (XBUFFER (buf)->name))
f927c5ae
JB
337 {
338 sprintf (name, " *Minibuf-%d*", depth);
339 buf = Fget_buffer_create (build_string (name));
5d6533f1
JB
340
341 /* Although the buffer's name starts with a space, undo should be
342 enabled in it. */
343 Fbuffer_enable_undo (buf);
344
f927c5ae
JB
345 XCONS (tail)->car = buf;
346 }
347 else
5956f71d 348 {
6b3faad8
RS
349 int count = specpdl_ptr - specpdl;
350
5956f71d 351 reset_buffer (XBUFFER (buf));
6b3faad8
RS
352 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
353 Fset_buffer (buf);
354 Fkill_all_local_variables ();
355 unbind_to (count, Qnil);
5956f71d 356 }
64a3a3c0 357
f927c5ae
JB
358 return buf;
359}
360
361/* This function is called on exiting minibuffer, whether normally or not,
362 and it restores the current window, buffer, etc. */
363
364void
43bad991
JB
365read_minibuf_unwind (data)
366 Lisp_Object data;
f927c5ae 367{
c24e1160
RS
368 Lisp_Object old_deactivate_mark;
369
0a1dd1c5
RS
370 /* We are exiting the minibuffer one way or the other,
371 so run the hook. */
372 if (!NILP (Vminibuffer_exit_hook) && !EQ (Vminibuffer_exit_hook, Qunbound)
373 && !NILP (Vrun_hooks))
374 call1 (Vrun_hooks, Qminibuffer_exit_hook);
375
f927c5ae
JB
376 /* Erase the minibuffer we were using at this level. */
377 Fset_buffer (XWINDOW (minibuf_window)->buffer);
378
379 /* Prevent error in erase-buffer. */
380 current_buffer->read_only = Qnil;
c24e1160
RS
381
382 old_deactivate_mark = Vdeactivate_mark;
f927c5ae 383 Ferase_buffer ();
c24e1160 384 Vdeactivate_mark = old_deactivate_mark;
f927c5ae
JB
385
386 /* If this was a recursive minibuffer,
387 tie the minibuffer window back to the outer level minibuffer buffer */
388 minibuf_level--;
389 /* Make sure minibuffer window is erased, not ignored */
390 windows_or_buffers_changed++;
5a866662 391 XSETFASTINT (XWINDOW (minibuf_window)->last_modified, 0);
f927c5ae 392
4d04c1f1
KH
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);
f927c5ae
JB
406}
407\f
b9d721de
JB
408
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.
412
f927c5ae
JB
413DEFUN ("read-from-minibuffer", Fread_from_minibuffer, Sread_from_minibuffer, 1, 5, 0,
414 "Read a string from the minibuffer, prompting with string PROMPT.\n\
415If optional second arg INITIAL-CONTENTS is non-nil, it is a string\n\
416 to be inserted into the minibuffer before reading input.\n\
770970cb
RS
417 If INITIAL-CONTENTS is (STRING . POSITION), the initial input\n\
418 is STRING, but point is placed POSITION characters into the string.\n\
f927c5ae
JB
419Third arg KEYMAP is a keymap to use whilst reading;\n\
420 if omitted or nil, the default is `minibuffer-local-map'.\n\
421If 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\
770970cb
RS
424Fifth 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\
b9d721de
JB
431 Positions are counted starting from 1 at the beginning of the list."
432*/
433
434DEFUN ("read-from-minibuffer", Fread_from_minibuffer, Sread_from_minibuffer, 1, 5, 0,
435 0 /* See immediately above */)
68e5a8a2
RS
436 (prompt, initial_contents, keymap, read, hist)
437 Lisp_Object prompt, initial_contents, keymap, read, hist;
f927c5ae
JB
438{
439 int pos = 0;
770970cb
RS
440 Lisp_Object histvar, histpos, position;
441 position = Qnil;
f927c5ae
JB
442
443 CHECK_STRING (prompt, 0);
68e5a8a2 444 if (!NILP (initial_contents))
f927c5ae 445 {
7510b296 446 if (CONSP (initial_contents))
770970cb 447 {
68e5a8a2
RS
448 position = Fcdr (initial_contents);
449 initial_contents = Fcar (initial_contents);
770970cb 450 }
68e5a8a2 451 CHECK_STRING (initial_contents, 1);
56a98455 452 if (!NILP (position))
f927c5ae
JB
453 {
454 CHECK_NUMBER (position, 0);
455 /* Convert to distance from end of input. */
68e5a8a2 456 pos = XINT (position) - 1 - XSTRING (initial_contents)->size;
f927c5ae
JB
457 }
458 }
459
56a98455 460 if (NILP (keymap))
f927c5ae
JB
461 keymap = Vminibuffer_local_map;
462 else
463 keymap = get_keymap (keymap,2);
770970cb 464
7510b296 465 if (SYMBOLP (hist))
770970cb
RS
466 {
467 histvar = hist;
468 histpos = Qnil;
469 }
470 else
471 {
472 histvar = Fcar_safe (hist);
473 histpos = Fcdr_safe (hist);
474 }
475 if (NILP (histvar))
476 histvar = Qminibuffer_history;
477 if (NILP (histpos))
5a866662 478 XSETFASTINT (histpos, 0);
770970cb 479
68e5a8a2 480 return read_minibuf (keymap, initial_contents, prompt,
85b5fe07 481 make_number (pos), !NILP (read), histvar, histpos);
f927c5ae
JB
482}
483
484DEFUN ("read-minibuffer", Fread_minibuffer, Sread_minibuffer, 1, 2, 0,
485 "Return a Lisp object read using the minibuffer.\n\
486Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS\n\
487is a string to insert in the minibuffer before reading.")
488 (prompt, initial_contents)
489 Lisp_Object prompt, initial_contents;
490{
491 CHECK_STRING (prompt, 0);
56a98455 492 if (!NILP (initial_contents))
a1b4b084 493 CHECK_STRING (initial_contents, 1);
770970cb
RS
494 return read_minibuf (Vminibuffer_local_map, initial_contents,
495 prompt, Qnil, 1, Qminibuffer_history, make_number (0));
f927c5ae
JB
496}
497
498DEFUN ("eval-minibuffer", Feval_minibuffer, Seval_minibuffer, 1, 2, 0,
499 "Return value of Lisp expression read using the minibuffer.\n\
500Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS\n\
501is a string to insert in the minibuffer before reading.")
502 (prompt, initial_contents)
503 Lisp_Object prompt, initial_contents;
504{
505 return Feval (Fread_minibuffer (prompt, initial_contents));
506}
507
508/* Functions that use the minibuffer to read various things. */
509
510DEFUN ("read-string", Fread_string, Sread_string, 1, 2, 0,
511 "Read a string from the minibuffer, prompting with string PROMPT.\n\
512If non-nil second arg INITIAL-INPUT is a string to insert before reading.")
513 (prompt, initial_input)
514 Lisp_Object prompt, initial_input;
515{
516 return Fread_from_minibuffer (prompt, initial_input, Qnil, Qnil, Qnil);
517}
518
b278606c 519DEFUN ("read-no-blanks-input", Fread_no_blanks_input, Sread_no_blanks_input, 1, 2, 0,
f927c5ae
JB
520 "Args PROMPT and INIT, strings. Read a string from the terminal, not allowing blanks.\n\
521Prompt with PROMPT, and provide INIT as an initial value of the input string.")
522 (prompt, init)
523 Lisp_Object prompt, init;
524{
525 CHECK_STRING (prompt, 0);
56a98455 526 if (! NILP (init))
f927c5ae
JB
527 CHECK_STRING (init, 1);
528
770970cb
RS
529 return read_minibuf (Vminibuffer_local_ns_map, init, prompt, Qnil, 0,
530 Qminibuffer_history, make_number (0));
f927c5ae
JB
531}
532
533DEFUN ("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\
535Prompts with PROMPT.")
536 (prompt)
537 Lisp_Object prompt;
538{
539 return Fintern (Fcompleting_read (prompt, Vobarray, Qcommandp, Qt, Qnil, Qnil),
540 Qnil);
541}
542
543#ifdef NOTDEF
544DEFUN ("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\
546Prompts with PROMPT.")
547 (prompt)
548 Lisp_Object prompt;
549{
550 return Fintern (Fcompleting_read (prompt, Vobarray, Qfboundp, Qt, Qnil, Qnil),
551 Qnil);
552}
553#endif /* NOTDEF */
554
555DEFUN ("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\
557it as a symbol. Prompts with PROMPT.\n\
558A user variable is one whose documentation starts with a `*' character.")
559 (prompt)
560 Lisp_Object prompt;
561{
562 return Fintern (Fcompleting_read (prompt, Vobarray,
563 Quser_variable_p, Qt, Qnil, Qnil),
564 Qnil);
565}
566
567DEFUN ("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\
569Prompts with PROMPT.\n\
570Optional second arg is value to return if user enters an empty line.\n\
571If 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;
574{
575 Lisp_Object tem;
576 Lisp_Object args[3];
577 struct gcpro gcpro1;
578
7510b296 579 if (BUFFERP (def))
f927c5ae 580 def = XBUFFER (def)->name;
56a98455 581 if (!NILP (def))
f927c5ae
JB
582 {
583 args[0] = build_string ("%s(default %s) ");
584 args[1] = prompt;
585 args[2] = def;
586 prompt = Fformat (3, args);
587 }
588 GCPRO1 (def);
589 tem = Fcompleting_read (prompt, Vbuffer_alist, Qnil, require_match, Qnil, Qnil);
590 UNGCPRO;
591 if (XSTRING (tem)->size)
592 return tem;
593 return def;
594}
595\f
596DEFUN ("try-completion", Ftry_completion, Stry_completion, 2, 3, 0,
597 "Return common substring of all completions of STRING in ALIST.\n\
598Each car of each element of ALIST is tested to see if it begins with STRING.\n\
599All that match are compared together; the longest initial sequence\n\
600common to all matches is returned as a string.\n\
601If there is no match at all, nil is returned.\n\
602For an exact match, t is returned.\n\
603\n\
604ALIST can be an obarray instead of an alist.\n\
605Then the print names of all symbols in the obarray are the possible matches.\n\
606\n\
607ALIST can also be a function to do the completion itself.\n\
608It receives three arguments: the values STRING, PREDICATE and nil.\n\
609Whatever it returns becomes the value of `try-completion'.\n\
610\n\
611If optional third argument PREDICATE is non-nil,\n\
612it is used to test each possible match.\n\
613The match is a candidate only if PREDICATE returns non-nil.\n\
89a255dc
RS
614The argument given to PREDICATE is the alist element\n\
615or the symbol from the obarray.")
f927c5ae
JB
616 (string, alist, pred)
617 Lisp_Object string, alist, pred;
618{
619 Lisp_Object bestmatch, tail, elt, eltstring;
620 int bestmatchsize;
621 int compare, matchsize;
56a98455 622 int list = CONSP (alist) || NILP (alist);
f927c5ae
JB
623 int index, obsize;
624 int matchcount = 0;
625 Lisp_Object bucket, zero, end, tem;
626 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
627
628 CHECK_STRING (string, 0);
7510b296 629 if (!list && !VECTORP (alist))
f927c5ae
JB
630 return call3 (alist, string, pred, Qnil);
631
632 bestmatch = Qnil;
633
634 /* If ALIST is not a list, set TAIL just for gc pro. */
635 tail = alist;
636 if (! list)
637 {
638 index = 0;
639 obsize = XVECTOR (alist)->size;
640 bucket = XVECTOR (alist)->contents[index];
641 }
642
643 while (1)
644 {
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. */
649
650 if (list)
651 {
56a98455 652 if (NILP (tail))
f927c5ae
JB
653 break;
654 elt = Fcar (tail);
655 eltstring = Fcar (elt);
656 tail = Fcdr (tail);
657 }
658 else
659 {
660 if (XFASTINT (bucket) != 0)
661 {
662 elt = bucket;
663 eltstring = Fsymbol_name (elt);
664 if (XSYMBOL (bucket)->next)
665 XSETSYMBOL (bucket, XSYMBOL (bucket)->next);
666 else
5a866662 667 XSETFASTINT (bucket, 0);
f927c5ae
JB
668 }
669 else if (++index >= obsize)
670 break;
671 else
672 {
673 bucket = XVECTOR (alist)->contents[index];
674 continue;
675 }
676 }
677
678 /* Is this element a possible completion? */
679
7510b296 680 if (STRINGP (eltstring)
42006772
RS
681 && XSTRING (string)->size <= XSTRING (eltstring)->size
682 && 0 > scmp (XSTRING (eltstring)->data, XSTRING (string)->data,
683 XSTRING (string)->size))
f927c5ae
JB
684 {
685 /* Yes. */
42006772
RS
686 Lisp_Object regexps;
687 Lisp_Object zero;
5a866662 688 XSETFASTINT (zero, 0);
42006772
RS
689
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)
693 {
694 tem = Fstring_match (XCONS (regexps)->car, eltstring, zero);
695 if (NILP (tem))
696 break;
697 }
698 if (CONSP (regexps))
699 continue;
700
f927c5ae
JB
701 /* Ignore this element if there is a predicate
702 and the predicate doesn't like it. */
703
56a98455 704 if (!NILP (pred))
f927c5ae
JB
705 {
706 if (EQ (pred, Qcommandp))
707 tem = Fcommandp (elt);
708 else
709 {
710 GCPRO4 (tail, string, eltstring, bestmatch);
711 tem = call1 (pred, elt);
712 UNGCPRO;
713 }
56a98455 714 if (NILP (tem)) continue;
f927c5ae
JB
715 }
716
717 /* Update computation of how much all possible completions match */
718
719 matchcount++;
56a98455 720 if (NILP (bestmatch))
f927c5ae
JB
721 bestmatch = eltstring, bestmatchsize = XSTRING (eltstring)->size;
722 else
723 {
724 compare = min (bestmatchsize, XSTRING (eltstring)->size);
725 matchsize = scmp (XSTRING (bestmatch)->data,
726 XSTRING (eltstring)->data,
727 compare);
52b14ac0
JB
728 if (matchsize < 0)
729 matchsize = compare;
730 if (completion_ignore_case)
731 {
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)
738 ||
739 /* If there is more than one exact match ignoring case,
740 and one of them is exact including case,
741 prefer that one. */
742 /* If there is no exact match ignoring case,
743 prefer a match that does not change the case
744 of the input. */
745 ((matchsize == XSTRING (eltstring)->size)
746 ==
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;
753 }
754 bestmatchsize = matchsize;
f927c5ae
JB
755 }
756 }
757 }
758
56a98455 759 if (NILP (bestmatch))
f927c5ae 760 return Qnil; /* No completions found */
52b14ac0
JB
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)
766 return string;
767
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,
772 bestmatchsize))
f927c5ae
JB
773 return Qt;
774
5a866662
KH
775 XSETFASTINT (zero, 0); /* Else extract the part in which */
776 XSETFASTINT (end, bestmatchsize); /* all completions agree */
f927c5ae
JB
777 return Fsubstring (bestmatch, zero, end);
778}
779
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. */
784
829f7f7c 785int
f927c5ae 786scmp (s1, s2, len)
829f7f7c 787 register unsigned char *s1, *s2;
f927c5ae
JB
788 int len;
789{
790 register int l = len;
791
792 if (completion_ignore_case)
793 {
794 while (l && DOWNCASE (*s1++) == DOWNCASE (*s2++))
795 l--;
796 }
797 else
798 {
799 while (l && *s1++ == *s2++)
800 l--;
801 }
802 if (l == 0)
803 return -1;
829f7f7c
KH
804 else
805 return len - l;
f927c5ae
JB
806}
807\f
89a255dc 808DEFUN ("all-completions", Fall_completions, Sall_completions, 2, 4, 0,
f927c5ae
JB
809 "Search for partial matches to STRING in ALIST.\n\
810Each car of each element of ALIST is tested to see if it begins with STRING.\n\
811The value is a list of all the strings from ALIST that match.\n\
89a255dc 812\n\
f927c5ae
JB
813ALIST can be an obarray instead of an alist.\n\
814Then the print names of all symbols in the obarray are the possible matches.\n\
815\n\
816ALIST can also be a function to do the completion itself.\n\
817It receives three arguments: the values STRING, PREDICATE and t.\n\
818Whatever it returns becomes the value of `all-completion'.\n\
819\n\
820If optional third argument PREDICATE is non-nil,\n\
821it is used to test each possible match.\n\
822The match is a candidate only if PREDICATE returns non-nil.\n\
89a255dc
RS
823The argument given to PREDICATE is the alist element\n\
824or the symbol from the obarray.\n\
825\n\
826If the optional fourth argument HIDE-SPACES is non-nil,\n\
827strings in ALIST that start with a space\n\
828are ignored unless STRING itself starts with a space.")
829 (string, alist, pred, hide_spaces)
830 Lisp_Object string, alist, pred, hide_spaces;
f927c5ae
JB
831{
832 Lisp_Object tail, elt, eltstring;
833 Lisp_Object allmatches;
56a98455 834 int list = CONSP (alist) || NILP (alist);
f927c5ae
JB
835 int index, obsize;
836 Lisp_Object bucket, tem;
837 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
838
839 CHECK_STRING (string, 0);
7510b296 840 if (!list && !VECTORP (alist))
f927c5ae
JB
841 {
842 return call3 (alist, string, pred, Qt);
843 }
844 allmatches = Qnil;
845
846 /* If ALIST is not a list, set TAIL just for gc pro. */
847 tail = alist;
848 if (! list)
849 {
850 index = 0;
851 obsize = XVECTOR (alist)->size;
852 bucket = XVECTOR (alist)->contents[index];
853 }
854
855 while (1)
856 {
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. */
861
862 if (list)
863 {
56a98455 864 if (NILP (tail))
f927c5ae
JB
865 break;
866 elt = Fcar (tail);
867 eltstring = Fcar (elt);
868 tail = Fcdr (tail);
869 }
870 else
871 {
872 if (XFASTINT (bucket) != 0)
873 {
874 elt = bucket;
875 eltstring = Fsymbol_name (elt);
876 if (XSYMBOL (bucket)->next)
877 XSETSYMBOL (bucket, XSYMBOL (bucket)->next);
878 else
5a866662 879 XSETFASTINT (bucket, 0);
f927c5ae
JB
880 }
881 else if (++index >= obsize)
882 break;
883 else
884 {
885 bucket = XVECTOR (alist)->contents[index];
886 continue;
887 }
888 }
889
890 /* Is this element a possible completion? */
891
7510b296 892 if (STRINGP (eltstring)
2cbaf886 893 && XSTRING (string)->size <= XSTRING (eltstring)->size
89a255dc 894 /* If HIDE_SPACES, reject alternatives that start with space
2cbaf886
RS
895 unless the input starts with space. */
896 && ((XSTRING (string)->size > 0 && XSTRING (string)->data[0] == ' ')
89a255dc
RS
897 || XSTRING (eltstring)->data[0] != ' '
898 || NILP (hide_spaces))
2cbaf886
RS
899 && 0 > scmp (XSTRING (eltstring)->data, XSTRING (string)->data,
900 XSTRING (string)->size))
f927c5ae
JB
901 {
902 /* Yes. */
42006772
RS
903 Lisp_Object regexps;
904 Lisp_Object zero;
5a866662 905 XSETFASTINT (zero, 0);
42006772
RS
906
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)
910 {
911 tem = Fstring_match (XCONS (regexps)->car, eltstring, zero);
912 if (NILP (tem))
913 break;
914 }
915 if (CONSP (regexps))
916 continue;
917
f927c5ae
JB
918 /* Ignore this element if there is a predicate
919 and the predicate doesn't like it. */
920
56a98455 921 if (!NILP (pred))
f927c5ae
JB
922 {
923 if (EQ (pred, Qcommandp))
924 tem = Fcommandp (elt);
925 else
926 {
927 GCPRO4 (tail, eltstring, allmatches, string);
928 tem = call1 (pred, elt);
929 UNGCPRO;
930 }
56a98455 931 if (NILP (tem)) continue;
f927c5ae
JB
932 }
933 /* Ok => put it on the list. */
934 allmatches = Fcons (eltstring, allmatches);
935 }
936 }
937
938 return Fnreverse (allmatches);
939}
940\f
941Lisp_Object Vminibuffer_completion_table, Qminibuffer_completion_table;
942Lisp_Object Vminibuffer_completion_predicate, Qminibuffer_completion_predicate;
943Lisp_Object Vminibuffer_completion_confirm, Qminibuffer_completion_confirm;
944
b9d721de
JB
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.
948
f927c5ae
JB
949DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 6, 0,
950 "Read a string in the minibuffer, with completion.\n\
770970cb 951Args: PROMPT, TABLE, PREDICATE, REQUIRE-MATCH, INITIAL-INPUT, HIST.\n\
f927c5ae
JB
952PROMPT is a string to prompt with; normally it ends in a colon and a space.\n\
953TABLE is an alist whose elements' cars are strings, or an obarray.\n\
954PREDICATE limits completion to a subset of TABLE.\n\
6b3faad8
RS
955See `try-completion' and `all-completions' for more details
956 on completion, TABLE, and PREDICATE.\n\
cbbc3917 957\n\
f927c5ae 958If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless\n\
4ced3209 959 the input is (or completes to) an element of TABLE or is null.\n\
f927c5ae 960 If it is also not t, Return does not exit if it does non-null completion.\n\
cbbc3917
RS
961If the input is null, `completing-read' returns nil,\n\
962 regardless of the value of REQUIRE-MATCH.\n\
963\n\
f927c5ae 964If INITIAL-INPUT is non-nil, insert it in the minibuffer initially.\n\
770970cb
RS
965 If it is (STRING . POSITION), the initial input\n\
966 is STRING, but point is placed POSITION characters into the string.\n\
967HIST, 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\
975Completion ignores case if the ambient value of\n\
b9d721de
JB
976 `completion-ignore-case' is non-nil."
977*/
978DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 6, 0,
979 0 /* See immediately above */)
770970cb
RS
980 (prompt, table, pred, require_match, init, hist)
981 Lisp_Object prompt, table, pred, require_match, init, hist;
f927c5ae 982{
770970cb
RS
983 Lisp_Object val, histvar, histpos, position;
984 int pos = 0;
f927c5ae
JB
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;
770970cb
RS
991
992 position = Qnil;
993 if (!NILP (init))
994 {
7510b296 995 if (CONSP (init))
770970cb
RS
996 {
997 position = Fcdr (init);
998 init = Fcar (init);
999 }
1000 CHECK_STRING (init, 0);
1001 if (!NILP (position))
1002 {
1003 CHECK_NUMBER (position, 0);
1004 /* Convert to distance from end of input. */
5dadd3a2 1005 pos = XINT (position) - XSTRING (init)->size;
770970cb
RS
1006 }
1007 }
1008
7510b296 1009 if (SYMBOLP (hist))
770970cb
RS
1010 {
1011 histvar = hist;
1012 histpos = Qnil;
1013 }
1014 else
1015 {
1016 histvar = Fcar_safe (hist);
1017 histpos = Fcdr_safe (hist);
1018 }
1019 if (NILP (histvar))
1020 histvar = Qminibuffer_history;
1021 if (NILP (histpos))
5a866662 1022 XSETFASTINT (histpos, 0);
770970cb 1023
56a98455 1024 val = read_minibuf (NILP (require_match)
f927c5ae
JB
1025 ? Vminibuffer_local_completion_map
1026 : Vminibuffer_local_must_match_map,
85b5fe07 1027 init, prompt, make_number (pos), 0,
770970cb 1028 histvar, histpos);
f927c5ae
JB
1029 return unbind_to (count, val);
1030}
1031\f
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
1036 messages. */
1037
1038temp_echo_area_glyphs (m)
1039 char *m;
1040{
f927c5ae
JB
1041 int osize = ZV;
1042 Lisp_Object oinhibit;
1043 oinhibit = Vinhibit_quit;
1044
896adf84
JB
1045 /* Clear out any old echo-area message to make way for our new thing. */
1046 message (0);
f927c5ae
JB
1047
1048 SET_PT (osize);
1049 insert_string (m);
1050 SET_PT (osize);
1051 Vinhibit_quit = Qt;
1052 Fsit_for (make_number (2), Qnil, Qnil);
a2dd849e 1053 del_range (PT, ZV);
56a98455 1054 if (!NILP (Vquit_flag))
f927c5ae
JB
1055 {
1056 Vquit_flag = Qnil;
ba71d84a 1057 Vunread_command_events = Fcons (make_number (quit_char), Qnil);
f927c5ae
JB
1058 }
1059 Vinhibit_quit = oinhibit;
1060}
1061
1062Lisp_Object Fminibuffer_completion_help ();
52b14ac0 1063Lisp_Object assoc_for_completion ();
5d2ca7ae
RS
1064/* A subroutine of Fintern_soft. */
1065extern Lisp_Object oblookup ();
1066
1067
1068/* Test whether TXT is an exact completion. */
1069Lisp_Object
1070test_completion (txt)
1071 Lisp_Object txt;
1072{
1073 Lisp_Object tem;
1074
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))
1079 {
1080 /* Bypass intern-soft as that loses for nil */
1081 tem = oblookup (Vminibuffer_completion_table,
1082 XSTRING (txt)->data, XSTRING (txt)->size);
44472c88 1083 if (!SYMBOLP (tem))
5d2ca7ae
RS
1084 return Qnil;
1085 else if (!NILP (Vminibuffer_completion_predicate))
1086 return call1 (Vminibuffer_completion_predicate, tem);
1087 else
1088 return Qt;
1089 }
1090 else
1091 return call3 (Vminibuffer_completion_table, txt,
1092 Vminibuffer_completion_predicate, Qlambda);
1093}
f927c5ae
JB
1094
1095/* returns:
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
1102 */
1103int
1104do_completion ()
1105{
1106 Lisp_Object completion, tem;
1107 int completedp;
1108 Lisp_Object last;
1e00c2ff 1109 struct gcpro gcpro1, gcpro2;
f927c5ae
JB
1110
1111 completion = Ftry_completion (Fbuffer_string (), Vminibuffer_completion_table,
1112 Vminibuffer_completion_predicate);
1113 last = last_exact_completion;
1114 last_exact_completion = Qnil;
1115
4f9b95e5
KH
1116 GCPRO2 (completion, last);
1117
56a98455 1118 if (NILP (completion))
f927c5ae
JB
1119 {
1120 bitch_at_user ();
1121 temp_echo_area_glyphs (" [No match]");
1e00c2ff 1122 UNGCPRO;
f927c5ae
JB
1123 return 0;
1124 }
1125
1126 if (EQ (completion, Qt)) /* exact and unique match */
1e00c2ff
KH
1127 {
1128 UNGCPRO;
1129 return 1;
1130 }
f927c5ae
JB
1131
1132 /* compiler bug */
1133 tem = Fstring_equal (completion, Fbuffer_string());
56a98455 1134 if (completedp = NILP (tem))
f927c5ae
JB
1135 {
1136 Ferase_buffer (); /* Some completion happened */
1137 Finsert (1, &completion);
1138 }
1139
1140 /* It did find a match. Do we match some possibility exactly now? */
5d2ca7ae 1141 tem = test_completion (Fbuffer_string ());
56a98455 1142 if (NILP (tem))
1e00c2ff
KH
1143 {
1144 /* not an exact match */
1145 UNGCPRO;
f927c5ae
JB
1146 if (completedp)
1147 return 5;
1148 else if (auto_help)
1149 Fminibuffer_completion_help ();
1150 else
1151 temp_echo_area_glyphs (" [Next char not unique]");
1152 return 6;
1153 }
1154 else if (completedp)
1e00c2ff
KH
1155 {
1156 UNGCPRO;
1157 return 4;
1158 }
f927c5ae
JB
1159 /* If the last exact completion and this one were the same,
1160 it means we've already given a "Complete but not unique"
52b14ac0 1161 message and the user's hit TAB again, so now we give him help. */
f927c5ae 1162 last_exact_completion = completion;
56a98455 1163 if (!NILP (last))
f927c5ae
JB
1164 {
1165 tem = Fbuffer_string ();
56a98455 1166 if (!NILP (Fequal (tem, last)))
f927c5ae
JB
1167 Fminibuffer_completion_help ();
1168 }
1e00c2ff 1169 UNGCPRO;
f927c5ae 1170 return 3;
f927c5ae 1171}
1e00c2ff 1172
52b14ac0
JB
1173/* Like assoc but assumes KEY is a string, and ignores case if appropriate. */
1174
1175Lisp_Object
1176assoc_for_completion (key, list)
1177 register Lisp_Object key;
1178 Lisp_Object list;
1179{
1180 register Lisp_Object tail;
1181
1182 if (completion_ignore_case)
1183 key = Fupcase (key);
1184
56a98455 1185 for (tail = list; !NILP (tail); tail = Fcdr (tail))
52b14ac0
JB
1186 {
1187 register Lisp_Object elt, tem, thiscar;
1188 elt = Fcar (tail);
1189 if (!CONSP (elt)) continue;
1190 thiscar = Fcar (elt);
7510b296 1191 if (!STRINGP (thiscar))
52b14ac0
JB
1192 continue;
1193 if (completion_ignore_case)
1194 thiscar = Fupcase (thiscar);
1195 tem = Fequal (thiscar, key);
56a98455 1196 if (!NILP (tem)) return elt;
52b14ac0
JB
1197 QUIT;
1198 }
1199 return Qnil;
1200}
f927c5ae
JB
1201
1202DEFUN ("minibuffer-complete", Fminibuffer_complete, Sminibuffer_complete, 0, 0, "",
6300d782 1203 "Complete the minibuffer contents as far as possible.\n\
2cb6da5c
RS
1204Return nil if there is no valid completion, else t.\n\
1205If no characters can be completed, display a list of possible completions.\n\
1206If you repeat this command after it displayed such a list,\n\
1207scroll the window of possible completions.")
f927c5ae
JB
1208 ()
1209{
2cb6da5c
RS
1210 register int i;
1211 Lisp_Object window, tem;
1212
1213 /* If the previous command was not this, then mark the completion
1214 buffer obsolete. */
1215 if (! EQ (last_command, this_command))
1216 Vminibuf_scroll_window = Qnil;
1217
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))
1223 {
1224 struct buffer *obuf = current_buffer;
1225
1226 Fset_buffer (XWINDOW (window)->buffer);
1227 tem = Fpos_visible_in_window_p (make_number (ZV), window);
1228 if (! NILP (tem))
1229 /* If end is in view, scroll up to the beginning. */
8768d630 1230 Fset_window_start (window, BEGV, Qnil);
2cb6da5c
RS
1231 else
1232 /* Else scroll down one screen. */
1233 Fscroll_other_window (Qnil);
1234
1235 set_buffer_internal (obuf);
1236 return Qnil;
1237 }
1238
1239 i = do_completion ();
f927c5ae
JB
1240 switch (i)
1241 {
1242 case 0:
1243 return Qnil;
1244
1245 case 1:
1246 temp_echo_area_glyphs (" [Sole completion]");
1247 break;
1248
1249 case 3:
1250 temp_echo_area_glyphs (" [Complete, but not unique]");
1251 break;
1252 }
1253
1254 return Qt;
1255}
e4c97a67
RS
1256\f
1257/* Subroutines of Fminibuffer_complete_and_exit. */
1258
1259/* This one is called by internal_condition_case to do the real work. */
1260
1261Lisp_Object
1262complete_and_exit_1 ()
1263{
1264 return make_number (do_completion ());
1265}
1266
1267/* This one is called by internal_condition_case if an error happens.
1268 Pretend the current value is an exact match. */
1269
1270Lisp_Object
1271complete_and_exit_2 (ignore)
1272 Lisp_Object ignore;
1273{
1274 return make_number (1);
1275}
f927c5ae
JB
1276
1277DEFUN ("minibuffer-complete-and-exit", Fminibuffer_complete_and_exit,
1278 Sminibuffer_complete_and_exit, 0, 0, "",
5d2ca7ae
RS
1279 "If the minibuffer contents is a valid completion then exit.\n\
1280Otherwise try to complete it. If completion leads to a valid completion,\n\
f927c5ae
JB
1281a repetition of this command will exit.")
1282 ()
1283{
1284 register int i;
e4c97a67 1285 Lisp_Object val;
f927c5ae
JB
1286
1287 /* Allow user to specify null string */
1288 if (BEGV == ZV)
1289 goto exit;
1290
5d2ca7ae
RS
1291 if (!NILP (test_completion (Fbuffer_string ())))
1292 goto exit;
1293
e4c97a67
RS
1294 /* Call do_completion, but ignore errors. */
1295 val = internal_condition_case (complete_and_exit_1, Qerror,
1296 complete_and_exit_2);
1297
1298 i = XFASTINT (val);
f927c5ae
JB
1299 switch (i)
1300 {
1301 case 1:
1302 case 3:
1303 goto exit;
1304
1305 case 4:
56a98455 1306 if (!NILP (Vminibuffer_completion_confirm))
f927c5ae
JB
1307 {
1308 temp_echo_area_glyphs (" [Confirm]");
1309 return Qnil;
1310 }
1311 else
1312 goto exit;
1313
1314 default:
1315 return Qnil;
1316 }
1317 exit:
1318 Fthrow (Qexit, Qnil);
1319 /* NOTREACHED */
1320}
1321
1322DEFUN ("minibuffer-complete-word", Fminibuffer_complete_word, Sminibuffer_complete_word,
1323 0, 0, "",
1324 "Complete the minibuffer contents at most a single word.\n\
1325After one word is completed as much as possible, a space or hyphen\n\
6300d782
KH
1326is added, provided that matches some possible completion.\n\
1327Return nil if there is no valid completion, else t.")
f927c5ae
JB
1328 ()
1329{
1330 Lisp_Object completion, tem;
1331 register int i;
1332 register unsigned char *completion_string;
d7be4211 1333 struct gcpro gcpro1, gcpro2;
b278606c
BF
1334
1335 /* We keep calling Fbuffer_string rather than arrange for GC to
1336 hold onto a pointer to one of the strings thus made. */
f927c5ae
JB
1337
1338 completion = Ftry_completion (Fbuffer_string (),
1339 Vminibuffer_completion_table,
1340 Vminibuffer_completion_predicate);
56a98455 1341 if (NILP (completion))
f927c5ae
JB
1342 {
1343 bitch_at_user ();
1344 temp_echo_area_glyphs (" [No match]");
1345 return Qnil;
1346 }
1347 if (EQ (completion, Qt))
1348 return Qnil;
1349
b278606c 1350#if 0 /* How the below code used to look, for reference. */
f927c5ae
JB
1351 tem = Fbuffer_string ();
1352 b = XSTRING (tem)->data;
1353 i = ZV - 1 - XSTRING (completion)->size;
1354 p = XSTRING (completion)->data;
1355 if (i > 0 ||
1356 0 <= scmp (b, p, ZV - 1))
1357 {
1358 i = 1;
1359 /* Set buffer to longest match of buffer tail and completion head. */
1360 while (0 <= scmp (b + i, p, ZV - 1 - i))
1361 i++;
1362 del_range (1, i + 1);
1363 SET_PT (ZV);
1364 }
1365#else /* Rewritten code */
1366 {
1367 register unsigned char *buffer_string;
1368 int buffer_length, completion_length;
1369
1370 tem = Fbuffer_string ();
d7be4211 1371 GCPRO2 (completion, tem);
719b4a40
RS
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))
1375 {
1376 Lisp_Object substituted;
1377 substituted = Fsubstitute_in_file_name (tem);
1378 if (! EQ (substituted, tem))
1379 {
1380 tem = substituted;
1381 Ferase_buffer ();
3cab9ae4 1382 insert_from_string (tem, 0, XSTRING (tem)->size, 0);
719b4a40
RS
1383 }
1384 }
f927c5ae
JB
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 */
1391 if (i > 0 ||
1392 0 <= scmp (buffer_string, completion_string, buffer_length))
1393 {
1394 /* Set buffer to longest match of buffer tail and completion head. */
1395 if (i <= 0) i = 1;
1396 buffer_string += i;
1397 buffer_length -= i;
1398 while (0 <= scmp (buffer_string++, completion_string, buffer_length--))
1399 i++;
1400 del_range (1, i + 1);
1401 SET_PT (ZV);
1402 }
d7be4211 1403 UNGCPRO;
f927c5ae
JB
1404 }
1405#endif /* Rewritten code */
1406 i = ZV - BEGV;
1407
1408 /* If completion finds next char not unique,
b278606c 1409 consider adding a space or a hyphen. */
f927c5ae
JB
1410 if (i == XSTRING (completion)->size)
1411 {
b278606c 1412 GCPRO1 (completion);
f927c5ae
JB
1413 tem = Ftry_completion (concat2 (Fbuffer_string (), build_string (" ")),
1414 Vminibuffer_completion_table,
1415 Vminibuffer_completion_predicate);
b278606c
BF
1416 UNGCPRO;
1417
7510b296 1418 if (STRINGP (tem))
f927c5ae
JB
1419 completion = tem;
1420 else
1421 {
b278606c
BF
1422 GCPRO1 (completion);
1423 tem =
1424 Ftry_completion (concat2 (Fbuffer_string (), build_string ("-")),
1425 Vminibuffer_completion_table,
1426 Vminibuffer_completion_predicate);
1427 UNGCPRO;
1428
7510b296 1429 if (STRINGP (tem))
f927c5ae
JB
1430 completion = tem;
1431 }
1432 }
1433
1434 /* Now find first word-break in the stuff found by completion.
1435 i gets index in string of where to stop completing. */
b278606c 1436
f927c5ae
JB
1437 completion_string = XSTRING (completion)->data;
1438
1439 for (; i < XSTRING (completion)->size; i++)
1440 if (SYNTAX (completion_string[i]) != Sword) break;
1441 if (i < XSTRING (completion)->size)
1442 i = i + 1;
1443
1444 /* If got no characters, print help for user. */
1445
1446 if (i == ZV - BEGV)
1447 {
1448 if (auto_help)
1449 Fminibuffer_completion_help ();
1450 return Qnil;
1451 }
1452
1453 /* Otherwise insert in minibuffer the chars we got */
1454
1455 Ferase_buffer ();
3cab9ae4 1456 insert_from_string (completion, 0, i, 1);
f927c5ae
JB
1457 return Qt;
1458}
1459\f
1460DEFUN ("display-completion-list", Fdisplay_completion_list, Sdisplay_completion_list,
1461 1, 1, 0,
2dc2b736 1462 "Display the list of completions, COMPLETIONS, using `standard-output'.\n\
f927c5ae 1463Each element may be just a symbol or string\n\
2d7e41fe
RS
1464or may be a list of two strings to be printed as if concatenated.\n\
1465`standard-output' must be a buffer.\n\
1466At the end, run the normal hook `completion-setup-hook'.\n\
1467It can find the completion buffer in `standard-output'.")
f927c5ae
JB
1468 (completions)
1469 Lisp_Object completions;
1470{
1471 register Lisp_Object tail, elt;
1472 register int i;
2dc2b736 1473 int column = 0;
486cc7fb 1474 struct gcpro gcpro1;
2dc2b736 1475 struct buffer *old = current_buffer;
681f5af4 1476 int first = 1;
486cc7fb
RS
1477
1478 /* Note that (when it matters) every variable
1479 points to a non-string that is pointed to by COMPLETIONS. */
1480 GCPRO1 (completions);
1481
7510b296 1482 if (BUFFERP (Vstandard_output))
2dc2b736 1483 set_buffer_internal (XBUFFER (Vstandard_output));
f927c5ae 1484
56a98455 1485 if (NILP (completions))
cfc736bf
RS
1486 write_string ("There are no possible completions of what you have typed.",
1487 -1);
f927c5ae
JB
1488 else
1489 {
2dc2b736 1490 write_string ("Possible completions are:", -1);
56a98455 1491 for (tail = completions, i = 0; !NILP (tail); tail = Fcdr (tail), i++)
f927c5ae 1492 {
681f5af4
RS
1493 Lisp_Object tem;
1494 int length;
1495
1496 elt = Fcar (tail);
1497 /* Compute the length of this element. */
1498 if (CONSP (elt))
1499 {
1500 tem = Fcar (elt);
1501 CHECK_STRING (tem, 0);
1502 length = XINT (XSTRING (tem)->size);
1503
1504 tem = Fcar (Fcdr (elt));
1505 CHECK_STRING (tem, 0);
1506 length += XINT (XSTRING (tem)->size);
1507 }
1508 else
1509 {
1510 CHECK_STRING (elt, 0);
1511 length = XINT (XSTRING (elt)->size);
1512 }
1513
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. */
1517
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)
1524 {
1525 Fterpri (Qnil);
1526 column = 0;
1527 }
1528 /* Otherwise advance to column 35. */
1529 else
2dc2b736 1530 {
7510b296 1531 if (BUFFERP (Vstandard_output))
681f5af4
RS
1532 {
1533 tem = Findent_to (make_number (35), make_number (2));
1534 column = XINT (tem);
1535 }
2dc2b736
RS
1536 else
1537 {
1538 do
1539 {
1540 write_string (" ", -1);
1541 column++;
1542 }
1543 while (column < 35);
1544 }
1545 }
681f5af4
RS
1546
1547 /* Output this element and update COLUMN. */
f927c5ae
JB
1548 if (CONSP (elt))
1549 {
1550 Fprinc (Fcar (elt), Qnil);
1551 Fprinc (Fcar (Fcdr (elt)), Qnil);
1552 }
1553 else
681f5af4
RS
1554 Fprinc (elt, Qnil);
1555
1556 column += length;
1557
1558 /* If output is to a buffer, recompute COLUMN in a way
1559 that takes account of character widths. */
1560 if (BUFFERP (Vstandard_output))
2dc2b736 1561 {
681f5af4
RS
1562 tem = Fcurrent_column ();
1563 column = XINT (tem);
2dc2b736 1564 }
681f5af4
RS
1565
1566 first = 0;
f927c5ae
JB
1567 }
1568 }
2dc2b736 1569
486cc7fb
RS
1570 UNGCPRO;
1571
7510b296 1572 if (BUFFERP (Vstandard_output))
2d7e41fe
RS
1573 set_buffer_internal (old);
1574
cfc736bf
RS
1575 if (!NILP (Vrun_hooks))
1576 call1 (Vrun_hooks, intern ("completion-setup-hook"));
1577
f927c5ae
JB
1578 return Qnil;
1579}
1580
1581DEFUN ("minibuffer-completion-help", Fminibuffer_completion_help, Sminibuffer_completion_help,
1582 0, 0, "",
1583 "Display a list of possible completions of the current minibuffer contents.")
1584 ()
1585{
1586 Lisp_Object completions;
1587
1588 message ("Making completion list...");
1589 completions = Fall_completions (Fbuffer_string (),
1590 Vminibuffer_completion_table,
89a255dc
RS
1591 Vminibuffer_completion_predicate,
1592 Qt);
f927c5ae
JB
1593 echo_area_glyphs = 0;
1594
56a98455 1595 if (NILP (completions))
f927c5ae
JB
1596 {
1597 bitch_at_user ();
1598 temp_echo_area_glyphs (" [No completions]");
1599 }
1600 else
1601 internal_with_output_to_temp_buffer ("*Completions*",
1602 Fdisplay_completion_list,
1603 Fsort (completions, Qstring_lessp));
1604 return Qnil;
1605}
1606\f
1607DEFUN ("self-insert-and-exit", Fself_insert_and_exit, Sself_insert_and_exit, 0, 0, "",
1608 "Terminate minibuffer input.")
1609 ()
1610{
7510b296 1611 if (INTEGERP (last_command_char))
f927c5ae
JB
1612 internal_self_insert (last_command_char, 0);
1613 else
1614 bitch_at_user ();
1615
1616 Fthrow (Qexit, Qnil);
1617}
1618
1619DEFUN ("exit-minibuffer", Fexit_minibuffer, Sexit_minibuffer, 0, 0, "",
1620 "Terminate this minibuffer argument.")
1621 ()
1622{
1623 Fthrow (Qexit, Qnil);
1624}
1625
1626DEFUN ("minibuffer-depth", Fminibuffer_depth, Sminibuffer_depth, 0, 0, 0,
1627 "Return current depth of activations of minibuffer, a nonnegative integer.")
1628 ()
1629{
1630 return make_number (minibuf_level);
1631}
1632
37e9a934
KH
1633DEFUN ("minibuffer-prompt", Fminibuffer_prompt, Sminibuffer_prompt, 0, 0, 0,
1634 "Return the prompt string of the currently-active minibuffer.\n\
1635If no minibuffer is active, return nil.")
1636 ()
1637{
4d04c1f1 1638 return Fcopy_sequence (minibuf_prompt);
37e9a934
KH
1639}
1640
1641DEFUN ("minibuffer-prompt-width", Fminibuffer_prompt_width,
1642 Sminibuffer_prompt_width, 0, 0, 0,
c5896ef4 1643 "Return the display width of the minibuffer prompt.")
37e9a934
KH
1644 ()
1645{
1646 Lisp_Object width;
5a866662 1647 XSETFASTINT (width, minibuf_prompt_width);
37e9a934
KH
1648 return width;
1649}
f927c5ae
JB
1650\f
1651init_minibuf_once ()
1652{
1653 Vminibuffer_list = Qnil;
1654 staticpro (&Vminibuffer_list);
1655}
1656
1657syms_of_minibuf ()
1658{
1659 minibuf_level = 0;
4d04c1f1
KH
1660 minibuf_prompt = Qnil;
1661 staticpro (&minibuf_prompt);
1662
1663 minibuf_save_list = Qnil;
1664 staticpro (&minibuf_save_list);
f927c5ae 1665
719b4a40
RS
1666 Qread_file_name_internal = intern ("read-file-name-internal");
1667 staticpro (&Qread_file_name_internal);
1668
f927c5ae
JB
1669 Qminibuffer_completion_table = intern ("minibuffer-completion-table");
1670 staticpro (&Qminibuffer_completion_table);
1671
1672 Qminibuffer_completion_confirm = intern ("minibuffer-completion-confirm");
1673 staticpro (&Qminibuffer_completion_confirm);
1674
1675 Qminibuffer_completion_predicate = intern ("minibuffer-completion-predicate");
1676 staticpro (&Qminibuffer_completion_predicate);
1677
1e00c2ff
KH
1678 staticpro (&last_exact_completion);
1679 last_exact_completion = Qnil;
1680
f927c5ae
JB
1681 staticpro (&last_minibuf_string);
1682 last_minibuf_string = Qnil;
1683
1684 Quser_variable_p = intern ("user-variable-p");
1685 staticpro (&Quser_variable_p);
1686
770970cb
RS
1687 Qminibuffer_history = intern ("minibuffer-history");
1688 staticpro (&Qminibuffer_history);
f927c5ae 1689
5c781212
RS
1690 Qminibuffer_setup_hook = intern ("minibuffer-setup-hook");
1691 staticpro (&Qminibuffer_setup_hook);
1692
177aecf9
KH
1693 Qminibuffer_exit_hook = intern ("minibuffer-exit-hook");
1694 staticpro (&Qminibuffer_exit_hook);
1695
5c781212
RS
1696 DEFVAR_LISP ("minibuffer-setup-hook", &Vminibuffer_setup_hook,
1697 "Normal hook run just after entry to minibuffer.");
1698 Vminibuffer_setup_hook = Qnil;
1699
177aecf9
KH
1700 DEFVAR_LISP ("minibuffer-exit-hook", &Vminibuffer_exit_hook,
1701 "Normal hook run just after exit from minibuffer.");
1702 Vminibuffer_exit_hook = Qnil;
1703
f927c5ae
JB
1704 DEFVAR_BOOL ("completion-auto-help", &auto_help,
1705 "*Non-nil means automatically provide help for invalid completion input.");
1706 auto_help = 1;
1707
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;
1711
1712 DEFVAR_BOOL ("enable-recursive-minibuffers", &enable_recursive_minibuffers,
1713 "*Non-nil means to allow minibuffer commands while in the minibuffer.\n\
1714More precisely, this variable makes a difference when the minibuffer window\n\
1715is the selected window. If you are in some other window, minibuffer commands\n\
1716are allowed even if a minibuffer is active.");
1717 enable_recursive_minibuffers = 0;
1718
1719 DEFVAR_LISP ("minibuffer-completion-table", &Vminibuffer_completion_table,
1720 "Alist or obarray used for completion in the minibuffer.\n\
1721This becomes the ALIST argument to `try-completion' and `all-completion'.\n\
1722\n\
1723The 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\
1727CODE can be nil, t or `lambda'.\n\
1728nil means to return the best completion of STRING, or nil if there is none.\n\
1729t 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;
1732
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;
1736
1737 DEFVAR_LISP ("minibuffer-completion-confirm", &Vminibuffer_completion_confirm,
1738 "Non-nil => demand confirmation of completion before exiting minibuffer.");
1739 Vminibuffer_completion_confirm = Qnil;
1740
1741 DEFVAR_LISP ("minibuffer-help-form", &Vminibuffer_help_form,
1742 "Value that `help-form' takes on inside the minibuffer.");
1743 Vminibuffer_help_form = Qnil;
1744
770970cb
RS
1745 DEFVAR_LISP ("minibuffer-history-variable", &Vminibuffer_history_variable,
1746 "History list symbol to add minibuffer values to.\n\
1747Each minibuffer output is added with\n\
1748 (set minibuffer-history-variable\n\
1749 (cons STRING (symbol-value minibuffer-history-variable)))");
5a866662 1750 XSETFASTINT (Vminibuffer_history_variable, 0);
770970cb
RS
1751
1752 DEFVAR_LISP ("minibuffer-history-position", &Vminibuffer_history_position,
1753 "Current position of redoing in the history list.");
1754 Vminibuffer_history_position = Qnil;
1755
6a9ee000
RS
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;
1759
42006772
RS
1760 DEFVAR_LISP ("completion-regexp-list", &Vcompletion_regexp_list,
1761 "List of regexps that should restrict possible completions.");
1762 Vcompletion_regexp_list = Qnil;
1763
f927c5ae
JB
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);
37e9a934
KH
1773 defsubr (&Sminibuffer_prompt);
1774 defsubr (&Sminibuffer_prompt_width);
f927c5ae
JB
1775
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);
1784
1785 defsubr (&Sself_insert_and_exit);
1786 defsubr (&Sexit_minibuffer);
1787
1788}
1789
1790keys_of_minibuf ()
1791{
1792 initial_define_key (Vminibuffer_local_map, Ctl ('g'),
1793 "abort-recursive-edit");
1794 initial_define_key (Vminibuffer_local_map, Ctl ('m'),
1795 "exit-minibuffer");
1796 initial_define_key (Vminibuffer_local_map, Ctl ('j'),
1797 "exit-minibuffer");
1798
1799 initial_define_key (Vminibuffer_local_ns_map, Ctl ('g'),
1800 "abort-recursive-edit");
1801 initial_define_key (Vminibuffer_local_ns_map, Ctl ('m'),
1802 "exit-minibuffer");
1803 initial_define_key (Vminibuffer_local_ns_map, Ctl ('j'),
1804 "exit-minibuffer");
1805
1806 initial_define_key (Vminibuffer_local_ns_map, ' ',
1807 "exit-minibuffer");
1808 initial_define_key (Vminibuffer_local_ns_map, '\t',
1809 "exit-minibuffer");
1810 initial_define_key (Vminibuffer_local_ns_map, '?',
1811 "self-insert-and-exit");
1812
1813 initial_define_key (Vminibuffer_local_completion_map, Ctl ('g'),
1814 "abort-recursive-edit");
1815 initial_define_key (Vminibuffer_local_completion_map, Ctl ('m'),
1816 "exit-minibuffer");
1817 initial_define_key (Vminibuffer_local_completion_map, Ctl ('j'),
1818 "exit-minibuffer");
1819
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");
1826
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");
1839}