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