简体   繁体   English

删除emacs中的主要模式键绑定

[英]Remove major mode key bindings in emacs

I installed a new major mode (sunrise commander), and I want to reset all its predefined key bindings. 我安装了新的主要模式(日出指挥官),并且想重置其所有预定义的键绑定。 Although I can use 虽然我可以用

(add-hook 'sr-mode-hook
    '(lambda ()
    (define-key sr-mode-map "KEY"        nil)
    ...
))

this mode have so many bindings, it's a tag tedious to my taste. 这种模式有很多绑定,这对我的口味来说是乏味的。

Is there a way to completely reset the key bindings of this major mode in a one-liner or few-liners? 有没有办法完全重置单行或几行这种主要模式的键绑定?


EDIT #1: I tried using these methods as described below: 编辑#1:我尝试使用如下所述的这些方法:

(eval-after-load "sunrise"
  '(setq sr-mode-map (make-sparse-keymap)))

OR 要么

(add-hook 'sr-mode-hook
    (lambda ()
    (setq sr-mode-map (make-sparse-keymap))))

Sadly, neither of them seems to work. 可悲的是,它们似乎都不起作用。

Do I actually need to define a new, empty keymap? 我是否真的需要定义一个新的空键盘图? Eg using 例如使用

(defvar sunrise-keys-mode-map (make-keymap) "sunrise-keys-mode keymap.")
(define-minor-mode sunrise-keys-mode
  "A minor mode so that my key settings override sunrise major mode keymap."
  t " my-keys" 'sunrise-keys-mode-map)
(sunrise-keys-mode 1)
(eval-after-load "sunrise" ;; Fix this line to include the correct library name
  '(setq sr-mode-map (sunrise-keys-mode)))

EDIT #2: After a bit of tinkering in the sunrise commander code, I noticed that the sr-mode-map is based on the dired mode map. 编辑#2:在修改了日出指挥官代码后,我注意到sr-mode-map是基于dired模式映射的。 I disabled both, and it worked perfectly. 我都禁用了它,并且效果很好。

(eval-after-load "sunrise-commander"
  '(setq sr-mode-map (make-sparse-keymap)
         dired-mode-map (make-sparse-keymap)))

For future reference - the above is the only code needed. 供以后参考-上面是唯一需要的代码。 make-sparse-keymap is a function that returns an empty keymap (unless provided with an argument, apparently). make-sparse-keymap是一个函数,它返回一个空的键盘映射(显然,除非提供了参数)。

You cound bind sr-mode-map to a newly-created, empty keymap: 您将sr-mode-map绑定到新创建的空keymap:

(setq sr-mode-map (make-sparse-keymap))

You might need to delay this until after sunrise commander is loaded: 您可能需要将其延迟到加载日出指挥官之后:

(eval-after-load "sc" ;; Fix this line to include the correct library name
  '(setq sr-mode-map (make-sparse-keymap)))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM