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 know I can use define-key
for that, but I would like to keep the binding for other buffers/major modes.
Can anyone help?
A minor mode is an optional editing mode that alters the behavior of Emacs in some well-defined way. Unlike major modes, any number of minor modes can be in effect at any time. Some minor modes are buffer-local, and can be turned on (enabled) in certain buffers and off (disabled) in others.
Creating a new minor mode is really easy, it's just a matter of understanding Emacs' conventions. Mode names should end in -mode and the command for toggling the mode should be the same name. They keymap for the mode should be called mode -map and the mode's toggle hook should be called mode -hook .
It's a bit cumbersome to do. You can do something like:
(add-hook '<major-mode>-hook
(lambda ()
(let ((oldmap (cdr (assoc '<minor-mode> minor-mode-map-alist)))
(newmap (make-sparse-keymap)))
(set-keymap-parent newmap oldmap)
(define-key newmap [<thekeyIwanttohide>] nil)
(make-local-variable 'minor-mode-overriding-map-alist)
(push `(<minor-mode> . ,newmap) minor-mode-overriding-map-alist))))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With