diff options
author | Richard M. Stallman <rms@gnu.org> | 1995-10-03 09:17:37 +0000 |
---|---|---|
committer | Richard M. Stallman <rms@gnu.org> | 1995-10-03 09:17:37 +0000 |
commit | af709d63a8ca6812cd69878ffc4c6a491d874fde (patch) | |
tree | 401cfb30bf7d7defba5c08fdcdb44c5c36aa6f0c /src/keyboard.c | |
parent | 2013bdfd286edd7d76aa4f8df8ec61c43897e715 (diff) | |
download | emacs-af709d63a8ca6812cd69878ffc4c6a491d874fde.tar.gz |
(Vsuggest_key_bindings): New variable.
(syms_of_keyboard): Set up Lisp variable.
(Fexecute_extended_command): When enabled, show an equivalent key binding.
Diffstat (limited to 'src/keyboard.c')
-rw-r--r-- | src/keyboard.c | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/keyboard.c b/src/keyboard.c index b4401f4fd62..23ab91f9745 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -172,6 +172,12 @@ Lisp_Object Vprefix_help_command; /* 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 @@ DEFUN ("execute-extended-command", Fexecute_extended_command, Sexecute_extended_ 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 @@ The precise format isn't relevant here; we just check whether it is nil."); 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 () |