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