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