3 /* m-x.c -- Meta-x minibuffer reader.
4 Id: m-x.c,v 1.3 2004/04/11 17:56:46 karl Exp
6 Copyright (C) 1993, 1997, 1998, 2001, 2002, 2004 Free Software
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 Originally written by Brian Fox (bfox@ai.mit.edu). */
28 /* **************************************************************** */
30 /* Reading Named Commands */
32 /* **************************************************************** */
34 /* Read the name of an Info function in the echo area and return the
35 name. A return value of NULL indicates that no function name could
38 read_function_name (char *prompt
, WINDOW
*window
)
42 REFERENCE
**array
= (REFERENCE
**)NULL
;
43 int array_index
= 0, array_slots
= 0;
45 /* Make an array of REFERENCE which actually contains the names of
46 the functions available in Info. */
47 for (i
= 0; function_doc_array
[i
].func
; i
++)
51 entry
= (REFERENCE
*)xmalloc (sizeof (REFERENCE
));
52 entry
->label
= xstrdup (function_doc_array
[i
].func_name
);
53 entry
->nodename
= (char *)NULL
;
54 entry
->filename
= (char *)NULL
;
57 (entry
, array_index
, array
, array_slots
, 200, REFERENCE
*);
60 line
= info_read_completing_in_echo_area (window
, prompt
, array
);
62 info_free_references (array
);
64 if (!echo_area_is_active
)
65 window_clear_echo_area ();
70 DECLARE_INFO_COMMAND (describe_command
,
71 _("Read the name of an Info command and describe it"))
75 line
= read_function_name ((char *) _("Describe command: "), window
);
79 info_abort_key (active_window
, count
, key
);
83 /* Describe the function named in "LINE". */
86 InfoCommand
*cmd
= named_function (line
);
91 window_message_in_echo_area ("%s: %s.",
92 line
, function_documentation (cmd
));
97 DECLARE_INFO_COMMAND (info_execute_command
,
98 _("Read a command name in the echo area and execute it"))
104 prompt
= (char *)xmalloc (20);
106 keys
= where_is (info_keymap
, InfoCmd(info_execute_command
));
107 /* If the where_is () function thinks that this command doesn't exist,
108 there's something very wrong! */
112 if (info_explicit_arg
|| count
!= 1)
113 sprintf (prompt
, "%d %s ", count
, keys
);
115 sprintf (prompt
, "%s ", keys
);
117 /* Ask the completer to read a reference for us. */
118 line
= read_function_name (prompt
, window
);
123 info_abort_key (active_window
, count
, key
);
127 /* User accepted "default"? (There is none.) */
134 /* User wants to execute a named command. Do it. */
136 InfoCommand
*command
;
138 if ((active_window
!= the_echo_area
) &&
139 (strncmp (line
, "echo-area-", 10) == 0))
142 info_error ((char *) _("Cannot execute an `echo-area' command here."),
147 command
= named_function (line
);
153 if (InfoFunction(command
))
154 (*InfoFunction(command
)) (active_window
, count
, 0);
156 info_error ((char *) _("Undefined command: %s"), line
, NULL
);
160 /* Okay, now that we have M-x, let the user set the screen height. */
161 DECLARE_INFO_COMMAND (set_screen_height
,
162 _("Set the height of the displayed window"))
164 int new_height
, old_height
= screenheight
;
166 if (info_explicit_arg
|| count
!= 1)
173 new_height
= screenheight
;
175 sprintf (prompt
, _("Set screen height to (%d): "), new_height
);
177 line
= info_read_in_echo_area (window
, prompt
);
179 /* If the user aborted, do that now. */
182 info_abort_key (active_window
, count
, 0);
186 /* Find out what the new height is supposed to be. */
188 new_height
= atoi (line
);
190 /* Clear the echo area if it isn't active. */
191 if (!echo_area_is_active
)
192 window_clear_echo_area ();
197 terminal_clear_screen ();
198 display_clear_display (the_display
);
199 screenheight
= new_height
;
200 #ifdef SET_SCREEN_SIZE_HELPER
201 SET_SCREEN_SIZE_HELPER
;
203 if (screenheight
== old_height
)
205 /* Display dimensions didn't actually change, so
206 window_new_screen_size won't do anything, but we've
207 already cleared the display above. Undo the damage. */
208 window_mark_chain (windows
, W_UpdateWindow
);
209 display_update_display (windows
);
213 display_initialize_display (screenwidth
, screenheight
);
214 window_new_screen_size (screenwidth
, screenheight
);