js2-modeでyasnippet

yasnippetスニペットフォルダにjs2-modeというフォルダを追加して、その下にスニペットを追加してみたんだが動かない。試しに手動で yas/minor-modeにしてみると、追加したスニペットの展開が行われるようになった。単純に js2-mode と yas/minor-mode の関連付けがうまく行っていない様子。
少し調べてみたら、解決策が見つかった。

Google Code Archive - Long-term storage for Google Code Project Hosting.より

Why YASnippet doesn't work in some modes?

Try: M-x yas/minor-mode-on.

- If it still doesn't work. Try to ask for help in the discussion group or report a bug.
- If it works. Add the mode-hook to yas/extra-mode-hooks.

YASnippet is enabled when yas/minor-mode is turned on. after-change-major-mode-hook is used to turn on yas/minor-mode in every mode. However, some modes (which doesn't follow the convention, like ruby-mode) just don't call this hook. So we need to explicitly hook into them:


(add-to-list 'yas/extra-mode-hooks
'ruby-mode-hook)


Note you should put this code after (require 'yasnippet) but before (yas/initialize).

You can report the modes that don't work to the discussion group. I'll include them in yas/extra-mode-hooks in later version when I see your report.

なので、.emacs の(require 'yasnippet)の後、(yas/initialize)の前へ以下の行を追加する事で、関連付けが行われるようになった。

;; js2-mode へのyas/minor-mode の関連づけ
(add-to-list 'yas/extra-mode-hooks
             'js2-mode-hook)