Restoring Keybinding changed by major mode

The Markdown major mode in Emacs binds M-<right> and M-<left> to markdown-demote and markdown-promote, respectively.

On a Mac keyboard, the key combinations above correspond to “Option” + right/left arrow. A more “natural” binding of these keys, in my opinion, is with forward and backward word, the behavior these two keys have in any other mode.

The simplest solution I have found to the problem is putting in .emacs the following code

(eval-after-load "markdown-mode"
     (define-key markdown-mode-map (kbd "M-<right>") nil)
     (define-key markdown-mode-map (kbd "M-<left>") nil)

Setting the keybinding to nil, in fact, removes it from the mode and restores the original behavior.

I found the solution after reading How to override/change mode key bindings in elisp?, which shows how to solve the same issue for a Dired-X binding.

I made it into a post, since I had to try a bit before finding the solution which I like the most.

Get in touch