Shammer's Philosophy

My private adversaria

OCaml環境構築

まずは、OCamlをインストール。

$ sudo port install ocaml

しかし、ここでエラー。ログを確認すると、HTTP 407 Error となっている。407 って何だ?

Emacs から使いたいので、プラグインを探す。いろいろ調べたが、これが一番良さそう。

 TuaregMode
 http://www.emacswiki.org/emacs/TuaregMode

これを入手し、適当なディレクトリ(/opt/local/share/tuareg-2.0.4)に解凍。
2011/09/09時点では最新版は2.0.4だった。
そして、init.elに以下のように追加。

(setq auto-mode-alist 
    (append '(
        ("\\.C$"    . c++-mode)
        ("\\.cc$"   . c++-mode)
        ("\\.cpp$"  . c++-mode)
        ("\\.hh$"   . c++-mode)
        ("\\.c$"    . c-mode)
        ("\\.h$"    . c-mode)
        ("\\.m$"    . objc-mode)
        ("\\.java$" . java-mode)
        ("\\.pl$"   . cperl-mode)
        ("\\.perl$" . cperl-mode)
        ("\\.tex$"  . yatex-mode)
        ("\\.sty$"  . yatex-mode)
        ("\\.cls$"  . yatex-mode)
        ("\\.clo$"  . yatex-mode)
        ("\\.dtx$"  . yatex-mode)
        ("\\.fdd$"  . yatex-mode)
        ("\\.ins$"  . yatex-mode)
        ("\\.s?html?$" . html-helper-mode)
        ("\\.php$" . html-helper-mode)
        ("\\.jsp$" . html-helper-mode)
        ("\\.css$"  . css-mode)
        ("\\.js$"   . java-mode)
        ("\\.el$"   . emacs-lisp-mode)
	("\\.lisp$" . lisp-mode)
	("\\.ml[ilyp]?$" . tuareg-mode) ;<-この行を追加
    ) auto-mode-alist)
)

;; OCaml Configurations
; see http://www.emacswiki.org/emacs/TuaregMode
(add-to-list 'load-path "/opt/local/share/tuareg-2.0.4")
(autoload 'tuareg-mode "tuareg" "Major mode for editing Caml code." t)
(autoload 'tuareg-run-caml "tuareg" "startup a Caml toplevel" t)
(autoload 'camldebug "camldebug" "Run the Caml debugger." t)

確認したサイトには、tuareg-run-camlのautoload行がないが、これがないとM-x tuareg-run-camlを使用できない(Emacs内でOCamlインタプリタを起動できない)。

ここまで設定してEmacsを起動して

M-x tuareg-run-caml

と実行すると、

Caml toplevel to run:ocaml

と出るはず。ここでEnterキーを押せば、ocaml が使えるようになるんだろうけれど、
冒頭のエラーで OCaml をインストールできていないからエラーで終了する。
日を改めて、OCamlのインストールは試してみよう。