428
|
1 /* Minibuffer input and completion.
|
|
2 Copyright (C) 1985, 1986, 1992-1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Sun Microsystems, Inc.
|
793
|
4 Copyright (C) 2002 Ben Wing.
|
428
|
5
|
|
6 This file is part of XEmacs.
|
|
7
|
|
8 XEmacs is free software; you can redistribute it and/or modify it
|
|
9 under the terms of the GNU General Public License as published by the
|
|
10 Free Software Foundation; either version 2, or (at your option) any
|
|
11 later version.
|
|
12
|
|
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
16 for more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License
|
|
19 along with XEmacs; see the file COPYING. If not, write to
|
|
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
21 Boston, MA 02111-1307, USA. */
|
|
22
|
|
23 /* Synched up with: Mule 2.0, FSF 19.28. Mule-ized except as noted.
|
|
24 Substantially different from FSF. */
|
|
25
|
|
26 /* #### dmoore - All sorts of things in here can call lisp, like message.
|
|
27 Track all this stuff. */
|
|
28
|
|
29 #include <config.h>
|
|
30 #include "lisp.h"
|
|
31
|
|
32 #include "buffer.h"
|
|
33 #include "commands.h"
|
|
34 #include "console-stream.h"
|
|
35 #include "events.h"
|
872
|
36 #include "frame-impl.h"
|
428
|
37 #include "insdel.h"
|
|
38 #include "redisplay.h"
|
872
|
39 #include "window-impl.h"
|
428
|
40
|
|
41 /* Depth in minibuffer invocations. */
|
|
42 int minibuf_level;
|
|
43
|
|
44 Lisp_Object Qcompletion_ignore_case;
|
|
45
|
|
46 /* Nonzero means completion ignores case. */
|
|
47 int completion_ignore_case;
|
|
48
|
|
49 /* List of regexps that should restrict possible completions. */
|
|
50 Lisp_Object Vcompletion_regexp_list;
|
|
51
|
|
52 /* The echo area buffer. */
|
|
53 Lisp_Object Vecho_area_buffer;
|
|
54
|
|
55 /* Prompt to display in front of the minibuffer contents */
|
|
56 Lisp_Object Vminibuf_prompt;
|
|
57
|
|
58 /* Added on 97/3/14 by Jareth Hein (jhod@po.iijnet.or.jp) for input system support */
|
|
59 /* String to be displayed in front of prompt of the minibuffer contents */
|
|
60 Lisp_Object Vminibuf_preprompt;
|
|
61
|
|
62 /* Hook to run just after entry to minibuffer. */
|
|
63 Lisp_Object Qminibuffer_setup_hook, Vminibuffer_setup_hook;
|
|
64
|
|
65 Lisp_Object Qappend_message, Qcurrent_message_label,
|
|
66 Qclear_message, Qdisplay_message;
|
|
67
|
|
68
|
|
69 DEFUN ("minibuffer-depth", Fminibuffer_depth, 0, 0, 0, /*
|
|
70 Return current depth of activations of minibuffer, a nonnegative integer.
|
|
71 */
|
|
72 ())
|
|
73 {
|
|
74 return make_int (minibuf_level);
|
|
75 }
|
|
76
|
|
77 /* The default buffer to use as the window-buffer of minibuffer windows */
|
|
78 /* Note there is special code in kill-buffer to make this unkillable */
|
|
79 Lisp_Object Vminibuffer_zero;
|
|
80
|
|
81
|
|
82 /* Actual minibuffer invocation. */
|
|
83
|
|
84 static Lisp_Object
|
|
85 read_minibuffer_internal_unwind (Lisp_Object unwind_data)
|
|
86 {
|
|
87 Lisp_Object frame;
|
|
88 XWINDOW (minibuf_window)->last_modified[CURRENT_DISP] = Qzero;
|
|
89 XWINDOW (minibuf_window)->last_modified[DESIRED_DISP] = Qzero;
|
|
90 XWINDOW (minibuf_window)->last_modified[CMOTION_DISP] = Qzero;
|
|
91 XWINDOW (minibuf_window)->last_facechange[CURRENT_DISP] = Qzero;
|
|
92 XWINDOW (minibuf_window)->last_facechange[DESIRED_DISP] = Qzero;
|
|
93 XWINDOW (minibuf_window)->last_facechange[CMOTION_DISP] = Qzero;
|
|
94 Vminibuf_prompt = Felt (unwind_data, Qzero);
|
|
95 minibuf_level = XINT (Felt (unwind_data, make_int (1)));
|
|
96 while (CONSP (unwind_data))
|
|
97 {
|
|
98 Lisp_Object victim = unwind_data;
|
|
99 unwind_data = XCDR (unwind_data);
|
853
|
100 free_cons (victim);
|
428
|
101 }
|
|
102
|
|
103 /* If cursor is on the minibuffer line,
|
|
104 show the user we have exited by putting it in column 0. */
|
|
105 frame = Fselected_frame (Qnil);
|
|
106 if (!noninteractive
|
|
107 && !NILP (frame)
|
|
108 && !NILP (XFRAME (frame)->minibuffer_window))
|
|
109 {
|
|
110 struct window *w = XWINDOW (XFRAME (frame)->minibuffer_window);
|
|
111 redisplay_move_cursor (w, 0, 0);
|
|
112 }
|
|
113
|
|
114 return Qnil;
|
|
115 }
|
|
116
|
|
117 /* 97/4/13 jhod: Added for input methods */
|
|
118 DEFUN ("set-minibuffer-preprompt", Fset_minibuffer_preprompt, 1, 1, 0, /*
|
|
119 Set the minibuffer preprompt string to PREPROMPT. This is used by language
|
|
120 input methods to relay state information to the user.
|
|
121 */
|
|
122 (preprompt))
|
|
123 {
|
|
124 if (NILP (preprompt))
|
|
125 {
|
|
126 Vminibuf_preprompt = Qnil;
|
|
127 }
|
|
128 else
|
|
129 {
|
|
130 CHECK_STRING (preprompt);
|
|
131
|
|
132 Vminibuf_preprompt = LISP_GETTEXT (preprompt);
|
|
133 }
|
|
134 return Qnil;
|
|
135 }
|
|
136
|
2268
|
137 DEFUN_NORETURN ("read-minibuffer-internal", Fread_minibuffer_internal,
|
|
138 1, 1, 0, /*
|
428
|
139 Lowest-level interface to minibuffers. Don't call this.
|
|
140 */
|
|
141 (prompt))
|
|
142 {
|
|
143 /* This function can GC */
|
2268
|
144
|
|
145 /* We used to record the specpdl_depth here, but since call_command_loop
|
|
146 never returns, we can never call unbind_to_1. Since we exit via a throw,
|
|
147 we let whoever catches unbind for us. */
|
|
148
|
428
|
149 CHECK_STRING (prompt);
|
|
150
|
|
151 single_console_state ();
|
|
152
|
|
153 record_unwind_protect (read_minibuffer_internal_unwind,
|
|
154 noseeum_cons
|
|
155 (Vminibuf_prompt,
|
|
156 noseeum_cons (make_int (minibuf_level), Qnil)));
|
|
157 Vminibuf_prompt = LISP_GETTEXT (prompt);
|
|
158
|
|
159 /* NOTE: Here (or somewhere around here), in FSFmacs 19.30,
|
|
160 choose_minibuf_frame() is called. This is the only
|
|
161 place in FSFmacs that it's called any more -- there's
|
|
162 also a call in xterm.c, but commented out, and 19.28
|
|
163 had the calls in different places.
|
|
164
|
|
165 choose_minibuf_frame() does the following:
|
|
166
|
|
167 if (!EQ (minibuf_window, selected_frame()->minibuffer_window))
|
|
168 {
|
|
169 Fset_window_buffer (selected_frame()->minibuffer_window,
|
|
170 XWINDOW (minibuf_window)->buffer);
|
|
171 minibuf_window = selected_frame()->minibuffer_window;
|
|
172 }
|
|
173
|
|
174 #### Note that we don't do the set-window-buffer. This call is
|
|
175 similar, but not identical, to a set-window-buffer call made
|
|
176 in `read-from-minibuffer' in minibuf.el. I hope it's close
|
|
177 enough, because minibuf_window isn't really exported to Lisp.
|
|
178
|
|
179 The comment above choose_minibuf_frame() reads:
|
|
180
|
|
181 Put minibuf on currently selected frame's minibuffer.
|
|
182 We do this whenever the user starts a new minibuffer
|
|
183 or when a minibuffer exits. */
|
|
184
|
|
185 minibuf_window = FRAME_MINIBUF_WINDOW (selected_frame ());
|
|
186
|
|
187 run_hook (Qminibuffer_setup_hook);
|
|
188
|
|
189 minibuf_level++;
|
|
190 clear_echo_area (selected_frame (), Qnil, 0);
|
|
191
|
2286
|
192 call_command_loop (Qt);
|
428
|
193
|
2286
|
194 RETURN_NOT_REACHED (Qnil);
|
428
|
195 }
|
|
196
|
|
197
|
|
198
|
|
199 /* Completion hair */
|
|
200
|
|
201 /* Compare exactly LEN chars of strings at S1 and S2,
|
|
202 ignoring case if appropriate.
|
|
203 Return -1 if strings match,
|
|
204 else number of chars that match at the beginning. */
|
|
205
|
|
206 /* Note that this function works in Charcounts, unlike most functions.
|
|
207 This is necessary for many reasons, one of which is that two
|
|
208 strings may match even if they have different numbers of bytes,
|
|
209 if IGNORE_CASE is true. */
|
|
210
|
|
211 Charcount
|
867
|
212 scmp_1 (const Ibyte *s1, const Ibyte *s2, Charcount len,
|
428
|
213 int ignore_case)
|
|
214 {
|
|
215 Charcount l = len;
|
|
216
|
|
217 if (ignore_case)
|
|
218 {
|
|
219 while (l)
|
|
220 {
|
867
|
221 Ichar c1 = DOWNCASE (0, itext_ichar (s1));
|
|
222 Ichar c2 = DOWNCASE (0, itext_ichar (s2));
|
428
|
223
|
|
224 if (c1 == c2)
|
|
225 {
|
|
226 l--;
|
867
|
227 INC_IBYTEPTR (s1);
|
|
228 INC_IBYTEPTR (s2);
|
428
|
229 }
|
|
230 else
|
|
231 break;
|
|
232 }
|
|
233 }
|
|
234 else
|
|
235 {
|
867
|
236 while (l && itext_ichar (s1) == itext_ichar (s2))
|
428
|
237 {
|
|
238 l--;
|
867
|
239 INC_IBYTEPTR (s1);
|
|
240 INC_IBYTEPTR (s2);
|
428
|
241 }
|
|
242 }
|
|
243
|
|
244 if (l == 0)
|
|
245 return -1;
|
|
246 else return len - l;
|
|
247 }
|
|
248
|
|
249
|
|
250 int
|
867
|
251 regexp_ignore_completion_p (const Ibyte *nonreloc,
|
428
|
252 Lisp_Object reloc, Bytecount offset,
|
|
253 Bytecount length)
|
|
254 {
|
|
255 /* Ignore this element if it fails to match all the regexps. */
|
|
256 if (!NILP (Vcompletion_regexp_list))
|
|
257 {
|
2367
|
258 EXTERNAL_LIST_LOOP_2 (re, Vcompletion_regexp_list)
|
428
|
259 {
|
|
260 CHECK_STRING (re);
|
|
261 if (fast_string_match (re, nonreloc, reloc, offset,
|
|
262 length, 0, ERROR_ME, 0) < 0)
|
|
263 return 1;
|
|
264 }
|
|
265 }
|
|
266 return 0;
|
|
267 }
|
|
268
|
|
269
|
|
270 /* Callers should GCPRO, since this may call eval */
|
|
271 static int
|
|
272 ignore_completion_p (Lisp_Object completion_string,
|
|
273 Lisp_Object pred, Lisp_Object completion)
|
|
274 {
|
|
275 if (regexp_ignore_completion_p (0, completion_string, 0, -1))
|
|
276 return 1;
|
|
277
|
|
278 /* Ignore this element if there is a predicate
|
|
279 and the predicate doesn't like it. */
|
|
280 if (!NILP (pred))
|
|
281 {
|
|
282 Lisp_Object tem;
|
|
283 if (EQ (pred, Qcommandp))
|
|
284 tem = Fcommandp (completion);
|
|
285 else
|
|
286 tem = call1 (pred, completion);
|
|
287 if (NILP (tem))
|
|
288 return 1;
|
|
289 }
|
|
290 return 0;
|
|
291 }
|
|
292
|
|
293
|
444
|
294 /* #### Maybe we should allow COLLECTION to be a hash table.
|
|
295 It is wrong for the use of obarrays to be better-rewarded than the
|
|
296 use of hash tables. By better-rewarded I mean that you can pass an
|
|
297 obarray to all of the completion functions, whereas you can't do
|
|
298 anything like that with a hash table.
|
428
|
299
|
|
300 To do so, there should probably be a
|
|
301 map_obarray_or_alist_or_hash_table function which would be used by
|
826
|
302 both Ftry_completion and Fall_completions. [[ But would the
|
|
303 additional funcalls slow things down? ]] Seriously doubtful. --ben */
|
428
|
304
|
|
305 DEFUN ("try-completion", Ftry_completion, 2, 3, 0, /*
|
444
|
306 Return common substring of all completions of STRING in COLLECTION.
|
|
307 COLLECTION must be an alist, an obarray, or a function.
|
|
308 Each string in COLLECTION is tested to see if it begins with STRING.
|
428
|
309 All that match are compared together; the longest initial sequence
|
444
|
310 common to all matches is returned as a string. If there is no match
|
|
311 at all, nil is returned. For an exact match, t is returned.
|
428
|
312
|
444
|
313 If COLLECTION is an alist, the cars of the elements of the alist
|
|
314 \(which must be strings) form the set of possible completions.
|
428
|
315
|
444
|
316 If COLLECTION is an obarray, the names of all symbols in the obarray
|
|
317 are the possible completions.
|
|
318
|
|
319 If COLLECTION is a function, it is called with three arguments: the
|
|
320 values STRING, PREDICATE and nil. Whatever it returns becomes the
|
|
321 value of `try-completion'.
|
428
|
322
|
444
|
323 If optional third argument PREDICATE is non-nil, it is used to test
|
|
324 each possible match. The match is a candidate only if PREDICATE
|
|
325 returns non-nil. The argument given to PREDICATE is the alist element
|
|
326 or the symbol from the obarray.
|
428
|
327 */
|
444
|
328 (string, collection, predicate))
|
428
|
329 {
|
|
330 /* This function can GC */
|
|
331 Lisp_Object bestmatch, tail;
|
|
332 Charcount bestmatchsize = 0;
|
|
333 int list;
|
|
334 int indice = 0;
|
|
335 int matchcount = 0;
|
|
336 int obsize;
|
|
337 Lisp_Object bucket;
|
|
338 Charcount slength, blength;
|
|
339
|
|
340 CHECK_STRING (string);
|
|
341
|
444
|
342 if (CONSP (collection))
|
428
|
343 {
|
444
|
344 Lisp_Object tem = XCAR (collection);
|
428
|
345 if (SYMBOLP (tem)) /* lambda, autoload, etc. Emacs-lisp sucks */
|
444
|
346 return call3 (collection, string, predicate, Qnil);
|
428
|
347 else
|
|
348 list = 1;
|
|
349 }
|
444
|
350 else if (VECTORP (collection))
|
428
|
351 list = 0;
|
444
|
352 else if (NILP (collection))
|
428
|
353 list = 1;
|
|
354 else
|
444
|
355 return call3 (collection, string, predicate, Qnil);
|
428
|
356
|
|
357 bestmatch = Qnil;
|
|
358 blength = 0;
|
826
|
359 slength = string_char_length (string);
|
428
|
360
|
444
|
361 /* If COLLECTION is not a list, set TAIL just for gc pro. */
|
|
362 tail = collection;
|
428
|
363 if (!list)
|
|
364 {
|
444
|
365 obsize = XVECTOR_LENGTH (collection);
|
|
366 bucket = XVECTOR_DATA (collection)[indice];
|
428
|
367 }
|
|
368 else /* warning suppression */
|
|
369 {
|
|
370 obsize = 0;
|
|
371 bucket = Qnil;
|
|
372 }
|
|
373
|
|
374 while (1)
|
|
375 {
|
|
376 /* Get the next element of the alist or obarray. */
|
|
377 /* Exit the loop if the elements are all used up. */
|
|
378 /* elt gets the alist element or symbol.
|
|
379 eltstring gets the name to check as a completion. */
|
|
380 Lisp_Object elt;
|
|
381 Lisp_Object eltstring;
|
|
382
|
|
383 if (list)
|
|
384 {
|
|
385 if (NILP (tail))
|
|
386 break;
|
|
387 elt = Fcar (tail);
|
|
388 eltstring = Fcar (elt);
|
|
389 tail = Fcdr (tail);
|
|
390 }
|
|
391 else
|
|
392 {
|
|
393 if (!ZEROP (bucket))
|
|
394 {
|
440
|
395 Lisp_Symbol *next;
|
428
|
396 if (!SYMBOLP (bucket))
|
|
397 {
|
563
|
398 invalid_argument ("Bad obarray passed to try-completions",
|
|
399 bucket);
|
428
|
400 }
|
|
401 next = symbol_next (XSYMBOL (bucket));
|
|
402 elt = bucket;
|
|
403 eltstring = Fsymbol_name (elt);
|
|
404 if (next)
|
793
|
405 bucket = wrap_symbol (next);
|
428
|
406 else
|
|
407 bucket = Qzero;
|
|
408 }
|
|
409 else if (++indice >= obsize)
|
|
410 break;
|
|
411 else
|
|
412 {
|
444
|
413 bucket = XVECTOR_DATA (collection)[indice];
|
428
|
414 continue;
|
|
415 }
|
|
416 }
|
|
417
|
|
418 /* Is this element a possible completion? */
|
|
419
|
|
420 if (STRINGP (eltstring))
|
|
421 {
|
826
|
422 Charcount eltlength = string_char_length (eltstring);
|
428
|
423 if (slength <= eltlength
|
|
424 && (0 > scmp (XSTRING_DATA (eltstring),
|
|
425 XSTRING_DATA (string),
|
|
426 slength)))
|
|
427 {
|
|
428 {
|
|
429 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
430 int loser;
|
|
431 GCPRO4 (tail, string, eltstring, bestmatch);
|
444
|
432 loser = ignore_completion_p (eltstring, predicate, elt);
|
428
|
433 UNGCPRO;
|
|
434 if (loser) /* reject this one */
|
|
435 continue;
|
|
436 }
|
|
437
|
|
438 /* Update computation of how much all possible
|
|
439 completions match */
|
|
440
|
|
441 matchcount++;
|
|
442 if (NILP (bestmatch))
|
|
443 {
|
|
444 bestmatch = eltstring;
|
|
445 blength = eltlength;
|
|
446 bestmatchsize = eltlength;
|
|
447 }
|
|
448 else
|
|
449 {
|
|
450 Charcount compare = min (bestmatchsize, eltlength);
|
|
451 Charcount matchsize =
|
|
452 scmp (XSTRING_DATA (bestmatch),
|
|
453 XSTRING_DATA (eltstring),
|
|
454 compare);
|
|
455 if (matchsize < 0)
|
|
456 matchsize = compare;
|
|
457 if (completion_ignore_case)
|
|
458 {
|
|
459 /* If this is an exact match except for case,
|
|
460 use it as the best match rather than one that is not
|
|
461 an exact match. This way, we get the case pattern
|
|
462 of the actual match. */
|
|
463 if ((matchsize == eltlength
|
|
464 && matchsize < blength)
|
|
465 ||
|
|
466 /* If there is more than one exact match ignoring
|
|
467 case, and one of them is exact including case,
|
|
468 prefer that one. */
|
|
469 /* If there is no exact match ignoring case,
|
|
470 prefer a match that does not change the case
|
|
471 of the input. */
|
|
472 ((matchsize == eltlength)
|
|
473 ==
|
|
474 (matchsize == blength)
|
|
475 && 0 > scmp_1 (XSTRING_DATA (eltstring),
|
|
476 XSTRING_DATA (string),
|
|
477 slength, 0)
|
|
478 && 0 <= scmp_1 (XSTRING_DATA (bestmatch),
|
|
479 XSTRING_DATA (string),
|
|
480 slength, 0)))
|
|
481 {
|
|
482 bestmatch = eltstring;
|
|
483 blength = eltlength;
|
|
484 }
|
|
485 }
|
|
486 bestmatchsize = matchsize;
|
|
487 }
|
|
488 }
|
|
489 }
|
|
490 }
|
|
491
|
|
492 if (NILP (bestmatch))
|
|
493 return Qnil; /* No completions found */
|
|
494 /* If we are ignoring case, and there is no exact match,
|
|
495 and no additional text was supplied,
|
|
496 don't change the case of what the user typed. */
|
|
497 if (completion_ignore_case
|
|
498 && bestmatchsize == slength
|
|
499 && blength > bestmatchsize)
|
|
500 return string;
|
|
501
|
|
502 /* Return t if the supplied string is an exact match (counting case);
|
|
503 it does not require any change to be made. */
|
|
504 if (matchcount == 1
|
|
505 && bestmatchsize == slength
|
|
506 && 0 > scmp_1 (XSTRING_DATA (bestmatch),
|
|
507 XSTRING_DATA (string),
|
|
508 bestmatchsize, 0))
|
|
509 return Qt;
|
|
510
|
|
511 /* Else extract the part in which all completions agree */
|
|
512 return Fsubstring (bestmatch, Qzero, make_int (bestmatchsize));
|
|
513 }
|
|
514
|
|
515
|
|
516 DEFUN ("all-completions", Fall_completions, 2, 3, 0, /*
|
444
|
517 Search for partial matches to STRING in COLLECTION.
|
|
518 COLLECTION must be an alist, an obarray, or a function.
|
|
519 Each string in COLLECTION is tested to see if it begins with STRING.
|
|
520 The value is a list of all the strings from COLLECTION that match.
|
|
521
|
|
522 If COLLECTION is an alist, the cars of the elements of the alist
|
|
523 \(which must be strings) form the set of possible completions.
|
|
524
|
|
525 If COLLECTION is an obarray, the names of all symbols in the obarray
|
|
526 are the possible completions.
|
428
|
527
|
444
|
528 If COLLECTION is a function, it is called with three arguments: the
|
|
529 values STRING, PREDICATE and t. Whatever it returns becomes the
|
|
530 value of `all-completions'.
|
428
|
531
|
444
|
532 If optional third argument PREDICATE is non-nil, it is used to test
|
|
533 each possible match. The match is a candidate only if PREDICATE
|
|
534 returns non-nil. The argument given to PREDICATE is the alist element
|
|
535 or the symbol from the obarray.
|
428
|
536 */
|
444
|
537 (string, collection, predicate))
|
428
|
538 {
|
|
539 /* This function can GC */
|
|
540 Lisp_Object tail;
|
|
541 Lisp_Object allmatches;
|
|
542 int list;
|
|
543 int indice = 0;
|
|
544 int obsize;
|
|
545 Lisp_Object bucket;
|
|
546 Charcount slength;
|
|
547
|
|
548 CHECK_STRING (string);
|
|
549
|
444
|
550 if (CONSP (collection))
|
428
|
551 {
|
444
|
552 Lisp_Object tem = XCAR (collection);
|
428
|
553 if (SYMBOLP (tem)) /* lambda, autoload, etc. Emacs-lisp sucks */
|
444
|
554 return call3 (collection, string, predicate, Qt);
|
428
|
555 else
|
|
556 list = 1;
|
|
557 }
|
444
|
558 else if (VECTORP (collection))
|
428
|
559 list = 0;
|
444
|
560 else if (NILP (collection))
|
428
|
561 list = 1;
|
|
562 else
|
444
|
563 return call3 (collection, string, predicate, Qt);
|
428
|
564
|
|
565 allmatches = Qnil;
|
826
|
566 slength = string_char_length (string);
|
428
|
567
|
444
|
568 /* If COLLECTION is not a list, set TAIL just for gc pro. */
|
|
569 tail = collection;
|
428
|
570 if (!list)
|
|
571 {
|
444
|
572 obsize = XVECTOR_LENGTH (collection);
|
|
573 bucket = XVECTOR_DATA (collection)[indice];
|
428
|
574 }
|
|
575 else /* warning suppression */
|
|
576 {
|
|
577 obsize = 0;
|
|
578 bucket = Qnil;
|
|
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 Lisp_Object elt;
|
|
588 Lisp_Object eltstring;
|
|
589
|
|
590 if (list)
|
|
591 {
|
|
592 if (NILP (tail))
|
|
593 break;
|
|
594 elt = Fcar (tail);
|
|
595 eltstring = Fcar (elt);
|
|
596 tail = Fcdr (tail);
|
|
597 }
|
|
598 else
|
|
599 {
|
|
600 if (!ZEROP (bucket))
|
|
601 {
|
440
|
602 Lisp_Symbol *next = symbol_next (XSYMBOL (bucket));
|
428
|
603 elt = bucket;
|
|
604 eltstring = Fsymbol_name (elt);
|
|
605 if (next)
|
793
|
606 bucket = wrap_symbol (next);
|
428
|
607 else
|
|
608 bucket = Qzero;
|
|
609 }
|
|
610 else if (++indice >= obsize)
|
|
611 break;
|
|
612 else
|
|
613 {
|
444
|
614 bucket = XVECTOR_DATA (collection)[indice];
|
428
|
615 continue;
|
|
616 }
|
|
617 }
|
|
618
|
|
619 /* Is this element a possible completion? */
|
|
620
|
|
621 if (STRINGP (eltstring)
|
826
|
622 && (slength <= string_char_length (eltstring))
|
448
|
623 /* Reject alternatives that start with space
|
|
624 unless the input starts with space. */
|
826
|
625 && ((string_char_length (string) > 0 &&
|
867
|
626 string_ichar (string, 0) == ' ')
|
|
627 || string_ichar (eltstring, 0) != ' ')
|
448
|
628 && (0 > scmp (XSTRING_DATA (eltstring),
|
428
|
629 XSTRING_DATA (string),
|
|
630 slength)))
|
|
631 {
|
|
632 /* Yes. Now check whether predicate likes it. */
|
|
633 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
634 int loser;
|
|
635 GCPRO4 (tail, eltstring, allmatches, string);
|
444
|
636 loser = ignore_completion_p (eltstring, predicate, elt);
|
428
|
637 UNGCPRO;
|
|
638 if (!loser)
|
|
639 /* Ok => put it on the list. */
|
|
640 allmatches = Fcons (eltstring, allmatches);
|
|
641 }
|
|
642 }
|
|
643
|
|
644 return Fnreverse (allmatches);
|
|
645 }
|
|
646
|
|
647 /* Useless FSFmacs functions */
|
|
648 /* More than useless. I've nuked minibuf_prompt_width so they won't
|
|
649 function at all in XEmacs at the moment. They are used to
|
|
650 implement some braindamage in FSF which we aren't including. --cet */
|
|
651
|
|
652 #if 0
|
826
|
653 DEFUN ("minibuffer-prompt", Fminibuffer_prompt, 0, 0, 0, /*
|
428
|
654 Return the prompt string of the currently-active minibuffer.
|
|
655 If no minibuffer is active, return nil.
|
|
656 */
|
|
657 ())
|
|
658 {
|
|
659 return Fcopy_sequence (Vminibuf_prompt);
|
|
660 }
|
|
661
|
826
|
662 DEFUN ("minibuffer-prompt-width", Fminibuffer_prompt_width, 0, 0, 0, /*
|
428
|
663 Return the display width of the minibuffer prompt.
|
|
664 */
|
|
665 ())
|
|
666 {
|
|
667 return make_int (minibuf_prompt_width);
|
|
668 }
|
|
669 #endif /* 0 */
|
|
670
|
|
671
|
|
672 /************************************************************************/
|
|
673 /* echo area */
|
|
674 /************************************************************************/
|
|
675
|
|
676 extern int stdout_needs_newline;
|
|
677
|
|
678 static Lisp_Object
|
|
679 clear_echo_area_internal (struct frame *f, Lisp_Object label, int from_print,
|
|
680 int no_restore)
|
|
681 {
|
|
682 /* This function can call lisp */
|
|
683 if (!NILP (Ffboundp (Qclear_message)))
|
|
684 {
|
793
|
685 Lisp_Object frame = wrap_frame (f);
|
428
|
686
|
|
687 return call4 (Qclear_message, label, frame, from_print ? Qt : Qnil,
|
|
688 no_restore ? Qt : Qnil);
|
|
689 }
|
|
690 else
|
|
691 {
|
771
|
692 stderr_out ("\n");
|
428
|
693 return Qnil;
|
|
694 }
|
|
695 }
|
|
696
|
|
697 Lisp_Object
|
|
698 clear_echo_area (struct frame *f, Lisp_Object label, int no_restore)
|
|
699 {
|
|
700 /* This function can call lisp */
|
|
701 return clear_echo_area_internal (f, label, 0, no_restore);
|
|
702 }
|
|
703
|
|
704 Lisp_Object
|
|
705 clear_echo_area_from_print (struct frame *f, Lisp_Object label, int no_restore)
|
|
706 {
|
|
707 /* This function can call lisp */
|
|
708 return clear_echo_area_internal (f, label, 1, no_restore);
|
|
709 }
|
|
710
|
|
711 void
|
867
|
712 echo_area_append (struct frame *f, const Ibyte *nonreloc, Lisp_Object reloc,
|
428
|
713 Bytecount offset, Bytecount length,
|
|
714 Lisp_Object label)
|
|
715 {
|
|
716 /* This function can call lisp */
|
|
717 Lisp_Object obj;
|
|
718 struct gcpro gcpro1;
|
|
719 Lisp_Object frame;
|
|
720
|
440
|
721 /* There is an inlining bug in egcs-20000131 c++ that can be worked
|
|
722 around as follows: */
|
|
723 #if defined (__GNUC__) && defined (__cplusplus)
|
|
724 alloca (4);
|
|
725 #endif
|
|
726
|
428
|
727 /* some callers pass in a null string as a way of clearing the echo area.
|
|
728 check for length == 0 now; if this case, neither nonreloc nor reloc
|
|
729 may be valid. */
|
|
730 if (length == 0)
|
|
731 return;
|
|
732
|
|
733 fixup_internal_substring (nonreloc, reloc, offset, &length);
|
|
734
|
|
735 /* also check it here, in case the string was really blank. */
|
|
736 if (length == 0)
|
|
737 return;
|
|
738
|
|
739 if (!NILP (Ffboundp (Qappend_message)))
|
|
740 {
|
|
741 if (STRINGP (reloc) && offset == 0 && length == XSTRING_LENGTH (reloc))
|
|
742 obj = reloc;
|
|
743 else
|
|
744 {
|
|
745 if (STRINGP (reloc))
|
|
746 nonreloc = XSTRING_DATA (reloc);
|
|
747 obj = make_string (nonreloc + offset, length);
|
|
748 }
|
|
749
|
793
|
750 frame = wrap_frame (f);
|
428
|
751 GCPRO1 (obj);
|
|
752 call4 (Qappend_message, label, obj, frame,
|
|
753 EQ (label, Qprint) ? Qt : Qnil);
|
|
754 UNGCPRO;
|
|
755 }
|
|
756 else
|
|
757 {
|
|
758 if (STRINGP (reloc))
|
|
759 nonreloc = XSTRING_DATA (reloc);
|
826
|
760 write_string_1 (Qexternal_debugging_output, nonreloc + offset, length);
|
428
|
761 }
|
|
762 }
|
|
763
|
|
764 void
|
867
|
765 echo_area_message (struct frame *f, const Ibyte *nonreloc,
|
428
|
766 Lisp_Object reloc, Bytecount offset, Bytecount length,
|
|
767 Lisp_Object label)
|
|
768 {
|
|
769 /* This function can call lisp */
|
|
770 clear_echo_area (f, label, 1);
|
|
771 echo_area_append (f, nonreloc, reloc, offset, length, label);
|
|
772 }
|
|
773
|
|
774 int
|
2286
|
775 echo_area_active (struct frame *UNUSED (f))
|
428
|
776 {
|
|
777 /* By definition, the echo area is active if the echo-area buffer
|
|
778 is not empty. No need to call Lisp code. (Anyway, this function
|
|
779 is called from redisplay.) */
|
|
780 struct buffer *echo_buffer = XBUFFER (Vecho_area_buffer);
|
|
781 return BUF_BEGV (echo_buffer) != BUF_ZV (echo_buffer);
|
|
782 }
|
|
783
|
|
784 Lisp_Object
|
|
785 echo_area_status (struct frame *f)
|
|
786 {
|
|
787 /* This function can call lisp */
|
|
788 if (!NILP (Ffboundp (Qcurrent_message_label)))
|
|
789 {
|
793
|
790 Lisp_Object frame = wrap_frame (f);
|
428
|
791
|
|
792 return call1 (Qcurrent_message_label, frame);
|
|
793 }
|
|
794 else
|
|
795 return stdout_needs_newline ? Qmessage : Qnil;
|
|
796 }
|
|
797
|
|
798 Lisp_Object
|
2286
|
799 echo_area_contents (struct frame *UNUSED (f))
|
428
|
800 {
|
|
801 /* See above. By definition, the contents of the echo-area buffer
|
|
802 are the contents of the echo area. */
|
|
803 return Fbuffer_substring (Qnil, Qnil, Vecho_area_buffer);
|
|
804 }
|
|
805
|
|
806 /* Dump an informative message to the echo area. This function takes a
|
|
807 string in internal format. */
|
|
808 void
|
867
|
809 message_internal (const Ibyte *nonreloc, Lisp_Object reloc,
|
428
|
810 Bytecount offset, Bytecount length)
|
|
811 {
|
|
812 /* This function can call lisp */
|
|
813 if (NILP (Vexecuting_macro))
|
|
814 echo_area_message (selected_frame (), nonreloc, reloc, offset, length,
|
|
815 Qmessage);
|
|
816 }
|
|
817
|
|
818 void
|
867
|
819 message_append_internal (const Ibyte *nonreloc, Lisp_Object reloc,
|
428
|
820 Bytecount offset, Bytecount length)
|
|
821 {
|
|
822 /* This function can call lisp */
|
|
823 if (NILP (Vexecuting_macro))
|
|
824 echo_area_append (selected_frame (), nonreloc, reloc, offset, length,
|
|
825 Qmessage);
|
|
826 }
|
|
827
|
|
828 /* The next three functions are interfaces to message_internal() that
|
|
829 take strings in external format. message() does I18N3 translating
|
|
830 on the format string; message_no_translate() does not. */
|
|
831
|
|
832 static void
|
867
|
833 message_1 (const CIbyte *fmt, va_list args)
|
428
|
834 {
|
|
835 /* This function can call lisp */
|
|
836 if (fmt)
|
|
837 {
|
|
838 struct gcpro gcpro1;
|
|
839 /* message_internal() might GC, e.g. if there are after-change-hooks
|
|
840 on the echo area buffer */
|
771
|
841 Lisp_Object obj = emacs_vsprintf_string (fmt, args);
|
428
|
842 GCPRO1 (obj);
|
|
843 message_internal (0, obj, 0, -1);
|
|
844 UNGCPRO;
|
|
845 }
|
|
846 else
|
|
847 message_internal (0, Qnil, 0, 0);
|
|
848 }
|
|
849
|
|
850 static void
|
867
|
851 message_append_1 (const CIbyte *fmt, va_list args)
|
428
|
852 {
|
|
853 /* This function can call lisp */
|
|
854 if (fmt)
|
|
855 {
|
|
856 struct gcpro gcpro1;
|
|
857 /* message_internal() might GC, e.g. if there are after-change-hooks
|
|
858 on the echo area buffer */
|
771
|
859 Lisp_Object obj = emacs_vsprintf_string (fmt, args);
|
428
|
860 GCPRO1 (obj);
|
|
861 message_append_internal (0, obj, 0, -1);
|
|
862 UNGCPRO;
|
|
863 }
|
|
864 else
|
|
865 message_append_internal (0, Qnil, 0, 0);
|
|
866 }
|
|
867
|
|
868 void
|
|
869 clear_message (void)
|
|
870 {
|
|
871 /* This function can call lisp */
|
|
872 message_internal (0, Qnil, 0, 0);
|
|
873 }
|
|
874
|
|
875 void
|
442
|
876 message (const char *fmt, ...)
|
428
|
877 {
|
|
878 /* This function can call lisp */
|
|
879 /* I think it's OK to pass the data of Lisp strings as arguments to
|
|
880 this function. No GC'ing will occur until the data has already
|
|
881 been copied. */
|
|
882 va_list args;
|
|
883
|
|
884 va_start (args, fmt);
|
|
885 if (fmt)
|
|
886 fmt = GETTEXT (fmt);
|
|
887 message_1 (fmt, args);
|
|
888 va_end (args);
|
|
889 }
|
|
890
|
|
891 void
|
442
|
892 message_append (const char *fmt, ...)
|
428
|
893 {
|
|
894 /* This function can call lisp */
|
|
895 va_list args;
|
|
896
|
|
897 va_start (args, fmt);
|
|
898 if (fmt)
|
|
899 fmt = GETTEXT (fmt);
|
|
900 message_append_1 (fmt, args);
|
|
901 va_end (args);
|
|
902 }
|
|
903
|
|
904 void
|
442
|
905 message_no_translate (const char *fmt, ...)
|
428
|
906 {
|
|
907 /* This function can call lisp */
|
|
908 /* I think it's OK to pass the data of Lisp strings as arguments to
|
|
909 this function. No GC'ing will occur until the data has already
|
|
910 been copied. */
|
|
911 va_list args;
|
|
912
|
|
913 va_start (args, fmt);
|
|
914 message_1 (fmt, args);
|
|
915 va_end (args);
|
|
916 }
|
|
917
|
|
918
|
|
919 /************************************************************************/
|
|
920 /* initialization */
|
|
921 /************************************************************************/
|
|
922
|
|
923 void
|
|
924 syms_of_minibuf (void)
|
|
925 {
|
563
|
926 DEFSYMBOL (Qminibuffer_setup_hook);
|
428
|
927
|
563
|
928 DEFSYMBOL (Qcompletion_ignore_case);
|
428
|
929
|
|
930 DEFSUBR (Fminibuffer_depth);
|
|
931 #if 0
|
|
932 DEFSUBR (Fminibuffer_prompt);
|
|
933 DEFSUBR (Fminibuffer_prompt_width);
|
|
934 #endif
|
|
935 DEFSUBR (Fset_minibuffer_preprompt);
|
|
936 DEFSUBR (Fread_minibuffer_internal);
|
|
937
|
|
938 DEFSUBR (Ftry_completion);
|
|
939 DEFSUBR (Fall_completions);
|
|
940
|
563
|
941 DEFSYMBOL (Qappend_message);
|
|
942 DEFSYMBOL (Qclear_message);
|
|
943 DEFSYMBOL (Qdisplay_message);
|
|
944 DEFSYMBOL (Qcurrent_message_label);
|
428
|
945 }
|
|
946
|
|
947 void
|
|
948 reinit_vars_of_minibuf (void)
|
|
949 {
|
|
950 minibuf_level = 0;
|
|
951 }
|
|
952
|
|
953 void
|
|
954 vars_of_minibuf (void)
|
|
955 {
|
|
956 staticpro (&Vminibuf_prompt);
|
|
957 Vminibuf_prompt = Qnil;
|
|
958
|
|
959 /* Added by Jareth Hein (jhod@po.iijnet.or.jp) for input system support */
|
|
960 staticpro (&Vminibuf_preprompt);
|
|
961 Vminibuf_preprompt = Qnil;
|
|
962
|
|
963 DEFVAR_LISP ("minibuffer-setup-hook", &Vminibuffer_setup_hook /*
|
|
964 Normal hook run just after entry to minibuffer.
|
|
965 */ );
|
|
966 Vminibuffer_setup_hook = Qnil;
|
|
967
|
|
968 DEFVAR_BOOL ("completion-ignore-case", &completion_ignore_case /*
|
|
969 Non-nil means don't consider case significant in completion.
|
|
970 */ );
|
|
971 completion_ignore_case = 0;
|
|
972
|
|
973 DEFVAR_LISP ("completion-regexp-list", &Vcompletion_regexp_list /*
|
|
974 List of regexps that should restrict possible completions.
|
|
975 Each completion has to match all regexps in this list.
|
|
976 */ );
|
|
977 Vcompletion_regexp_list = Qnil;
|
|
978 }
|
|
979
|
|
980 void
|
|
981 reinit_complex_vars_of_minibuf (void)
|
|
982 {
|
|
983 /* This function can GC */
|
|
984 #ifdef I18N3
|
|
985 /* #### This needs to be fixed up so that the gettext() gets called
|
|
986 at runtime instead of at load time. */
|
|
987 #endif
|
|
988 Vminibuffer_zero
|
|
989 = Fget_buffer_create
|
|
990 (build_string (DEFER_GETTEXT (" *Minibuf-0*")));
|
|
991 Vecho_area_buffer
|
|
992 = Fget_buffer_create
|
|
993 (build_string (DEFER_GETTEXT (" *Echo Area*")));
|
|
994 }
|
|
995
|
|
996 void
|
|
997 complex_vars_of_minibuf (void)
|
|
998 {
|
|
999 reinit_complex_vars_of_minibuf ();
|
|
1000 }
|