My Haskell Emacs configuration

Submitted by mrd on Fri, 11/02/2007 - 12:18pm.

I generally like some of the features that come with haskell-mode for Emacs. But I cannot reconcile my style with that of the "smart" indentation mode. I'm not too keen on the default indentation function of Emacs either, at least, not for Haskell code. I use the basic tab-to-tab-stop function but it needs a little tweaking to bring it down to reasonable levels of indentation.

Tabs should never be used.

(setq-default indent-tabs-mode nil)

I like align-regexp, a neat tool from Emacs 22.

(global-set-key (kbd "C-x a r") 'align-regexp)

Basic haskell-mode loading:

(add-to-list 'load-path "path/to/haskell-mode")
(load-library "haskell-site-file")
(add-to-list 'auto-mode-alist '("\\.hs\\'" . haskell-mode))

My indentation settings. I wrote my own "newline and indent" function which brings any code you split onto the newline back up to the same indentation level it was at previously.

(remove-hook 'haskell-mode-hook 'turn-on-haskell-indent)
;; Just use tab-stop indentation, 2-space tabs
(add-hook 'haskell-mode-hook
(lambda ()
(turn-on-haskell-doc-mode)
(turn-on-haskell-simple-indent)
(setq indent-line-function 'tab-to-tab-stop)
(setq tab-stop-list
(loop for i from 2 upto 120 by 2 collect i))
(local-set-key (kbd "RET") 'newline-and-indent-relative))
(defun newline-and-indent-relative ()
(interactive)
(newline)
(indent-to-column (save-excursion
(forward-line -1)
(back-to-indentation)
(current-column))))

And just in case you were wondering how to tweak syntax highlighting colors in your .emacs, here's what I do:

(set-face-bold-p 'font-lock-builtin-face nil)
(set-face-bold-p 'font-lock-comment-face nil)
(set-face-bold-p 'font-lock-function-name-face nil)
(set-face-bold-p 'font-lock-keyword-face nil)
(set-face-bold-p 'font-lock-variable-name-face nil)
(set-face-foreground 'font-lock-builtin-face "cyan")
(set-face-foreground 'font-lock-comment-face "pale green")
(set-face-foreground 'font-lock-function-name-face "green")
(set-face-foreground 'font-lock-variable-name-face "pale green")

I think it's fairly self-explanatory. You can play around with the values and find what you like. M-x list-colors-display is a handy tool to list out all the possible colors along with examples.