如何显示重写/阴影键绑定?

时间:2012-12-20 11:30:33

标签: emacs

在emacs中,如何为当前缓冲区显示阴影/重写的键绑定? 运行describe-bindingsC-h b)时,它们不会显示。

换句话说:如何查看缓冲区中活动的模式是否存在冲突的键绑定?

2 个答案:

答案 0 :(得分:9)

只需致电describe-mode C-h m

大多数模式文档字符串将显示其键盘映射,此处用于列出它们的方法也会告诉您是否遮蔽了绑定。

它并没有告诉你它被遮蔽了什么,但当然用 Ch c Ch 进行检查是微不足道的ķ

e.g:

key             binding
---             -------
[...]
C-M-q           indent-sexp
  (that binding is currently shadowed by another mode)

该文本由函数substitute-command-keys生成,该函数在调用documentation函数时处理模式docstring。

e.g:

(substitute-command-keys "\\{lisp-interaction-mode-map}")

以下功能也很有用:

(key-binding KEY &optional ACCEPT-DEFAULT NO-REMAP POSITION) ;; dominant binding
(global-key-binding KEYS &optional ACCEPT-DEFAULT)
(local-key-binding KEYS &optional ACCEPT-DEFAULT)
(minor-mode-key-binding KEY &optional ACCEPT-DEFAULT) ;; discover keymap(s)

答案 1 :(得分:0)

对于它,我做到了这一点:

(define-key c++-mode-map "\C-c\C-s" 'kaw-sort-projects)

然后做C-h b(看结合)。得到了这个输出:

Major Mode Bindings:
key             binding
---             -------

C-c C-q     c-indent-defun
C-c C-s     kaw-sort-projects
C-c C-u     c-up-conditional
C-c C-w     subword-mode

所以它似乎确实出现了。

这是你的意思吗?

创建此函数,在您定义键

时为您提供以前的值
(defun define-key-warn (map key fxn)
  "Bind a key and give info message if already bound"
  (setq old-fxn (lookup-key map key))
  (if old-fxn
      (message "INFO: key %s was defined as %s" key old-fxn))

  (define-key map key fxn)
)