5

Whenever one runs a function/command for which there is already a shortcut, Emacs shows briefly a message in the echo area to recall that there is a shortcut associated with that command.

For example if I run backward-word, Emacs shows for some seconds the following in the echo area:

You can run the command `backward-word' with M-b

Is there a mechanism for the reverse of this? i.e., to recall the name of function when one uses a shortcut to revoke a command. I know by the command describe-key I can find which function corresponds to which shortcut. But it would be interesting to see the name of function every time one runS a shortcut.

  • 1
    You would probably only want to invoke this selectively on a few commands, because otherwise, every time you type, you'll get self-insert-command over and over in the echo area (corresponding to each of the letter/number keys, which invoke that command). – Dan Oct 27 '16 at 12:15
5

You can use post-command-hook.

(defun my-echo-command-name-hook ()
  (unless (or (eq this-command 'self-insert-command)
              (eq this-command 'next-line))
    (message "%s" this-command)))

(add-hook 'post-command-hook 'my-echo-command-name-hook)
  • Thanks, is there a way to exclude some obvious commands for example self-insert-command mentioned by Dan in the above comment? – Name Oct 27 '16 at 12:24
  • This was not a part of my question, but is it possible to modify your code in order that this message disappears after 2 or 3 seconds? – Name Oct 27 '16 at 12:56
  • This is not a general solution. E.g., org-mode uses org-self-insert-command in-place of self-insert-command. – Tobias Oct 27 '16 at 13:28
  • 1
    When I want to see my used commands I use command-log-mode and clm/toggle-command-log-buffer. However the commands are not displayed in the echo area that way. – bertfred Oct 27 '16 at 13:54
4

Library ShowKey (code: showkey.el does this. It shows keys and other events as you use them.

And yes, you can tailor the behavior, to ignore certain event types (e.g., key sequences) for display.

There are two global minor modes defined in showkey.el, which give you two ways to show keys:

  • showkey-tooltip-mode: Show only the last key used, in a tooltip. This is refreshed with each such event.

  • showkey-log-mode: Show a log of such events, in a separate frame. It is refreshed with each new event, and it is kept on top of other frames without stealing the input focus.

Events that raise an error are not shown.

A few user options control the behavior:

  • showkey-tooltip-ignored-events and showkey-log-ignored-events are each a list of regexps to match against events that you do not want to show, for showkey-tooltip-mode and showkey-log-mode, respectively.

  • showkey-log-frame-alist is an association list of frame parameters for the logging frame. (It is not used for showkey-tooltip-mode.)

  • showkey-log-erase-keys is a list of keys that will each restart logging, that is, erase the log and start it over. For example, if you add the RET key to it (?\r) then each time it is pressed the log is restarted from scratch. By default, the list is empty. (It is not used for showkey-tooltip-mode.)

  • showkey-tooltip-timeout is the number of seconds to show the tooltip, before hiding it. (It is also hidden upon any user event, such as hitting another key.)

1

If you are using Emacs 25 or newer, the built-in command view-lossage (bound to C-h l) might be useful here. This shows you anything you've recently typed and the corresponding commands that were executed.

For example, the output might look like this:

 C-SPC [set-mark-command]
 C-e [move-end-of-line]
 M-w [kill-ring-save]
 C-x o [other-window]
 C-y [yank]
 C-h l [view-lossage]

This command exists in earlier versions of Emacs as well, but prior to Emacs 25 it did not display the commands that were run.

  • Thanks, I tested Emacs 25 and it seems that your suggestion is fine. – Name Nov 2 '16 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.