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