4

Even after following all that was given in Globally override key binding in Emacs I still couldn't get it to work.

I bound M-o to other-window in my global key map like this:

(defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.")
(define-key my-keys-minor-mode-map "\M-o" 'other-window)

(define-minor-mode my-keys-minor-mode
  "A minor mode so that my key settings override annoying major modes."
  t " my-keys" 'my-keys-minor-mode-map)

(my-keys-minor-mode 1)

(defun my-minibuffer-setup-hook ()
  (my-keys-minor-mode 0))
(add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-hook)

;; Maintain the above keymap even after loading a new library
(defadvice load (after give-my-keybindings-priority)
  "Try to ensure that my keybindings always have priority."
  (if (not (eq (car (car minor-mode-map-alist)) 'my-keys-minor-mode))
      (let ((mykeys (assq 'my-keys-minor-mode minor-mode-map-alist)))
        (assq-delete-all 'my-keys-minor-mode minor-mode-map-alist)
        (add-to-list 'minor-mode-map-alist mykeys))))
(ad-activate 'load)

but dired mode overrides this and remaps it to dired-omit-mode.

What am I missing ?

Community
  • 1
  • 1
user994572
  • 139
  • 1
  • 11
  • That configuration works for me (in Emacs 24.2). If I `load-library dired-x` to get the `dired-omit-mode` binding (either before or after evaluating the code above), then I still see your binding for `M-o` when in dired (unless I disable `my-keys-minor-mode`, in which case I see `dired-omit-mode`). – phils Sep 21 '12 at 08:45

1 Answers1

3

Your minor mode is defined to be buffer-local. You can Define it to be global, like this:

(define-minor-mode my-keys-minor-mode
  "A minor mode so that my key settings override annoying major modes."
  :global t
  :lighter " my-keys")

But then your my-minibuffer-setup-hook will turn it off globally as well. Also if it's global and you basically always have it ON, you might prefer to not provide the :lighter " my-keys", so your mode-line isn't filled unnecessarily.

Stefan
  • 27,908
  • 4
  • 53
  • 82