Back to index

tetex-bin  3.0
m-x.c
Go to the documentation of this file.
00001 /* m-x.c -- Meta-x minibuffer reader.
00002    $Id: m-x.c,v 1.3 2004/04/11 17:56:46 karl Exp $
00003 
00004    Copyright (C) 1993, 1997, 1998, 2001, 2002, 2004 Free Software
00005    Foundation, Inc.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2, or (at your option)
00010    any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program; if not, write to the Free Software
00019    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00020 
00021    Originally written by Brian Fox (bfox@ai.mit.edu). */
00022 
00023 #include "info.h"
00024 #include "funs.h"
00025 
00026 /* **************************************************************** */
00027 /*                                                                  */
00028 /*                     Reading Named Commands                       */
00029 /*                                                                  */
00030 /* **************************************************************** */
00031 
00032 /* Read the name of an Info function in the echo area and return the
00033    name.  A return value of NULL indicates that no function name could
00034    be read. */
00035 char *
00036 read_function_name (char *prompt, WINDOW *window)
00037 {
00038   register int i;
00039   char *line;
00040   REFERENCE **array = (REFERENCE **)NULL;
00041   int array_index = 0, array_slots = 0;
00042 
00043   /* Make an array of REFERENCE which actually contains the names of
00044      the functions available in Info. */
00045   for (i = 0; function_doc_array[i].func; i++)
00046     {
00047       REFERENCE *entry;
00048 
00049       entry = (REFERENCE *)xmalloc (sizeof (REFERENCE));
00050       entry->label = xstrdup (function_doc_array[i].func_name);
00051       entry->nodename = (char *)NULL;
00052       entry->filename = (char *)NULL;
00053 
00054       add_pointer_to_array
00055         (entry, array_index, array, array_slots, 200, REFERENCE *);
00056     }
00057 
00058   line = info_read_completing_in_echo_area (window, prompt, array);
00059 
00060   info_free_references (array);
00061 
00062   if (!echo_area_is_active)
00063     window_clear_echo_area ();
00064 
00065   return (line);
00066 }
00067 
00068 DECLARE_INFO_COMMAND (describe_command,
00069    _("Read the name of an Info command and describe it"))
00070 {
00071   char *line;
00072 
00073   line = read_function_name ((char *) _("Describe command: "), window);
00074 
00075   if (!line)
00076     {
00077       info_abort_key (active_window, count, key);
00078       return;
00079     }
00080 
00081   /* Describe the function named in "LINE". */
00082   if (*line)
00083     {
00084       InfoCommand *cmd = named_function (line);
00085 
00086       if (!cmd)
00087         return;
00088 
00089       window_message_in_echo_area ("%s: %s.",
00090                                    line, function_documentation (cmd));
00091     }
00092   free (line);
00093 }
00094 
00095 DECLARE_INFO_COMMAND (info_execute_command,
00096    _("Read a command name in the echo area and execute it"))
00097 {
00098   char *line;
00099   char *keys;
00100   char *prompt;
00101 
00102   prompt = (char *)xmalloc (20);
00103 
00104   keys = where_is (info_keymap, InfoCmd(info_execute_command));
00105   /* If the where_is () function thinks that this command doesn't exist,
00106      there's something very wrong!  */
00107   if (!keys)
00108     abort();
00109 
00110   if (info_explicit_arg || count != 1)
00111     sprintf (prompt, "%d %s ", count, keys);
00112   else
00113     sprintf (prompt, "%s ", keys);
00114 
00115   /* Ask the completer to read a reference for us. */
00116   line = read_function_name (prompt, window);
00117 
00118   /* User aborted? */
00119   if (!line)
00120     {
00121       info_abort_key (active_window, count, key);
00122       return;
00123     }
00124 
00125   /* User accepted "default"?  (There is none.) */
00126   if (!*line)
00127     {
00128       free (line);
00129       return;
00130     }
00131 
00132   /* User wants to execute a named command.  Do it. */
00133   {
00134     InfoCommand *command;
00135 
00136     if ((active_window != the_echo_area) &&
00137         (strncmp (line, "echo-area-", 10) == 0))
00138       {
00139         free (line);
00140         info_error ((char *) _("Cannot execute an `echo-area' command here."),
00141             NULL, NULL);
00142         return;
00143       }
00144 
00145     command = named_function (line);
00146     free (line);
00147 
00148     if (!command)
00149       return;
00150 
00151     if (InfoFunction(command))
00152       (*InfoFunction(command)) (active_window, count, 0);
00153     else
00154       info_error ((char *) _("Undefined command: %s"), line, NULL);
00155   }
00156 }
00157 
00158 /* Okay, now that we have M-x, let the user set the screen height. */
00159 DECLARE_INFO_COMMAND (set_screen_height,
00160   _("Set the height of the displayed window"))
00161 {
00162   int new_height, old_height = screenheight;
00163 
00164   if (info_explicit_arg || count != 1)
00165     new_height = count;
00166   else
00167     {
00168       char prompt[80];
00169       char *line;
00170 
00171       new_height = screenheight;
00172 
00173       sprintf (prompt, _("Set screen height to (%d): "), new_height);
00174 
00175       line = info_read_in_echo_area (window, prompt);
00176 
00177       /* If the user aborted, do that now. */
00178       if (!line)
00179         {
00180           info_abort_key (active_window, count, 0);
00181           return;
00182         }
00183 
00184       /* Find out what the new height is supposed to be. */
00185       if (*line)
00186         new_height = atoi (line);
00187 
00188       /* Clear the echo area if it isn't active. */
00189       if (!echo_area_is_active)
00190         window_clear_echo_area ();
00191 
00192       free (line);
00193     }
00194 
00195   terminal_clear_screen ();
00196   display_clear_display (the_display);
00197   screenheight = new_height;
00198 #ifdef SET_SCREEN_SIZE_HELPER
00199   SET_SCREEN_SIZE_HELPER;
00200 #endif
00201   if (screenheight == old_height)
00202     {
00203       /* Display dimensions didn't actually change, so
00204         window_new_screen_size won't do anything, but we've
00205         already cleared the display above.  Undo the damage.  */
00206       window_mark_chain (windows, W_UpdateWindow);
00207       display_update_display (windows);
00208     }
00209   else
00210     {
00211       display_initialize_display (screenwidth, screenheight);
00212       window_new_screen_size (screenwidth, screenheight);
00213     }
00214 }