即使在遵循所有给出的内容之后
Globally override key binding in Emacs
我仍然无法让它工作。

我将 M-o 绑定(bind)到全局键映射中的其他窗口,如下所示:

(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)

但是 dired 模式会覆盖它并将其重新映射到 dired-omit-mode

我错过了什么?

最佳答案

您的次要模式被定义为缓冲区本地。您可以将其定义为全局的,如下所示:

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

但是随后您的 my-minibuffer-setup-hook 也会在全局范围内将其关闭。此外,如果它是全局的并且您基本上总是将其打开,您可能更愿意不提供 :lighter " my-keys" ,因此您的模式行不会被不必要地填充。

10-08 14:02