Mercurial > emacs
annotate src/minibuf.c @ 1287:02bd1ea07b17
* intervals.h: Declare temp_set_point.
author | Joseph Arceneaux <jla@gnu.org> |
---|---|
date | Thu, 01 Oct 1992 00:56:11 +0000 |
parents | 7c4519722020 |
children | b74069f669cc |
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)); | |
1198
7c4519722020
Thu Sep 17 15:51:18 1992 Jim Blandy (jimb@pogo.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1010
diff
changeset
|
272 |
7c4519722020
Thu Sep 17 15:51:18 1992 Jim Blandy (jimb@pogo.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1010
diff
changeset
|
273 /* Although the buffer's name starts with a space, undo should be |
7c4519722020
Thu Sep 17 15:51:18 1992 Jim Blandy (jimb@pogo.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1010
diff
changeset
|
274 enabled in it. */ |
7c4519722020
Thu Sep 17 15:51:18 1992 Jim Blandy (jimb@pogo.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1010
diff
changeset
|
275 Fbuffer_enable_undo (buf); |
7c4519722020
Thu Sep 17 15:51:18 1992 Jim Blandy (jimb@pogo.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1010
diff
changeset
|
276 |
284 | 277 XCONS (tail)->car = buf; |
278 } | |
279 else | |
280 reset_buffer (XBUFFER (buf)); | |
281 return buf; | |
282 } | |
283 | |
284 /* This function is called on exiting minibuffer, whether normally or not, | |
285 and it restores the current window, buffer, etc. */ | |
286 | |
287 void | |
358 | 288 read_minibuf_unwind (data) |
289 Lisp_Object data; | |
284 | 290 { |
291 /* Erase the minibuffer we were using at this level. */ | |
292 Fset_buffer (XWINDOW (minibuf_window)->buffer); | |
293 | |
294 /* Prevent error in erase-buffer. */ | |
295 current_buffer->read_only = Qnil; | |
296 Ferase_buffer (); | |
297 | |
298 /* If this was a recursive minibuffer, | |
299 tie the minibuffer window back to the outer level minibuffer buffer */ | |
300 minibuf_level--; | |
301 /* Make sure minibuffer window is erased, not ignored */ | |
302 windows_or_buffers_changed++; | |
303 XFASTINT (XWINDOW (minibuf_window)->last_modified) = 0; | |
304 | |
305 /* Restore prompt from outer minibuffer */ | |
306 minibuf_prompt = minibuf_save_vector[minibuf_level].prompt; | |
307 minibuf_prompt_width = minibuf_save_vector[minibuf_level].prompt_width; | |
308 Vhelp_form = minibuf_save_vector[minibuf_level].help_form; | |
309 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
|
310 Vminibuffer_history_position |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
311 = minibuf_save_vector[minibuf_level].history_position; |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
312 Vminibuffer_history_variable |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
313 = minibuf_save_vector[minibuf_level].history_variable; |
358 | 314 |
765 | 315 #ifdef MULTI_FRAME |
316 /* Redirect the focus of the frame that called the minibuffer. */ | |
358 | 317 if (CONSP (data)) |
765 | 318 Fredirect_frame_focus (XCONS (data)->car, XCONS (data)->cdr); |
358 | 319 #endif |
284 | 320 } |
321 | |
1010
b6a67ffc7536
* minibuf.c (Fread_from_minibuffer): Put this function's doc
Jim Blandy <jimb@redhat.com>
parents:
967
diff
changeset
|
322 |
b6a67ffc7536
* minibuf.c (Fread_from_minibuffer): Put this function's doc
Jim Blandy <jimb@redhat.com>
parents:
967
diff
changeset
|
323 /* 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
|
324 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
|
325 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
|
326 |
284 | 327 DEFUN ("read-from-minibuffer", Fread_from_minibuffer, Sread_from_minibuffer, 1, 5, 0, |
328 "Read a string from the minibuffer, prompting with string PROMPT.\n\ | |
329 If optional second arg INITIAL-CONTENTS is non-nil, it is a string\n\ | |
330 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
|
331 If INITIAL-CONTENTS is (STRING . POSITION), the initial input\n\ |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
332 is STRING, but point is placed POSITION characters into the string.\n\ |
284 | 333 Third arg KEYMAP is a keymap to use whilst reading;\n\ |
334 if omitted or nil, the default is `minibuffer-local-map'.\n\ | |
335 If fourth arg READ is non-nil, then interpret the result as a lisp object\n\ | |
336 and return that object:\n\ | |
337 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
|
338 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
|
339 and optionally the initial position in the list.\n\ |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
340 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
|
341 or it can be a cons cell (HISTVAR . HISTPOS).\n\ |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
342 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
|
343 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
|
344 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
|
345 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
|
346 */ |
b6a67ffc7536
* minibuf.c (Fread_from_minibuffer): Put this function's doc
Jim Blandy <jimb@redhat.com>
parents:
967
diff
changeset
|
347 |
b6a67ffc7536
* minibuf.c (Fread_from_minibuffer): Put this function's doc
Jim Blandy <jimb@redhat.com>
parents:
967
diff
changeset
|
348 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
|
349 0 /* See immediately above */) |
864
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
350 (prompt, initial_input, keymap, read, hist) |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
351 Lisp_Object prompt, initial_input, keymap, read, hist; |
284 | 352 { |
353 int pos = 0; | |
864
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
354 Lisp_Object histvar, histpos, position; |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
355 position = Qnil; |
284 | 356 |
357 CHECK_STRING (prompt, 0); | |
488 | 358 if (!NILP (initial_input)) |
284 | 359 { |
864
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
360 if (XTYPE (initial_input) == Lisp_Cons) |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
361 { |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
362 position = Fcdr (initial_input); |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
363 initial_input = Fcar (initial_input); |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
364 } |
284 | 365 CHECK_STRING (initial_input, 1); |
488 | 366 if (!NILP (position)) |
284 | 367 { |
368 CHECK_NUMBER (position, 0); | |
369 /* Convert to distance from end of input. */ | |
370 pos = XINT (position) - 1 - XSTRING (initial_input)->size; | |
371 } | |
372 } | |
373 | |
488 | 374 if (NILP (keymap)) |
284 | 375 keymap = Vminibuffer_local_map; |
376 else | |
377 keymap = get_keymap (keymap,2); | |
864
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 if (XTYPE (hist) == Lisp_Symbol) |
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 = hist; |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
382 histpos = Qnil; |
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 else |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
385 { |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
386 histvar = Fcar_safe (hist); |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
387 histpos = Fcdr_safe (hist); |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
388 } |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
389 if (NILP (histvar)) |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
390 histvar = Qminibuffer_history; |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
391 if (NILP (histpos)) |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
392 XFASTINT (histpos) = 0; |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
393 |
284 | 394 return read_minibuf (keymap, initial_input, prompt, |
866 | 395 make_number (pos), !NILP (read), histvar, histpos); |
284 | 396 } |
397 | |
398 DEFUN ("read-minibuffer", Fread_minibuffer, Sread_minibuffer, 1, 2, 0, | |
399 "Return a Lisp object read using the minibuffer.\n\ | |
400 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS\n\ | |
401 is a string to insert in the minibuffer before reading.") | |
402 (prompt, initial_contents) | |
403 Lisp_Object prompt, initial_contents; | |
404 { | |
405 CHECK_STRING (prompt, 0); | |
488 | 406 if (!NILP (initial_contents)) |
284 | 407 CHECK_STRING (initial_contents, 1) |
864
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
408 return read_minibuf (Vminibuffer_local_map, initial_contents, |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
409 prompt, Qnil, 1, Qminibuffer_history, make_number (0)); |
284 | 410 } |
411 | |
412 DEFUN ("eval-minibuffer", Feval_minibuffer, Seval_minibuffer, 1, 2, 0, | |
413 "Return value of Lisp expression read using the minibuffer.\n\ | |
414 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS\n\ | |
415 is a string to insert in the minibuffer before reading.") | |
416 (prompt, initial_contents) | |
417 Lisp_Object prompt, initial_contents; | |
418 { | |
419 return Feval (Fread_minibuffer (prompt, initial_contents)); | |
420 } | |
421 | |
422 /* Functions that use the minibuffer to read various things. */ | |
423 | |
424 DEFUN ("read-string", Fread_string, Sread_string, 1, 2, 0, | |
425 "Read a string from the minibuffer, prompting with string PROMPT.\n\ | |
426 If non-nil second arg INITIAL-INPUT is a string to insert before reading.") | |
427 (prompt, initial_input) | |
428 Lisp_Object prompt, initial_input; | |
429 { | |
430 return Fread_from_minibuffer (prompt, initial_input, Qnil, Qnil, Qnil); | |
431 } | |
432 | |
732 | 433 DEFUN ("read-no-blanks-input", Fread_no_blanks_input, Sread_no_blanks_input, 2, 2, 0, |
284 | 434 "Args PROMPT and INIT, strings. Read a string from the terminal, not allowing blanks.\n\ |
435 Prompt with PROMPT, and provide INIT as an initial value of the input string.") | |
436 (prompt, init) | |
437 Lisp_Object prompt, init; | |
438 { | |
439 CHECK_STRING (prompt, 0); | |
488 | 440 if (! NILP (init)) |
284 | 441 CHECK_STRING (init, 1); |
442 | |
864
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
443 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
|
444 Qminibuffer_history, make_number (0)); |
284 | 445 } |
446 | |
447 DEFUN ("read-command", Fread_command, Sread_command, 1, 1, 0, | |
448 "One arg PROMPT, a string. Read the name of a command and return as a symbol.\n\ | |
449 Prompts with PROMPT.") | |
450 (prompt) | |
451 Lisp_Object prompt; | |
452 { | |
453 return Fintern (Fcompleting_read (prompt, Vobarray, Qcommandp, Qt, Qnil, Qnil), | |
454 Qnil); | |
455 } | |
456 | |
457 #ifdef NOTDEF | |
458 DEFUN ("read-function", Fread_function, Sread_function, 1, 1, 0, | |
459 "One arg PROMPT, a string. Read the name of a function and return as a symbol.\n\ | |
460 Prompts with PROMPT.") | |
461 (prompt) | |
462 Lisp_Object prompt; | |
463 { | |
464 return Fintern (Fcompleting_read (prompt, Vobarray, Qfboundp, Qt, Qnil, Qnil), | |
465 Qnil); | |
466 } | |
467 #endif /* NOTDEF */ | |
468 | |
469 DEFUN ("read-variable", Fread_variable, Sread_variable, 1, 1, 0, | |
470 "One arg PROMPT, a string. Read the name of a user variable and return\n\ | |
471 it as a symbol. Prompts with PROMPT.\n\ | |
472 A user variable is one whose documentation starts with a `*' character.") | |
473 (prompt) | |
474 Lisp_Object prompt; | |
475 { | |
476 return Fintern (Fcompleting_read (prompt, Vobarray, | |
477 Quser_variable_p, Qt, Qnil, Qnil), | |
478 Qnil); | |
479 } | |
480 | |
481 DEFUN ("read-buffer", Fread_buffer, Sread_buffer, 1, 3, 0, | |
482 "One arg PROMPT, a string. Read the name of a buffer and return as a string.\n\ | |
483 Prompts with PROMPT.\n\ | |
484 Optional second arg is value to return if user enters an empty line.\n\ | |
485 If optional third arg REQUIRE-MATCH is non-nil, only existing buffer names are allowed.") | |
486 (prompt, def, require_match) | |
487 Lisp_Object prompt, def, require_match; | |
488 { | |
489 Lisp_Object tem; | |
490 Lisp_Object args[3]; | |
491 struct gcpro gcpro1; | |
492 | |
493 if (XTYPE (def) == Lisp_Buffer) | |
494 def = XBUFFER (def)->name; | |
488 | 495 if (!NILP (def)) |
284 | 496 { |
497 args[0] = build_string ("%s(default %s) "); | |
498 args[1] = prompt; | |
499 args[2] = def; | |
500 prompt = Fformat (3, args); | |
501 } | |
502 GCPRO1 (def); | |
503 tem = Fcompleting_read (prompt, Vbuffer_alist, Qnil, require_match, Qnil, Qnil); | |
504 UNGCPRO; | |
505 if (XSTRING (tem)->size) | |
506 return tem; | |
507 return def; | |
508 } | |
509 | |
510 DEFUN ("try-completion", Ftry_completion, Stry_completion, 2, 3, 0, | |
511 "Return common substring of all completions of STRING in ALIST.\n\ | |
512 Each car of each element of ALIST is tested to see if it begins with STRING.\n\ | |
513 All that match are compared together; the longest initial sequence\n\ | |
514 common to all matches is returned as a string.\n\ | |
515 If there is no match at all, nil is returned.\n\ | |
516 For an exact match, t is returned.\n\ | |
517 \n\ | |
518 ALIST can be an obarray instead of an alist.\n\ | |
519 Then the print names of all symbols in the obarray are the possible matches.\n\ | |
520 \n\ | |
521 ALIST can also be a function to do the completion itself.\n\ | |
522 It receives three arguments: the values STRING, PREDICATE and nil.\n\ | |
523 Whatever it returns becomes the value of `try-completion'.\n\ | |
524 \n\ | |
525 If optional third argument PREDICATE is non-nil,\n\ | |
526 it is used to test each possible match.\n\ | |
527 The match is a candidate only if PREDICATE returns non-nil.\n\ | |
528 The argument given to PREDICATE is the alist element or the symbol from the obarray.") | |
529 (string, alist, pred) | |
530 Lisp_Object string, alist, pred; | |
531 { | |
532 Lisp_Object bestmatch, tail, elt, eltstring; | |
533 int bestmatchsize; | |
534 int compare, matchsize; | |
488 | 535 int list = CONSP (alist) || NILP (alist); |
284 | 536 int index, obsize; |
537 int matchcount = 0; | |
538 Lisp_Object bucket, zero, end, tem; | |
539 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | |
540 | |
541 CHECK_STRING (string, 0); | |
542 if (!list && XTYPE (alist) != Lisp_Vector) | |
543 return call3 (alist, string, pred, Qnil); | |
544 | |
545 bestmatch = Qnil; | |
546 | |
547 /* If ALIST is not a list, set TAIL just for gc pro. */ | |
548 tail = alist; | |
549 if (! list) | |
550 { | |
551 index = 0; | |
552 obsize = XVECTOR (alist)->size; | |
553 bucket = XVECTOR (alist)->contents[index]; | |
554 } | |
555 | |
556 while (1) | |
557 { | |
558 /* Get the next element of the alist or obarray. */ | |
559 /* Exit the loop if the elements are all used up. */ | |
560 /* elt gets the alist element or symbol. | |
561 eltstring gets the name to check as a completion. */ | |
562 | |
563 if (list) | |
564 { | |
488 | 565 if (NILP (tail)) |
284 | 566 break; |
567 elt = Fcar (tail); | |
568 eltstring = Fcar (elt); | |
569 tail = Fcdr (tail); | |
570 } | |
571 else | |
572 { | |
573 if (XFASTINT (bucket) != 0) | |
574 { | |
575 elt = bucket; | |
576 eltstring = Fsymbol_name (elt); | |
577 if (XSYMBOL (bucket)->next) | |
578 XSETSYMBOL (bucket, XSYMBOL (bucket)->next); | |
579 else | |
580 XFASTINT (bucket) = 0; | |
581 } | |
582 else if (++index >= obsize) | |
583 break; | |
584 else | |
585 { | |
586 bucket = XVECTOR (alist)->contents[index]; | |
587 continue; | |
588 } | |
589 } | |
590 | |
591 /* Is this element a possible completion? */ | |
592 | |
593 if (XTYPE (eltstring) == Lisp_String && | |
594 XSTRING (string)->size <= XSTRING (eltstring)->size && | |
595 0 > scmp (XSTRING (eltstring)->data, XSTRING (string)->data, | |
596 XSTRING (string)->size)) | |
597 { | |
598 /* Yes. */ | |
599 /* Ignore this element if there is a predicate | |
600 and the predicate doesn't like it. */ | |
601 | |
488 | 602 if (!NILP (pred)) |
284 | 603 { |
604 if (EQ (pred, Qcommandp)) | |
605 tem = Fcommandp (elt); | |
606 else | |
607 { | |
608 GCPRO4 (tail, string, eltstring, bestmatch); | |
609 tem = call1 (pred, elt); | |
610 UNGCPRO; | |
611 } | |
488 | 612 if (NILP (tem)) continue; |
284 | 613 } |
614 | |
615 /* Update computation of how much all possible completions match */ | |
616 | |
617 matchcount++; | |
488 | 618 if (NILP (bestmatch)) |
284 | 619 bestmatch = eltstring, bestmatchsize = XSTRING (eltstring)->size; |
620 else | |
621 { | |
622 compare = min (bestmatchsize, XSTRING (eltstring)->size); | |
623 matchsize = scmp (XSTRING (bestmatch)->data, | |
624 XSTRING (eltstring)->data, | |
625 compare); | |
330 | 626 if (matchsize < 0) |
627 matchsize = compare; | |
628 if (completion_ignore_case) | |
629 { | |
630 /* If this is an exact match except for case, | |
631 use it as the best match rather than one that is not an | |
632 exact match. This way, we get the case pattern | |
633 of the actual match. */ | |
634 if ((matchsize == XSTRING (eltstring)->size | |
635 && matchsize < XSTRING (bestmatch)->size) | |
636 || | |
637 /* If there is more than one exact match ignoring case, | |
638 and one of them is exact including case, | |
639 prefer that one. */ | |
640 /* If there is no exact match ignoring case, | |
641 prefer a match that does not change the case | |
642 of the input. */ | |
643 ((matchsize == XSTRING (eltstring)->size) | |
644 == | |
645 (matchsize == XSTRING (bestmatch)->size) | |
646 && !bcmp (XSTRING (eltstring)->data, | |
647 XSTRING (string)->data, XSTRING (string)->size) | |
648 && bcmp (XSTRING (bestmatch)->data, | |
649 XSTRING (string)->data, XSTRING (string)->size))) | |
650 bestmatch = eltstring; | |
651 } | |
652 bestmatchsize = matchsize; | |
284 | 653 } |
654 } | |
655 } | |
656 | |
488 | 657 if (NILP (bestmatch)) |
284 | 658 return Qnil; /* No completions found */ |
330 | 659 /* If we are ignoring case, and there is no exact match, |
660 and no additional text was supplied, | |
661 don't change the case of what the user typed. */ | |
662 if (completion_ignore_case && bestmatchsize == XSTRING (string)->size | |
663 && XSTRING (bestmatch)->size > bestmatchsize) | |
664 return string; | |
665 | |
666 /* Return t if the supplied string is an exact match (counting case); | |
667 it does not require any change to be made. */ | |
668 if (matchcount == 1 && bestmatchsize == XSTRING (string)->size | |
669 && !bcmp (XSTRING (bestmatch)->data, XSTRING (string)->data, | |
670 bestmatchsize)) | |
284 | 671 return Qt; |
672 | |
673 XFASTINT (zero) = 0; /* Else extract the part in which */ | |
674 XFASTINT (end) = bestmatchsize; /* all completions agree */ | |
675 return Fsubstring (bestmatch, zero, end); | |
676 } | |
677 | |
678 /* Compare exactly LEN chars of strings at S1 and S2, | |
679 ignoring case if appropriate. | |
680 Return -1 if strings match, | |
681 else number of chars that match at the beginning. */ | |
682 | |
683 scmp (s1, s2, len) | |
684 register char *s1, *s2; | |
685 int len; | |
686 { | |
687 register int l = len; | |
688 | |
689 if (completion_ignore_case) | |
690 { | |
691 while (l && DOWNCASE (*s1++) == DOWNCASE (*s2++)) | |
692 l--; | |
693 } | |
694 else | |
695 { | |
696 while (l && *s1++ == *s2++) | |
697 l--; | |
698 } | |
699 if (l == 0) | |
700 return -1; | |
701 else return len - l; | |
702 } | |
703 | |
704 DEFUN ("all-completions", Fall_completions, Sall_completions, 2, 3, 0, | |
705 "Search for partial matches to STRING in ALIST.\n\ | |
706 Each car of each element of ALIST is tested to see if it begins with STRING.\n\ | |
707 The value is a list of all the strings from ALIST that match.\n\ | |
708 ALIST can be an obarray instead of an alist.\n\ | |
709 Then the print names of all symbols in the obarray are the possible matches.\n\ | |
710 \n\ | |
711 ALIST can also be a function to do the completion itself.\n\ | |
712 It receives three arguments: the values STRING, PREDICATE and t.\n\ | |
713 Whatever it returns becomes the value of `all-completion'.\n\ | |
714 \n\ | |
715 If optional third argument PREDICATE is non-nil,\n\ | |
716 it is used to test each possible match.\n\ | |
717 The match is a candidate only if PREDICATE returns non-nil.\n\ | |
718 The argument given to PREDICATE is the alist element or the symbol from the obarray.") | |
719 (string, alist, pred) | |
720 Lisp_Object string, alist, pred; | |
721 { | |
722 Lisp_Object tail, elt, eltstring; | |
723 Lisp_Object allmatches; | |
488 | 724 int list = CONSP (alist) || NILP (alist); |
284 | 725 int index, obsize; |
726 Lisp_Object bucket, tem; | |
727 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | |
728 | |
729 CHECK_STRING (string, 0); | |
730 if (!list && XTYPE (alist) != Lisp_Vector) | |
731 { | |
732 return call3 (alist, string, pred, Qt); | |
733 } | |
734 allmatches = Qnil; | |
735 | |
736 /* If ALIST is not a list, set TAIL just for gc pro. */ | |
737 tail = alist; | |
738 if (! list) | |
739 { | |
740 index = 0; | |
741 obsize = XVECTOR (alist)->size; | |
742 bucket = XVECTOR (alist)->contents[index]; | |
743 } | |
744 | |
745 while (1) | |
746 { | |
747 /* Get the next element of the alist or obarray. */ | |
748 /* Exit the loop if the elements are all used up. */ | |
749 /* elt gets the alist element or symbol. | |
750 eltstring gets the name to check as a completion. */ | |
751 | |
752 if (list) | |
753 { | |
488 | 754 if (NILP (tail)) |
284 | 755 break; |
756 elt = Fcar (tail); | |
757 eltstring = Fcar (elt); | |
758 tail = Fcdr (tail); | |
759 } | |
760 else | |
761 { | |
762 if (XFASTINT (bucket) != 0) | |
763 { | |
764 elt = bucket; | |
765 eltstring = Fsymbol_name (elt); | |
766 if (XSYMBOL (bucket)->next) | |
767 XSETSYMBOL (bucket, XSYMBOL (bucket)->next); | |
768 else | |
769 XFASTINT (bucket) = 0; | |
770 } | |
771 else if (++index >= obsize) | |
772 break; | |
773 else | |
774 { | |
775 bucket = XVECTOR (alist)->contents[index]; | |
776 continue; | |
777 } | |
778 } | |
779 | |
780 /* Is this element a possible completion? */ | |
781 | |
782 if (XTYPE (eltstring) == Lisp_String && | |
783 XSTRING (string)->size <= XSTRING (eltstring)->size && | |
784 XSTRING (eltstring)->data[0] != ' ' && | |
785 0 > scmp (XSTRING (eltstring)->data, XSTRING (string)->data, | |
786 XSTRING (string)->size)) | |
787 { | |
788 /* Yes. */ | |
789 /* Ignore this element if there is a predicate | |
790 and the predicate doesn't like it. */ | |
791 | |
488 | 792 if (!NILP (pred)) |
284 | 793 { |
794 if (EQ (pred, Qcommandp)) | |
795 tem = Fcommandp (elt); | |
796 else | |
797 { | |
798 GCPRO4 (tail, eltstring, allmatches, string); | |
799 tem = call1 (pred, elt); | |
800 UNGCPRO; | |
801 } | |
488 | 802 if (NILP (tem)) continue; |
284 | 803 } |
804 /* Ok => put it on the list. */ | |
805 allmatches = Fcons (eltstring, allmatches); | |
806 } | |
807 } | |
808 | |
809 return Fnreverse (allmatches); | |
810 } | |
811 | |
812 Lisp_Object Vminibuffer_completion_table, Qminibuffer_completion_table; | |
813 Lisp_Object Vminibuffer_completion_predicate, Qminibuffer_completion_predicate; | |
814 Lisp_Object Vminibuffer_completion_confirm, Qminibuffer_completion_confirm; | |
815 | |
1010
b6a67ffc7536
* minibuf.c (Fread_from_minibuffer): Put this function's doc
Jim Blandy <jimb@redhat.com>
parents:
967
diff
changeset
|
816 /* 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
|
817 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
|
818 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
|
819 |
284 | 820 DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 6, 0, |
821 "Read a string in the minibuffer, with completion.\n\ | |
864
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
822 Args: PROMPT, TABLE, PREDICATE, REQUIRE-MATCH, INITIAL-INPUT, HIST.\n\ |
284 | 823 PROMPT is a string to prompt with; normally it ends in a colon and a space.\n\ |
824 TABLE is an alist whose elements' cars are strings, or an obarray.\n\ | |
825 PREDICATE limits completion to a subset of TABLE.\n\ | |
826 See `try-completion' for more details on completion, TABLE, and PREDICATE.\n\ | |
827 If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless\n\ | |
828 the input is (or completes to) an element of TABLE.\n\ | |
829 If it is also not t, Return does not exit if it does non-null completion.\n\ | |
830 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
|
831 If it is (STRING . POSITION), the initial input\n\ |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
832 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
|
833 HIST, if non-nil, specifies a history list\n\ |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
834 and optionally the initial position in the list.\n\ |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
835 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
|
836 or it can be a cons cell (HISTVAR . HISTPOS).\n\ |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
837 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
|
838 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
|
839 which INITIAL-CONTENTS corresponds to).\n\ |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
840 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
|
841 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
|
842 `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
|
843 */ |
b6a67ffc7536
* minibuf.c (Fread_from_minibuffer): Put this function's doc
Jim Blandy <jimb@redhat.com>
parents:
967
diff
changeset
|
844 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
|
845 0 /* See immediately above */) |
864
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
846 (prompt, table, pred, require_match, init, hist) |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
847 Lisp_Object prompt, table, pred, require_match, init, hist; |
284 | 848 { |
864
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
849 Lisp_Object val, histvar, histpos, position; |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
850 int pos = 0; |
284 | 851 int count = specpdl_ptr - specpdl; |
852 specbind (Qminibuffer_completion_table, table); | |
853 specbind (Qminibuffer_completion_predicate, pred); | |
854 specbind (Qminibuffer_completion_confirm, | |
855 EQ (require_match, Qt) ? Qnil : Qt); | |
856 last_exact_completion = Qnil; | |
864
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 = Qnil; |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
859 if (!NILP (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 if (XTYPE (init) == Lisp_Cons) |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
862 { |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
863 position = Fcdr (init); |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
864 init = Fcar (init); |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
865 } |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
866 CHECK_STRING (init, 0); |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
867 if (!NILP (position)) |
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 CHECK_NUMBER (position, 0); |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
870 /* 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
|
871 pos = XINT (position) - XSTRING (init)->size; |
864
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
872 } |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
873 } |
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 if (XTYPE (hist) == Lisp_Symbol) |
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 = hist; |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
878 histpos = Qnil; |
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 else |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
881 { |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
882 histvar = Fcar_safe (hist); |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
883 histpos = Fcdr_safe (hist); |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
884 } |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
885 if (NILP (histvar)) |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
886 histvar = Qminibuffer_history; |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
887 if (NILP (histpos)) |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
888 XFASTINT (histpos) = 0; |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
889 |
488 | 890 val = read_minibuf (NILP (require_match) |
284 | 891 ? Vminibuffer_local_completion_map |
892 : Vminibuffer_local_must_match_map, | |
866 | 893 init, prompt, make_number (pos), 0, |
864
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
894 histvar, histpos); |
284 | 895 return unbind_to (count, val); |
896 } | |
897 | |
898 /* Temporarily display the string M at the end of the current | |
899 minibuffer contents. This is used to display things like | |
900 "[No Match]" when the user requests a completion for a prefix | |
901 that has no possible completions, and other quick, unobtrusive | |
902 messages. */ | |
903 | |
904 temp_echo_area_glyphs (m) | |
905 char *m; | |
906 { | |
907 /* It's not very modular to do things this way, but then it seems | |
908 to me that the whole echo_area_glyphs thing is a hack anyway. */ | |
909 extern char *previous_echo_glyphs; | |
910 | |
911 int osize = ZV; | |
912 Lisp_Object oinhibit; | |
913 oinhibit = Vinhibit_quit; | |
914 | |
915 /* Clear out any old echo-area message to make way for our new | |
916 thing. */ | |
917 echo_area_glyphs = previous_echo_glyphs = 0; | |
918 | |
919 SET_PT (osize); | |
920 insert_string (m); | |
921 SET_PT (osize); | |
922 Vinhibit_quit = Qt; | |
923 Fsit_for (make_number (2), Qnil, Qnil); | |
924 del_range (point, ZV); | |
488 | 925 if (!NILP (Vquit_flag)) |
284 | 926 { |
927 Vquit_flag = Qnil; | |
928 unread_command_char = Ctl ('g'); | |
929 } | |
930 Vinhibit_quit = oinhibit; | |
931 } | |
932 | |
933 Lisp_Object Fminibuffer_completion_help (); | |
330 | 934 Lisp_Object assoc_for_completion (); |
284 | 935 |
936 /* returns: | |
937 * 0 no possible completion | |
938 * 1 was already an exact and unique completion | |
939 * 3 was already an exact completion | |
940 * 4 completed to an exact completion | |
941 * 5 some completion happened | |
942 * 6 no completion happened | |
943 */ | |
944 int | |
945 do_completion () | |
946 { | |
947 Lisp_Object completion, tem; | |
948 int completedp; | |
949 Lisp_Object last; | |
950 | |
951 completion = Ftry_completion (Fbuffer_string (), Vminibuffer_completion_table, | |
952 Vminibuffer_completion_predicate); | |
953 last = last_exact_completion; | |
954 last_exact_completion = Qnil; | |
955 | |
488 | 956 if (NILP (completion)) |
284 | 957 { |
958 bitch_at_user (); | |
959 temp_echo_area_glyphs (" [No match]"); | |
960 return 0; | |
961 } | |
962 | |
963 if (EQ (completion, Qt)) /* exact and unique match */ | |
964 return 1; | |
965 | |
966 /* compiler bug */ | |
967 tem = Fstring_equal (completion, Fbuffer_string()); | |
488 | 968 if (completedp = NILP (tem)) |
284 | 969 { |
970 Ferase_buffer (); /* Some completion happened */ | |
971 Finsert (1, &completion); | |
972 } | |
973 | |
974 /* It did find a match. Do we match some possibility exactly now? */ | |
975 if (CONSP (Vminibuffer_completion_table) | |
488 | 976 || NILP (Vminibuffer_completion_table)) |
330 | 977 tem = assoc_for_completion (Fbuffer_string (), |
978 Vminibuffer_completion_table); | |
284 | 979 else if (XTYPE (Vminibuffer_completion_table) == Lisp_Vector) |
980 { | |
981 /* the primitive used by Fintern_soft */ | |
982 extern Lisp_Object oblookup (); | |
983 | |
984 tem = Fbuffer_string (); | |
985 /* Bypass intern-soft as that loses for nil */ | |
986 tem = oblookup (Vminibuffer_completion_table, | |
987 XSTRING (tem)->data, XSTRING (tem)->size); | |
988 if (XTYPE (tem) != Lisp_Symbol) | |
989 tem = Qnil; | |
488 | 990 else if (!NILP (Vminibuffer_completion_predicate)) |
284 | 991 tem = call1 (Vminibuffer_completion_predicate, tem); |
992 else | |
993 tem = Qt; | |
994 } | |
995 else | |
996 tem = call3 (Vminibuffer_completion_table, | |
997 Fbuffer_string (), | |
998 Vminibuffer_completion_predicate, | |
999 Qlambda); | |
1000 | |
488 | 1001 if (NILP (tem)) |
284 | 1002 { /* not an exact match */ |
1003 if (completedp) | |
1004 return 5; | |
1005 else if (auto_help) | |
1006 Fminibuffer_completion_help (); | |
1007 else | |
1008 temp_echo_area_glyphs (" [Next char not unique]"); | |
1009 return 6; | |
1010 } | |
1011 else if (completedp) | |
1012 return 4; | |
1013 /* If the last exact completion and this one were the same, | |
1014 it means we've already given a "Complete but not unique" | |
330 | 1015 message and the user's hit TAB again, so now we give him help. */ |
284 | 1016 last_exact_completion = completion; |
488 | 1017 if (!NILP (last)) |
284 | 1018 { |
1019 tem = Fbuffer_string (); | |
488 | 1020 if (!NILP (Fequal (tem, last))) |
284 | 1021 Fminibuffer_completion_help (); |
1022 } | |
1023 return 3; | |
1024 } | |
1025 | |
330 | 1026 /* Like assoc but assumes KEY is a string, and ignores case if appropriate. */ |
1027 | |
1028 Lisp_Object | |
1029 assoc_for_completion (key, list) | |
1030 register Lisp_Object key; | |
1031 Lisp_Object list; | |
1032 { | |
1033 register Lisp_Object tail; | |
1034 | |
1035 if (completion_ignore_case) | |
1036 key = Fupcase (key); | |
1037 | |
488 | 1038 for (tail = list; !NILP (tail); tail = Fcdr (tail)) |
330 | 1039 { |
1040 register Lisp_Object elt, tem, thiscar; | |
1041 elt = Fcar (tail); | |
1042 if (!CONSP (elt)) continue; | |
1043 thiscar = Fcar (elt); | |
1044 if (XTYPE (thiscar) != Lisp_String) | |
1045 continue; | |
1046 if (completion_ignore_case) | |
1047 thiscar = Fupcase (thiscar); | |
1048 tem = Fequal (thiscar, key); | |
488 | 1049 if (!NILP (tem)) return elt; |
330 | 1050 QUIT; |
1051 } | |
1052 return Qnil; | |
1053 } | |
284 | 1054 |
1055 DEFUN ("minibuffer-complete", Fminibuffer_complete, Sminibuffer_complete, 0, 0, "", | |
1056 "Complete the minibuffer contents as far as possible.") | |
1057 () | |
1058 { | |
1059 register int i = do_completion (); | |
1060 switch (i) | |
1061 { | |
1062 case 0: | |
1063 return Qnil; | |
1064 | |
1065 case 1: | |
1066 temp_echo_area_glyphs (" [Sole completion]"); | |
1067 break; | |
1068 | |
1069 case 3: | |
1070 temp_echo_area_glyphs (" [Complete, but not unique]"); | |
1071 break; | |
1072 } | |
1073 | |
1074 return Qt; | |
1075 } | |
1076 | |
1077 DEFUN ("minibuffer-complete-and-exit", Fminibuffer_complete_and_exit, | |
1078 Sminibuffer_complete_and_exit, 0, 0, "", | |
1079 "Complete the minibuffer contents, and maybe exit.\n\ | |
1080 Exit if the name is valid with no completion needed.\n\ | |
1081 If name was completed to a valid match,\n\ | |
1082 a repetition of this command will exit.") | |
1083 () | |
1084 { | |
1085 register int i; | |
1086 | |
1087 /* Allow user to specify null string */ | |
1088 if (BEGV == ZV) | |
1089 goto exit; | |
1090 | |
1091 i = do_completion (); | |
1092 switch (i) | |
1093 { | |
1094 case 1: | |
1095 case 3: | |
1096 goto exit; | |
1097 | |
1098 case 4: | |
488 | 1099 if (!NILP (Vminibuffer_completion_confirm)) |
284 | 1100 { |
1101 temp_echo_area_glyphs (" [Confirm]"); | |
1102 return Qnil; | |
1103 } | |
1104 else | |
1105 goto exit; | |
1106 | |
1107 default: | |
1108 return Qnil; | |
1109 } | |
1110 exit: | |
1111 Fthrow (Qexit, Qnil); | |
1112 /* NOTREACHED */ | |
1113 } | |
1114 | |
1115 DEFUN ("minibuffer-complete-word", Fminibuffer_complete_word, Sminibuffer_complete_word, | |
1116 0, 0, "", | |
1117 "Complete the minibuffer contents at most a single word.\n\ | |
1118 After one word is completed as much as possible, a space or hyphen\n\ | |
1119 is added, provided that matches some possible completion.") | |
1120 () | |
1121 { | |
1122 Lisp_Object completion, tem; | |
1123 register int i; | |
1124 register unsigned char *completion_string; | |
1125 /* We keep calling Fbuffer_string | |
1126 rather than arrange for GC to hold onto a pointer to | |
1127 one of the strings thus made. */ | |
1128 | |
1129 completion = Ftry_completion (Fbuffer_string (), | |
1130 Vminibuffer_completion_table, | |
1131 Vminibuffer_completion_predicate); | |
488 | 1132 if (NILP (completion)) |
284 | 1133 { |
1134 bitch_at_user (); | |
1135 temp_echo_area_glyphs (" [No match]"); | |
1136 return Qnil; | |
1137 } | |
1138 if (EQ (completion, Qt)) | |
1139 return Qnil; | |
1140 | |
1141 #if 0 /* How the below code used to look, for reference */ | |
1142 tem = Fbuffer_string (); | |
1143 b = XSTRING (tem)->data; | |
1144 i = ZV - 1 - XSTRING (completion)->size; | |
1145 p = XSTRING (completion)->data; | |
1146 if (i > 0 || | |
1147 0 <= scmp (b, p, ZV - 1)) | |
1148 { | |
1149 i = 1; | |
1150 /* Set buffer to longest match of buffer tail and completion head. */ | |
1151 while (0 <= scmp (b + i, p, ZV - 1 - i)) | |
1152 i++; | |
1153 del_range (1, i + 1); | |
1154 SET_PT (ZV); | |
1155 } | |
1156 #else /* Rewritten code */ | |
1157 { | |
1158 register unsigned char *buffer_string; | |
1159 int buffer_length, completion_length; | |
1160 | |
1161 tem = Fbuffer_string (); | |
1162 buffer_string = XSTRING (tem)->data; | |
1163 completion_string = XSTRING (completion)->data; | |
1164 buffer_length = XSTRING (tem)->size; /* ie ZV - BEGV */ | |
1165 completion_length = XSTRING (completion)->size; | |
1166 i = buffer_length - completion_length; | |
1167 /* Mly: I don't understand what this is supposed to do AT ALL */ | |
1168 if (i > 0 || | |
1169 0 <= scmp (buffer_string, completion_string, buffer_length)) | |
1170 { | |
1171 /* Set buffer to longest match of buffer tail and completion head. */ | |
1172 if (i <= 0) i = 1; | |
1173 buffer_string += i; | |
1174 buffer_length -= i; | |
1175 while (0 <= scmp (buffer_string++, completion_string, buffer_length--)) | |
1176 i++; | |
1177 del_range (1, i + 1); | |
1178 SET_PT (ZV); | |
1179 } | |
1180 } | |
1181 #endif /* Rewritten code */ | |
1182 i = ZV - BEGV; | |
1183 | |
1184 /* If completion finds next char not unique, | |
1185 consider adding a space or a hyphen */ | |
1186 if (i == XSTRING (completion)->size) | |
1187 { | |
1188 tem = Ftry_completion (concat2 (Fbuffer_string (), build_string (" ")), | |
1189 Vminibuffer_completion_table, | |
1190 Vminibuffer_completion_predicate); | |
1191 if (XTYPE (tem) == Lisp_String) | |
1192 completion = tem; | |
1193 else | |
1194 { | |
1195 tem = Ftry_completion (concat2 (Fbuffer_string (), build_string ("-")), | |
1196 Vminibuffer_completion_table, | |
1197 Vminibuffer_completion_predicate); | |
1198 if (XTYPE (tem) == Lisp_String) | |
1199 completion = tem; | |
1200 } | |
1201 } | |
1202 | |
1203 /* Now find first word-break in the stuff found by completion. | |
1204 i gets index in string of where to stop completing. */ | |
1205 completion_string = XSTRING (completion)->data; | |
1206 | |
1207 for (; i < XSTRING (completion)->size; i++) | |
1208 if (SYNTAX (completion_string[i]) != Sword) break; | |
1209 if (i < XSTRING (completion)->size) | |
1210 i = i + 1; | |
1211 | |
1212 /* If got no characters, print help for user. */ | |
1213 | |
1214 if (i == ZV - BEGV) | |
1215 { | |
1216 if (auto_help) | |
1217 Fminibuffer_completion_help (); | |
1218 return Qnil; | |
1219 } | |
1220 | |
1221 /* Otherwise insert in minibuffer the chars we got */ | |
1222 | |
1223 Ferase_buffer (); | |
1224 insert_from_string (completion, 0, i); | |
1225 return Qt; | |
1226 } | |
1227 | |
1228 DEFUN ("display-completion-list", Fdisplay_completion_list, Sdisplay_completion_list, | |
1229 1, 1, 0, | |
736
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1230 "Display the list of completions, COMPLETIONS, using `standard-output'.\n\ |
284 | 1231 Each element may be just a symbol or string\n\ |
1232 or may be a list of two strings to be printed as if concatenated.") | |
1233 (completions) | |
1234 Lisp_Object completions; | |
1235 { | |
1236 register Lisp_Object tail, elt; | |
1237 register int i; | |
736
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1238 int column = 0; |
284 | 1239 /* No GCPRO needed, since (when it matters) every variable |
1240 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
|
1241 struct buffer *old = current_buffer; |
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1242 if (XTYPE (Vstandard_output) == Lisp_Buffer) |
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1243 set_buffer_internal (XBUFFER (Vstandard_output)); |
284 | 1244 |
488 | 1245 if (NILP (completions)) |
736
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1246 write_string ("There are no possible completions of what you have typed.", -1); |
284 | 1247 else |
1248 { | |
736
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1249 write_string ("Possible completions are:", -1); |
488 | 1250 for (tail = completions, i = 0; !NILP (tail); tail = Fcdr (tail), i++) |
284 | 1251 { |
1252 /* this needs fixing for the case of long completions | |
1253 and/or narrow windows */ | |
1254 /* Sadly, the window it will appear in is not known | |
1255 until after the text has been made. */ | |
1256 if (i & 1) | |
736
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1257 { |
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1258 if (XTYPE (Vstandard_output) == Lisp_Buffer) |
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1259 Findent_to (make_number (35), make_number (1)); |
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1260 else |
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 do |
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 write_string (" ", -1); |
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1265 column++; |
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 while (column < 35); |
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1268 } |
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1269 } |
284 | 1270 else |
736
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1271 { |
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1272 Fterpri (Qnil); |
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1273 column = 0; |
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1274 } |
284 | 1275 elt = Fcar (tail); |
1276 if (CONSP (elt)) | |
1277 { | |
736
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1278 if (XTYPE (Vstandard_output) != Lisp_Buffer) |
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1279 { |
737 | 1280 Lisp_Object tem; |
736
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1281 tem = Flength (Fcar (elt)); |
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1282 column += XINT (tem); |
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1283 tem = Flength (Fcar (Fcdr (elt))); |
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1284 column += XINT (tem); |
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1285 } |
284 | 1286 Fprinc (Fcar (elt), Qnil); |
1287 Fprinc (Fcar (Fcdr (elt)), Qnil); | |
1288 } | |
1289 else | |
736
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1290 { |
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1291 if (XTYPE (Vstandard_output) != Lisp_Buffer) |
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1292 { |
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1293 Lisp_Object tem; |
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1294 tem = Flength (elt, Qt); |
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1295 column += XINT (tem); |
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 Fprinc (elt, Qnil); |
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1298 } |
284 | 1299 } |
1300 } | |
736
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1301 |
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1302 if (XTYPE (Vstandard_output) == Lisp_Buffer) |
18b892513cb7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
1303 set_buffer_internal (old); |
284 | 1304 return Qnil; |
1305 } | |
1306 | |
1307 DEFUN ("minibuffer-completion-help", Fminibuffer_completion_help, Sminibuffer_completion_help, | |
1308 0, 0, "", | |
1309 "Display a list of possible completions of the current minibuffer contents.") | |
1310 () | |
1311 { | |
1312 Lisp_Object completions; | |
1313 | |
1314 message ("Making completion list..."); | |
1315 completions = Fall_completions (Fbuffer_string (), | |
1316 Vminibuffer_completion_table, | |
1317 Vminibuffer_completion_predicate); | |
1318 echo_area_glyphs = 0; | |
1319 | |
488 | 1320 if (NILP (completions)) |
284 | 1321 { |
1322 bitch_at_user (); | |
1323 temp_echo_area_glyphs (" [No completions]"); | |
1324 } | |
1325 else | |
1326 internal_with_output_to_temp_buffer ("*Completions*", | |
1327 Fdisplay_completion_list, | |
1328 Fsort (completions, Qstring_lessp)); | |
1329 return Qnil; | |
1330 } | |
1331 | |
1332 DEFUN ("self-insert-and-exit", Fself_insert_and_exit, Sself_insert_and_exit, 0, 0, "", | |
1333 "Terminate minibuffer input.") | |
1334 () | |
1335 { | |
1336 if (XTYPE (last_command_char) == Lisp_Int) | |
1337 internal_self_insert (last_command_char, 0); | |
1338 else | |
1339 bitch_at_user (); | |
1340 | |
1341 Fthrow (Qexit, Qnil); | |
1342 } | |
1343 | |
1344 DEFUN ("exit-minibuffer", Fexit_minibuffer, Sexit_minibuffer, 0, 0, "", | |
1345 "Terminate this minibuffer argument.") | |
1346 () | |
1347 { | |
1348 Fthrow (Qexit, Qnil); | |
1349 } | |
1350 | |
1351 DEFUN ("minibuffer-depth", Fminibuffer_depth, Sminibuffer_depth, 0, 0, 0, | |
1352 "Return current depth of activations of minibuffer, a nonnegative integer.") | |
1353 () | |
1354 { | |
1355 return make_number (minibuf_level); | |
1356 } | |
1357 | |
1358 | |
1359 init_minibuf_once () | |
1360 { | |
1361 Vminibuffer_list = Qnil; | |
1362 staticpro (&Vminibuffer_list); | |
1363 } | |
1364 | |
1365 syms_of_minibuf () | |
1366 { | |
1367 minibuf_level = 0; | |
1368 minibuf_prompt = 0; | |
1369 minibuf_save_vector_size = 5; | |
1370 minibuf_save_vector = (struct minibuf_save_data *) malloc (5 * sizeof (struct minibuf_save_data)); | |
1371 | |
1372 Qminibuffer_completion_table = intern ("minibuffer-completion-table"); | |
1373 staticpro (&Qminibuffer_completion_table); | |
1374 | |
1375 Qminibuffer_completion_confirm = intern ("minibuffer-completion-confirm"); | |
1376 staticpro (&Qminibuffer_completion_confirm); | |
1377 | |
1378 Qminibuffer_completion_predicate = intern ("minibuffer-completion-predicate"); | |
1379 staticpro (&Qminibuffer_completion_predicate); | |
1380 | |
1381 staticpro (&last_minibuf_string); | |
1382 last_minibuf_string = Qnil; | |
1383 | |
1384 Quser_variable_p = intern ("user-variable-p"); | |
1385 staticpro (&Quser_variable_p); | |
1386 | |
864
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
1387 Qminibuffer_history = intern ("minibuffer-history"); |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
1388 staticpro (&Qminibuffer_history); |
284 | 1389 |
1390 DEFVAR_BOOL ("completion-auto-help", &auto_help, | |
1391 "*Non-nil means automatically provide help for invalid completion input."); | |
1392 auto_help = 1; | |
1393 | |
1394 DEFVAR_BOOL ("completion-ignore-case", &completion_ignore_case, | |
1395 "Non-nil means don't consider case significant in completion."); | |
1396 completion_ignore_case = 0; | |
1397 | |
1398 DEFVAR_BOOL ("enable-recursive-minibuffers", &enable_recursive_minibuffers, | |
1399 "*Non-nil means to allow minibuffer commands while in the minibuffer.\n\ | |
1400 More precisely, this variable makes a difference when the minibuffer window\n\ | |
1401 is the selected window. If you are in some other window, minibuffer commands\n\ | |
1402 are allowed even if a minibuffer is active."); | |
1403 enable_recursive_minibuffers = 0; | |
1404 | |
1405 DEFVAR_LISP ("minibuffer-completion-table", &Vminibuffer_completion_table, | |
1406 "Alist or obarray used for completion in the minibuffer.\n\ | |
1407 This becomes the ALIST argument to `try-completion' and `all-completion'.\n\ | |
1408 \n\ | |
1409 The value may alternatively be a function, which is given three arguments:\n\ | |
1410 STRING, the current buffer contents;\n\ | |
1411 PREDICATE, the predicate for filtering possible matches;\n\ | |
1412 CODE, which says what kind of things to do.\n\ | |
1413 CODE can be nil, t or `lambda'.\n\ | |
1414 nil means to return the best completion of STRING, or nil if there is none.\n\ | |
1415 t means to return a list of all possible completions of STRING.\n\ | |
1416 `lambda' means to return t if STRING is a valid completion as it stands."); | |
1417 Vminibuffer_completion_table = Qnil; | |
1418 | |
1419 DEFVAR_LISP ("minibuffer-completion-predicate", &Vminibuffer_completion_predicate, | |
1420 "Within call to `completing-read', this holds the PREDICATE argument."); | |
1421 Vminibuffer_completion_predicate = Qnil; | |
1422 | |
1423 DEFVAR_LISP ("minibuffer-completion-confirm", &Vminibuffer_completion_confirm, | |
1424 "Non-nil => demand confirmation of completion before exiting minibuffer."); | |
1425 Vminibuffer_completion_confirm = Qnil; | |
1426 | |
1427 DEFVAR_LISP ("minibuffer-help-form", &Vminibuffer_help_form, | |
1428 "Value that `help-form' takes on inside the minibuffer."); | |
1429 Vminibuffer_help_form = Qnil; | |
1430 | |
864
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
1431 DEFVAR_LISP ("minibuffer-history-variable", &Vminibuffer_history_variable, |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
1432 "History list symbol to add minibuffer values to.\n\ |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
1433 Each minibuffer output is added with\n\ |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
1434 (set minibuffer-history-variable\n\ |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
1435 (cons STRING (symbol-value minibuffer-history-variable)))"); |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
1436 XFASTINT (Vminibuffer_history_variable) = 0; |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
1437 |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
1438 DEFVAR_LISP ("minibuffer-history-position", &Vminibuffer_history_position, |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
1439 "Current position of redoing in the history list."); |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
1440 Vminibuffer_history_position = Qnil; |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
765
diff
changeset
|
1441 |
284 | 1442 defsubr (&Sread_from_minibuffer); |
1443 defsubr (&Seval_minibuffer); | |
1444 defsubr (&Sread_minibuffer); | |
1445 defsubr (&Sread_string); | |
1446 defsubr (&Sread_command); | |
1447 defsubr (&Sread_variable); | |
1448 defsubr (&Sread_buffer); | |
1449 defsubr (&Sread_no_blanks_input); | |
1450 defsubr (&Sminibuffer_depth); | |
1451 | |
1452 defsubr (&Stry_completion); | |
1453 defsubr (&Sall_completions); | |
1454 defsubr (&Scompleting_read); | |
1455 defsubr (&Sminibuffer_complete); | |
1456 defsubr (&Sminibuffer_complete_word); | |
1457 defsubr (&Sminibuffer_complete_and_exit); | |
1458 defsubr (&Sdisplay_completion_list); | |
1459 defsubr (&Sminibuffer_completion_help); | |
1460 | |
1461 defsubr (&Sself_insert_and_exit); | |
1462 defsubr (&Sexit_minibuffer); | |
1463 | |
1464 } | |
1465 | |
1466 keys_of_minibuf () | |
1467 { | |
1468 initial_define_key (Vminibuffer_local_map, Ctl ('g'), | |
1469 "abort-recursive-edit"); | |
1470 initial_define_key (Vminibuffer_local_map, Ctl ('m'), | |
1471 "exit-minibuffer"); | |
1472 initial_define_key (Vminibuffer_local_map, Ctl ('j'), | |
1473 "exit-minibuffer"); | |
1474 | |
1475 initial_define_key (Vminibuffer_local_ns_map, Ctl ('g'), | |
1476 "abort-recursive-edit"); | |
1477 initial_define_key (Vminibuffer_local_ns_map, Ctl ('m'), | |
1478 "exit-minibuffer"); | |
1479 initial_define_key (Vminibuffer_local_ns_map, Ctl ('j'), | |
1480 "exit-minibuffer"); | |
1481 | |
1482 initial_define_key (Vminibuffer_local_ns_map, ' ', | |
1483 "exit-minibuffer"); | |
1484 initial_define_key (Vminibuffer_local_ns_map, '\t', | |
1485 "exit-minibuffer"); | |
1486 initial_define_key (Vminibuffer_local_ns_map, '?', | |
1487 "self-insert-and-exit"); | |
1488 | |
1489 initial_define_key (Vminibuffer_local_completion_map, Ctl ('g'), | |
1490 "abort-recursive-edit"); | |
1491 initial_define_key (Vminibuffer_local_completion_map, Ctl ('m'), | |
1492 "exit-minibuffer"); | |
1493 initial_define_key (Vminibuffer_local_completion_map, Ctl ('j'), | |
1494 "exit-minibuffer"); | |
1495 | |
1496 initial_define_key (Vminibuffer_local_completion_map, '\t', | |
1497 "minibuffer-complete"); | |
1498 initial_define_key (Vminibuffer_local_completion_map, ' ', | |
1499 "minibuffer-complete-word"); | |
1500 initial_define_key (Vminibuffer_local_completion_map, '?', | |
1501 "minibuffer-completion-help"); | |
1502 | |
1503 initial_define_key (Vminibuffer_local_must_match_map, Ctl ('g'), | |
1504 "abort-recursive-edit"); | |
1505 initial_define_key (Vminibuffer_local_must_match_map, Ctl ('m'), | |
1506 "minibuffer-complete-and-exit"); | |
1507 initial_define_key (Vminibuffer_local_must_match_map, Ctl ('j'), | |
1508 "minibuffer-complete-and-exit"); | |
1509 initial_define_key (Vminibuffer_local_must_match_map, '\t', | |
1510 "minibuffer-complete"); | |
1511 initial_define_key (Vminibuffer_local_must_match_map, ' ', | |
1512 "minibuffer-complete-word"); | |
1513 initial_define_key (Vminibuffer_local_must_match_map, '?', | |
1514 "minibuffer-completion-help"); | |
1515 } |