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