156160Sru/* m-x.c -- Meta-x minibuffer reader. 2146515Sru $Id: m-x.c,v 1.3 2004/04/11 17:56:46 karl Exp $ 321495Sjmacd 4146515Sru Copyright (C) 1993, 1997, 1998, 2001, 2002, 2004 Free Software 5146515Sru Foundation, Inc. 621495Sjmacd 721495Sjmacd This program is free software; you can redistribute it and/or modify 821495Sjmacd it under the terms of the GNU General Public License as published by 921495Sjmacd the Free Software Foundation; either version 2, or (at your option) 1021495Sjmacd any later version. 1121495Sjmacd 1221495Sjmacd This program is distributed in the hope that it will be useful, 1321495Sjmacd but WITHOUT ANY WARRANTY; without even the implied warranty of 1421495Sjmacd MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1521495Sjmacd GNU General Public License for more details. 1621495Sjmacd 1721495Sjmacd You should have received a copy of the GNU General Public License 1821495Sjmacd along with this program; if not, write to the Free Software 1921495Sjmacd Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 2021495Sjmacd 21146515Sru Originally written by Brian Fox (bfox@ai.mit.edu). */ 2221495Sjmacd 2321495Sjmacd#include "info.h" 2493139Sru#include "funs.h" 2521495Sjmacd 2621495Sjmacd/* **************************************************************** */ 2742660Smarkm/* */ 2842660Smarkm/* Reading Named Commands */ 2942660Smarkm/* */ 3021495Sjmacd/* **************************************************************** */ 3121495Sjmacd 3221495Sjmacd/* Read the name of an Info function in the echo area and return the 3321495Sjmacd name. A return value of NULL indicates that no function name could 3421495Sjmacd be read. */ 3521495Sjmacdchar * 36146515Sruread_function_name (char *prompt, WINDOW *window) 3721495Sjmacd{ 3821495Sjmacd register int i; 3921495Sjmacd char *line; 4021495Sjmacd REFERENCE **array = (REFERENCE **)NULL; 4121495Sjmacd int array_index = 0, array_slots = 0; 4221495Sjmacd 4321495Sjmacd /* Make an array of REFERENCE which actually contains the names of 4421495Sjmacd the functions available in Info. */ 4521495Sjmacd for (i = 0; function_doc_array[i].func; i++) 4621495Sjmacd { 4721495Sjmacd REFERENCE *entry; 4821495Sjmacd 4921495Sjmacd entry = (REFERENCE *)xmalloc (sizeof (REFERENCE)); 5042660Smarkm entry->label = xstrdup (function_doc_array[i].func_name); 5121495Sjmacd entry->nodename = (char *)NULL; 5221495Sjmacd entry->filename = (char *)NULL; 5321495Sjmacd 5421495Sjmacd add_pointer_to_array 5542660Smarkm (entry, array_index, array, array_slots, 200, REFERENCE *); 5621495Sjmacd } 5721495Sjmacd 5821495Sjmacd line = info_read_completing_in_echo_area (window, prompt, array); 5921495Sjmacd 6021495Sjmacd info_free_references (array); 6121495Sjmacd 6221495Sjmacd if (!echo_area_is_active) 6321495Sjmacd window_clear_echo_area (); 6421495Sjmacd 6521495Sjmacd return (line); 6621495Sjmacd} 6721495Sjmacd 6821495SjmacdDECLARE_INFO_COMMAND (describe_command, 6942660Smarkm _("Read the name of an Info command and describe it")) 7021495Sjmacd{ 7121495Sjmacd char *line; 7221495Sjmacd 73146515Sru line = read_function_name ((char *) _("Describe command: "), window); 7421495Sjmacd 7521495Sjmacd if (!line) 7621495Sjmacd { 7721495Sjmacd info_abort_key (active_window, count, key); 7821495Sjmacd return; 7921495Sjmacd } 8021495Sjmacd 8121495Sjmacd /* Describe the function named in "LINE". */ 8221495Sjmacd if (*line) 8321495Sjmacd { 8493139Sru InfoCommand *cmd = named_function (line); 8521495Sjmacd 8693139Sru if (!cmd) 8742660Smarkm return; 8821495Sjmacd 8921495Sjmacd window_message_in_echo_area ("%s: %s.", 9093139Sru line, function_documentation (cmd)); 9121495Sjmacd } 9221495Sjmacd free (line); 9321495Sjmacd} 9421495Sjmacd 9521495SjmacdDECLARE_INFO_COMMAND (info_execute_command, 9642660Smarkm _("Read a command name in the echo area and execute it")) 9721495Sjmacd{ 9821495Sjmacd char *line; 9993139Sru char *keys; 10093139Sru char *prompt; 10121495Sjmacd 10293139Sru prompt = (char *)xmalloc (20); 10393139Sru 10493139Sru keys = where_is (info_keymap, InfoCmd(info_execute_command)); 10593139Sru /* If the where_is () function thinks that this command doesn't exist, 10693139Sru there's something very wrong! */ 10793139Sru if (!keys) 10893139Sru abort(); 10993139Sru 11021495Sjmacd if (info_explicit_arg || count != 1) 11193139Sru sprintf (prompt, "%d %s ", count, keys); 11221495Sjmacd else 11393139Sru sprintf (prompt, "%s ", keys); 11421495Sjmacd 11593139Sru /* Ask the completer to read a reference for us. */ 11693139Sru line = read_function_name (prompt, window); 11793139Sru 11821495Sjmacd /* User aborted? */ 11921495Sjmacd if (!line) 12021495Sjmacd { 12121495Sjmacd info_abort_key (active_window, count, key); 12221495Sjmacd return; 12321495Sjmacd } 12421495Sjmacd 12521495Sjmacd /* User accepted "default"? (There is none.) */ 12621495Sjmacd if (!*line) 12721495Sjmacd { 12821495Sjmacd free (line); 12921495Sjmacd return; 13021495Sjmacd } 13121495Sjmacd 13221495Sjmacd /* User wants to execute a named command. Do it. */ 13321495Sjmacd { 13493139Sru InfoCommand *command; 13521495Sjmacd 13621495Sjmacd if ((active_window != the_echo_area) && 13742660Smarkm (strncmp (line, "echo-area-", 10) == 0)) 13821495Sjmacd { 13942660Smarkm free (line); 140146515Sru info_error ((char *) _("Cannot execute an `echo-area' command here."), 141146515Sru NULL, NULL); 14242660Smarkm return; 14321495Sjmacd } 14421495Sjmacd 14593139Sru command = named_function (line); 14621495Sjmacd free (line); 14721495Sjmacd 14893139Sru if (!command) 14921495Sjmacd return; 15021495Sjmacd 151146515Sru if (InfoFunction(command)) 152146515Sru (*InfoFunction(command)) (active_window, count, 0); 153146515Sru else 154146515Sru info_error ((char *) _("Undefined command: %s"), line, NULL); 15521495Sjmacd } 15621495Sjmacd} 15721495Sjmacd 15821495Sjmacd/* Okay, now that we have M-x, let the user set the screen height. */ 15921495SjmacdDECLARE_INFO_COMMAND (set_screen_height, 16042660Smarkm _("Set the height of the displayed window")) 16121495Sjmacd{ 16256160Sru int new_height, old_height = screenheight; 16321495Sjmacd 16421495Sjmacd if (info_explicit_arg || count != 1) 16521495Sjmacd new_height = count; 16621495Sjmacd else 16721495Sjmacd { 16821495Sjmacd char prompt[80]; 16921495Sjmacd char *line; 17021495Sjmacd 17121495Sjmacd new_height = screenheight; 17221495Sjmacd 17342660Smarkm sprintf (prompt, _("Set screen height to (%d): "), new_height); 17421495Sjmacd 17521495Sjmacd line = info_read_in_echo_area (window, prompt); 17621495Sjmacd 17721495Sjmacd /* If the user aborted, do that now. */ 17821495Sjmacd if (!line) 17942660Smarkm { 18042660Smarkm info_abort_key (active_window, count, 0); 18142660Smarkm return; 18242660Smarkm } 18321495Sjmacd 18421495Sjmacd /* Find out what the new height is supposed to be. */ 18521495Sjmacd if (*line) 18642660Smarkm new_height = atoi (line); 18721495Sjmacd 18821495Sjmacd /* Clear the echo area if it isn't active. */ 18921495Sjmacd if (!echo_area_is_active) 19042660Smarkm window_clear_echo_area (); 19121495Sjmacd 19221495Sjmacd free (line); 19321495Sjmacd } 19421495Sjmacd 19521495Sjmacd terminal_clear_screen (); 19621495Sjmacd display_clear_display (the_display); 19721495Sjmacd screenheight = new_height; 19856160Sru#ifdef SET_SCREEN_SIZE_HELPER 19956160Sru SET_SCREEN_SIZE_HELPER; 20056160Sru#endif 20156160Sru if (screenheight == old_height) 20256160Sru { 20356160Sru /* Display dimensions didn't actually change, so 20456160Sru window_new_screen_size won't do anything, but we've 20556160Sru already cleared the display above. Undo the damage. */ 20656160Sru window_mark_chain (windows, W_UpdateWindow); 20756160Sru display_update_display (windows); 20856160Sru } 20956160Sru else 21056160Sru { 21156160Sru display_initialize_display (screenwidth, screenheight); 21256160Sru window_new_screen_size (screenwidth, screenheight); 21356160Sru } 21421495Sjmacd} 215