Meadow に Ruby 開発環境を設定 ― 2009/12/04 20:04
「どんならんな」さんの「Emacs で Ruby 開発環境」(http://d.hatena.ne.jp/yuko1658/20071213/1197517201) を参考にしながら設定
色々と試行錯誤 (行き当たりばったり) したので、次に下記の通り行っても本当に上手くいくかどうかは不明
なお、以下の作業はすべて Meadow の shell-mode で行った
以上で、M-r で ri をロードしてから、M-c でコード補完できるようになる。たぶん、、、
上の様なメソッドの候補画面が表示されたら C-n, C-p で候補を選んでもいいし、メソッド名のつづきを入力する。Enter で決定
色々と試行錯誤 (行き当たりばったり) したので、次に下記の通り行っても本当に上手くいくかどうかは不明
なお、以下の作業はすべて Meadow の shell-mode で行った
-
下準備として wget をインストール (←これは cygwin の setup.exe で実行)
-
Ruby のソースコードを取得・展開し、ruby-1.9.1-p243.tar/misc ディレクトリ下の全ての *.el ファイルを Meadow インストールディレクトリ下にある site-lisp ディレクトリ下にコピー
$ wget http://core.ring.gr.jp/archives/lang/ruby/ruby-1.9.1-p243.tar.gz $ tar xzvf ruby-1.9.1-p243.tar.gz $ cp ruby-1.9.1-p243/misc/*.el c:/TOOLS/meadow/site-lisp/
-
emacs-rails を取得・展開し、emacs-rails ディレクトリ下の全ての *.el ファイルをMeadow インストールディレクトリ下にある site-lisp ディレクトリ下にコピー
$ wget http://rubyforge.org/frs/download.php/20976/emacs-rails-0.5.99.5.tar.gz $ tar xzvf emacs-rails-0.5.99.5.tar.gz $ cp emacs-rails/*.el c:/TOOLS/meadow/site-lisp/
-
ruby-block.el を取得し、Meadow インストールディレクトリ下にある site-lisp ディレクトリ下にコピー
$ wget http://www.emacswiki.org/cgi-bin/wiki/ruby-block.el $ cp ruby-block.el c:/TOOLS/meadow/site-lisp/
-
snippet.el を取得し、Meadow インストールディレクトリ下にある site-lisp ディレクトリ下にコピー
$ wget http://www.kazmier.com/computer/snippet.el $ cp snippet.el c:/TOOLS/meadow/site-lisp/
-
find-recursive.el を取得し、Meadow インストールディレクトリ下にある site-lisp ディレクトリ下にコピー
$ wget http://www.webweavertech.com/ovidiu/emacs/find-recursive.txt $ cp find-recursive.txt c:/TOOLS/meadow/site-lisp/find-recursive.el
-
ここで、.emacs を設定してちょっと動かしてみる .emnacs に追加する設定は、次の通り (つか、「Emacs で Ruby 開発環境」のまんま)
;; ruby-mode (autoload 'ruby-mode "ruby-mode" "Mode for editing ruby source files" t) (setq auto-mode-alist (append '(("\\.rb$" . ruby-mode)) auto-mode-alist)) (setq interpreter-mode-alist (append '(("ruby" . ruby-mode)) interpreter-mode-alist)) (autoload 'run-ruby "inf-ruby" "Run an inferior Ruby process") (autoload 'inf-ruby-keys "inf-ruby" "Set local key defs for inf-ruby in ruby-mode") (add-hook 'ruby-mode-hook '(lambda () (inf-ruby-keys))) ;; ruby-electric (require 'ruby-electric) (add-hook 'ruby-mode-hook '(lambda () (ruby-electric-mode t))) ;; rubydb (autoload 'rubydb "rubydb3x" "run rubydb on program file in buffer *gud-file*. the directory containing file becomes the initial working directory and source-file directory for your debugger." t) ;; rails (defun try-complete-abbrev (old) (if (expand-abbrev) t nil)) (setq hippie-expand-try-functions-list '(try-complete-abbrev try-complete-file-name try-expand-dabbrev)) (setq rails-use-mongrel t) (require 'cl) (require 'rails) ;; ruby-block (require 'ruby-block) (ruby-block-mode t) ;; ミニバッファに表示し, かつ, オーバレイする. (setq ruby-block-highlight-toggle t)
おおむね良好、が、ここで if とか { とか入力すると対応する end や } が自動的に挿入され喜ぶ、が CentOS の Emacs に設定したときにはこんな動きはならなかったけどなー、と思い調べてみると、.rb ファイルを読み込むと次のようなエラーが発生していたFile mode specification error: (void-function run-mode-hooks)
困ったときの google 頼みで "ruby-mode File mode specification error: (void-function run-mode-hooks)" で検索すると、次のようなページに行き当たった「[ruby-dev:34853] emacs21でruby-mode.el」(http://old.nabble.com/-ruby-dev:34853--emacs21%E3%81%A7ruby-mode.el-td17466768.html)
ピンポンみたいです。このページの説明にしたがい ruby-mode.el の259 (run-mode-hooks 'ruby-mode-hook))
を259 (if (fboundp 'run-mode-hooks) 260 (run-mode-hooks 'ruby-mode-hook) 261 (run-hooks 'ruby-mode-hook)))
に変えると動き出した。Meadow の方は Emacs のバージョンが新しいので、こんな問題は発生しないみたい。 -
Ruby でコード補完
以下の設定は、「nao研究室」さんの「[Emacs]Rubyでコード補完」(http://blogs.dion.ne.jp/moe_moe/archives/7481321.html) を開始点にして google 先生に教えを請いながら行った。
また、スクリプトをいろいろと修正しているが、これは僕の環境が Ruby 1.9 であるためである。Ruby が 1.8 ならそのまま動くと思う。
※下準備- ruby は C:\Program Files 等のようなディレクトリ名に空白を含んだディレクトリではなく、c:\ruby のようなシンプルなディレクトリ下にインストールした方がよさげ
- gem が openssl のライブラリを使うみたいなので、http://www.deanlee.cn/programming/openssl-for-windows/ から openssl-0.9.8e_WIN32.zip をダウンロードし、解凍してできたファイルの中から ssleay32.dll と libeay32.dll を ruby の bin ディレクトリにコピー
-
readline.dll つーのが、いるみたいなので http://jarp.does.notwork.org/win32/ から readline-4.3-2-mswin32.zip をダウンロード
ついでに gdbm-1.8.3-1-mswin32.zip, pdcurses-2.60-1-mswin32.zip, zlib-1.1.4-1-mswin32.zip もダウンロード
ダウンロードできたから、解凍してそれぞれの bin ディレクトリ下の dll ファイルを
ruby の bin ディレクトリ下にコピー
-
http://rubyforge.org/projects/ri-emacs/ から ri-emacs をダウンロード・展開し、できたファイルをすべて Meadow インストールディレクトリ下にある site-lisp ディレクトリ下にコピー
$ wget http://rubyforge.org/frs/download.php/16392/ri-emacs-0.2.3.tar.gz $ tar xzvf ri-emacs-0.2.3.tar.gz $ cp ri-ruby.el c:/TOOLS/meadow/site-lisp/ $ cp ri-emacs.rb c:/TOOLS/meadow/site-lisp/
-
rcodetools, fastri のインストール
> gem install rcodetools > gem install fastri
rcodetoolsのインストールが終わったなら、rubyインストールディレクトリ下のlib\ruby\gems\1.9.1\gems\rcodetools-0.8.5.0\rcodetools.el
を Meadow インストールディレクトリ下にある site-lisp ディレクトリ下にコピー -
下記の 2 つのファイルをダウンロードして Meadow インストールディレクトリ下にある site-lisp ディレクトリ下にコピー
http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
http://www.emacswiki.org/cgi-bin/wiki/download/anything-rcodetools.el
$ cd c:/tools/meadow/site-lisp $ wget http://www.emacswiki.org/cgi-bin/wiki/download/anything.el $ wget http://www.emacswiki.org/cgi-bin/wiki/download/anything-rcodetools.el
-
meadow\site-lisp\ri-emacs.rb に http://d.hatena.ne.jp/derui/20090626/1246154582 のパッチを当てる
patch コマンドで上手く当たらないので、マニュアルで当てた
それから、このパッチには以下の修正が含まれていないので、自分で修正すること
require 'rdoc/ri/ri_paths' require 'rdoc/ri/ri_cache' require 'rdoc/ri/ri_util' require 'rdoc/ri/ri_reader' require 'rdoc/ri/ri_formatter' require 'rdoc/ri/ri_display'
↓require 'rdoc/ri/paths' require 'rdoc/ri/cache' require 'rdoc/ri/util' require 'rdoc/ri/reader' require 'rdoc/ri/formatter' require 'rdoc/ri/display'
-
fastri に http://writequit.org/blog/?p=307 のパッチを当てる
こんなパッチらしい- ::RI ==> RDoc::RI
- RI::RiXxxx ==> RRoc::RI::
- fastri/ri_index.rb の 237 行付近
- RDoc::RI::Path.new(path) ==> RDoc::RI::Path.new([path])
- require 'rdoc/ri/ri_xxxxx' ==> require 'rdoc/ri/xxxxx'
- RI::RiXxxxx ==> RI::Xxxxx
$ wget http://writequit.org/misc/files/fastri-0.3.1-ruby1.9.1.v3.patch $ cd cd c:/ruby-1.9/lib/ruby/gems/1.9.1/gems/fastri-0.3.1.1/ $ patch -p1 <d:/home/work/fastri-0.3.1-ruby1.9.1.v3.patch
-
.emacs に下記を追加
(setq ri-ruby-script "c:/TOOLS/meadow/site-lisp/ri-emacs.rb") (autoload 'ri "c:/TOOLS/meadow/site-lisp/ri-ruby.el" nil t) (add-hook 'ruby-mode-hook (lambda () (local-set-key "\M-r" 'ri) (local-set-key "\M-c" 'rct-complete-symbol) ;; (local-set-key "\M-c" 'ri-ruby-complete-symbol) ;(local-set-key "\M-g" 'ri-ruby-show-args) )) (require 'anything-rcodetools)
以上で、M-r で ri をロードしてから、M-c でコード補完できるようになる。たぶん、、、

上の様なメソッドの候補画面が表示されたら C-n, C-p で候補を選んでもいいし、メソッド名のつづきを入力する。Enter で決定
Meadow 設定のその後 ― 2009/12/04 17:39
■ shell mode で bash を使っている分には問題ないのだが、Windows の cmd を使うと、シ
ェルが入力をエコーするみたいで鬱陶しいので消す。.emacs に下記を追加
ェルが入力をエコーするみたいで鬱陶しいので消す。.emacs に下記を追加
(add-hook 'comint-mode-hook (lambda () (setq comint-process-echoes t)))
↓
■ auto-complete-ruby.el というのを発見
このページ (http://www.cx4a.org/blog/2009/01/autocomplete-ruby.html) の説明にしたがい、auto-complete.el, auto-complete-ruby.el 導入し、.emacs に下記の設定を追加
(require 'auto-complete-ruby)
(add-hook 'ruby-mode-hook
(lambda ()
(setq ac-omni-completion-sources '(("\\.\\=" ac-source-rcodetools)))))
すると、Ruby のコード補完が、プルダウンされる。
C-n/<↓> : 次の候補を選択する。
C-p/<↑> : 前の候補を選択する。
C-m/RET : 補完を実行して終了する。 が、僕の環境では RET が効かない、、、
スゴイ!!
■ タイトルバーにファイル名表示
(setq frame-title-format "%b")
■ ツールバーは使わないので表示しない
(tool-bar-mode 0)
Meadow セットアップ ― 2009/12/03 12:23
Ruby + Rails のコーディング用に Meadow をセットアップしたのでその記録
なお、以下の設定は自分用なので、他の人には通用しないかもしれない、、、
なお、以下の設定は自分用なので、他の人には通用しないかもしれない、、、
■ インストール~初期設定 (参考サイト -> http://www.bookshelf.jp/soft/meadow_9.html)
(1) http://www.meadowy.org/meadow/dists/3.00/ から setup-ja.exe をダウンロード
(2) ダウンロードした setup-ja-exe を実行して、普通にインストール -> C:\TOOLS\meadow
ディレクトリ下にインストールした
Meadow のインストールと同時に ImageMagick というものがインストールされるが、どうも
システム環境変数の Path を上書きしてしまうみたいで、元々の Path の設定が消えてし
まった (net use とかのコマンドラインのツールが使えなかったので気づいた) 。何が設定
されていたのか、わからないのでとりあえず次の %SystemRoot% の分だけ追加しておい
た。
Path=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;c:\tools\meadow\imagemagick-6.2.8-q16
(3) home ディレクトリと tmp ディレクトリの作成
home ディレクトリ -> d:\home
tmp ディレクトリ -> d:\home\tmp
(4) 環境変数の設定
LANG=ja_JP.SJIS
TZ=JST-9
TMP=d:/home/tmp
HOME=d:/home
PATH=%PATH%;c:\tools\meadow\bin
CYGWIN="binmode nontsec tty"
(5) .emacs の作成
Meadow インストールディレクトリ (c:\tools\meadow) にある dot.emacs.ja をそのまま使
用した
copy c:\tools\meadow\dot.emacs.ja d:\home\.emacs
(6) マシンを再起動して Meadow の動作確認
■ TicagoFix フォントが使いたい
「Meadowうそっこちゅーとりある」さん (http://www.remus.dti.ne.jp/~m-mikiya/emacs/meadow.html) の「■なんかデフォルトのフォントでかいんだけど」で書いてある設定 (これは、Meadow とか Meadow2 とかの記述方法で、今回インストールした Meadow3 には通用しない) と、「ぬぞうメモ」さんの「Meadowのフォントを変える」(http://milky.way-nifty.com/nuzou/2004/02/meadow.html) で書いてある設定を合成したものを .emacs に追加
;;; Ticago フォント設定
(w32-add-font
"ticago-fontset"
'((spec
((:char-spec ascii :height any)
strict
(w32-logfont "TicagoFix" 0 -10 400 0 nil nil nil 128 1 1 1))
((:char-spec ascii :height any :weight bold)
strict
(w32-logfont "TicagoFix" 0 -10 700 0 nil nil nil 128 1 1 1)
((spacing . -1)))
((:char-spec ascii :height any :slant italic)
strict
(w32-logfont "TicagoFix" 0 -10 400 0 t nil nil 128 1 1 1))
((:char-spec ascii :height any :weight bold :slant italic)
strict
(w32-logfont "TicagoFix" 0 -10 700 0 t nil nil 128 1 1 1)
((spacing . -1)))
((:char-spec katakana-jisx0201 :height any)
strict
(w32-logfont "TicagoFix" 0 -10 400 0 nil nil nil 128 1 1 1))
((:char-spec katakana-jisx0201 :height any :weight bold)
strict
(w32-logfont "TicagoFix" 0 -10 700 0 nil nil nil 128 1 1 1)
((spacing . -1)))
((:char-spec katakana-jisx0201 :height any :slant italic)
strict
(w32-logfont "TicagoFix" 0 -10 400 0 t nil nil 128 1 1 1))
((:char-spec katakana-jisx0201 :height any :weight bold :slant italic)
strict
(w32-logfont "TicagoFix" 0 -10 700 0 t nil nil 128 1 1 1)
((spacing . -1)))
((:char-spec japanese-jisx0208 :height any)
strict
(w32-logfont "TicagoFix" 0 -10 400 0 nil nil nil 128 1 1 1))
((:char-spec japanese-jisx0208 :height any :weight bold)
strict
(w32-logfont "TicagoFix" 0 -10 700 0 nil nil nil 128 1 1 1)
((spacing . -1)))
((:char-spec japanese-jisx0208 :height any :slant italic)
strict
(w32-logfont "TicagoFix" 0 -10 400 0 t nil nil 128 1 1 1))
((:char-spec japanese-jisx0208 :height any :weight bold :slant italic)
strict
(w32-logfont "TicagoFix" 0 -10 700 0 t nil nil 128 1 1 1)
((spacing . -1))))))
(w32-add-font
"ticago-fontset"
'((spec
((:char-spec ascii :height any)
strict
(w32-logfont "TicagoFix" 0 -10 400 0 nil nil nil 128 1 1 1))
((:char-spec ascii :height any :weight bold)
strict
(w32-logfont "TicagoFix" 0 -10 700 0 nil nil nil 128 1 1 1)
((spacing . -1)))
((:char-spec ascii :height any :slant italic)
strict
(w32-logfont "TicagoFix" 0 -10 400 0 t nil nil 128 1 1 1))
((:char-spec ascii :height any :weight bold :slant italic)
strict
(w32-logfont "TicagoFix" 0 -10 700 0 t nil nil 128 1 1 1)
((spacing . -1)))
((:char-spec katakana-jisx0201 :height any)
strict
(w32-logfont "TicagoFix" 0 -10 400 0 nil nil nil 128 1 1 1))
((:char-spec katakana-jisx0201 :height any :weight bold)
strict
(w32-logfont "TicagoFix" 0 -10 700 0 nil nil nil 128 1 1 1)
((spacing . -1)))
((:char-spec katakana-jisx0201 :height any :slant italic)
strict
(w32-logfont "TicagoFix" 0 -10 400 0 t nil nil 128 1 1 1))
((:char-spec katakana-jisx0201 :height any :weight bold :slant italic)
strict
(w32-logfont "TicagoFix" 0 -10 700 0 t nil nil 128 1 1 1)
((spacing . -1)))
((:char-spec japanese-jisx0208 :height any)
strict
(w32-logfont "TicagoFix" 0 -10 400 0 nil nil nil 128 1 1 1))
((:char-spec japanese-jisx0208 :height any :weight bold)
strict
(w32-logfont "TicagoFix" 0 -10 700 0 nil nil nil 128 1 1 1)
((spacing . -1)))
((:char-spec japanese-jisx0208 :height any :slant italic)
strict
(w32-logfont "TicagoFix" 0 -10 400 0 t nil nil 128 1 1 1))
((:char-spec japanese-jisx0208 :height any :weight bold :slant italic)
strict
(w32-logfont "TicagoFix" 0 -10 700 0 t nil nil 128 1 1 1)
((spacing . -1))))))
;; Ticago をデフォルトで
(setq default-frame-alist
(append (list
'(width . 128)
'(height . 60)
'(font . "ticago-fontset"))
default-frame-alist))
(setq default-frame-alist
(append (list
'(width . 128)
'(height . 60)
'(font . "ticago-fontset"))
default-frame-alist))
・w32-logfont の "-10" を変えるとフォントのサイズが変わるみたい
・setq default-frame-alist の中の width と height がウインドウのサイズみたい
あとは、よくわからなぁ~い
■ shell モードで bash が使いたいので、cygwin をインストール
(1) http://www.cygwin.com/ から setup.exe をダウンロード
(2) ダウンロードした setup.exe を実行して、普通にインストール
特にオプションは指定しなかったが、Default Text File Type (つまり改行コード) は Unix
形式の LF を選択した
(3) Path の追加 -> PATH=%PATH%;C:\TOOLS\cygwin\bin
(4) 再起動
(5) とりあえず bash の動作確認
(a) コマンドラインプロンプトから bash と入力 -> bash が起動
(b) ls -l を実行してみる -> 実行できるが日本語が文字化けする
(b) ls -l を実行してみる -> 実行できるが日本語が文字化けする
(6) ホームディレクトリ (d:\home) 下に .bash_profile と .bashrc を作成
「Cygwinのページ」さん (http://www.asahi-net.or.jp/~UQ7K-HRSM/cygwin.html) に記載
されているものをそのまま利用させていただきました。
「Cygwinのページ」さん (http://www.asahi-net.or.jp/~UQ7K-HRSM/cygwin.html) に記載
されているものをそのまま利用させていただきました。
--- .bash_profile ---
# ~/.bash_profile: executed by bash for login shells.
if [ -e /etc/bash.bashrc ] ; then
source /etc/bash.bashrc
fi
source /etc/bash.bashrc
fi
if [ -e ~/.bashrc ] ; then
source ~/.bashrc
fi
source ~/.bashrc
fi
--- .bashrc ---
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
export SHELL=/bin/bash
export HOME=/cygdrive/d/home
export TMPDIR=/cygdrive/d/home/tmp
export TZ=JST-09
export MAKE_MODE=unix
export LANG=ja_JP.SJIS
export HOME=/cygdrive/d/home
export TMPDIR=/cygdrive/d/home/tmp
export TZ=JST-09
export MAKE_MODE=unix
export LANG=ja_JP.SJIS
PATH=/usr/local/sbin:/usr/sbin:/sbin:.:~/bin
PATH=/usr/local/bin:/usr/X11R6/bin:/usr/bin:/bin:$PATH
PAGER=less
JLESSCHARSET=japanese-sjis
export PATH PAGER JLESSCHARSET
PATH=/usr/local/bin:/usr/X11R6/bin:/usr/bin:/bin:$PATH
PAGER=less
JLESSCHARSET=japanese-sjis
export PATH PAGER JLESSCHARSET
PS1="$HOSTNAME:\w$ "
if [ -n ${DISPLAY} ]; then
export DISPLAY=localhost:0.0
fi
export DISPLAY=localhost:0.0
fi
if [ ! -n "${TERM}" ]; then
TERM=cygwin
fi
TERM=cygwin
fi
alias ls='ls --show-control-chars'
最初、これらのファイルの改行コードを CR+LF で作ってしまい bash を起動すると
bash: /cygdrive/d/home/.bashrc: line 30: syntax error: unexpected end of file
のようなエラーが発生していた。改行コードの問題と気づくまでにずいぶんかかってしまった、、、
(7) 日本語ファイル名等が文字化けするので、「日本語メッセージの文字化けに対応する」
(http://www.sixnine.net/cygwin/cygwin-doc/japo.html) の説明にしたがって、Shift_JIS
のメッセージカタログを作成
なお、このページで公開されている moconv.sh の実行には nkf と msgfmt 等の cygwin
のデフォルトインストールではインストールされないツールが必要なので、別途インストー
ルしておく必要がある
a) nkf のインストール
「nkf Network Kanji Filter プロジェクト日本語トップページ」
(http://sourceforge.jp/projects/nkf/) には、ソースコードしかなく、make するのが面
倒、というか make する環境を作るのが面倒だっだので、cygwin 用のバイナリを探す
http://cygwin-je.sourceforge.jp/cygwin_je/release/nkf/ に nkf-2.0.4-1.tar.bz2 つーの
があるので、展開してできたファイルをフォルダ毎コピー
$ tar -jxvf nkf-2.0.4-1.tar.bz2
$ cp -R usr/* /usr
b) cygwin の setup.exe を実行して gettext-devel をインストール
c) moconv.sh を実行
■ Meadow の shell 設定 (参考サイト -> http://www.bookshelf.jp/soft/meadow_15.html)
基本的には、参考サイトの設定通りなのだが、日本語が文字化けしたりするので、coding-system の設定を色々といじった結果 (試行錯誤、行き当たりばったり) 下記のような設定になっている
;; Shell の設定
(setq explicit-shell-file-name "bash.exe")
(setq shell-file-name "sh.exe")
(setq shell-command-switch "-c")
(modify-coding-system-alist 'process ".*sh\\.exe" '(sjis-dos . euc-jp-unix))
;; argument-editing の設定
(require 'mw32script)
(mw32script-init)
(setq exec-suffix-list '(".exe" ".sh" ".pl"))
(setq shell-file-name-chars "~/A-Za-z0-9_^$!#%&{}@`'.:()-")
■ その他の設定
・Ctrl-z で undo
(global-set-key "\C-z" 'undo)
とりあえず、以上
最近のコメント