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