m-x.c revision 93139
156160Sru/* m-x.c -- Meta-x minibuffer reader. 293139Sru $Id: m-x.c,v 1.9 2001/11/16 23:14:33 karl Exp $ 321495Sjmacd 493139Sru Copyright (C) 1993, 97, 98, 2001 Free Software Foundation, Inc. 521495Sjmacd 621495Sjmacd This program is free software; you can redistribute it and/or modify 721495Sjmacd it under the terms of the GNU General Public License as published by 821495Sjmacd the Free Software Foundation; either version 2, or (at your option) 921495Sjmacd any later version. 1021495Sjmacd 1121495Sjmacd This program is distributed in the hope that it will be useful, 1221495Sjmacd but WITHOUT ANY WARRANTY; without even the implied warranty of 1321495Sjmacd MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1421495Sjmacd GNU General Public License for more details. 1521495Sjmacd 1621495Sjmacd You should have received a copy of the GNU General Public License 1721495Sjmacd along with this program; if not, write to the Free Software 1821495Sjmacd Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 1921495Sjmacd 2021495Sjmacd Written by Brian Fox (bfox@ai.mit.edu). */ 2121495Sjmacd 2221495Sjmacd#include "info.h" 2393139Sru#include "funs.h" 2421495Sjmacd 2521495Sjmacd/* **************************************************************** */ 2642660Smarkm/* */ 2742660Smarkm/* Reading Named Commands */ 2842660Smarkm/* */ 2921495Sjmacd/* **************************************************************** */ 3021495Sjmacd 3121495Sjmacd/* Read the name of an Info function in the echo area and return the 3221495Sjmacd name. A return value of NULL indicates that no function name could 3321495Sjmacd be read. */ 3421495Sjmacdchar * 3521495Sjmacdread_function_name (prompt, window) 3621495Sjmacd char *prompt; 3721495Sjmacd WINDOW *window; 3821495Sjmacd{ 3921495Sjmacd register int i; 4021495Sjmacd char *line; 4121495Sjmacd REFERENCE **array = (REFERENCE **)NULL; 4221495Sjmacd int array_index = 0, array_slots = 0; 4321495Sjmacd 4421495Sjmacd /* Make an array of REFERENCE which actually contains the names of 4521495Sjmacd the functions available in Info. */ 4621495Sjmacd for (i = 0; function_doc_array[i].func; i++) 4721495Sjmacd { 4821495Sjmacd REFERENCE *entry; 4921495Sjmacd 5021495Sjmacd entry = (REFERENCE *)xmalloc (sizeof (REFERENCE)); 5142660Smarkm entry->label = xstrdup (function_doc_array[i].func_name); 5221495Sjmacd entry->nodename = (char *)NULL; 5321495Sjmacd entry->filename = (char *)NULL; 5421495Sjmacd 5521495Sjmacd add_pointer_to_array 5642660Smarkm (entry, array_index, array, array_slots, 200, REFERENCE *); 5721495Sjmacd } 5821495Sjmacd 5921495Sjmacd line = info_read_completing_in_echo_area (window, prompt, array); 6021495Sjmacd 6121495Sjmacd info_free_references (array); 6221495Sjmacd 6321495Sjmacd if (!echo_area_is_active) 6421495Sjmacd window_clear_echo_area (); 6521495Sjmacd 6621495Sjmacd return (line); 6721495Sjmacd} 6821495Sjmacd 6921495SjmacdDECLARE_INFO_COMMAND (describe_command, 7042660Smarkm _("Read the name of an Info command and describe it")) 7121495Sjmacd{ 7221495Sjmacd char *line; 7321495Sjmacd 7442660Smarkm line = read_function_name (_("Describe command: "), window); 7521495Sjmacd 7621495Sjmacd if (!line) 7721495Sjmacd { 7821495Sjmacd info_abort_key (active_window, count, key); 7921495Sjmacd return; 8021495Sjmacd } 8121495Sjmacd 8221495Sjmacd /* Describe the function named in "LINE". */ 8321495Sjmacd if (*line) 8421495Sjmacd { 8593139Sru InfoCommand *cmd = named_function (line); 8621495Sjmacd 8793139Sru if (!cmd) 8842660Smarkm return; 8921495Sjmacd 9021495Sjmacd window_message_in_echo_area ("%s: %s.", 9193139Sru line, function_documentation (cmd)); 9221495Sjmacd } 9321495Sjmacd free (line); 9421495Sjmacd} 9521495Sjmacd 9621495SjmacdDECLARE_INFO_COMMAND (info_execute_command, 9742660Smarkm _("Read a command name in the echo area and execute it")) 9821495Sjmacd{ 9921495Sjmacd char *line; 10093139Sru char *keys; 10193139Sru char *prompt; 10221495Sjmacd 10393139Sru prompt = (char *)xmalloc (20); 10493139Sru 10593139Sru keys = where_is (info_keymap, InfoCmd(info_execute_command)); 10693139Sru /* If the where_is () function thinks that this command doesn't exist, 10793139Sru there's something very wrong! */ 10893139Sru if (!keys) 10993139Sru abort(); 11093139Sru 11121495Sjmacd if (info_explicit_arg || count != 1) 11293139Sru sprintf (prompt, "%d %s ", count, keys); 11321495Sjmacd else 11493139Sru sprintf (prompt, "%s ", keys); 11521495Sjmacd 11693139Sru /* Ask the completer to read a reference for us. */ 11793139Sru line = read_function_name (prompt, window); 11893139Sru 11921495Sjmacd /* User aborted? */ 12021495Sjmacd if (!line) 12121495Sjmacd { 12221495Sjmacd info_abort_key (active_window, count, key); 12321495Sjmacd return; 12421495Sjmacd } 12521495Sjmacd 12621495Sjmacd /* User accepted "default"? (There is none.) */ 12721495Sjmacd if (!*line) 12821495Sjmacd { 12921495Sjmacd free (line); 13021495Sjmacd return; 13121495Sjmacd } 13221495Sjmacd 13321495Sjmacd /* User wants to execute a named command. Do it. */ 13421495Sjmacd { 13593139Sru InfoCommand *command; 13621495Sjmacd 13721495Sjmacd if ((active_window != the_echo_area) && 13842660Smarkm (strncmp (line, "echo-area-", 10) == 0)) 13921495Sjmacd { 14042660Smarkm free (line); 14142660Smarkm info_error (_("Cannot execute an `echo-area' command here.")); 14242660Smarkm return; 14321495Sjmacd } 14421495Sjmacd 14593139Sru command = named_function (line); 14621495Sjmacd free (line); 14721495Sjmacd 14893139Sru if (!command) 14921495Sjmacd return; 15021495Sjmacd 15193139Sru (*InfoFunction(command)) (active_window, count, 0); 15221495Sjmacd } 15321495Sjmacd} 15421495Sjmacd 15521495Sjmacd/* Okay, now that we have M-x, let the user set the screen height. */ 15621495SjmacdDECLARE_INFO_COMMAND (set_screen_height, 15742660Smarkm _("Set the height of the displayed window")) 15821495Sjmacd{ 15956160Sru int new_height, old_height = screenheight; 16021495Sjmacd 16121495Sjmacd if (info_explicit_arg || count != 1) 16221495Sjmacd new_height = count; 16321495Sjmacd else 16421495Sjmacd { 16521495Sjmacd char prompt[80]; 16621495Sjmacd char *line; 16721495Sjmacd 16821495Sjmacd new_height = screenheight; 16921495Sjmacd 17042660Smarkm sprintf (prompt, _("Set screen height to (%d): "), new_height); 17121495Sjmacd 17221495Sjmacd line = info_read_in_echo_area (window, prompt); 17321495Sjmacd 17421495Sjmacd /* If the user aborted, do that now. */ 17521495Sjmacd if (!line) 17642660Smarkm { 17742660Smarkm info_abort_key (active_window, count, 0); 17842660Smarkm return; 17942660Smarkm } 18021495Sjmacd 18121495Sjmacd /* Find out what the new height is supposed to be. */ 18221495Sjmacd if (*line) 18342660Smarkm new_height = atoi (line); 18421495Sjmacd 18521495Sjmacd /* Clear the echo area if it isn't active. */ 18621495Sjmacd if (!echo_area_is_active) 18742660Smarkm window_clear_echo_area (); 18821495Sjmacd 18921495Sjmacd free (line); 19021495Sjmacd } 19121495Sjmacd 19221495Sjmacd terminal_clear_screen (); 19321495Sjmacd display_clear_display (the_display); 19421495Sjmacd screenheight = new_height; 19556160Sru#ifdef SET_SCREEN_SIZE_HELPER 19656160Sru SET_SCREEN_SIZE_HELPER; 19756160Sru#endif 19856160Sru if (screenheight == old_height) 19956160Sru { 20056160Sru /* Display dimensions didn't actually change, so 20156160Sru window_new_screen_size won't do anything, but we've 20256160Sru already cleared the display above. Undo the damage. */ 20356160Sru window_mark_chain (windows, W_UpdateWindow); 20456160Sru display_update_display (windows); 20556160Sru } 20656160Sru else 20756160Sru { 20856160Sru display_initialize_display (screenwidth, screenheight); 20956160Sru window_new_screen_size (screenwidth, screenheight); 21056160Sru } 21121495Sjmacd} 212