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