EmacsでRubyの開発環境を整えた
突然Rubyが書きたくなったので、EmacsでRubyの開発環境を整えた。elispのインストールは全てel-getを使った。
環境
ruby-mode
標準で入っていたのを使う。あとGemfileをruby-modeで開くように設定。
(add-to-list 'auto-mode-alist '("Gemfile$" . ruby-mode))
inf-ruby.el
Emacsからirbを使えるようにする。
inf-ruby-keysがinf-ruby-setup-keybindingsにリネームされていたので注意。
後半部分はrbenvでインストールしたrubyに対応させるためのPATHの設定。
(autoload 'run-ruby "inf-ruby" "Run an inferior Ruby process") (autoload 'inf-ruby-setup-keybindings "inf-ruby" "Set local key defs for inf-ruby in ruby-mode") (add-hook 'ruby-mode-hook '(lambda () (inf-ruby-setup-keybindings))) (setenv "PATH" (concat (getenv "HOME") "/.rbenv/shims:" (getenv "HOME") "/.rbenv/bin:" (getenv "PATH"))) (setq exec-path (cons (concat (getenv "HOME") "/.rbenv/shims") (cons (concat (getenv "HOME") "/.rbenv/bin") exec-path)))
ruby-end.el
endを自動で保管してくれる。特に設定なし。
rsense
オムニ補完をできるようにする。auto-completeの情報源として使う。
まずはrsenseの起動に必要なJREをインストール。
$ sudo apt-get install openjdk-7-jre
デフォルトのrecipeだとうまくいかなかったので、自分でrecipeを書いてインストール。
recipe
(:name rsense :description "RSense client for Emacs" :website "http://cx4a.org/software/rsense/index.html" :type http-tar :options ("xf") :url "http://cx4a.org/pub/rsense/rsense-0.3.tar.bz2" :load-path ("etc") :build `(("ruby etc/config.rb > ~/.rsense")) :post-init (setq rsense-home (expand-file-name ".")) :features "rsense")
設定
(add-hook 'ruby-mode-hook '(lambda () (add-to-list 'ac-sources 'ac-source-rsense)))
ユーザーマニュアルに載っている設定が古いのか、ac-source-rsense-constantはdeprecatedであり、ac-source-rsense-methodはac-source-rsenseのエイリアスだった。なので、情報源に追加するのはac-source-rsenseだけで大丈夫だと思う。