Buffer-locally overriding minor-mode key bindings in Emacs

后端 未结 3 694
梦谈多话
梦谈多话 2020-12-15 18:48

I want to use a minor mode which rebinds a major-mode key that I definitely want to keep. How can I rebind the key without deleting it from the minor-mode map globally? I kn

3条回答
  •  爱一瞬间的悲伤
    2020-12-15 19:43

    In my case, company-mode was overriding the cider-repl-mode bindings for M-p and M-n when the Company completions menu was showing. The keymap for the completions menu is company-active-map, but there's no minor mode corresponding to it (company-mode is for when the menu is not active), so I couldn't use any of the existing answers.

    Here's what I came up with instead:

    (add-hook 'cider-repl-mode-hook
              (lambda ()
                (make-local-variable 'company-active-map)
                (setq company-active-map (copy-tree company-active-map))
                (define-key company-active-map (kbd "M-p") nil)
                (define-key company-active-map (kbd "M-n") nil)))
    

提交回复
热议问题