(HAVE_PNG): New.
[bpt/emacs.git] / src / minibuf.c
CommitLineData
f927c5ae 1/* Minibuffer input and completion.
4a2f9c6a 2 Copyright (C) 1985, 1986, 1993, 1994, 1995, 1996, 1997, 1998
6801b300 3 Free Software Foundation, Inc.
f927c5ae
JB
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
ffd56f97 9the Free Software Foundation; either version 2, or (at your option)
f927c5ae
JB
10any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs; see the file COPYING. If not, write to
3b7ad313
EN
19the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
f927c5ae
JB
21
22
18160b98 23#include <config.h>
f927c5ae
JB
24#include "lisp.h"
25#include "commands.h"
26#include "buffer.h"
d50a3d2a 27#include "charset.h"
f927c5ae 28#include "dispextern.h"
ff11dfa1 29#include "frame.h"
f927c5ae
JB
30#include "window.h"
31#include "syntax.h"
5221fd63 32#include "keyboard.h"
f927c5ae
JB
33
34#define min(a, b) ((a) < (b) ? (a) : (b))
35
a4e71d81
KH
36extern int quit_char;
37
f927c5ae 38/* List of buffers for use as minibuffers.
4d04c1f1
KH
39 The first element of the list is used for the outermost minibuffer
40 invocation, the next element is used for a recursive minibuffer
41 invocation, etc. The list is extended at the end as deeper
42 minibuffer recursions are encountered. */
f927c5ae
JB
43Lisp_Object Vminibuffer_list;
44
4d04c1f1
KH
45/* Data to remember during recursive minibuffer invocations */
46Lisp_Object minibuf_save_list;
f927c5ae
JB
47
48/* Depth in minibuffer invocations. */
49int minibuf_level;
50
77aa8edf 51/* Nonzero means display completion help for invalid input. */
f927c5ae
JB
52int auto_help;
53
77aa8edf
RS
54/* The maximum length of a minibuffer history. */
55Lisp_Object Qhistory_length, Vhistory_length;
56
b278606c 57/* Fread_minibuffer leaves the input here as a string. */
f927c5ae
JB
58Lisp_Object last_minibuf_string;
59
60/* Nonzero means let functions called when within a minibuffer
61 invoke recursive minibuffers (to read arguments, or whatever) */
62int enable_recursive_minibuffers;
63
c3421833
RS
64/* Nonzero means don't ignore text properties
65 in Fread_from_minibuffer. */
66int minibuffer_allow_text_properties;
67
f927c5ae
JB
68/* help-form is bound to this while in the minibuffer. */
69
70Lisp_Object Vminibuffer_help_form;
71
770970cb
RS
72/* Variable which is the history list to add minibuffer values to. */
73
74Lisp_Object Vminibuffer_history_variable;
75
76/* Current position in the history list (adjusted by M-n and M-p). */
77
78Lisp_Object Vminibuffer_history_position;
79
406e55df 80Lisp_Object Qminibuffer_history, Qbuffer_name_history;
770970cb 81
719b4a40
RS
82Lisp_Object Qread_file_name_internal;
83
177aecf9 84/* Normal hooks for entry to and exit from minibuffer. */
5c781212
RS
85
86Lisp_Object Qminibuffer_setup_hook, Vminibuffer_setup_hook;
177aecf9 87Lisp_Object Qminibuffer_exit_hook, Vminibuffer_exit_hook;
5c781212 88
eebbfb01
KH
89/* Function to call to read a buffer name. */
90Lisp_Object Vread_buffer_function;
91
f927c5ae
JB
92/* Nonzero means completion ignores case. */
93
94int completion_ignore_case;
95
42006772
RS
96/* List of regexps that should restrict possible completions. */
97
98Lisp_Object Vcompletion_regexp_list;
99
6a9ee000
RS
100/* Nonzero means raise the minibuffer frame when the minibuffer
101 is entered. */
102
103int minibuffer_auto_raise;
104
f927c5ae
JB
105/* If last completion attempt reported "Complete but not unique"
106 then this is the string completed then; otherwise this is nil. */
107
108static Lisp_Object last_exact_completion;
109
2cb6da5c
RS
110/* Non-nil means it is the window for C-M-v to scroll
111 when the minibuffer is selected. */
112extern Lisp_Object Vminibuf_scroll_window;
30e13e56
RS
113
114extern Lisp_Object Voverriding_local_map;
cee54539 115
5744fa7c
RS
116Lisp_Object Quser_variable_p;
117
118Lisp_Object Qminibuffer_default;
119
cee54539
KH
120Lisp_Object Qcurrent_input_method, Qactivate_input_method;
121
5744fa7c 122extern Lisp_Object Qmouse_face;
f927c5ae 123\f
89fdc4a0
KH
124/* Put minibuf on currently selected frame's minibuffer.
125 We do this whenever the user starts a new minibuffer
126 or when a minibuffer exits. */
127
128void
129choose_minibuf_frame ()
130{
131 if (selected_frame != 0
132 && !EQ (minibuf_window, selected_frame->minibuffer_window))
133 {
134 /* I don't think that any frames may validly have a null minibuffer
135 window anymore. */
136 if (NILP (selected_frame->minibuffer_window))
137 abort ();
138
139 Fset_window_buffer (selected_frame->minibuffer_window,
140 XWINDOW (minibuf_window)->buffer);
141 minibuf_window = selected_frame->minibuffer_window;
142 }
914860c2
RS
143
144 /* Make sure no other frame has a minibuffer as its selected window,
145 because the text would not be displayed in it, and that would be
07d402c8
RS
146 confusing. Only allow the selected frame to do this,
147 and that only if the minibuffer is active. */
914860c2
RS
148 {
149 Lisp_Object tail, frame;
150
151 FOR_EACH_FRAME (tail, frame)
07d402c8
RS
152 if (MINI_WINDOW_P (XWINDOW (FRAME_SELECTED_WINDOW (XFRAME (frame))))
153 && !(XFRAME (frame) == selected_frame
154 && minibuf_level > 0))
914860c2
RS
155 Fset_frame_selected_window (frame, Fframe_first_window (frame));
156 }
89fdc4a0 157}
68313ed8 158
0c94f256
RS
159Lisp_Object
160choose_minibuf_frame_1 (ignore)
161 Lisp_Object ignore;
162{
163 choose_minibuf_frame ();
164 return Qnil;
165}
166
68313ed8
RS
167DEFUN ("set-minibuffer-window", Fset_minibuffer_window,
168 Sset_minibuffer_window, 1, 1, 0,
169 "Specify which minibuffer window to use for the minibuffer.\n\
170This effects where the minibuffer is displayed if you put text in it\n\
171without invoking the usual minibuffer commands.")
172 (window)
173 Lisp_Object window;
174{
175 CHECK_WINDOW (window, 1);
176 if (! MINI_WINDOW_P (XWINDOW (window)))
177 error ("Window is not a minibuffer window");
178
179 minibuf_window = window;
180
181 return window;
182}
183
89fdc4a0 184\f
f927c5ae
JB
185/* Actual minibuffer invocation. */
186
af2b7cd5
RS
187static Lisp_Object read_minibuf_unwind P_ ((Lisp_Object));
188static Lisp_Object read_minibuf P_ ((Lisp_Object, Lisp_Object,
189 Lisp_Object, Lisp_Object,
190 int, Lisp_Object,
191 Lisp_Object, Lisp_Object,
192 int, int));
f927c5ae 193
770970cb 194/* Read from the minibuffer using keymap MAP, initial contents INITIAL
a9c26562 195 (a string), putting point minus BACKUP_N bytes from the end of INITIAL,
770970cb 196 prompting with PROMPT (a string), using history list HISTVAR
85b5fe07 197 with initial position HISTPOS. (BACKUP_N should be <= 0.)
770970cb
RS
198
199 Normally return the result as a string (the text that was read),
3ab14176 200 but if EXPFLAG is nonzero, read it and return the object read.
b278606c
BF
201 If HISTVAR is given, save the value read on that history only if it doesn't
202 match the front of that history list exactly. The value is pushed onto
e5d4686b 203 the list as the string that was read.
770970cb 204
c3421833
RS
205 DEFALT specifies te default value for the sake of history commands.
206
cee54539
KH
207 If ALLOW_PROPS is nonzero, we do not throw away text properties.
208
209 if INHERIT_INPUT_METHOD is nonzeor, the minibuffer inherit the
210 current input method. */
e5d4686b
RS
211
212static Lisp_Object
213read_minibuf (map, initial, prompt, backup_n, expflag,
cee54539 214 histvar, histpos, defalt, allow_props, inherit_input_method)
f927c5ae
JB
215 Lisp_Object map;
216 Lisp_Object initial;
217 Lisp_Object prompt;
5061d9c3 218 Lisp_Object backup_n;
f927c5ae 219 int expflag;
770970cb
RS
220 Lisp_Object histvar;
221 Lisp_Object histpos;
e5d4686b 222 Lisp_Object defalt;
af2b7cd5 223 int allow_props;
cee54539 224 int inherit_input_method;
f927c5ae 225{
00a34088 226 Lisp_Object val;
f927c5ae 227 int count = specpdl_ptr - specpdl;
cee54539
KH
228 Lisp_Object mini_frame, ambient_dir, minibuffer, input_method;
229 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
c75000c7 230 Lisp_Object enable_multibyte;
00a34088 231
e5d4686b
RS
232 specbind (Qminibuffer_default, defalt);
233
08f7d623 234 single_kboard_state ();
718d3251 235
00a34088 236 val = Qnil;
57ceaa8a 237 ambient_dir = current_buffer->directory;
cee54539 238 input_method = Qnil;
c75000c7 239 enable_multibyte = Qnil;
57ceaa8a 240
00a34088
RS
241 /* Don't need to protect PROMPT, HISTVAR, and HISTPOS because we
242 store them away before we can GC. Don't need to protect
243 BACKUP_N because we use the value only if it is an integer. */
cee54539 244 GCPRO5 (map, initial, val, ambient_dir, input_method);
f927c5ae 245
7510b296 246 if (!STRINGP (prompt))
f927c5ae
JB
247 prompt = build_string ("");
248
f927c5ae 249 if (!enable_recursive_minibuffers
be15a518
RS
250 && minibuf_level > 0)
251 {
252 if (EQ (selected_window, minibuf_window))
253 error ("Command attempted to use minibuffer while in minibuffer");
254 else
255 /* If we're in another window, cancel the minibuffer that's active. */
256 Fthrow (Qexit,
257 build_string ("Command attempted to use minibuffer while in minibuffer"));
258 }
f927c5ae 259
748dc60a 260 /* Choose the minibuffer window and frame, and take action on them. */
f927c5ae 261
c5b6b680
RS
262 choose_minibuf_frame ();
263
0c94f256
RS
264 record_unwind_protect (choose_minibuf_frame_1, Qnil);
265
f927c5ae 266 record_unwind_protect (Fset_window_configuration,
b2b2c677
JB
267 Fcurrent_window_configuration (Qnil));
268
ff11dfa1
JB
269 /* If the minibuffer window is on a different frame, save that
270 frame's configuration too. */
75f00e72 271 mini_frame = WINDOW_FRAME (XWINDOW (minibuf_window));
ff11dfa1 272 if (XFRAME (mini_frame) != selected_frame)
5061d9c3
RS
273 record_unwind_protect (Fset_window_configuration,
274 Fcurrent_window_configuration (mini_frame));
5563e8e8
KH
275
276 /* If the minibuffer is on an iconified or invisible frame,
277 make it visible now. */
278 Fmake_frame_visible (mini_frame);
279
6a9ee000
RS
280 if (minibuffer_auto_raise)
281 Fraise_frame (mini_frame);
f927c5ae 282
748dc60a
RS
283 /* We have to do this after saving the window configuration
284 since that is what restores the current buffer. */
285
286 /* Arrange to restore a number of minibuffer-related variables.
287 We could bind each variable separately, but that would use lots of
288 specpdl slots. */
289 minibuf_save_list
290 = Fcons (Voverriding_local_map,
291 Fcons (minibuf_window, minibuf_save_list));
292 minibuf_save_list
293 = Fcons (minibuf_prompt,
294 Fcons (make_number (minibuf_prompt_width),
295 Fcons (Vhelp_form,
296 Fcons (Vcurrent_prefix_arg,
297 Fcons (Vminibuffer_history_position,
298 Fcons (Vminibuffer_history_variable,
299 minibuf_save_list))))));
300
301 record_unwind_protect (read_minibuf_unwind, Qnil);
302 minibuf_level++;
303
304 /* Now that we can restore all those variables, start changing them. */
305
306 minibuf_prompt_width = 0; /* xdisp.c puts in the right value. */
307 minibuf_prompt = Fcopy_sequence (prompt);
308 Vminibuffer_history_position = histpos;
309 Vminibuffer_history_variable = histvar;
310 Vhelp_form = Vminibuffer_help_form;
311
cee54539 312 if (inherit_input_method)
c75000c7
RS
313 {
314 /* `current-input-method' is buffer local. So, remeber it in
315 INPUT_METHOD before changing the current buffer. */
316 input_method = Fsymbol_value (Qcurrent_input_method);
317 enable_multibyte = current_buffer->enable_multibyte_characters;
318 }
cee54539 319
748dc60a
RS
320 /* Switch to the minibuffer. */
321
4f69d8f6
RS
322 minibuffer = get_minibuffer (minibuf_level);
323 Fset_buffer (minibuffer);
64a3a3c0
JB
324
325 /* The current buffer's default directory is usually the right thing
326 for our minibuffer here. However, if you're typing a command at
327 a minibuffer-only frame when minibuf_level is zero, then buf IS
328 the current_buffer, so reset_buffer leaves buf's default
329 directory unchanged. This is a bummer when you've just started
330 up Emacs and buf's default directory is Qnil. Here's a hack; can
331 you think of something better to do? Find another buffer with a
332 better directory, and use that one instead. */
748dc60a
RS
333 if (STRINGP (ambient_dir))
334 current_buffer->directory = ambient_dir;
64a3a3c0
JB
335 else
336 {
337 Lisp_Object buf_list;
338
339 for (buf_list = Vbuffer_alist;
340 CONSP (buf_list);
341 buf_list = XCONS (buf_list)->cdr)
342 {
1e62748e 343 Lisp_Object other_buf;
64a3a3c0 344
1e62748e 345 other_buf = XCONS (XCONS (buf_list)->car)->cdr;
7510b296 346 if (STRINGP (XBUFFER (other_buf)->directory))
64a3a3c0
JB
347 {
348 current_buffer->directory = XBUFFER (other_buf)->directory;
349 break;
350 }
351 }
352 }
353
0abbff13
KH
354 if (XFRAME (mini_frame) != selected_frame)
355 Fredirect_frame_focus (Fselected_frame (), mini_frame);
43bad991 356
f927c5ae
JB
357 Vminibuf_scroll_window = selected_window;
358 Fset_window_buffer (minibuf_window, Fcurrent_buffer ());
f927c5ae 359 Fselect_window (minibuf_window);
5a866662 360 XSETFASTINT (XWINDOW (minibuf_window)->hscroll, 0);
f927c5ae 361
748dc60a
RS
362 Fmake_local_variable (Qprint_escape_newlines);
363 print_escape_newlines = 1;
364
365 /* Erase the buffer. */
59115a22
RS
366 {
367 int count1 = specpdl_ptr - specpdl;
368 specbind (Qinhibit_read_only, Qt);
369 Ferase_buffer ();
370 unbind_to (count1, Qnil);
371 }
372
094d9789
RS
373 /* If appropriate, copy enable-multibyte-characters into the minibuffer. */
374 if (inherit_input_method)
375 current_buffer->enable_multibyte_characters = enable_multibyte;
376
748dc60a 377 /* Put in the initial input. */
56a98455 378 if (!NILP (initial))
f927c5ae
JB
379 {
380 Finsert (1, &initial);
a9c26562
RS
381 if (INTEGERP (backup_n))
382 Fforward_char (backup_n);
f927c5ae
JB
383 }
384
f927c5ae 385 echo_area_glyphs = 0;
73168c8b
RS
386 /* This is in case the minibuffer-setup-hook calls Fsit_for. */
387 previous_echo_glyphs = 0;
f927c5ae 388
f927c5ae
JB
389 current_buffer->keymap = map;
390
cee54539 391 /* Turn on an input method stored in INPUT_METHOD if any. */
6801b300 392 if (STRINGP (input_method) && !NILP (Ffboundp (Qactivate_input_method)))
cee54539
KH
393 call1 (Qactivate_input_method, input_method);
394
9404446f
RS
395 if (!NILP (current_buffer->enable_multibyte_characters)
396 && ! STRING_MULTIBYTE (minibuf_prompt))
397 minibuf_prompt = Fstring_make_multibyte (minibuf_prompt);
398
5c781212
RS
399 /* Run our hook, but not if it is empty.
400 (run-hooks would do nothing if it is empty,
748dc60a 401 but it's important to save time here in the usual case). */
92d3b06e
RS
402 if (!NILP (Vminibuffer_setup_hook) && !EQ (Vminibuffer_setup_hook, Qunbound)
403 && !NILP (Vrun_hooks))
5c781212
RS
404 call1 (Vrun_hooks, Qminibuffer_setup_hook);
405
f927c5ae
JB
406 recursive_edit_1 ();
407
408 /* If cursor is on the minibuffer line,
409 show the user we have exited by putting it in column 0. */
ff11dfa1 410 if ((FRAME_CURSOR_Y (selected_frame)
f927c5ae
JB
411 >= XFASTINT (XWINDOW (minibuf_window)->top))
412 && !noninteractive)
413 {
85462999
RS
414 FRAME_CURSOR_X (selected_frame)
415 = FRAME_LEFT_SCROLL_BAR_WIDTH (selected_frame);
ff11dfa1 416 update_frame (selected_frame, 1, 1);
f927c5ae
JB
417 }
418
c3421833 419 /* Make minibuffer contents into a string. */
4f69d8f6 420 Fset_buffer (minibuffer);
c3421833 421 val = make_buffer_string (1, Z, allow_props);
770970cb 422
b278606c 423 /* VAL is the string of minibuffer text. */
7019cca7 424
b278606c
BF
425 last_minibuf_string = val;
426
3ab14176 427 /* Add the value to the appropriate history list unless it is empty. */
9f6131cf 428 if (XSTRING (val)->size != 0
c6d65724 429 && SYMBOLP (Vminibuffer_history_variable))
3ab14176
KH
430 {
431 /* If the caller wanted to save the value read on a history list,
432 then do so if the value is not already the front of the list. */
433 Lisp_Object histval;
c6d65724
RS
434
435 /* If variable is unbound, make it nil. */
436 if (EQ (XSYMBOL (Vminibuffer_history_variable)->value, Qunbound))
437 Fset (Vminibuffer_history_variable, Qnil);
438
3ab14176
KH
439 histval = Fsymbol_value (Vminibuffer_history_variable);
440
441 /* The value of the history variable must be a cons or nil. Other
442 values are unacceptable. We silently ignore these values. */
443 if (NILP (histval)
9f6131cf
RS
444 || (CONSP (histval)
445 && NILP (Fequal (last_minibuf_string, Fcar (histval)))))
77aa8edf
RS
446 {
447 Lisp_Object length;
448
449 histval = Fcons (last_minibuf_string, histval);
450 Fset (Vminibuffer_history_variable, histval);
451
452 /* Truncate if requested. */
453 length = Fget (Vminibuffer_history_variable, Qhistory_length);
454 if (NILP (length)) length = Vhistory_length;
e5d4686b
RS
455 if (INTEGERP (length))
456 {
457 if (XINT (length) <= 0)
458 Fset (Vminibuffer_history_variable, Qnil);
459 else
460 {
461 Lisp_Object temp;
462
463 temp = Fnthcdr (Fsub1 (length), histval);
464 if (CONSP (temp)) Fsetcdr (temp, Qnil);
465 }
466 }
77aa8edf 467 }
9f6131cf
RS
468 }
469
470 /* If Lisp form desired instead of string, parse it. */
471 if (expflag)
472 {
473 Lisp_Object expr_and_pos;
474 unsigned char *p;
82d6226f 475 int pos;
9f6131cf 476
c923ccc9
RS
477 if (STRINGP (val) && XSTRING (val)->size == 0
478 && STRINGP (defalt))
479 val = defalt;
480
9f6131cf 481 expr_and_pos = Fread_from_string (val, Qnil, Qnil);
82d6226f
RS
482 pos = XINT (Fcdr (expr_and_pos));
483 if (pos != XSTRING (val)->size)
484 {
485 /* Ignore trailing whitespace; any other trailing junk is an error. */
486 int i;
487 pos = string_char_to_byte (val, pos);
fc932ac6 488 for (i = pos; i < STRING_BYTES (XSTRING (val)); i++)
82d6226f
RS
489 {
490 int c = XSTRING (val)->data[i];
491 if (c != ' ' && c != '\t' && c != '\n')
492 error ("Trailing garbage following expression");
493 }
494 }
9f6131cf 495 val = Fcar (expr_and_pos);
3ab14176
KH
496 }
497
00a34088
RS
498 /* The appropriate frame will get selected
499 in set-window-configuration. */
500 RETURN_UNGCPRO (unbind_to (count, val));
f927c5ae
JB
501}
502
503/* Return a buffer to be used as the minibuffer at depth `depth'.
504 depth = 0 is the lowest allowed argument, and that is the value
505 used for nonrecursive minibuffer invocations */
506
507Lisp_Object
508get_minibuffer (depth)
509 int depth;
510{
511 Lisp_Object tail, num, buf;
9f6c23bc 512 char name[24];
f927c5ae
JB
513 extern Lisp_Object nconc2 ();
514
5a866662 515 XSETFASTINT (num, depth);
f927c5ae 516 tail = Fnthcdr (num, Vminibuffer_list);
56a98455 517 if (NILP (tail))
f927c5ae
JB
518 {
519 tail = Fcons (Qnil, Qnil);
520 Vminibuffer_list = nconc2 (Vminibuffer_list, tail);
521 }
522 buf = Fcar (tail);
56a98455 523 if (NILP (buf) || NILP (XBUFFER (buf)->name))
f927c5ae
JB
524 {
525 sprintf (name, " *Minibuf-%d*", depth);
526 buf = Fget_buffer_create (build_string (name));
5d6533f1
JB
527
528 /* Although the buffer's name starts with a space, undo should be
529 enabled in it. */
530 Fbuffer_enable_undo (buf);
531
f927c5ae
JB
532 XCONS (tail)->car = buf;
533 }
534 else
5956f71d 535 {
6b3faad8
RS
536 int count = specpdl_ptr - specpdl;
537
5956f71d 538 reset_buffer (XBUFFER (buf));
6b3faad8
RS
539 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
540 Fset_buffer (buf);
541 Fkill_all_local_variables ();
542 unbind_to (count, Qnil);
5956f71d 543 }
64a3a3c0 544
f927c5ae
JB
545 return buf;
546}
547
548/* This function is called on exiting minibuffer, whether normally or not,
549 and it restores the current window, buffer, etc. */
550
9d815fd9 551static Lisp_Object
43bad991
JB
552read_minibuf_unwind (data)
553 Lisp_Object data;
f927c5ae 554{
c24e1160 555 Lisp_Object old_deactivate_mark;
59115a22 556 Lisp_Object window;
c24e1160 557
0a1dd1c5
RS
558 /* We are exiting the minibuffer one way or the other,
559 so run the hook. */
560 if (!NILP (Vminibuffer_exit_hook) && !EQ (Vminibuffer_exit_hook, Qunbound)
561 && !NILP (Vrun_hooks))
060ffec1 562 safe_run_hooks (Qminibuffer_exit_hook);
0a1dd1c5 563
f927c5ae 564 /* If this was a recursive minibuffer,
59115a22 565 tie the minibuffer window back to the outer level minibuffer buffer. */
f927c5ae 566 minibuf_level--;
f927c5ae 567
59115a22
RS
568 window = minibuf_window;
569 /* To keep things predictable, in case it matters, let's be in the minibuffer
570 when we reset the relevant variables. */
571 Fset_buffer (XWINDOW (window)->buffer);
572
573 /* Restore prompt, etc, from outer minibuffer level. */
4d04c1f1
KH
574 minibuf_prompt = Fcar (minibuf_save_list);
575 minibuf_save_list = Fcdr (minibuf_save_list);
576 minibuf_prompt_width = XFASTINT (Fcar (minibuf_save_list));
577 minibuf_save_list = Fcdr (minibuf_save_list);
578 Vhelp_form = Fcar (minibuf_save_list);
579 minibuf_save_list = Fcdr (minibuf_save_list);
ee9e37ab 580 Vcurrent_prefix_arg = Fcar (minibuf_save_list);
4d04c1f1
KH
581 minibuf_save_list = Fcdr (minibuf_save_list);
582 Vminibuffer_history_position = Fcar (minibuf_save_list);
583 minibuf_save_list = Fcdr (minibuf_save_list);
584 Vminibuffer_history_variable = Fcar (minibuf_save_list);
585 minibuf_save_list = Fcdr (minibuf_save_list);
30e13e56 586 Voverriding_local_map = Fcar (minibuf_save_list);
c5b6b680 587 minibuf_save_list = Fcdr (minibuf_save_list);
914860c2
RS
588#if 0
589 temp = Fcar (minibuf_save_list);
590 if (FRAME_LIVE_P (XFRAME (WINDOW_FRAME (XWINDOW (temp)))))
591 minibuf_window = temp;
592#endif
30e13e56 593 minibuf_save_list = Fcdr (minibuf_save_list);
59115a22
RS
594
595 /* Erase the minibuffer we were using at this level. */
596 {
597 int count = specpdl_ptr - specpdl;
598 /* Prevent error in erase-buffer. */
599 specbind (Qinhibit_read_only, Qt);
600 old_deactivate_mark = Vdeactivate_mark;
601 Ferase_buffer ();
602 Vdeactivate_mark = old_deactivate_mark;
603 unbind_to (count, Qnil);
604 }
605
606 /* Make sure minibuffer window is erased, not ignored. */
607 windows_or_buffers_changed++;
608 XSETFASTINT (XWINDOW (window)->last_modified, 0);
193e4518 609 XSETFASTINT (XWINDOW (window)->last_overlay_modified, 0);
9d815fd9
AS
610
611 return Qnil;
f927c5ae
JB
612}
613\f
b9d721de
JB
614
615/* This comment supplies the doc string for read-from-minibuffer,
616 for make-docfile to see. We cannot put this in the real DEFUN
617 due to limits in the Unix cpp.
618
cee54539 619DEFUN ("read-from-minibuffer", Fread_from_minibuffer, Sread_from_minibuffer, 1, 7, 0,
f927c5ae
JB
620 "Read a string from the minibuffer, prompting with string PROMPT.\n\
621If optional second arg INITIAL-CONTENTS is non-nil, it is a string\n\
622 to be inserted into the minibuffer before reading input.\n\
770970cb 623 If INITIAL-CONTENTS is (STRING . POSITION), the initial input\n\
18fef111 624 is STRING, but point is placed at position POSITION in the minibuffer.\n\
f927c5ae
JB
625Third arg KEYMAP is a keymap to use whilst reading;\n\
626 if omitted or nil, the default is `minibuffer-local-map'.\n\
627If fourth arg READ is non-nil, then interpret the result as a lisp object\n\
628 and return that object:\n\
629 in other words, do `(car (read-from-string INPUT-STRING))'\n\
770970cb
RS
630Fifth arg HIST, if non-nil, specifies a history list\n\
631 and optionally the initial position in the list.\n\
632 It can be a symbol, which is the history list variable to use,\n\
633 or it can be a cons cell (HISTVAR . HISTPOS).\n\
634 In that case, HISTVAR is the history list variable to use,\n\
635 and HISTPOS is the initial position (the position in the list\n\
636 which INITIAL-CONTENTS corresponds to).\n\
e5d4686b 637 Positions are counted starting from 1 at the beginning of the list.\n\
b9a86585
RS
638Sixth arg DEFAULT-VALUE is the default value. If non-nil, it is available\n\
639 for history commands; but `read-from-minibuffer' does NOT return DEFAULT-VALUE\n\
640 if the user enters empty input! It returns the empty string.\n\
c8c15521
RS
641Seventh arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits\n\
642 the current input method and the setting of enable-multibyte-characters.\n\
19a4cb25 643If the variable `minibuffer-allow-text-properties' is non-nil,\n\
c3421833 644 then the string which is returned includes whatever text properties\n\
cee54539
KH
645 were present in the minibuffer. Otherwise the value has no text properties.")
646 (prompt, initial_contents, keymap, read, hist, default_value, inherit_input_method)
647 */
b9d721de 648
cee54539 649DEFUN ("read-from-minibuffer", Fread_from_minibuffer, Sread_from_minibuffer, 1, 7, 0,
b9d721de 650 0 /* See immediately above */)
cee54539 651 (prompt, initial_contents, keymap, read, hist, default_value, inherit_input_method)
e5d4686b 652 Lisp_Object prompt, initial_contents, keymap, read, hist, default_value;
cee54539 653 Lisp_Object inherit_input_method;
f927c5ae
JB
654{
655 int pos = 0;
e5d4686b 656 Lisp_Object histvar, histpos, position, val;
1d8d92f4
RS
657 struct gcpro gcpro1;
658
770970cb 659 position = Qnil;
f927c5ae
JB
660
661 CHECK_STRING (prompt, 0);
68e5a8a2 662 if (!NILP (initial_contents))
f927c5ae 663 {
7510b296 664 if (CONSP (initial_contents))
770970cb 665 {
68e5a8a2
RS
666 position = Fcdr (initial_contents);
667 initial_contents = Fcar (initial_contents);
770970cb 668 }
68e5a8a2 669 CHECK_STRING (initial_contents, 1);
56a98455 670 if (!NILP (position))
f927c5ae
JB
671 {
672 CHECK_NUMBER (position, 0);
673 /* Convert to distance from end of input. */
18fef111
RS
674 if (XINT (position) < 1)
675 /* A number too small means the beginning of the string. */
676 pos = - XSTRING (initial_contents)->size;
677 else
678 pos = XINT (position) - 1 - XSTRING (initial_contents)->size;
f927c5ae
JB
679 }
680 }
681
56a98455 682 if (NILP (keymap))
f927c5ae
JB
683 keymap = Vminibuffer_local_map;
684 else
b7df898e 685 keymap = get_keymap (keymap);
770970cb 686
7510b296 687 if (SYMBOLP (hist))
770970cb
RS
688 {
689 histvar = hist;
690 histpos = Qnil;
691 }
692 else
693 {
694 histvar = Fcar_safe (hist);
695 histpos = Fcdr_safe (hist);
696 }
697 if (NILP (histvar))
698 histvar = Qminibuffer_history;
699 if (NILP (histpos))
5a866662 700 XSETFASTINT (histpos, 0);
770970cb 701
1d8d92f4 702 GCPRO1 (default_value);
e5d4686b
RS
703 val = read_minibuf (keymap, initial_contents, prompt,
704 make_number (pos), !NILP (read),
c3421833 705 histvar, histpos, default_value,
cee54539
KH
706 minibuffer_allow_text_properties,
707 !NILP (inherit_input_method));
1d8d92f4 708 UNGCPRO;
e5d4686b 709 return val;
f927c5ae
JB
710}
711
712DEFUN ("read-minibuffer", Fread_minibuffer, Sread_minibuffer, 1, 2, 0,
713 "Return a Lisp object read using the minibuffer.\n\
714Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS\n\
715is a string to insert in the minibuffer before reading.")
716 (prompt, initial_contents)
717 Lisp_Object prompt, initial_contents;
718{
719 CHECK_STRING (prompt, 0);
56a98455 720 if (!NILP (initial_contents))
a1b4b084 721 CHECK_STRING (initial_contents, 1);
770970cb 722 return read_minibuf (Vminibuffer_local_map, initial_contents,
e5d4686b 723 prompt, Qnil, 1, Qminibuffer_history,
dd9d15d6 724 make_number (0), Qnil, 0, 0);
f927c5ae
JB
725}
726
727DEFUN ("eval-minibuffer", Feval_minibuffer, Seval_minibuffer, 1, 2, 0,
728 "Return value of Lisp expression read using the minibuffer.\n\
729Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS\n\
730is a string to insert in the minibuffer before reading.")
731 (prompt, initial_contents)
732 Lisp_Object prompt, initial_contents;
733{
734 return Feval (Fread_minibuffer (prompt, initial_contents));
735}
736
737/* Functions that use the minibuffer to read various things. */
738
cee54539 739DEFUN ("read-string", Fread_string, Sread_string, 1, 5, 0,
f927c5ae 740 "Read a string from the minibuffer, prompting with string PROMPT.\n\
80896ab4
RS
741If non-nil, second arg INITIAL-INPUT is a string to insert before reading.\n\
742The third arg HISTORY, if non-nil, specifies a history list\n\
743 and optionally the initial position in the list.\n\
cee54539 744See `read-from-minibuffer' for details of HISTORY argument.\n\
19a4cb25
SE
745Fourth arg DEFAULT-VALUE is the default value. If non-nil, it is used\n\
746 for history commands, and as the value to return if the user enters\n\
747 the empty string.\n\
748Fifth arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits\n\
c8c15521 749 the current input method and the setting of enable-multibyte-characters.")
cee54539 750 (prompt, initial_input, history, default_value, inherit_input_method)
e5d4686b 751 Lisp_Object prompt, initial_input, history, default_value;
cee54539 752 Lisp_Object inherit_input_method;
f927c5ae 753{
b9a86585
RS
754 Lisp_Object val;
755 val = Fread_from_minibuffer (prompt, initial_input, Qnil,
756 Qnil, history, default_value,
757 inherit_input_method);
758 if (STRINGP (val) && XSTRING (val)->size == 0 && ! NILP (default_value))
759 val = default_value;
760 return val;
f927c5ae
JB
761}
762
cee54539 763DEFUN ("read-no-blanks-input", Fread_no_blanks_input, Sread_no_blanks_input, 1, 3, 0,
c923ccc9
RS
764 "Read a string from the terminal, not allowing blanks.\n\
765Prompt with PROMPT, and provide INITIAL as an initial value of the input string.\n\
c8c15521
RS
766Third arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits\n\
767the current input method and the setting of enable-multibyte-characters.")
c923ccc9
RS
768 (prompt, initial, inherit_input_method)
769 Lisp_Object prompt, initial, inherit_input_method;
f927c5ae
JB
770{
771 CHECK_STRING (prompt, 0);
c923ccc9
RS
772 if (! NILP (initial))
773 CHECK_STRING (initial, 1);
f927c5ae 774
c923ccc9 775 return read_minibuf (Vminibuffer_local_ns_map, initial, prompt, Qnil,
cee54539
KH
776 0, Qminibuffer_history, make_number (0), Qnil, 0,
777 !NILP (inherit_input_method));
f927c5ae
JB
778}
779
e5d4686b
RS
780DEFUN ("read-command", Fread_command, Sread_command, 1, 2, 0,
781 "Read the name of a command and return as a symbol.\n\
782Prompts with PROMPT. By default, return DEFAULT-VALUE.")
783 (prompt, default_value)
784 Lisp_Object prompt, default_value;
f927c5ae 785{
7c8d9931
RS
786 Lisp_Object name, default_string;
787
788 if (NILP (default_value))
789 default_string = Qnil;
790 else if (SYMBOLP (default_value))
6dd05c14 791 XSETSTRING (default_string, XSYMBOL (default_value)->name);
7c8d9931
RS
792 else
793 default_string = default_value;
794
795 name = Fcompleting_read (prompt, Vobarray, Qcommandp, Qt,
796 Qnil, Qnil, default_string, Qnil);
797 if (NILP (name))
798 return name;
799 return Fintern (name, Qnil);
f927c5ae
JB
800}
801
802#ifdef NOTDEF
803DEFUN ("read-function", Fread_function, Sread_function, 1, 1, 0,
804 "One arg PROMPT, a string. Read the name of a function and return as a symbol.\n\
805Prompts with PROMPT.")
806 (prompt)
807 Lisp_Object prompt;
808{
cee54539 809 return Fintern (Fcompleting_read (prompt, Vobarray, Qfboundp, Qt, Qnil, Qnil, Qnil, Qnil),
f927c5ae
JB
810 Qnil);
811}
812#endif /* NOTDEF */
813
e5d4686b
RS
814DEFUN ("read-variable", Fread_variable, Sread_variable, 1, 2, 0,
815 "Read the name of a user variable and return it as a symbol.\n\
816Prompts with PROMPT. By default, return DEFAULT-VALUE.\n\
f927c5ae 817A user variable is one whose documentation starts with a `*' character.")
e5d4686b
RS
818 (prompt, default_value)
819 Lisp_Object prompt, default_value;
f927c5ae 820{
7c8d9931
RS
821 Lisp_Object name, default_string;
822
823 if (NILP (default_value))
824 default_string = Qnil;
825 else if (SYMBOLP (default_value))
6dd05c14 826 XSETSTRING (default_string, XSYMBOL (default_value)->name);
7c8d9931
RS
827 else
828 default_string = default_value;
829
830 name = Fcompleting_read (prompt, Vobarray,
831 Quser_variable_p, Qt,
832 Qnil, Qnil, default_string, Qnil);
833 if (NILP (name))
834 return name;
835 return Fintern (name, Qnil);
f927c5ae
JB
836}
837
838DEFUN ("read-buffer", Fread_buffer, Sread_buffer, 1, 3, 0,
839 "One arg PROMPT, a string. Read the name of a buffer and return as a string.\n\
840Prompts with PROMPT.\n\
e5d4686b 841Optional second arg DEF is value to return if user enters an empty line.\n\
f927c5ae
JB
842If optional third arg REQUIRE-MATCH is non-nil, only existing buffer names are allowed.")
843 (prompt, def, require_match)
844 Lisp_Object prompt, def, require_match;
845{
846 Lisp_Object tem;
eebbfb01
KH
847 Lisp_Object args[4];
848
7510b296 849 if (BUFFERP (def))
f927c5ae 850 def = XBUFFER (def)->name;
eebbfb01
KH
851
852 if (NILP (Vread_buffer_function))
853 {
854 if (!NILP (def))
855 {
856 args[0] = build_string ("%s(default %s) ");
857 args[1] = prompt;
858 args[2] = def;
859 prompt = Fformat (3, args);
860 }
861
862 return Fcompleting_read (prompt, Vbuffer_alist, Qnil,
406e55df
RS
863 require_match, Qnil, Qbuffer_name_history,
864 def, Qnil);
eebbfb01
KH
865 }
866 else
f927c5ae 867 {
eebbfb01 868 args[0] = Vread_buffer_function;
f927c5ae
JB
869 args[1] = prompt;
870 args[2] = def;
eebbfb01
KH
871 args[3] = require_match;
872 return Ffuncall(4, args);
f927c5ae 873 }
f927c5ae
JB
874}
875\f
ec067ec7
RS
876static Lisp_Object
877minibuf_conform_representation (string, basis)
878 Lisp_Object string, basis;
879{
880 if (STRING_MULTIBYTE (string) == STRING_MULTIBYTE (basis))
881 return string;
882
883 if (STRING_MULTIBYTE (string))
884 return Fstring_make_unibyte (string);
885 else
886 return Fstring_make_multibyte (string);
887}
888
f927c5ae
JB
889DEFUN ("try-completion", Ftry_completion, Stry_completion, 2, 3, 0,
890 "Return common substring of all completions of STRING in ALIST.\n\
891Each car of each element of ALIST is tested to see if it begins with STRING.\n\
892All that match are compared together; the longest initial sequence\n\
893common to all matches is returned as a string.\n\
894If there is no match at all, nil is returned.\n\
895For an exact match, t is returned.\n\
896\n\
897ALIST can be an obarray instead of an alist.\n\
898Then the print names of all symbols in the obarray are the possible matches.\n\
899\n\
900ALIST can also be a function to do the completion itself.\n\
901It receives three arguments: the values STRING, PREDICATE and nil.\n\
902Whatever it returns becomes the value of `try-completion'.\n\
903\n\
904If optional third argument PREDICATE is non-nil,\n\
905it is used to test each possible match.\n\
906The match is a candidate only if PREDICATE returns non-nil.\n\
89a255dc
RS
907The argument given to PREDICATE is the alist element\n\
908or the symbol from the obarray.")
7efd36fc
EN
909 (string, alist, predicate)
910 Lisp_Object string, alist, predicate;
f927c5ae
JB
911{
912 Lisp_Object bestmatch, tail, elt, eltstring;
af2b7cd5 913 /* Size in bytes of BESTMATCH. */
f927c5ae 914 int bestmatchsize;
af2b7cd5 915 /* These are in bytes, too. */
f927c5ae 916 int compare, matchsize;
56a98455 917 int list = CONSP (alist) || NILP (alist);
f927c5ae
JB
918 int index, obsize;
919 int matchcount = 0;
920 Lisp_Object bucket, zero, end, tem;
921 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
922
923 CHECK_STRING (string, 0);
7510b296 924 if (!list && !VECTORP (alist))
7efd36fc 925 return call3 (alist, string, predicate, Qnil);
f927c5ae
JB
926
927 bestmatch = Qnil;
928
929 /* If ALIST is not a list, set TAIL just for gc pro. */
930 tail = alist;
931 if (! list)
932 {
933 index = 0;
934 obsize = XVECTOR (alist)->size;
935 bucket = XVECTOR (alist)->contents[index];
936 }
937
938 while (1)
939 {
940 /* Get the next element of the alist or obarray. */
941 /* Exit the loop if the elements are all used up. */
942 /* elt gets the alist element or symbol.
943 eltstring gets the name to check as a completion. */
944
945 if (list)
946 {
56a98455 947 if (NILP (tail))
f927c5ae
JB
948 break;
949 elt = Fcar (tail);
950 eltstring = Fcar (elt);
951 tail = Fcdr (tail);
952 }
953 else
954 {
955 if (XFASTINT (bucket) != 0)
956 {
957 elt = bucket;
958 eltstring = Fsymbol_name (elt);
959 if (XSYMBOL (bucket)->next)
960 XSETSYMBOL (bucket, XSYMBOL (bucket)->next);
961 else
5a866662 962 XSETFASTINT (bucket, 0);
f927c5ae
JB
963 }
964 else if (++index >= obsize)
965 break;
966 else
967 {
968 bucket = XVECTOR (alist)->contents[index];
969 continue;
970 }
971 }
972
973 /* Is this element a possible completion? */
974
7510b296 975 if (STRINGP (eltstring)
7d315986 976 && XSTRING (string)->size <= XSTRING (eltstring)->size
69f4ef20
RS
977 && (tem = Fcompare_strings (eltstring, make_number (0),
978 make_number (XSTRING (string)->size),
979 string, make_number (0), Qnil,
980 completion_ignore_case ?Qt : Qnil),
981 EQ (Qt, tem)))
f927c5ae
JB
982 {
983 /* Yes. */
42006772
RS
984 Lisp_Object regexps;
985 Lisp_Object zero;
5a866662 986 XSETFASTINT (zero, 0);
42006772
RS
987
988 /* Ignore this element if it fails to match all the regexps. */
989 for (regexps = Vcompletion_regexp_list; CONSP (regexps);
990 regexps = XCONS (regexps)->cdr)
991 {
992 tem = Fstring_match (XCONS (regexps)->car, eltstring, zero);
993 if (NILP (tem))
994 break;
995 }
996 if (CONSP (regexps))
997 continue;
998
f927c5ae
JB
999 /* Ignore this element if there is a predicate
1000 and the predicate doesn't like it. */
1001
7efd36fc 1002 if (!NILP (predicate))
f927c5ae 1003 {
7efd36fc 1004 if (EQ (predicate, Qcommandp))
f927c5ae
JB
1005 tem = Fcommandp (elt);
1006 else
1007 {
1008 GCPRO4 (tail, string, eltstring, bestmatch);
7efd36fc 1009 tem = call1 (predicate, elt);
f927c5ae
JB
1010 UNGCPRO;
1011 }
56a98455 1012 if (NILP (tem)) continue;
f927c5ae
JB
1013 }
1014
1015 /* Update computation of how much all possible completions match */
1016
1017 matchcount++;
56a98455 1018 if (NILP (bestmatch))
af2b7cd5
RS
1019 {
1020 bestmatch = eltstring;
69f4ef20 1021 bestmatchsize = XSTRING (eltstring)->size;
af2b7cd5 1022 }
f927c5ae
JB
1023 else
1024 {
69f4ef20
RS
1025 compare = min (bestmatchsize, XSTRING (eltstring)->size);
1026 tem = Fcompare_strings (bestmatch, make_number (0),
1027 make_number (compare),
1028 eltstring, make_number (0),
1029 make_number (compare),
1030 completion_ignore_case ? Qt : Qnil);
1031 if (EQ (tem, Qt))
1032 matchsize = compare;
1033 else if (XINT (tem) < 0)
1034 matchsize = - XINT (tem) - 1;
1035 else
1036 matchsize = XINT (tem) - 1;
1037
52b14ac0
JB
1038 if (matchsize < 0)
1039 matchsize = compare;
1040 if (completion_ignore_case)
1041 {
1042 /* If this is an exact match except for case,
1043 use it as the best match rather than one that is not an
1044 exact match. This way, we get the case pattern
1045 of the actual match. */
69f4ef20
RS
1046 if ((matchsize == XSTRING (eltstring)->size
1047 && matchsize < XSTRING (bestmatch)->size)
52b14ac0
JB
1048 ||
1049 /* If there is more than one exact match ignoring case,
1050 and one of them is exact including case,
1051 prefer that one. */
1052 /* If there is no exact match ignoring case,
1053 prefer a match that does not change the case
1054 of the input. */
69f4ef20 1055 ((matchsize == XSTRING (eltstring)->size)
52b14ac0 1056 ==
69f4ef20
RS
1057 (matchsize == XSTRING (bestmatch)->size)
1058 && (tem = Fcompare_strings (eltstring, make_number (0),
1059 make_number (XSTRING (string)->size),
1060 string, make_number (0),
1061 Qnil,
1062 Qnil),
1063 EQ (Qt, tem))
1064 && (tem = Fcompare_strings (bestmatch, make_number (0),
1065 make_number (XSTRING (string)->size),
1066 string, make_number (0),
1067 Qnil,
1068 Qnil),
1069 ! EQ (Qt, tem))))
52b14ac0
JB
1070 bestmatch = eltstring;
1071 }
1072 bestmatchsize = matchsize;
f927c5ae
JB
1073 }
1074 }
1075 }
1076
56a98455 1077 if (NILP (bestmatch))
f927c5ae 1078 return Qnil; /* No completions found */
52b14ac0
JB
1079 /* If we are ignoring case, and there is no exact match,
1080 and no additional text was supplied,
1081 don't change the case of what the user typed. */
69f4ef20
RS
1082 if (completion_ignore_case && bestmatchsize == XSTRING (string)->size
1083 && XSTRING (bestmatch)->size > bestmatchsize)
ec067ec7 1084 return minibuf_conform_representation (string, bestmatch);
52b14ac0
JB
1085
1086 /* Return t if the supplied string is an exact match (counting case);
1087 it does not require any change to be made. */
69f4ef20
RS
1088 if (matchcount == 1 && bestmatchsize == XSTRING (string)->size
1089 && (tem = Fcompare_strings (bestmatch, make_number (0),
1090 make_number (bestmatchsize),
1091 string, make_number (0),
1092 make_number (bestmatchsize),
1093 Qnil),
1094 EQ (Qt, tem)))
f927c5ae
JB
1095 return Qt;
1096
5a866662
KH
1097 XSETFASTINT (zero, 0); /* Else extract the part in which */
1098 XSETFASTINT (end, bestmatchsize); /* all completions agree */
f927c5ae
JB
1099 return Fsubstring (bestmatch, zero, end);
1100}
1101
1102/* Compare exactly LEN chars of strings at S1 and S2,
1103 ignoring case if appropriate.
1104 Return -1 if strings match,
1105 else number of chars that match at the beginning. */
1106
829f7f7c 1107int
f927c5ae 1108scmp (s1, s2, len)
829f7f7c 1109 register unsigned char *s1, *s2;
f927c5ae
JB
1110 int len;
1111{
1112 register int l = len;
d50a3d2a 1113 register unsigned char *start = s1;
f927c5ae
JB
1114
1115 if (completion_ignore_case)
1116 {
2e34157c 1117 while (l && DOWNCASE (*s1++) == DOWNCASE (*s2++))
f927c5ae
JB
1118 l--;
1119 }
1120 else
1121 {
1122 while (l && *s1++ == *s2++)
1123 l--;
1124 }
1125 if (l == 0)
1126 return -1;
829f7f7c 1127 else
d50a3d2a
KH
1128 {
1129 int match = len - l;
1130
1131 /* Now *--S1 is the unmatching byte. If it is in the middle of
1132 multi-byte form, we must say that the multi-byte character
1133 there doesn't match. */
1134 while (match && *--s1 >= 0xA0) match--;
1135 return match;
1136 }
f927c5ae
JB
1137}
1138\f
89a255dc 1139DEFUN ("all-completions", Fall_completions, Sall_completions, 2, 4, 0,
f927c5ae
JB
1140 "Search for partial matches to STRING in ALIST.\n\
1141Each car of each element of ALIST is tested to see if it begins with STRING.\n\
1142The value is a list of all the strings from ALIST that match.\n\
89a255dc 1143\n\
f927c5ae
JB
1144ALIST can be an obarray instead of an alist.\n\
1145Then the print names of all symbols in the obarray are the possible matches.\n\
1146\n\
1147ALIST can also be a function to do the completion itself.\n\
1148It receives three arguments: the values STRING, PREDICATE and t.\n\
1149Whatever it returns becomes the value of `all-completion'.\n\
1150\n\
1151If optional third argument PREDICATE is non-nil,\n\
1152it is used to test each possible match.\n\
1153The match is a candidate only if PREDICATE returns non-nil.\n\
89a255dc
RS
1154The argument given to PREDICATE is the alist element\n\
1155or the symbol from the obarray.\n\
1156\n\
1157If the optional fourth argument HIDE-SPACES is non-nil,\n\
1158strings in ALIST that start with a space\n\
1159are ignored unless STRING itself starts with a space.")
7efd36fc
EN
1160 (string, alist, predicate, hide_spaces)
1161 Lisp_Object string, alist, predicate, hide_spaces;
f927c5ae
JB
1162{
1163 Lisp_Object tail, elt, eltstring;
1164 Lisp_Object allmatches;
56a98455 1165 int list = CONSP (alist) || NILP (alist);
f927c5ae
JB
1166 int index, obsize;
1167 Lisp_Object bucket, tem;
1168 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
1169
1170 CHECK_STRING (string, 0);
7510b296 1171 if (!list && !VECTORP (alist))
f927c5ae 1172 {
7efd36fc 1173 return call3 (alist, string, predicate, Qt);
f927c5ae
JB
1174 }
1175 allmatches = Qnil;
1176
1177 /* If ALIST is not a list, set TAIL just for gc pro. */
1178 tail = alist;
1179 if (! list)
1180 {
1181 index = 0;
1182 obsize = XVECTOR (alist)->size;
1183 bucket = XVECTOR (alist)->contents[index];
1184 }
1185
1186 while (1)
1187 {
1188 /* Get the next element of the alist or obarray. */
1189 /* Exit the loop if the elements are all used up. */
1190 /* elt gets the alist element or symbol.
1191 eltstring gets the name to check as a completion. */
1192
1193 if (list)
1194 {
56a98455 1195 if (NILP (tail))
f927c5ae
JB
1196 break;
1197 elt = Fcar (tail);
1198 eltstring = Fcar (elt);
1199 tail = Fcdr (tail);
1200 }
1201 else
1202 {
1203 if (XFASTINT (bucket) != 0)
1204 {
1205 elt = bucket;
1206 eltstring = Fsymbol_name (elt);
1207 if (XSYMBOL (bucket)->next)
1208 XSETSYMBOL (bucket, XSYMBOL (bucket)->next);
1209 else
5a866662 1210 XSETFASTINT (bucket, 0);
f927c5ae
JB
1211 }
1212 else if (++index >= obsize)
1213 break;
1214 else
1215 {
1216 bucket = XVECTOR (alist)->contents[index];
1217 continue;
1218 }
1219 }
1220
1221 /* Is this element a possible completion? */
1222
7510b296 1223 if (STRINGP (eltstring)
7d315986 1224 && XSTRING (string)->size <= XSTRING (eltstring)->size
89a255dc 1225 /* If HIDE_SPACES, reject alternatives that start with space
2cbaf886 1226 unless the input starts with space. */
fc932ac6 1227 && ((STRING_BYTES (XSTRING (string)) > 0
af2b7cd5 1228 && XSTRING (string)->data[0] == ' ')
89a255dc
RS
1229 || XSTRING (eltstring)->data[0] != ' '
1230 || NILP (hide_spaces))
69f4ef20
RS
1231 && (tem = Fcompare_strings (eltstring, make_number (0),
1232 make_number (XSTRING (string)->size),
1233 string, make_number (0),
1234 make_number (XSTRING (string)->size),
1235 completion_ignore_case ? Qt : Qnil),
1236 EQ (Qt, tem)))
f927c5ae
JB
1237 {
1238 /* Yes. */
42006772
RS
1239 Lisp_Object regexps;
1240 Lisp_Object zero;
5a866662 1241 XSETFASTINT (zero, 0);
42006772
RS
1242
1243 /* Ignore this element if it fails to match all the regexps. */
1244 for (regexps = Vcompletion_regexp_list; CONSP (regexps);
1245 regexps = XCONS (regexps)->cdr)
1246 {
1247 tem = Fstring_match (XCONS (regexps)->car, eltstring, zero);
1248 if (NILP (tem))
1249 break;
1250 }
1251 if (CONSP (regexps))
1252 continue;
1253
f927c5ae
JB
1254 /* Ignore this element if there is a predicate
1255 and the predicate doesn't like it. */
1256
7efd36fc 1257 if (!NILP (predicate))
f927c5ae 1258 {
7efd36fc 1259 if (EQ (predicate, Qcommandp))
f927c5ae
JB
1260 tem = Fcommandp (elt);
1261 else
1262 {
1263 GCPRO4 (tail, eltstring, allmatches, string);
7efd36fc 1264 tem = call1 (predicate, elt);
f927c5ae
JB
1265 UNGCPRO;
1266 }
56a98455 1267 if (NILP (tem)) continue;
f927c5ae
JB
1268 }
1269 /* Ok => put it on the list. */
1270 allmatches = Fcons (eltstring, allmatches);
1271 }
1272 }
1273
1274 return Fnreverse (allmatches);
1275}
1276\f
1277Lisp_Object Vminibuffer_completion_table, Qminibuffer_completion_table;
1278Lisp_Object Vminibuffer_completion_predicate, Qminibuffer_completion_predicate;
1279Lisp_Object Vminibuffer_completion_confirm, Qminibuffer_completion_confirm;
ccf330a6 1280Lisp_Object Vminibuffer_completing_file_name;
f927c5ae 1281
b9d721de
JB
1282/* This comment supplies the doc string for completing-read,
1283 for make-docfile to see. We cannot put this in the real DEFUN
1284 due to limits in the Unix cpp.
1285
cee54539 1286DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 8, 0,
f927c5ae 1287 "Read a string in the minibuffer, with completion.\n\
f927c5ae
JB
1288PROMPT is a string to prompt with; normally it ends in a colon and a space.\n\
1289TABLE is an alist whose elements' cars are strings, or an obarray.\n\
1290PREDICATE limits completion to a subset of TABLE.\n\
60e6659c 1291See `try-completion' and `all-completions' for more details\n\
6b3faad8 1292 on completion, TABLE, and PREDICATE.\n\
cbbc3917 1293\n\
f927c5ae 1294If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless\n\
4ced3209 1295 the input is (or completes to) an element of TABLE or is null.\n\
f927c5ae 1296 If it is also not t, Return does not exit if it does non-null completion.\n\
fab95625 1297If the input is null, `completing-read' returns an empty string,\n\
cbbc3917
RS
1298 regardless of the value of REQUIRE-MATCH.\n\
1299\n\
f927c5ae 1300If INITIAL-INPUT is non-nil, insert it in the minibuffer initially.\n\
770970cb
RS
1301 If it is (STRING . POSITION), the initial input\n\
1302 is STRING, but point is placed POSITION characters into the string.\n\
1303HIST, if non-nil, specifies a history list\n\
1304 and optionally the initial position in the list.\n\
1305 It can be a symbol, which is the history list variable to use,\n\
1306 or it can be a cons cell (HISTVAR . HISTPOS).\n\
1307 In that case, HISTVAR is the history list variable to use,\n\
1308 and HISTPOS is the initial position (the position in the list\n\
4356f221 1309 which INITIAL-INPUT corresponds to).\n\
770970cb 1310 Positions are counted starting from 1 at the beginning of the list.\n\
cee54539
KH
1311DEF, if non-nil, is the default value.\n\
1312\n\
1313If INHERIT-INPUT-METHOD is non-nil, the minibuffer inherits\n\
c8c15521 1314 the current input method and the setting of enable-multibyte-characters.\n\
cee54539 1315\n\
770970cb 1316Completion ignores case if the ambient value of\n\
b9d721de
JB
1317 `completion-ignore-case' is non-nil."
1318*/
cee54539 1319DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 8, 0,
b9d721de 1320 0 /* See immediately above */)
cee54539 1321 (prompt, table, predicate, require_match, init, hist, def, inherit_input_method)
e5d4686b 1322 Lisp_Object prompt, table, predicate, require_match, init, hist, def;
cee54539 1323 Lisp_Object inherit_input_method;
f927c5ae 1324{
770970cb
RS
1325 Lisp_Object val, histvar, histpos, position;
1326 int pos = 0;
f927c5ae 1327 int count = specpdl_ptr - specpdl;
0c8ee1a2 1328 struct gcpro gcpro1;
ccf330a6 1329 int disable_multibyte = ! NILP (Vminibuffer_completing_file_name);
0c8ee1a2
RS
1330
1331 GCPRO1 (def);
1332
f927c5ae 1333 specbind (Qminibuffer_completion_table, table);
7efd36fc 1334 specbind (Qminibuffer_completion_predicate, predicate);
f927c5ae
JB
1335 specbind (Qminibuffer_completion_confirm,
1336 EQ (require_match, Qt) ? Qnil : Qt);
1337 last_exact_completion = Qnil;
770970cb
RS
1338
1339 position = Qnil;
1340 if (!NILP (init))
1341 {
7510b296 1342 if (CONSP (init))
770970cb
RS
1343 {
1344 position = Fcdr (init);
1345 init = Fcar (init);
1346 }
1347 CHECK_STRING (init, 0);
1348 if (!NILP (position))
1349 {
1350 CHECK_NUMBER (position, 0);
1351 /* Convert to distance from end of input. */
5dadd3a2 1352 pos = XINT (position) - XSTRING (init)->size;
770970cb
RS
1353 }
1354 }
1355
7510b296 1356 if (SYMBOLP (hist))
770970cb
RS
1357 {
1358 histvar = hist;
1359 histpos = Qnil;
1360 }
1361 else
1362 {
1363 histvar = Fcar_safe (hist);
1364 histpos = Fcdr_safe (hist);
1365 }
1366 if (NILP (histvar))
1367 histvar = Qminibuffer_history;
1368 if (NILP (histpos))
5a866662 1369 XSETFASTINT (histpos, 0);
770970cb 1370
56a98455 1371 val = read_minibuf (NILP (require_match)
f927c5ae
JB
1372 ? Vminibuffer_local_completion_map
1373 : Vminibuffer_local_must_match_map,
85b5fe07 1374 init, prompt, make_number (pos), 0,
cee54539
KH
1375 histvar, histpos, def, 0,
1376 !NILP (inherit_input_method));
b9a86585
RS
1377
1378 if (STRINGP (val) && XSTRING (val)->size == 0 && ! NILP (def))
1379 val = def;
1380
0c8ee1a2 1381 RETURN_UNGCPRO (unbind_to (count, val));
f927c5ae
JB
1382}
1383\f
f927c5ae 1384Lisp_Object Fminibuffer_completion_help ();
52b14ac0 1385Lisp_Object assoc_for_completion ();
5d2ca7ae
RS
1386
1387/* Test whether TXT is an exact completion. */
1388Lisp_Object
1389test_completion (txt)
1390 Lisp_Object txt;
1391{
1392 Lisp_Object tem;
1393
1394 if (CONSP (Vminibuffer_completion_table)
1395 || NILP (Vminibuffer_completion_table))
1396 return assoc_for_completion (txt, Vminibuffer_completion_table);
1397 else if (VECTORP (Vminibuffer_completion_table))
1398 {
1399 /* Bypass intern-soft as that loses for nil */
1400 tem = oblookup (Vminibuffer_completion_table,
af2b7cd5
RS
1401 XSTRING (txt)->data,
1402 XSTRING (txt)->size,
fc932ac6 1403 STRING_BYTES (XSTRING (txt)));
44472c88 1404 if (!SYMBOLP (tem))
9404446f
RS
1405 {
1406 if (STRING_MULTIBYTE (txt))
1407 txt = Fstring_make_unibyte (txt);
1408 else
1409 txt = Fstring_make_multibyte (txt);
1410
1411 tem = oblookup (Vminibuffer_completion_table,
1412 XSTRING (txt)->data,
1413 XSTRING (txt)->size,
1414 STRING_BYTES (XSTRING (txt)));
1415 if (!SYMBOLP (tem))
1416 return Qnil;
1417 }
1418 if (!NILP (Vminibuffer_completion_predicate))
5d2ca7ae
RS
1419 return call1 (Vminibuffer_completion_predicate, tem);
1420 else
1421 return Qt;
1422 }
1423 else
1424 return call3 (Vminibuffer_completion_table, txt,
1425 Vminibuffer_completion_predicate, Qlambda);
1426}
f927c5ae
JB
1427
1428/* returns:
1429 * 0 no possible completion
1430 * 1 was already an exact and unique completion
1431 * 3 was already an exact completion
1432 * 4 completed to an exact completion
1433 * 5 some completion happened
1434 * 6 no completion happened
1435 */
1436int
1437do_completion ()
1438{
1439 Lisp_Object completion, tem;
1440 int completedp;
1441 Lisp_Object last;
1e00c2ff 1442 struct gcpro gcpro1, gcpro2;
f927c5ae
JB
1443
1444 completion = Ftry_completion (Fbuffer_string (), Vminibuffer_completion_table,
1445 Vminibuffer_completion_predicate);
1446 last = last_exact_completion;
1447 last_exact_completion = Qnil;
1448
4f9b95e5
KH
1449 GCPRO2 (completion, last);
1450
56a98455 1451 if (NILP (completion))
f927c5ae
JB
1452 {
1453 bitch_at_user ();
1454 temp_echo_area_glyphs (" [No match]");
1e00c2ff 1455 UNGCPRO;
f927c5ae
JB
1456 return 0;
1457 }
1458
1459 if (EQ (completion, Qt)) /* exact and unique match */
1e00c2ff
KH
1460 {
1461 UNGCPRO;
1462 return 1;
1463 }
f927c5ae
JB
1464
1465 /* compiler bug */
1466 tem = Fstring_equal (completion, Fbuffer_string());
56a98455 1467 if (completedp = NILP (tem))
f927c5ae
JB
1468 {
1469 Ferase_buffer (); /* Some completion happened */
1470 Finsert (1, &completion);
1471 }
1472
1473 /* It did find a match. Do we match some possibility exactly now? */
5d2ca7ae 1474 tem = test_completion (Fbuffer_string ());
56a98455 1475 if (NILP (tem))
1e00c2ff
KH
1476 {
1477 /* not an exact match */
1478 UNGCPRO;
f927c5ae
JB
1479 if (completedp)
1480 return 5;
1481 else if (auto_help)
1482 Fminibuffer_completion_help ();
1483 else
1484 temp_echo_area_glyphs (" [Next char not unique]");
1485 return 6;
1486 }
1487 else if (completedp)
1e00c2ff
KH
1488 {
1489 UNGCPRO;
1490 return 4;
1491 }
f927c5ae
JB
1492 /* If the last exact completion and this one were the same,
1493 it means we've already given a "Complete but not unique"
52b14ac0 1494 message and the user's hit TAB again, so now we give him help. */
f927c5ae 1495 last_exact_completion = completion;
56a98455 1496 if (!NILP (last))
f927c5ae
JB
1497 {
1498 tem = Fbuffer_string ();
56a98455 1499 if (!NILP (Fequal (tem, last)))
f927c5ae
JB
1500 Fminibuffer_completion_help ();
1501 }
1e00c2ff 1502 UNGCPRO;
f927c5ae 1503 return 3;
f927c5ae 1504}
1e00c2ff 1505
52b14ac0
JB
1506/* Like assoc but assumes KEY is a string, and ignores case if appropriate. */
1507
1508Lisp_Object
1509assoc_for_completion (key, list)
1510 register Lisp_Object key;
1511 Lisp_Object list;
1512{
1513 register Lisp_Object tail;
1514
56a98455 1515 for (tail = list; !NILP (tail); tail = Fcdr (tail))
52b14ac0
JB
1516 {
1517 register Lisp_Object elt, tem, thiscar;
1518 elt = Fcar (tail);
1519 if (!CONSP (elt)) continue;
1520 thiscar = Fcar (elt);
7510b296 1521 if (!STRINGP (thiscar))
52b14ac0 1522 continue;
9404446f
RS
1523 tem = Fcompare_strings (thiscar, make_number (0), Qnil,
1524 key, make_number (0), Qnil,
1525 completion_ignore_case ? Qt : Qnil);
1526 if (EQ (tem, Qt))
1527 return elt;
52b14ac0
JB
1528 QUIT;
1529 }
1530 return Qnil;
1531}
f927c5ae
JB
1532
1533DEFUN ("minibuffer-complete", Fminibuffer_complete, Sminibuffer_complete, 0, 0, "",
6300d782 1534 "Complete the minibuffer contents as far as possible.\n\
2cb6da5c
RS
1535Return nil if there is no valid completion, else t.\n\
1536If no characters can be completed, display a list of possible completions.\n\
1537If you repeat this command after it displayed such a list,\n\
1538scroll the window of possible completions.")
f927c5ae
JB
1539 ()
1540{
2cb6da5c
RS
1541 register int i;
1542 Lisp_Object window, tem;
1543
df902b62
RS
1544 /* If the previous command was not this,
1545 mark the completion buffer obsolete. */
1546 if (! EQ (current_kboard->Vlast_command, Vthis_command))
2cb6da5c
RS
1547 Vminibuf_scroll_window = Qnil;
1548
1549 window = Vminibuf_scroll_window;
1550 /* If there's a fresh completion window with a live buffer,
1551 and this command is repeated, scroll that window. */
1552 if (! NILP (window) && ! NILP (XWINDOW (window)->buffer)
1553 && !NILP (XBUFFER (XWINDOW (window)->buffer)->name))
1554 {
1555 struct buffer *obuf = current_buffer;
1556
1557 Fset_buffer (XWINDOW (window)->buffer);
1558 tem = Fpos_visible_in_window_p (make_number (ZV), window);
1559 if (! NILP (tem))
1560 /* If end is in view, scroll up to the beginning. */
b7df898e 1561 Fset_window_start (window, make_number (BEGV), Qnil);
2cb6da5c
RS
1562 else
1563 /* Else scroll down one screen. */
1564 Fscroll_other_window (Qnil);
1565
1566 set_buffer_internal (obuf);
1567 return Qnil;
1568 }
1569
1570 i = do_completion ();
f927c5ae
JB
1571 switch (i)
1572 {
1573 case 0:
1574 return Qnil;
1575
1576 case 1:
1577 temp_echo_area_glyphs (" [Sole completion]");
1578 break;
1579
1580 case 3:
1581 temp_echo_area_glyphs (" [Complete, but not unique]");
1582 break;
1583 }
1584
1585 return Qt;
1586}
e4c97a67
RS
1587\f
1588/* Subroutines of Fminibuffer_complete_and_exit. */
1589
1590/* This one is called by internal_condition_case to do the real work. */
1591
1592Lisp_Object
1593complete_and_exit_1 ()
1594{
1595 return make_number (do_completion ());
1596}
1597
1598/* This one is called by internal_condition_case if an error happens.
1599 Pretend the current value is an exact match. */
1600
1601Lisp_Object
1602complete_and_exit_2 (ignore)
1603 Lisp_Object ignore;
1604{
1605 return make_number (1);
1606}
f927c5ae
JB
1607
1608DEFUN ("minibuffer-complete-and-exit", Fminibuffer_complete_and_exit,
1609 Sminibuffer_complete_and_exit, 0, 0, "",
5d2ca7ae
RS
1610 "If the minibuffer contents is a valid completion then exit.\n\
1611Otherwise try to complete it. If completion leads to a valid completion,\n\
f927c5ae
JB
1612a repetition of this command will exit.")
1613 ()
1614{
1615 register int i;
e4c97a67 1616 Lisp_Object val;
f927c5ae
JB
1617
1618 /* Allow user to specify null string */
1619 if (BEGV == ZV)
1620 goto exit;
1621
5d2ca7ae
RS
1622 if (!NILP (test_completion (Fbuffer_string ())))
1623 goto exit;
1624
e4c97a67
RS
1625 /* Call do_completion, but ignore errors. */
1626 val = internal_condition_case (complete_and_exit_1, Qerror,
1627 complete_and_exit_2);
1628
1629 i = XFASTINT (val);
f927c5ae
JB
1630 switch (i)
1631 {
1632 case 1:
1633 case 3:
1634 goto exit;
1635
1636 case 4:
56a98455 1637 if (!NILP (Vminibuffer_completion_confirm))
f927c5ae
JB
1638 {
1639 temp_echo_area_glyphs (" [Confirm]");
1640 return Qnil;
1641 }
1642 else
1643 goto exit;
1644
1645 default:
1646 return Qnil;
1647 }
1648 exit:
1649 Fthrow (Qexit, Qnil);
1650 /* NOTREACHED */
1651}
1652
1653DEFUN ("minibuffer-complete-word", Fminibuffer_complete_word, Sminibuffer_complete_word,
1654 0, 0, "",
1655 "Complete the minibuffer contents at most a single word.\n\
1656After one word is completed as much as possible, a space or hyphen\n\
6300d782
KH
1657is added, provided that matches some possible completion.\n\
1658Return nil if there is no valid completion, else t.")
f927c5ae
JB
1659 ()
1660{
69f4ef20 1661 Lisp_Object completion, tem, tem1;
af2b7cd5 1662 register int i, i_byte;
f927c5ae 1663 register unsigned char *completion_string;
d7be4211 1664 struct gcpro gcpro1, gcpro2;
b278606c
BF
1665
1666 /* We keep calling Fbuffer_string rather than arrange for GC to
1667 hold onto a pointer to one of the strings thus made. */
f927c5ae
JB
1668
1669 completion = Ftry_completion (Fbuffer_string (),
1670 Vminibuffer_completion_table,
1671 Vminibuffer_completion_predicate);
56a98455 1672 if (NILP (completion))
f927c5ae
JB
1673 {
1674 bitch_at_user ();
1675 temp_echo_area_glyphs (" [No match]");
1676 return Qnil;
1677 }
1678 if (EQ (completion, Qt))
1679 return Qnil;
1680
b278606c 1681#if 0 /* How the below code used to look, for reference. */
f927c5ae
JB
1682 tem = Fbuffer_string ();
1683 b = XSTRING (tem)->data;
1684 i = ZV - 1 - XSTRING (completion)->size;
1685 p = XSTRING (completion)->data;
1686 if (i > 0 ||
1687 0 <= scmp (b, p, ZV - 1))
1688 {
1689 i = 1;
1690 /* Set buffer to longest match of buffer tail and completion head. */
1691 while (0 <= scmp (b + i, p, ZV - 1 - i))
1692 i++;
1693 del_range (1, i + 1);
1694 SET_PT (ZV);
1695 }
1696#else /* Rewritten code */
1697 {
69f4ef20 1698 int buffer_nchars, completion_nchars;
f927c5ae 1699
59860a8c 1700 CHECK_STRING (completion, 0);
f927c5ae 1701 tem = Fbuffer_string ();
d7be4211 1702 GCPRO2 (completion, tem);
719b4a40
RS
1703 /* If reading a file name,
1704 expand any $ENVVAR refs in the buffer and in TEM. */
ccf330a6 1705 if (! NILP (Vminibuffer_completing_file_name))
719b4a40
RS
1706 {
1707 Lisp_Object substituted;
1708 substituted = Fsubstitute_in_file_name (tem);
1709 if (! EQ (substituted, tem))
1710 {
1711 tem = substituted;
1712 Ferase_buffer ();
af2b7cd5 1713 insert_from_string (tem, 0, 0, XSTRING (tem)->size,
fc932ac6 1714 STRING_BYTES (XSTRING (tem)), 0);
719b4a40
RS
1715 }
1716 }
69f4ef20
RS
1717 buffer_nchars = XSTRING (tem)->size; /* ie ZV - BEGV */
1718 completion_nchars = XSTRING (completion)->size;
1719 i = buffer_nchars - completion_nchars;
1720 if (i > 0
1721 ||
1722 (tem1 = Fcompare_strings (tem, make_number (0),
1723 make_number (buffer_nchars),
1724 completion, make_number (0),
1725 make_number (buffer_nchars),
1726 completion_ignore_case ? Qt : Qnil),
1727 ! EQ (tem1, Qt)))
f927c5ae 1728 {
69f4ef20
RS
1729 int start_pos;
1730
1731 /* Set buffer to longest match of buffer tail and completion head. */
1732 if (i <= 0) i = 1;
1733 start_pos= i;
1734 buffer_nchars -= i;
669c6673 1735 while (i > 0)
69f4ef20 1736 {
669c6673 1737 tem1 = Fcompare_strings (tem, make_number (start_pos), Qnil,
69f4ef20
RS
1738 completion, make_number (0),
1739 make_number (buffer_nchars),
1740 completion_ignore_case ? Qt : Qnil);
1741 start_pos++;
1742 if (EQ (tem1, Qt))
1743 break;
1744 i++;
669c6673 1745 buffer_nchars--;
69f4ef20
RS
1746 }
1747 del_range (1, i + 1);
a9c26562 1748 SET_PT_BOTH (ZV, ZV_BYTE);
f927c5ae 1749 }
d7be4211 1750 UNGCPRO;
f927c5ae
JB
1751 }
1752#endif /* Rewritten code */
af2b7cd5
RS
1753 i_byte = ZV_BYTE - BEGV_BYTE;
1754 i = ZV - BEGV;
f927c5ae
JB
1755
1756 /* If completion finds next char not unique,
b278606c 1757 consider adding a space or a hyphen. */
f927c5ae
JB
1758 if (i == XSTRING (completion)->size)
1759 {
b278606c 1760 GCPRO1 (completion);
f927c5ae
JB
1761 tem = Ftry_completion (concat2 (Fbuffer_string (), build_string (" ")),
1762 Vminibuffer_completion_table,
1763 Vminibuffer_completion_predicate);
b278606c
BF
1764 UNGCPRO;
1765
7510b296 1766 if (STRINGP (tem))
f927c5ae
JB
1767 completion = tem;
1768 else
1769 {
b278606c
BF
1770 GCPRO1 (completion);
1771 tem =
1772 Ftry_completion (concat2 (Fbuffer_string (), build_string ("-")),
1773 Vminibuffer_completion_table,
1774 Vminibuffer_completion_predicate);
1775 UNGCPRO;
1776
7510b296 1777 if (STRINGP (tem))
f927c5ae
JB
1778 completion = tem;
1779 }
1780 }
1781
1782 /* Now find first word-break in the stuff found by completion.
1783 i gets index in string of where to stop completing. */
d50a3d2a
KH
1784 {
1785 int len, c;
b278606c 1786
d50a3d2a 1787 completion_string = XSTRING (completion)->data;
fc932ac6 1788 for (; i_byte < STRING_BYTES (XSTRING (completion)); i_byte += len, i++)
d50a3d2a 1789 {
af2b7cd5
RS
1790 c = STRING_CHAR_AND_LENGTH (completion_string + i_byte,
1791 XSTRING (completion)->size - i_byte,
d50a3d2a
KH
1792 len);
1793 if (SYNTAX (c) != Sword)
1794 {
af2b7cd5
RS
1795 i_byte += len;
1796 i++;
d50a3d2a
KH
1797 break;
1798 }
1799 }
1800 }
f927c5ae
JB
1801
1802 /* If got no characters, print help for user. */
1803
af2b7cd5 1804 if (i_byte == ZV_BYTE - BEGV_BYTE)
f927c5ae
JB
1805 {
1806 if (auto_help)
1807 Fminibuffer_completion_help ();
1808 return Qnil;
1809 }
1810
1811 /* Otherwise insert in minibuffer the chars we got */
1812
1813 Ferase_buffer ();
af2b7cd5 1814 insert_from_string (completion, 0, 0, i, i_byte, 1);
f927c5ae
JB
1815 return Qt;
1816}
1817\f
1818DEFUN ("display-completion-list", Fdisplay_completion_list, Sdisplay_completion_list,
1819 1, 1, 0,
2dc2b736 1820 "Display the list of completions, COMPLETIONS, using `standard-output'.\n\
f927c5ae 1821Each element may be just a symbol or string\n\
2d7e41fe
RS
1822or may be a list of two strings to be printed as if concatenated.\n\
1823`standard-output' must be a buffer.\n\
5744fa7c
RS
1824The actual completion alternatives, as inserted, are given `mouse-face'\n\
1825properties of `highlight'.\n\
1826At the end, this runs the normal hook `completion-setup-hook'.\n\
2d7e41fe 1827It can find the completion buffer in `standard-output'.")
f927c5ae
JB
1828 (completions)
1829 Lisp_Object completions;
1830{
dae36123 1831 Lisp_Object tail, elt;
f927c5ae 1832 register int i;
2dc2b736 1833 int column = 0;
dae36123 1834 struct gcpro gcpro1, gcpro2;
2dc2b736 1835 struct buffer *old = current_buffer;
681f5af4 1836 int first = 1;
486cc7fb
RS
1837
1838 /* Note that (when it matters) every variable
dae36123
RS
1839 points to a non-string that is pointed to by COMPLETIONS,
1840 except for ELT. ELT can be pointing to a string
1841 when terpri or Findent_to calls a change hook. */
1842 elt = Qnil;
1843 GCPRO2 (completions, elt);
486cc7fb 1844
7510b296 1845 if (BUFFERP (Vstandard_output))
2dc2b736 1846 set_buffer_internal (XBUFFER (Vstandard_output));
f927c5ae 1847
56a98455 1848 if (NILP (completions))
cfc736bf
RS
1849 write_string ("There are no possible completions of what you have typed.",
1850 -1);
f927c5ae
JB
1851 else
1852 {
2dc2b736 1853 write_string ("Possible completions are:", -1);
56a98455 1854 for (tail = completions, i = 0; !NILP (tail); tail = Fcdr (tail), i++)
f927c5ae 1855 {
ec067ec7 1856 Lisp_Object tem, string;
681f5af4 1857 int length;
47d7d104 1858 Lisp_Object startpos, endpos;
681f5af4
RS
1859
1860 elt = Fcar (tail);
1861 /* Compute the length of this element. */
1862 if (CONSP (elt))
1863 {
49db96ce 1864 tem = XCAR (elt);
681f5af4 1865 CHECK_STRING (tem, 0);
49db96ce 1866 length = XSTRING (tem)->size;
681f5af4 1867
49db96ce 1868 tem = Fcar (XCDR (elt));
681f5af4 1869 CHECK_STRING (tem, 0);
49db96ce 1870 length += XSTRING (tem)->size;
681f5af4
RS
1871 }
1872 else
1873 {
1874 CHECK_STRING (elt, 0);
49db96ce 1875 length = XSTRING (elt)->size;
681f5af4
RS
1876 }
1877
1878 /* This does a bad job for narrower than usual windows.
1879 Sadly, the window it will appear in is not known
1880 until after the text has been made. */
1881
47d7d104
RS
1882 if (BUFFERP (Vstandard_output))
1883 XSETINT (startpos, BUF_PT (XBUFFER (Vstandard_output)));
1884
681f5af4
RS
1885 /* If the previous completion was very wide,
1886 or we have two on this line already,
1887 don't put another on the same line. */
1888 if (column > 33 || first
1889 /* If this is really wide, don't put it second on a line. */
1890 || column > 0 && length > 45)
1891 {
1892 Fterpri (Qnil);
1893 column = 0;
1894 }
1895 /* Otherwise advance to column 35. */
1896 else
2dc2b736 1897 {
7510b296 1898 if (BUFFERP (Vstandard_output))
681f5af4
RS
1899 {
1900 tem = Findent_to (make_number (35), make_number (2));
47d7d104 1901
681f5af4
RS
1902 column = XINT (tem);
1903 }
2dc2b736
RS
1904 else
1905 {
1906 do
1907 {
1908 write_string (" ", -1);
1909 column++;
1910 }
1911 while (column < 35);
1912 }
1913 }
681f5af4 1914
47d7d104
RS
1915 if (BUFFERP (Vstandard_output))
1916 {
1917 XSETINT (endpos, BUF_PT (XBUFFER (Vstandard_output)));
1918 Fset_text_properties (startpos, endpos,
1919 Qnil, Vstandard_output);
1920 }
1921
ec067ec7 1922 /* Output this element.
9404446f 1923 If necessary, convert it to unibyte or to multibyte first. */
f927c5ae 1924 if (CONSP (elt))
ec067ec7 1925 string = Fcar (elt);
f927c5ae 1926 else
ec067ec7
RS
1927 string = elt;
1928 if (NILP (current_buffer->enable_multibyte_characters)
1929 && STRING_MULTIBYTE (string))
1930 string = Fstring_make_unibyte (string);
9404446f
RS
1931 else if (!NILP (current_buffer->enable_multibyte_characters)
1932 && !STRING_MULTIBYTE (string))
1933 string = Fstring_make_multibyte (string);
5744fa7c
RS
1934
1935 if (BUFFERP (Vstandard_output))
1936 {
4b37311e 1937 XSETINT (startpos, BUF_PT (XBUFFER (Vstandard_output)));
5744fa7c
RS
1938
1939 Fprinc (string, Qnil);
1940
4b37311e 1941 XSETINT (endpos, BUF_PT (XBUFFER (Vstandard_output)));
5744fa7c 1942
4b37311e 1943 Fput_text_property (startpos, endpos,
5744fa7c
RS
1944 Qmouse_face, intern ("highlight"),
1945 Vstandard_output);
1946 }
1947 else
1948 {
1949 Fprinc (string, Qnil);
1950 }
ec067ec7
RS
1951
1952 /* Output the annotation for this element. */
1953 if (CONSP (elt))
4b37311e
RS
1954 {
1955 if (BUFFERP (Vstandard_output))
1956 {
1957 XSETINT (startpos, BUF_PT (XBUFFER (Vstandard_output)));
1958
1959 Fprinc (Fcar (Fcdr (elt)), Qnil);
1960
1961 XSETINT (endpos, BUF_PT (XBUFFER (Vstandard_output)));
1962
1963 Fset_text_properties (startpos, endpos, Qnil,
1964 Vstandard_output);
1965 }
1966 else
1967 {
1968 Fprinc (Fcar (Fcdr (elt)), Qnil);
1969 }
1970 }
1971
681f5af4 1972
ec067ec7 1973 /* Update COLUMN for what we have output. */
681f5af4
RS
1974 column += length;
1975
1976 /* If output is to a buffer, recompute COLUMN in a way
1977 that takes account of character widths. */
1978 if (BUFFERP (Vstandard_output))
2dc2b736 1979 {
681f5af4
RS
1980 tem = Fcurrent_column ();
1981 column = XINT (tem);
2dc2b736 1982 }
681f5af4
RS
1983
1984 first = 0;
f927c5ae
JB
1985 }
1986 }
2dc2b736 1987
486cc7fb
RS
1988 UNGCPRO;
1989
7510b296 1990 if (BUFFERP (Vstandard_output))
2d7e41fe
RS
1991 set_buffer_internal (old);
1992
cfc736bf
RS
1993 if (!NILP (Vrun_hooks))
1994 call1 (Vrun_hooks, intern ("completion-setup-hook"));
1995
f927c5ae
JB
1996 return Qnil;
1997}
1998
1999DEFUN ("minibuffer-completion-help", Fminibuffer_completion_help, Sminibuffer_completion_help,
2000 0, 0, "",
2001 "Display a list of possible completions of the current minibuffer contents.")
2002 ()
2003{
2004 Lisp_Object completions;
2005
2006 message ("Making completion list...");
2007 completions = Fall_completions (Fbuffer_string (),
2008 Vminibuffer_completion_table,
89a255dc
RS
2009 Vminibuffer_completion_predicate,
2010 Qt);
f927c5ae
JB
2011 echo_area_glyphs = 0;
2012
56a98455 2013 if (NILP (completions))
f927c5ae
JB
2014 {
2015 bitch_at_user ();
2016 temp_echo_area_glyphs (" [No completions]");
2017 }
2018 else
2019 internal_with_output_to_temp_buffer ("*Completions*",
2020 Fdisplay_completion_list,
2021 Fsort (completions, Qstring_lessp));
2022 return Qnil;
2023}
2024\f
2025DEFUN ("self-insert-and-exit", Fself_insert_and_exit, Sself_insert_and_exit, 0, 0, "",
2026 "Terminate minibuffer input.")
2027 ()
2028{
7510b296 2029 if (INTEGERP (last_command_char))
dab3ab3c 2030 internal_self_insert (XINT (last_command_char), 0);
f927c5ae
JB
2031 else
2032 bitch_at_user ();
2033
2034 Fthrow (Qexit, Qnil);
2035}
2036
2037DEFUN ("exit-minibuffer", Fexit_minibuffer, Sexit_minibuffer, 0, 0, "",
2038 "Terminate this minibuffer argument.")
2039 ()
2040{
2041 Fthrow (Qexit, Qnil);
2042}
2043
2044DEFUN ("minibuffer-depth", Fminibuffer_depth, Sminibuffer_depth, 0, 0, 0,
2045 "Return current depth of activations of minibuffer, a nonnegative integer.")
2046 ()
2047{
2048 return make_number (minibuf_level);
2049}
2050
37e9a934
KH
2051DEFUN ("minibuffer-prompt", Fminibuffer_prompt, Sminibuffer_prompt, 0, 0, 0,
2052 "Return the prompt string of the currently-active minibuffer.\n\
2053If no minibuffer is active, return nil.")
2054 ()
2055{
4d04c1f1 2056 return Fcopy_sequence (minibuf_prompt);
37e9a934
KH
2057}
2058
2059DEFUN ("minibuffer-prompt-width", Fminibuffer_prompt_width,
2060 Sminibuffer_prompt_width, 0, 0, 0,
c5896ef4 2061 "Return the display width of the minibuffer prompt.")
37e9a934
KH
2062 ()
2063{
2064 Lisp_Object width;
5a866662 2065 XSETFASTINT (width, minibuf_prompt_width);
37e9a934
KH
2066 return width;
2067}
f927c5ae 2068\f
2d955a50
RS
2069/* Temporarily display the string M at the end of the current
2070 minibuffer contents. This is used to display things like
2071 "[No Match]" when the user requests a completion for a prefix
2072 that has no possible completions, and other quick, unobtrusive
2073 messages. */
2074
9d815fd9 2075void
2d955a50
RS
2076temp_echo_area_glyphs (m)
2077 char *m;
2078{
2079 int osize = ZV;
a9c26562 2080 int osize_byte = ZV_BYTE;
2d955a50 2081 int opoint = PT;
a9c26562 2082 int opoint_byte = PT_BYTE;
2d955a50
RS
2083 Lisp_Object oinhibit;
2084 oinhibit = Vinhibit_quit;
2085
2086 /* Clear out any old echo-area message to make way for our new thing. */
2087 message (0);
2088
a9c26562 2089 SET_PT_BOTH (osize, osize_byte);
2d955a50 2090 insert_string (m);
a9c26562 2091 SET_PT_BOTH (opoint, opoint_byte);
2d955a50
RS
2092 Vinhibit_quit = Qt;
2093 Fsit_for (make_number (2), Qnil, Qnil);
bc69581b 2094 del_range_both (osize, osize_byte, ZV, ZV_BYTE, 1);
a9c26562 2095 SET_PT_BOTH (opoint, opoint_byte);
2d955a50
RS
2096 if (!NILP (Vquit_flag))
2097 {
2098 Vquit_flag = Qnil;
2099 Vunread_command_events = Fcons (make_number (quit_char), Qnil);
2100 }
2101 Vinhibit_quit = oinhibit;
2102}
2103
2104DEFUN ("minibuffer-message", Fminibuffer_message, Sminibuffer_message,
2105 1, 1, 0,
2106 "Temporarily display STRING at the end of the minibuffer.\n\
2107The text is displayed for two seconds,\n\
2108or until the next input event arrives, whichever comes first.")
2109 (string)
2110 Lisp_Object string;
2111{
2112 temp_echo_area_glyphs (XSTRING (string)->data);
2113 return Qnil;
2114}
2115\f
9d815fd9 2116void
f927c5ae
JB
2117init_minibuf_once ()
2118{
2119 Vminibuffer_list = Qnil;
2120 staticpro (&Vminibuffer_list);
2121}
2122
9d815fd9 2123void
f927c5ae
JB
2124syms_of_minibuf ()
2125{
2126 minibuf_level = 0;
4d04c1f1
KH
2127 minibuf_prompt = Qnil;
2128 staticpro (&minibuf_prompt);
2129
2130 minibuf_save_list = Qnil;
2131 staticpro (&minibuf_save_list);
f927c5ae 2132
719b4a40
RS
2133 Qread_file_name_internal = intern ("read-file-name-internal");
2134 staticpro (&Qread_file_name_internal);
2135
e5d4686b
RS
2136 Qminibuffer_default = intern ("minibuffer-default");
2137 staticpro (&Qminibuffer_default);
2138 Fset (Qminibuffer_default, Qnil);
2139
f927c5ae
JB
2140 Qminibuffer_completion_table = intern ("minibuffer-completion-table");
2141 staticpro (&Qminibuffer_completion_table);
2142
2143 Qminibuffer_completion_confirm = intern ("minibuffer-completion-confirm");
2144 staticpro (&Qminibuffer_completion_confirm);
2145
2146 Qminibuffer_completion_predicate = intern ("minibuffer-completion-predicate");
2147 staticpro (&Qminibuffer_completion_predicate);
2148
1e00c2ff
KH
2149 staticpro (&last_exact_completion);
2150 last_exact_completion = Qnil;
2151
f927c5ae
JB
2152 staticpro (&last_minibuf_string);
2153 last_minibuf_string = Qnil;
2154
2155 Quser_variable_p = intern ("user-variable-p");
2156 staticpro (&Quser_variable_p);
2157
770970cb
RS
2158 Qminibuffer_history = intern ("minibuffer-history");
2159 staticpro (&Qminibuffer_history);
f927c5ae 2160
406e55df
RS
2161 Qbuffer_name_history = intern ("buffer-name-history");
2162 staticpro (&Qbuffer_name_history);
33d0a17f 2163 Fset (Qbuffer_name_history, Qnil);
406e55df 2164
5c781212
RS
2165 Qminibuffer_setup_hook = intern ("minibuffer-setup-hook");
2166 staticpro (&Qminibuffer_setup_hook);
2167
177aecf9
KH
2168 Qminibuffer_exit_hook = intern ("minibuffer-exit-hook");
2169 staticpro (&Qminibuffer_exit_hook);
2170
77aa8edf
RS
2171 Qhistory_length = intern ("history-length");
2172 staticpro (&Qhistory_length);
2173
cee54539
KH
2174 Qcurrent_input_method = intern ("current-input-method");
2175 staticpro (&Qcurrent_input_method);
2176
2177 Qactivate_input_method = intern ("activate-input-method");
2178 staticpro (&Qactivate_input_method);
2179
eebbfb01
KH
2180 DEFVAR_LISP ("read-buffer-function", &Vread_buffer_function,
2181 "If this is non-nil, `read-buffer' does its work by calling this function.");
2182 Vread_buffer_function = Qnil;
2183
5c781212
RS
2184 DEFVAR_LISP ("minibuffer-setup-hook", &Vminibuffer_setup_hook,
2185 "Normal hook run just after entry to minibuffer.");
2186 Vminibuffer_setup_hook = Qnil;
2187
177aecf9
KH
2188 DEFVAR_LISP ("minibuffer-exit-hook", &Vminibuffer_exit_hook,
2189 "Normal hook run just after exit from minibuffer.");
2190 Vminibuffer_exit_hook = Qnil;
2191
77aa8edf
RS
2192 DEFVAR_LISP ("history-length", &Vhistory_length,
2193 "*Maximum length for history lists before truncation takes place.\n\
2194A number means that length; t means infinite. Truncation takes place\n\
2195just after a new element is inserted. Setting the history-length\n\
2196property of a history variable overrides this default.");
2197 XSETFASTINT (Vhistory_length, 30);
2198
f927c5ae
JB
2199 DEFVAR_BOOL ("completion-auto-help", &auto_help,
2200 "*Non-nil means automatically provide help for invalid completion input.");
2201 auto_help = 1;
2202
2203 DEFVAR_BOOL ("completion-ignore-case", &completion_ignore_case,
2204 "Non-nil means don't consider case significant in completion.");
2205 completion_ignore_case = 0;
2206
2207 DEFVAR_BOOL ("enable-recursive-minibuffers", &enable_recursive_minibuffers,
2208 "*Non-nil means to allow minibuffer commands while in the minibuffer.\n\
7e3e3ad1 2209This variable makes a difference whenever the minibuffer window is active.");
f927c5ae
JB
2210 enable_recursive_minibuffers = 0;
2211
2212 DEFVAR_LISP ("minibuffer-completion-table", &Vminibuffer_completion_table,
2213 "Alist or obarray used for completion in the minibuffer.\n\
2214This becomes the ALIST argument to `try-completion' and `all-completion'.\n\
2215\n\
2216The value may alternatively be a function, which is given three arguments:\n\
2217 STRING, the current buffer contents;\n\
2218 PREDICATE, the predicate for filtering possible matches;\n\
2219 CODE, which says what kind of things to do.\n\
2220CODE can be nil, t or `lambda'.\n\
2221nil means to return the best completion of STRING, or nil if there is none.\n\
2222t means to return a list of all possible completions of STRING.\n\
2223`lambda' means to return t if STRING is a valid completion as it stands.");
2224 Vminibuffer_completion_table = Qnil;
2225
2226 DEFVAR_LISP ("minibuffer-completion-predicate", &Vminibuffer_completion_predicate,
2227 "Within call to `completing-read', this holds the PREDICATE argument.");
2228 Vminibuffer_completion_predicate = Qnil;
2229
2230 DEFVAR_LISP ("minibuffer-completion-confirm", &Vminibuffer_completion_confirm,
2231 "Non-nil => demand confirmation of completion before exiting minibuffer.");
2232 Vminibuffer_completion_confirm = Qnil;
2233
ccf330a6
RS
2234 DEFVAR_LISP ("minibuffer-completing-file-name",
2235 &Vminibuffer_completing_file_name,
2236 "Non-nil means completing file names.");
2237 Vminibuffer_completing_file_name = Qnil;
2238
f927c5ae
JB
2239 DEFVAR_LISP ("minibuffer-help-form", &Vminibuffer_help_form,
2240 "Value that `help-form' takes on inside the minibuffer.");
2241 Vminibuffer_help_form = Qnil;
2242
770970cb
RS
2243 DEFVAR_LISP ("minibuffer-history-variable", &Vminibuffer_history_variable,
2244 "History list symbol to add minibuffer values to.\n\
2fa2413b
RS
2245Each string of minibuffer input, as it appears on exit from the minibuffer,\n\
2246is added with\n\
770970cb
RS
2247 (set minibuffer-history-variable\n\
2248 (cons STRING (symbol-value minibuffer-history-variable)))");
5a866662 2249 XSETFASTINT (Vminibuffer_history_variable, 0);
770970cb
RS
2250
2251 DEFVAR_LISP ("minibuffer-history-position", &Vminibuffer_history_position,
2252 "Current position of redoing in the history list.");
2253 Vminibuffer_history_position = Qnil;
2254
6a9ee000 2255 DEFVAR_BOOL ("minibuffer-auto-raise", &minibuffer_auto_raise,
e98bcc1a
RS
2256 "*Non-nil means entering the minibuffer raises the minibuffer's frame.\n\
2257Some uses of the echo area also raise that frame (since they use it too).");
6a9ee000
RS
2258 minibuffer_auto_raise = 0;
2259
42006772
RS
2260 DEFVAR_LISP ("completion-regexp-list", &Vcompletion_regexp_list,
2261 "List of regexps that should restrict possible completions.");
2262 Vcompletion_regexp_list = Qnil;
2263
c3421833
RS
2264 DEFVAR_BOOL ("minibuffer-allow-text-properties",
2265 &minibuffer_allow_text_properties,
e9cccb71 2266 "Non-nil means `read-from-minibuffer' should not discard text properties.\n\
c3421833
RS
2267This also affects `read-string', but it does not affect `read-minibuffer',\n\
2268`read-no-blanks-input', or any of the functions that do minibuffer input\n\
2bfbde2b 2269with completion; they always discard text properties.");
c3421833
RS
2270 minibuffer_allow_text_properties = 0;
2271
68313ed8 2272 defsubr (&Sset_minibuffer_window);
f927c5ae
JB
2273 defsubr (&Sread_from_minibuffer);
2274 defsubr (&Seval_minibuffer);
2275 defsubr (&Sread_minibuffer);
2276 defsubr (&Sread_string);
2277 defsubr (&Sread_command);
2278 defsubr (&Sread_variable);
2279 defsubr (&Sread_buffer);
2280 defsubr (&Sread_no_blanks_input);
2281 defsubr (&Sminibuffer_depth);
37e9a934
KH
2282 defsubr (&Sminibuffer_prompt);
2283 defsubr (&Sminibuffer_prompt_width);
f927c5ae
JB
2284
2285 defsubr (&Stry_completion);
2286 defsubr (&Sall_completions);
2287 defsubr (&Scompleting_read);
2288 defsubr (&Sminibuffer_complete);
2289 defsubr (&Sminibuffer_complete_word);
2290 defsubr (&Sminibuffer_complete_and_exit);
2291 defsubr (&Sdisplay_completion_list);
2292 defsubr (&Sminibuffer_completion_help);
2293
2294 defsubr (&Sself_insert_and_exit);
2295 defsubr (&Sexit_minibuffer);
2296
2d955a50 2297 defsubr (&Sminibuffer_message);
f927c5ae
JB
2298}
2299
9d815fd9 2300void
f927c5ae
JB
2301keys_of_minibuf ()
2302{
2303 initial_define_key (Vminibuffer_local_map, Ctl ('g'),
2304 "abort-recursive-edit");
2305 initial_define_key (Vminibuffer_local_map, Ctl ('m'),
2306 "exit-minibuffer");
2307 initial_define_key (Vminibuffer_local_map, Ctl ('j'),
2308 "exit-minibuffer");
2309
2310 initial_define_key (Vminibuffer_local_ns_map, Ctl ('g'),
2311 "abort-recursive-edit");
2312 initial_define_key (Vminibuffer_local_ns_map, Ctl ('m'),
2313 "exit-minibuffer");
2314 initial_define_key (Vminibuffer_local_ns_map, Ctl ('j'),
2315 "exit-minibuffer");
2316
2317 initial_define_key (Vminibuffer_local_ns_map, ' ',
2318 "exit-minibuffer");
2319 initial_define_key (Vminibuffer_local_ns_map, '\t',
2320 "exit-minibuffer");
2321 initial_define_key (Vminibuffer_local_ns_map, '?',
2322 "self-insert-and-exit");
2323
2324 initial_define_key (Vminibuffer_local_completion_map, Ctl ('g'),
2325 "abort-recursive-edit");
2326 initial_define_key (Vminibuffer_local_completion_map, Ctl ('m'),
2327 "exit-minibuffer");
2328 initial_define_key (Vminibuffer_local_completion_map, Ctl ('j'),
2329 "exit-minibuffer");
2330
2331 initial_define_key (Vminibuffer_local_completion_map, '\t',
2332 "minibuffer-complete");
2333 initial_define_key (Vminibuffer_local_completion_map, ' ',
2334 "minibuffer-complete-word");
2335 initial_define_key (Vminibuffer_local_completion_map, '?',
2336 "minibuffer-completion-help");
2337
2338 initial_define_key (Vminibuffer_local_must_match_map, Ctl ('g'),
2339 "abort-recursive-edit");
2340 initial_define_key (Vminibuffer_local_must_match_map, Ctl ('m'),
2341 "minibuffer-complete-and-exit");
2342 initial_define_key (Vminibuffer_local_must_match_map, Ctl ('j'),
2343 "minibuffer-complete-and-exit");
2344 initial_define_key (Vminibuffer_local_must_match_map, '\t',
2345 "minibuffer-complete");
2346 initial_define_key (Vminibuffer_local_must_match_map, ' ',
2347 "minibuffer-complete-word");
2348 initial_define_key (Vminibuffer_local_must_match_map, '?',
2349 "minibuffer-completion-help");
2350}