emacsでghc-modを使う

2015-07-10

Haskellモードの設定

;;;; .emacs
;; Haskell.
(add-to-list 'load-path "~/.emacs.d/elisp/haskell-mode-2.8.0")
(autoload 'haskell-mode "haskell-mode" nil t)
(autoload 'haskell-cabal "haskell-cabal" nil t)

(add-to-list 'auto-mode-alist '("\\.hs$" . haskell-mode))
(add-to-list 'auto-mode-alist '("\\.lhs$" . literate-haskell-mode))
(add-to-list 'auto-mode-alist '("\\.cabal\\'" . haskell-cabal-mode))

(add-to-list 'interpreter-mode-alist '("runghc" . haskell-mode)) ;#!/usr/bin/env runghc 用
(add-to-list 'interpreter-mode-alist '("runhaskell" . haskell-mode)) ;#!/usr/bin/env runhaskell 用

ghc-modのインストール

$ cabal install ghc-mod

ghc-mod用の.emacs設定

;;;; .emacs
(add-to-list 'exec-path "~/.cabal/bin") ; これをしてないと*Message*に"ghc-mod not found"と出て動かない
(add-to-list 'load-path "~/.emacs.d/elisp/ghc-mod")

(autoload 'ghc-init "ghc" nil t)
(add-hook 'haskell-mode-hook
(lambda ()
(ghc-init)
(flymake-mode)))

;(setq haskell-program-name "/usr/bin/ghci")
;(add-hook 'haskell-mode-hook 'inf-haskell-mode) ;; enable
(defadvice inferior-haskell-load-file (after change-focus-after-load)
"Change focus to GHCi window after C-c C-l command"
(other-window 1))
(ad-activate 'inferior-haskell-load-file)

ghc-modの使い方

  • Usage of Emacs front-end
  • M-tで型注釈を挿入してくれるはずが、ミニバッファにArgs out of range: 0, 1などと出てしまう、謎