*** empty log message ***
[bpt/emacs.git] / src / minibuf.c
CommitLineData
f927c5ae 1/* Minibuffer input and completion.
ffd56f97 2 Copyright (C) 1985, 1986, 1992 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
21#include "config.h"
22#include "lisp.h"
23#include "commands.h"
24#include "buffer.h"
25#include "dispextern.h"
ff11dfa1 26#include "frame.h"
f927c5ae
JB
27#include "window.h"
28#include "syntax.h"
29
30#define min(a, b) ((a) < (b) ? (a) : (b))
31
32/* List of buffers for use as minibuffers.
33 The first element of the list is used for the outermost minibuffer invocation,
34 the next element is used for a recursive minibuffer invocation, etc.
35 The list is extended at the end as deeped minibuffer recursions are encountered. */
36Lisp_Object Vminibuffer_list;
37
38struct minibuf_save_data
39 {
40 char *prompt;
41 int prompt_width;
42 Lisp_Object help_form;
43 Lisp_Object current_prefix_arg;
44 };
45
46int minibuf_save_vector_size;
47struct minibuf_save_data *minibuf_save_vector;
48
49/* Depth in minibuffer invocations. */
50int minibuf_level;
51
52/* Nonzero means display completion help for invalid input */
53int auto_help;
54
55/* Fread_minibuffer leaves the input, as a string, here */
56Lisp_Object last_minibuf_string;
57
58/* Nonzero means let functions called when within a minibuffer
59 invoke recursive minibuffers (to read arguments, or whatever) */
60int enable_recursive_minibuffers;
61
62/* help-form is bound to this while in the minibuffer. */
63
64Lisp_Object Vminibuffer_help_form;
65
66/* Nonzero means completion ignores case. */
67
68int completion_ignore_case;
69
70/* If last completion attempt reported "Complete but not unique"
71 then this is the string completed then; otherwise this is nil. */
72
73static Lisp_Object last_exact_completion;
74
75Lisp_Object Quser_variable_p;
76
f927c5ae
JB
77\f
78/* Actual minibuffer invocation. */
79
80void read_minibuf_unwind ();
81Lisp_Object get_minibuffer ();
82Lisp_Object read_minibuf ();
83
84Lisp_Object
85read_minibuf (map, initial, prompt, backup_n, expflag)
86 Lisp_Object map;
87 Lisp_Object initial;
88 Lisp_Object prompt;
89 Lisp_Object backup_n;
90 int expflag;
91{
92 register Lisp_Object val;
93 int count = specpdl_ptr - specpdl;
ff11dfa1 94 Lisp_Object mini_frame = WINDOW_FRAME (XWINDOW (minibuf_window));
f927c5ae 95 struct gcpro gcpro1, gcpro2;
f927c5ae
JB
96
97 if (XTYPE (prompt) != Lisp_String)
98 prompt = build_string ("");
99
100 /* Emacs in -batch mode calls minibuffer: print the prompt. */
101 if (noninteractive && XTYPE (prompt) == Lisp_String)
102 printf ("%s", XSTRING (prompt)->data);
103
104 if (!enable_recursive_minibuffers
105 && minibuf_level > 0
106 && (EQ (selected_window, minibuf_window)))
107#if 0
ff11dfa1 108 || selected_frame != XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window)))
f927c5ae
JB
109#endif
110 error ("Command attempted to use minibuffer while in minibuffer");
111
112 if (minibuf_level == minibuf_save_vector_size)
113 minibuf_save_vector =
114 (struct minibuf_save_data *)
115 xrealloc (minibuf_save_vector,
116 (minibuf_save_vector_size *= 2)
117 * sizeof (struct minibuf_save_data));
118 minibuf_save_vector[minibuf_level].prompt = minibuf_prompt;
119 minibuf_save_vector[minibuf_level].prompt_width = minibuf_prompt_width;
120 minibuf_prompt_width = 0;
121 /* >> Why is this done this way rather than binding these variables? */
122 minibuf_save_vector[minibuf_level].help_form = Vhelp_form;
123 minibuf_save_vector[minibuf_level].current_prefix_arg = Vcurrent_prefix_arg;
124 GCPRO2 (minibuf_save_vector[minibuf_level].help_form,
125 minibuf_save_vector[minibuf_level].current_prefix_arg);
126
127 record_unwind_protect (Fset_window_configuration,
b2b2c677
JB
128 Fcurrent_window_configuration (Qnil));
129
ff11dfa1
JB
130 /* If the minibuffer window is on a different frame, save that
131 frame's configuration too. */
132 if (XFRAME (mini_frame) != selected_frame)
43bad991
JB
133 {
134 record_unwind_protect (Fset_window_configuration,
ff11dfa1 135 Fcurrent_window_configuration (mini_frame));
43bad991 136 }
f927c5ae
JB
137
138 val = current_buffer->directory;
139 Fset_buffer (get_minibuffer (minibuf_level));
140 current_buffer->directory = val;
141 Fmake_local_variable (Qprint_escape_newlines);
142 print_escape_newlines = 1;
143
ff11dfa1
JB
144#ifdef MULTI_FRAME
145 /* If the minibuffer window is on another frame, shift this frame's
43bad991 146 focus to that window, and arrange to put it back later. */
ff11dfa1
JB
147 if (XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window)))
148 != selected_frame)
43bad991
JB
149 {
150 record_unwind_protect (read_minibuf_unwind,
ff11dfa1
JB
151 Fcons (Fselected_frame (),
152 FRAME_FOCUS_FRAME (selected_frame)));
43bad991 153
ff11dfa1 154 Fredirect_frame_focus (Fselected_frame (), mini_frame);
43bad991
JB
155 }
156 else
157 record_unwind_protect (read_minibuf_unwind, Qnil);
158#else
159 record_unwind_protect (read_minibuf_unwind, Qnil);
160#endif
161
f927c5ae
JB
162 Vminibuf_scroll_window = selected_window;
163 Fset_window_buffer (minibuf_window, Fcurrent_buffer ());
f927c5ae
JB
164 Fselect_window (minibuf_window);
165 XFASTINT (XWINDOW (minibuf_window)->hscroll) = 0;
166
167 Ferase_buffer ();
168 minibuf_level++;
f927c5ae 169
56a98455 170 if (!NILP (initial))
f927c5ae
JB
171 {
172 Finsert (1, &initial);
56a98455 173 if (!NILP (backup_n) && XTYPE (backup_n) == Lisp_Int)
f927c5ae
JB
174 Fforward_char (backup_n);
175 }
176
177 minibuf_prompt = (char *) alloca (XSTRING (prompt)->size + 1);
178 bcopy (XSTRING (prompt)->data, minibuf_prompt, XSTRING (prompt)->size + 1);
179 echo_area_glyphs = 0;
180
181 Vhelp_form = Vminibuffer_help_form;
182 current_buffer->keymap = map;
183
184/* ??? MCC did redraw_screen here if switching screens. */
185 recursive_edit_1 ();
186
187 /* If cursor is on the minibuffer line,
188 show the user we have exited by putting it in column 0. */
ff11dfa1 189 if ((FRAME_CURSOR_Y (selected_frame)
f927c5ae
JB
190 >= XFASTINT (XWINDOW (minibuf_window)->top))
191 && !noninteractive)
192 {
ff11dfa1
JB
193 FRAME_CURSOR_X (selected_frame) = 0;
194 update_frame (selected_frame, 1, 1);
f927c5ae
JB
195 }
196
197 /* Make minibuffer contents into a string */
ffd56f97 198 val = make_buffer_string (1, Z);
f927c5ae 199 bcopy (GAP_END_ADDR, XSTRING (val)->data + GPT - BEG, Z - GPT);
ff11dfa1 200 unbind_to (count, Qnil); /* The appropriate frame will get selected
43bad991 201 in set-window-configuration. */
f927c5ae
JB
202
203 UNGCPRO;
204
205 /* VAL is the string of minibuffer text. */
206
207 last_minibuf_string = val;
208
209 /* If Lisp form desired instead of string, parse it */
210 if (expflag)
211 val = Fread (val);
212
f927c5ae
JB
213 return val;
214}
215
216/* Return a buffer to be used as the minibuffer at depth `depth'.
217 depth = 0 is the lowest allowed argument, and that is the value
218 used for nonrecursive minibuffer invocations */
219
220Lisp_Object
221get_minibuffer (depth)
222 int depth;
223{
224 Lisp_Object tail, num, buf;
225 char name[14];
226 extern Lisp_Object nconc2 ();
227
228 XFASTINT (num) = depth;
229 tail = Fnthcdr (num, Vminibuffer_list);
56a98455 230 if (NILP (tail))
f927c5ae
JB
231 {
232 tail = Fcons (Qnil, Qnil);
233 Vminibuffer_list = nconc2 (Vminibuffer_list, tail);
234 }
235 buf = Fcar (tail);
56a98455 236 if (NILP (buf) || NILP (XBUFFER (buf)->name))
f927c5ae
JB
237 {
238 sprintf (name, " *Minibuf-%d*", depth);
239 buf = Fget_buffer_create (build_string (name));
240 XCONS (tail)->car = buf;
241 }
242 else
243 reset_buffer (XBUFFER (buf));
244 return buf;
245}
246
247/* This function is called on exiting minibuffer, whether normally or not,
248 and it restores the current window, buffer, etc. */
249
250void
43bad991
JB
251read_minibuf_unwind (data)
252 Lisp_Object data;
f927c5ae
JB
253{
254 /* Erase the minibuffer we were using at this level. */
255 Fset_buffer (XWINDOW (minibuf_window)->buffer);
256
257 /* Prevent error in erase-buffer. */
258 current_buffer->read_only = Qnil;
259 Ferase_buffer ();
260
261 /* If this was a recursive minibuffer,
262 tie the minibuffer window back to the outer level minibuffer buffer */
263 minibuf_level--;
264 /* Make sure minibuffer window is erased, not ignored */
265 windows_or_buffers_changed++;
266 XFASTINT (XWINDOW (minibuf_window)->last_modified) = 0;
267
268 /* Restore prompt from outer minibuffer */
269 minibuf_prompt = minibuf_save_vector[minibuf_level].prompt;
270 minibuf_prompt_width = minibuf_save_vector[minibuf_level].prompt_width;
271 Vhelp_form = minibuf_save_vector[minibuf_level].help_form;
272 Vcurrent_prefix_arg = minibuf_save_vector[minibuf_level].current_prefix_arg;
43bad991 273
ff11dfa1
JB
274#ifdef MULTI_FRAME
275 /* Redirect the focus of the frame that called the minibuffer. */
43bad991 276 if (CONSP (data))
ff11dfa1 277 Fredirect_frame_focus (XCONS (data)->car, XCONS (data)->cdr);
43bad991 278#endif
f927c5ae
JB
279}
280\f
281DEFUN ("read-from-minibuffer", Fread_from_minibuffer, Sread_from_minibuffer, 1, 5, 0,
282 "Read a string from the minibuffer, prompting with string PROMPT.\n\
283If optional second arg INITIAL-CONTENTS is non-nil, it is a string\n\
284 to be inserted into the minibuffer before reading input.\n\
285Third arg KEYMAP is a keymap to use whilst reading;\n\
286 if omitted or nil, the default is `minibuffer-local-map'.\n\
287If fourth arg READ is non-nil, then interpret the result as a lisp object\n\
288 and return that object:\n\
289 in other words, do `(car (read-from-string INPUT-STRING))'\n\
290Fifth arg POSITION, if non-nil, is where to put point\n\
291 in the minibuffer after inserting INITIAL-CONTENTS.")
292 (prompt, initial_input, keymap, read, position)
293 Lisp_Object prompt, initial_input, keymap, read, position;
294{
295 int pos = 0;
296
297 CHECK_STRING (prompt, 0);
56a98455 298 if (!NILP (initial_input))
f927c5ae
JB
299 {
300 CHECK_STRING (initial_input, 1);
56a98455 301 if (!NILP (position))
f927c5ae
JB
302 {
303 CHECK_NUMBER (position, 0);
304 /* Convert to distance from end of input. */
305 pos = XINT (position) - 1 - XSTRING (initial_input)->size;
306 }
307 }
308
56a98455 309 if (NILP (keymap))
f927c5ae
JB
310 keymap = Vminibuffer_local_map;
311 else
312 keymap = get_keymap (keymap,2);
313 return read_minibuf (keymap, initial_input, prompt,
56a98455 314 pos, !NILP (read));
f927c5ae
JB
315}
316
317DEFUN ("read-minibuffer", Fread_minibuffer, Sread_minibuffer, 1, 2, 0,
318 "Return a Lisp object read using the minibuffer.\n\
319Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS\n\
320is a string to insert in the minibuffer before reading.")
321 (prompt, initial_contents)
322 Lisp_Object prompt, initial_contents;
323{
324 CHECK_STRING (prompt, 0);
56a98455 325 if (!NILP (initial_contents))
f927c5ae
JB
326 CHECK_STRING (initial_contents, 1)
327 return read_minibuf (Vminibuffer_local_map, initial_contents, prompt, Qnil, 1);
328}
329
330DEFUN ("eval-minibuffer", Feval_minibuffer, Seval_minibuffer, 1, 2, 0,
331 "Return value of Lisp expression read using the minibuffer.\n\
332Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS\n\
333is a string to insert in the minibuffer before reading.")
334 (prompt, initial_contents)
335 Lisp_Object prompt, initial_contents;
336{
337 return Feval (Fread_minibuffer (prompt, initial_contents));
338}
339
340/* Functions that use the minibuffer to read various things. */
341
342DEFUN ("read-string", Fread_string, Sread_string, 1, 2, 0,
343 "Read a string from the minibuffer, prompting with string PROMPT.\n\
344If non-nil second arg INITIAL-INPUT is a string to insert before reading.")
345 (prompt, initial_input)
346 Lisp_Object prompt, initial_input;
347{
348 return Fread_from_minibuffer (prompt, initial_input, Qnil, Qnil, Qnil);
349}
350
e5d77022 351DEFUN ("read-no-blanks-input", Fread_no_blanks_input, Sread_no_blanks_input, 2, 2, 0,
f927c5ae
JB
352 "Args PROMPT and INIT, strings. Read a string from the terminal, not allowing blanks.\n\
353Prompt with PROMPT, and provide INIT as an initial value of the input string.")
354 (prompt, init)
355 Lisp_Object prompt, init;
356{
357 CHECK_STRING (prompt, 0);
56a98455 358 if (! NILP (init))
f927c5ae
JB
359 CHECK_STRING (init, 1);
360
361 return read_minibuf (Vminibuffer_local_ns_map, init, prompt, Qnil, 0);
362}
363
364DEFUN ("read-command", Fread_command, Sread_command, 1, 1, 0,
365 "One arg PROMPT, a string. Read the name of a command and return as a symbol.\n\
366Prompts with PROMPT.")
367 (prompt)
368 Lisp_Object prompt;
369{
370 return Fintern (Fcompleting_read (prompt, Vobarray, Qcommandp, Qt, Qnil, Qnil),
371 Qnil);
372}
373
374#ifdef NOTDEF
375DEFUN ("read-function", Fread_function, Sread_function, 1, 1, 0,
376 "One arg PROMPT, a string. Read the name of a function and return as a symbol.\n\
377Prompts with PROMPT.")
378 (prompt)
379 Lisp_Object prompt;
380{
381 return Fintern (Fcompleting_read (prompt, Vobarray, Qfboundp, Qt, Qnil, Qnil),
382 Qnil);
383}
384#endif /* NOTDEF */
385
386DEFUN ("read-variable", Fread_variable, Sread_variable, 1, 1, 0,
387 "One arg PROMPT, a string. Read the name of a user variable and return\n\
388it as a symbol. Prompts with PROMPT.\n\
389A user variable is one whose documentation starts with a `*' character.")
390 (prompt)
391 Lisp_Object prompt;
392{
393 return Fintern (Fcompleting_read (prompt, Vobarray,
394 Quser_variable_p, Qt, Qnil, Qnil),
395 Qnil);
396}
397
398DEFUN ("read-buffer", Fread_buffer, Sread_buffer, 1, 3, 0,
399 "One arg PROMPT, a string. Read the name of a buffer and return as a string.\n\
400Prompts with PROMPT.\n\
401Optional second arg is value to return if user enters an empty line.\n\
402If optional third arg REQUIRE-MATCH is non-nil, only existing buffer names are allowed.")
403 (prompt, def, require_match)
404 Lisp_Object prompt, def, require_match;
405{
406 Lisp_Object tem;
407 Lisp_Object args[3];
408 struct gcpro gcpro1;
409
410 if (XTYPE (def) == Lisp_Buffer)
411 def = XBUFFER (def)->name;
56a98455 412 if (!NILP (def))
f927c5ae
JB
413 {
414 args[0] = build_string ("%s(default %s) ");
415 args[1] = prompt;
416 args[2] = def;
417 prompt = Fformat (3, args);
418 }
419 GCPRO1 (def);
420 tem = Fcompleting_read (prompt, Vbuffer_alist, Qnil, require_match, Qnil, Qnil);
421 UNGCPRO;
422 if (XSTRING (tem)->size)
423 return tem;
424 return def;
425}
426\f
427DEFUN ("try-completion", Ftry_completion, Stry_completion, 2, 3, 0,
428 "Return common substring of all completions of STRING in ALIST.\n\
429Each car of each element of ALIST is tested to see if it begins with STRING.\n\
430All that match are compared together; the longest initial sequence\n\
431common to all matches is returned as a string.\n\
432If there is no match at all, nil is returned.\n\
433For an exact match, t is returned.\n\
434\n\
435ALIST can be an obarray instead of an alist.\n\
436Then the print names of all symbols in the obarray are the possible matches.\n\
437\n\
438ALIST can also be a function to do the completion itself.\n\
439It receives three arguments: the values STRING, PREDICATE and nil.\n\
440Whatever it returns becomes the value of `try-completion'.\n\
441\n\
442If optional third argument PREDICATE is non-nil,\n\
443it is used to test each possible match.\n\
444The match is a candidate only if PREDICATE returns non-nil.\n\
445The argument given to PREDICATE is the alist element or the symbol from the obarray.")
446 (string, alist, pred)
447 Lisp_Object string, alist, pred;
448{
449 Lisp_Object bestmatch, tail, elt, eltstring;
450 int bestmatchsize;
451 int compare, matchsize;
56a98455 452 int list = CONSP (alist) || NILP (alist);
f927c5ae
JB
453 int index, obsize;
454 int matchcount = 0;
455 Lisp_Object bucket, zero, end, tem;
456 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
457
458 CHECK_STRING (string, 0);
459 if (!list && XTYPE (alist) != Lisp_Vector)
460 return call3 (alist, string, pred, Qnil);
461
462 bestmatch = Qnil;
463
464 /* If ALIST is not a list, set TAIL just for gc pro. */
465 tail = alist;
466 if (! list)
467 {
468 index = 0;
469 obsize = XVECTOR (alist)->size;
470 bucket = XVECTOR (alist)->contents[index];
471 }
472
473 while (1)
474 {
475 /* Get the next element of the alist or obarray. */
476 /* Exit the loop if the elements are all used up. */
477 /* elt gets the alist element or symbol.
478 eltstring gets the name to check as a completion. */
479
480 if (list)
481 {
56a98455 482 if (NILP (tail))
f927c5ae
JB
483 break;
484 elt = Fcar (tail);
485 eltstring = Fcar (elt);
486 tail = Fcdr (tail);
487 }
488 else
489 {
490 if (XFASTINT (bucket) != 0)
491 {
492 elt = bucket;
493 eltstring = Fsymbol_name (elt);
494 if (XSYMBOL (bucket)->next)
495 XSETSYMBOL (bucket, XSYMBOL (bucket)->next);
496 else
497 XFASTINT (bucket) = 0;
498 }
499 else if (++index >= obsize)
500 break;
501 else
502 {
503 bucket = XVECTOR (alist)->contents[index];
504 continue;
505 }
506 }
507
508 /* Is this element a possible completion? */
509
510 if (XTYPE (eltstring) == Lisp_String &&
511 XSTRING (string)->size <= XSTRING (eltstring)->size &&
512 0 > scmp (XSTRING (eltstring)->data, XSTRING (string)->data,
513 XSTRING (string)->size))
514 {
515 /* Yes. */
516 /* Ignore this element if there is a predicate
517 and the predicate doesn't like it. */
518
56a98455 519 if (!NILP (pred))
f927c5ae
JB
520 {
521 if (EQ (pred, Qcommandp))
522 tem = Fcommandp (elt);
523 else
524 {
525 GCPRO4 (tail, string, eltstring, bestmatch);
526 tem = call1 (pred, elt);
527 UNGCPRO;
528 }
56a98455 529 if (NILP (tem)) continue;
f927c5ae
JB
530 }
531
532 /* Update computation of how much all possible completions match */
533
534 matchcount++;
56a98455 535 if (NILP (bestmatch))
f927c5ae
JB
536 bestmatch = eltstring, bestmatchsize = XSTRING (eltstring)->size;
537 else
538 {
539 compare = min (bestmatchsize, XSTRING (eltstring)->size);
540 matchsize = scmp (XSTRING (bestmatch)->data,
541 XSTRING (eltstring)->data,
542 compare);
52b14ac0
JB
543 if (matchsize < 0)
544 matchsize = compare;
545 if (completion_ignore_case)
546 {
547 /* If this is an exact match except for case,
548 use it as the best match rather than one that is not an
549 exact match. This way, we get the case pattern
550 of the actual match. */
551 if ((matchsize == XSTRING (eltstring)->size
552 && matchsize < XSTRING (bestmatch)->size)
553 ||
554 /* If there is more than one exact match ignoring case,
555 and one of them is exact including case,
556 prefer that one. */
557 /* If there is no exact match ignoring case,
558 prefer a match that does not change the case
559 of the input. */
560 ((matchsize == XSTRING (eltstring)->size)
561 ==
562 (matchsize == XSTRING (bestmatch)->size)
563 && !bcmp (XSTRING (eltstring)->data,
564 XSTRING (string)->data, XSTRING (string)->size)
565 && bcmp (XSTRING (bestmatch)->data,
566 XSTRING (string)->data, XSTRING (string)->size)))
567 bestmatch = eltstring;
568 }
569 bestmatchsize = matchsize;
f927c5ae
JB
570 }
571 }
572 }
573
56a98455 574 if (NILP (bestmatch))
f927c5ae 575 return Qnil; /* No completions found */
52b14ac0
JB
576 /* If we are ignoring case, and there is no exact match,
577 and no additional text was supplied,
578 don't change the case of what the user typed. */
579 if (completion_ignore_case && bestmatchsize == XSTRING (string)->size
580 && XSTRING (bestmatch)->size > bestmatchsize)
581 return string;
582
583 /* Return t if the supplied string is an exact match (counting case);
584 it does not require any change to be made. */
585 if (matchcount == 1 && bestmatchsize == XSTRING (string)->size
586 && !bcmp (XSTRING (bestmatch)->data, XSTRING (string)->data,
587 bestmatchsize))
f927c5ae
JB
588 return Qt;
589
590 XFASTINT (zero) = 0; /* Else extract the part in which */
591 XFASTINT (end) = bestmatchsize; /* all completions agree */
592 return Fsubstring (bestmatch, zero, end);
593}
594
595/* Compare exactly LEN chars of strings at S1 and S2,
596 ignoring case if appropriate.
597 Return -1 if strings match,
598 else number of chars that match at the beginning. */
599
600scmp (s1, s2, len)
601 register char *s1, *s2;
602 int len;
603{
604 register int l = len;
605
606 if (completion_ignore_case)
607 {
608 while (l && DOWNCASE (*s1++) == DOWNCASE (*s2++))
609 l--;
610 }
611 else
612 {
613 while (l && *s1++ == *s2++)
614 l--;
615 }
616 if (l == 0)
617 return -1;
618 else return len - l;
619}
620\f
621DEFUN ("all-completions", Fall_completions, Sall_completions, 2, 3, 0,
622 "Search for partial matches to STRING in ALIST.\n\
623Each car of each element of ALIST is tested to see if it begins with STRING.\n\
624The value is a list of all the strings from ALIST that match.\n\
625ALIST can be an obarray instead of an alist.\n\
626Then the print names of all symbols in the obarray are the possible matches.\n\
627\n\
628ALIST can also be a function to do the completion itself.\n\
629It receives three arguments: the values STRING, PREDICATE and t.\n\
630Whatever it returns becomes the value of `all-completion'.\n\
631\n\
632If optional third argument PREDICATE is non-nil,\n\
633it is used to test each possible match.\n\
634The match is a candidate only if PREDICATE returns non-nil.\n\
635The argument given to PREDICATE is the alist element or the symbol from the obarray.")
636 (string, alist, pred)
637 Lisp_Object string, alist, pred;
638{
639 Lisp_Object tail, elt, eltstring;
640 Lisp_Object allmatches;
56a98455 641 int list = CONSP (alist) || NILP (alist);
f927c5ae
JB
642 int index, obsize;
643 Lisp_Object bucket, tem;
644 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
645
646 CHECK_STRING (string, 0);
647 if (!list && XTYPE (alist) != Lisp_Vector)
648 {
649 return call3 (alist, string, pred, Qt);
650 }
651 allmatches = Qnil;
652
653 /* If ALIST is not a list, set TAIL just for gc pro. */
654 tail = alist;
655 if (! list)
656 {
657 index = 0;
658 obsize = XVECTOR (alist)->size;
659 bucket = XVECTOR (alist)->contents[index];
660 }
661
662 while (1)
663 {
664 /* Get the next element of the alist or obarray. */
665 /* Exit the loop if the elements are all used up. */
666 /* elt gets the alist element or symbol.
667 eltstring gets the name to check as a completion. */
668
669 if (list)
670 {
56a98455 671 if (NILP (tail))
f927c5ae
JB
672 break;
673 elt = Fcar (tail);
674 eltstring = Fcar (elt);
675 tail = Fcdr (tail);
676 }
677 else
678 {
679 if (XFASTINT (bucket) != 0)
680 {
681 elt = bucket;
682 eltstring = Fsymbol_name (elt);
683 if (XSYMBOL (bucket)->next)
684 XSETSYMBOL (bucket, XSYMBOL (bucket)->next);
685 else
686 XFASTINT (bucket) = 0;
687 }
688 else if (++index >= obsize)
689 break;
690 else
691 {
692 bucket = XVECTOR (alist)->contents[index];
693 continue;
694 }
695 }
696
697 /* Is this element a possible completion? */
698
699 if (XTYPE (eltstring) == Lisp_String &&
700 XSTRING (string)->size <= XSTRING (eltstring)->size &&
701 XSTRING (eltstring)->data[0] != ' ' &&
702 0 > scmp (XSTRING (eltstring)->data, XSTRING (string)->data,
703 XSTRING (string)->size))
704 {
705 /* Yes. */
706 /* Ignore this element if there is a predicate
707 and the predicate doesn't like it. */
708
56a98455 709 if (!NILP (pred))
f927c5ae
JB
710 {
711 if (EQ (pred, Qcommandp))
712 tem = Fcommandp (elt);
713 else
714 {
715 GCPRO4 (tail, eltstring, allmatches, string);
716 tem = call1 (pred, elt);
717 UNGCPRO;
718 }
56a98455 719 if (NILP (tem)) continue;
f927c5ae
JB
720 }
721 /* Ok => put it on the list. */
722 allmatches = Fcons (eltstring, allmatches);
723 }
724 }
725
726 return Fnreverse (allmatches);
727}
728\f
729Lisp_Object Vminibuffer_completion_table, Qminibuffer_completion_table;
730Lisp_Object Vminibuffer_completion_predicate, Qminibuffer_completion_predicate;
731Lisp_Object Vminibuffer_completion_confirm, Qminibuffer_completion_confirm;
732
733DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 6, 0,
734 "Read a string in the minibuffer, with completion.\n\
3371bdfc 735Args: PROMPT, TABLE, PREDICATE, REQUIRE-MATCH, INITIAL-INPUT, BACKUP-N.\n\
f927c5ae
JB
736PROMPT is a string to prompt with; normally it ends in a colon and a space.\n\
737TABLE is an alist whose elements' cars are strings, or an obarray.\n\
738PREDICATE limits completion to a subset of TABLE.\n\
739See `try-completion' for more details on completion, TABLE, and PREDICATE.\n\
740If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless\n\
741 the input is (or completes to) an element of TABLE.\n\
742 If it is also not t, Return does not exit if it does non-null completion.\n\
743If INITIAL-INPUT is non-nil, insert it in the minibuffer initially.\n\
744Case is ignored if ambient value of `completion-ignore-case' is non-nil.\n\
745If BACKUP-N is specified, point should be placed that many spaces from\n\
746the end of the buffer. This is useful when providing default values,\n\
747because you can put point before the last component of a filename or any\n\
748other component that is likely to be deleted.")
749 (prompt, table, pred, require_match, init, backup_n)
750 Lisp_Object prompt, table, pred, require_match, init, backup_n;
751{
752 Lisp_Object val;
753 int count = specpdl_ptr - specpdl;
754 specbind (Qminibuffer_completion_table, table);
755 specbind (Qminibuffer_completion_predicate, pred);
756 specbind (Qminibuffer_completion_confirm,
757 EQ (require_match, Qt) ? Qnil : Qt);
758 last_exact_completion = Qnil;
56a98455 759 val = read_minibuf (NILP (require_match)
f927c5ae
JB
760 ? Vminibuffer_local_completion_map
761 : Vminibuffer_local_must_match_map,
762 init, prompt, backup_n, 0);
763 return unbind_to (count, val);
764}
765\f
766/* Temporarily display the string M at the end of the current
767 minibuffer contents. This is used to display things like
768 "[No Match]" when the user requests a completion for a prefix
769 that has no possible completions, and other quick, unobtrusive
770 messages. */
771
772temp_echo_area_glyphs (m)
773 char *m;
774{
775 /* It's not very modular to do things this way, but then it seems
776 to me that the whole echo_area_glyphs thing is a hack anyway. */
777 extern char *previous_echo_glyphs;
778
779 int osize = ZV;
780 Lisp_Object oinhibit;
781 oinhibit = Vinhibit_quit;
782
783 /* Clear out any old echo-area message to make way for our new
784 thing. */
785 echo_area_glyphs = previous_echo_glyphs = 0;
786
787 SET_PT (osize);
788 insert_string (m);
789 SET_PT (osize);
790 Vinhibit_quit = Qt;
791 Fsit_for (make_number (2), Qnil, Qnil);
792 del_range (point, ZV);
56a98455 793 if (!NILP (Vquit_flag))
f927c5ae
JB
794 {
795 Vquit_flag = Qnil;
796 unread_command_char = Ctl ('g');
797 }
798 Vinhibit_quit = oinhibit;
799}
800
801Lisp_Object Fminibuffer_completion_help ();
52b14ac0 802Lisp_Object assoc_for_completion ();
f927c5ae
JB
803
804/* returns:
805 * 0 no possible completion
806 * 1 was already an exact and unique completion
807 * 3 was already an exact completion
808 * 4 completed to an exact completion
809 * 5 some completion happened
810 * 6 no completion happened
811 */
812int
813do_completion ()
814{
815 Lisp_Object completion, tem;
816 int completedp;
817 Lisp_Object last;
818
819 completion = Ftry_completion (Fbuffer_string (), Vminibuffer_completion_table,
820 Vminibuffer_completion_predicate);
821 last = last_exact_completion;
822 last_exact_completion = Qnil;
823
56a98455 824 if (NILP (completion))
f927c5ae
JB
825 {
826 bitch_at_user ();
827 temp_echo_area_glyphs (" [No match]");
828 return 0;
829 }
830
831 if (EQ (completion, Qt)) /* exact and unique match */
832 return 1;
833
834 /* compiler bug */
835 tem = Fstring_equal (completion, Fbuffer_string());
56a98455 836 if (completedp = NILP (tem))
f927c5ae
JB
837 {
838 Ferase_buffer (); /* Some completion happened */
839 Finsert (1, &completion);
840 }
841
842 /* It did find a match. Do we match some possibility exactly now? */
843 if (CONSP (Vminibuffer_completion_table)
56a98455 844 || NILP (Vminibuffer_completion_table))
52b14ac0
JB
845 tem = assoc_for_completion (Fbuffer_string (),
846 Vminibuffer_completion_table);
f927c5ae
JB
847 else if (XTYPE (Vminibuffer_completion_table) == Lisp_Vector)
848 {
849 /* the primitive used by Fintern_soft */
850 extern Lisp_Object oblookup ();
851
852 tem = Fbuffer_string ();
853 /* Bypass intern-soft as that loses for nil */
854 tem = oblookup (Vminibuffer_completion_table,
855 XSTRING (tem)->data, XSTRING (tem)->size);
856 if (XTYPE (tem) != Lisp_Symbol)
857 tem = Qnil;
56a98455 858 else if (!NILP (Vminibuffer_completion_predicate))
f927c5ae
JB
859 tem = call1 (Vminibuffer_completion_predicate, tem);
860 else
861 tem = Qt;
862 }
863 else
864 tem = call3 (Vminibuffer_completion_table,
865 Fbuffer_string (),
866 Vminibuffer_completion_predicate,
867 Qlambda);
868
56a98455 869 if (NILP (tem))
f927c5ae
JB
870 { /* not an exact match */
871 if (completedp)
872 return 5;
873 else if (auto_help)
874 Fminibuffer_completion_help ();
875 else
876 temp_echo_area_glyphs (" [Next char not unique]");
877 return 6;
878 }
879 else if (completedp)
880 return 4;
881 /* If the last exact completion and this one were the same,
882 it means we've already given a "Complete but not unique"
52b14ac0 883 message and the user's hit TAB again, so now we give him help. */
f927c5ae 884 last_exact_completion = completion;
56a98455 885 if (!NILP (last))
f927c5ae
JB
886 {
887 tem = Fbuffer_string ();
56a98455 888 if (!NILP (Fequal (tem, last)))
f927c5ae
JB
889 Fminibuffer_completion_help ();
890 }
891 return 3;
f927c5ae
JB
892}
893
52b14ac0
JB
894/* Like assoc but assumes KEY is a string, and ignores case if appropriate. */
895
896Lisp_Object
897assoc_for_completion (key, list)
898 register Lisp_Object key;
899 Lisp_Object list;
900{
901 register Lisp_Object tail;
902
903 if (completion_ignore_case)
904 key = Fupcase (key);
905
56a98455 906 for (tail = list; !NILP (tail); tail = Fcdr (tail))
52b14ac0
JB
907 {
908 register Lisp_Object elt, tem, thiscar;
909 elt = Fcar (tail);
910 if (!CONSP (elt)) continue;
911 thiscar = Fcar (elt);
912 if (XTYPE (thiscar) != Lisp_String)
913 continue;
914 if (completion_ignore_case)
915 thiscar = Fupcase (thiscar);
916 tem = Fequal (thiscar, key);
56a98455 917 if (!NILP (tem)) return elt;
52b14ac0
JB
918 QUIT;
919 }
920 return Qnil;
921}
f927c5ae
JB
922
923DEFUN ("minibuffer-complete", Fminibuffer_complete, Sminibuffer_complete, 0, 0, "",
924 "Complete the minibuffer contents as far as possible.")
925 ()
926{
927 register int i = do_completion ();
928 switch (i)
929 {
930 case 0:
931 return Qnil;
932
933 case 1:
934 temp_echo_area_glyphs (" [Sole completion]");
935 break;
936
937 case 3:
938 temp_echo_area_glyphs (" [Complete, but not unique]");
939 break;
940 }
941
942 return Qt;
943}
944
945DEFUN ("minibuffer-complete-and-exit", Fminibuffer_complete_and_exit,
946 Sminibuffer_complete_and_exit, 0, 0, "",
947 "Complete the minibuffer contents, and maybe exit.\n\
948Exit if the name is valid with no completion needed.\n\
949If name was completed to a valid match,\n\
950a repetition of this command will exit.")
951 ()
952{
953 register int i;
954
955 /* Allow user to specify null string */
956 if (BEGV == ZV)
957 goto exit;
958
959 i = do_completion ();
960 switch (i)
961 {
962 case 1:
963 case 3:
964 goto exit;
965
966 case 4:
56a98455 967 if (!NILP (Vminibuffer_completion_confirm))
f927c5ae
JB
968 {
969 temp_echo_area_glyphs (" [Confirm]");
970 return Qnil;
971 }
972 else
973 goto exit;
974
975 default:
976 return Qnil;
977 }
978 exit:
979 Fthrow (Qexit, Qnil);
980 /* NOTREACHED */
981}
982
983DEFUN ("minibuffer-complete-word", Fminibuffer_complete_word, Sminibuffer_complete_word,
984 0, 0, "",
985 "Complete the minibuffer contents at most a single word.\n\
986After one word is completed as much as possible, a space or hyphen\n\
987is added, provided that matches some possible completion.")
988 ()
989{
990 Lisp_Object completion, tem;
991 register int i;
992 register unsigned char *completion_string;
993 /* We keep calling Fbuffer_string
994 rather than arrange for GC to hold onto a pointer to
995 one of the strings thus made. */
996
997 completion = Ftry_completion (Fbuffer_string (),
998 Vminibuffer_completion_table,
999 Vminibuffer_completion_predicate);
56a98455 1000 if (NILP (completion))
f927c5ae
JB
1001 {
1002 bitch_at_user ();
1003 temp_echo_area_glyphs (" [No match]");
1004 return Qnil;
1005 }
1006 if (EQ (completion, Qt))
1007 return Qnil;
1008
1009#if 0 /* How the below code used to look, for reference */
1010 tem = Fbuffer_string ();
1011 b = XSTRING (tem)->data;
1012 i = ZV - 1 - XSTRING (completion)->size;
1013 p = XSTRING (completion)->data;
1014 if (i > 0 ||
1015 0 <= scmp (b, p, ZV - 1))
1016 {
1017 i = 1;
1018 /* Set buffer to longest match of buffer tail and completion head. */
1019 while (0 <= scmp (b + i, p, ZV - 1 - i))
1020 i++;
1021 del_range (1, i + 1);
1022 SET_PT (ZV);
1023 }
1024#else /* Rewritten code */
1025 {
1026 register unsigned char *buffer_string;
1027 int buffer_length, completion_length;
1028
1029 tem = Fbuffer_string ();
1030 buffer_string = XSTRING (tem)->data;
1031 completion_string = XSTRING (completion)->data;
1032 buffer_length = XSTRING (tem)->size; /* ie ZV - BEGV */
1033 completion_length = XSTRING (completion)->size;
1034 i = buffer_length - completion_length;
1035 /* Mly: I don't understand what this is supposed to do AT ALL */
1036 if (i > 0 ||
1037 0 <= scmp (buffer_string, completion_string, buffer_length))
1038 {
1039 /* Set buffer to longest match of buffer tail and completion head. */
1040 if (i <= 0) i = 1;
1041 buffer_string += i;
1042 buffer_length -= i;
1043 while (0 <= scmp (buffer_string++, completion_string, buffer_length--))
1044 i++;
1045 del_range (1, i + 1);
1046 SET_PT (ZV);
1047 }
1048 }
1049#endif /* Rewritten code */
1050 i = ZV - BEGV;
1051
1052 /* If completion finds next char not unique,
1053 consider adding a space or a hyphen */
1054 if (i == XSTRING (completion)->size)
1055 {
1056 tem = Ftry_completion (concat2 (Fbuffer_string (), build_string (" ")),
1057 Vminibuffer_completion_table,
1058 Vminibuffer_completion_predicate);
1059 if (XTYPE (tem) == Lisp_String)
1060 completion = tem;
1061 else
1062 {
1063 tem = Ftry_completion (concat2 (Fbuffer_string (), build_string ("-")),
1064 Vminibuffer_completion_table,
1065 Vminibuffer_completion_predicate);
1066 if (XTYPE (tem) == Lisp_String)
1067 completion = tem;
1068 }
1069 }
1070
1071 /* Now find first word-break in the stuff found by completion.
1072 i gets index in string of where to stop completing. */
1073 completion_string = XSTRING (completion)->data;
1074
1075 for (; i < XSTRING (completion)->size; i++)
1076 if (SYNTAX (completion_string[i]) != Sword) break;
1077 if (i < XSTRING (completion)->size)
1078 i = i + 1;
1079
1080 /* If got no characters, print help for user. */
1081
1082 if (i == ZV - BEGV)
1083 {
1084 if (auto_help)
1085 Fminibuffer_completion_help ();
1086 return Qnil;
1087 }
1088
1089 /* Otherwise insert in minibuffer the chars we got */
1090
1091 Ferase_buffer ();
1092 insert_from_string (completion, 0, i);
1093 return Qt;
1094}
1095\f
1096DEFUN ("display-completion-list", Fdisplay_completion_list, Sdisplay_completion_list,
1097 1, 1, 0,
2dc2b736 1098 "Display the list of completions, COMPLETIONS, using `standard-output'.\n\
f927c5ae
JB
1099Each element may be just a symbol or string\n\
1100or may be a list of two strings to be printed as if concatenated.")
1101 (completions)
1102 Lisp_Object completions;
1103{
1104 register Lisp_Object tail, elt;
1105 register int i;
2dc2b736 1106 int column = 0;
f927c5ae
JB
1107 /* No GCPRO needed, since (when it matters) every variable
1108 points to a non-string that is pointed to by COMPLETIONS. */
2dc2b736
RS
1109 struct buffer *old = current_buffer;
1110 if (XTYPE (Vstandard_output) == Lisp_Buffer)
1111 set_buffer_internal (XBUFFER (Vstandard_output));
f927c5ae 1112
56a98455 1113 if (NILP (completions))
2dc2b736 1114 write_string ("There are no possible completions of what you have typed.", -1);
f927c5ae
JB
1115 else
1116 {
2dc2b736 1117 write_string ("Possible completions are:", -1);
56a98455 1118 for (tail = completions, i = 0; !NILP (tail); tail = Fcdr (tail), i++)
f927c5ae
JB
1119 {
1120 /* this needs fixing for the case of long completions
1121 and/or narrow windows */
1122 /* Sadly, the window it will appear in is not known
1123 until after the text has been made. */
1124 if (i & 1)
2dc2b736
RS
1125 {
1126 if (XTYPE (Vstandard_output) == Lisp_Buffer)
1127 Findent_to (make_number (35), make_number (1));
1128 else
1129 {
1130 do
1131 {
1132 write_string (" ", -1);
1133 column++;
1134 }
1135 while (column < 35);
1136 }
1137 }
f927c5ae 1138 else
2dc2b736
RS
1139 {
1140 Fterpri (Qnil);
1141 column = 0;
1142 }
f927c5ae
JB
1143 elt = Fcar (tail);
1144 if (CONSP (elt))
1145 {
2dc2b736
RS
1146 if (XTYPE (Vstandard_output) != Lisp_Buffer)
1147 {
07accdfe 1148 Lisp_Object tem;
2dc2b736
RS
1149 tem = Flength (Fcar (elt));
1150 column += XINT (tem);
1151 tem = Flength (Fcar (Fcdr (elt)));
1152 column += XINT (tem);
1153 }
f927c5ae
JB
1154 Fprinc (Fcar (elt), Qnil);
1155 Fprinc (Fcar (Fcdr (elt)), Qnil);
1156 }
1157 else
2dc2b736
RS
1158 {
1159 if (XTYPE (Vstandard_output) != Lisp_Buffer)
1160 {
1161 Lisp_Object tem;
1162 tem = Flength (elt, Qt);
1163 column += XINT (tem);
1164 }
1165 Fprinc (elt, Qnil);
1166 }
f927c5ae
JB
1167 }
1168 }
2dc2b736
RS
1169
1170 if (XTYPE (Vstandard_output) == Lisp_Buffer)
1171 set_buffer_internal (old);
f927c5ae
JB
1172 return Qnil;
1173}
1174
1175DEFUN ("minibuffer-completion-help", Fminibuffer_completion_help, Sminibuffer_completion_help,
1176 0, 0, "",
1177 "Display a list of possible completions of the current minibuffer contents.")
1178 ()
1179{
1180 Lisp_Object completions;
1181
1182 message ("Making completion list...");
1183 completions = Fall_completions (Fbuffer_string (),
1184 Vminibuffer_completion_table,
1185 Vminibuffer_completion_predicate);
1186 echo_area_glyphs = 0;
1187
56a98455 1188 if (NILP (completions))
f927c5ae
JB
1189 {
1190 bitch_at_user ();
1191 temp_echo_area_glyphs (" [No completions]");
1192 }
1193 else
1194 internal_with_output_to_temp_buffer ("*Completions*",
1195 Fdisplay_completion_list,
1196 Fsort (completions, Qstring_lessp));
1197 return Qnil;
1198}
1199\f
1200DEFUN ("self-insert-and-exit", Fself_insert_and_exit, Sself_insert_and_exit, 0, 0, "",
1201 "Terminate minibuffer input.")
1202 ()
1203{
1204 if (XTYPE (last_command_char) == Lisp_Int)
1205 internal_self_insert (last_command_char, 0);
1206 else
1207 bitch_at_user ();
1208
1209 Fthrow (Qexit, Qnil);
1210}
1211
1212DEFUN ("exit-minibuffer", Fexit_minibuffer, Sexit_minibuffer, 0, 0, "",
1213 "Terminate this minibuffer argument.")
1214 ()
1215{
1216 Fthrow (Qexit, Qnil);
1217}
1218
1219DEFUN ("minibuffer-depth", Fminibuffer_depth, Sminibuffer_depth, 0, 0, 0,
1220 "Return current depth of activations of minibuffer, a nonnegative integer.")
1221 ()
1222{
1223 return make_number (minibuf_level);
1224}
1225
1226\f
1227init_minibuf_once ()
1228{
1229 Vminibuffer_list = Qnil;
1230 staticpro (&Vminibuffer_list);
1231}
1232
1233syms_of_minibuf ()
1234{
1235 minibuf_level = 0;
1236 minibuf_prompt = 0;
1237 minibuf_save_vector_size = 5;
1238 minibuf_save_vector = (struct minibuf_save_data *) malloc (5 * sizeof (struct minibuf_save_data));
1239
1240 Qminibuffer_completion_table = intern ("minibuffer-completion-table");
1241 staticpro (&Qminibuffer_completion_table);
1242
1243 Qminibuffer_completion_confirm = intern ("minibuffer-completion-confirm");
1244 staticpro (&Qminibuffer_completion_confirm);
1245
1246 Qminibuffer_completion_predicate = intern ("minibuffer-completion-predicate");
1247 staticpro (&Qminibuffer_completion_predicate);
1248
1249 staticpro (&last_minibuf_string);
1250 last_minibuf_string = Qnil;
1251
1252 Quser_variable_p = intern ("user-variable-p");
1253 staticpro (&Quser_variable_p);
1254
1255
1256
1257 DEFVAR_BOOL ("completion-auto-help", &auto_help,
1258 "*Non-nil means automatically provide help for invalid completion input.");
1259 auto_help = 1;
1260
1261 DEFVAR_BOOL ("completion-ignore-case", &completion_ignore_case,
1262 "Non-nil means don't consider case significant in completion.");
1263 completion_ignore_case = 0;
1264
1265 DEFVAR_BOOL ("enable-recursive-minibuffers", &enable_recursive_minibuffers,
1266 "*Non-nil means to allow minibuffer commands while in the minibuffer.\n\
1267More precisely, this variable makes a difference when the minibuffer window\n\
1268is the selected window. If you are in some other window, minibuffer commands\n\
1269are allowed even if a minibuffer is active.");
1270 enable_recursive_minibuffers = 0;
1271
1272 DEFVAR_LISP ("minibuffer-completion-table", &Vminibuffer_completion_table,
1273 "Alist or obarray used for completion in the minibuffer.\n\
1274This becomes the ALIST argument to `try-completion' and `all-completion'.\n\
1275\n\
1276The value may alternatively be a function, which is given three arguments:\n\
1277 STRING, the current buffer contents;\n\
1278 PREDICATE, the predicate for filtering possible matches;\n\
1279 CODE, which says what kind of things to do.\n\
1280CODE can be nil, t or `lambda'.\n\
1281nil means to return the best completion of STRING, or nil if there is none.\n\
1282t means to return a list of all possible completions of STRING.\n\
1283`lambda' means to return t if STRING is a valid completion as it stands.");
1284 Vminibuffer_completion_table = Qnil;
1285
1286 DEFVAR_LISP ("minibuffer-completion-predicate", &Vminibuffer_completion_predicate,
1287 "Within call to `completing-read', this holds the PREDICATE argument.");
1288 Vminibuffer_completion_predicate = Qnil;
1289
1290 DEFVAR_LISP ("minibuffer-completion-confirm", &Vminibuffer_completion_confirm,
1291 "Non-nil => demand confirmation of completion before exiting minibuffer.");
1292 Vminibuffer_completion_confirm = Qnil;
1293
1294 DEFVAR_LISP ("minibuffer-help-form", &Vminibuffer_help_form,
1295 "Value that `help-form' takes on inside the minibuffer.");
1296 Vminibuffer_help_form = Qnil;
1297
1298 defsubr (&Sread_from_minibuffer);
1299 defsubr (&Seval_minibuffer);
1300 defsubr (&Sread_minibuffer);
1301 defsubr (&Sread_string);
1302 defsubr (&Sread_command);
1303 defsubr (&Sread_variable);
1304 defsubr (&Sread_buffer);
1305 defsubr (&Sread_no_blanks_input);
1306 defsubr (&Sminibuffer_depth);
1307
1308 defsubr (&Stry_completion);
1309 defsubr (&Sall_completions);
1310 defsubr (&Scompleting_read);
1311 defsubr (&Sminibuffer_complete);
1312 defsubr (&Sminibuffer_complete_word);
1313 defsubr (&Sminibuffer_complete_and_exit);
1314 defsubr (&Sdisplay_completion_list);
1315 defsubr (&Sminibuffer_completion_help);
1316
1317 defsubr (&Sself_insert_and_exit);
1318 defsubr (&Sexit_minibuffer);
1319
1320}
1321
1322keys_of_minibuf ()
1323{
1324 initial_define_key (Vminibuffer_local_map, Ctl ('g'),
1325 "abort-recursive-edit");
1326 initial_define_key (Vminibuffer_local_map, Ctl ('m'),
1327 "exit-minibuffer");
1328 initial_define_key (Vminibuffer_local_map, Ctl ('j'),
1329 "exit-minibuffer");
1330
1331 initial_define_key (Vminibuffer_local_ns_map, Ctl ('g'),
1332 "abort-recursive-edit");
1333 initial_define_key (Vminibuffer_local_ns_map, Ctl ('m'),
1334 "exit-minibuffer");
1335 initial_define_key (Vminibuffer_local_ns_map, Ctl ('j'),
1336 "exit-minibuffer");
1337
1338 initial_define_key (Vminibuffer_local_ns_map, ' ',
1339 "exit-minibuffer");
1340 initial_define_key (Vminibuffer_local_ns_map, '\t',
1341 "exit-minibuffer");
1342 initial_define_key (Vminibuffer_local_ns_map, '?',
1343 "self-insert-and-exit");
1344
1345 initial_define_key (Vminibuffer_local_completion_map, Ctl ('g'),
1346 "abort-recursive-edit");
1347 initial_define_key (Vminibuffer_local_completion_map, Ctl ('m'),
1348 "exit-minibuffer");
1349 initial_define_key (Vminibuffer_local_completion_map, Ctl ('j'),
1350 "exit-minibuffer");
1351
1352 initial_define_key (Vminibuffer_local_completion_map, '\t',
1353 "minibuffer-complete");
1354 initial_define_key (Vminibuffer_local_completion_map, ' ',
1355 "minibuffer-complete-word");
1356 initial_define_key (Vminibuffer_local_completion_map, '?',
1357 "minibuffer-completion-help");
1358
1359 initial_define_key (Vminibuffer_local_must_match_map, Ctl ('g'),
1360 "abort-recursive-edit");
1361 initial_define_key (Vminibuffer_local_must_match_map, Ctl ('m'),
1362 "minibuffer-complete-and-exit");
1363 initial_define_key (Vminibuffer_local_must_match_map, Ctl ('j'),
1364 "minibuffer-complete-and-exit");
1365 initial_define_key (Vminibuffer_local_must_match_map, '\t',
1366 "minibuffer-complete");
1367 initial_define_key (Vminibuffer_local_must_match_map, ' ',
1368 "minibuffer-complete-word");
1369 initial_define_key (Vminibuffer_local_must_match_map, '?',
1370 "minibuffer-completion-help");
1371}