1

ここで説明されているように、独自のユーザー定義のキーバインディングがあります: Emacs でキーバインディングをグローバルにオーバーライドする

OrgMode などの新しいメジャー モードをロードするたびに、その特定のモードでのニーズに合わせて、バインディングの一部を上書きします。しかし、独自の上書きがある別のメジャーモードをロードすると、そのメジャーモードのバッファにいなくても、それらはそのまま残ります。

例えば

(define-key custom-keys-mode-map (kbd "C-p") 'some-cool-function)
(add-hook 'org-mode-hook
    (lambda ()
    (define-key custom-keys-mode-map (kbd "C-p") 'org-cool-function )))
(add-hook 'sunrise-mode-hook
    (lambda ()
    (define-key custom-keys-mode-map (kbd "C-p") 'sunrise-cool-function )))

最初に、Cp を使用してクールなデフォルトの関数を実行します。Org-Mode をロードした後、Cp を使用して「org-cool-function」を実行し、Sunrise-Commander をロードすると、Cp は「sunrise-cool-function」を実行します。

しかし、Org-Mode ファイルに戻ると、Cp は「org-cool-function」ではなく「sunrise-cool-function」を実行しようとします。

私が明確であることを願っています:)

4

3 に答える 3

6

表示される動作は、コードから期待されるものです。次のようになります。

  • あなたはemacsを起動し、some-cool-function割り当てられます
  • その後、新しい組織ファイルを開くたびに(バッファを切り替えるだけでなく)org-cool-function割り当てられます
  • 起動するたびsunrise-commander sunrise-cool-functionに割り当てられます

あなたの問題は、ローカルイベントからグローバルプロパティを設定しようとしたことに起因します。

キーバインディングを配置するorg-mode-map代わりにを使用する必要があります。これにより、組織のコンテンツを含むすべてのバッファーに対して一度だけ設定されます。custom-keys-mode-mapC-p

(define-key custom-keys-mode-map (kbd "C-p") 'some-cool-function)
(eval-after-load "org"
  '(define-key org-mode-map (kbd "C-p") 'org-cool-function))
于 2013-04-08T19:20:28.390 に答える
3

Minor mode maps supersede major mode maps which supersede the global map.

So a few options are:

  1. Do not include these bindings in your custom minor mode map at all. Make your preferred binding a plain global binding, and let the major modes over-ride it as required.

  2. Create additional minor modes to take precedence over your existing minor mode, and enable them in the corresponding major modes. Each minor mode's position in minor-mode-map-alist determines precedence when looking up key bindings, so you need these additional modes to be defined after your current mode is defined (meaning that they will appear earlier in the alist), and of course keep them in that order if updating that list dynamically.

  3. Leave everything the way it is, but bind these keys to custom functions which check the major mode and act accordingly. You may or may not need to take care of passing on prefix arguments if you take this approach.

于 2013-04-08T21:13:39.910 に答える