1 /* m-x.c -- Meta-x minibuffer reader.
2 $Id: m-x.c,v 1.3 2004/04/11 17:56:46 karl Exp $
4 Copyright (C) 1993, 1997, 1998, 2001, 2002, 2004 Free Software
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 2, or (at your option)
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, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 Originally written by Brian Fox (bfox@ai.mit.edu). */
26 /* **************************************************************** */
28 /* Reading Named Commands */
30 /* **************************************************************** */
32 /* Read the name of an Info function in the echo area and return the
33 name. A return value of NULL indicates that no function name could
36 read_function_name (char *prompt
, WINDOW
*window
)
40 REFERENCE
**array
= (REFERENCE
**)NULL
;
41 int array_index
= 0, array_slots
= 0;
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
++)
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
;
55 (entry
, array_index
, array
, array_slots
, 200, REFERENCE
*);
58 line
= info_read_completing_in_echo_area (window
, prompt
, array
);
60 info_free_references (array
);
62 if (!echo_area_is_active
)
63 window_clear_echo_area ();
68 DECLARE_INFO_COMMAND (describe_command
,
69 _("Read the name of an Info command and describe it"))
73 line
= read_function_name ((char *) _("Describe command: "), window
);
77 info_abort_key (active_window
, count
, key
);
81 /* Describe the function named in "LINE". */
84 InfoCommand
*cmd
= named_function (line
);
89 window_message_in_echo_area ("%s: %s.",
90 line
, function_documentation (cmd
));
95 DECLARE_INFO_COMMAND (info_execute_command
,
96 _("Read a command name in the echo area and execute it"))
102 prompt
= (char *)xmalloc (20);
104 keys
= where_is (info_keymap
, InfoCmd(info_execute_command
));
105 /* If the where_is () function thinks that this command doesn't exist,
106 there's something very wrong! */
110 if (info_explicit_arg
|| count
!= 1)
111 sprintf (prompt
, "%d %s ", count
, keys
);
113 sprintf (prompt
, "%s ", keys
);
115 /* Ask the completer to read a reference for us. */
116 line
= read_function_name (prompt
, window
);
121 info_abort_key (active_window
, count
, key
);
125 /* User accepted "default"? (There is none.) */
132 /* User wants to execute a named command. Do it. */
134 InfoCommand
*command
;
136 if ((active_window
!= the_echo_area
) &&
137 (strncmp (line
, "echo-area-", 10) == 0))
140 info_error ((char *) _("Cannot execute an `echo-area' command here."),
145 command
= named_function (line
);
151 if (InfoFunction(command
))
152 (*InfoFunction(command
)) (active_window
, count
, 0);
154 info_error ((char *) _("Undefined command: %s"), line
, NULL
);
158 /* Okay, now that we have M-x, let the user set the screen height. */
159 DECLARE_INFO_COMMAND (set_screen_height
,
160 _("Set the height of the displayed window"))
162 int new_height
, old_height
= screenheight
;
164 if (info_explicit_arg
|| count
!= 1)
171 new_height
= screenheight
;
173 sprintf (prompt
, _("Set screen height to (%d): "), new_height
);
175 line
= info_read_in_echo_area (window
, prompt
);
177 /* If the user aborted, do that now. */
180 info_abort_key (active_window
, count
, 0);
184 /* Find out what the new height is supposed to be. */
186 new_height
= atoi (line
);
188 /* Clear the echo area if it isn't active. */
189 if (!echo_area_is_active
)
190 window_clear_echo_area ();
195 terminal_clear_screen ();
196 display_clear_display (the_display
);
197 screenheight
= new_height
;
198 #ifdef SET_SCREEN_SIZE_HELPER
199 SET_SCREEN_SIZE_HELPER
;
201 if (screenheight
== old_height
)
203 /* Display dimensions didn't actually change, so
204 window_new_screen_size won't do anything, but we've
205 already cleared the display above. Undo the damage. */
206 window_mark_chain (windows
, W_UpdateWindow
);
207 display_update_display (windows
);
211 display_initialize_display (screenwidth
, screenheight
);
212 window_new_screen_size (screenwidth
, screenheight
);