aboutsummaryrefslogtreecommitdiffstats
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
parent15c65264fae0a306ac53cef41af7b1879051ce17 (diff)
downloademacs-770970cbad7bc867d747ad04b5d620d223ca6f40.tar.gz
emacs-770970cbad7bc867d747ad04b5d620d223ca6f40.zip
*** empty log message ***
-rw-r--r--lisp/comint.el4
-rw-r--r--lisp/progmodes/compile.el39
-rw-r--r--lisp/replace.el32
-rw-r--r--lisp/simple.el6
-rw-r--r--src/minibuf.c163
5 files changed, 189 insertions, 55 deletions
diff --git a/lisp/comint.el b/lisp/comint.el
index 938b559fc30..fc8ba3103e3 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -538,8 +538,8 @@ Buffer local variable.")
538 "Searches backwards through input history for substring match." 538 "Searches backwards through input history for substring match."
539 (interactive (let* ((last-command last-command) ; preserve around r-f-m 539 (interactive (let* ((last-command last-command) ; preserve around r-f-m
540 (s (read-from-minibuffer 540 (s (read-from-minibuffer
541 (format "Command substring (default %s): " 541 (format "Command substring (default %s): "
542 comint-last-input-match)))) 542 comint-last-input-match))))
543 (list (if (string= s "") comint-last-input-match s)))) 543 (list (if (string= s "") comint-last-input-match s))))
544; (interactive "sCommand substring: ") 544; (interactive "sCommand substring: ")
545 (setq comint-last-input-match str) ; update default 545 (setq comint-last-input-match str) ; update default
diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index 4930a7875e8..888c5578dbe 100644
--- a/lisp/progmodes/compile.el
+++ b/lisp/progmodes/compile.el
@@ -139,12 +139,6 @@ You might also use mode hooks to specify it in certain modes, like this:
139 (concat \"make -k \" 139 (concat \"make -k \"
140 buffer-file-name))))))") 140 buffer-file-name))))))")
141 141
142;;;###autoload
143(defvar grep-command "grep -n "
144 "Last shell command used to do a grep search; default for next search.
145Typically \"grep -n\" or \"egrep -n\".
146\(The \"-n\" option tells grep to output line numbers.)")
147
148(defconst compilation-enter-directory-regexp 142(defconst compilation-enter-directory-regexp
149 ": Entering directory `\\(.*\\)'$" 143 ": Entering directory `\\(.*\\)'$"
150 "Regular expression for a line in the compilation log that 144 "Regular expression for a line in the compilation log that
@@ -169,6 +163,11 @@ The default value matches lines printed by the `-w' option of GNU Make.")
169\`compilation-leave-directory-regexp'. The head element is the directory 163\`compilation-leave-directory-regexp'. The head element is the directory
170the compilation was started in.") 164the compilation was started in.")
171 165
166;; History of compile commands.
167(defvar compile-history nil)
168;; History of grep commands.
169(defvar grep-history nil)
170
172;;;###autoload 171;;;###autoload
173(defun compile (command) 172(defun compile (command)
174 "Compile the program including the current buffer. Default: run `make'. 173 "Compile the program including the current buffer. Default: run `make'.
@@ -185,7 +184,9 @@ Then start the next one.
185The name used for the buffer is actually whatever is returned by 184The name used for the buffer is actually whatever is returned by
186the function in `compilation-buffer-name-function', so you can set that 185the function in `compilation-buffer-name-function', so you can set that
187to a function that generates a unique name." 186to a function that generates a unique name."
188 (interactive (list (read-string "Compile command: " compile-command))) 187 (interactive (list (read-from-minibuffer "Compile command: "
188 compile-command nil
189 '(compile-history . 1))))
189 (setq compile-command command) 190 (setq compile-command command)
190 (save-some-buffers nil nil) 191 (save-some-buffers nil nil)
191 (compile-internal compile-command "No more errors")) 192 (compile-internal compile-command "No more errors"))
@@ -196,26 +197,12 @@ to a function that generates a unique name."
196While grep runs asynchronously, you can use the \\[next-error] command 197While grep runs asynchronously, you can use the \\[next-error] command
197to find the text that grep hits refer to. 198to find the text that grep hits refer to.
198 199
199The variable `grep-command' holds the last grep command run, 200This command uses a special history list for its arguments, so you can
200and is the default for future runs. The command should use the `-n' 201easily repeat a grep command."
201flag, so that line numbers are displayed for each match.
202What the user enters in response to the prompt for grep args is
203appended to everything up to and including the `-n' in `grep-command'."
204 (interactive 202 (interactive
205 (list (read-string (concat "Run " 203 (list (read-from-minibuffer "Run grep (like this): "
206 (substring grep-command 0 204 "grep -n " nil nil 'grep-history)))
207 (string-match "[\t ]+" grep-command)) 205 (compile-internal (concat command-args " /dev/null")
208 " (with args): ")
209 (progn
210 (string-match "-n[\t ]+" grep-command)
211 (substring grep-command (match-end 0))))))
212 ;; why a redundant string-match? It might not be interactive ...
213 (setq grep-command (concat (substring grep-command 0
214 (progn
215 (string-match "-n" grep-command)
216 (match-end 0)))
217 " " command-args))
218 (compile-internal (concat grep-command " /dev/null")
219 "No more grep hits" "grep")) 206 "No more grep hits" "grep"))
220 207
221(defun compile-internal (command error-message 208(defun compile-internal (command error-message
diff --git a/lisp/replace.el b/lisp/replace.el
index 01dbeb5558a..24a4818051f 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -23,6 +23,18 @@
23(defconst case-replace t "\ 23(defconst case-replace t "\
24*Non-nil means query-replace should preserve case in replacements.") 24*Non-nil means query-replace should preserve case in replacements.")
25 25
26(defvar query-replace-history nil)
27
28(defun query-replace-read-args (string)
29 (let (from to)
30 (setq from (read-from-minibuffer (format "%s: " string)
31 nil nil nil
32 'query-replace-history))
33 (setq to (read-from-minibuffer (format "%s %s with: " string from)
34 nil nil nil
35 'query-replace-history))
36 (list from to current-prefix-arg)))
37
26(defun query-replace (from-string to-string &optional arg) 38(defun query-replace (from-string to-string &optional arg)
27 "Replace some occurrences of FROM-STRING with TO-STRING. 39 "Replace some occurrences of FROM-STRING with TO-STRING.
28As each match is found, the user must type a character saying 40As each match is found, the user must type a character saying
@@ -32,7 +44,7 @@ Preserves case in each replacement if case-replace and case-fold-search
32are non-nil and FROM-STRING has no uppercase letters. 44are non-nil and FROM-STRING has no uppercase letters.
33Third arg DELIMITED (prefix arg if interactive) non-nil means replace 45Third arg DELIMITED (prefix arg if interactive) non-nil means replace
34only matches surrounded by word boundaries." 46only matches surrounded by word boundaries."
35 (interactive "sQuery replace: \nsQuery replace %s with: \nP") 47 (interactive (query-replace-read-args "Query replace"))
36 (perform-replace from-string to-string t nil arg) 48 (perform-replace from-string to-string t nil arg)
37 (message "Done")) 49 (message "Done"))
38(define-key esc-map "%" 'query-replace) 50(define-key esc-map "%" 'query-replace)
@@ -48,7 +60,7 @@ Third arg DELIMITED (prefix arg if interactive) non-nil means replace
48only matches surrounded by word boundaries. 60only matches surrounded by word boundaries.
49In TO-STRING, \\& means insert what matched REGEXP, 61In TO-STRING, \\& means insert what matched REGEXP,
50and \\=\\<n> means insert what matched <n>th \\(...\\) in REGEXP." 62and \\=\\<n> means insert what matched <n>th \\(...\\) in REGEXP."
51 (interactive "sQuery replace regexp: \nsQuery replace regexp %s with: \nP") 63 (interactive (query-replace-read-args "Query replace regexp"))
52 (perform-replace regexp to-string t t arg) 64 (perform-replace regexp to-string t t arg)
53 (message "Done")) 65 (message "Done"))
54 66
@@ -63,7 +75,17 @@ Non-interactively, TO-STRINGS may be a list of replacement strings.
63 75
64A prefix argument N says to use each replacement string N times 76A prefix argument N says to use each replacement string N times
65before rotating to the next." 77before rotating to the next."
66 (interactive "sMap query replace (regexp): \nsQuery replace %s with (space-separated strings): \nP") 78 (interactive
79 (let (from to)
80 (setq from (read-from-minibuffer "Map query replace (regexp): "
81 nil nil nil
82 'query-replace-history))
83 (setq to (read-from-minibuffer
84 (format "Query replace %s with (space-separated strings): "
85 from)
86 nil nil nil
87 'query-replace-history))
88 (list from to current-prefix-arg)))
67 (let (replacements) 89 (let (replacements)
68 (if (listp to-strings) 90 (if (listp to-strings)
69 (setq replacements to-strings) 91 (setq replacements to-strings)
@@ -92,7 +114,7 @@ What you probably want is a loop like this:
92 (while (search-forward OLD-STRING nil t) 114 (while (search-forward OLD-STRING nil t)
93 (replace-match REPLACEMENT nil t)) 115 (replace-match REPLACEMENT nil t))
94which will run faster and will not set the mark or print anything." 116which will run faster and will not set the mark or print anything."
95 (interactive "sReplace string: \nsReplace string %s with: \nP") 117 (interactive (query-replace-read-args "Replace string"))
96 (perform-replace from-string to-string nil nil delimited) 118 (perform-replace from-string to-string nil nil delimited)
97 (message "Done")) 119 (message "Done"))
98 120
@@ -110,7 +132,7 @@ What you probably want is a loop like this:
110 (while (re-search-forward REGEXP nil t) 132 (while (re-search-forward REGEXP nil t)
111 (replace-match REPLACEMENT nil nil)) 133 (replace-match REPLACEMENT nil nil))
112which will run faster and will not set the mark or print anything." 134which will run faster and will not set the mark or print anything."
113 (interactive "sReplace regexp: \nsReplace regexp %s with: \nP") 135 (interactive (query-replace-read-args "Replace regexp"))
114 (perform-replace regexp to-string nil t delimited) 136 (perform-replace regexp to-string nil t delimited)
115 (message "Done")) 137 (message "Done"))
116 138
diff --git a/lisp/simple.el b/lisp/simple.el
index 59211c9db20..6c7cce59c03 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -391,7 +391,9 @@ Whilst editing the command, the following commands are available:
391 (setq newcmd (read-from-minibuffer "Redo: " 391 (setq newcmd (read-from-minibuffer "Redo: "
392 (prin1-to-string elt) 392 (prin1-to-string elt)
393 minibuffer-local-map 393 minibuffer-local-map
394 t)) 394 t
395 (cons 'command-history
396 arg)))
395 ;; If command to be redone does not match front of history, 397 ;; If command to be redone does not match front of history,
396 ;; add it to the history. 398 ;; add it to the history.
397 (or (equal newcmd (car command-history)) 399 (or (equal newcmd (car command-history))
@@ -415,7 +417,7 @@ Whilst editing the command, the following commands are available:
415 (insert 417 (insert
416 (if minibuffer-history-sexp-flag 418 (if minibuffer-history-sexp-flag
417 (prin1-to-string elt) 419 (prin1-to-string elt)
418 elt)))) 420 elt)))
419 (goto-char (point-min))))) 421 (goto-char (point-min)))))
420 422
421(defun previous-history-element (n) 423(defun previous-history-element (n)
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);