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