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