みつきんのメモ

組み込みエンジニアです。Interface誌で「Yocto Projectではじめる 組み込みLinux開発入門」連載中

Emacs shell-script-modeのフック

はじめに

(を入力すると対応する)を自動で入力してくれる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-modesh-modeエイリアスで、正式なフックはsh-mode-hookとなるはずだ。と。

(add-hook 'sh-mode-hook 'smartparens-mode)

これで試したところ、フックが効くようになった。

まとめ

shell-script-modeにフックを追加したい場合はsh-mode-hookを使う。