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