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