4

即使遵循 了 Emacs 中全局覆盖键绑定中给出的所有内容, 我仍然无法让它工作。

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

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

我错过了什么?

4

1 回答 1

3

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

(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",因此您的模式行不会被不必要地填充。

于 2012-09-21T13:35:52.313 回答