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