comparison src/minibuf.c @ 864:fe5f6b7c9727

*** empty log message ***
author Richard M. Stallman <rms@gnu.org>
date Fri, 24 Jul 1992 08:17:31 +0000
parents e4093444f9f8
children ae5c412a32ec
comparison
equal deleted inserted replaced
863:427299469901 864:fe5f6b7c9727
39 { 39 {
40 char *prompt; 40 char *prompt;
41 int prompt_width; 41 int prompt_width;
42 Lisp_Object help_form; 42 Lisp_Object help_form;
43 Lisp_Object current_prefix_arg; 43 Lisp_Object current_prefix_arg;
44 Lisp_Object history_position;
45 Lisp_Object history_variable;
44 }; 46 };
45 47
46 int minibuf_save_vector_size; 48 int minibuf_save_vector_size;
47 struct minibuf_save_data *minibuf_save_vector; 49 struct minibuf_save_data *minibuf_save_vector;
48 50
61 63
62 /* help-form is bound to this while in the minibuffer. */ 64 /* help-form is bound to this while in the minibuffer. */
63 65
64 Lisp_Object Vminibuffer_help_form; 66 Lisp_Object Vminibuffer_help_form;
65 67
68 /* Variable which is the history list to add minibuffer values to. */
69
70 Lisp_Object Vminibuffer_history_variable;
71
72 /* Current position in the history list (adjusted by M-n and M-p). */
73
74 Lisp_Object Vminibuffer_history_position;
75
76 Lisp_Object Qminibuffer_history;
77
66 /* Nonzero means completion ignores case. */ 78 /* Nonzero means completion ignores case. */
67 79
68 int completion_ignore_case; 80 int completion_ignore_case;
69 81
70 /* If last completion attempt reported "Complete but not unique" 82 /* If last completion attempt reported "Complete but not unique"
79 91
80 void read_minibuf_unwind (); 92 void read_minibuf_unwind ();
81 Lisp_Object get_minibuffer (); 93 Lisp_Object get_minibuffer ();
82 Lisp_Object read_minibuf (); 94 Lisp_Object read_minibuf ();
83 95
96 /* Read from the minibuffer using keymap MAP, initial contents INITIAL
97 (a string), putting point BACKUP_N chars from the end of INITIAL,
98 prompting with PROMPT (a string), using history list HISTVAR
99 with initial position HISTPOS.
100
101 Normally return the result as a string (the text that was read),
102 but if EXPFLAG is non-nil, read it and return the object read. */
103
84 Lisp_Object 104 Lisp_Object
85 read_minibuf (map, initial, prompt, backup_n, expflag) 105 read_minibuf (map, initial, prompt, backup_n, expflag, histvar, histpos)
86 Lisp_Object map; 106 Lisp_Object map;
87 Lisp_Object initial; 107 Lisp_Object initial;
88 Lisp_Object prompt; 108 Lisp_Object prompt;
89 Lisp_Object backup_n; 109 Lisp_Object backup_n;
90 int expflag; 110 int expflag;
111 Lisp_Object histvar;
112 Lisp_Object histpos;
91 { 113 {
92 register Lisp_Object val; 114 register Lisp_Object val;
93 int count = specpdl_ptr - specpdl; 115 int count = specpdl_ptr - specpdl;
94 Lisp_Object mini_frame = WINDOW_FRAME (XWINDOW (minibuf_window)); 116 Lisp_Object mini_frame = WINDOW_FRAME (XWINDOW (minibuf_window));
95 struct gcpro gcpro1, gcpro2; 117 struct gcpro gcpro1, gcpro2;
119 minibuf_save_vector[minibuf_level].prompt_width = minibuf_prompt_width; 141 minibuf_save_vector[minibuf_level].prompt_width = minibuf_prompt_width;
120 minibuf_prompt_width = 0; 142 minibuf_prompt_width = 0;
121 /* >> Why is this done this way rather than binding these variables? */ 143 /* >> Why is this done this way rather than binding these variables? */
122 minibuf_save_vector[minibuf_level].help_form = Vhelp_form; 144 minibuf_save_vector[minibuf_level].help_form = Vhelp_form;
123 minibuf_save_vector[minibuf_level].current_prefix_arg = Vcurrent_prefix_arg; 145 minibuf_save_vector[minibuf_level].current_prefix_arg = Vcurrent_prefix_arg;
146 minibuf_save_vector[minibuf_level].history_position = Vminibuffer_history_position;
147 minibuf_save_vector[minibuf_level].history_variable = Vminibuffer_history_variable;
124 GCPRO2 (minibuf_save_vector[minibuf_level].help_form, 148 GCPRO2 (minibuf_save_vector[minibuf_level].help_form,
125 minibuf_save_vector[minibuf_level].current_prefix_arg); 149 minibuf_save_vector[minibuf_level].current_prefix_arg);
126 150
127 record_unwind_protect (Fset_window_configuration, 151 record_unwind_protect (Fset_window_configuration,
128 Fcurrent_window_configuration (Qnil)); 152 Fcurrent_window_configuration (Qnil));
178 bcopy (XSTRING (prompt)->data, minibuf_prompt, XSTRING (prompt)->size + 1); 202 bcopy (XSTRING (prompt)->data, minibuf_prompt, XSTRING (prompt)->size + 1);
179 echo_area_glyphs = 0; 203 echo_area_glyphs = 0;
180 204
181 Vhelp_form = Vminibuffer_help_form; 205 Vhelp_form = Vminibuffer_help_form;
182 current_buffer->keymap = map; 206 current_buffer->keymap = map;
207 Vminibuffer_history_position = histpos;
208 Vminibuffer_history_variable = histvar;
183 209
184 /* ??? MCC did redraw_screen here if switching screens. */ 210 /* ??? MCC did redraw_screen here if switching screens. */
185 recursive_edit_1 (); 211 recursive_edit_1 ();
186 212
187 /* If cursor is on the minibuffer line, 213 /* If cursor is on the minibuffer line,
195 } 221 }
196 222
197 /* Make minibuffer contents into a string */ 223 /* Make minibuffer contents into a string */
198 val = make_buffer_string (1, Z); 224 val = make_buffer_string (1, Z);
199 bcopy (GAP_END_ADDR, XSTRING (val)->data + GPT - BEG, Z - GPT); 225 bcopy (GAP_END_ADDR, XSTRING (val)->data + GPT - BEG, Z - GPT);
226
227 /* Add the value to the appropriate history list. */
228 if (XTYPE (Vminibuffer_history_variable) == Lisp_Symbol
229 && XSYMBOL (Vminibuffer_history_variable)->value != Qunbound)
230 Fset (Vminibuffer_history_variable,
231 Fcons (val, Fsymbol_value (Vminibuffer_history_variable)));
232
200 unbind_to (count, Qnil); /* The appropriate frame will get selected 233 unbind_to (count, Qnil); /* The appropriate frame will get selected
201 in set-window-configuration. */ 234 in set-window-configuration. */
202 235
203 UNGCPRO; 236 UNGCPRO;
204 237
205 /* VAL is the string of minibuffer text. */ 238 /* VAL is the string of minibuffer text. */
206
207 last_minibuf_string = val; 239 last_minibuf_string = val;
208 240
209 /* If Lisp form desired instead of string, parse it */ 241 /* If Lisp form desired instead of string, parse it */
210 if (expflag) 242 if (expflag)
211 val = Fread (val); 243 val = Fread (val);
268 /* Restore prompt from outer minibuffer */ 300 /* Restore prompt from outer minibuffer */
269 minibuf_prompt = minibuf_save_vector[minibuf_level].prompt; 301 minibuf_prompt = minibuf_save_vector[minibuf_level].prompt;
270 minibuf_prompt_width = minibuf_save_vector[minibuf_level].prompt_width; 302 minibuf_prompt_width = minibuf_save_vector[minibuf_level].prompt_width;
271 Vhelp_form = minibuf_save_vector[minibuf_level].help_form; 303 Vhelp_form = minibuf_save_vector[minibuf_level].help_form;
272 Vcurrent_prefix_arg = minibuf_save_vector[minibuf_level].current_prefix_arg; 304 Vcurrent_prefix_arg = minibuf_save_vector[minibuf_level].current_prefix_arg;
305 Vminibuffer_history_position
306 = minibuf_save_vector[minibuf_level].history_position;
307 Vminibuffer_history_variable
308 = minibuf_save_vector[minibuf_level].history_variable;
273 309
274 #ifdef MULTI_FRAME 310 #ifdef MULTI_FRAME
275 /* Redirect the focus of the frame that called the minibuffer. */ 311 /* Redirect the focus of the frame that called the minibuffer. */
276 if (CONSP (data)) 312 if (CONSP (data))
277 Fredirect_frame_focus (XCONS (data)->car, XCONS (data)->cdr); 313 Fredirect_frame_focus (XCONS (data)->car, XCONS (data)->cdr);
280 316
281 DEFUN ("read-from-minibuffer", Fread_from_minibuffer, Sread_from_minibuffer, 1, 5, 0, 317 DEFUN ("read-from-minibuffer", Fread_from_minibuffer, Sread_from_minibuffer, 1, 5, 0,
282 "Read a string from the minibuffer, prompting with string PROMPT.\n\ 318 "Read a string from the minibuffer, prompting with string PROMPT.\n\
283 If optional second arg INITIAL-CONTENTS is non-nil, it is a string\n\ 319 If optional second arg INITIAL-CONTENTS is non-nil, it is a string\n\
284 to be inserted into the minibuffer before reading input.\n\ 320 to be inserted into the minibuffer before reading input.\n\
321 If INITIAL-CONTENTS is (STRING . POSITION), the initial input\n\
322 is STRING, but point is placed POSITION characters into the string.\n\
285 Third arg KEYMAP is a keymap to use whilst reading;\n\ 323 Third arg KEYMAP is a keymap to use whilst reading;\n\
286 if omitted or nil, the default is `minibuffer-local-map'.\n\ 324 if omitted or nil, the default is `minibuffer-local-map'.\n\
287 If fourth arg READ is non-nil, then interpret the result as a lisp object\n\ 325 If fourth arg READ is non-nil, then interpret the result as a lisp object\n\
288 and return that object:\n\ 326 and return that object:\n\
289 in other words, do `(car (read-from-string INPUT-STRING))'\n\ 327 in other words, do `(car (read-from-string INPUT-STRING))'\n\
290 Fifth arg POSITION, if non-nil, is where to put point\n\ 328 Fifth arg HIST, if non-nil, specifies a history list\n\
291 in the minibuffer after inserting INITIAL-CONTENTS.") 329 and optionally the initial position in the list.\n\
292 (prompt, initial_input, keymap, read, position) 330 It can be a symbol, which is the history list variable to use,\n\
293 Lisp_Object prompt, initial_input, keymap, read, position; 331 or it can be a cons cell (HISTVAR . HISTPOS).\n\
332 In that case, HISTVAR is the history list variable to use,\n\
333 and HISTPOS is the initial position (the position in the list\n\
334 which INITIAL-CONTENTS corresponds to).\n\
335 Positions are counted starting from 1 at the beginning of the list.")
336 (prompt, initial_input, keymap, read, hist)
337 Lisp_Object prompt, initial_input, keymap, read, hist;
294 { 338 {
295 int pos = 0; 339 int pos = 0;
340 Lisp_Object histvar, histpos, position;
341 position = Qnil;
296 342
297 CHECK_STRING (prompt, 0); 343 CHECK_STRING (prompt, 0);
298 if (!NILP (initial_input)) 344 if (!NILP (initial_input))
299 { 345 {
346 if (XTYPE (initial_input) == Lisp_Cons)
347 {
348 position = Fcdr (initial_input);
349 initial_input = Fcar (initial_input);
350 }
300 CHECK_STRING (initial_input, 1); 351 CHECK_STRING (initial_input, 1);
301 if (!NILP (position)) 352 if (!NILP (position))
302 { 353 {
303 CHECK_NUMBER (position, 0); 354 CHECK_NUMBER (position, 0);
304 /* Convert to distance from end of input. */ 355 /* Convert to distance from end of input. */
308 359
309 if (NILP (keymap)) 360 if (NILP (keymap))
310 keymap = Vminibuffer_local_map; 361 keymap = Vminibuffer_local_map;
311 else 362 else
312 keymap = get_keymap (keymap,2); 363 keymap = get_keymap (keymap,2);
364
365 if (XTYPE (hist) == Lisp_Symbol)
366 {
367 histvar = hist;
368 histpos = Qnil;
369 }
370 else
371 {
372 histvar = Fcar_safe (hist);
373 histpos = Fcdr_safe (hist);
374 }
375 if (NILP (histvar))
376 histvar = Qminibuffer_history;
377 if (NILP (histpos))
378 XFASTINT (histpos) = 0;
379
313 return read_minibuf (keymap, initial_input, prompt, 380 return read_minibuf (keymap, initial_input, prompt,
314 pos, !NILP (read)); 381 pos, !NILP (read), histvar, histpos);
315 } 382 }
316 383
317 DEFUN ("read-minibuffer", Fread_minibuffer, Sread_minibuffer, 1, 2, 0, 384 DEFUN ("read-minibuffer", Fread_minibuffer, Sread_minibuffer, 1, 2, 0,
318 "Return a Lisp object read using the minibuffer.\n\ 385 "Return a Lisp object read using the minibuffer.\n\
319 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS\n\ 386 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS\n\
322 Lisp_Object prompt, initial_contents; 389 Lisp_Object prompt, initial_contents;
323 { 390 {
324 CHECK_STRING (prompt, 0); 391 CHECK_STRING (prompt, 0);
325 if (!NILP (initial_contents)) 392 if (!NILP (initial_contents))
326 CHECK_STRING (initial_contents, 1) 393 CHECK_STRING (initial_contents, 1)
327 return read_minibuf (Vminibuffer_local_map, initial_contents, prompt, Qnil, 1); 394 return read_minibuf (Vminibuffer_local_map, initial_contents,
395 prompt, Qnil, 1, Qminibuffer_history, make_number (0));
328 } 396 }
329 397
330 DEFUN ("eval-minibuffer", Feval_minibuffer, Seval_minibuffer, 1, 2, 0, 398 DEFUN ("eval-minibuffer", Feval_minibuffer, Seval_minibuffer, 1, 2, 0,
331 "Return value of Lisp expression read using the minibuffer.\n\ 399 "Return value of Lisp expression read using the minibuffer.\n\
332 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS\n\ 400 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS\n\
356 { 424 {
357 CHECK_STRING (prompt, 0); 425 CHECK_STRING (prompt, 0);
358 if (! NILP (init)) 426 if (! NILP (init))
359 CHECK_STRING (init, 1); 427 CHECK_STRING (init, 1);
360 428
361 return read_minibuf (Vminibuffer_local_ns_map, init, prompt, Qnil, 0); 429 return read_minibuf (Vminibuffer_local_ns_map, init, prompt, Qnil, 0,
430 Qminibuffer_history, make_number (0));
362 } 431 }
363 432
364 DEFUN ("read-command", Fread_command, Sread_command, 1, 1, 0, 433 DEFUN ("read-command", Fread_command, Sread_command, 1, 1, 0,
365 "One arg PROMPT, a string. Read the name of a command and return as a symbol.\n\ 434 "One arg PROMPT, a string. Read the name of a command and return as a symbol.\n\
366 Prompts with PROMPT.") 435 Prompts with PROMPT.")
730 Lisp_Object Vminibuffer_completion_predicate, Qminibuffer_completion_predicate; 799 Lisp_Object Vminibuffer_completion_predicate, Qminibuffer_completion_predicate;
731 Lisp_Object Vminibuffer_completion_confirm, Qminibuffer_completion_confirm; 800 Lisp_Object Vminibuffer_completion_confirm, Qminibuffer_completion_confirm;
732 801
733 DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 6, 0, 802 DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 6, 0,
734 "Read a string in the minibuffer, with completion.\n\ 803 "Read a string in the minibuffer, with completion.\n\
735 Args: PROMPT, TABLE, PREDICATE, REQUIRE-MATCH, INITIAL-INPUT, BACKUP-N.\n\ 804 Args: PROMPT, TABLE, PREDICATE, REQUIRE-MATCH, INITIAL-INPUT, HIST.\n\
736 PROMPT is a string to prompt with; normally it ends in a colon and a space.\n\ 805 PROMPT is a string to prompt with; normally it ends in a colon and a space.\n\
737 TABLE is an alist whose elements' cars are strings, or an obarray.\n\ 806 TABLE is an alist whose elements' cars are strings, or an obarray.\n\
738 PREDICATE limits completion to a subset of TABLE.\n\ 807 PREDICATE limits completion to a subset of TABLE.\n\
739 See `try-completion' for more details on completion, TABLE, and PREDICATE.\n\ 808 See `try-completion' for more details on completion, TABLE, and PREDICATE.\n\
740 If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless\n\ 809 If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless\n\
741 the input is (or completes to) an element of TABLE.\n\ 810 the input is (or completes to) an element of TABLE.\n\
742 If it is also not t, Return does not exit if it does non-null completion.\n\ 811 If it is also not t, Return does not exit if it does non-null completion.\n\
743 If INITIAL-INPUT is non-nil, insert it in the minibuffer initially.\n\ 812 If INITIAL-INPUT is non-nil, insert it in the minibuffer initially.\n\
744 Case is ignored if ambient value of `completion-ignore-case' is non-nil.\n\ 813 If it is (STRING . POSITION), the initial input\n\
745 If BACKUP-N is specified, point should be placed that many spaces from\n\ 814 is STRING, but point is placed POSITION characters into the string.\n\
746 the end of the buffer. This is useful when providing default values,\n\ 815 HIST, if non-nil, specifies a history list\n\
747 because you can put point before the last component of a filename or any\n\ 816 and optionally the initial position in the list.\n\
748 other component that is likely to be deleted.") 817 It can be a symbol, which is the history list variable to use,\n\
749 (prompt, table, pred, require_match, init, backup_n) 818 or it can be a cons cell (HISTVAR . HISTPOS).\n\
750 Lisp_Object prompt, table, pred, require_match, init, backup_n; 819 In that case, HISTVAR is the history list variable to use,\n\
751 { 820 and HISTPOS is the initial position (the position in the list\n\
752 Lisp_Object val; 821 which INITIAL-CONTENTS corresponds to).\n\
822 Positions are counted starting from 1 at the beginning of the list.\n\
823 Completion ignores case if the ambient value of\n\
824 `completion-ignore-case' is non-nil.")
825 (prompt, table, pred, require_match, init, hist)
826 Lisp_Object prompt, table, pred, require_match, init, hist;
827 {
828 Lisp_Object val, histvar, histpos, position;
829 int pos = 0;
753 int count = specpdl_ptr - specpdl; 830 int count = specpdl_ptr - specpdl;
754 specbind (Qminibuffer_completion_table, table); 831 specbind (Qminibuffer_completion_table, table);
755 specbind (Qminibuffer_completion_predicate, pred); 832 specbind (Qminibuffer_completion_predicate, pred);
756 specbind (Qminibuffer_completion_confirm, 833 specbind (Qminibuffer_completion_confirm,
757 EQ (require_match, Qt) ? Qnil : Qt); 834 EQ (require_match, Qt) ? Qnil : Qt);
758 last_exact_completion = Qnil; 835 last_exact_completion = Qnil;
836
837 position = Qnil;
838 if (!NILP (init))
839 {
840 if (XTYPE (init) == Lisp_Cons)
841 {
842 position = Fcdr (init);
843 init = Fcar (init);
844 }
845 CHECK_STRING (init, 0);
846 if (!NILP (position))
847 {
848 CHECK_NUMBER (position, 0);
849 /* Convert to distance from end of input. */
850 pos = XINT (position) - 1 - XSTRING (init)->size;
851 }
852 }
853
854 if (XTYPE (hist) == Lisp_Symbol)
855 {
856 histvar = hist;
857 histpos = Qnil;
858 }
859 else
860 {
861 histvar = Fcar_safe (hist);
862 histpos = Fcdr_safe (hist);
863 }
864 if (NILP (histvar))
865 histvar = Qminibuffer_history;
866 if (NILP (histpos))
867 XFASTINT (histpos) = 0;
868
759 val = read_minibuf (NILP (require_match) 869 val = read_minibuf (NILP (require_match)
760 ? Vminibuffer_local_completion_map 870 ? Vminibuffer_local_completion_map
761 : Vminibuffer_local_must_match_map, 871 : Vminibuffer_local_must_match_map,
762 init, prompt, backup_n, 0); 872 init, prompt, pos, 0,
873 histvar, histpos);
763 return unbind_to (count, val); 874 return unbind_to (count, val);
764 } 875 }
765 876
766 /* Temporarily display the string M at the end of the current 877 /* Temporarily display the string M at the end of the current
767 minibuffer contents. This is used to display things like 878 minibuffer contents. This is used to display things like
1250 last_minibuf_string = Qnil; 1361 last_minibuf_string = Qnil;
1251 1362
1252 Quser_variable_p = intern ("user-variable-p"); 1363 Quser_variable_p = intern ("user-variable-p");
1253 staticpro (&Quser_variable_p); 1364 staticpro (&Quser_variable_p);
1254 1365
1255 1366 Qminibuffer_history = intern ("minibuffer-history");
1367 staticpro (&Qminibuffer_history);
1256 1368
1257 DEFVAR_BOOL ("completion-auto-help", &auto_help, 1369 DEFVAR_BOOL ("completion-auto-help", &auto_help,
1258 "*Non-nil means automatically provide help for invalid completion input."); 1370 "*Non-nil means automatically provide help for invalid completion input.");
1259 auto_help = 1; 1371 auto_help = 1;
1260 1372
1293 1405
1294 DEFVAR_LISP ("minibuffer-help-form", &Vminibuffer_help_form, 1406 DEFVAR_LISP ("minibuffer-help-form", &Vminibuffer_help_form,
1295 "Value that `help-form' takes on inside the minibuffer."); 1407 "Value that `help-form' takes on inside the minibuffer.");
1296 Vminibuffer_help_form = Qnil; 1408 Vminibuffer_help_form = Qnil;
1297 1409
1410 DEFVAR_LISP ("minibuffer-history-variable", &Vminibuffer_history_variable,
1411 "History list symbol to add minibuffer values to.\n\
1412 Each minibuffer output is added with\n\
1413 (set minibuffer-history-variable\n\
1414 (cons STRING (symbol-value minibuffer-history-variable)))");
1415 XFASTINT (Vminibuffer_history_variable) = 0;
1416
1417 DEFVAR_LISP ("minibuffer-history-position", &Vminibuffer_history_position,
1418 "Current position of redoing in the history list.");
1419 Vminibuffer_history_position = Qnil;
1420
1298 defsubr (&Sread_from_minibuffer); 1421 defsubr (&Sread_from_minibuffer);
1299 defsubr (&Seval_minibuffer); 1422 defsubr (&Seval_minibuffer);
1300 defsubr (&Sread_minibuffer); 1423 defsubr (&Sread_minibuffer);
1301 defsubr (&Sread_string); 1424 defsubr (&Sread_string);
1302 defsubr (&Sread_command); 1425 defsubr (&Sread_command);