Skip to content

Instantly share code, notes, and snippets.

@ShigekiKarita
Created October 10, 2014 07:03
Show Gist options
  • Save ShigekiKarita/041279c6deee3713aede to your computer and use it in GitHub Desktop.
Save ShigekiKarita/041279c6deee3713aede to your computer and use it in GitHub Desktop.
setup haskell-mode
;; =======
;; Haskell
;; =======
(require 'auto-complete)
(require 'haskell-mode)
(require 'haskell-cabal)
(autoload 'ghc-init "ghc" nil t)
(add-hook 'haskell-mode-hook (lambda () (ghc-init)))
(add-hook 'haskell-mode-hook 'interactive-haskell-mode)
(eval-after-load "haskell-mode"
'(progn
(setq haskell-stylish-on-save t)
(setq haskell-process-args-cabal-repl '("--ghc-option=-ferror-spans"
"--with-ghc=ghci-ng"))
(define-key haskell-mode-map (kbd "C-,") 'haskell-move-nested-left)
(define-key haskell-mode-map (kbd "C-.") 'haskell-move-nested-right)
(define-key haskell-mode-map (kbd "C-c v c") 'haskell-cabal-visit-file)
(define-key haskell-mode-map (kbd "C-c C-c") 'haskell-compile)
(define-key haskell-mode-map (kbd "C-x C-d") nil)
(define-key haskell-mode-map (kbd "C-c C-z") 'haskell-interactive-switch)
(define-key haskell-mode-map (kbd "C-c C-l") 'haskell-process-load-file)
(define-key haskell-mode-map (kbd "C-c C-b") 'haskell-interactive-switch)
(define-key haskell-mode-map (kbd "C-c C-t") 'haskell-process-do-type)
(define-key haskell-mode-map (kbd "C-c C-i") 'haskell-process-do-info)
(define-key haskell-mode-map (kbd "C-c M-.") nil)
(define-key haskell-mode-map (kbd "C-c C-d") nil)
(add-to-list 'interpreter-mode-alist '("runghc" . haskell-mode))
(add-to-list 'interpreter-mode-alist '("runhaskell" . haskell-mode))
(auto-complete-mode)
(ac-define-source ghc-mod
'((depends ghc)
(candidates . (ghc-select-completion-symbol))
(symbol . "s")
(cache)))
(defun my-ac-haskell-mode ()
(setq ac-sources '(ac-source-words-in-same-mode-buffers
ac-source-dictionary
ac-source-ghc-mod)))
(add-hook 'haskell-mode-hook 'my-ac-haskell-mode)
(defun my-haskell-ac-init ()
(when (member (file-name-extension buffer-file-name) '("hs" "lhs"))
(auto-complete-mode t)
(setq ac-sources '(ac-source-words-in-same-mode-buffers
ac-source-dictionary
ac-source-ghc-mod))))
(add-hook 'find-file-hook 'my-haskell-ac-init)))
(add-hook 'haskell-mode-hook 'turn-on-haskell-decl-scan)
(add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
(eval-after-load "which-func"
'(add-to-list 'which-func-modes 'haskell-mode))
(eval-after-load "haskell-cabal"
'(define-key haskell-cabal-mode-map (kbd "C-c C-c") 'haskell-compile))
(setq haskell-program-name "/usr/local/bin/ghci")
;; 拡張子
(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))
;; ghc-mod
(add-to-list 'exec-path (concat (getenv "HOME") "/.cabal/bin/"))
(add-to-list 'load-path "~/.cabal/share/x86_64-osx-ghc-7.6.3/ghc-mod-4.1.6")
(add-to-list 'ac-sources 'ac-source-ghc-mod)
(autoload 'ghc-init "ghc" nil t)
(add-hook 'haskell-mode-hook (lambda () (ghc-init)))
(add-hook 'haskell-mode-hook 'flycheck-mode)
(setq ghc-ghc-options '("-idir1" "-idir2"))
(defun haskell-other-window ()
"Run GHCi on other window"
(interactive)
(split-window-horizontally (/ (frame-width) 2))
(let ((buf-name (buffer-name (current-buffer))))
(haskell-mode)
(switch-to-buffer-other-window
(get-buffer-create "*GHCi*"))
(run-haskell haskell-program-name)
(switch-to-buffer-other-window
(get-buffer-create buf-name))))
(define-key global-map
"\C-cH" 'haskell-other-window)
;; M-x anything-ghc-browse-document() に対応するキーの割り当て
(add-hook 'haskell-mode-hook
(lambda()
(define-key haskell-mode-map (kbd "C-M-d") 'anything-ghc-browse-document)))
(defun anything-default-display-buffer (buf)
(if anything-samewindow
(switch-to-buffer buf)
(progn
(delete-other-windows)
(split-window (selected-window) nil t)
(pop-to-buffer buf))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment