看标题原以为跟 showkey.el 一类的事显示按键的命令的呢, 原来是写 elisp 提示按键的时候, 不用写死的按键, 而用对应的命令的方式---当命令对应的按键被重定义就显示出合理性来了.
If you ever need to show the keybinding for a particular command to the users of your package (e.g. you’re adding some tips functionality), you should avoid resisting the urge to write something like this:
(message "Press <C-c p p> to switch between projects.")
Why is this a bad idea? Because you might change the keybinding of the command in question (e.g.
projectile-switch-project, but you might forget to update messages like this. Is there a better way?
substitute-command-keys to the rescue:
(message (substitute-command-keys "Press <\\[projectile-switch-project]> to switch between projects"))
This will produce exactly the same message as before and you’re guaranteed the keybinding will always be in sync with the command.
P.S. If you want to check interactively the keybinding of some command use
C-h f (
describe-function). Here’s an example -
C-h f RET projectile-switch-project RET will produce this:
projectile-switch-project is an interactive compiled Lisp function. It is bound to C-c p p, s-p p, <menu-bar> <tools> <Projectile> <Switch to project>. (projectile-switch-project &optional ARG1) ...
You can also check which command is bound to some key with
原文时间: 2016-02-01 14:23
整理时间: 2016-02-01 20:15
本文由 Hick 整理，转载请保留以上信息;
The articles on this site come from Internet, thanks to all the original authors.
If anything about COPYRIGHT, or LEFT, please contact Emacsist at gmail dot com .