11

paredit binds M-<up> and M-<down>, but I want windmove to own those keybindings. I have paredit-mode set to activate in certain modes only, but windmove is set to run globally. I want windmove to win, but paredit steals those keybindings when it loads.

How can I easily stop paredit from stomping on windmove's keybindings? I have been going into paredit.el and commenting out the lines which set the keybinding, but this is far from ideal (I have to remember to do this every time I update paredit).

More generally, can I load an elisp file while "protecting" certain keybindings from being changed?

Emerick Rogul
  • 6,706
  • 3
  • 32
  • 39
Brian Carper
  • 71,150
  • 28
  • 166
  • 168

2 Answers2

14

You can use eval-after-load to configure paredit's behavior after loading it, as described in its comments:

;;; Customize paredit using `eval-after-load':
;;;
;;;   (eval-after-load 'paredit
;;;     '(progn ...redefine keys, &c....))

So, for example:

(eval-after-load 'paredit
  '(progn
     (define-key paredit-mode-map (kbd "<M-up>") nil)
     (define-key paredit-mode-map (kbd "<M-down>") nil)))
Emerick Rogul
  • 6,706
  • 3
  • 32
  • 39
  • This is a also great general purpose answer - thanks so much. My one contribution is to point out that if also you want to alter a keybinding (rather than remove it), you would put the name of the paredit function where Emerick put the `nil` above, like I've done for "forward-slurp": `(eval-after-load 'paredit '(progn (define-key paredit-mode-map (kbd "") 'paredit-forward-slurp-sexp)))` – quux00 Aug 17 '12 at 12:57
1

This question has been answered before: Globally override key binding in Emacs

You create your own minor mode with your preferred keybindings and enable it globally, so that it overrides all other keybindings.

Community
  • 1
  • 1
Ryan C. Thompson
  • 40,856
  • 28
  • 97
  • 159