バッファ固有のキーバインディングを設定する一般的な方法を次に示します。
- 以下にスニペット保存(一時的なマイナーモードを作成
temp-mode.elし、requireそれはあなたにinit.el。
- その
temp-modeマイナーモードを有効にし、必要なバッファーのみでそのマイナーモードのキーマップを定義します。
以下のLocal Variablesスニペットを、カスタムキーバインディングが必要なバッファーに配置します。以下はorg-modeファイルの例です。
バッファONE内
# Local Variables:
# eval: (temp-mode 1)
# eval: (define-key temp-mode-map (kbd "<f10>") 'function-ONE)
# End:
他のバッファが同じキーバインディングを使用して再定義する場合、
バッファー2
# Local Variables:
# eval: (temp-mode 1)
# eval: (define-key temp-mode-map (kbd "<f10>") 'function-TWO)
# End:
次に、新しいバインディングが実行時に有効になりM-x revert-bufferます。
これは、これら2つのバッファーを頻繁に切り替える必要がありF10、両方でバインディングを使用する必要がある場合に行うことです。
- バッファー1で作業し
C-x C-s(保存)、バッファー2に切り替えます
revert-buffer(バインディングを更新)、バッファー2で作業し、C-x C-sバッファーONEに切り替えます
revert-buffer(バインディングを更新する)、バッファーONEで作業し、C-x C-sバッファーTWOに切り替える
しかし、私はむしろ、さまざまなバッファ固有のコマンドをさまざまなキーにバインドします。
一時的なマイナーモード
;; temp-mode.el
;; Temporary minor mode
;; Main use is to enable it only in specific buffers to achieve the goal of
;; buffer-specific keymaps
(defvar temp-mode-map (make-sparse-keymap)
"Keymap while temp-mode is active.")
;;;###autoload
(define-minor-mode temp-mode
"A temporary minor mode to be activated only specific to a buffer."
nil
:lighter " Temp"
temp-mode-map)
(provide 'temp-mode)