EmacsでCucumberのfeatureをシンタックスハイライトするにはcucumber-mode.elが便利
Cucumberのfeatureをemacsで編集しようとするとシンタックスが色づけされないのでとても不便です。
そういうときはcucumber-mode.elを使いましょう。
http://github.com/michaelklishin/cucumber.el/tree/master
インストール方法
インストールするにはgithubからcloneした中にあるcucumber-mode.elをパスの通ったディレクトリにコピーします。
$ git clone git://github.com/michaelklishin/cucumber.el.git $ tree cucumber.el cucumber.el |-- cucumber-mode.el `-- snippets `-- feature-mode |-- and |-- fea |-- giv |-- sce |-- the `-- whe 2 directories, 7 files
またcucumber-mode.elにはyasnippet用のsnippetが添付されているのでsnippetフォルダの中にfeature-modeフォルダを放り込んどきましょう。
もし、まだyasnippetをインストールしていないのであればかなり便利なのでインストールをおすすめします。
http://code.google.com/p/yasnippet/
あとは~/.emacsに以下を書くだけです。
(require 'cucumber-mode)
ただ、このcucumber-modeをインストールして再起動すると正常に起動しなかったので
(provide 'cucumber-mode)
をcucumber-mode.elの末尾に追加しました。
あと、私はfeatureを日本語で書きたいので日本語の予約語でも動くように以下のように編集しています。
(eval-when-compile (require 'cl)) ;; ;; Keywords and font locking ;; (defconst feature-mode-keywords '("Feature" "Scenario", "Given", "Then", "When", "And", "フィーチャ", "シナリオ", "前提", "ならば", "かつ")) (cond ((featurep 'font-lock) (or (boundp 'font-lock-variable-name-face) (setq font-lock-variable-name-face font-lock-type-face))) (set (make-local-variable 'font-lock-syntax-table) feature-font-lock-syntax-table)) (defconst feature-font-lock-keywords (list '("^ *Feature:" (0 font-lock-keyword-face) (".*" nil nil (0 font-lock-type-face t))) '("^ *Scenario\\(?: Outline\\)?:" (0 font-lock-keyword-face) (".*" nil nil (0 font-lock-function-name-face t))) '("^ *Given" . font-lock-keyword-face) '("^ *When" . font-lock-keyword-face) '("^ *Then" . font-lock-keyword-face) '("^ *And" . font-lock-keyword-face) '("^ *フィーチャ:" (0 font-lock-keyword-face) (".*" nil nil (0 font-lock-type-face t))) '("^ *シナリオ\\(?: Outline\\)?:" (0 font-lock-keyword-face) (".*" nil nil (0 font-lock-function-name-face t))) '("^ *前提" . font-lock-keyword-face) '("^ *もし" . font-lock-keyword-face) '("^ *ならば" . font-lock-keyword-face) '("^ *かつ" . font-lock-keyword-face) '("^ *\\(?:More \\)?Examples:" . font-lock-keyword-face) '("^ *#.*" 0 font-lock-comment-face t) )) ~以下略~
もし必要であればsnippetも修正してください。