171
|
1 /* echo_area.c -- How to read a line in the echo area. */ |
|
2 |
|
3 /* This file is part of GNU Info, a program for reading online documentation |
|
4 stored in Info format. |
|
5 |
|
6 Copyright (C) 1993 Free Software Foundation, Inc. |
|
7 |
|
8 This program is free software; you can redistribute it and/or modify |
|
9 it under the terms of the GNU General Public License as published by |
|
10 the Free Software Foundation; either version 2, or (at your option) |
|
11 any later version. |
|
12 |
|
13 This program is distributed in the hope that it will be useful, |
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 GNU General Public License for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with this program; if not, write to the Free Software |
|
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 Written by Brian Fox (bfox@ai.mit.edu). */ |
|
23 |
|
24 #include "info.h" |
|
25 |
|
26 /* Non-zero means that C-g was used to quit reading input. */ |
|
27 int info_aborted_echo_area = 0; |
|
28 |
|
29 /* Non-zero means that the echo area is being used to read input. */ |
|
30 int echo_area_is_active = 0; |
|
31 |
|
32 /* The address of the last command executed in the echo area. */ |
|
33 VFunction *ea_last_executed_command = (VFunction *)NULL; |
|
34 |
|
35 /* Non-zero means that the last command executed while reading input |
|
36 killed some text. */ |
|
37 int echo_area_last_command_was_kill = 0; |
|
38 |
|
39 /* Variables which hold on to the current state of the input line. */ |
|
40 static char input_line[1 + EA_MAX_INPUT]; |
|
41 static char *input_line_prompt; |
|
42 static int input_line_point; |
|
43 static int input_line_beg; |
|
44 static int input_line_end; |
|
45 static NODE input_line_node = { |
|
46 (char *)NULL, (char *)NULL, (char *)NULL, input_line, EA_MAX_INPUT, 0 |
|
47 }; |
|
48 |
|
49 static void echo_area_initialize_node (); |
|
50 static void push_echo_area (), pop_echo_area (); |
|
51 static int echo_area_stack_depth (), echo_area_stack_contains_completions_p (); |
|
52 |
|
53 static void ea_kill_text (); |
|
54 |
|
55 /* Non-zero means we force the user to complete. */ |
|
56 static int echo_area_must_complete_p = 0; |
|
57 static int completions_window_p (); |
|
58 |
|
59 /* If non-null, this is a window which was specifically created to display |
|
60 possible completions output. We remember it so we can delete it when |
|
61 appropriate. */ |
|
62 static WINDOW *echo_area_completions_window = (WINDOW *)NULL; |
|
63 |
|
64 /* Variables which keep track of the window which was active prior to |
|
65 entering the echo area. */ |
|
66 static WINDOW *calling_window = (WINDOW *)NULL; |
|
67 static NODE *calling_window_node = (NODE *)NULL; |
|
68 static long calling_window_point = 0; |
|
69 static long calling_window_pagetop = 0; |
|
70 |
|
71 /* Remember the node and pertinent variables of the calling window. */ |
|
72 static void |
|
73 remember_calling_window (window) |
|
74 WINDOW *window; |
|
75 { |
|
76 /* Only do this if the calling window is not the completions window, or, |
|
77 if it is the completions window and there is no other window. */ |
|
78 if (!completions_window_p (window) || |
|
79 ((window == windows) && !(window->next))) |
|
80 { |
|
81 calling_window = window; |
|
82 calling_window_node = window->node; |
|
83 calling_window_point = window->point; |
|
84 calling_window_pagetop = window->pagetop; |
|
85 } |
|
86 } |
|
87 |
|
88 /* Restore the caller's window so that it shows the node that it was showing |
|
89 on entry to info_read_xxx_echo_area (). */ |
|
90 static void |
|
91 restore_calling_window () |
|
92 { |
|
93 register WINDOW *win, *compwin = (WINDOW *)NULL; |
|
94 |
|
95 /* If the calling window is still visible, and it is the window that |
|
96 we used for completions output, then restore the calling window. */ |
|
97 for (win = windows; win; win = win->next) |
|
98 { |
|
99 if (completions_window_p (win)) |
|
100 compwin = win; |
|
101 |
|
102 if (win == calling_window && win == compwin) |
|
103 { |
|
104 window_set_node_of_window (calling_window, calling_window_node); |
|
105 calling_window->point = calling_window_point; |
|
106 calling_window->pagetop = calling_window_pagetop; |
|
107 compwin = (WINDOW *)NULL; |
|
108 break; |
|
109 } |
|
110 } |
|
111 |
|
112 /* Delete the completions window if it is still present, it isn't the |
|
113 last window on the screen, and there aren't any prior echo area reads |
|
114 pending which created a completions window. */ |
|
115 if (compwin) |
|
116 { |
|
117 if ((compwin != windows || windows->next) && |
|
118 !echo_area_stack_contains_completions_p ()) |
|
119 { |
|
120 WINDOW *next; |
|
121 int pagetop, start, end, amount; |
|
122 |
|
123 next = compwin->next; |
|
124 if (next) |
|
125 { |
|
126 start = next->first_row; |
|
127 end = start + next->height; |
|
128 amount = - (compwin->height + 1); |
|
129 pagetop = next->pagetop; |
|
130 } |
|
131 |
|
132 info_delete_window_internal (compwin); |
|
133 |
|
134 /* This is not necessary because info_delete_window_internal () |
|
135 calls echo_area_inform_of_deleted_window (), which does the |
|
136 right thing. */ |
|
137 #if defined (UNNECESSARY) |
|
138 echo_area_completions_window = (WINDOW *)NULL; |
|
139 #endif /* UNNECESSARY */ |
|
140 |
|
141 if (next) |
|
142 { |
|
143 display_scroll_display (start, end, amount); |
|
144 next->pagetop = pagetop; |
|
145 display_update_display (windows); |
|
146 } |
|
147 } |
|
148 } |
|
149 } |
|
150 |
|
151 /* Set up a new input line with PROMPT. */ |
|
152 static void |
|
153 initialize_input_line (prompt) |
|
154 char *prompt; |
|
155 { |
|
156 input_line_prompt = prompt; |
|
157 if (prompt) |
|
158 strcpy (input_line, prompt); |
|
159 else |
|
160 input_line[0] = '\0'; |
|
161 |
|
162 input_line_beg = input_line_end = input_line_point = strlen (prompt); |
|
163 } |
|
164 |
|
165 static char * |
|
166 echo_area_after_read () |
|
167 { |
|
168 char *return_value; |
|
169 |
|
170 if (info_aborted_echo_area) |
|
171 { |
|
172 info_aborted_echo_area = 0; |
|
173 return_value = (char *)NULL; |
|
174 } |
|
175 else |
|
176 { |
|
177 if (input_line_beg == input_line_end) |
|
178 return_value = savestring (""); |
|
179 else |
|
180 { |
|
181 int line_len = input_line_end - input_line_beg; |
|
182 return_value = (char *) xmalloc (1 + line_len); |
|
183 strncpy (return_value, &input_line[input_line_beg], line_len); |
|
184 return_value[line_len] = '\0'; |
|
185 } |
|
186 } |
|
187 return (return_value); |
|
188 } |
|
189 |
|
190 /* Read a line of text in the echo area. Return a malloc ()'ed string, |
|
191 or NULL if the user aborted out of this read. WINDOW is the currently |
|
192 active window, so that we can restore it when we need to. PROMPT, if |
|
193 non-null, is a prompt to print before reading the line. */ |
|
194 char * |
|
195 info_read_in_echo_area (window, prompt) |
|
196 WINDOW *window; |
|
197 char *prompt; |
|
198 { |
|
199 char *line; |
|
200 |
|
201 /* If the echo area is already active, remember the current state. */ |
|
202 if (echo_area_is_active) |
|
203 push_echo_area (); |
|
204 |
|
205 /* Initialize our local variables. */ |
|
206 initialize_input_line (prompt); |
|
207 |
|
208 /* Initialize the echo area for the first (but maybe not the last) time. */ |
|
209 echo_area_initialize_node (); |
|
210 |
|
211 /* Save away the original node of this window, and the window itself, |
|
212 so echo area commands can temporarily use this window. */ |
|
213 remember_calling_window (window); |
|
214 |
|
215 /* Let the rest of Info know that the echo area is active. */ |
|
216 echo_area_is_active++; |
|
217 active_window = the_echo_area; |
|
218 |
|
219 /* Read characters in the echo area. */ |
|
220 info_read_and_dispatch (); |
|
221 |
|
222 echo_area_is_active--; |
|
223 |
|
224 /* Restore the original active window and show point in it. */ |
|
225 active_window = calling_window; |
|
226 restore_calling_window (); |
|
227 display_cursor_at_point (active_window); |
|
228 fflush (stdout); |
|
229 |
|
230 /* Get the value of the line. */ |
|
231 line = echo_area_after_read (); |
|
232 |
|
233 /* If there is a previous loop waiting for us, restore it now. */ |
|
234 if (echo_area_is_active) |
|
235 pop_echo_area (); |
|
236 |
|
237 /* Return the results to the caller. */ |
|
238 return (line); |
|
239 } |
|
240 |
|
241 /* (re) Initialize the echo area node. */ |
|
242 static void |
|
243 echo_area_initialize_node () |
|
244 { |
|
245 register int i; |
|
246 |
|
247 for (i = input_line_end; i < sizeof (input_line); i++) |
|
248 input_line[i] = ' '; |
|
249 |
|
250 input_line[i - 1] = '\n'; |
|
251 window_set_node_of_window (the_echo_area, &input_line_node); |
|
252 input_line[input_line_end] = '\n'; |
|
253 } |
|
254 |
|
255 /* Prepare to read characters in the echo area. This can initialize the |
|
256 echo area node, but its primary purpose is to side effect the input |
|
257 line buffer contents. */ |
|
258 void |
|
259 echo_area_prep_read () |
|
260 { |
|
261 if (the_echo_area->node != &input_line_node) |
|
262 echo_area_initialize_node (); |
|
263 |
|
264 the_echo_area->point = input_line_point; |
|
265 input_line[input_line_end] = '\n'; |
|
266 display_update_one_window (the_echo_area); |
|
267 display_cursor_at_point (active_window); |
|
268 } |
|
269 |
|
270 |
|
271 /* **************************************************************** */ |
|
272 /* */ |
|
273 /* Echo Area Movement Commands */ |
|
274 /* */ |
|
275 /* **************************************************************** */ |
|
276 |
|
277 DECLARE_INFO_COMMAND (ea_forward, "Move forward a character") |
|
278 { |
|
279 if (count < 0) |
|
280 ea_backward (window, -count, key); |
|
281 else |
|
282 { |
|
283 input_line_point += count; |
|
284 if (input_line_point > input_line_end) |
|
285 input_line_point = input_line_end; |
|
286 } |
|
287 } |
|
288 |
|
289 DECLARE_INFO_COMMAND (ea_backward, "Move backward a character") |
|
290 { |
|
291 if (count < 0) |
|
292 ea_forward (window, -count, key); |
|
293 else |
|
294 { |
|
295 input_line_point -= count; |
|
296 if (input_line_point < input_line_beg) |
|
297 input_line_point = input_line_beg; |
|
298 } |
|
299 } |
|
300 |
|
301 DECLARE_INFO_COMMAND (ea_beg_of_line, "Move to the start of this line") |
|
302 { |
|
303 input_line_point = input_line_beg; |
|
304 } |
|
305 |
|
306 DECLARE_INFO_COMMAND (ea_end_of_line, "Move to the end of this line") |
|
307 { |
|
308 input_line_point = input_line_end; |
|
309 } |
|
310 |
|
311 #define alphabetic(c) (islower (c) || isupper (c) || isdigit (c)) |
|
312 |
|
313 /* Move forward a word in the input line. */ |
|
314 DECLARE_INFO_COMMAND (ea_forward_word, "Move forward a word") |
|
315 { |
|
316 int c; |
|
317 |
|
318 if (count < 0) |
|
319 ea_backward_word (window, -count, key); |
|
320 else |
|
321 { |
|
322 while (count--) |
|
323 { |
|
324 if (input_line_point == input_line_end) |
|
325 return; |
|
326 |
|
327 /* If we are not in a word, move forward until we are in one. |
|
328 Then, move forward until we hit a non-alphabetic character. */ |
|
329 c = input_line[input_line_point]; |
|
330 |
|
331 if (!alphabetic (c)) |
|
332 { |
|
333 while (++input_line_point < input_line_end) |
|
334 { |
|
335 c = input_line[input_line_point]; |
|
336 if (alphabetic (c)) |
|
337 break; |
|
338 } |
|
339 } |
|
340 |
|
341 if (input_line_point == input_line_end) |
|
342 return; |
|
343 |
|
344 while (++input_line_point < input_line_end) |
|
345 { |
|
346 c = input_line[input_line_point]; |
|
347 if (!alphabetic (c)) |
|
348 break; |
|
349 } |
|
350 } |
|
351 } |
|
352 } |
|
353 |
|
354 DECLARE_INFO_COMMAND (ea_backward_word, "Move backward a word") |
|
355 { |
|
356 int c; |
|
357 |
|
358 if (count < 0) |
|
359 ea_forward_word (window, -count, key); |
|
360 else |
|
361 { |
|
362 while (count--) |
|
363 { |
|
364 if (input_line_point == input_line_beg) |
|
365 return; |
|
366 |
|
367 /* Like ea_forward_word (), except that we look at the |
|
368 characters just before point. */ |
|
369 |
|
370 c = input_line[input_line_point - 1]; |
|
371 |
|
372 if (!alphabetic (c)) |
|
373 { |
|
374 while (--input_line_point) |
|
375 { |
|
376 c = input_line[input_line_point - 1]; |
|
377 if (alphabetic (c)) |
|
378 break; |
|
379 } |
|
380 } |
|
381 |
|
382 while (input_line_point != input_line_beg) |
|
383 { |
|
384 c = input_line[input_line_point - 1]; |
|
385 if (!alphabetic (c)) |
|
386 break; |
|
387 else |
|
388 --input_line_point; |
|
389 } |
|
390 } |
|
391 } |
|
392 } |
|
393 |
|
394 DECLARE_INFO_COMMAND (ea_delete, "Delete the character under the cursor") |
|
395 { |
|
396 register int i; |
|
397 |
|
398 if (count < 0) |
|
399 ea_rubout (window, -count, key); |
|
400 else |
|
401 { |
|
402 if (input_line_point == input_line_end) |
|
403 return; |
|
404 |
|
405 if (info_explicit_arg || count > 1) |
|
406 { |
|
407 int orig_point; |
|
408 |
|
409 orig_point = input_line_point; |
|
410 ea_forward (window, count, key); |
|
411 ea_kill_text (orig_point, input_line_point); |
|
412 input_line_point = orig_point; |
|
413 } |
|
414 else |
|
415 { |
|
416 for (i = input_line_point; i < input_line_end; i++) |
|
417 input_line[i] = input_line[i + 1]; |
|
418 |
|
419 input_line_end--; |
|
420 } |
|
421 } |
|
422 } |
|
423 |
|
424 DECLARE_INFO_COMMAND (ea_rubout, "Delete the character behind the cursor") |
|
425 { |
|
426 if (count < 0) |
|
427 ea_delete (window, -count, key); |
|
428 else |
|
429 { |
|
430 int start; |
|
431 |
|
432 if (input_line_point == input_line_beg) |
|
433 return; |
|
434 |
|
435 start = input_line_point; |
|
436 ea_backward (window, count, key); |
|
437 |
|
438 if (info_explicit_arg || count > 1) |
|
439 ea_kill_text (start, input_line_point); |
|
440 else |
|
441 ea_delete (window, count, key); |
|
442 } |
|
443 } |
|
444 |
|
445 DECLARE_INFO_COMMAND (ea_abort, "Cancel or quit operation") |
|
446 { |
|
447 /* If any text, just discard it, and restore the calling window's node. |
|
448 If no text, quit. */ |
|
449 if (input_line_end != input_line_beg) |
|
450 { |
|
451 terminal_ring_bell (); |
|
452 input_line_end = input_line_point = input_line_beg; |
|
453 if (calling_window->node != calling_window_node) |
|
454 restore_calling_window (); |
|
455 } |
|
456 else |
|
457 info_aborted_echo_area = 1; |
|
458 } |
|
459 |
|
460 DECLARE_INFO_COMMAND (ea_newline, "Accept (or force completion of) this line") |
|
461 { |
|
462 /* Stub does nothing. Simply here to see if it has been executed. */ |
|
463 } |
|
464 |
|
465 DECLARE_INFO_COMMAND (ea_quoted_insert, "Insert next character verbatim") |
|
466 { |
|
467 unsigned char character; |
|
468 |
|
469 character = info_get_another_input_char (); |
|
470 ea_insert (window, count, character); |
|
471 } |
|
472 |
|
473 DECLARE_INFO_COMMAND (ea_insert, "Insert this character") |
|
474 { |
|
475 register int i; |
|
476 |
|
477 if ((input_line_end + 1) == EA_MAX_INPUT) |
|
478 { |
|
479 terminal_ring_bell (); |
|
480 return; |
|
481 } |
|
482 |
|
483 for (i = input_line_end + 1; i != input_line_point; i--) |
|
484 input_line[i] = input_line[i - 1]; |
|
485 |
|
486 input_line[input_line_point] = key; |
|
487 input_line_point++; |
|
488 input_line_end++; |
|
489 } |
|
490 |
|
491 DECLARE_INFO_COMMAND (ea_tab_insert, "Insert a TAB character") |
|
492 { |
|
493 ea_insert (window, count, '\t'); |
|
494 } |
|
495 |
|
496 /* Transpose the characters at point. If point is at the end of the line, |
|
497 then transpose the characters before point. */ |
|
498 DECLARE_INFO_COMMAND (ea_transpose_chars, "Transpose characters at point") |
|
499 { |
|
500 /* Handle conditions that would make it impossible to transpose |
|
501 characters. */ |
|
502 if (!count || !input_line_point || (input_line_end - input_line_beg) < 2) |
|
503 return; |
|
504 |
|
505 while (count) |
|
506 { |
|
507 int t; |
|
508 if (input_line_point == input_line_end) |
|
509 { |
|
510 t = input_line[input_line_point - 1]; |
|
511 |
|
512 input_line[input_line_point - 1] = input_line[input_line_point - 2]; |
|
513 input_line[input_line_point - 2] = t; |
|
514 } |
|
515 else |
|
516 { |
|
517 t = input_line[input_line_point]; |
|
518 |
|
519 input_line[input_line_point] = input_line[input_line_point - 1]; |
|
520 input_line[input_line_point - 1] = t; |
|
521 |
|
522 if (count < 0 && input_line_point != input_line_beg) |
|
523 input_line_point--; |
|
524 else |
|
525 input_line_point++; |
|
526 } |
|
527 |
|
528 if (count < 0) |
|
529 count++; |
|
530 else |
|
531 count--; |
|
532 } |
|
533 } |
|
534 |
|
535 /* **************************************************************** */ |
|
536 /* */ |
|
537 /* Echo Area Killing and Yanking */ |
|
538 /* */ |
|
539 /* **************************************************************** */ |
|
540 |
|
541 static char **kill_ring = (char **)NULL; |
|
542 static int kill_ring_index = 0; /* Number of kills appearing in KILL_RING. */ |
|
543 static int kill_ring_slots = 0; /* Number of slots allocated to KILL_RING. */ |
|
544 static int kill_ring_loc = 0; /* Location of current yank pointer. */ |
|
545 |
|
546 /* The largest number of kills that we remember at one time. */ |
|
547 static int max_retained_kills = 15; |
|
548 |
|
549 DECLARE_INFO_COMMAND (ea_yank, "Yank back the contents of the last kill") |
|
550 { |
|
551 register int i; |
|
552 register char *text; |
|
553 |
|
554 if (!kill_ring_index) |
|
555 { |
|
556 inform_in_echo_area ("Kill ring is empty"); |
|
557 return; |
|
558 } |
|
559 |
|
560 text = kill_ring[kill_ring_loc]; |
|
561 |
|
562 for (i = 0; text[i]; i++) |
|
563 ea_insert (window, 1, text[i]); |
|
564 } |
|
565 |
|
566 /* If the last command was yank, or yank_pop, and the text just before |
|
567 point is identical to the current kill item, then delete that text |
|
568 from the line, rotate the index down, and yank back some other text. */ |
|
569 DECLARE_INFO_COMMAND (ea_yank_pop, "Yank back a previous kill") |
|
570 { |
|
571 register int len; |
|
572 |
|
573 if (((ea_last_executed_command != ea_yank) && |
|
574 (ea_last_executed_command != ea_yank_pop)) || |
|
575 (kill_ring_index == 0)) |
|
576 return; |
|
577 |
|
578 len = strlen (kill_ring[kill_ring_loc]); |
|
579 |
|
580 /* Delete the last yanked item from the line. */ |
|
581 { |
|
582 register int i, counter; |
|
583 |
|
584 counter = input_line_end - input_line_point; |
|
585 |
|
586 for (i = input_line_point - len; counter; i++, counter--) |
|
587 input_line[i] = input_line[i + len]; |
|
588 |
|
589 input_line_end -= len; |
|
590 input_line_point -= len; |
|
591 } |
|
592 |
|
593 /* Get a previous kill, and yank that. */ |
|
594 kill_ring_loc--; |
|
595 if (kill_ring_loc < 0) |
|
596 kill_ring_loc = kill_ring_index - 1; |
|
597 |
|
598 ea_yank (window, count, key); |
|
599 } |
|
600 |
|
601 /* Delete the text from point to end of line. */ |
|
602 DECLARE_INFO_COMMAND (ea_kill_line, "Kill to the end of the line") |
|
603 { |
|
604 if (count < 0) |
|
605 { |
|
606 ea_kill_text (input_line_point, input_line_beg); |
|
607 input_line_point = input_line_beg; |
|
608 } |
|
609 else |
|
610 ea_kill_text (input_line_point, input_line_end); |
|
611 } |
|
612 |
|
613 /* Delete the text from point to beg of line. */ |
|
614 DECLARE_INFO_COMMAND (ea_backward_kill_line, |
|
615 "Kill to the beginning of the line") |
|
616 { |
|
617 if (count < 0) |
|
618 ea_kill_text (input_line_point, input_line_end); |
|
619 else |
|
620 { |
|
621 ea_kill_text (input_line_point, input_line_beg); |
|
622 input_line_point = input_line_beg; |
|
623 } |
|
624 } |
|
625 |
|
626 /* Delete from point to the end of the current word. */ |
|
627 DECLARE_INFO_COMMAND (ea_kill_word, "Kill the word following the cursor") |
|
628 { |
|
629 int orig_point = input_line_point; |
|
630 |
|
631 if (count < 0) |
|
632 ea_backward_kill_word (window, -count, key); |
|
633 else |
|
634 { |
|
635 ea_forward_word (window, count, key); |
|
636 |
|
637 if (input_line_point != orig_point) |
|
638 ea_kill_text (orig_point, input_line_point); |
|
639 |
|
640 input_line_point = orig_point; |
|
641 } |
|
642 } |
|
643 |
|
644 /* Delete from point to the start of the current word. */ |
|
645 DECLARE_INFO_COMMAND (ea_backward_kill_word, |
|
646 "Kill the word preceding the cursor") |
|
647 { |
|
648 int orig_point = input_line_point; |
|
649 |
|
650 if (count < 0) |
|
651 ea_kill_word (window, -count, key); |
|
652 else |
|
653 { |
|
654 ea_backward_word (window, count, key); |
|
655 |
|
656 if (input_line_point != orig_point) |
|
657 ea_kill_text (orig_point, input_line_point); |
|
658 } |
|
659 } |
|
660 |
|
661 /* The way to kill something. This appends or prepends to the last |
|
662 kill, if the last command was a kill command. If FROM is less |
|
663 than TO, then the killed text is appended to the most recent kill, |
|
664 otherwise it is prepended. If the last command was not a kill command, |
|
665 then a new slot is made for this kill. */ |
|
666 static void |
|
667 ea_kill_text (from, to) |
|
668 int from, to; |
|
669 { |
|
670 register int i, counter, distance; |
|
671 int killing_backwards, slot; |
|
672 char *killed_text; |
|
673 |
|
674 killing_backwards = (from > to); |
|
675 |
|
676 /* If killing backwards, reverse the values of FROM and TO. */ |
|
677 if (killing_backwards) |
|
678 { |
|
679 int temp = from; |
|
680 from = to; |
|
681 to = temp; |
|
682 } |
|
683 |
|
684 /* Remember the text that we are about to delete. */ |
|
685 distance = to - from; |
|
686 killed_text = (char *)xmalloc (1 + distance); |
|
687 strncpy (killed_text, &input_line[from], distance); |
|
688 killed_text[distance] = '\0'; |
|
689 |
|
690 /* Actually delete the text from the line. */ |
|
691 counter = input_line_end - to; |
|
692 |
|
693 for (i = from; counter; i++, counter--) |
|
694 input_line[i] = input_line[i + distance]; |
|
695 |
|
696 input_line_end -= distance; |
|
697 |
|
698 /* If the last command was a kill, append or prepend the killed text to |
|
699 the last command's killed text. */ |
|
700 if (echo_area_last_command_was_kill) |
|
701 { |
|
702 char *old, *new; |
|
703 |
|
704 slot = kill_ring_loc; |
|
705 old = kill_ring[slot]; |
|
706 new = (char *)xmalloc (1 + strlen (old) + strlen (killed_text)); |
|
707 |
|
708 if (killing_backwards) |
|
709 { |
|
710 /* Prepend TEXT to current kill. */ |
|
711 strcpy (new, killed_text); |
|
712 strcat (new, old); |
|
713 } |
|
714 else |
|
715 { |
|
716 /* Append TEXT to current kill. */ |
|
717 strcpy (new, old); |
|
718 strcat (new, killed_text); |
|
719 } |
|
720 |
|
721 free (old); |
|
722 free (killed_text); |
|
723 kill_ring[slot] = new; |
|
724 } |
|
725 else |
|
726 { |
|
727 /* Try to store the kill in a new slot, unless that would cause there |
|
728 to be too many remembered kills. */ |
|
729 slot = kill_ring_index; |
|
730 |
|
731 if (slot == max_retained_kills) |
|
732 slot = 0; |
|
733 |
|
734 if (slot + 1 > kill_ring_slots) |
|
735 kill_ring = (char **) xrealloc |
|
736 (kill_ring, |
|
737 (kill_ring_slots += max_retained_kills) * sizeof (char *)); |
|
738 |
|
739 if (slot != kill_ring_index) |
|
740 free (kill_ring[slot]); |
|
741 else |
|
742 kill_ring_index++; |
|
743 |
|
744 kill_ring[slot] = killed_text; |
|
745 |
|
746 kill_ring_loc = slot; |
|
747 } |
|
748 |
|
749 /* Notice that the last command was a kill. */ |
|
750 echo_area_last_command_was_kill++; |
|
751 } |
|
752 |
|
753 /* **************************************************************** */ |
|
754 /* */ |
|
755 /* Echo Area Completion */ |
|
756 /* */ |
|
757 /* **************************************************************** */ |
|
758 |
|
759 /* Pointer to an array of REFERENCE to complete over. */ |
|
760 static REFERENCE **echo_area_completion_items = (REFERENCE **)NULL; |
|
761 |
|
762 /* Sorted array of REFERENCE * which is the possible completions found in |
|
763 the variable echo_area_completion_items. If there is only one element, |
|
764 it is the only possible completion. */ |
|
765 static REFERENCE **completions_found = (REFERENCE **)NULL; |
|
766 static int completions_found_index = 0; |
|
767 static int completions_found_slots = 0; |
|
768 |
|
769 /* The lowest common denominator found while completing. */ |
|
770 static REFERENCE *LCD_completion; |
|
771 |
|
772 /* Internal functions used by the user calls. */ |
|
773 static void build_completions (), completions_must_be_rebuilt (); |
|
774 |
|
775 /* Variable which holds the output of completions. */ |
|
776 static NODE *possible_completions_output_node = (NODE *)NULL; |
|
777 |
|
778 static char *compwin_name = "*Completions*"; |
|
779 |
|
780 /* Return non-zero if WINDOW is a window used for completions output. */ |
|
781 static int |
|
782 completions_window_p (window) |
|
783 WINDOW *window; |
|
784 { |
|
785 int result = 0; |
|
786 |
|
787 if (internal_info_node_p (window->node) && |
|
788 (strcmp (window->node->nodename, compwin_name) == 0)) |
|
789 result = 1; |
|
790 |
|
791 return (result); |
|
792 } |
|
793 |
|
794 /* Workhorse for completion readers. If FORCE is non-zero, the user cannot |
|
795 exit unless the line read completes, or is empty. */ |
|
796 char * |
|
797 info_read_completing_internal (window, prompt, completions, force) |
|
798 WINDOW *window; |
|
799 char *prompt; |
|
800 REFERENCE **completions; |
|
801 int force; |
|
802 { |
|
803 char *line; |
|
804 |
|
805 /* If the echo area is already active, remember the current state. */ |
|
806 if (echo_area_is_active) |
|
807 push_echo_area (); |
|
808 |
|
809 echo_area_must_complete_p = force; |
|
810 |
|
811 /* Initialize our local variables. */ |
|
812 initialize_input_line (prompt); |
|
813 |
|
814 /* Initialize the echo area for the first (but maybe not the last) time. */ |
|
815 echo_area_initialize_node (); |
|
816 |
|
817 /* Save away the original node of this window, and the window itself, |
|
818 so echo area commands can temporarily use this window. */ |
|
819 remember_calling_window (window); |
|
820 |
|
821 /* Save away the list of items to complete over. */ |
|
822 echo_area_completion_items = completions; |
|
823 completions_must_be_rebuilt (); |
|
824 |
|
825 active_window = the_echo_area; |
|
826 echo_area_is_active++; |
|
827 |
|
828 /* Read characters in the echo area. */ |
|
829 while (1) |
|
830 { |
|
831 info_read_and_dispatch (); |
|
832 |
|
833 line = echo_area_after_read (); |
|
834 |
|
835 /* Force the completion to take place if the user hasn't accepted |
|
836 a default or aborted, and if FORCE is active. */ |
|
837 if (force && line && *line && completions) |
|
838 { |
|
839 register int i; |
|
840 |
|
841 build_completions (); |
|
842 |
|
843 /* If there is only one completion, then make the line be that |
|
844 completion. */ |
|
845 if (completions_found_index == 1) |
|
846 { |
|
847 free (line); |
|
848 line = savestring (completions_found[0]->label); |
|
849 break; |
|
850 } |
|
851 |
|
852 /* If one of the completions matches exactly, then that is okay, so |
|
853 return the current line. */ |
|
854 for (i = 0; i < completions_found_index; i++) |
|
855 if (stricmp (completions_found[i]->label, line) == 0) |
|
856 { |
|
857 free (line); |
|
858 line = savestring (completions_found[i]->label); |
|
859 break; |
|
860 } |
|
861 |
|
862 /* If no match, go back and try again. */ |
|
863 if (i == completions_found_index) |
|
864 { |
|
865 inform_in_echo_area ("Not complete"); |
|
866 continue; |
|
867 } |
|
868 } |
|
869 break; |
|
870 } |
|
871 echo_area_is_active--; |
|
872 |
|
873 /* Restore the original active window and show point in it. */ |
|
874 active_window = calling_window; |
|
875 restore_calling_window (); |
|
876 display_cursor_at_point (active_window); |
|
877 fflush (stdout); |
|
878 |
|
879 echo_area_completion_items = (REFERENCE **)NULL; |
|
880 completions_must_be_rebuilt (); |
|
881 |
|
882 /* If there is a previous loop waiting for us, restore it now. */ |
|
883 if (echo_area_is_active) |
|
884 pop_echo_area (); |
|
885 |
|
886 return (line); |
|
887 } |
|
888 |
|
889 /* Read a line in the echo area with completion over COMPLETIONS. */ |
|
890 char * |
|
891 info_read_completing_in_echo_area (window, prompt, completions) |
|
892 WINDOW *window; |
|
893 char *prompt; |
|
894 REFERENCE **completions; |
|
895 { |
|
896 return (info_read_completing_internal (window, prompt, completions, 1)); |
|
897 } |
|
898 |
|
899 /* Read a line in the echo area allowing completion over COMPLETIONS, but |
|
900 not requiring it. */ |
|
901 char * |
|
902 info_read_maybe_completing (window, prompt, completions) |
|
903 WINDOW *window; |
|
904 char *prompt; |
|
905 REFERENCE **completions; |
|
906 { |
|
907 return (info_read_completing_internal (window, prompt, completions, 0)); |
|
908 } |
|
909 |
|
910 DECLARE_INFO_COMMAND (ea_possible_completions, "List possible completions") |
|
911 { |
|
912 if (!echo_area_completion_items) |
|
913 { |
|
914 ea_insert (window, count, key); |
|
915 return; |
|
916 } |
|
917 |
|
918 build_completions (); |
|
919 |
|
920 if (!completions_found_index) |
|
921 { |
|
922 terminal_ring_bell (); |
|
923 inform_in_echo_area ("No completions"); |
|
924 } |
|
925 else if ((completions_found_index == 1) && (key != '?')) |
|
926 { |
|
927 inform_in_echo_area ("Sole completion"); |
|
928 } |
|
929 else |
|
930 { |
|
931 register int i, l; |
|
932 int limit, count, max_label = 0; |
|
933 |
|
934 initialize_message_buffer (); |
|
935 printf_to_message_buffer |
|
936 ("There %s %d ", completions_found_index == 1 ? "is" : "are", |
|
937 completions_found_index); |
|
938 printf_to_message_buffer |
|
939 ("completion%s:\n", completions_found_index == 1 ? "" : "s"); |
|
940 |
|
941 /* Find the maximum length of a label. */ |
|
942 for (i = 0; i < completions_found_index; i++) |
|
943 { |
|
944 int len = strlen (completions_found[i]->label); |
|
945 if (len > max_label) |
|
946 max_label = len; |
|
947 } |
|
948 |
|
949 max_label += 4; |
|
950 |
|
951 /* Find out how many columns we should print in. */ |
|
952 limit = calling_window->width / max_label; |
|
953 if (limit != 1 && (limit * max_label == calling_window->width)) |
|
954 limit--; |
|
955 |
|
956 /* Avoid a possible floating exception. If max_label > width then |
|
957 the limit will be 0 and a divide-by-zero fault will result. */ |
|
958 if (limit == 0) |
|
959 limit = 1; |
|
960 |
|
961 /* How many iterations of the printing loop? */ |
|
962 count = (completions_found_index + (limit - 1)) / limit; |
|
963 |
|
964 /* Watch out for special case. If the number of completions is less |
|
965 than LIMIT, then just do the inner printing loop. */ |
|
966 if (completions_found_index < limit) |
|
967 count = 1; |
|
968 |
|
969 /* Print the sorted items, up-and-down alphabetically. */ |
|
970 for (i = 0; i < count; i++) |
|
971 { |
|
972 register int j; |
|
973 |
|
974 for (j = 0, l = i; j < limit; j++) |
|
975 { |
|
976 if (l >= completions_found_index) |
|
977 break; |
|
978 else |
|
979 { |
|
980 char *label; |
|
981 int printed_length, k; |
|
982 |
|
983 label = completions_found[l]->label; |
|
984 printed_length = strlen (label); |
|
985 printf_to_message_buffer ("%s", label); |
|
986 |
|
987 if (j + 1 < limit) |
|
988 { |
|
989 for (k = 0; k < max_label - printed_length; k++) |
|
990 printf_to_message_buffer (" "); |
|
991 } |
|
992 } |
|
993 l += count; |
|
994 } |
|
995 printf_to_message_buffer ("\n"); |
|
996 } |
|
997 |
|
998 /* Make a new node to hold onto possible completions. Don't destroy |
|
999 dangling pointers. */ |
|
1000 { |
|
1001 NODE *temp; |
|
1002 |
|
1003 temp = message_buffer_to_node (); |
|
1004 add_gcable_pointer (temp->contents); |
|
1005 name_internal_node (temp, compwin_name); |
|
1006 possible_completions_output_node = temp; |
|
1007 } |
|
1008 |
|
1009 /* Find a suitable window for displaying the completions output. |
|
1010 First choice is an existing window showing completions output. |
|
1011 If there is only one window, and it is large, make another |
|
1012 (smaller) window, and use that one. Otherwise, use the caller's |
|
1013 window. */ |
|
1014 { |
|
1015 WINDOW *compwin; |
|
1016 |
|
1017 compwin = get_internal_info_window (compwin_name); |
|
1018 |
|
1019 if (!compwin) |
|
1020 { |
|
1021 /* If we can split the window to display most of the completion |
|
1022 items, then do so. */ |
|
1023 if (calling_window->height > (count * 2)) |
|
1024 { |
|
1025 int start, end, pagetop; |
|
1026 |
|
1027 active_window = calling_window; |
|
1028 |
|
1029 /* Perhaps we can scroll this window on redisplay. */ |
|
1030 start = calling_window->first_row; |
|
1031 pagetop = calling_window->pagetop; |
|
1032 |
|
1033 compwin = |
|
1034 window_make_window (possible_completions_output_node); |
|
1035 active_window = the_echo_area; |
|
1036 window_change_window_height |
|
1037 (compwin, -(compwin->height - (count + 2))); |
|
1038 |
|
1039 window_adjust_pagetop (calling_window); |
|
1040 remember_calling_window (calling_window); |
|
1041 |
|
1042 #if defined (SPLIT_BEFORE_ACTIVE) |
|
1043 /* If the pagetop hasn't changed, scrolling the calling |
|
1044 window is a reasonable thing to do. */ |
|
1045 if (pagetop == calling_window->pagetop) |
|
1046 { |
|
1047 end = start + calling_window->height; |
|
1048 display_scroll_display |
|
1049 (start, end, calling_window->prev->height + 1); |
|
1050 } |
|
1051 #else /* !SPLIT_BEFORE_ACTIVE */ |
|
1052 /* If the pagetop has changed, set the new pagetop here. */ |
|
1053 if (pagetop != calling_window->pagetop) |
|
1054 { |
|
1055 int newtop = calling_window->pagetop; |
|
1056 calling_window->pagetop = pagetop; |
|
1057 set_window_pagetop (calling_window, newtop); |
|
1058 } |
|
1059 #endif /* !SPLIT_BEFORE_ACTIVE */ |
|
1060 |
|
1061 echo_area_completions_window = compwin; |
|
1062 remember_window_and_node (compwin, compwin->node); |
|
1063 } |
|
1064 else |
|
1065 compwin = calling_window; |
|
1066 } |
|
1067 |
|
1068 if (compwin->node != possible_completions_output_node) |
|
1069 { |
|
1070 window_set_node_of_window |
|
1071 (compwin, possible_completions_output_node); |
|
1072 remember_window_and_node (compwin, compwin->node); |
|
1073 } |
|
1074 |
|
1075 display_update_display (windows); |
|
1076 } |
|
1077 } |
|
1078 } |
|
1079 |
|
1080 DECLARE_INFO_COMMAND (ea_complete, "Insert completion") |
|
1081 { |
|
1082 if (!echo_area_completion_items) |
|
1083 { |
|
1084 ea_insert (window, count, key); |
|
1085 return; |
|
1086 } |
|
1087 |
|
1088 /* If KEY is SPC, and we are not forcing completion to take place, simply |
|
1089 insert the key. */ |
|
1090 if (!echo_area_must_complete_p && key == SPC) |
|
1091 { |
|
1092 ea_insert (window, count, key); |
|
1093 return; |
|
1094 } |
|
1095 |
|
1096 if (ea_last_executed_command == ea_complete) |
|
1097 { |
|
1098 /* If the keypress is a SPC character, and we have already tried |
|
1099 completing once, and there are several completions, then check |
|
1100 the batch of completions to see if any continue with a space. |
|
1101 If there are some, insert the space character and continue. */ |
|
1102 if (key == SPC && completions_found_index > 1) |
|
1103 { |
|
1104 register int i, offset; |
|
1105 |
|
1106 offset = input_line_end - input_line_beg; |
|
1107 |
|
1108 for (i = 0; i < completions_found_index; i++) |
|
1109 if (completions_found[i]->label[offset] == ' ') |
|
1110 break; |
|
1111 |
|
1112 if (completions_found[i]) |
|
1113 ea_insert (window, 1, ' '); |
|
1114 else |
|
1115 { |
|
1116 ea_possible_completions (window, count, key); |
|
1117 return; |
|
1118 } |
|
1119 } |
|
1120 else |
|
1121 { |
|
1122 ea_possible_completions (window, count, key); |
|
1123 return; |
|
1124 } |
|
1125 } |
|
1126 |
|
1127 input_line_point = input_line_end; |
|
1128 build_completions (); |
|
1129 |
|
1130 if (!completions_found_index) |
|
1131 terminal_ring_bell (); |
|
1132 else if (LCD_completion->label[0] == '\0') |
|
1133 ea_possible_completions (window, count, key); |
|
1134 else |
|
1135 { |
|
1136 register int i; |
|
1137 input_line_point = input_line_end = input_line_beg; |
|
1138 for (i = 0; LCD_completion->label[i]; i++) |
|
1139 ea_insert (window, 1, LCD_completion->label[i]); |
|
1140 } |
|
1141 } |
|
1142 |
|
1143 /* Utility REFERENCE used to store possible LCD. */ |
|
1144 static REFERENCE LCD_reference = { (char *)NULL, (char *)NULL, (char *)NULL }; |
|
1145 |
|
1146 static void remove_completion_duplicates (); |
|
1147 |
|
1148 /* Variables which remember the state of the most recent call |
|
1149 to build_completions (). */ |
|
1150 static char *last_completion_request = (char *)NULL; |
|
1151 static REFERENCE **last_completion_items = (REFERENCE **)NULL; |
|
1152 |
|
1153 /* How to tell the completion builder to reset internal state. */ |
|
1154 static void |
|
1155 completions_must_be_rebuilt () |
|
1156 { |
|
1157 maybe_free (last_completion_request); |
|
1158 last_completion_request = (char *)NULL; |
|
1159 last_completion_items = (REFERENCE **)NULL; |
|
1160 } |
|
1161 |
|
1162 /* Build a list of possible completions from echo_area_completion_items, |
|
1163 and the contents of input_line. */ |
|
1164 static void |
|
1165 build_completions () |
|
1166 { |
|
1167 register int i, len; |
|
1168 register REFERENCE *entry; |
|
1169 char *request; |
|
1170 int informed_of_lengthy_job = 0; |
|
1171 |
|
1172 /* If there are no items to complete over, exit immediately. */ |
|
1173 if (!echo_area_completion_items) |
|
1174 { |
|
1175 completions_found_index = 0; |
|
1176 LCD_completion = (REFERENCE *)NULL; |
|
1177 return; |
|
1178 } |
|
1179 |
|
1180 /* Check to see if this call to build completions is the same as the last |
|
1181 call to build completions. */ |
|
1182 len = input_line_end - input_line_beg; |
|
1183 request = (char *)xmalloc (1 + len); |
|
1184 strncpy (request, &input_line[input_line_beg], len); |
|
1185 request[len] = '\0'; |
|
1186 |
|
1187 if (last_completion_request && last_completion_items && |
|
1188 last_completion_items == echo_area_completion_items && |
|
1189 (strcmp (last_completion_request, request) == 0)) |
|
1190 { |
|
1191 free (request); |
|
1192 return; |
|
1193 } |
|
1194 |
|
1195 maybe_free (last_completion_request); |
|
1196 last_completion_request = request; |
|
1197 last_completion_items = echo_area_completion_items; |
|
1198 |
|
1199 /* Always start at the beginning of the list. */ |
|
1200 completions_found_index = 0; |
|
1201 LCD_completion = (REFERENCE *)NULL; |
|
1202 |
|
1203 for (i = 0; entry = echo_area_completion_items[i]; i++) |
|
1204 { |
|
1205 if (strnicmp (request, entry->label, len) == 0) |
|
1206 add_pointer_to_array (entry, completions_found_index, |
|
1207 completions_found, completions_found_slots, |
|
1208 20, REFERENCE *); |
|
1209 |
|
1210 if (!informed_of_lengthy_job && completions_found_index > 100) |
|
1211 { |
|
1212 informed_of_lengthy_job = 1; |
|
1213 window_message_in_echo_area ("Building completions..."); |
|
1214 } |
|
1215 } |
|
1216 |
|
1217 if (!completions_found_index) |
|
1218 return; |
|
1219 |
|
1220 /* Sort and prune duplicate entries from the completions array. */ |
|
1221 remove_completion_duplicates (); |
|
1222 |
|
1223 /* If there is only one completion, just return that. */ |
|
1224 if (completions_found_index == 1) |
|
1225 { |
|
1226 LCD_completion = completions_found[0]; |
|
1227 return; |
|
1228 } |
|
1229 |
|
1230 /* Find the least common denominator. */ |
|
1231 { |
|
1232 long shortest = 100000; |
|
1233 |
|
1234 for (i = 1; i < completions_found_index; i++) |
|
1235 { |
|
1236 register int j; |
|
1237 int c1, c2; |
|
1238 |
|
1239 for (j = 0; |
|
1240 (c1 = info_tolower (completions_found[i - 1]->label[j])) && |
|
1241 (c2 = info_tolower (completions_found[i]->label[j])); |
|
1242 j++) |
|
1243 if (c1 != c2) |
|
1244 break; |
|
1245 |
|
1246 if (shortest > j) |
|
1247 shortest = j; |
|
1248 } |
|
1249 |
|
1250 maybe_free (LCD_reference.label); |
|
1251 LCD_reference.label = (char *)xmalloc (1 + shortest); |
|
1252 strncpy (LCD_reference.label, completions_found[0]->label, shortest); |
|
1253 LCD_reference.label[shortest] = '\0'; |
|
1254 LCD_completion = &LCD_reference; |
|
1255 } |
|
1256 |
|
1257 if (informed_of_lengthy_job) |
|
1258 echo_area_initialize_node (); |
|
1259 } |
|
1260 |
|
1261 /* Function called by qsort. */ |
|
1262 static int |
|
1263 compare_references (entry1, entry2) |
|
1264 REFERENCE **entry1, **entry2; |
|
1265 { |
|
1266 return (stricmp ((*entry1)->label, (*entry2)->label)); |
|
1267 } |
|
1268 |
|
1269 /* Prune duplicate entries from COMPLETIONS_FOUND. */ |
|
1270 static void |
|
1271 remove_completion_duplicates () |
|
1272 { |
|
1273 register int i, j; |
|
1274 REFERENCE **temp; |
|
1275 int newlen; |
|
1276 |
|
1277 if (!completions_found_index) |
|
1278 return; |
|
1279 |
|
1280 /* Sort the items. */ |
|
1281 qsort (completions_found, completions_found_index, sizeof (REFERENCE *), |
|
1282 compare_references); |
|
1283 |
|
1284 for (i = 0, newlen = 1; i < completions_found_index - 1; i++) |
|
1285 { |
|
1286 if (strcmp (completions_found[i]->label, |
|
1287 completions_found[i + 1]->label) == 0) |
|
1288 completions_found[i] = (REFERENCE *)NULL; |
|
1289 else |
|
1290 newlen++; |
|
1291 } |
|
1292 |
|
1293 /* We have marked all the dead slots. It is faster to copy the live slots |
|
1294 twice than to prune the dead slots one by one. */ |
|
1295 temp = (REFERENCE **)xmalloc ((1 + newlen) * sizeof (REFERENCE *)); |
|
1296 for (i = 0, j = 0; i < completions_found_index; i++) |
|
1297 if (completions_found[i]) |
|
1298 temp[j++] = completions_found[i]; |
|
1299 |
|
1300 for (i = 0; i < newlen; i++) |
|
1301 completions_found[i] = temp[i]; |
|
1302 |
|
1303 completions_found[i] = (REFERENCE *)NULL; |
|
1304 completions_found_index = newlen; |
|
1305 free (temp); |
|
1306 } |
|
1307 |
|
1308 /* Scroll the "other" window. If there is a window showing completions, scroll |
|
1309 that one, otherwise scroll the window which was active on entering the read |
|
1310 function. */ |
|
1311 DECLARE_INFO_COMMAND (ea_scroll_completions_window, "Scroll the completions window") |
|
1312 { |
|
1313 WINDOW *compwin; |
|
1314 int old_pagetop; |
|
1315 |
|
1316 compwin = get_internal_info_window (compwin_name); |
|
1317 |
|
1318 if (!compwin) |
|
1319 compwin = calling_window; |
|
1320 |
|
1321 old_pagetop = compwin->pagetop; |
|
1322 |
|
1323 /* Let info_scroll_forward () do the work, and print any messages that |
|
1324 need to be displayed. */ |
|
1325 info_scroll_forward (compwin, count, key); |
|
1326 } |
|
1327 |
|
1328 /* Function which gets called when an Info window is deleted while the |
|
1329 echo area is active. WINDOW is the window which has just been deleted. */ |
|
1330 void |
|
1331 echo_area_inform_of_deleted_window (window) |
|
1332 WINDOW *window; |
|
1333 { |
|
1334 /* If this is the calling_window, forget what we remembered about it. */ |
|
1335 if (window == calling_window) |
|
1336 { |
|
1337 if (active_window != the_echo_area) |
|
1338 remember_calling_window (active_window); |
|
1339 else |
|
1340 remember_calling_window (windows); |
|
1341 } |
|
1342 |
|
1343 /* If this window was the echo_area_completions_window, then notice that |
|
1344 the window has been deleted. */ |
|
1345 if (window == echo_area_completions_window) |
|
1346 echo_area_completions_window = (WINDOW *)NULL; |
|
1347 } |
|
1348 |
|
1349 /* **************************************************************** */ |
|
1350 /* */ |
|
1351 /* Pushing and Popping the Echo Area */ |
|
1352 /* */ |
|
1353 /* **************************************************************** */ |
|
1354 |
|
1355 /* Push and Pop the echo area. */ |
|
1356 typedef struct { |
|
1357 char *line; |
|
1358 char *prompt; |
|
1359 REFERENCE **comp_items; |
|
1360 int point, beg, end; |
|
1361 int must_complete; |
|
1362 NODE node; |
|
1363 WINDOW *compwin; |
|
1364 } PUSHED_EA; |
|
1365 |
|
1366 static PUSHED_EA **pushed_echo_areas = (PUSHED_EA **)NULL; |
|
1367 static int pushed_echo_areas_index = 0; |
|
1368 static int pushed_echo_areas_slots = 0; |
|
1369 |
|
1370 /* Pushing the echo_area has a side effect of zeroing the completion_items. */ |
|
1371 static void |
|
1372 push_echo_area () |
|
1373 { |
|
1374 PUSHED_EA *pushed; |
|
1375 |
|
1376 pushed = (PUSHED_EA *)xmalloc (sizeof (PUSHED_EA)); |
|
1377 pushed->line = savestring (input_line); |
|
1378 pushed->prompt = input_line_prompt; |
|
1379 pushed->point = input_line_point; |
|
1380 pushed->beg = input_line_beg; |
|
1381 pushed->end = input_line_end; |
|
1382 pushed->node = input_line_node; |
|
1383 pushed->comp_items = echo_area_completion_items; |
|
1384 pushed->must_complete = echo_area_must_complete_p; |
|
1385 pushed->compwin = echo_area_completions_window; |
|
1386 |
|
1387 add_pointer_to_array (pushed, pushed_echo_areas_index, pushed_echo_areas, |
|
1388 pushed_echo_areas_slots, 4, PUSHED_EA *); |
|
1389 |
|
1390 echo_area_completion_items = (REFERENCE **)NULL; |
|
1391 } |
|
1392 |
|
1393 static void |
|
1394 pop_echo_area () |
|
1395 { |
|
1396 PUSHED_EA *popped; |
|
1397 |
|
1398 popped = pushed_echo_areas[--pushed_echo_areas_index]; |
|
1399 |
|
1400 strcpy (input_line, popped->line); |
|
1401 free (popped->line); |
|
1402 input_line_prompt = popped->prompt; |
|
1403 input_line_point = popped->point; |
|
1404 input_line_beg = popped->beg; |
|
1405 input_line_end = popped->end; |
|
1406 input_line_node = popped->node; |
|
1407 echo_area_completion_items = popped->comp_items; |
|
1408 echo_area_must_complete_p = popped->must_complete; |
|
1409 echo_area_completions_window = popped->compwin; |
|
1410 completions_must_be_rebuilt (); |
|
1411 |
|
1412 /* If the completion window no longer exists, forget about it. */ |
|
1413 if (echo_area_completions_window) |
|
1414 { |
|
1415 register WINDOW *win; |
|
1416 |
|
1417 for (win = windows; win; win = win->next) |
|
1418 if (echo_area_completions_window == win) |
|
1419 break; |
|
1420 |
|
1421 /* If the window wasn't found, then it has already been deleted. */ |
|
1422 if (!win) |
|
1423 echo_area_completions_window = (WINDOW *)NULL; |
|
1424 } |
|
1425 |
|
1426 free (popped); |
|
1427 } |
|
1428 |
|
1429 static int |
|
1430 echo_area_stack_depth () |
|
1431 { |
|
1432 return (pushed_echo_areas_index); |
|
1433 } |
|
1434 |
|
1435 /* Returns non-zero if any of the prior stacked calls to read in the echo |
|
1436 area produced a completions window. */ |
|
1437 static int |
|
1438 echo_area_stack_contains_completions_p () |
|
1439 { |
|
1440 register int i; |
|
1441 |
|
1442 for (i = 0; i < pushed_echo_areas_index; i++) |
|
1443 if (pushed_echo_areas[i]->compwin) |
|
1444 return (1); |
|
1445 |
|
1446 return (0); |
|
1447 } |
|
1448 |
|
1449 /* **************************************************************** */ |
|
1450 /* */ |
|
1451 /* Error Messages While Reading in Echo Area */ |
|
1452 /* */ |
|
1453 /* **************************************************************** */ |
|
1454 |
|
1455 #if defined (HAVE_SYS_TIME_H) |
|
1456 # include <sys/time.h> |
|
1457 # define HAVE_STRUCT_TIMEVAL |
|
1458 #endif /* HAVE_SYS_TIME_H */ |
|
1459 |
|
1460 static void |
|
1461 pause_or_input () |
|
1462 { |
|
1463 #if defined (FD_SET) |
|
1464 struct timeval timer; |
|
1465 fd_set readfds; |
|
1466 int ready; |
|
1467 |
|
1468 FD_ZERO (&readfds); |
|
1469 FD_SET (fileno (stdin), &readfds); |
|
1470 timer.tv_sec = 2; |
|
1471 timer.tv_usec = 750; |
|
1472 ready = select (1, &readfds, (fd_set *)NULL, (fd_set *)NULL, &timer); |
|
1473 #endif /* FD_SET */ |
|
1474 } |
|
1475 |
|
1476 /* Print MESSAGE right after the end of the current line, and wait |
|
1477 for input or 2.75 seconds, whichever comes first. Then flush the |
|
1478 informational message that was printed. */ |
|
1479 void |
|
1480 inform_in_echo_area (message) |
|
1481 char *message; |
|
1482 { |
|
1483 register int i; |
|
1484 char *text; |
|
1485 |
|
1486 text = savestring (message); |
|
1487 for (i = 0; text[i] && text[i] != '\n'; i++); |
|
1488 text[i] = '\0'; |
|
1489 |
|
1490 echo_area_initialize_node (); |
|
1491 sprintf (&input_line[input_line_end], "%s[%s]\n", |
|
1492 echo_area_is_active ? " ": "", text); |
|
1493 free (text); |
|
1494 the_echo_area->point = input_line_point; |
|
1495 display_update_one_window (the_echo_area); |
|
1496 display_cursor_at_point (active_window); |
|
1497 fflush (stdout); |
|
1498 pause_or_input (); |
|
1499 echo_area_initialize_node (); |
|
1500 } |