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;
|
219
|
255 EXTERNAL_LIST_LOOP (regexps, Vcompletion_regexp_list)
|
0
|
256 {
|
|
257 Lisp_Object re = XCAR (regexps);
|
219
|
258 CHECK_STRING (re);
|
|
259 if (fast_string_match (re, nonreloc, reloc, offset,
|
|
260 length, 0, ERROR_ME, 0) < 0)
|
173
|
261 return 1;
|
0
|
262 }
|
|
263 }
|
173
|
264 return 0;
|
0
|
265 }
|
|
266
|
|
267
|
|
268 /* Callers should GCPRO, since this may call eval */
|
|
269 static int
|
|
270 ignore_completion_p (Lisp_Object completion_string,
|
|
271 Lisp_Object pred, Lisp_Object completion)
|
|
272 {
|
|
273 if (regexp_ignore_completion_p (0, completion_string, 0, -1))
|
173
|
274 return 1;
|
|
275
|
0
|
276 /* Ignore this element if there is a predicate
|
|
277 and the predicate doesn't like it. */
|
|
278 if (!NILP (pred))
|
|
279 {
|
|
280 Lisp_Object tem;
|
|
281 if (EQ (pred, Qcommandp))
|
|
282 tem = Fcommandp (completion);
|
|
283 else
|
|
284 tem = call1 (pred, completion);
|
|
285 if (NILP (tem))
|
173
|
286 return 1;
|
0
|
287 }
|
173
|
288 return 0;
|
0
|
289 }
|
|
290
|
|
291
|
|
292
|
|
293
|
20
|
294 DEFUN ("try-completion", Ftry_completion, 2, 3, 0, /*
|
0
|
295 Return common substring of all completions of STRING in ALIST.
|
|
296 Each car of each element of ALIST is tested to see if it begins with STRING.
|
|
297 All that match are compared together; the longest initial sequence
|
|
298 common to all matches is returned as a string.
|
|
299 If there is no match at all, nil is returned.
|
|
300 For an exact match, t is returned.
|
|
301
|
|
302 ALIST can be an obarray instead of an alist.
|
|
303 Then the print names of all symbols in the obarray are the possible matches.
|
|
304
|
|
305 ALIST can also be a function to do the completion itself.
|
|
306 It receives three arguments: the values STRING, PREDICATE and nil.
|
|
307 Whatever it returns becomes the value of `try-completion'.
|
|
308
|
|
309 If optional third argument PREDICATE is non-nil,
|
|
310 it is used to test each possible match.
|
|
311 The match is a candidate only if PREDICATE returns non-nil.
|
|
312 The argument given to PREDICATE is the alist element or the symbol from the obarray.
|
20
|
313 */
|
|
314 (string, alist, pred))
|
0
|
315 {
|
|
316 /* This function can GC */
|
|
317 Lisp_Object bestmatch, tail;
|
|
318 Charcount bestmatchsize = 0;
|
|
319 int list;
|
|
320 int indice = 0;
|
|
321 int matchcount = 0;
|
173
|
322 int obsize;
|
0
|
323 Lisp_Object bucket;
|
|
324 Charcount slength, blength;
|
|
325
|
|
326 CHECK_STRING (string);
|
|
327
|
|
328 if (CONSP (alist))
|
|
329 {
|
|
330 Lisp_Object tem = XCAR (alist);
|
|
331 if (SYMBOLP (tem)) /* lambda, autoload, etc. Emacs-lisp sucks */
|
|
332 return call3 (alist, string, pred, Qnil);
|
|
333 else
|
|
334 list = 1;
|
|
335 }
|
|
336 else if (VECTORP (alist))
|
|
337 list = 0;
|
|
338 else if (NILP (alist))
|
|
339 list = 1;
|
|
340 else
|
|
341 return call3 (alist, string, pred, Qnil);
|
|
342
|
|
343 bestmatch = Qnil;
|
|
344 blength = 0;
|
|
345 slength = string_char_length (XSTRING (string));
|
|
346
|
|
347 /* If ALIST is not a list, set TAIL just for gc pro. */
|
|
348 tail = alist;
|
|
349 if (!list)
|
|
350 {
|
173
|
351 obsize = XVECTOR_LENGTH (alist);
|
|
352 bucket = XVECTOR_DATA (alist)[indice];
|
|
353 }
|
|
354 else /* warning suppression */
|
|
355 {
|
|
356 obsize = 0;
|
|
357 bucket = Qnil;
|
0
|
358 }
|
|
359
|
|
360 while (1)
|
|
361 {
|
|
362 /* Get the next element of the alist or obarray. */
|
|
363 /* Exit the loop if the elements are all used up. */
|
|
364 /* elt gets the alist element or symbol.
|
|
365 eltstring gets the name to check as a completion. */
|
|
366 Lisp_Object elt;
|
|
367 Lisp_Object eltstring;
|
|
368
|
|
369 if (list)
|
|
370 {
|
|
371 if (NILP (tail))
|
|
372 break;
|
|
373 elt = Fcar (tail);
|
|
374 eltstring = Fcar (elt);
|
|
375 tail = Fcdr (tail);
|
|
376 }
|
|
377 else
|
|
378 {
|
|
379 if (!ZEROP (bucket))
|
|
380 {
|
80
|
381 struct Lisp_Symbol *next;
|
|
382 if (!SYMBOLP (bucket)) {
|
|
383 signal_simple_error("Bad obarry passed to try-completions",
|
|
384 bucket);
|
|
385 }
|
|
386 next = symbol_next (XSYMBOL (bucket));
|
0
|
387 elt = bucket;
|
|
388 eltstring = Fsymbol_name (elt);
|
|
389 if (next)
|
|
390 XSETSYMBOL (bucket, next);
|
|
391 else
|
|
392 bucket = Qzero;
|
|
393 }
|
|
394 else if (++indice >= obsize)
|
|
395 break;
|
|
396 else
|
|
397 {
|
173
|
398 bucket = XVECTOR_DATA (alist)[indice];
|
0
|
399 continue;
|
|
400 }
|
|
401 }
|
|
402
|
|
403 /* Is this element a possible completion? */
|
|
404
|
|
405 if (STRINGP (eltstring))
|
|
406 {
|
|
407 Charcount eltlength = string_char_length (XSTRING (eltstring));
|
|
408 if (slength <= eltlength
|
16
|
409 && (0 > scmp (XSTRING_DATA (eltstring),
|
|
410 XSTRING_DATA (string),
|
0
|
411 slength)))
|
|
412 {
|
|
413 {
|
|
414 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
415 int loser;
|
|
416 GCPRO4 (tail, string, eltstring, bestmatch);
|
|
417 loser = ignore_completion_p (eltstring, pred, elt);
|
|
418 UNGCPRO;
|
|
419 if (loser) /* reject this one */
|
|
420 continue;
|
|
421 }
|
|
422
|
|
423 /* Update computation of how much all possible
|
|
424 completions match */
|
|
425
|
|
426 matchcount++;
|
|
427 if (NILP (bestmatch))
|
|
428 {
|
|
429 bestmatch = eltstring;
|
|
430 blength = eltlength;
|
|
431 bestmatchsize = eltlength;
|
|
432 }
|
|
433 else
|
|
434 {
|
|
435 Charcount compare = min (bestmatchsize, eltlength);
|
|
436 Charcount matchsize =
|
16
|
437 scmp (XSTRING_DATA (bestmatch),
|
|
438 XSTRING_DATA (eltstring),
|
0
|
439 compare);
|
|
440 if (matchsize < 0)
|
|
441 matchsize = compare;
|
|
442 if (completion_ignore_case)
|
|
443 {
|
|
444 /* If this is an exact match except for case,
|
|
445 use it as the best match rather than one that is not
|
|
446 an exact match. This way, we get the case pattern
|
|
447 of the actual match. */
|
|
448 if ((matchsize == eltlength
|
|
449 && matchsize < blength)
|
|
450 ||
|
|
451 /* If there is more than one exact match ignoring
|
|
452 case, and one of them is exact including case,
|
|
453 prefer that one. */
|
|
454 /* If there is no exact match ignoring case,
|
|
455 prefer a match that does not change the case
|
|
456 of the input. */
|
|
457 ((matchsize == eltlength)
|
|
458 ==
|
|
459 (matchsize == blength)
|
16
|
460 && 0 > scmp_1 (XSTRING_DATA (eltstring),
|
|
461 XSTRING_DATA (string),
|
0
|
462 slength, 0)
|
16
|
463 && 0 <= scmp_1 (XSTRING_DATA (bestmatch),
|
173
|
464 XSTRING_DATA (string),
|
0
|
465 slength, 0)))
|
|
466 {
|
|
467 bestmatch = eltstring;
|
|
468 blength = eltlength;
|
|
469 }
|
|
470 }
|
|
471 bestmatchsize = matchsize;
|
|
472 }
|
|
473 }
|
|
474 }
|
|
475 }
|
|
476
|
|
477 if (NILP (bestmatch))
|
|
478 return Qnil; /* No completions found */
|
|
479 /* If we are ignoring case, and there is no exact match,
|
|
480 and no additional text was supplied,
|
|
481 don't change the case of what the user typed. */
|
|
482 if (completion_ignore_case
|
|
483 && bestmatchsize == slength
|
|
484 && blength > bestmatchsize)
|
|
485 return string;
|
|
486
|
|
487 /* Return t if the supplied string is an exact match (counting case);
|
|
488 it does not require any change to be made. */
|
|
489 if (matchcount == 1
|
|
490 && bestmatchsize == slength
|
16
|
491 && 0 > scmp_1 (XSTRING_DATA (bestmatch),
|
|
492 XSTRING_DATA (string),
|
0
|
493 bestmatchsize, 0))
|
|
494 return Qt;
|
|
495
|
|
496 /* Else extract the part in which all completions agree */
|
|
497 return Fsubstring (bestmatch, Qzero, make_int (bestmatchsize));
|
|
498 }
|
|
499
|
|
500
|
20
|
501 DEFUN ("all-completions", Fall_completions, 2, 3, 0, /*
|
0
|
502 Search for partial matches to STRING in ALIST.
|
|
503 Each car of each element of ALIST is tested to see if it begins with STRING.
|
|
504 The value is a list of all the strings from ALIST that match.
|
|
505 ALIST can be an obarray instead of an alist.
|
|
506 Then the print names of all symbols in the obarray are the possible matches.
|
|
507
|
|
508 ALIST can also be a function to do the completion itself.
|
|
509 It receives three arguments: the values STRING, PREDICATE and t.
|
|
510 Whatever it returns becomes the value of `all-completions'.
|
|
511
|
|
512 If optional third argument PREDICATE is non-nil,
|
|
513 it is used to test each possible match.
|
|
514 The match is a candidate only if PREDICATE returns non-nil.
|
|
515 The argument given to PREDICATE is the alist element or
|
|
516 the symbol from the obarray.
|
20
|
517 */
|
|
518 (string, alist, pred))
|
0
|
519 {
|
|
520 /* This function can GC */
|
|
521 Lisp_Object tail;
|
|
522 Lisp_Object allmatches;
|
|
523 int list;
|
|
524 int indice = 0;
|
173
|
525 int obsize;
|
0
|
526 Lisp_Object bucket;
|
|
527 Charcount slength;
|
|
528
|
|
529 CHECK_STRING (string);
|
|
530
|
|
531 if (CONSP (alist))
|
|
532 {
|
|
533 Lisp_Object tem = XCAR (alist);
|
|
534 if (SYMBOLP (tem)) /* lambda, autoload, etc. Emacs-lisp sucks */
|
|
535 return call3 (alist, string, pred, Qt);
|
|
536 else
|
|
537 list = 1;
|
|
538 }
|
|
539 else if (VECTORP (alist))
|
|
540 list = 0;
|
|
541 else if (NILP (alist))
|
|
542 list = 1;
|
|
543 else
|
|
544 return call3 (alist, string, pred, Qt);
|
|
545
|
|
546 allmatches = Qnil;
|
|
547 slength = string_char_length (XSTRING (string));
|
|
548
|
|
549 /* If ALIST is not a list, set TAIL just for gc pro. */
|
|
550 tail = alist;
|
|
551 if (!list)
|
|
552 {
|
173
|
553 obsize = XVECTOR_LENGTH (alist);
|
|
554 bucket = XVECTOR_DATA (alist)[indice];
|
|
555 }
|
|
556 else /* warning suppression */
|
|
557 {
|
|
558 obsize = 0;
|
|
559 bucket = Qnil;
|
0
|
560 }
|
|
561
|
|
562 while (1)
|
|
563 {
|
|
564 /* Get the next element of the alist or obarray. */
|
|
565 /* Exit the loop if the elements are all used up. */
|
|
566 /* elt gets the alist element or symbol.
|
|
567 eltstring gets the name to check as a completion. */
|
|
568 Lisp_Object elt;
|
|
569 Lisp_Object eltstring;
|
|
570
|
|
571 if (list)
|
|
572 {
|
|
573 if (NILP (tail))
|
|
574 break;
|
|
575 elt = Fcar (tail);
|
|
576 eltstring = Fcar (elt);
|
|
577 tail = Fcdr (tail);
|
|
578 }
|
|
579 else
|
|
580 {
|
|
581 if (!ZEROP (bucket))
|
|
582 {
|
|
583 struct Lisp_Symbol *next = symbol_next (XSYMBOL (bucket));
|
|
584 elt = bucket;
|
|
585 eltstring = Fsymbol_name (elt);
|
|
586 if (next)
|
|
587 XSETSYMBOL (bucket, next);
|
|
588 else
|
|
589 bucket = Qzero;
|
|
590 }
|
|
591 else if (++indice >= obsize)
|
|
592 break;
|
|
593 else
|
|
594 {
|
173
|
595 bucket = XVECTOR_DATA (alist)[indice];
|
0
|
596 continue;
|
|
597 }
|
|
598 }
|
|
599
|
|
600 /* Is this element a possible completion? */
|
|
601
|
173
|
602 if (STRINGP (eltstring)
|
0
|
603 && (slength <= string_char_length (XSTRING (eltstring)))
|
|
604 /* Reject alternatives that start with space
|
|
605 unless the input starts with space. */
|
|
606 && ((string_char_length (XSTRING (string)) > 0 &&
|
|
607 string_char (XSTRING (string), 0) == ' ')
|
|
608 || string_char (XSTRING (eltstring), 0) != ' ')
|
16
|
609 && (0 > scmp (XSTRING_DATA (eltstring),
|
|
610 XSTRING_DATA (string),
|
0
|
611 slength)))
|
|
612 {
|
|
613 /* Yes. Now check whether predicate likes it. */
|
|
614 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
615 int loser;
|
|
616 GCPRO4 (tail, eltstring, allmatches, string);
|
|
617 loser = ignore_completion_p (eltstring, pred, elt);
|
|
618 UNGCPRO;
|
|
619 if (!loser)
|
|
620 /* Ok => put it on the list. */
|
|
621 allmatches = Fcons (eltstring, allmatches);
|
|
622 }
|
|
623 }
|
|
624
|
|
625 return Fnreverse (allmatches);
|
|
626 }
|
|
627
|
|
628 /* Useless FSFmacs functions */
|
|
629 /* More than useless. I've nuked minibuf_prompt_width so they won't
|
|
630 function at all in XEmacs at the moment. They are used to
|
|
631 implement some braindamage in FSF which we aren't including. --cet */
|
|
632
|
|
633 #if 0
|
149
|
634 xxDEFUN ("minibuffer-prompt", Fminibuffer_prompt, 0, 0, 0, /*
|
|
635 Return the prompt string of the currently-active minibuffer.
|
|
636 If no minibuffer is active, return nil.
|
|
637 */
|
|
638 ())
|
0
|
639 {
|
173
|
640 return Fcopy_sequence (Vminibuf_prompt);
|
0
|
641 }
|
|
642
|
149
|
643 xxDEFUN ("minibuffer-prompt-width", Fminibuffer_prompt_width, 0, 0, 0, /*
|
|
644 Return the display width of the minibuffer prompt.
|
|
645 */
|
|
646 ())
|
0
|
647 {
|
173
|
648 return make_int (minibuf_prompt_width);
|
0
|
649 }
|
16
|
650 #endif /* 0 */
|
0
|
651
|
|
652
|
|
653 /************************************************************************/
|
|
654 /* echo area */
|
|
655 /************************************************************************/
|
|
656
|
|
657 extern int stdout_needs_newline;
|
|
658
|
|
659 static Lisp_Object
|
|
660 clear_echo_area_internal (struct frame *f, Lisp_Object label, int from_print,
|
|
661 int no_restore)
|
|
662 {
|
116
|
663 /* This function can call lisp */
|
0
|
664 if (!NILP (Ffboundp (Qclear_message)))
|
|
665 {
|
|
666 Lisp_Object frame;
|
|
667
|
|
668 XSETFRAME (frame, f);
|
173
|
669 return call4 (Qclear_message, label, frame, from_print ? Qt : Qnil,
|
0
|
670 no_restore ? Qt : Qnil);
|
|
671 }
|
|
672 else
|
|
673 {
|
|
674 write_string_to_stdio_stream (stderr, 0, (CONST Bufbyte *) "\n", 0, 1,
|
16
|
675 FORMAT_TERMINAL);
|
0
|
676 return Qnil;
|
|
677 }
|
|
678 }
|
|
679
|
|
680 Lisp_Object
|
|
681 clear_echo_area (struct frame *f, Lisp_Object label, int no_restore)
|
|
682 {
|
116
|
683 /* This function can call lisp */
|
0
|
684 return clear_echo_area_internal (f, label, 0, no_restore);
|
|
685 }
|
|
686
|
|
687 Lisp_Object
|
|
688 clear_echo_area_from_print (struct frame *f, Lisp_Object label, int no_restore)
|
|
689 {
|
116
|
690 /* This function can call lisp */
|
0
|
691 return clear_echo_area_internal (f, label, 1, no_restore);
|
|
692 }
|
|
693
|
|
694 void
|
|
695 echo_area_append (struct frame *f, CONST Bufbyte *nonreloc, Lisp_Object reloc,
|
|
696 Bytecount offset, Bytecount length,
|
|
697 Lisp_Object label)
|
|
698 {
|
116
|
699 /* This function can call lisp */
|
0
|
700 Lisp_Object obj;
|
|
701 struct gcpro gcpro1;
|
|
702 Lisp_Object frame;
|
|
703
|
|
704 /* some callers pass in a null string as a way of clearing the echo area.
|
|
705 check for length == 0 now; if this case, neither nonreloc nor reloc
|
|
706 may be valid. */
|
|
707 if (length == 0)
|
|
708 return;
|
173
|
709
|
0
|
710 fixup_internal_substring (nonreloc, reloc, offset, &length);
|
173
|
711
|
0
|
712 /* also check it here, in case the string was really blank. */
|
|
713 if (length == 0)
|
|
714 return;
|
|
715
|
|
716 if (!NILP (Ffboundp (Qappend_message)))
|
|
717 {
|
16
|
718 if (STRINGP (reloc) && offset == 0 && length == XSTRING_LENGTH (reloc))
|
0
|
719 obj = reloc;
|
|
720 else
|
|
721 {
|
|
722 if (STRINGP (reloc))
|
16
|
723 nonreloc = XSTRING_DATA (reloc);
|
0
|
724 obj = make_string (nonreloc + offset, length);
|
|
725 }
|
173
|
726
|
0
|
727 XSETFRAME (frame, f);
|
|
728 GCPRO1 (obj);
|
173
|
729 call4 (Qappend_message, label, obj, frame,
|
0
|
730 EQ (label, Qprint) ? Qt : Qnil);
|
|
731 UNGCPRO;
|
|
732 }
|
|
733 else
|
|
734 {
|
|
735 if (STRINGP (reloc))
|
16
|
736 nonreloc = XSTRING_DATA (reloc);
|
0
|
737 write_string_to_stdio_stream (stderr, 0, nonreloc, offset, length,
|
16
|
738 FORMAT_TERMINAL);
|
0
|
739 }
|
|
740 }
|
|
741
|
|
742 void
|
|
743 echo_area_message (struct frame *f, CONST Bufbyte *nonreloc,
|
|
744 Lisp_Object reloc, Bytecount offset, Bytecount length,
|
|
745 Lisp_Object label)
|
|
746 {
|
116
|
747 /* This function can call lisp */
|
0
|
748 clear_echo_area (f, label, 1);
|
|
749 echo_area_append (f, nonreloc, reloc, offset, length, label);
|
|
750 }
|
|
751
|
|
752 int
|
|
753 echo_area_active (struct frame *f)
|
|
754 {
|
|
755 /* By definition, the echo area is active if the echo-area buffer
|
|
756 is not empty. No need to call Lisp code. (Anyway, this function
|
|
757 is called from redisplay.) */
|
16
|
758 struct buffer *echo_buffer = XBUFFER (Vecho_area_buffer);
|
173
|
759 return BUF_BEGV (echo_buffer) != BUF_ZV (echo_buffer);
|
0
|
760 }
|
|
761
|
|
762 Lisp_Object
|
|
763 echo_area_status (struct frame *f)
|
|
764 {
|
116
|
765 /* This function can call lisp */
|
0
|
766 if (!NILP (Ffboundp (Qcurrent_message_label)))
|
|
767 {
|
|
768 Lisp_Object frame;
|
|
769
|
|
770 XSETFRAME (frame, f);
|
173
|
771 return call1 (Qcurrent_message_label, frame);
|
0
|
772 }
|
|
773 else
|
|
774 return stdout_needs_newline ? Qmessage : Qnil;
|
|
775 }
|
|
776
|
|
777 Lisp_Object
|
|
778 echo_area_contents (struct frame *f)
|
|
779 {
|
|
780 /* See above. By definition, the contents of the echo-area buffer
|
|
781 are the contents of the echo area. */
|
|
782 return Fbuffer_substring (Qnil, Qnil, Vecho_area_buffer);
|
|
783 }
|
|
784
|
|
785 /* Dump an informative message to the echo area. This function takes a
|
|
786 string in internal format. */
|
|
787 void
|
|
788 message_internal (CONST Bufbyte *nonreloc, Lisp_Object reloc,
|
|
789 Bytecount offset, Bytecount length)
|
|
790 {
|
116
|
791 /* This function can call lisp */
|
0
|
792 if (NILP (Vexecuting_macro))
|
|
793 echo_area_message (selected_frame (), nonreloc, reloc, offset, length,
|
|
794 Qmessage);
|
|
795 }
|
|
796
|
|
797 void
|
|
798 message_append_internal (CONST Bufbyte *nonreloc, Lisp_Object reloc,
|
|
799 Bytecount offset, Bytecount length)
|
|
800 {
|
116
|
801 /* This function can call lisp */
|
0
|
802 if (NILP (Vexecuting_macro))
|
|
803 echo_area_append (selected_frame (), nonreloc, reloc, offset, length,
|
|
804 Qmessage);
|
|
805 }
|
|
806
|
|
807 /* The next three functions are interfaces to message_internal() that
|
|
808 take strings in external format. message() does I18N3 translating
|
|
809 on the format string; message_no_translate() does not. */
|
|
810
|
|
811 static void
|
|
812 message_1 (CONST char *fmt, va_list args)
|
|
813 {
|
116
|
814 /* This function can call lisp */
|
0
|
815 if (fmt)
|
|
816 {
|
|
817 struct gcpro gcpro1;
|
|
818 /* message_internal() might GC, e.g. if there are after-change-hooks
|
|
819 on the echo area buffer */
|
|
820 Lisp_Object obj = emacs_doprnt_string_va ((CONST Bufbyte *) fmt, Qnil,
|
|
821 -1, args);
|
|
822 GCPRO1 (obj);
|
|
823 message_internal (0, obj, 0, -1);
|
|
824 UNGCPRO;
|
|
825 }
|
|
826 else
|
|
827 message_internal (0, Qnil, 0, 0);
|
|
828 }
|
|
829
|
|
830 static void
|
|
831 message_append_1 (CONST char *fmt, va_list args)
|
|
832 {
|
116
|
833 /* This function can call lisp */
|
0
|
834 if (fmt)
|
|
835 {
|
|
836 struct gcpro gcpro1;
|
|
837 /* message_internal() might GC, e.g. if there are after-change-hooks
|
|
838 on the echo area buffer */
|
|
839 Lisp_Object obj = emacs_doprnt_string_va ((CONST Bufbyte *) fmt, Qnil,
|
|
840 -1, args);
|
|
841 GCPRO1 (obj);
|
|
842 message_append_internal (0, obj, 0, -1);
|
|
843 UNGCPRO;
|
|
844 }
|
|
845 else
|
|
846 message_append_internal (0, Qnil, 0, 0);
|
|
847 }
|
|
848
|
|
849 void
|
|
850 clear_message (void)
|
|
851 {
|
116
|
852 /* This function can call lisp */
|
0
|
853 message_internal (0, Qnil, 0, 0);
|
|
854 }
|
|
855
|
|
856 void
|
|
857 message (CONST char *fmt, ...)
|
|
858 {
|
116
|
859 /* This function can call lisp */
|
0
|
860 /* I think it's OK to pass the data of Lisp strings as arguments to
|
|
861 this function. No GC'ing will occur until the data has already
|
|
862 been copied. */
|
|
863 va_list args;
|
|
864
|
|
865 va_start (args, fmt);
|
|
866 if (fmt)
|
|
867 fmt = GETTEXT (fmt);
|
|
868 message_1 (fmt, args);
|
|
869 va_end (args);
|
|
870 }
|
|
871
|
|
872 void
|
|
873 message_append (CONST char *fmt, ...)
|
|
874 {
|
116
|
875 /* This function can call lisp */
|
0
|
876 va_list args;
|
|
877
|
|
878 va_start (args, fmt);
|
|
879 if (fmt)
|
|
880 fmt = GETTEXT (fmt);
|
|
881 message_append_1 (fmt, args);
|
|
882 va_end (args);
|
|
883 }
|
|
884
|
|
885 void
|
|
886 message_no_translate (CONST char *fmt, ...)
|
|
887 {
|
116
|
888 /* This function can call lisp */
|
0
|
889 /* I think it's OK to pass the data of Lisp strings as arguments to
|
|
890 this function. No GC'ing will occur until the data has already
|
|
891 been copied. */
|
|
892 va_list args;
|
|
893
|
|
894 va_start (args, fmt);
|
|
895 message_1 (fmt, args);
|
|
896 va_end (args);
|
|
897 }
|
|
898
|
|
899
|
|
900 /************************************************************************/
|
|
901 /* initialization */
|
|
902 /************************************************************************/
|
|
903
|
|
904 void
|
|
905 syms_of_minibuf (void)
|
|
906 {
|
|
907 defsymbol (&Qminibuffer_setup_hook, "minibuffer-setup-hook");
|
|
908
|
|
909 defsymbol (&Qcompletion_ignore_case, "completion-ignore-case");
|
|
910
|
20
|
911 DEFSUBR (Fminibuffer_depth);
|
0
|
912 #if 0
|
20
|
913 DEFSUBR (Fminibuffer_prompt);
|
|
914 DEFSUBR (Fminibuffer_prompt_width);
|
0
|
915 #endif
|
110
|
916 DEFSUBR (Fset_minibuffer_preprompt);
|
20
|
917 DEFSUBR (Fread_minibuffer_internal);
|
0
|
918
|
20
|
919 DEFSUBR (Ftry_completion);
|
|
920 DEFSUBR (Fall_completions);
|
0
|
921
|
|
922 defsymbol (&Qappend_message, "append-message");
|
|
923 defsymbol (&Qclear_message, "clear-message");
|
|
924 defsymbol (&Qdisplay_message, "display-message");
|
|
925 defsymbol (&Qcurrent_message_label, "current-message-label");
|
|
926 }
|
|
927
|
|
928 void
|
|
929 vars_of_minibuf (void)
|
|
930 {
|
|
931 minibuf_level = 0;
|
|
932
|
|
933 staticpro (&Vminibuf_prompt);
|
|
934 Vminibuf_prompt = Qnil;
|
|
935
|
110
|
936 /* Added by Jareth Hein (jhod@po.iijnet.or.jp) for input system support */
|
|
937 staticpro (&Vminibuf_preprompt);
|
|
938 Vminibuf_preprompt = Qnil;
|
173
|
939
|
0
|
940 DEFVAR_LISP ("minibuffer-setup-hook", &Vminibuffer_setup_hook /*
|
|
941 Normal hook run just after entry to minibuffer.
|
|
942 */ );
|
|
943 Vminibuffer_setup_hook = Qnil;
|
|
944
|
|
945 DEFVAR_BOOL ("completion-ignore-case", &completion_ignore_case /*
|
|
946 Non-nil means don't consider case significant in completion.
|
|
947 */ );
|
|
948 completion_ignore_case = 0;
|
|
949
|
|
950 DEFVAR_LISP ("completion-regexp-list", &Vcompletion_regexp_list /*
|
|
951 List of regexps that should restrict possible completions.
|
110
|
952 Each completion has to match all regexps in this list.
|
0
|
953 */ );
|
|
954 Vcompletion_regexp_list = Qnil;
|
|
955 }
|
|
956
|
|
957 void
|
|
958 complex_vars_of_minibuf (void)
|
|
959 {
|
|
960 /* This function can GC */
|
|
961 #ifdef I18N3
|
|
962 /* #### This needs to be fixed up so that the gettext() gets called
|
|
963 at runtime instead of at load time. */
|
|
964 #endif
|
|
965 Vminibuffer_zero
|
|
966 = Fget_buffer_create
|
|
967 (Fpurecopy (build_string (DEFER_GETTEXT (" *Minibuf-0*"))));
|
|
968 Vecho_area_buffer
|
|
969 = Fget_buffer_create
|
|
970 (Fpurecopy (build_string (DEFER_GETTEXT (" *Echo Area*"))));
|
|
971 }
|