4

I have two modes that bind a key. How can I choose which one should get to do its thing?

I'm asking generally but currently the situation is that when I'm in a certain mode, I want to use its bindings (which are currently shadowed by another mode).

I even tried to add a hook that local-set-keys at the end of my init file but that doesn't work, it gets shadowed too.

4
  • Most simply, minor mode keymaps take precedence over the local (major mode, usually) keymap, which takes precedence over the global keymap. Minor mode keymap precedence is based on the order of minor-mode-map-alist at any given time (you can use after-load-functions to programatically massage this as new libraries are loaded). However there are more (and more complex) levels of keymap than this. You should update your question with precise details of what you are doing. Include the relevant elisp.
    – phils
    Jan 13, 2017 at 14:01
  • 1
    See the Elisp manual, node Active Keymaps.
    – Drew
    Jan 13, 2017 at 15:11
  • minor-mode keymaps always take precedence over the major mode and your local-keymap (which is usually a modified copy of the major-mode map). However, the problem you've run into is that multiple minor-modes can conflict with each other, and there's no built-in way to force one to have priority over another. See emacs.stackexchange.com/questions/13447/… for a workaround
    – Tyler
    Dec 6, 2018 at 17:27
  • "mode" is too vague to be able to answer. Minor mode? Major mode? Just tell us which modes you're thinking of.
    – Stefan
    Dec 6, 2018 at 20:02

0

Browse other questions tagged or ask your own question.