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