M-x compileでスクリプトを実行
EmacsからRubyスクリプトを実行するときには、M-x compileを使うと便利だと気付きました。詳細は、ruby-list:40996のスレッドからruby-list:40997を参照。この設定をしておくとユニットテストでエラーが発生した場合に、M-x next-errorでその行に飛べます。
以下の2点がポイントです。
- M-x compile、M-x next-errorを入力しやすいキーバインドに置き換えておくこと。僕はこんな感じで割り当てています。
(global-set-key "\C-xn" 'next-error) (global-set-key "\M-c" 'compile)
以下、実行例です。
ファイル: a.rb
#!/usr/bin/env ruby # -*- compile-command: "ruby a.rb" -*- p 123
M-x compile実行例。エラーが発生したら、M-x next-errorでその行に飛べます。
-*- mode: compilation; default-directory: "c:/Documents and Settings/s-tanaka/デスクトップ/" -*- Compilation started at Thu Jun 28 22:55:40 ruby a.rb 123 Compilation finished at Thu Jun 28 22:55:41