Restoring Keybindings changed by a Major Mode

Menu

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 forward and backward word respectively, the behavior these two keys have in other Emacs modes.

I solved the problem by adding the following code to my .emacs file:

(eval-after-load "markdown-mode"
    '(progn
       (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 search a bit before finding the solution which I like the most.

Author: Adolfo Villafiorita

Last modified: 2020-06-04 Thu 19:01 (created on: 2016-04-28 Thu 00:00)

Published: 2020-06-30 Tue 22:55