1

Some of the packages I use define keybindings that I want to overwrite or remove. How do I overwrite/remove these keybindings?

For example, I use ace-window and speedbar together. ace-window uses M-p for switching windows, and I want to keep that binding. However, it's used by speedbar for speedbar-restricted-prev with (define-key map "\M-p" 'speedbar-restricted-prev) in the source).

I don't know what speedbar-restricted-prev does and I don't think I will be using it. This is how I have configured ace-window. What else do I need to do to disable the binding of M-p in speedbar? Outside of speedbar it works.

(use-package ace-window
  :ensure t
  :defer t
  :init
  (progn
    (global-set-key (kbd "M-p") 'ace-window)
    (setq aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l))
     ;;more info at https://github.com/abo-abo/ace-window
    ))
Dan
  • 32,584
  • 6
  • 98
  • 168
vfclists
  • 1,347
  • 1
  • 11
  • 28
  • See https://emacs.stackexchange.com/a/12385/105. Just bind the key to `nil` in the appropriate keymap. – Drew Aug 04 '17 at 16:44

1 Answers1

2
(define-key speedbar-mode-map "\M-p" nil)

should remove the binding of M-p from the speedbar map, so that it no longer interferes with your binding for ace-window.

You'll need to call this after speedbar-mode is loaded for it to have effect. Since you're using use-package, you can accomplish this by adding it as a :config option, e.g.,

(use-package sr-speedbar
  :ensure t
  :defer t
  :config     (define-key speedbar-mode-map "\M-p" nil)
  ...)

More generally, you can use eval-after-load:

(eval-after-load "speedbar"
    '(define-key speedbar-mode-map "\M-p" nil))
Tyler
  • 21,719
  • 1
  • 52
  • 92
  • [pastebin of current config[(https://pastebin.com/niciAQcc) - At what point in the cycle should the `define-key` be executed. I am aware of `add-hook` options but don't know how to use them. Would putting the above command after the `(sr-speedbar-open)` be okay? How would I guarantee that the setting in `ace-window` would came into effect only after your `define-key` had been applied? – vfclists Aug 04 '17 at 16:41
  • With this config, it doesn't matter if the `ace-window` setting comes before or after `speedbar`. – Tyler Aug 04 '17 at 17:21