1 /* m-x.c -- Meta-x minibuffer reader.
2 $Id: m-x.c,v 1.8 2008/06/11 09:55:42 gray Exp $
4 Copyright (C) 1993, 1997, 1998, 2001, 2002, 2004, 2007, 2008
5 Free Software Foundation, Inc.
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 Originally written by Brian Fox (bfox@ai.mit.edu). */
25 /* **************************************************************** */
27 /* Reading Named Commands */
29 /* **************************************************************** */
31 /* Read the name of an Info function in the echo area and return the
32 name. A return value of NULL indicates that no function name could
35 read_function_name (const char *prompt, WINDOW *window)
39 REFERENCE **array = NULL;
40 int array_index = 0, array_slots = 0;
42 /* Make an array of REFERENCE which actually contains the names of
43 the functions available in Info. */
44 for (i = 0; function_doc_array[i].func; i++)
48 entry = xmalloc (sizeof (REFERENCE));
49 entry->label = xstrdup (function_doc_array[i].func_name);
50 entry->nodename = NULL;
51 entry->filename = NULL;
54 (entry, array_index, array, array_slots, 200, REFERENCE *);
57 line = info_read_completing_in_echo_area (window, prompt, array);
59 info_free_references (array);
61 if (!echo_area_is_active)
62 window_clear_echo_area ();
67 DECLARE_INFO_COMMAND (describe_command,
68 _("Read the name of an Info command and describe it"))
72 line = read_function_name (_("Describe command: "), window);
76 info_abort_key (active_window, count, key);
80 /* Describe the function named in "LINE". */
83 InfoCommand *cmd = named_function (line);
88 window_message_in_echo_area ("%s: %s.",
89 line, function_documentation (cmd));
94 DECLARE_INFO_COMMAND (info_execute_command,
95 _("Read a command name in the echo area and execute it"))
101 prompt = xmalloc (20);
103 keys = where_is (info_keymap, InfoCmd(info_execute_command));
104 /* If the where_is () function thinks that this command doesn't exist,
105 there's something very wrong! */
109 if (info_explicit_arg || count != 1)
110 sprintf (prompt, "%d %s ", count, keys);
112 sprintf (prompt, "%s ", keys);
114 /* Ask the completer to read a reference for us. */
115 line = read_function_name (prompt, window);
120 info_abort_key (active_window, count, key);
124 /* User accepted "default"? (There is none.) */
131 /* User wants to execute a named command. Do it. */
133 InfoCommand *command;
135 if ((active_window != the_echo_area) &&
136 (strncmp (line, "echo-area-", 10) == 0))
139 info_error (_("Cannot execute an `echo-area' command here."),
144 command = named_function (line);
150 if (InfoFunction(command))
151 (*InfoFunction(command)) (active_window, count, 0);
153 info_error (_("Undefined command: %s"), line, NULL);
157 /* Okay, now that we have M-x, let the user set the screen height. */
158 DECLARE_INFO_COMMAND (set_screen_height,
159 _("Set the height of the displayed window"))
161 int new_height, old_height = screenheight;
163 if (info_explicit_arg || count != 1)
170 new_height = screenheight;
172 sprintf (prompt, _("Set screen height to (%d): "), new_height);
174 line = info_read_in_echo_area (window, prompt);
176 /* If the user aborted, do that now. */
179 info_abort_key (active_window, count, 0);
183 /* Find out what the new height is supposed to be. */
185 new_height = atoi (line);
187 /* Clear the echo area if it isn't active. */
188 if (!echo_area_is_active)
189 window_clear_echo_area ();
194 terminal_clear_screen ();
195 display_clear_display (the_display);
196 screenheight = new_height;
197 #ifdef SET_SCREEN_SIZE_HELPER
198 SET_SCREEN_SIZE_HELPER;
200 if (screenheight == old_height)
202 /* Display dimensions didn't actually change, so
203 window_new_screen_size won't do anything, but we've
204 already cleared the display above. Undo the damage. */
205 window_mark_chain (windows, W_UpdateWindow);
206 display_update_display (windows);
210 display_initialize_display (screenwidth, screenheight);
211 window_new_screen_size (screenwidth, screenheight);