Previous: Keymaps and Minor Modes, Up: Minor Modes
パッケージeasy-mmodeは、マイナモードを実装する便利な方法を提供します。 これを使うと、単純なマイナモードを1つの自己完結した定義に指定できます。
このマクロは、mode(シンボル)という名前の新しいマイナモードを定義する。
このマクロは、マイナモードをトグルする modeという名前のコマンドを定義し、 その説明文字列をdocとする。
また、modeという名前の変数も定義する。 この変数はモードのオン/オフにしたがって
t
/nil
に設定される。 この変数はinit-valueに初期化される。文字列mode-indicatorは、モードがオンのときにモード行に 表示される文字列である。 それが
nil
であるとモード行にはモードを表示しない。省略可能な引数keymapは、マイナモードのキーマップを指定する。 これは、値がキーマップであるような変数の名前か、 つぎの形のバインディングを指定した連想リストであること。
(key-sequence . definition)
easy-mmode-define-minor-mode
を使った例を示します。
(easy-mmode-define-minor-mode hungry-mode "Toggle Hungry mode. With no argument, this command toggles the mode. Non-null prefix argument turns on the mode. Null prefix argument turns off the mode. When Hungry mode is enabled, the control delete key gobbles all preceding whitespace except the last. See the command \\[hungry-electric-delete]." ;; 初期値 nil ;; モード行への表示 " Hungry" ;; マイナモードのバインディング '(("\C-\^?" . hungry-electric-delete) ("\C-\M-\^?" . (lambda () (interactive) (hungry-electric-delete t)))))
これは、『hungryモード』という名前のマイナモードを定義します。
モードをトグルするコマンドの名前はhungry-mode
、
モードのオン/オフを表す変数の名前はhungry-mode
、
モードがオンのときに活性なキーマップを保持する
変数の名前はhungry-mode-map
です。
C-<DEL>とC-M-<DEL>に対するキーバインディングで
キーマップを初期化します。