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