m-x.c revision 56160
1/* m-x.c -- Meta-x minibuffer reader. 2 $Id: m-x.c,v 1.8 1999/06/25 21:57:40 karl Exp $ 3 4 Copyright (C) 1993, 97, 98 Free Software Foundation, Inc. 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 20 Written by Brian Fox (bfox@ai.mit.edu). */ 21 22#include "info.h" 23 24/* **************************************************************** */ 25/* */ 26/* Reading Named Commands */ 27/* */ 28/* **************************************************************** */ 29 30/* Read the name of an Info function in the echo area and return the 31 name. A return value of NULL indicates that no function name could 32 be read. */ 33char * 34read_function_name (prompt, window) 35 char *prompt; 36 WINDOW *window; 37{ 38 register int i; 39 char *line; 40 REFERENCE **array = (REFERENCE **)NULL; 41 int array_index = 0, array_slots = 0; 42 43 /* Make an array of REFERENCE which actually contains the names of 44 the functions available in Info. */ 45 for (i = 0; function_doc_array[i].func; i++) 46 { 47 REFERENCE *entry; 48 49 entry = (REFERENCE *)xmalloc (sizeof (REFERENCE)); 50 entry->label = xstrdup (function_doc_array[i].func_name); 51 entry->nodename = (char *)NULL; 52 entry->filename = (char *)NULL; 53 54 add_pointer_to_array 55 (entry, array_index, array, array_slots, 200, REFERENCE *); 56 } 57 58 line = info_read_completing_in_echo_area (window, prompt, array); 59 60 info_free_references (array); 61 62 if (!echo_area_is_active) 63 window_clear_echo_area (); 64 65 return (line); 66} 67 68DECLARE_INFO_COMMAND (describe_command, 69 _("Read the name of an Info command and describe it")) 70{ 71 char *line; 72 73 line = read_function_name (_("Describe command: "), window); 74 75 if (!line) 76 { 77 info_abort_key (active_window, count, key); 78 return; 79 } 80 81 /* Describe the function named in "LINE". */ 82 if (*line) 83 { 84 VFunction *fun = named_function (line); 85 86 if (!fun) 87 return; 88 89 window_message_in_echo_area ("%s: %s.", 90 line, function_documentation (fun)); 91 } 92 free (line); 93} 94 95DECLARE_INFO_COMMAND (info_execute_command, 96 _("Read a command name in the echo area and execute it")) 97{ 98 char *line; 99 100 /* Ask the completer to read a reference for us. */ 101 if (info_explicit_arg || count != 1) 102 { 103 char *prompt; 104 105 prompt = (char *)xmalloc (20); 106 sprintf (prompt, "%d M-x ", count); 107 line = read_function_name (prompt, window); 108 } 109 else 110 line = read_function_name ("M-x ", window); 111 112 /* User aborted? */ 113 if (!line) 114 { 115 info_abort_key (active_window, count, key); 116 return; 117 } 118 119 /* User accepted "default"? (There is none.) */ 120 if (!*line) 121 { 122 free (line); 123 return; 124 } 125 126 /* User wants to execute a named command. Do it. */ 127 { 128 VFunction *function; 129 130 if ((active_window != the_echo_area) && 131 (strncmp (line, "echo-area-", 10) == 0)) 132 { 133 free (line); 134 info_error (_("Cannot execute an `echo-area' command here.")); 135 return; 136 } 137 138 function = named_function (line); 139 free (line); 140 141 if (!function) 142 return; 143 144 (*function) (active_window, count, 0); 145 } 146} 147 148/* Okay, now that we have M-x, let the user set the screen height. */ 149DECLARE_INFO_COMMAND (set_screen_height, 150 _("Set the height of the displayed window")) 151{ 152 int new_height, old_height = screenheight; 153 154 if (info_explicit_arg || count != 1) 155 new_height = count; 156 else 157 { 158 char prompt[80]; 159 char *line; 160 161 new_height = screenheight; 162 163 sprintf (prompt, _("Set screen height to (%d): "), new_height); 164 165 line = info_read_in_echo_area (window, prompt); 166 167 /* If the user aborted, do that now. */ 168 if (!line) 169 { 170 info_abort_key (active_window, count, 0); 171 return; 172 } 173 174 /* Find out what the new height is supposed to be. */ 175 if (*line) 176 new_height = atoi (line); 177 178 /* Clear the echo area if it isn't active. */ 179 if (!echo_area_is_active) 180 window_clear_echo_area (); 181 182 free (line); 183 } 184 185 terminal_clear_screen (); 186 display_clear_display (the_display); 187 screenheight = new_height; 188#ifdef SET_SCREEN_SIZE_HELPER 189 SET_SCREEN_SIZE_HELPER; 190#endif 191 if (screenheight == old_height) 192 { 193 /* Display dimensions didn't actually change, so 194 window_new_screen_size won't do anything, but we've 195 already cleared the display above. Undo the damage. */ 196 window_mark_chain (windows, W_UpdateWindow); 197 display_update_display (windows); 198 } 199 else 200 { 201 display_initialize_display (screenwidth, screenheight); 202 window_new_screen_size (screenwidth, screenheight); 203 } 204} 205