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