I use ace-window to change windows, with M-o as my key-binding.

However, when I enter a window that is in HTML mode, this gets clobbered to "set face." I'm now stuck in this window, and can't M-o my way back out.

I have the following in my ace-window config, which specifies the key is global:

(use-package ace-window
  (setq aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l))
  (setq aw-dispatch-always t)
  (global-set-key (kbd "M-o") 'ace-window)

How can I stop html-mode for now, and /any/ mode in general, from clobbering the global keybinding?

I'm generally learning about key-bindings from here.


This was marked a duplicate but it’s not clear to me how to apply the links to this problem. I didn’t load markdown-mode in my init.el as these suggest editing—it automatically clobbered my keybindings with defaults without any loader.

What I’m looking for in this question is specifically how can I make the keybindings in ace-jump un-overwritable, even if rogue modes load themselves after.

  • This is a duplicate. See here, for example: emacs.stackexchange.com/questions/23800/… Commented Jan 2, 2023 at 8:40
  • Does this answer your question? Emacs ignoring global keybindings Commented Jan 2, 2023 at 8:40
  • See Searching the Active Keymaps: the global keymap is the last keymap to be looked at, so if a higher-precedence keymap binds the key, that's what you will end up with. So they don't really clobber the global keybinding: they just shadow it.
    – NickD
    Commented Jan 2, 2023 at 8:52
  • 1
    As to an immutable keybinding, the answer is "no", but that is not the problem you have (as I tried to explain): the keybinding in the global map is not changed - it is still there, but it is shadowed by a keybinding in a different map that is of higher priority. As for a hook, I don't think that packages do that in general, so even if some did, it would still be a whack-a-mole thing. Your best bet IMO is to use a "safe" keybinding in the global map (maybe C-c o to make it as similar to M-o if you are inclined that way).
    – NickD
    Commented Jan 2, 2023 at 17:58
  • 1
    In your update you say "What I’m looking for in this question is specifically how can I make the keybindings in ace-jump un-overwritable, even if rogue modes load themselves after." and as explained, there is no way to do that. Even with an overriding keymap as in @FranBurstall's answer, a "rogue" mode can add its own overriding keymap, so it can always throw a wrench into the machinery. That is why Emacs reserves some keys that by convention packages will not use, but even here a rogue package can flout the convention and cause havoc.
    – NickD
    Commented Jan 3, 2023 at 14:26

1 Answer 1


Sorry: I was reluctant to add to the gazillion "global-set-key does not work" answers but the comments indicate that I did not say enough. Anyway, here is an actual answer:

  1. By now it should be clear that the global-keymap is at the bottom of the keymap hierarchy and will be overridden by almost any other keymap.
  2. There is however a solution for use-package users:
(use-package ace-window
  :demand t
  (setq aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l))
  (setq aw-dispatch-always t)
  :bind*("M-o" . ace-window))

This invokes the bind-key package which provides an over-riding keymap. Do C-h P bind-key for more information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.