Mercurial > emacs
changeset 13108:04466bd88580
(Vsuggest_key_bindings): New variable.
(syms_of_keyboard): Set up Lisp variable.
(Fexecute_extended_command): When enabled, show an equivalent key binding.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 03 Oct 1995 09:17:37 +0000 |
parents | fab67884f69a |
children | acb0ab49f4e7 |
files | src/keyboard.c |
diffstat | 1 files changed, 79 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/keyboard.c Tue Oct 03 09:15:49 1995 +0000 +++ b/src/keyboard.c Tue Oct 03 09:17:37 1995 +0000 @@ -172,6 +172,12 @@ /* List of items that should move to the end of the menu bar. */ Lisp_Object Vmenu_bar_final_items; +/* Non-nil means show the equivalent key-binding for + any M-x command that has one. + The value can be a length of time to show the message for. + If the value is non-nil and not a number, we wait 2 seconds. */ +Lisp_Object Vsuggest_key_bindings; + /* Character that causes a quit. Normally C-g. If we are running on an ordinary terminal, this must be an ordinary @@ -6367,8 +6373,75 @@ current_kboard->Vprefix_arg = prefixarg; this_command = function; + /* If enabled, show which key runs this command. */ + if (!NILP (Vsuggest_key_bindings) + && SYMBOLP (function)) + { + Lisp_Object *maps, bindings; + int nmaps, i; + + bindings = Qnil; + nmaps = current_active_maps (&maps); + + for (i = 0; i < nmaps && NILP (bindings); i++) + bindings = Fwhere_is_internal (function, maps[i], Qt, Qnil); + + free (maps); + + if (!NILP (bindings)) + { + message ("You can run the command `%s' by typing %s", + XSYMBOL (function)->name->data, + XSTRING (Fkey_description (bindings))->data); + Fsit_for ((NUMBERP (Vsuggest_key_bindings) + ? Vsuggest_key_bindings : make_number (2)), + Qnil, Qnil); + } + } + return Fcommand_execute (function, Qt); } + +/* Find the set of keymaps now active. + Store into *MAPS_P a vector holding the various maps + and return the number of them. The vector was malloc'd + and the caller should free it. */ + +int +current_active_maps (maps_p) + Lisp_Object **maps_p; +{ + Lisp_Object *tmaps, *maps; + int nmaps; + + /* Should overriding-terminal-local-map and overriding-local-map apply? */ + if (!NILP (Voverriding_local_map_menu_flag)) + { + /* Yes, use them (if non-nil) as well as the global map. */ + maps = (Lisp_Object *) xmalloc (3 * sizeof (maps[0])); + nmaps = 0; + if (!NILP (current_kboard->Voverriding_terminal_local_map)) + maps[nmaps++] = current_kboard->Voverriding_terminal_local_map; + if (!NILP (Voverriding_local_map)) + maps[nmaps++] = Voverriding_local_map; + } + else + { + /* No, so use major and minor mode keymaps. */ + nmaps = current_minor_maps (NULL, &tmaps); + maps = (Lisp_Object *) xmalloc ((nmaps + 2) * sizeof (maps[0])); + bcopy (tmaps, maps, nmaps * sizeof (maps[0])); +#ifdef USE_TEXT_PROPERTIES + maps[nmaps++] = get_local_map (PT, current_buffer); +#else + maps[nmaps++] = current_buffer->keymap; +#endif + } + maps[nmaps++] = current_global_map; + + *maps_p = maps; + return nmaps; +} detect_input_pending () @@ -7407,6 +7480,12 @@ This function is called with no arguments after each command\n\ whenever `deferred-action-list' is non-nil."); Vdeferred_action_function = Qnil; + + DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings, + "Non-nil means show the equivalent key-binding when M-x command has one.\n\ +The value can be a length of time to show the message for.\n\ +If the value is non-nil and not a number, we wait 2 seconds."); + Vsuggest_key_bindings = Qt; } keys_of_keyboard ()