1
1
/* echo-area.c -- how to read a line in the echo area.
2
$Id: echo-area.c,v 1.15 2001/12/12 16:19:39 karl Exp $
2
$Id: echo-area.c,v 1.7 2004/12/14 00:15:36 karl Exp $
4
Copyright (C) 1993, 97, 98, 99, 2001 Free Software Foundation, Inc.
4
Copyright (C) 1993, 1997, 1998, 1999, 2001, 2004 Free Software
6
7
This program is free software; you can redistribute it and/or modify
7
8
it under the terms of the GNU General Public License as published by
49
50
static int input_line_beg;
50
51
static int input_line_end;
51
52
static NODE input_line_node = {
52
(char *)NULL, (char *)NULL, (char *)NULL, input_line, EA_MAX_INPUT, 0
53
(char *)NULL, (char *)NULL, (char *)NULL, input_line,
54
EA_MAX_INPUT, 0, N_IsInternal
55
static void echo_area_initialize_node ();
56
static void push_echo_area (), pop_echo_area ();
57
static int echo_area_stack_contains_completions_p ();
57
static void echo_area_initialize_node (void);
58
static void push_echo_area (void), pop_echo_area (void);
59
static int echo_area_stack_contains_completions_p (void);
59
static void ea_kill_text ();
61
static void ea_kill_text (int from, int to);
61
63
/* Non-zero means we force the user to complete. */
62
64
static int echo_area_must_complete_p = 0;
63
static int completions_window_p ();
65
static int completions_window_p (WINDOW *window);
65
67
/* If non-null, this is a window which was specifically created to display
66
68
possible completions output. We remember it so we can delete it when
77
79
/* Remember the node and pertinent variables of the calling window. */
79
remember_calling_window (window)
81
remember_calling_window (WINDOW *window)
82
83
/* Only do this if the calling window is not the completions window, or,
83
84
if it is the completions window and there is no other window. */
94
95
/* Restore the caller's window so that it shows the node that it was showing
95
96
on entry to info_read_xxx_echo_area (). */
97
restore_calling_window ()
98
restore_calling_window (void)
99
100
register WINDOW *win, *compwin = (WINDOW *)NULL;
198
201
active window, so that we can restore it when we need to. PROMPT, if
199
202
non-null, is a prompt to print before reading the line. */
201
info_read_in_echo_area (window, prompt)
204
info_read_in_echo_area (WINDOW *window, char *prompt)
247
248
/* (re) Initialize the echo area node. */
249
echo_area_initialize_node ()
250
echo_area_initialize_node (void)
253
for (i = input_line_end; i < sizeof (input_line); i++)
254
for (i = input_line_end; (unsigned int) i < sizeof (input_line); i++)
254
255
input_line[i] = ' ';
256
257
input_line[i - 1] = '\n';
262
263
echo area node, but its primary purpose is to side effect the input
263
264
line buffer contents. */
265
echo_area_prep_read ()
266
echo_area_prep_read (void)
267
268
if (the_echo_area->node != &input_line_node)
268
269
echo_area_initialize_node ();
577
578
register int len;
579
if (((ea_last_executed_command != ea_yank) &&
580
(ea_last_executed_command != ea_yank_pop)) ||
580
if (((ea_last_executed_command != (VFunction *) ea_yank) &&
581
(ea_last_executed_command != (VFunction *) ea_yank_pop)) ||
581
582
(kill_ring_index == 0))
670
671
otherwise it is prepended. If the last command was not a kill command,
671
672
then a new slot is made for this kill. */
673
ea_kill_text (from, to)
674
ea_kill_text (int from, int to)
676
676
register int i, counter, distance;
677
677
int killing_backwards, slot;
776
776
static REFERENCE *LCD_completion;
778
778
/* Internal functions used by the user calls. */
779
static void build_completions (), completions_must_be_rebuilt ();
779
static void build_completions (void), completions_must_be_rebuilt (void);
781
781
/* Variable which holds the output of completions. */
782
782
static NODE *possible_completions_output_node = (NODE *)NULL;
800
799
/* Workhorse for completion readers. If FORCE is non-zero, the user cannot
801
800
exit unless the line read completes, or is empty. */
803
info_read_completing_internal (window, prompt, completions, force)
806
REFERENCE **completions;
802
info_read_completing_internal (WINDOW *window, char *prompt,
803
REFERENCE **completions, int force)
869
865
if (i == completions_found_index)
871
867
if (!completions_found_index)
872
inform_in_echo_area (_("No completions"));
868
inform_in_echo_area ((char *) _("No completions"));
874
inform_in_echo_area (_("Not complete"));
870
inform_in_echo_area ((char *) _("Not complete"));
898
894
/* Read a line in the echo area with completion over COMPLETIONS. */
900
info_read_completing_in_echo_area (window, prompt, completions)
903
REFERENCE **completions;
896
info_read_completing_in_echo_area (WINDOW *window,
897
char *prompt, REFERENCE **completions)
905
899
return (info_read_completing_internal (window, prompt, completions, 1));
908
902
/* Read a line in the echo area allowing completion over COMPLETIONS, but
909
903
not requiring it. */
911
info_read_maybe_completing (window, prompt, completions)
914
REFERENCE **completions;
905
info_read_maybe_completing (WINDOW *window,
906
char *prompt, REFERENCE **completions)
916
908
return (info_read_completing_internal (window, prompt, completions, 0));
929
921
if (!completions_found_index)
931
923
terminal_ring_bell ();
932
inform_in_echo_area (_("No completions"));
924
inform_in_echo_area ((char *) _("No completions"));
934
926
else if ((completions_found_index == 1) && (key != '?'))
936
inform_in_echo_area (_("Sole completion"));
928
inform_in_echo_area ((char *) _("Sole completion"));
940
932
register int i, l;
941
int limit, count, max_label = 0;
933
int limit, iterations, max_label = 0;
943
935
initialize_message_buffer ();
944
936
printf_to_message_buffer (completions_found_index == 1
945
? _("One completion:\n")
946
: _("%d completions:\n"),
947
completions_found_index);
937
? (char *) _("One completion:\n")
938
: (char *) _("%d completions:\n"),
939
(void *) (long) completions_found_index,
949
942
/* Find the maximum length of a label. */
950
943
for (i = 0; i < completions_found_index; i++)
969
962
/* How many iterations of the printing loop? */
970
count = (completions_found_index + (limit - 1)) / limit;
963
iterations = (completions_found_index + (limit - 1)) / limit;
972
965
/* Watch out for special case. If the number of completions is less
973
966
than LIMIT, then just do the inner printing loop. */
974
967
if (completions_found_index < limit)
977
970
/* Print the sorted items, up-and-down alphabetically. */
978
for (i = 0; i < count; i++)
971
for (i = 0; i < iterations; i++)
991
984
label = completions_found[l]->label;
992
985
printed_length = strlen (label);
993
printf_to_message_buffer ("%s", label);
986
printf_to_message_buffer ("%s", label, NULL, NULL);
995
988
if (j + 1 < limit)
997
990
for (k = 0; k < max_label - printed_length; k++)
998
printf_to_message_buffer (" ");
991
printf_to_message_buffer (" ", NULL, NULL, NULL);
1003
printf_to_message_buffer ("\n");
996
printf_to_message_buffer ("\n", NULL, NULL, NULL);
1006
999
/* Make a new node to hold onto possible completions. Don't destroy
1046
1039
window_make_window (possible_completions_output_node);
1047
1040
active_window = the_echo_area;
1048
1041
window_change_window_height
1049
(compwin, -(compwin->height - (count + 2)));
1042
(compwin, -(compwin->height - (iterations + 2)));
1051
1044
window_adjust_pagetop (calling_window);
1052
1045
remember_calling_window (calling_window);
1108
if (ea_last_executed_command == ea_complete)
1101
if (ea_last_executed_command == (VFunction *) ea_complete)
1110
1103
/* If the keypress is a SPC character, and we have already tried
1111
1104
completing once, and there are several completions, then check
1155
1148
/* Utility REFERENCE used to store possible LCD. */
1156
static REFERENCE LCD_reference = { (char *)NULL, (char *)NULL, (char *)NULL };
1149
static REFERENCE LCD_reference = {
1150
(char *)NULL, (char *)NULL, (char *)NULL, 0, 0, 0
1158
static void remove_completion_duplicates ();
1153
static void remove_completion_duplicates (void);
1160
1155
/* Variables which remember the state of the most recent call
1161
1156
to build_completions (). */
1165
1160
/* How to tell the completion builder to reset internal state. */
1167
completions_must_be_rebuilt ()
1162
completions_must_be_rebuilt (void)
1169
1164
maybe_free (last_completion_request);
1170
1165
last_completion_request = (char *)NULL;
1222
1217
if (!informed_of_lengthy_job && completions_found_index > 100)
1224
1219
informed_of_lengthy_job = 1;
1225
window_message_in_echo_area (_("Building completions..."));
1220
window_message_in_echo_area ((char *) _("Building completions..."),
1292
1288
/* Function called by qsort. */
1294
compare_references (entry1, entry2)
1295
REFERENCE **entry1, **entry2;
1290
compare_references (const void *entry1, const void *entry2)
1297
return (strcasecmp ((*entry1)->label, (*entry2)->label));
1292
REFERENCE **e1 = (REFERENCE **) entry1;
1293
REFERENCE **e2 = (REFERENCE **) entry2;
1295
return (strcasecmp ((*e1)->label, (*e2)->label));
1300
1298
/* Prune duplicate entries from COMPLETIONS_FOUND. */
1302
remove_completion_duplicates ()
1300
remove_completion_duplicates (void)
1304
1302
register int i, j;
1305
1303
REFERENCE **temp;
1359
1357
/* Function which gets called when an Info window is deleted while the
1360
1358
echo area is active. WINDOW is the window which has just been deleted. */
1362
echo_area_inform_of_deleted_window (window)
1360
echo_area_inform_of_deleted_window (WINDOW *window)
1365
1362
/* If this is the calling_window, forget what we remembered about it. */
1366
1363
if (window == calling_window)
1503
1500
for input or a couple of seconds, whichever comes first. Then flush the
1504
1501
informational message that was printed. */
1506
inform_in_echo_area (message)
1503
inform_in_echo_area (const char *message)
1507
int avail = EA_MAX_INPUT + 1 - input_line_end;
1512
1509
text = xstrdup (message);
1513
for (i = 0; text[i] && text[i] != '\n'; i++)
1510
for (i = 0; text[i] && text[i] != '\n' && i < avail; i++)