aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard M. Stallman1992-07-24 08:17:31 +0000
committerRichard M. Stallman1992-07-24 08:17:31 +0000
commit770970cbad7bc867d747ad04b5d620d223ca6f40 (patch)
tree65a356b0125f8e7cbabbc07fabd0e733b9771b5a /src
parent15c65264fae0a306ac53cef41af7b1879051ce17 (diff)
downloademacs-770970cbad7bc867d747ad04b5d620d223ca6f40.tar.gz
emacs-770970cbad7bc867d747ad04b5d620d223ca6f40.zip
*** empty log message ***
Diffstat (limited to 'src')
-rw-r--r--src/minibuf.c163
1 files changed, 143 insertions, 20 deletions
diff --git a/src/minibuf.c b/src/minibuf.c
index 08abe94e789..1997f4f5cbb 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -41,6 +41,8 @@ struct minibuf_save_data
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
46int minibuf_save_vector_size; 48int minibuf_save_vector_size;
@@ -63,6 +65,16 @@ int enable_recursive_minibuffers;
63 65
64Lisp_Object Vminibuffer_help_form; 66Lisp_Object Vminibuffer_help_form;
65 67
68/* Variable which is the history list to add minibuffer values to. */
69
70Lisp_Object Vminibuffer_history_variable;
71
72/* Current position in the history list (adjusted by M-n and M-p). */
73
74Lisp_Object Vminibuffer_history_position;
75
76Lisp_Object Qminibuffer_history;
77
66/* Nonzero means completion ignores case. */ 78/* Nonzero means completion ignores case. */
67 79
68int completion_ignore_case; 80int completion_ignore_case;
@@ -81,13 +93,23 @@ void read_minibuf_unwind ();
81Lisp_Object get_minibuffer (); 93Lisp_Object get_minibuffer ();
82Lisp_Object read_minibuf (); 94Lisp_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
84Lisp_Object 104Lisp_Object
85read_minibuf (map, initial, prompt, backup_n, expflag) 105read_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;
@@ -121,6 +143,8 @@ read_minibuf (map, initial, prompt, backup_n, expflag)
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
@@ -180,6 +204,8 @@ read_minibuf (map, initial, prompt, backup_n, expflag)
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 ();
@@ -197,13 +223,19 @@ read_minibuf (map, initial, prompt, backup_n, expflag)
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 */
@@ -270,6 +302,10 @@ read_minibuf_unwind (data)
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. */
@@ -282,21 +318,36 @@ DEFUN ("read-from-minibuffer", Fread_from_minibuffer, Sread_from_minibuffer, 1,
282 "Read a string from the minibuffer, prompting with string PROMPT.\n\ 318 "Read a string from the minibuffer, prompting with string PROMPT.\n\
283If optional second arg INITIAL-CONTENTS is non-nil, it is a string\n\ 319If 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\
285Third arg KEYMAP is a keymap to use whilst reading;\n\ 323Third 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\
287If fourth arg READ is non-nil, then interpret the result as a lisp object\n\ 325If 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\
290Fifth arg POSITION, if non-nil, is where to put point\n\ 328Fifth 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 {
@@ -310,8 +361,24 @@ Fifth arg POSITION, if non-nil, is where to put point\n\
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
317DEFUN ("read-minibuffer", Fread_minibuffer, Sread_minibuffer, 1, 2, 0, 384DEFUN ("read-minibuffer", Fread_minibuffer, Sread_minibuffer, 1, 2, 0,
@@ -324,7 +391,8 @@ is a string to insert in the minibuffer before reading.")
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
330DEFUN ("eval-minibuffer", Feval_minibuffer, Seval_minibuffer, 1, 2, 0, 398DEFUN ("eval-minibuffer", Feval_minibuffer, Seval_minibuffer, 1, 2, 0,
@@ -358,7 +426,8 @@ Prompt with PROMPT, and provide INIT as an initial value of the input string.")
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
364DEFUN ("read-command", Fread_command, Sread_command, 1, 1, 0, 433DEFUN ("read-command", Fread_command, Sread_command, 1, 1, 0,
@@ -732,7 +801,7 @@ Lisp_Object Vminibuffer_completion_confirm, Qminibuffer_completion_confirm;
732 801
733DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 6, 0, 802DEFUN ("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\
735Args: PROMPT, TABLE, PREDICATE, REQUIRE-MATCH, INITIAL-INPUT, BACKUP-N.\n\ 804Args: PROMPT, TABLE, PREDICATE, REQUIRE-MATCH, INITIAL-INPUT, HIST.\n\
736PROMPT is a string to prompt with; normally it ends in a colon and a space.\n\ 805PROMPT is a string to prompt with; normally it ends in a colon and a space.\n\
737TABLE is an alist whose elements' cars are strings, or an obarray.\n\ 806TABLE is an alist whose elements' cars are strings, or an obarray.\n\
738PREDICATE limits completion to a subset of TABLE.\n\ 807PREDICATE limits completion to a subset of TABLE.\n\
@@ -741,25 +810,67 @@ 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\
743If INITIAL-INPUT is non-nil, insert it in the minibuffer initially.\n\ 812If INITIAL-INPUT is non-nil, insert it in the minibuffer initially.\n\
744Case is ignored if ambient value of `completion-ignore-case' is non-nil.\n\ 813 If it is (STRING . POSITION), the initial input\n\
745If 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\
746the end of the buffer. This is useful when providing default values,\n\ 815HIST, if non-nil, specifies a history list\n\
747because you can put point before the last component of a filename or any\n\ 816 and optionally the initial position in the list.\n\
748other 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\
820 and HISTPOS is the initial position (the position in the list\n\
821 which INITIAL-CONTENTS corresponds to).\n\
822 Positions are counted starting from 1 at the beginning of the list.\n\
823Completion 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;
751{ 827{
752 Lisp_Object val; 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
@@ -1252,7 +1363,8 @@ syms_of_minibuf ()
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.");
@@ -1295,6 +1407,17 @@ t means to return a list of all possible completions of STRING.\n\
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\
1412Each 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);