roro
roro

Reputation: 940

Can't rebind C-M-q in emacs

I'm trying to set some custom bindings and have ran into a puzzling problem, I'm unable to rebind C-M-q or unbind it entirely. I have no trouble rebinding other keys, so I don't know what is special about C-M-q. Below are some of the things I've tried in my .emacs file.

;;(global-set-key (kbd "C-M-q") nil)
;;(global-unset-key (kbd "C-M-q"))
;;(global-set-key (kbd "C-M-q") 'shrink-window-horizontally)
(global-set-key (kbd "C-M-y") 'shrink-window-horizontally)
(global-set-key (kbd "C-M-w") 'shrink-window)
(global-set-key (kbd "C-M-e") 'enlarge-window)
(global-set-key (kbd "C-M-r") 'enlarge-window-horizontally)

No matter what I try, the C-h k command says C-M-q is bound to

C-M-q runs the command indent-pp-sexp, which is an interactive compiled Lisp function in `lisp-mode.el'.

It is bound to C-M-q.

Upvotes: 0

Views: 219

Answers (1)

phils
phils

Reputation: 73256

The global keymap is the lowest-priority keymap, whereas this binding is in the local (major mode) keymap for the buffer you are looking at (which is a lisp buffer), so Emacs never sees your global keymap changes, because it has found a binding before getting that far.

Specifically, this binding is in lisp-mode-shared-map (a parent keymap for several lisp modes), which is shadowing a more generic binding in prog-mode-map. Other programming modes have their own bindings for this key, to ensure that it will always have some kind of "indent expression" behaviour.

As such, I would suggest you don't clobber this binding, as there's a standard use for it. If you really want to do so, then you should look at Globally override key binding in Emacs.

Emacs has many layers of keymaps, and it's important to have an idea of how the system works, so I highly recommend taking the time to read the following article on the subject:

https://www.masteringemacs.org/article/mastering-key-bindings-emacs

Upvotes: 1

Related Questions