Commit | Line | Data |
---|---|---|
f927c5ae | 1 | /* Minibuffer input and completion. |
9ec0b715 GM |
2 | Copyright (C) 1985, 1986, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
3 | 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, | |
4 | 2008 Free Software Foundation, Inc. | |
f927c5ae JB |
5 | |
6 | This file is part of GNU Emacs. | |
7 | ||
9ec0b715 | 8 | GNU Emacs is free software: you can redistribute it and/or modify |
f927c5ae | 9 | it under the terms of the GNU General Public License as published by |
9ec0b715 GM |
10 | the Free Software Foundation, either version 3 of the License, or |
11 | (at your option) any later version. | |
f927c5ae JB |
12 | |
13 | GNU Emacs is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
9ec0b715 | 19 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
f927c5ae JB |
20 | |
21 | ||
18160b98 | 22 | #include <config.h> |
3f708f4c | 23 | #include <stdio.h> |
af52c32d | 24 | |
f927c5ae JB |
25 | #include "lisp.h" |
26 | #include "commands.h" | |
27 | #include "buffer.h" | |
83be827a | 28 | #include "character.h" |
f927c5ae | 29 | #include "dispextern.h" |
2538fae4 | 30 | #include "keyboard.h" |
ff11dfa1 | 31 | #include "frame.h" |
f927c5ae JB |
32 | #include "window.h" |
33 | #include "syntax.h" | |
0c21eeeb | 34 | #include "intervals.h" |
8feddab4 | 35 | #include "keymap.h" |
fa971ac3 | 36 | #include "termhooks.h" |
f927c5ae | 37 | |
a4e71d81 KH |
38 | extern int quit_char; |
39 | ||
f927c5ae | 40 | /* List of buffers for use as minibuffers. |
4d04c1f1 KH |
41 | The first element of the list is used for the outermost minibuffer |
42 | invocation, the next element is used for a recursive minibuffer | |
43 | invocation, etc. The list is extended at the end as deeper | |
44 | minibuffer recursions are encountered. */ | |
279cf52c | 45 | |
f927c5ae JB |
46 | Lisp_Object Vminibuffer_list; |
47 | ||
4d04c1f1 | 48 | /* Data to remember during recursive minibuffer invocations */ |
279cf52c | 49 | |
4d04c1f1 | 50 | Lisp_Object minibuf_save_list; |
f927c5ae JB |
51 | |
52 | /* Depth in minibuffer invocations. */ | |
279cf52c | 53 | |
f927c5ae JB |
54 | int minibuf_level; |
55 | ||
77aa8edf | 56 | /* The maximum length of a minibuffer history. */ |
279cf52c | 57 | |
77aa8edf RS |
58 | Lisp_Object Qhistory_length, Vhistory_length; |
59 | ||
0da4d471 JL |
60 | /* No duplicates in history. */ |
61 | ||
62 | int history_delete_duplicates; | |
63 | ||
179a4ca7 JL |
64 | /* Non-nil means add new input to history. */ |
65 | ||
66 | Lisp_Object Vhistory_add_new_input; | |
67 | ||
b278606c | 68 | /* Fread_minibuffer leaves the input here as a string. */ |
279cf52c | 69 | |
f927c5ae JB |
70 | Lisp_Object last_minibuf_string; |
71 | ||
9ab4a725 | 72 | /* Nonzero means let functions called when within a minibuffer |
f927c5ae | 73 | invoke recursive minibuffers (to read arguments, or whatever) */ |
279cf52c | 74 | |
f927c5ae JB |
75 | int enable_recursive_minibuffers; |
76 | ||
c3421833 RS |
77 | /* Nonzero means don't ignore text properties |
78 | in Fread_from_minibuffer. */ | |
279cf52c | 79 | |
c3421833 RS |
80 | int minibuffer_allow_text_properties; |
81 | ||
f927c5ae JB |
82 | /* help-form is bound to this while in the minibuffer. */ |
83 | ||
84 | Lisp_Object Vminibuffer_help_form; | |
85 | ||
770970cb RS |
86 | /* Variable which is the history list to add minibuffer values to. */ |
87 | ||
88 | Lisp_Object Vminibuffer_history_variable; | |
89 | ||
90 | /* Current position in the history list (adjusted by M-n and M-p). */ | |
91 | ||
92 | Lisp_Object Vminibuffer_history_position; | |
93 | ||
cc64f5c9 MB |
94 | /* Text properties that are added to minibuffer prompts. |
95 | These are in addition to the basic `field' property, and stickiness | |
96 | properties. */ | |
97 | ||
98 | Lisp_Object Vminibuffer_prompt_properties; | |
99 | ||
406e55df | 100 | Lisp_Object Qminibuffer_history, Qbuffer_name_history; |
770970cb | 101 | |
719b4a40 RS |
102 | Lisp_Object Qread_file_name_internal; |
103 | ||
177aecf9 | 104 | /* Normal hooks for entry to and exit from minibuffer. */ |
5c781212 RS |
105 | |
106 | Lisp_Object Qminibuffer_setup_hook, Vminibuffer_setup_hook; | |
177aecf9 | 107 | Lisp_Object Qminibuffer_exit_hook, Vminibuffer_exit_hook; |
5c781212 | 108 | |
eebbfb01 | 109 | /* Function to call to read a buffer name. */ |
9ab4a725 | 110 | Lisp_Object Vread_buffer_function; |
eebbfb01 | 111 | |
f927c5ae JB |
112 | /* Nonzero means completion ignores case. */ |
113 | ||
114 | int completion_ignore_case; | |
9fa5c213 | 115 | Lisp_Object Qcompletion_ignore_case; |
f927c5ae | 116 | |
42006772 RS |
117 | /* List of regexps that should restrict possible completions. */ |
118 | ||
119 | Lisp_Object Vcompletion_regexp_list; | |
120 | ||
6a9ee000 RS |
121 | /* Nonzero means raise the minibuffer frame when the minibuffer |
122 | is entered. */ | |
123 | ||
124 | int minibuffer_auto_raise; | |
125 | ||
627fb581 RS |
126 | /* Keymap for reading expressions. */ |
127 | Lisp_Object Vread_expression_map; | |
cee54539 | 128 | |
3372a51b RS |
129 | Lisp_Object Vminibuffer_completion_table, Qminibuffer_completion_table; |
130 | Lisp_Object Vminibuffer_completion_predicate, Qminibuffer_completion_predicate; | |
131 | Lisp_Object Vminibuffer_completion_confirm, Qminibuffer_completion_confirm; | |
132 | Lisp_Object Vminibuffer_completing_file_name; | |
133 | ||
5744fa7c RS |
134 | Lisp_Object Quser_variable_p; |
135 | ||
136 | Lisp_Object Qminibuffer_default; | |
137 | ||
cee54539 KH |
138 | Lisp_Object Qcurrent_input_method, Qactivate_input_method; |
139 | ||
6b61353c KH |
140 | Lisp_Object Qcase_fold_search; |
141 | ||
627fb581 RS |
142 | Lisp_Object Qread_expression_history; |
143 | ||
144 | extern Lisp_Object Voverriding_local_map; | |
145 | ||
5744fa7c | 146 | extern Lisp_Object Qmouse_face; |
279cf52c | 147 | |
8e9968c6 | 148 | extern Lisp_Object Qfield; |
f927c5ae | 149 | \f |
89fdc4a0 KH |
150 | /* Put minibuf on currently selected frame's minibuffer. |
151 | We do this whenever the user starts a new minibuffer | |
152 | or when a minibuffer exits. */ | |
153 | ||
154 | void | |
155 | choose_minibuf_frame () | |
156 | { | |
a4aafc54 GM |
157 | if (FRAMEP (selected_frame) |
158 | && FRAME_LIVE_P (XFRAME (selected_frame)) | |
159 | && !EQ (minibuf_window, XFRAME (selected_frame)->minibuffer_window)) | |
89fdc4a0 | 160 | { |
a4aafc54 GM |
161 | struct frame *sf = XFRAME (selected_frame); |
162 | Lisp_Object buffer; | |
9ab4a725 | 163 | |
89fdc4a0 KH |
164 | /* I don't think that any frames may validly have a null minibuffer |
165 | window anymore. */ | |
a4aafc54 | 166 | if (NILP (sf->minibuffer_window)) |
89fdc4a0 KH |
167 | abort (); |
168 | ||
a4aafc54 GM |
169 | /* Under X, we come here with minibuf_window being the |
170 | minibuffer window of the unused termcap window created in | |
171 | init_window_once. That window doesn't have a buffer. */ | |
172 | buffer = XWINDOW (minibuf_window)->buffer; | |
173 | if (BUFFERP (buffer)) | |
cbbfe056 | 174 | Fset_window_buffer (sf->minibuffer_window, buffer, Qnil); |
a4aafc54 | 175 | minibuf_window = sf->minibuffer_window; |
89fdc4a0 | 176 | } |
914860c2 RS |
177 | |
178 | /* Make sure no other frame has a minibuffer as its selected window, | |
179 | because the text would not be displayed in it, and that would be | |
07d402c8 RS |
180 | confusing. Only allow the selected frame to do this, |
181 | and that only if the minibuffer is active. */ | |
914860c2 RS |
182 | { |
183 | Lisp_Object tail, frame; | |
184 | ||
185 | FOR_EACH_FRAME (tail, frame) | |
07d402c8 | 186 | if (MINI_WINDOW_P (XWINDOW (FRAME_SELECTED_WINDOW (XFRAME (frame)))) |
a4aafc54 | 187 | && !(EQ (frame, selected_frame) |
07d402c8 | 188 | && minibuf_level > 0)) |
914860c2 RS |
189 | Fset_frame_selected_window (frame, Fframe_first_window (frame)); |
190 | } | |
89fdc4a0 | 191 | } |
68313ed8 | 192 | |
0c94f256 RS |
193 | Lisp_Object |
194 | choose_minibuf_frame_1 (ignore) | |
195 | Lisp_Object ignore; | |
196 | { | |
197 | choose_minibuf_frame (); | |
198 | return Qnil; | |
199 | } | |
200 | ||
68313ed8 RS |
201 | DEFUN ("set-minibuffer-window", Fset_minibuffer_window, |
202 | Sset_minibuffer_window, 1, 1, 0, | |
af52c32d | 203 | doc: /* Specify which minibuffer window to use for the minibuffer. |
6b61353c | 204 | This affects where the minibuffer is displayed if you put text in it |
af52c32d MB |
205 | without invoking the usual minibuffer commands. */) |
206 | (window) | |
68313ed8 RS |
207 | Lisp_Object window; |
208 | { | |
b7826503 | 209 | CHECK_WINDOW (window); |
68313ed8 RS |
210 | if (! MINI_WINDOW_P (XWINDOW (window))) |
211 | error ("Window is not a minibuffer window"); | |
212 | ||
213 | minibuf_window = window; | |
214 | ||
215 | return window; | |
216 | } | |
217 | ||
89fdc4a0 | 218 | \f |
f927c5ae JB |
219 | /* Actual minibuffer invocation. */ |
220 | ||
af2b7cd5 | 221 | static Lisp_Object read_minibuf_unwind P_ ((Lisp_Object)); |
7292839d | 222 | static Lisp_Object run_exit_minibuf_hook P_ ((Lisp_Object)); |
af2b7cd5 RS |
223 | static Lisp_Object read_minibuf P_ ((Lisp_Object, Lisp_Object, |
224 | Lisp_Object, Lisp_Object, | |
225 | int, Lisp_Object, | |
226 | Lisp_Object, Lisp_Object, | |
b35cd215 | 227 | int, int)); |
edfef199 GM |
228 | static Lisp_Object read_minibuf_noninteractive P_ ((Lisp_Object, Lisp_Object, |
229 | Lisp_Object, Lisp_Object, | |
230 | int, Lisp_Object, | |
231 | Lisp_Object, Lisp_Object, | |
232 | int, int)); | |
233 | static Lisp_Object string_to_object P_ ((Lisp_Object, Lisp_Object)); | |
234 | ||
235 | ||
236 | /* Read a Lisp object from VAL and return it. If VAL is an empty | |
237 | string, and DEFALT is a string, read from DEFALT instead of VAL. */ | |
238 | ||
239 | static Lisp_Object | |
240 | string_to_object (val, defalt) | |
241 | Lisp_Object val, defalt; | |
242 | { | |
243 | struct gcpro gcpro1, gcpro2; | |
244 | Lisp_Object expr_and_pos; | |
245 | int pos; | |
9ab4a725 | 246 | |
edfef199 | 247 | GCPRO2 (val, defalt); |
9ab4a725 | 248 | |
fb30dfd2 JL |
249 | if (STRINGP (val) && SCHARS (val) == 0) |
250 | { | |
251 | if (STRINGP (defalt)) | |
252 | val = defalt; | |
253 | else if (CONSP (defalt) && STRINGP (XCAR (defalt))) | |
254 | val = XCAR (defalt); | |
255 | } | |
9ab4a725 | 256 | |
edfef199 GM |
257 | expr_and_pos = Fread_from_string (val, Qnil, Qnil); |
258 | pos = XINT (Fcdr (expr_and_pos)); | |
d5db4077 | 259 | if (pos != SCHARS (val)) |
edfef199 GM |
260 | { |
261 | /* Ignore trailing whitespace; any other trailing junk | |
262 | is an error. */ | |
263 | int i; | |
264 | pos = string_char_to_byte (val, pos); | |
d5db4077 | 265 | for (i = pos; i < SBYTES (val); i++) |
edfef199 | 266 | { |
d5db4077 | 267 | int c = SREF (val, i); |
edfef199 GM |
268 | if (c != ' ' && c != '\t' && c != '\n') |
269 | error ("Trailing garbage following expression"); | |
270 | } | |
271 | } | |
9ab4a725 | 272 | |
edfef199 GM |
273 | val = Fcar (expr_and_pos); |
274 | RETURN_UNGCPRO (val); | |
275 | } | |
276 | ||
277 | ||
278 | /* Like read_minibuf but reading from stdin. This function is called | |
279 | from read_minibuf to do the job if noninteractive. */ | |
280 | ||
281 | static Lisp_Object | |
282 | read_minibuf_noninteractive (map, initial, prompt, backup_n, expflag, | |
283 | histvar, histpos, defalt, allow_props, | |
284 | inherit_input_method) | |
285 | Lisp_Object map; | |
286 | Lisp_Object initial; | |
287 | Lisp_Object prompt; | |
288 | Lisp_Object backup_n; | |
289 | int expflag; | |
290 | Lisp_Object histvar; | |
291 | Lisp_Object histpos; | |
292 | Lisp_Object defalt; | |
293 | int allow_props; | |
294 | int inherit_input_method; | |
295 | { | |
296 | int size, len; | |
297 | char *line, *s; | |
edfef199 GM |
298 | Lisp_Object val; |
299 | ||
d5db4077 | 300 | fprintf (stdout, "%s", SDATA (prompt)); |
edfef199 GM |
301 | fflush (stdout); |
302 | ||
6bbd7a29 | 303 | val = Qnil; |
edfef199 GM |
304 | size = 100; |
305 | len = 0; | |
306 | line = (char *) xmalloc (size * sizeof *line); | |
307 | while ((s = fgets (line + len, size - len, stdin)) != NULL | |
308 | && (len = strlen (line), | |
309 | len == size - 1 && line[len - 1] != '\n')) | |
310 | { | |
311 | size *= 2; | |
312 | line = (char *) xrealloc (line, size); | |
313 | } | |
314 | ||
315 | if (s) | |
316 | { | |
317 | len = strlen (line); | |
9ab4a725 | 318 | |
edfef199 GM |
319 | if (len > 0 && line[len - 1] == '\n') |
320 | line[--len] = '\0'; | |
9ab4a725 | 321 | |
edfef199 GM |
322 | val = build_string (line); |
323 | xfree (line); | |
324 | } | |
325 | else | |
326 | { | |
327 | xfree (line); | |
328 | error ("Error reading from stdin"); | |
329 | } | |
9ab4a725 | 330 | |
edfef199 GM |
331 | /* If Lisp form desired instead of string, parse it. */ |
332 | if (expflag) | |
fb30dfd2 | 333 | val = string_to_object (val, CONSP (defalt) ? XCAR (defalt) : defalt); |
9ab4a725 | 334 | |
edfef199 GM |
335 | return val; |
336 | } | |
1011edb5 | 337 | \f |
873ef78e | 338 | DEFUN ("minibufferp", Fminibufferp, |
6d1b1d7b JPW |
339 | Sminibufferp, 0, 1, 0, |
340 | doc: /* Return t if BUFFER is a minibuffer. | |
6b61353c KH |
341 | No argument or nil as argument means use current buffer as BUFFER. |
342 | BUFFER can be a buffer or a buffer name. */) | |
6d1b1d7b JPW |
343 | (buffer) |
344 | Lisp_Object buffer; | |
873ef78e RS |
345 | { |
346 | Lisp_Object tem; | |
347 | ||
6d1b1d7b JPW |
348 | if (NILP (buffer)) |
349 | buffer = Fcurrent_buffer (); | |
350 | else if (STRINGP (buffer)) | |
351 | buffer = Fget_buffer (buffer); | |
352 | else | |
353 | CHECK_BUFFER (buffer); | |
354 | ||
355 | tem = Fmemq (buffer, Vminibuffer_list); | |
873ef78e RS |
356 | return ! NILP (tem) ? Qt : Qnil; |
357 | } | |
358 | ||
a346ec72 MB |
359 | DEFUN ("minibuffer-prompt-end", Fminibuffer_prompt_end, |
360 | Sminibuffer_prompt_end, 0, 0, 0, | |
af52c32d | 361 | doc: /* Return the buffer position of the end of the minibuffer prompt. |
eb7c9b64 | 362 | Return (point-min) if current buffer is not a minibuffer. */) |
af52c32d | 363 | () |
a346ec72 MB |
364 | { |
365 | /* This function is written to be most efficient when there's a prompt. */ | |
873ef78e RS |
366 | Lisp_Object beg, end, tem; |
367 | beg = make_number (BEGV); | |
368 | ||
369 | tem = Fmemq (Fcurrent_buffer (), Vminibuffer_list); | |
370 | if (NILP (tem)) | |
371 | return beg; | |
372 | ||
373 | end = Ffield_end (beg, Qnil, Qnil); | |
9ab4a725 | 374 | |
a346ec72 | 375 | if (XINT (end) == ZV && NILP (Fget_char_property (beg, Qfield, Qnil))) |
b056f36d | 376 | return beg; |
a346ec72 MB |
377 | else |
378 | return end; | |
379 | } | |
380 | ||
381 | DEFUN ("minibuffer-contents", Fminibuffer_contents, | |
382 | Sminibuffer_contents, 0, 0, 0, | |
029a305c | 383 | doc: /* Return the user input in a minibuffer as a string. |
6cc62df0 | 384 | If the current buffer is not a minibuffer, return its entire contents. */) |
af52c32d | 385 | () |
a346ec72 MB |
386 | { |
387 | int prompt_end = XINT (Fminibuffer_prompt_end ()); | |
388 | return make_buffer_string (prompt_end, ZV, 1); | |
389 | } | |
390 | ||
391 | DEFUN ("minibuffer-contents-no-properties", Fminibuffer_contents_no_properties, | |
392 | Sminibuffer_contents_no_properties, 0, 0, 0, | |
029a305c | 393 | doc: /* Return the user input in a minibuffer as a string, without text-properties. |
6cc62df0 | 394 | If the current buffer is not a minibuffer, return its entire contents. */) |
af52c32d | 395 | () |
a346ec72 MB |
396 | { |
397 | int prompt_end = XINT (Fminibuffer_prompt_end ()); | |
398 | return make_buffer_string (prompt_end, ZV, 0); | |
399 | } | |
400 | ||
b5e1e449 JL |
401 | DEFUN ("minibuffer-completion-contents", Fminibuffer_completion_contents, |
402 | Sminibuffer_completion_contents, 0, 0, 0, | |
403 | doc: /* Return the user input in a minibuffer before point as a string. | |
404 | That is what completion commands operate on. | |
6cc62df0 | 405 | If the current buffer is not a minibuffer, return its entire contents. */) |
b5e1e449 JL |
406 | () |
407 | { | |
408 | int prompt_end = XINT (Fminibuffer_prompt_end ()); | |
409 | if (PT < prompt_end) | |
410 | error ("Cannot do completion in the prompt"); | |
411 | return make_buffer_string (prompt_end, PT, 1); | |
412 | } | |
413 | ||
1011edb5 | 414 | \f |
6b61353c KH |
415 | /* Read from the minibuffer using keymap MAP and initial contents INITIAL, |
416 | putting point minus BACKUP_N bytes from the end of INITIAL, | |
770970cb | 417 | prompting with PROMPT (a string), using history list HISTVAR |
6b61353c KH |
418 | with initial position HISTPOS. INITIAL should be a string or a |
419 | cons of a string and an integer. BACKUP_N should be <= 0, or | |
420 | Qnil, which is equivalent to 0. If INITIAL is a cons, BACKUP_N is | |
421 | ignored and replaced with an integer that puts point at one-indexed | |
422 | position N in INITIAL, where N is the CDR of INITIAL, or at the | |
423 | beginning of INITIAL if N <= 0. | |
770970cb RS |
424 | |
425 | Normally return the result as a string (the text that was read), | |
3ab14176 | 426 | but if EXPFLAG is nonzero, read it and return the object read. |
b278606c BF |
427 | If HISTVAR is given, save the value read on that history only if it doesn't |
428 | match the front of that history list exactly. The value is pushed onto | |
e5d4686b | 429 | the list as the string that was read. |
770970cb | 430 | |
4f9f637a | 431 | DEFALT specifies the default value for the sake of history commands. |
c3421833 | 432 | |
cee54539 KH |
433 | If ALLOW_PROPS is nonzero, we do not throw away text properties. |
434 | ||
6b61353c | 435 | if INHERIT_INPUT_METHOD is nonzero, the minibuffer inherits the |
cee54539 | 436 | current input method. */ |
e5d4686b RS |
437 | |
438 | static Lisp_Object | |
439 | read_minibuf (map, initial, prompt, backup_n, expflag, | |
b35cd215 | 440 | histvar, histpos, defalt, allow_props, inherit_input_method) |
f927c5ae JB |
441 | Lisp_Object map; |
442 | Lisp_Object initial; | |
443 | Lisp_Object prompt; | |
5061d9c3 | 444 | Lisp_Object backup_n; |
f927c5ae | 445 | int expflag; |
770970cb RS |
446 | Lisp_Object histvar; |
447 | Lisp_Object histpos; | |
e5d4686b | 448 | Lisp_Object defalt; |
af2b7cd5 | 449 | int allow_props; |
cee54539 | 450 | int inherit_input_method; |
f927c5ae | 451 | { |
00a34088 | 452 | Lisp_Object val; |
aed13378 | 453 | int count = SPECPDL_INDEX (); |
cee54539 KH |
454 | Lisp_Object mini_frame, ambient_dir, minibuffer, input_method; |
455 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; | |
c75000c7 | 456 | Lisp_Object enable_multibyte; |
6b61353c | 457 | int pos = INTEGERP (backup_n) ? XINT (backup_n) : 0; |
4f9f637a RS |
458 | /* String to add to the history. */ |
459 | Lisp_Object histstring; | |
460 | ||
b20de1cd RS |
461 | Lisp_Object empty_minibuf; |
462 | Lisp_Object dummy, frame; | |
463 | ||
04012254 | 464 | extern Lisp_Object Qfront_sticky; |
fbd1209a | 465 | extern Lisp_Object Qrear_nonsticky; |
00a34088 | 466 | |
e5d4686b RS |
467 | specbind (Qminibuffer_default, defalt); |
468 | ||
ef72eaff KS |
469 | /* If Vminibuffer_completing_file_name is `lambda' on entry, it was t |
470 | in previous recursive minibuffer, but was not set explicitly | |
471 | to t for this invocation, so set it to nil in this minibuffer. | |
472 | Save the old value now, before we change it. */ | |
473 | specbind (intern ("minibuffer-completing-file-name"), Vminibuffer_completing_file_name); | |
474 | if (EQ (Vminibuffer_completing_file_name, Qlambda)) | |
475 | Vminibuffer_completing_file_name = Qnil; | |
476 | ||
d148e14d | 477 | #ifdef HAVE_WINDOW_SYSTEM |
526a058f GM |
478 | if (display_hourglass_p) |
479 | cancel_hourglass (); | |
e5baa1a7 | 480 | #endif |
718d3251 | 481 | |
6b61353c KH |
482 | if (!NILP (initial)) |
483 | { | |
484 | if (CONSP (initial)) | |
485 | { | |
486 | backup_n = Fcdr (initial); | |
487 | initial = Fcar (initial); | |
488 | CHECK_STRING (initial); | |
489 | if (!NILP (backup_n)) | |
490 | { | |
491 | CHECK_NUMBER (backup_n); | |
492 | /* Convert to distance from end of input. */ | |
493 | if (XINT (backup_n) < 1) | |
494 | /* A number too small means the beginning of the string. */ | |
495 | pos = - SCHARS (initial); | |
496 | else | |
497 | pos = XINT (backup_n) - 1 - SCHARS (initial); | |
498 | } | |
499 | } | |
500 | else | |
501 | CHECK_STRING (initial); | |
502 | } | |
00a34088 | 503 | val = Qnil; |
57ceaa8a | 504 | ambient_dir = current_buffer->directory; |
cee54539 | 505 | input_method = Qnil; |
c75000c7 | 506 | enable_multibyte = Qnil; |
57ceaa8a | 507 | |
00a34088 RS |
508 | /* Don't need to protect PROMPT, HISTVAR, and HISTPOS because we |
509 | store them away before we can GC. Don't need to protect | |
510 | BACKUP_N because we use the value only if it is an integer. */ | |
cee54539 | 511 | GCPRO5 (map, initial, val, ambient_dir, input_method); |
f927c5ae | 512 | |
7510b296 | 513 | if (!STRINGP (prompt)) |
a2665596 | 514 | prompt = empty_unibyte_string; |
f927c5ae | 515 | |
f927c5ae | 516 | if (!enable_recursive_minibuffers |
be15a518 RS |
517 | && minibuf_level > 0) |
518 | { | |
519 | if (EQ (selected_window, minibuf_window)) | |
520 | error ("Command attempted to use minibuffer while in minibuffer"); | |
521 | else | |
522 | /* If we're in another window, cancel the minibuffer that's active. */ | |
523 | Fthrow (Qexit, | |
524 | build_string ("Command attempted to use minibuffer while in minibuffer")); | |
525 | } | |
f927c5ae | 526 | |
8b0ba111 | 527 | if (noninteractive && NILP (Vexecuting_kbd_macro)) |
c28b847b | 528 | { |
6b61353c KH |
529 | val = read_minibuf_noninteractive (map, initial, prompt, |
530 | make_number (pos), | |
c28b847b GM |
531 | expflag, histvar, histpos, defalt, |
532 | allow_props, inherit_input_method); | |
f9b9ccef | 533 | UNGCPRO; |
c28b847b GM |
534 | return unbind_to (count, val); |
535 | } | |
edfef199 | 536 | |
748dc60a | 537 | /* Choose the minibuffer window and frame, and take action on them. */ |
f927c5ae | 538 | |
c5b6b680 RS |
539 | choose_minibuf_frame (); |
540 | ||
0c94f256 RS |
541 | record_unwind_protect (choose_minibuf_frame_1, Qnil); |
542 | ||
f927c5ae | 543 | record_unwind_protect (Fset_window_configuration, |
b2b2c677 JB |
544 | Fcurrent_window_configuration (Qnil)); |
545 | ||
ff11dfa1 JB |
546 | /* If the minibuffer window is on a different frame, save that |
547 | frame's configuration too. */ | |
75f00e72 | 548 | mini_frame = WINDOW_FRAME (XWINDOW (minibuf_window)); |
a4aafc54 | 549 | if (!EQ (mini_frame, selected_frame)) |
5061d9c3 RS |
550 | record_unwind_protect (Fset_window_configuration, |
551 | Fcurrent_window_configuration (mini_frame)); | |
5563e8e8 KH |
552 | |
553 | /* If the minibuffer is on an iconified or invisible frame, | |
554 | make it visible now. */ | |
555 | Fmake_frame_visible (mini_frame); | |
556 | ||
6a9ee000 RS |
557 | if (minibuffer_auto_raise) |
558 | Fraise_frame (mini_frame); | |
f927c5ae | 559 | |
b3e6f69c | 560 | temporarily_switch_to_single_kboard (XFRAME (mini_frame)); |
256c9c3a | 561 | |
748dc60a RS |
562 | /* We have to do this after saving the window configuration |
563 | since that is what restores the current buffer. */ | |
564 | ||
565 | /* Arrange to restore a number of minibuffer-related variables. | |
566 | We could bind each variable separately, but that would use lots of | |
567 | specpdl slots. */ | |
568 | minibuf_save_list | |
569 | = Fcons (Voverriding_local_map, | |
3372a51b | 570 | Fcons (minibuf_window, |
ef72eaff | 571 | minibuf_save_list)); |
748dc60a RS |
572 | minibuf_save_list |
573 | = Fcons (minibuf_prompt, | |
574 | Fcons (make_number (minibuf_prompt_width), | |
575 | Fcons (Vhelp_form, | |
576 | Fcons (Vcurrent_prefix_arg, | |
577 | Fcons (Vminibuffer_history_position, | |
578 | Fcons (Vminibuffer_history_variable, | |
579 | minibuf_save_list)))))); | |
580 | ||
581 | record_unwind_protect (read_minibuf_unwind, Qnil); | |
582 | minibuf_level++; | |
7292839d SM |
583 | /* We are exiting the minibuffer one way or the other, so run the hook. |
584 | It should be run before unwinding the minibuf settings. Do it | |
585 | separately from read_minibuf_unwind because we need to make sure that | |
586 | read_minibuf_unwind is fully executed even if exit-minibuffer-hook | |
587 | signals an error. --Stef */ | |
588 | record_unwind_protect (run_exit_minibuf_hook, Qnil); | |
748dc60a RS |
589 | |
590 | /* Now that we can restore all those variables, start changing them. */ | |
591 | ||
1e3f16d5 | 592 | minibuf_prompt_width = 0; |
748dc60a RS |
593 | minibuf_prompt = Fcopy_sequence (prompt); |
594 | Vminibuffer_history_position = histpos; | |
595 | Vminibuffer_history_variable = histvar; | |
596 | Vhelp_form = Vminibuffer_help_form; | |
ef72eaff KS |
597 | /* If this minibuffer is reading a file name, that doesn't mean |
598 | recursive ones are. But we cannot set it to nil, because | |
599 | completion code still need to know the minibuffer is completing a | |
600 | file name. So use `lambda' as intermediate value meaning | |
601 | "t" in this minibuffer, but "nil" in next minibuffer. */ | |
602 | if (!NILP (Vminibuffer_completing_file_name)) | |
603 | Vminibuffer_completing_file_name = Qlambda; | |
748dc60a | 604 | |
cee54539 | 605 | if (inherit_input_method) |
c75000c7 | 606 | { |
fd771ceb | 607 | /* `current-input-method' is buffer local. So, remember it in |
c75000c7 RS |
608 | INPUT_METHOD before changing the current buffer. */ |
609 | input_method = Fsymbol_value (Qcurrent_input_method); | |
610 | enable_multibyte = current_buffer->enable_multibyte_characters; | |
611 | } | |
cee54539 | 612 | |
748dc60a RS |
613 | /* Switch to the minibuffer. */ |
614 | ||
4f69d8f6 RS |
615 | minibuffer = get_minibuffer (minibuf_level); |
616 | Fset_buffer (minibuffer); | |
64a3a3c0 | 617 | |
1d69c502 RS |
618 | /* If appropriate, copy enable-multibyte-characters into the minibuffer. */ |
619 | if (inherit_input_method) | |
620 | current_buffer->enable_multibyte_characters = enable_multibyte; | |
621 | ||
64a3a3c0 JB |
622 | /* The current buffer's default directory is usually the right thing |
623 | for our minibuffer here. However, if you're typing a command at | |
624 | a minibuffer-only frame when minibuf_level is zero, then buf IS | |
625 | the current_buffer, so reset_buffer leaves buf's default | |
626 | directory unchanged. This is a bummer when you've just started | |
627 | up Emacs and buf's default directory is Qnil. Here's a hack; can | |
628 | you think of something better to do? Find another buffer with a | |
629 | better directory, and use that one instead. */ | |
748dc60a RS |
630 | if (STRINGP (ambient_dir)) |
631 | current_buffer->directory = ambient_dir; | |
64a3a3c0 JB |
632 | else |
633 | { | |
634 | Lisp_Object buf_list; | |
635 | ||
636 | for (buf_list = Vbuffer_alist; | |
637 | CONSP (buf_list); | |
7539e11f | 638 | buf_list = XCDR (buf_list)) |
64a3a3c0 | 639 | { |
1e62748e | 640 | Lisp_Object other_buf; |
64a3a3c0 | 641 | |
7539e11f | 642 | other_buf = XCDR (XCAR (buf_list)); |
7510b296 | 643 | if (STRINGP (XBUFFER (other_buf)->directory)) |
64a3a3c0 JB |
644 | { |
645 | current_buffer->directory = XBUFFER (other_buf)->directory; | |
646 | break; | |
647 | } | |
648 | } | |
649 | } | |
650 | ||
a4aafc54 GM |
651 | if (!EQ (mini_frame, selected_frame)) |
652 | Fredirect_frame_focus (selected_frame, mini_frame); | |
43bad991 | 653 | |
f927c5ae | 654 | Vminibuf_scroll_window = selected_window; |
6122844a | 655 | if (minibuf_level == 1 || !EQ (minibuf_window, selected_window)) |
5705966b | 656 | minibuf_selected_window = selected_window; |
b20de1cd RS |
657 | |
658 | /* Empty out the minibuffers of all frames other than the one | |
659 | where we are going to display one now. | |
660 | Set them to point to ` *Minibuf-0*', which is always empty. */ | |
661 | empty_minibuf = Fget_buffer (build_string (" *Minibuf-0*")); | |
662 | ||
663 | FOR_EACH_FRAME (dummy, frame) | |
664 | { | |
665 | Lisp_Object root_window = Fframe_root_window (frame); | |
666 | Lisp_Object mini_window = XWINDOW (root_window)->next; | |
667 | ||
dd95745a RS |
668 | if (! NILP (mini_window) && ! EQ (mini_window, minibuf_window) |
669 | && !NILP (Fwindow_minibuffer_p (mini_window))) | |
b20de1cd RS |
670 | Fset_window_buffer (mini_window, empty_minibuf, Qnil); |
671 | } | |
672 | ||
673 | /* Display this minibuffer in the proper window. */ | |
cbbfe056 | 674 | Fset_window_buffer (minibuf_window, Fcurrent_buffer (), Qnil); |
f1321dc3 | 675 | Fselect_window (minibuf_window, Qnil); |
5a866662 | 676 | XSETFASTINT (XWINDOW (minibuf_window)->hscroll, 0); |
f927c5ae | 677 | |
748dc60a RS |
678 | Fmake_local_variable (Qprint_escape_newlines); |
679 | print_escape_newlines = 1; | |
680 | ||
681 | /* Erase the buffer. */ | |
59115a22 | 682 | { |
331379bf | 683 | int count1 = SPECPDL_INDEX (); |
59115a22 | 684 | specbind (Qinhibit_read_only, Qt); |
a41edd99 | 685 | specbind (Qinhibit_modification_hooks, Qt); |
59115a22 | 686 | Ferase_buffer (); |
d9d7b298 SM |
687 | |
688 | if (!NILP (current_buffer->enable_multibyte_characters) | |
689 | && ! STRING_MULTIBYTE (minibuf_prompt)) | |
690 | minibuf_prompt = Fstring_make_multibyte (minibuf_prompt); | |
6cc62df0 | 691 | |
d9d7b298 SM |
692 | /* Insert the prompt, record where it ends. */ |
693 | Finsert (1, &minibuf_prompt); | |
694 | if (PT > BEG) | |
695 | { | |
696 | Fput_text_property (make_number (BEG), make_number (PT), | |
697 | Qfront_sticky, Qt, Qnil); | |
698 | Fput_text_property (make_number (BEG), make_number (PT), | |
699 | Qrear_nonsticky, Qt, Qnil); | |
700 | Fput_text_property (make_number (BEG), make_number (PT), | |
701 | Qfield, Qt, Qnil); | |
702 | Fadd_text_properties (make_number (BEG), make_number (PT), | |
703 | Vminibuffer_prompt_properties, Qnil); | |
704 | } | |
59115a22 RS |
705 | unbind_to (count1, Qnil); |
706 | } | |
707 | ||
9ab4a725 TTN |
708 | minibuf_prompt_width = (int) current_column (); /* iftc */ |
709 | ||
748dc60a | 710 | /* Put in the initial input. */ |
56a98455 | 711 | if (!NILP (initial)) |
f927c5ae JB |
712 | { |
713 | Finsert (1, &initial); | |
6b61353c | 714 | Fforward_char (make_number (pos)); |
f927c5ae JB |
715 | } |
716 | ||
39e98b38 | 717 | clear_message (1, 1); |
f927c5ae JB |
718 | current_buffer->keymap = map; |
719 | ||
cee54539 | 720 | /* Turn on an input method stored in INPUT_METHOD if any. */ |
6801b300 | 721 | if (STRINGP (input_method) && !NILP (Ffboundp (Qactivate_input_method))) |
cee54539 KH |
722 | call1 (Qactivate_input_method, input_method); |
723 | ||
5c781212 RS |
724 | /* Run our hook, but not if it is empty. |
725 | (run-hooks would do nothing if it is empty, | |
fd771ceb | 726 | but it's important to save time here in the usual case.) */ |
92d3b06e RS |
727 | if (!NILP (Vminibuffer_setup_hook) && !EQ (Vminibuffer_setup_hook, Qunbound) |
728 | && !NILP (Vrun_hooks)) | |
5c781212 RS |
729 | call1 (Vrun_hooks, Qminibuffer_setup_hook); |
730 | ||
4e6b7204 MB |
731 | /* Don't allow the user to undo past this point. */ |
732 | current_buffer->undo_list = Qnil; | |
733 | ||
f927c5ae JB |
734 | recursive_edit_1 (); |
735 | ||
736 | /* If cursor is on the minibuffer line, | |
737 | show the user we have exited by putting it in column 0. */ | |
279cf52c | 738 | if (XWINDOW (minibuf_window)->cursor.vpos >= 0 |
f927c5ae JB |
739 | && !noninteractive) |
740 | { | |
279cf52c GM |
741 | XWINDOW (minibuf_window)->cursor.hpos = 0; |
742 | XWINDOW (minibuf_window)->cursor.x = 0; | |
743 | XWINDOW (minibuf_window)->must_be_updated_p = 1; | |
a4aafc54 | 744 | update_frame (XFRAME (selected_frame), 1, 1); |
fa971ac3 KL |
745 | { |
746 | struct frame *f = XFRAME (XWINDOW (minibuf_window)->frame); | |
747 | struct redisplay_interface *rif = FRAME_RIF (f); | |
748 | if (rif && rif->flush_display) | |
749 | rif->flush_display (f); | |
750 | } | |
f927c5ae JB |
751 | } |
752 | ||
c3421833 | 753 | /* Make minibuffer contents into a string. */ |
4f69d8f6 | 754 | Fset_buffer (minibuffer); |
be95a9b6 | 755 | if (allow_props) |
a346ec72 | 756 | val = Fminibuffer_contents (); |
be95a9b6 | 757 | else |
a346ec72 | 758 | val = Fminibuffer_contents_no_properties (); |
770970cb | 759 | |
b278606c | 760 | /* VAL is the string of minibuffer text. */ |
7019cca7 | 761 | |
b278606c BF |
762 | last_minibuf_string = val; |
763 | ||
4f9f637a | 764 | /* Choose the string to add to the history. */ |
b35cd215 | 765 | if (SCHARS (val) != 0) |
4f9f637a RS |
766 | histstring = val; |
767 | else if (STRINGP (defalt)) | |
768 | histstring = defalt; | |
fb30dfd2 JL |
769 | else if (CONSP (defalt) && STRINGP (XCAR (defalt))) |
770 | histstring = XCAR (defalt); | |
4f9f637a RS |
771 | else |
772 | histstring = Qnil; | |
773 | ||
774 | /* Add the value to the appropriate history list, if any. */ | |
179a4ca7 JL |
775 | if (!NILP (Vhistory_add_new_input) |
776 | && SYMBOLP (Vminibuffer_history_variable) | |
4f9f637a | 777 | && !NILP (histstring)) |
3ab14176 KH |
778 | { |
779 | /* If the caller wanted to save the value read on a history list, | |
780 | then do so if the value is not already the front of the list. */ | |
781 | Lisp_Object histval; | |
c6d65724 RS |
782 | |
783 | /* If variable is unbound, make it nil. */ | |
c6d65724 | 784 | |
8c2dccbf SM |
785 | histval = find_symbol_value (Vminibuffer_history_variable); |
786 | if (EQ (histval, Qunbound)) | |
787 | Fset (Vminibuffer_history_variable, Qnil); | |
3ab14176 KH |
788 | |
789 | /* The value of the history variable must be a cons or nil. Other | |
790 | values are unacceptable. We silently ignore these values. */ | |
4f9f637a | 791 | |
3ab14176 | 792 | if (NILP (histval) |
9f6131cf | 793 | || (CONSP (histval) |
4f9f637a | 794 | /* Don't duplicate the most recent entry in the history. */ |
b35cd215 | 795 | && (NILP (Fequal (histstring, Fcar (histval)))))) |
77aa8edf RS |
796 | { |
797 | Lisp_Object length; | |
798 | ||
0da4d471 | 799 | if (history_delete_duplicates) Fdelete (histstring, histval); |
4f9f637a | 800 | histval = Fcons (histstring, histval); |
77aa8edf RS |
801 | Fset (Vminibuffer_history_variable, histval); |
802 | ||
803 | /* Truncate if requested. */ | |
804 | length = Fget (Vminibuffer_history_variable, Qhistory_length); | |
805 | if (NILP (length)) length = Vhistory_length; | |
e5d4686b RS |
806 | if (INTEGERP (length)) |
807 | { | |
808 | if (XINT (length) <= 0) | |
809 | Fset (Vminibuffer_history_variable, Qnil); | |
810 | else | |
811 | { | |
812 | Lisp_Object temp; | |
813 | ||
814 | temp = Fnthcdr (Fsub1 (length), histval); | |
815 | if (CONSP (temp)) Fsetcdr (temp, Qnil); | |
816 | } | |
817 | } | |
77aa8edf | 818 | } |
9f6131cf RS |
819 | } |
820 | ||
821 | /* If Lisp form desired instead of string, parse it. */ | |
822 | if (expflag) | |
edfef199 | 823 | val = string_to_object (val, defalt); |
3ab14176 | 824 | |
00a34088 RS |
825 | /* The appropriate frame will get selected |
826 | in set-window-configuration. */ | |
f9b9ccef SM |
827 | UNGCPRO; |
828 | return unbind_to (count, val); | |
f927c5ae JB |
829 | } |
830 | ||
831 | /* Return a buffer to be used as the minibuffer at depth `depth'. | |
832 | depth = 0 is the lowest allowed argument, and that is the value | |
833 | used for nonrecursive minibuffer invocations */ | |
834 | ||
835 | Lisp_Object | |
836 | get_minibuffer (depth) | |
837 | int depth; | |
838 | { | |
839 | Lisp_Object tail, num, buf; | |
9f6c23bc | 840 | char name[24]; |
f927c5ae JB |
841 | extern Lisp_Object nconc2 (); |
842 | ||
5a866662 | 843 | XSETFASTINT (num, depth); |
f927c5ae | 844 | tail = Fnthcdr (num, Vminibuffer_list); |
56a98455 | 845 | if (NILP (tail)) |
f927c5ae JB |
846 | { |
847 | tail = Fcons (Qnil, Qnil); | |
848 | Vminibuffer_list = nconc2 (Vminibuffer_list, tail); | |
849 | } | |
850 | buf = Fcar (tail); | |
56a98455 | 851 | if (NILP (buf) || NILP (XBUFFER (buf)->name)) |
f927c5ae JB |
852 | { |
853 | sprintf (name, " *Minibuf-%d*", depth); | |
854 | buf = Fget_buffer_create (build_string (name)); | |
5d6533f1 JB |
855 | |
856 | /* Although the buffer's name starts with a space, undo should be | |
857 | enabled in it. */ | |
858 | Fbuffer_enable_undo (buf); | |
859 | ||
f3fbd155 | 860 | XSETCAR (tail, buf); |
f927c5ae JB |
861 | } |
862 | else | |
5956f71d | 863 | { |
aed13378 | 864 | int count = SPECPDL_INDEX (); |
7f856567 SM |
865 | /* `reset_buffer' blindly sets the list of overlays to NULL, so we |
866 | have to empty the list, otherwise we end up with overlays that | |
867 | think they belong to this buffer while the buffer doesn't know about | |
868 | them any more. */ | |
599ca9c2 SM |
869 | delete_all_overlays (XBUFFER (buf)); |
870 | reset_buffer (XBUFFER (buf)); | |
6b3faad8 RS |
871 | record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); |
872 | Fset_buffer (buf); | |
873 | Fkill_all_local_variables (); | |
874 | unbind_to (count, Qnil); | |
5956f71d | 875 | } |
64a3a3c0 | 876 | |
f927c5ae JB |
877 | return buf; |
878 | } | |
879 | ||
7292839d SM |
880 | static Lisp_Object |
881 | run_exit_minibuf_hook (data) | |
882 | Lisp_Object data; | |
883 | { | |
884 | if (!NILP (Vminibuffer_exit_hook) && !EQ (Vminibuffer_exit_hook, Qunbound) | |
885 | && !NILP (Vrun_hooks)) | |
886 | safe_run_hooks (Qminibuffer_exit_hook); | |
887 | ||
888 | return Qnil; | |
889 | } | |
890 | ||
279cf52c GM |
891 | /* This function is called on exiting minibuffer, whether normally or |
892 | not, and it restores the current window, buffer, etc. */ | |
f927c5ae | 893 | |
9d815fd9 | 894 | static Lisp_Object |
43bad991 JB |
895 | read_minibuf_unwind (data) |
896 | Lisp_Object data; | |
f927c5ae | 897 | { |
c24e1160 | 898 | Lisp_Object old_deactivate_mark; |
59115a22 | 899 | Lisp_Object window; |
c24e1160 | 900 | |
f927c5ae | 901 | /* If this was a recursive minibuffer, |
59115a22 | 902 | tie the minibuffer window back to the outer level minibuffer buffer. */ |
f927c5ae | 903 | minibuf_level--; |
f927c5ae | 904 | |
59115a22 | 905 | window = minibuf_window; |
279cf52c GM |
906 | /* To keep things predictable, in case it matters, let's be in the |
907 | minibuffer when we reset the relevant variables. */ | |
59115a22 RS |
908 | Fset_buffer (XWINDOW (window)->buffer); |
909 | ||
910 | /* Restore prompt, etc, from outer minibuffer level. */ | |
4d04c1f1 KH |
911 | minibuf_prompt = Fcar (minibuf_save_list); |
912 | minibuf_save_list = Fcdr (minibuf_save_list); | |
913 | minibuf_prompt_width = XFASTINT (Fcar (minibuf_save_list)); | |
914 | minibuf_save_list = Fcdr (minibuf_save_list); | |
915 | Vhelp_form = Fcar (minibuf_save_list); | |
916 | minibuf_save_list = Fcdr (minibuf_save_list); | |
ee9e37ab | 917 | Vcurrent_prefix_arg = Fcar (minibuf_save_list); |
4d04c1f1 KH |
918 | minibuf_save_list = Fcdr (minibuf_save_list); |
919 | Vminibuffer_history_position = Fcar (minibuf_save_list); | |
920 | minibuf_save_list = Fcdr (minibuf_save_list); | |
921 | Vminibuffer_history_variable = Fcar (minibuf_save_list); | |
922 | minibuf_save_list = Fcdr (minibuf_save_list); | |
30e13e56 | 923 | Voverriding_local_map = Fcar (minibuf_save_list); |
c5b6b680 | 924 | minibuf_save_list = Fcdr (minibuf_save_list); |
914860c2 RS |
925 | #if 0 |
926 | temp = Fcar (minibuf_save_list); | |
927 | if (FRAME_LIVE_P (XFRAME (WINDOW_FRAME (XWINDOW (temp))))) | |
928 | minibuf_window = temp; | |
929 | #endif | |
30e13e56 | 930 | minibuf_save_list = Fcdr (minibuf_save_list); |
59115a22 RS |
931 | |
932 | /* Erase the minibuffer we were using at this level. */ | |
933 | { | |
aed13378 | 934 | int count = SPECPDL_INDEX (); |
59115a22 RS |
935 | /* Prevent error in erase-buffer. */ |
936 | specbind (Qinhibit_read_only, Qt); | |
bd819d14 | 937 | specbind (Qinhibit_modification_hooks, Qt); |
59115a22 RS |
938 | old_deactivate_mark = Vdeactivate_mark; |
939 | Ferase_buffer (); | |
940 | Vdeactivate_mark = old_deactivate_mark; | |
941 | unbind_to (count, Qnil); | |
942 | } | |
943 | ||
544e358d GM |
944 | /* When we get to the outmost level, make sure we resize the |
945 | mini-window back to its normal size. */ | |
946 | if (minibuf_level == 0) | |
1e3f16d5 | 947 | resize_mini_window (XWINDOW (window), 0); |
544e358d | 948 | |
59115a22 RS |
949 | /* Make sure minibuffer window is erased, not ignored. */ |
950 | windows_or_buffers_changed++; | |
951 | XSETFASTINT (XWINDOW (window)->last_modified, 0); | |
193e4518 | 952 | XSETFASTINT (XWINDOW (window)->last_overlay_modified, 0); |
9d815fd9 | 953 | return Qnil; |
f927c5ae JB |
954 | } |
955 | \f | |
b9d721de | 956 | |
b35cd215 | 957 | DEFUN ("read-from-minibuffer", Fread_from_minibuffer, Sread_from_minibuffer, 1, 7, 0, |
af52c32d | 958 | doc: /* Read a string from the minibuffer, prompting with string PROMPT. |
6b61353c KH |
959 | The optional second arg INITIAL-CONTENTS is an obsolete alternative to |
960 | DEFAULT-VALUE. It normally should be nil in new code, except when | |
961 | HIST is a cons. It is discussed in more detail below. | |
a1f17501 PJ |
962 | Third arg KEYMAP is a keymap to use whilst reading; |
963 | if omitted or nil, the default is `minibuffer-local-map'. | |
fd771ceb | 964 | If fourth arg READ is non-nil, then interpret the result as a Lisp object |
a1f17501 PJ |
965 | and return that object: |
966 | in other words, do `(car (read-from-string INPUT-STRING))' | |
6b61353c KH |
967 | Fifth arg HIST, if non-nil, specifies a history list and optionally |
968 | the initial position in the list. It can be a symbol, which is the | |
969 | history list variable to use, or it can be a cons cell | |
970 | (HISTVAR . HISTPOS). In that case, HISTVAR is the history list variable | |
971 | to use, and HISTPOS is the initial position for use by the minibuffer | |
972 | history commands. For consistency, you should also specify that | |
973 | element of the history as the value of INITIAL-CONTENTS. Positions | |
974 | are counted starting from 1 at the beginning of the list. | |
2e3148e2 JL |
975 | Sixth arg DEFAULT-VALUE is the default value or the list of default values. |
976 | If non-nil, it is available for history commands, and as the value | |
977 | (or the first element of the list of default values) to return | |
978 | if the user enters the empty string. But, unless READ is non-nil, | |
979 | `read-from-minibuffer' does NOT return DEFAULT-VALUE if the user enters | |
980 | empty input! It returns the empty string. | |
a1f17501 | 981 | Seventh arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits |
029a305c | 982 | the current input method and the setting of `enable-multibyte-characters'. |
a1f17501 PJ |
983 | If the variable `minibuffer-allow-text-properties' is non-nil, |
984 | then the string which is returned includes whatever text properties | |
6b61353c KH |
985 | were present in the minibuffer. Otherwise the value has no text properties. |
986 | ||
987 | The remainder of this documentation string describes the | |
988 | INITIAL-CONTENTS argument in more detail. It is only relevant when | |
989 | studying existing code, or when HIST is a cons. If non-nil, | |
990 | INITIAL-CONTENTS is a string to be inserted into the minibuffer before | |
991 | reading input. Normally, point is put at the end of that string. | |
992 | However, if INITIAL-CONTENTS is \(STRING . POSITION), the initial | |
993 | input is STRING, but point is placed at _one-indexed_ position | |
994 | POSITION in the minibuffer. Any integer value less than or equal to | |
995 | one puts point at the beginning of the string. *Note* that this | |
996 | behavior differs from the way such arguments are used in `completing-read' | |
997 | and some related functions, which use zero-indexing for POSITION. */) | |
4bafae49 | 998 | (prompt, initial_contents, keymap, read, hist, default_value, inherit_input_method) |
e5d4686b | 999 | Lisp_Object prompt, initial_contents, keymap, read, hist, default_value; |
b35cd215 | 1000 | Lisp_Object inherit_input_method; |
f927c5ae | 1001 | { |
6b61353c | 1002 | Lisp_Object histvar, histpos, val; |
1d8d92f4 RS |
1003 | struct gcpro gcpro1; |
1004 | ||
b7826503 | 1005 | CHECK_STRING (prompt); |
56a98455 | 1006 | if (NILP (keymap)) |
f927c5ae JB |
1007 | keymap = Vminibuffer_local_map; |
1008 | else | |
02067692 | 1009 | keymap = get_keymap (keymap, 1, 0); |
770970cb | 1010 | |
7510b296 | 1011 | if (SYMBOLP (hist)) |
770970cb RS |
1012 | { |
1013 | histvar = hist; | |
1014 | histpos = Qnil; | |
1015 | } | |
1016 | else | |
1017 | { | |
1018 | histvar = Fcar_safe (hist); | |
1019 | histpos = Fcdr_safe (hist); | |
1020 | } | |
1021 | if (NILP (histvar)) | |
1022 | histvar = Qminibuffer_history; | |
1023 | if (NILP (histpos)) | |
5a866662 | 1024 | XSETFASTINT (histpos, 0); |
770970cb | 1025 | |
1d8d92f4 | 1026 | GCPRO1 (default_value); |
e5d4686b | 1027 | val = read_minibuf (keymap, initial_contents, prompt, |
6b61353c | 1028 | Qnil, !NILP (read), |
c3421833 | 1029 | histvar, histpos, default_value, |
cee54539 | 1030 | minibuffer_allow_text_properties, |
b35cd215 | 1031 | !NILP (inherit_input_method)); |
1d8d92f4 | 1032 | UNGCPRO; |
e5d4686b | 1033 | return val; |
f927c5ae JB |
1034 | } |
1035 | ||
1036 | DEFUN ("read-minibuffer", Fread_minibuffer, Sread_minibuffer, 1, 2, 0, | |
6b61353c | 1037 | doc: /* Return a Lisp object read using the minibuffer, unevaluated. |
a1f17501 | 1038 | Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS |
6b61353c | 1039 | is a string to insert in the minibuffer before reading. |
e298936f JB |
1040 | \(INITIAL-CONTENTS can also be a cons of a string and an integer. |
1041 | Such arguments are used as in `read-from-minibuffer'.) */) | |
af52c32d | 1042 | (prompt, initial_contents) |
f927c5ae JB |
1043 | Lisp_Object prompt, initial_contents; |
1044 | { | |
b7826503 | 1045 | CHECK_STRING (prompt); |
770970cb | 1046 | return read_minibuf (Vminibuffer_local_map, initial_contents, |
e5d4686b | 1047 | prompt, Qnil, 1, Qminibuffer_history, |
b35cd215 | 1048 | make_number (0), Qnil, 0, 0); |
f927c5ae JB |
1049 | } |
1050 | ||
1051 | DEFUN ("eval-minibuffer", Feval_minibuffer, Seval_minibuffer, 1, 2, 0, | |
af52c32d | 1052 | doc: /* Return value of Lisp expression read using the minibuffer. |
a1f17501 | 1053 | Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS |
6b61353c | 1054 | is a string to insert in the minibuffer before reading. |
e298936f JB |
1055 | \(INITIAL-CONTENTS can also be a cons of a string and an integer. |
1056 | Such arguments are used as in `read-from-minibuffer'.) */) | |
af52c32d | 1057 | (prompt, initial_contents) |
f927c5ae JB |
1058 | Lisp_Object prompt, initial_contents; |
1059 | { | |
627fb581 RS |
1060 | return Feval (read_minibuf (Vread_expression_map, initial_contents, |
1061 | prompt, Qnil, 1, Qread_expression_history, | |
1062 | make_number (0), Qnil, 0, 0)); | |
f927c5ae JB |
1063 | } |
1064 | ||
1065 | /* Functions that use the minibuffer to read various things. */ | |
1066 | ||
cee54539 | 1067 | DEFUN ("read-string", Fread_string, Sread_string, 1, 5, 0, |
af52c32d | 1068 | doc: /* Read a string from the minibuffer, prompting with string PROMPT. |
a1f17501 | 1069 | If non-nil, second arg INITIAL-INPUT is a string to insert before reading. |
6b61353c KH |
1070 | This argument has been superseded by DEFAULT-VALUE and should normally |
1071 | be nil in new code. It behaves as in `read-from-minibuffer'. See the | |
1072 | documentation string of that function for details. | |
a1f17501 PJ |
1073 | The third arg HISTORY, if non-nil, specifies a history list |
1074 | and optionally the initial position in the list. | |
1075 | See `read-from-minibuffer' for details of HISTORY argument. | |
2e3148e2 JL |
1076 | Fourth arg DEFAULT-VALUE is the default value or the list of default values. |
1077 | If non-nil, it is used for history commands, and as the value (or the first | |
1078 | element of the list of default values) to return if the user enters the | |
1079 | empty string. | |
a1f17501 | 1080 | Fifth arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits |
029a305c | 1081 | the current input method and the setting of `enable-multibyte-characters'. */) |
af52c32d | 1082 | (prompt, initial_input, history, default_value, inherit_input_method) |
e5d4686b | 1083 | Lisp_Object prompt, initial_input, history, default_value; |
cee54539 | 1084 | Lisp_Object inherit_input_method; |
f927c5ae | 1085 | { |
b9a86585 RS |
1086 | Lisp_Object val; |
1087 | val = Fread_from_minibuffer (prompt, initial_input, Qnil, | |
1088 | Qnil, history, default_value, | |
b35cd215 | 1089 | inherit_input_method); |
d5db4077 | 1090 | if (STRINGP (val) && SCHARS (val) == 0 && ! NILP (default_value)) |
fb30dfd2 | 1091 | val = CONSP (default_value) ? XCAR (default_value) : default_value; |
b9a86585 | 1092 | return val; |
f927c5ae JB |
1093 | } |
1094 | ||
cee54539 | 1095 | DEFUN ("read-no-blanks-input", Fread_no_blanks_input, Sread_no_blanks_input, 1, 3, 0, |
af52c32d | 1096 | doc: /* Read a string from the terminal, not allowing blanks. |
6b61353c KH |
1097 | Prompt with PROMPT. Whitespace terminates the input. If INITIAL is |
1098 | non-nil, it should be a string, which is used as initial input, with | |
1099 | point positioned at the end, so that SPACE will accept the input. | |
1100 | \(Actually, INITIAL can also be a cons of a string and an integer. | |
1101 | Such values are treated as in `read-from-minibuffer', but are normally | |
1102 | not useful in this function.) | |
a1f17501 | 1103 | Third arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits |
6b61353c | 1104 | the current input method and the setting of`enable-multibyte-characters'. */) |
af52c32d | 1105 | (prompt, initial, inherit_input_method) |
c923ccc9 | 1106 | Lisp_Object prompt, initial, inherit_input_method; |
f927c5ae | 1107 | { |
b7826503 | 1108 | CHECK_STRING (prompt); |
c923ccc9 | 1109 | return read_minibuf (Vminibuffer_local_ns_map, initial, prompt, Qnil, |
cee54539 | 1110 | 0, Qminibuffer_history, make_number (0), Qnil, 0, |
b35cd215 | 1111 | !NILP (inherit_input_method)); |
f927c5ae JB |
1112 | } |
1113 | ||
e5d4686b | 1114 | DEFUN ("read-command", Fread_command, Sread_command, 1, 2, 0, |
af52c32d | 1115 | doc: /* Read the name of a command and return as a symbol. |
2e3148e2 JL |
1116 | Prompt with PROMPT. By default, return DEFAULT-VALUE or its first element |
1117 | if it is a list. */) | |
af52c32d | 1118 | (prompt, default_value) |
e5d4686b | 1119 | Lisp_Object prompt, default_value; |
f927c5ae | 1120 | { |
7c8d9931 RS |
1121 | Lisp_Object name, default_string; |
1122 | ||
1123 | if (NILP (default_value)) | |
1124 | default_string = Qnil; | |
1125 | else if (SYMBOLP (default_value)) | |
caa4733e | 1126 | default_string = SYMBOL_NAME (default_value); |
7c8d9931 RS |
1127 | else |
1128 | default_string = default_value; | |
9ab4a725 | 1129 | |
7c8d9931 RS |
1130 | name = Fcompleting_read (prompt, Vobarray, Qcommandp, Qt, |
1131 | Qnil, Qnil, default_string, Qnil); | |
1132 | if (NILP (name)) | |
1133 | return name; | |
1134 | return Fintern (name, Qnil); | |
f927c5ae JB |
1135 | } |
1136 | ||
1137 | #ifdef NOTDEF | |
1138 | DEFUN ("read-function", Fread_function, Sread_function, 1, 1, 0, | |
af52c32d | 1139 | doc: /* One arg PROMPT, a string. Read the name of a function and return as a symbol. |
fd771ceb | 1140 | Prompt with PROMPT. */) |
af52c32d | 1141 | (prompt) |
f927c5ae JB |
1142 | Lisp_Object prompt; |
1143 | { | |
cee54539 | 1144 | return Fintern (Fcompleting_read (prompt, Vobarray, Qfboundp, Qt, Qnil, Qnil, Qnil, Qnil), |
f927c5ae JB |
1145 | Qnil); |
1146 | } | |
1147 | #endif /* NOTDEF */ | |
1148 | ||
e5d4686b | 1149 | DEFUN ("read-variable", Fread_variable, Sread_variable, 1, 2, 0, |
af52c32d | 1150 | doc: /* Read the name of a user variable and return it as a symbol. |
2e3148e2 JL |
1151 | Prompt with PROMPT. By default, return DEFAULT-VALUE or its first element |
1152 | if it is a list. | |
316f9bfc | 1153 | A user variable is one for which `user-variable-p' returns non-nil. */) |
af52c32d | 1154 | (prompt, default_value) |
e5d4686b | 1155 | Lisp_Object prompt, default_value; |
f927c5ae | 1156 | { |
7c8d9931 RS |
1157 | Lisp_Object name, default_string; |
1158 | ||
1159 | if (NILP (default_value)) | |
1160 | default_string = Qnil; | |
1161 | else if (SYMBOLP (default_value)) | |
caa4733e | 1162 | default_string = SYMBOL_NAME (default_value); |
7c8d9931 RS |
1163 | else |
1164 | default_string = default_value; | |
9ab4a725 | 1165 | |
7c8d9931 RS |
1166 | name = Fcompleting_read (prompt, Vobarray, |
1167 | Quser_variable_p, Qt, | |
1168 | Qnil, Qnil, default_string, Qnil); | |
1169 | if (NILP (name)) | |
1170 | return name; | |
1171 | return Fintern (name, Qnil); | |
f927c5ae JB |
1172 | } |
1173 | ||
1174 | DEFUN ("read-buffer", Fread_buffer, Sread_buffer, 1, 3, 0, | |
fd771ceb PJ |
1175 | doc: /* Read the name of a buffer and return as a string. |
1176 | Prompt with PROMPT. | |
a1f17501 | 1177 | Optional second arg DEF is value to return if user enters an empty line. |
2e3148e2 | 1178 | If DEF is a list of default values, return its first element. |
fd771ceb | 1179 | If optional third arg REQUIRE-MATCH is non-nil, |
97c3e4cc RF |
1180 | only existing buffer names are allowed. |
1181 | The argument PROMPT should be a string ending with a colon and a space. */) | |
af52c32d | 1182 | (prompt, def, require_match) |
f927c5ae JB |
1183 | Lisp_Object prompt, def, require_match; |
1184 | { | |
eebbfb01 | 1185 | Lisp_Object args[4]; |
97c3e4cc RF |
1186 | unsigned char *s; |
1187 | int len; | |
9ab4a725 | 1188 | |
7510b296 | 1189 | if (BUFFERP (def)) |
f927c5ae | 1190 | def = XBUFFER (def)->name; |
eebbfb01 KH |
1191 | |
1192 | if (NILP (Vread_buffer_function)) | |
1193 | { | |
1194 | if (!NILP (def)) | |
1195 | { | |
97c3e4cc RF |
1196 | /* A default value was provided: we must change PROMPT, |
1197 | editing the default value in before the colon. To achieve | |
1198 | this, we replace PROMPT with a substring that doesn't | |
1199 | contain the terminal space and colon (if present). They | |
1200 | are then added back using Fformat. */ | |
1201 | ||
1202 | if (STRINGP (prompt)) | |
1203 | { | |
1204 | s = SDATA (prompt); | |
1205 | len = strlen (s); | |
1206 | if (len >= 2 && s[len - 2] == ':' && s[len - 1] == ' ') | |
1207 | len = len - 2; | |
1208 | else if (len >= 1 && (s[len - 1] == ':' || s[len - 1] == ' ')) | |
1209 | len--; | |
1210 | ||
1211 | prompt = make_specified_string (s, -1, len, | |
1212 | STRING_MULTIBYTE (prompt)); | |
1213 | } | |
1214 | ||
1215 | args[0] = build_string ("%s (default %s): "); | |
eebbfb01 | 1216 | args[1] = prompt; |
fb30dfd2 | 1217 | args[2] = CONSP (def) ? XCAR (def) : def; |
eebbfb01 KH |
1218 | prompt = Fformat (3, args); |
1219 | } | |
1220 | ||
ff137f16 EZ |
1221 | return Fcompleting_read (prompt, intern ("internal-complete-buffer"), |
1222 | Qnil, require_match, Qnil, Qbuffer_name_history, | |
406e55df | 1223 | def, Qnil); |
eebbfb01 KH |
1224 | } |
1225 | else | |
f927c5ae | 1226 | { |
eebbfb01 | 1227 | args[0] = Vread_buffer_function; |
f927c5ae JB |
1228 | args[1] = prompt; |
1229 | args[2] = def; | |
eebbfb01 KH |
1230 | args[3] = require_match; |
1231 | return Ffuncall(4, args); | |
f927c5ae | 1232 | } |
f927c5ae JB |
1233 | } |
1234 | \f | |
ec067ec7 RS |
1235 | static Lisp_Object |
1236 | minibuf_conform_representation (string, basis) | |
1237 | Lisp_Object string, basis; | |
1238 | { | |
1239 | if (STRING_MULTIBYTE (string) == STRING_MULTIBYTE (basis)) | |
1240 | return string; | |
1241 | ||
1242 | if (STRING_MULTIBYTE (string)) | |
1243 | return Fstring_make_unibyte (string); | |
1244 | else | |
1245 | return Fstring_make_multibyte (string); | |
1246 | } | |
1247 | ||
f927c5ae | 1248 | DEFUN ("try-completion", Ftry_completion, Stry_completion, 2, 3, 0, |
a284cdbb RS |
1249 | doc: /* Return common substring of all completions of STRING in COLLECTION. |
1250 | Test each possible completion specified by COLLECTION | |
1251 | to see if it begins with STRING. The possible completions may be | |
3809648a KS |
1252 | strings or symbols. Symbols are converted to strings before testing, |
1253 | see `symbol-name'. | |
a284cdbb RS |
1254 | All that match STRING are compared together; the longest initial sequence |
1255 | common to all these matches is the return value. | |
1256 | If there is no match at all, the return value is nil. | |
1257 | For a unique match which is exact, the return value is t. | |
1258 | ||
1259 | If COLLECTION is an alist, the keys (cars of elements) are the | |
1260 | possible completions. If an element is not a cons cell, then the | |
1261 | element itself is the possible completion. | |
1262 | If COLLECTION is a hash-table, all the keys that are strings or symbols | |
1263 | are the possible completions. | |
1264 | If COLLECTION is an obarray, the names of all symbols in the obarray | |
1265 | are the possible completions. | |
1266 | ||
1267 | COLLECTION can also be a function to do the completion itself. | |
a1f17501 PJ |
1268 | It receives three arguments: the values STRING, PREDICATE and nil. |
1269 | Whatever it returns becomes the value of `try-completion'. | |
1270 | ||
1271 | If optional third argument PREDICATE is non-nil, | |
1272 | it is used to test each possible match. | |
1273 | The match is a candidate only if PREDICATE returns non-nil. | |
1274 | The argument given to PREDICATE is the alist element | |
a284cdbb | 1275 | or the symbol from the obarray. If COLLECTION is a hash-table, |
85cd4372 | 1276 | predicate is called with two arguments: the key and the value. |
a1f17501 | 1277 | Additionally to this predicate, `completion-regexp-list' |
af52c32d | 1278 | is used to further constrain the set of candidates. */) |
a284cdbb RS |
1279 | (string, collection, predicate) |
1280 | Lisp_Object string, collection, predicate; | |
f927c5ae JB |
1281 | { |
1282 | Lisp_Object bestmatch, tail, elt, eltstring; | |
af2b7cd5 | 1283 | /* Size in bytes of BESTMATCH. */ |
6bbd7a29 | 1284 | int bestmatchsize = 0; |
af2b7cd5 | 1285 | /* These are in bytes, too. */ |
f927c5ae | 1286 | int compare, matchsize; |
f6d4c7a4 RS |
1287 | enum { function_table, list_table, obarray_table, hash_table} |
1288 | type = (HASH_TABLE_P (collection) ? hash_table | |
1289 | : VECTORP (collection) ? obarray_table | |
1290 | : ((NILP (collection) | |
1291 | || (CONSP (collection) | |
1292 | && (!SYMBOLP (XCAR (collection)) | |
1293 | || NILP (XCAR (collection))))) | |
1294 | ? list_table : function_table)); | |
6bbd7a29 | 1295 | int index = 0, obsize = 0; |
f927c5ae | 1296 | int matchcount = 0; |
acd81db9 | 1297 | int bindcount = -1; |
f927c5ae JB |
1298 | Lisp_Object bucket, zero, end, tem; |
1299 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | |
1300 | ||
b7826503 | 1301 | CHECK_STRING (string); |
f6d4c7a4 | 1302 | if (type == function_table) |
a284cdbb | 1303 | return call3 (collection, string, predicate, Qnil); |
f927c5ae | 1304 | |
6bbd7a29 | 1305 | bestmatch = bucket = Qnil; |
c8ae863b | 1306 | zero = make_number (0); |
f927c5ae | 1307 | |
a284cdbb RS |
1308 | /* If COLLECTION is not a list, set TAIL just for gc pro. */ |
1309 | tail = collection; | |
f6d4c7a4 | 1310 | if (type == obarray_table) |
f927c5ae | 1311 | { |
a284cdbb RS |
1312 | collection = check_obarray (collection); |
1313 | obsize = XVECTOR (collection)->size; | |
1314 | bucket = XVECTOR (collection)->contents[index]; | |
f927c5ae JB |
1315 | } |
1316 | ||
1317 | while (1) | |
1318 | { | |
85cd4372 | 1319 | /* Get the next element of the alist, obarray, or hash-table. */ |
f927c5ae JB |
1320 | /* Exit the loop if the elements are all used up. */ |
1321 | /* elt gets the alist element or symbol. | |
1322 | eltstring gets the name to check as a completion. */ | |
1323 | ||
f6d4c7a4 | 1324 | if (type == list_table) |
f927c5ae | 1325 | { |
695deb18 | 1326 | if (!CONSP (tail)) |
f927c5ae | 1327 | break; |
695deb18 SM |
1328 | elt = XCAR (tail); |
1329 | eltstring = CONSP (elt) ? XCAR (elt) : elt; | |
1330 | tail = XCDR (tail); | |
f927c5ae | 1331 | } |
f6d4c7a4 | 1332 | else if (type == obarray_table) |
f927c5ae | 1333 | { |
c8ae863b | 1334 | if (!EQ (bucket, zero)) |
f927c5ae | 1335 | { |
9b6b374a JB |
1336 | if (!SYMBOLP (bucket)) |
1337 | error ("Bad data in guts of obarray"); | |
f927c5ae | 1338 | elt = bucket; |
3809648a | 1339 | eltstring = elt; |
f927c5ae JB |
1340 | if (XSYMBOL (bucket)->next) |
1341 | XSETSYMBOL (bucket, XSYMBOL (bucket)->next); | |
1342 | else | |
5a866662 | 1343 | XSETFASTINT (bucket, 0); |
f927c5ae JB |
1344 | } |
1345 | else if (++index >= obsize) | |
1346 | break; | |
1347 | else | |
1348 | { | |
a284cdbb | 1349 | bucket = XVECTOR (collection)->contents[index]; |
f927c5ae JB |
1350 | continue; |
1351 | } | |
1352 | } | |
f6d4c7a4 | 1353 | else /* if (type == hash_table) */ |
85cd4372 | 1354 | { |
a284cdbb RS |
1355 | while (index < HASH_TABLE_SIZE (XHASH_TABLE (collection)) |
1356 | && NILP (HASH_HASH (XHASH_TABLE (collection), index))) | |
85cd4372 | 1357 | index++; |
a284cdbb | 1358 | if (index >= HASH_TABLE_SIZE (XHASH_TABLE (collection))) |
85cd4372 SM |
1359 | break; |
1360 | else | |
a284cdbb | 1361 | elt = eltstring = HASH_KEY (XHASH_TABLE (collection), index++); |
85cd4372 | 1362 | } |
f927c5ae JB |
1363 | |
1364 | /* Is this element a possible completion? */ | |
1365 | ||
3809648a KS |
1366 | if (SYMBOLP (eltstring)) |
1367 | eltstring = Fsymbol_name (eltstring); | |
1368 | ||
7510b296 | 1369 | if (STRINGP (eltstring) |
d5db4077 | 1370 | && SCHARS (string) <= SCHARS (eltstring) |
c8ae863b | 1371 | && (tem = Fcompare_strings (eltstring, zero, |
d5db4077 | 1372 | make_number (SCHARS (string)), |
c8ae863b | 1373 | string, zero, Qnil, |
6b61353c | 1374 | completion_ignore_case ? Qt : Qnil), |
69f4ef20 | 1375 | EQ (Qt, tem))) |
f927c5ae JB |
1376 | { |
1377 | /* Yes. */ | |
42006772 | 1378 | Lisp_Object regexps; |
42006772 RS |
1379 | |
1380 | /* Ignore this element if it fails to match all the regexps. */ | |
6b61353c | 1381 | { |
6b61353c KH |
1382 | for (regexps = Vcompletion_regexp_list; CONSP (regexps); |
1383 | regexps = XCDR (regexps)) | |
1384 | { | |
acd81db9 DK |
1385 | if (bindcount < 0) { |
1386 | bindcount = SPECPDL_INDEX (); | |
1387 | specbind (Qcase_fold_search, | |
1388 | completion_ignore_case ? Qt : Qnil); | |
77443789 | 1389 | } |
6b61353c KH |
1390 | tem = Fstring_match (XCAR (regexps), eltstring, zero); |
1391 | if (NILP (tem)) | |
1392 | break; | |
1393 | } | |
6b61353c KH |
1394 | if (CONSP (regexps)) |
1395 | continue; | |
1396 | } | |
42006772 | 1397 | |
f927c5ae JB |
1398 | /* Ignore this element if there is a predicate |
1399 | and the predicate doesn't like it. */ | |
1400 | ||
7efd36fc | 1401 | if (!NILP (predicate)) |
f927c5ae | 1402 | { |
7efd36fc | 1403 | if (EQ (predicate, Qcommandp)) |
c837f4f9 | 1404 | tem = Fcommandp (elt, Qnil); |
f927c5ae JB |
1405 | else |
1406 | { | |
f6d4c7a4 RS |
1407 | if (bindcount >= 0) |
1408 | { | |
1409 | unbind_to (bindcount, Qnil); | |
1410 | bindcount = -1; | |
1411 | } | |
f927c5ae | 1412 | GCPRO4 (tail, string, eltstring, bestmatch); |
f6d4c7a4 RS |
1413 | tem = (type == hash_table |
1414 | ? call2 (predicate, elt, | |
1415 | HASH_VALUE (XHASH_TABLE (collection), | |
1416 | index - 1)) | |
1417 | : call1 (predicate, elt)); | |
f927c5ae JB |
1418 | UNGCPRO; |
1419 | } | |
56a98455 | 1420 | if (NILP (tem)) continue; |
f927c5ae JB |
1421 | } |
1422 | ||
1423 | /* Update computation of how much all possible completions match */ | |
1424 | ||
56a98455 | 1425 | if (NILP (bestmatch)) |
af2b7cd5 | 1426 | { |
85cd4372 | 1427 | matchcount = 1; |
af2b7cd5 | 1428 | bestmatch = eltstring; |
d5db4077 | 1429 | bestmatchsize = SCHARS (eltstring); |
af2b7cd5 | 1430 | } |
f927c5ae JB |
1431 | else |
1432 | { | |
d5db4077 | 1433 | compare = min (bestmatchsize, SCHARS (eltstring)); |
c8ae863b | 1434 | tem = Fcompare_strings (bestmatch, zero, |
69f4ef20 | 1435 | make_number (compare), |
c8ae863b | 1436 | eltstring, zero, |
69f4ef20 RS |
1437 | make_number (compare), |
1438 | completion_ignore_case ? Qt : Qnil); | |
1439 | if (EQ (tem, Qt)) | |
1440 | matchsize = compare; | |
1441 | else if (XINT (tem) < 0) | |
1442 | matchsize = - XINT (tem) - 1; | |
1443 | else | |
1444 | matchsize = XINT (tem) - 1; | |
1445 | ||
52b14ac0 JB |
1446 | if (completion_ignore_case) |
1447 | { | |
1448 | /* If this is an exact match except for case, | |
1449 | use it as the best match rather than one that is not an | |
1450 | exact match. This way, we get the case pattern | |
1451 | of the actual match. */ | |
d5db4077 KR |
1452 | if ((matchsize == SCHARS (eltstring) |
1453 | && matchsize < SCHARS (bestmatch)) | |
52b14ac0 JB |
1454 | || |
1455 | /* If there is more than one exact match ignoring case, | |
1456 | and one of them is exact including case, | |
1457 | prefer that one. */ | |
1458 | /* If there is no exact match ignoring case, | |
1459 | prefer a match that does not change the case | |
1460 | of the input. */ | |
d5db4077 | 1461 | ((matchsize == SCHARS (eltstring)) |
52b14ac0 | 1462 | == |
d5db4077 | 1463 | (matchsize == SCHARS (bestmatch)) |
c8ae863b | 1464 | && (tem = Fcompare_strings (eltstring, zero, |
d5db4077 | 1465 | make_number (SCHARS (string)), |
c8ae863b | 1466 | string, zero, |
69f4ef20 RS |
1467 | Qnil, |
1468 | Qnil), | |
1469 | EQ (Qt, tem)) | |
c8ae863b | 1470 | && (tem = Fcompare_strings (bestmatch, zero, |
d5db4077 | 1471 | make_number (SCHARS (string)), |
c8ae863b | 1472 | string, zero, |
69f4ef20 RS |
1473 | Qnil, |
1474 | Qnil), | |
1475 | ! EQ (Qt, tem)))) | |
52b14ac0 JB |
1476 | bestmatch = eltstring; |
1477 | } | |
d5db4077 | 1478 | if (bestmatchsize != SCHARS (eltstring) |
85cd4372 SM |
1479 | || bestmatchsize != matchsize) |
1480 | /* Don't count the same string multiple times. */ | |
1481 | matchcount++; | |
52b14ac0 | 1482 | bestmatchsize = matchsize; |
d5db4077 | 1483 | if (matchsize <= SCHARS (string) |
78893e05 CY |
1484 | /* If completion-ignore-case is non-nil, don't |
1485 | short-circuit because we want to find the best | |
1486 | possible match *including* case differences. */ | |
1487 | && !completion_ignore_case | |
695deb18 SM |
1488 | && matchcount > 1) |
1489 | /* No need to look any further. */ | |
1490 | break; | |
f927c5ae JB |
1491 | } |
1492 | } | |
1493 | } | |
1494 | ||
acd81db9 DK |
1495 | if (bindcount >= 0) { |
1496 | unbind_to (bindcount, Qnil); | |
1497 | bindcount = -1; | |
1498 | } | |
1499 | ||
56a98455 | 1500 | if (NILP (bestmatch)) |
f927c5ae | 1501 | return Qnil; /* No completions found */ |
52b14ac0 JB |
1502 | /* If we are ignoring case, and there is no exact match, |
1503 | and no additional text was supplied, | |
1504 | don't change the case of what the user typed. */ | |
d5db4077 KR |
1505 | if (completion_ignore_case && bestmatchsize == SCHARS (string) |
1506 | && SCHARS (bestmatch) > bestmatchsize) | |
ec067ec7 | 1507 | return minibuf_conform_representation (string, bestmatch); |
52b14ac0 JB |
1508 | |
1509 | /* Return t if the supplied string is an exact match (counting case); | |
1510 | it does not require any change to be made. */ | |
d5db4077 | 1511 | if (matchcount == 1 && bestmatchsize == SCHARS (string) |
69f4ef20 RS |
1512 | && (tem = Fcompare_strings (bestmatch, make_number (0), |
1513 | make_number (bestmatchsize), | |
1514 | string, make_number (0), | |
1515 | make_number (bestmatchsize), | |
1516 | Qnil), | |
1517 | EQ (Qt, tem))) | |
f927c5ae JB |
1518 | return Qt; |
1519 | ||
5a866662 KH |
1520 | XSETFASTINT (zero, 0); /* Else extract the part in which */ |
1521 | XSETFASTINT (end, bestmatchsize); /* all completions agree */ | |
f927c5ae JB |
1522 | return Fsubstring (bestmatch, zero, end); |
1523 | } | |
f927c5ae | 1524 | \f |
89a255dc | 1525 | DEFUN ("all-completions", Fall_completions, Sall_completions, 2, 4, 0, |
a284cdbb RS |
1526 | doc: /* Search for partial matches to STRING in COLLECTION. |
1527 | Test each of the possible completions specified by COLLECTION | |
1528 | to see if it begins with STRING. The possible completions may be | |
3809648a KS |
1529 | strings or symbols. Symbols are converted to strings before testing, |
1530 | see `symbol-name'. | |
a284cdbb | 1531 | The value is a list of all the possible completions that match STRING. |
a1f17501 | 1532 | |
a284cdbb RS |
1533 | If COLLECTION is an alist, the keys (cars of elements) are the |
1534 | possible completions. If an element is not a cons cell, then the | |
1535 | element itself is the possible completion. | |
1536 | If COLLECTION is a hash-table, all the keys that are strings or symbols | |
1537 | are the possible completions. | |
1538 | If COLLECTION is an obarray, the names of all symbols in the obarray | |
1539 | are the possible completions. | |
a1f17501 | 1540 | |
a284cdbb | 1541 | COLLECTION can also be a function to do the completion itself. |
a1f17501 PJ |
1542 | It receives three arguments: the values STRING, PREDICATE and t. |
1543 | Whatever it returns becomes the value of `all-completions'. | |
1544 | ||
1545 | If optional third argument PREDICATE is non-nil, | |
1546 | it is used to test each possible match. | |
1547 | The match is a candidate only if PREDICATE returns non-nil. | |
1548 | The argument given to PREDICATE is the alist element | |
a284cdbb | 1549 | or the symbol from the obarray. If COLLECTION is a hash-table, |
85cd4372 | 1550 | predicate is called with two arguments: the key and the value. |
a1f17501 PJ |
1551 | Additionally to this predicate, `completion-regexp-list' |
1552 | is used to further constrain the set of candidates. | |
1553 | ||
1554 | If the optional fourth argument HIDE-SPACES is non-nil, | |
a284cdbb | 1555 | strings in COLLECTION that start with a space |
af52c32d | 1556 | are ignored unless STRING itself starts with a space. */) |
a284cdbb RS |
1557 | (string, collection, predicate, hide_spaces) |
1558 | Lisp_Object string, collection, predicate, hide_spaces; | |
f927c5ae JB |
1559 | { |
1560 | Lisp_Object tail, elt, eltstring; | |
1561 | Lisp_Object allmatches; | |
a284cdbb RS |
1562 | int type = HASH_TABLE_P (collection) ? 3 |
1563 | : VECTORP (collection) ? 2 | |
1564 | : NILP (collection) || (CONSP (collection) | |
1565 | && (!SYMBOLP (XCAR (collection)) | |
1566 | || NILP (XCAR (collection)))); | |
6bbd7a29 | 1567 | int index = 0, obsize = 0; |
acd81db9 | 1568 | int bindcount = -1; |
c8ae863b | 1569 | Lisp_Object bucket, tem, zero; |
f927c5ae JB |
1570 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
1571 | ||
b7826503 | 1572 | CHECK_STRING (string); |
85cd4372 | 1573 | if (type == 0) |
a284cdbb | 1574 | return call3 (collection, string, predicate, Qt); |
6bbd7a29 | 1575 | allmatches = bucket = Qnil; |
c8ae863b | 1576 | zero = make_number (0); |
f927c5ae | 1577 | |
a284cdbb RS |
1578 | /* If COLLECTION is not a list, set TAIL just for gc pro. */ |
1579 | tail = collection; | |
85cd4372 | 1580 | if (type == 2) |
f927c5ae | 1581 | { |
a284cdbb RS |
1582 | obsize = XVECTOR (collection)->size; |
1583 | bucket = XVECTOR (collection)->contents[index]; | |
f927c5ae JB |
1584 | } |
1585 | ||
1586 | while (1) | |
1587 | { | |
85cd4372 | 1588 | /* Get the next element of the alist, obarray, or hash-table. */ |
f927c5ae JB |
1589 | /* Exit the loop if the elements are all used up. */ |
1590 | /* elt gets the alist element or symbol. | |
1591 | eltstring gets the name to check as a completion. */ | |
1592 | ||
85cd4372 | 1593 | if (type == 1) |
f927c5ae | 1594 | { |
695deb18 | 1595 | if (!CONSP (tail)) |
f927c5ae | 1596 | break; |
695deb18 SM |
1597 | elt = XCAR (tail); |
1598 | eltstring = CONSP (elt) ? XCAR (elt) : elt; | |
1599 | tail = XCDR (tail); | |
f927c5ae | 1600 | } |
85cd4372 | 1601 | else if (type == 2) |
f927c5ae | 1602 | { |
c8ae863b | 1603 | if (!EQ (bucket, zero)) |
f927c5ae JB |
1604 | { |
1605 | elt = bucket; | |
3809648a | 1606 | eltstring = elt; |
f927c5ae JB |
1607 | if (XSYMBOL (bucket)->next) |
1608 | XSETSYMBOL (bucket, XSYMBOL (bucket)->next); | |
1609 | else | |
5a866662 | 1610 | XSETFASTINT (bucket, 0); |
f927c5ae JB |
1611 | } |
1612 | else if (++index >= obsize) | |
1613 | break; | |
1614 | else | |
1615 | { | |
a284cdbb | 1616 | bucket = XVECTOR (collection)->contents[index]; |
f927c5ae JB |
1617 | continue; |
1618 | } | |
1619 | } | |
85cd4372 SM |
1620 | else /* if (type == 3) */ |
1621 | { | |
a284cdbb RS |
1622 | while (index < HASH_TABLE_SIZE (XHASH_TABLE (collection)) |
1623 | && NILP (HASH_HASH (XHASH_TABLE (collection), index))) | |
85cd4372 | 1624 | index++; |
a284cdbb | 1625 | if (index >= HASH_TABLE_SIZE (XHASH_TABLE (collection))) |
85cd4372 SM |
1626 | break; |
1627 | else | |
a284cdbb | 1628 | elt = eltstring = HASH_KEY (XHASH_TABLE (collection), index++); |
85cd4372 | 1629 | } |
f927c5ae JB |
1630 | |
1631 | /* Is this element a possible completion? */ | |
1632 | ||
3809648a KS |
1633 | if (SYMBOLP (eltstring)) |
1634 | eltstring = Fsymbol_name (eltstring); | |
1635 | ||
7510b296 | 1636 | if (STRINGP (eltstring) |
d5db4077 | 1637 | && SCHARS (string) <= SCHARS (eltstring) |
89a255dc | 1638 | /* If HIDE_SPACES, reject alternatives that start with space |
2cbaf886 | 1639 | unless the input starts with space. */ |
d5db4077 KR |
1640 | && ((SBYTES (string) > 0 |
1641 | && SREF (string, 0) == ' ') | |
1642 | || SREF (eltstring, 0) != ' ' | |
89a255dc | 1643 | || NILP (hide_spaces)) |
c8ae863b | 1644 | && (tem = Fcompare_strings (eltstring, zero, |
d5db4077 | 1645 | make_number (SCHARS (string)), |
c8ae863b | 1646 | string, zero, |
d5db4077 | 1647 | make_number (SCHARS (string)), |
69f4ef20 RS |
1648 | completion_ignore_case ? Qt : Qnil), |
1649 | EQ (Qt, tem))) | |
f927c5ae JB |
1650 | { |
1651 | /* Yes. */ | |
42006772 RS |
1652 | Lisp_Object regexps; |
1653 | Lisp_Object zero; | |
5a866662 | 1654 | XSETFASTINT (zero, 0); |
42006772 RS |
1655 | |
1656 | /* Ignore this element if it fails to match all the regexps. */ | |
6b61353c | 1657 | { |
6b61353c KH |
1658 | for (regexps = Vcompletion_regexp_list; CONSP (regexps); |
1659 | regexps = XCDR (regexps)) | |
1660 | { | |
acd81db9 DK |
1661 | if (bindcount < 0) { |
1662 | bindcount = SPECPDL_INDEX (); | |
1663 | specbind (Qcase_fold_search, | |
1664 | completion_ignore_case ? Qt : Qnil); | |
77443789 | 1665 | } |
6b61353c KH |
1666 | tem = Fstring_match (XCAR (regexps), eltstring, zero); |
1667 | if (NILP (tem)) | |
1668 | break; | |
1669 | } | |
6b61353c KH |
1670 | if (CONSP (regexps)) |
1671 | continue; | |
1672 | } | |
42006772 | 1673 | |
f927c5ae JB |
1674 | /* Ignore this element if there is a predicate |
1675 | and the predicate doesn't like it. */ | |
1676 | ||
7efd36fc | 1677 | if (!NILP (predicate)) |
f927c5ae | 1678 | { |
7efd36fc | 1679 | if (EQ (predicate, Qcommandp)) |
c837f4f9 | 1680 | tem = Fcommandp (elt, Qnil); |
f927c5ae JB |
1681 | else |
1682 | { | |
acd81db9 DK |
1683 | if (bindcount >= 0) { |
1684 | unbind_to (bindcount, Qnil); | |
1685 | bindcount = -1; | |
1686 | } | |
f927c5ae | 1687 | GCPRO4 (tail, eltstring, allmatches, string); |
85cd4372 SM |
1688 | tem = type == 3 |
1689 | ? call2 (predicate, elt, | |
a284cdbb | 1690 | HASH_VALUE (XHASH_TABLE (collection), index - 1)) |
85cd4372 | 1691 | : call1 (predicate, elt); |
f927c5ae JB |
1692 | UNGCPRO; |
1693 | } | |
56a98455 | 1694 | if (NILP (tem)) continue; |
f927c5ae JB |
1695 | } |
1696 | /* Ok => put it on the list. */ | |
1697 | allmatches = Fcons (eltstring, allmatches); | |
1698 | } | |
1699 | } | |
1700 | ||
acd81db9 DK |
1701 | if (bindcount >= 0) { |
1702 | unbind_to (bindcount, Qnil); | |
1703 | bindcount = -1; | |
1704 | } | |
1705 | ||
f927c5ae JB |
1706 | return Fnreverse (allmatches); |
1707 | } | |
1708 | \f | |
cee54539 | 1709 | DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 8, 0, |
af52c32d | 1710 | doc: /* Read a string in the minibuffer, with completion. |
a1f17501 | 1711 | PROMPT is a string to prompt with; normally it ends in a colon and a space. |
a284cdbb RS |
1712 | COLLECTION can be a list of strings, an alist, an obarray or a hash table. |
1713 | COLLECTION can also be a function to do the completion itself. | |
1714 | PREDICATE limits completion to a subset of COLLECTION. | |
a1f17501 | 1715 | See `try-completion' and `all-completions' for more details |
a284cdbb | 1716 | on completion, COLLECTION, and PREDICATE. |
a1f17501 | 1717 | |
4d02fc25 SM |
1718 | REQUIRE-MATCH can take the following values: |
1719 | - t means that the user is not allowed to exit unless | |
1720 | the input is (or completes to) an element of COLLECTION or is null. | |
1721 | - nil means that the user can exit with any input. | |
1722 | - `confirm-only' means that the user can exit with any input, but she will | |
1723 | need to confirm her choice if the input is not an element of COLLECTION. | |
1724 | - anything else behaves like t except that typing RET does not exit if it | |
1725 | does non-null completion. | |
1726 | ||
2e3148e2 JL |
1727 | If the input is null, `completing-read' returns DEF, or the first element |
1728 | of the list of default values, or an empty string if DEF is nil, | |
1729 | regardless of the value of REQUIRE-MATCH. | |
6b61353c KH |
1730 | |
1731 | If INITIAL-INPUT is non-nil, insert it in the minibuffer initially, | |
1732 | with point positioned at the end. | |
1733 | If it is (STRING . POSITION), the initial input is STRING, but point | |
1734 | is placed at _zero-indexed_ position POSITION in STRING. (*Note* | |
1735 | that this is different from `read-from-minibuffer' and related | |
1736 | functions, which use one-indexing for POSITION.) This feature is | |
1737 | deprecated--it is best to pass nil for INITIAL-INPUT and supply the | |
1738 | default value DEF instead. The user can yank the default value into | |
1739 | the minibuffer easily using \\[next-history-element]. | |
1740 | ||
1741 | HIST, if non-nil, specifies a history list and optionally the initial | |
1742 | position in the list. It can be a symbol, which is the history list | |
1743 | variable to use, or it can be a cons cell (HISTVAR . HISTPOS). In | |
1744 | that case, HISTVAR is the history list variable to use, and HISTPOS | |
1745 | is the initial position (the position in the list used by the | |
1746 | minibuffer history commands). For consistency, you should also | |
1747 | specify that element of the history as the value of | |
1fb101f3 | 1748 | INITIAL-INPUT. (This is the only case in which you should use |
6b61353c KH |
1749 | INITIAL-INPUT instead of DEF.) Positions are counted starting from |
1750 | 1 at the beginning of the list. The variable `history-length' | |
1751 | controls the maximum length of a history list. | |
38668f81 | 1752 | |
2e3148e2 | 1753 | DEF, if non-nil, is the default value or the list of default values. |
a1f17501 PJ |
1754 | |
1755 | If INHERIT-INPUT-METHOD is non-nil, the minibuffer inherits | |
029a305c | 1756 | the current input method and the setting of `enable-multibyte-characters'. |
a1f17501 PJ |
1757 | |
1758 | Completion ignores case if the ambient value of | |
af52c32d | 1759 | `completion-ignore-case' is non-nil. */) |
a284cdbb RS |
1760 | (prompt, collection, predicate, require_match, initial_input, hist, def, inherit_input_method) |
1761 | Lisp_Object prompt, collection, predicate, require_match, initial_input; | |
d43f85c2 | 1762 | Lisp_Object hist, def, inherit_input_method; |
f927c5ae | 1763 | { |
770970cb | 1764 | Lisp_Object val, histvar, histpos, position; |
d43f85c2 | 1765 | Lisp_Object init; |
770970cb | 1766 | int pos = 0; |
aed13378 | 1767 | int count = SPECPDL_INDEX (); |
0c8ee1a2 RS |
1768 | struct gcpro gcpro1; |
1769 | ||
d43f85c2 | 1770 | init = initial_input; |
0c8ee1a2 RS |
1771 | GCPRO1 (def); |
1772 | ||
a284cdbb | 1773 | specbind (Qminibuffer_completion_table, collection); |
7efd36fc | 1774 | specbind (Qminibuffer_completion_predicate, predicate); |
f927c5ae | 1775 | specbind (Qminibuffer_completion_confirm, |
695deb18 | 1776 | EQ (require_match, Qt) ? Qnil : require_match); |
770970cb RS |
1777 | |
1778 | position = Qnil; | |
1779 | if (!NILP (init)) | |
1780 | { | |
7510b296 | 1781 | if (CONSP (init)) |
770970cb RS |
1782 | { |
1783 | position = Fcdr (init); | |
1784 | init = Fcar (init); | |
1785 | } | |
b7826503 | 1786 | CHECK_STRING (init); |
770970cb RS |
1787 | if (!NILP (position)) |
1788 | { | |
b7826503 | 1789 | CHECK_NUMBER (position); |
770970cb | 1790 | /* Convert to distance from end of input. */ |
d5db4077 | 1791 | pos = XINT (position) - SCHARS (init); |
770970cb RS |
1792 | } |
1793 | } | |
1794 | ||
7510b296 | 1795 | if (SYMBOLP (hist)) |
770970cb RS |
1796 | { |
1797 | histvar = hist; | |
1798 | histpos = Qnil; | |
1799 | } | |
1800 | else | |
1801 | { | |
1802 | histvar = Fcar_safe (hist); | |
1803 | histpos = Fcdr_safe (hist); | |
1804 | } | |
1805 | if (NILP (histvar)) | |
1806 | histvar = Qminibuffer_history; | |
1807 | if (NILP (histpos)) | |
5a866662 | 1808 | XSETFASTINT (histpos, 0); |
770970cb | 1809 | |
56a98455 | 1810 | val = read_minibuf (NILP (require_match) |
bb0bdf70 | 1811 | ? (NILP (Vminibuffer_completing_file_name) |
ef72eaff | 1812 | || EQ (Vminibuffer_completing_file_name, Qlambda) |
bb0bdf70 EZ |
1813 | ? Vminibuffer_local_completion_map |
1814 | : Vminibuffer_local_filename_completion_map) | |
1815 | : (NILP (Vminibuffer_completing_file_name) | |
ef72eaff | 1816 | || EQ (Vminibuffer_completing_file_name, Qlambda) |
bb0bdf70 | 1817 | ? Vminibuffer_local_must_match_map |
8ba31f36 | 1818 | : Vminibuffer_local_filename_must_match_map), |
85b5fe07 | 1819 | init, prompt, make_number (pos), 0, |
cee54539 | 1820 | histvar, histpos, def, 0, |
b35cd215 | 1821 | !NILP (inherit_input_method)); |
b9a86585 | 1822 | |
d5db4077 | 1823 | if (STRINGP (val) && SCHARS (val) == 0 && ! NILP (def)) |
fb30dfd2 | 1824 | val = CONSP (def) ? XCAR (def) : def; |
b9a86585 | 1825 | |
0c8ee1a2 | 1826 | RETURN_UNGCPRO (unbind_to (count, val)); |
f927c5ae JB |
1827 | } |
1828 | \f | |
695deb18 | 1829 | Lisp_Object Fassoc_string (); |
5d2ca7ae RS |
1830 | |
1831 | /* Test whether TXT is an exact completion. */ | |
695deb18 SM |
1832 | DEFUN ("test-completion", Ftest_completion, Stest_completion, 2, 3, 0, |
1833 | doc: /* Return non-nil if STRING is a valid completion. | |
1834 | Takes the same arguments as `all-completions' and `try-completion'. | |
a284cdbb | 1835 | If COLLECTION is a function, it is called with three arguments: |
695deb18 | 1836 | the values STRING, PREDICATE and `lambda'. */) |
a284cdbb RS |
1837 | (string, collection, predicate) |
1838 | Lisp_Object string, collection, predicate; | |
5d2ca7ae | 1839 | { |
6b61353c | 1840 | Lisp_Object regexps, tail, tem = Qnil; |
85cd4372 | 1841 | int i = 0; |
5d2ca7ae | 1842 | |
695deb18 SM |
1843 | CHECK_STRING (string); |
1844 | ||
a284cdbb RS |
1845 | if ((CONSP (collection) |
1846 | && (!SYMBOLP (XCAR (collection)) || NILP (XCAR (collection)))) | |
1847 | || NILP (collection)) | |
695deb18 | 1848 | { |
a284cdbb | 1849 | tem = Fassoc_string (string, collection, completion_ignore_case ? Qt : Qnil); |
9f4a578d | 1850 | if (NILP (tem)) |
695deb18 SM |
1851 | return Qnil; |
1852 | } | |
a284cdbb | 1853 | else if (VECTORP (collection)) |
5d2ca7ae | 1854 | { |
695deb18 | 1855 | /* Bypass intern-soft as that loses for nil. */ |
a284cdbb | 1856 | tem = oblookup (collection, |
d5db4077 KR |
1857 | SDATA (string), |
1858 | SCHARS (string), | |
1859 | SBYTES (string)); | |
44472c88 | 1860 | if (!SYMBOLP (tem)) |
9404446f | 1861 | { |
695deb18 SM |
1862 | if (STRING_MULTIBYTE (string)) |
1863 | string = Fstring_make_unibyte (string); | |
9404446f | 1864 | else |
695deb18 | 1865 | string = Fstring_make_multibyte (string); |
9404446f | 1866 | |
a284cdbb | 1867 | tem = oblookup (collection, |
d5db4077 KR |
1868 | SDATA (string), |
1869 | SCHARS (string), | |
1870 | SBYTES (string)); | |
9404446f | 1871 | } |
6b61353c KH |
1872 | |
1873 | if (completion_ignore_case && !SYMBOLP (tem)) | |
1874 | { | |
a284cdbb | 1875 | for (i = XVECTOR (collection)->size - 1; i >= 0; i--) |
6b61353c | 1876 | { |
a284cdbb | 1877 | tail = XVECTOR (collection)->contents[i]; |
6b61353c KH |
1878 | if (SYMBOLP (tail)) |
1879 | while (1) | |
1880 | { | |
1881 | if (EQ((Fcompare_strings (string, make_number (0), Qnil, | |
1882 | Fsymbol_name (tail), | |
1883 | make_number (0) , Qnil, Qt)), | |
1884 | Qt)) | |
1885 | { | |
1886 | tem = tail; | |
1887 | break; | |
1888 | } | |
1889 | if (XSYMBOL (tail)->next == 0) | |
1890 | break; | |
1891 | XSETSYMBOL (tail, XSYMBOL (tail)->next); | |
1892 | } | |
1893 | } | |
1894 | } | |
1895 | ||
1896 | if (!SYMBOLP (tem)) | |
1897 | return Qnil; | |
5d2ca7ae | 1898 | } |
a284cdbb | 1899 | else if (HASH_TABLE_P (collection)) |
85cd4372 | 1900 | { |
a284cdbb | 1901 | struct Lisp_Hash_Table *h = XHASH_TABLE (collection); |
6b61353c | 1902 | i = hash_lookup (h, string, NULL); |
85cd4372 | 1903 | if (i >= 0) |
6b61353c | 1904 | tem = HASH_KEY (h, i); |
85cd4372 | 1905 | else |
6b61353c KH |
1906 | for (i = 0; i < HASH_TABLE_SIZE (h); ++i) |
1907 | if (!NILP (HASH_HASH (h, i)) && | |
1908 | EQ (Fcompare_strings (string, make_number (0), Qnil, | |
1909 | HASH_KEY (h, i), make_number (0) , Qnil, | |
1910 | completion_ignore_case ? Qt : Qnil), | |
1911 | Qt)) | |
1912 | { | |
1913 | tem = HASH_KEY (h, i); | |
1914 | break; | |
1915 | } | |
1916 | if (!STRINGP (tem)) | |
85cd4372 SM |
1917 | return Qnil; |
1918 | } | |
5d2ca7ae | 1919 | else |
a284cdbb | 1920 | return call3 (collection, string, predicate, Qlambda); |
695deb18 SM |
1921 | |
1922 | /* Reject this element if it fails to match all the regexps. */ | |
77443789 AS |
1923 | if (CONSP (Vcompletion_regexp_list)) |
1924 | { | |
1925 | int count = SPECPDL_INDEX (); | |
1926 | specbind (Qcase_fold_search, completion_ignore_case ? Qt : Qnil); | |
1927 | for (regexps = Vcompletion_regexp_list; CONSP (regexps); | |
1928 | regexps = XCDR (regexps)) | |
1929 | { | |
1930 | if (NILP (Fstring_match (XCAR (regexps), | |
1931 | SYMBOLP (tem) ? string : tem, | |
1932 | Qnil))) | |
1933 | return unbind_to (count, Qnil); | |
1934 | } | |
1935 | unbind_to (count, Qnil); | |
1936 | } | |
695deb18 SM |
1937 | |
1938 | /* Finally, check the predicate. */ | |
1939 | if (!NILP (predicate)) | |
6b61353c | 1940 | { |
a284cdbb RS |
1941 | return HASH_TABLE_P (collection) |
1942 | ? call2 (predicate, tem, HASH_VALUE (XHASH_TABLE (collection), i)) | |
6b61353c KH |
1943 | : call1 (predicate, tem); |
1944 | } | |
695deb18 SM |
1945 | else |
1946 | return Qt; | |
5d2ca7ae | 1947 | } |
f927c5ae | 1948 | |
655ea21c JD |
1949 | DEFUN ("internal-complete-buffer", Finternal_complete_buffer, Sinternal_complete_buffer, 3, 3, 0, |
1950 | doc: /* Perform completion on buffer names. | |
1951 | If the argument FLAG is nil, invoke `try-completion', if it's t, invoke | |
1952 | `all-completions', otherwise invoke `test-completion'. | |
1953 | ||
ba5524f4 | 1954 | The arguments STRING and PREDICATE are as in `try-completion', |
655ea21c JD |
1955 | `all-completions', and `test-completion'. */) |
1956 | (string, predicate, flag) | |
1957 | Lisp_Object string, predicate, flag; | |
1958 | { | |
1959 | if (NILP (flag)) | |
1960 | return Ftry_completion (string, Vbuffer_alist, predicate); | |
1961 | else if (EQ (flag, Qt)) | |
8c2dccbf | 1962 | { |
73913e2e | 1963 | Lisp_Object res = Fall_completions (string, Vbuffer_alist, predicate, Qnil); |
8c2dccbf SM |
1964 | if (SCHARS (string) > 0) |
1965 | return res; | |
1966 | else | |
1967 | { /* Strip out internal buffers. */ | |
1968 | Lisp_Object bufs = res; | |
1969 | /* First, look for a non-internal buffer in `res'. */ | |
1970 | while (CONSP (bufs) && SREF (XCAR (bufs), 0) == ' ') | |
1971 | bufs = XCDR (bufs); | |
1972 | if (NILP (bufs)) | |
1973 | /* All bufs in `res' are internal, so don't trip them out. */ | |
1974 | return res; | |
1975 | res = bufs; | |
1976 | while (CONSP (XCDR (bufs))) | |
1977 | if (SREF (XCAR (XCDR (bufs)), 0) == ' ') | |
1978 | XSETCDR (bufs, XCDR (XCDR (bufs))); | |
1979 | else | |
1980 | bufs = XCDR (bufs); | |
1981 | return res; | |
1982 | } | |
1983 | } | |
655ea21c JD |
1984 | else /* assume `lambda' */ |
1985 | return Ftest_completion (string, Vbuffer_alist, predicate); | |
1986 | } | |
1987 | ||
52b14ac0 JB |
1988 | /* Like assoc but assumes KEY is a string, and ignores case if appropriate. */ |
1989 | ||
695deb18 | 1990 | DEFUN ("assoc-string", Fassoc_string, Sassoc_string, 2, 3, 0, |
d3fc66fb | 1991 | doc: /* Like `assoc' but specifically for strings (and symbols). |
c6a82c18 CY |
1992 | |
1993 | This returns the first element of LIST whose car matches the string or | |
1994 | symbol KEY, or nil if no match exists. When performing the | |
1995 | comparison, symbols are first converted to strings, and unibyte | |
1996 | strings to multibyte. If the optional arg CASE-FOLD is non-nil, case | |
1997 | is ignored. | |
1998 | ||
1999 | Unlike `assoc', KEY can also match an entry in LIST consisting of a | |
2000 | single string, rather than a cons cell whose car is a string. */) | |
695deb18 | 2001 | (key, list, case_fold) |
52b14ac0 | 2002 | register Lisp_Object key; |
695deb18 | 2003 | Lisp_Object list, case_fold; |
52b14ac0 JB |
2004 | { |
2005 | register Lisp_Object tail; | |
2006 | ||
d3fc66fb KS |
2007 | if (SYMBOLP (key)) |
2008 | key = Fsymbol_name (key); | |
2009 | ||
99784d63 | 2010 | for (tail = list; CONSP (tail); tail = XCDR (tail)) |
52b14ac0 JB |
2011 | { |
2012 | register Lisp_Object elt, tem, thiscar; | |
99784d63 | 2013 | elt = XCAR (tail); |
695deb18 | 2014 | thiscar = CONSP (elt) ? XCAR (elt) : elt; |
1954495f KS |
2015 | if (SYMBOLP (thiscar)) |
2016 | thiscar = Fsymbol_name (thiscar); | |
2017 | else if (!STRINGP (thiscar)) | |
52b14ac0 | 2018 | continue; |
9404446f RS |
2019 | tem = Fcompare_strings (thiscar, make_number (0), Qnil, |
2020 | key, make_number (0), Qnil, | |
695deb18 | 2021 | case_fold); |
9404446f RS |
2022 | if (EQ (tem, Qt)) |
2023 | return elt; | |
52b14ac0 JB |
2024 | QUIT; |
2025 | } | |
2026 | return Qnil; | |
2027 | } | |
f927c5ae | 2028 | |
e4c97a67 | 2029 | \f |
f927c5ae | 2030 | DEFUN ("minibuffer-depth", Fminibuffer_depth, Sminibuffer_depth, 0, 0, 0, |
af52c32d MB |
2031 | doc: /* Return current depth of activations of minibuffer, a nonnegative integer. */) |
2032 | () | |
f927c5ae JB |
2033 | { |
2034 | return make_number (minibuf_level); | |
2035 | } | |
2036 | ||
37e9a934 | 2037 | DEFUN ("minibuffer-prompt", Fminibuffer_prompt, Sminibuffer_prompt, 0, 0, 0, |
af52c32d MB |
2038 | doc: /* Return the prompt string of the currently-active minibuffer. |
2039 | If no minibuffer is active, return nil. */) | |
2040 | () | |
37e9a934 | 2041 | { |
4d04c1f1 | 2042 | return Fcopy_sequence (minibuf_prompt); |
37e9a934 KH |
2043 | } |
2044 | ||
f927c5ae | 2045 | \f |
9d815fd9 | 2046 | void |
f927c5ae JB |
2047 | init_minibuf_once () |
2048 | { | |
2049 | Vminibuffer_list = Qnil; | |
2050 | staticpro (&Vminibuffer_list); | |
2051 | } | |
2052 | ||
9d815fd9 | 2053 | void |
f927c5ae JB |
2054 | syms_of_minibuf () |
2055 | { | |
2056 | minibuf_level = 0; | |
4d04c1f1 KH |
2057 | minibuf_prompt = Qnil; |
2058 | staticpro (&minibuf_prompt); | |
2059 | ||
2060 | minibuf_save_list = Qnil; | |
2061 | staticpro (&minibuf_save_list); | |
f927c5ae | 2062 | |
9fa5c213 GM |
2063 | Qcompletion_ignore_case = intern ("completion-ignore-case"); |
2064 | staticpro (&Qcompletion_ignore_case); | |
2065 | ||
719b4a40 RS |
2066 | Qread_file_name_internal = intern ("read-file-name-internal"); |
2067 | staticpro (&Qread_file_name_internal); | |
2068 | ||
e5d4686b RS |
2069 | Qminibuffer_default = intern ("minibuffer-default"); |
2070 | staticpro (&Qminibuffer_default); | |
2071 | Fset (Qminibuffer_default, Qnil); | |
2072 | ||
f927c5ae JB |
2073 | Qminibuffer_completion_table = intern ("minibuffer-completion-table"); |
2074 | staticpro (&Qminibuffer_completion_table); | |
2075 | ||
2076 | Qminibuffer_completion_confirm = intern ("minibuffer-completion-confirm"); | |
2077 | staticpro (&Qminibuffer_completion_confirm); | |
2078 | ||
2079 | Qminibuffer_completion_predicate = intern ("minibuffer-completion-predicate"); | |
2080 | staticpro (&Qminibuffer_completion_predicate); | |
2081 | ||
2082 | staticpro (&last_minibuf_string); | |
2083 | last_minibuf_string = Qnil; | |
2084 | ||
2085 | Quser_variable_p = intern ("user-variable-p"); | |
2086 | staticpro (&Quser_variable_p); | |
2087 | ||
770970cb RS |
2088 | Qminibuffer_history = intern ("minibuffer-history"); |
2089 | staticpro (&Qminibuffer_history); | |
f927c5ae | 2090 | |
406e55df RS |
2091 | Qbuffer_name_history = intern ("buffer-name-history"); |
2092 | staticpro (&Qbuffer_name_history); | |
33d0a17f | 2093 | Fset (Qbuffer_name_history, Qnil); |
406e55df | 2094 | |
5c781212 RS |
2095 | Qminibuffer_setup_hook = intern ("minibuffer-setup-hook"); |
2096 | staticpro (&Qminibuffer_setup_hook); | |
2097 | ||
177aecf9 KH |
2098 | Qminibuffer_exit_hook = intern ("minibuffer-exit-hook"); |
2099 | staticpro (&Qminibuffer_exit_hook); | |
2100 | ||
77aa8edf RS |
2101 | Qhistory_length = intern ("history-length"); |
2102 | staticpro (&Qhistory_length); | |
2103 | ||
cee54539 KH |
2104 | Qcurrent_input_method = intern ("current-input-method"); |
2105 | staticpro (&Qcurrent_input_method); | |
2106 | ||
2107 | Qactivate_input_method = intern ("activate-input-method"); | |
2108 | staticpro (&Qactivate_input_method); | |
2109 | ||
6b61353c KH |
2110 | Qcase_fold_search = intern ("case-fold-search"); |
2111 | staticpro (&Qcase_fold_search); | |
2112 | ||
627fb581 RS |
2113 | Qread_expression_history = intern ("read-expression-history"); |
2114 | staticpro (&Qread_expression_history); | |
2115 | ||
af52c32d MB |
2116 | DEFVAR_LISP ("read-buffer-function", &Vread_buffer_function, |
2117 | doc: /* If this is non-nil, `read-buffer' does its work by calling this function. */); | |
eebbfb01 KH |
2118 | Vread_buffer_function = Qnil; |
2119 | ||
af52c32d MB |
2120 | DEFVAR_LISP ("minibuffer-setup-hook", &Vminibuffer_setup_hook, |
2121 | doc: /* Normal hook run just after entry to minibuffer. */); | |
5c781212 RS |
2122 | Vminibuffer_setup_hook = Qnil; |
2123 | ||
af52c32d MB |
2124 | DEFVAR_LISP ("minibuffer-exit-hook", &Vminibuffer_exit_hook, |
2125 | doc: /* Normal hook run just after exit from minibuffer. */); | |
177aecf9 KH |
2126 | Vminibuffer_exit_hook = Qnil; |
2127 | ||
af52c32d MB |
2128 | DEFVAR_LISP ("history-length", &Vhistory_length, |
2129 | doc: /* *Maximum length for history lists before truncation takes place. | |
a1f17501 | 2130 | A number means that length; t means infinite. Truncation takes place |
f4b46bb9 | 2131 | just after a new element is inserted. Setting the `history-length' |
a1f17501 | 2132 | property of a history variable overrides this default. */); |
77aa8edf RS |
2133 | XSETFASTINT (Vhistory_length, 30); |
2134 | ||
0da4d471 JL |
2135 | DEFVAR_BOOL ("history-delete-duplicates", &history_delete_duplicates, |
2136 | doc: /* *Non-nil means to delete duplicates in history. | |
2137 | If set to t when adding a new history element, all previous identical | |
179a4ca7 | 2138 | elements are deleted from the history list. */); |
0da4d471 JL |
2139 | history_delete_duplicates = 0; |
2140 | ||
179a4ca7 JL |
2141 | DEFVAR_LISP ("history-add-new-input", &Vhistory_add_new_input, |
2142 | doc: /* *Non-nil means to add new elements in history. | |
2143 | If set to nil, minibuffer reading functions don't add new elements to the | |
2144 | history list, so it is possible to do this afterwards by calling | |
2145 | `add-to-history' explicitly. */); | |
2146 | Vhistory_add_new_input = Qt; | |
2147 | ||
af52c32d | 2148 | DEFVAR_BOOL ("completion-ignore-case", &completion_ignore_case, |
75028673 JPW |
2149 | doc: /* Non-nil means don't consider case significant in completion. |
2150 | ||
d9a03ad2 RS |
2151 | For file-name completion, the variable `read-file-name-completion-ignore-case' |
2152 | controls the behavior, rather than this variable. */); | |
f927c5ae JB |
2153 | completion_ignore_case = 0; |
2154 | ||
af52c32d MB |
2155 | DEFVAR_BOOL ("enable-recursive-minibuffers", &enable_recursive_minibuffers, |
2156 | doc: /* *Non-nil means to allow minibuffer commands while in the minibuffer. | |
a1f17501 | 2157 | This variable makes a difference whenever the minibuffer window is active. */); |
f927c5ae JB |
2158 | enable_recursive_minibuffers = 0; |
2159 | ||
af52c32d MB |
2160 | DEFVAR_LISP ("minibuffer-completion-table", &Vminibuffer_completion_table, |
2161 | doc: /* Alist or obarray used for completion in the minibuffer. | |
6b61353c KH |
2162 | This becomes the ALIST argument to `try-completion' and `all-completions'. |
2163 | The value can also be a list of strings or a hash table. | |
a1f17501 PJ |
2164 | |
2165 | The value may alternatively be a function, which is given three arguments: | |
2166 | STRING, the current buffer contents; | |
2167 | PREDICATE, the predicate for filtering possible matches; | |
2168 | CODE, which says what kind of things to do. | |
b2ef9714 JB |
2169 | CODE can be nil, t or `lambda': |
2170 | nil -- return the best completion of STRING, or nil if there is none. | |
2171 | t -- return a list of all possible completions of STRING. | |
2172 | lambda -- return t if STRING is a valid completion as it stands. */); | |
f927c5ae JB |
2173 | Vminibuffer_completion_table = Qnil; |
2174 | ||
af52c32d MB |
2175 | DEFVAR_LISP ("minibuffer-completion-predicate", &Vminibuffer_completion_predicate, |
2176 | doc: /* Within call to `completing-read', this holds the PREDICATE argument. */); | |
f927c5ae JB |
2177 | Vminibuffer_completion_predicate = Qnil; |
2178 | ||
af52c32d | 2179 | DEFVAR_LISP ("minibuffer-completion-confirm", &Vminibuffer_completion_confirm, |
fd771ceb | 2180 | doc: /* Non-nil means to demand confirmation of completion before exiting minibuffer. */); |
f927c5ae JB |
2181 | Vminibuffer_completion_confirm = Qnil; |
2182 | ||
ccf330a6 | 2183 | DEFVAR_LISP ("minibuffer-completing-file-name", |
af52c32d | 2184 | &Vminibuffer_completing_file_name, |
6ddfc113 | 2185 | doc: /* Non-nil means completing file names. */); |
ccf330a6 RS |
2186 | Vminibuffer_completing_file_name = Qnil; |
2187 | ||
af52c32d MB |
2188 | DEFVAR_LISP ("minibuffer-help-form", &Vminibuffer_help_form, |
2189 | doc: /* Value that `help-form' takes on inside the minibuffer. */); | |
f927c5ae JB |
2190 | Vminibuffer_help_form = Qnil; |
2191 | ||
af52c32d MB |
2192 | DEFVAR_LISP ("minibuffer-history-variable", &Vminibuffer_history_variable, |
2193 | doc: /* History list symbol to add minibuffer values to. | |
a1f17501 PJ |
2194 | Each string of minibuffer input, as it appears on exit from the minibuffer, |
2195 | is added with | |
2196 | (set minibuffer-history-variable | |
2197 | (cons STRING (symbol-value minibuffer-history-variable))) */); | |
5a866662 | 2198 | XSETFASTINT (Vminibuffer_history_variable, 0); |
770970cb | 2199 | |
af52c32d MB |
2200 | DEFVAR_LISP ("minibuffer-history-position", &Vminibuffer_history_position, |
2201 | doc: /* Current position of redoing in the history list. */); | |
770970cb RS |
2202 | Vminibuffer_history_position = Qnil; |
2203 | ||
af52c32d MB |
2204 | DEFVAR_BOOL ("minibuffer-auto-raise", &minibuffer_auto_raise, |
2205 | doc: /* *Non-nil means entering the minibuffer raises the minibuffer's frame. | |
a1f17501 | 2206 | Some uses of the echo area also raise that frame (since they use it too). */); |
6a9ee000 RS |
2207 | minibuffer_auto_raise = 0; |
2208 | ||
af52c32d | 2209 | DEFVAR_LISP ("completion-regexp-list", &Vcompletion_regexp_list, |
6b61353c KH |
2210 | doc: /* List of regexps that should restrict possible completions. |
2211 | The basic completion functions only consider a completion acceptable | |
2212 | if it matches all regular expressions in this list, with | |
2213 | `case-fold-search' bound to the value of `completion-ignore-case'. | |
2214 | See Info node `(elisp)Basic Completion', for a description of these | |
2215 | functions. */); | |
42006772 RS |
2216 | Vcompletion_regexp_list = Qnil; |
2217 | ||
c3421833 | 2218 | DEFVAR_BOOL ("minibuffer-allow-text-properties", |
af52c32d MB |
2219 | &minibuffer_allow_text_properties, |
2220 | doc: /* Non-nil means `read-from-minibuffer' should not discard text properties. | |
a1f17501 PJ |
2221 | This also affects `read-string', but it does not affect `read-minibuffer', |
2222 | `read-no-blanks-input', or any of the functions that do minibuffer input | |
2223 | with completion; they always discard text properties. */); | |
c3421833 RS |
2224 | minibuffer_allow_text_properties = 0; |
2225 | ||
af52c32d MB |
2226 | DEFVAR_LISP ("minibuffer-prompt-properties", &Vminibuffer_prompt_properties, |
2227 | doc: /* Text properties that are added to minibuffer prompts. | |
a1f17501 PJ |
2228 | These are in addition to the basic `field' property, and stickiness |
2229 | properties. */); | |
cc64f5c9 MB |
2230 | /* We use `intern' here instead of Qread_only to avoid |
2231 | initialization-order problems. */ | |
2232 | Vminibuffer_prompt_properties | |
2233 | = Fcons (intern ("read-only"), Fcons (Qt, Qnil)); | |
2234 | ||
627fb581 RS |
2235 | DEFVAR_LISP ("read-expression-map", &Vread_expression_map, |
2236 | doc: /* Minibuffer keymap used for reading Lisp expressions. */); | |
2237 | Vread_expression_map = Qnil; | |
2238 | ||
68313ed8 | 2239 | defsubr (&Sset_minibuffer_window); |
f927c5ae JB |
2240 | defsubr (&Sread_from_minibuffer); |
2241 | defsubr (&Seval_minibuffer); | |
2242 | defsubr (&Sread_minibuffer); | |
2243 | defsubr (&Sread_string); | |
2244 | defsubr (&Sread_command); | |
2245 | defsubr (&Sread_variable); | |
ff137f16 | 2246 | defsubr (&Sinternal_complete_buffer); |
f927c5ae JB |
2247 | defsubr (&Sread_buffer); |
2248 | defsubr (&Sread_no_blanks_input); | |
2249 | defsubr (&Sminibuffer_depth); | |
37e9a934 | 2250 | defsubr (&Sminibuffer_prompt); |
f927c5ae | 2251 | |
873ef78e | 2252 | defsubr (&Sminibufferp); |
a346ec72 MB |
2253 | defsubr (&Sminibuffer_prompt_end); |
2254 | defsubr (&Sminibuffer_contents); | |
2255 | defsubr (&Sminibuffer_contents_no_properties); | |
b5e1e449 | 2256 | defsubr (&Sminibuffer_completion_contents); |
a346ec72 | 2257 | |
f927c5ae JB |
2258 | defsubr (&Stry_completion); |
2259 | defsubr (&Sall_completions); | |
695deb18 SM |
2260 | defsubr (&Stest_completion); |
2261 | defsubr (&Sassoc_string); | |
f927c5ae | 2262 | defsubr (&Scompleting_read); |
f927c5ae JB |
2263 | } |
2264 | ||
6b61353c KH |
2265 | /* arch-tag: 8f69b601-fba3-484c-a6dd-ceaee54a7a73 |
2266 | (do not change this comment) */ |