はじめに
(
を入力すると対応する)
を自動で入力してくれるsmartparens-mode
。
シェルスクリプトを書く時にも便利なので、init.elでshell-script-mode
にadd-hookしたいと思ったが、
少しハマった。
shell-script-modeのフック
最初は次のようにhookを追加しようとした。
(add-hook 'shell-script--mode-hook 'smartparens-mode)
しかし、シェルスクリプトファイルを開いても自動的にsmartparens-modeは有効化しない。
webで調べた結果次のようなことがわかった。
shell-script-mode is an alias for sh-mode. I haven't checked, but I would suspect that only the hook variable for the 'real' function name is evaluated, so I think sh-mode-hook would be the one to use.
つまりshell-script-mode
はsh-mode
のエイリアスで、正式なフックはsh-mode-hook
となるはずだ。と。
(add-hook 'sh-mode-hook 'smartparens-mode)
これで試したところ、フックが効くようになった。
まとめ
shell-script-mode
にフックを追加したい場合はsh-mode-hook
を使う。