This is part of the Emacs Starter Kit.
Support for editing HaskellYou can skip these steps if you’ve already setup ghc and cabal
sudo apt-get update
sudo apt-get install ghc cabal-install
cabal update
brew update
brew install ghc cabal-install
cabal update
#+start_src sh cabal install cabal-install
echo 'PATH=~/.cabal/bin:$PATH'|tee -a ~/.profile
source ~/.profile
which cabal
The last line should show you that you are now using the local and latest version of cabal located in your ~/.cabal/bin directory.
Haskell modes usually have two components to them. One side is haskell and the other side is installed and configured in Emacs
We will want to install some basic haskell packages in our ~/.cabal & ~/.ghc user directories. This makes them available along side cabal for doing development on your projects.
Running those commands in the shell might take some time - emacs appears to be frozen; trust me, it’s not
cabal install happy alex ;# needed but not listed as dependency
Paste the following into your terminal:
pretty lambdas in Haskell code
(defun pretty-lambdas-haskell ()
(font-lock-add-keywords
nil `((,(concat "(?\\(" (regexp-quote "\\") "\\)")
(0 (progn (compose-region (match-beginning 1) (match-end 1)
,(make-char 'greek-iso8859-7 107))
nil))))))
(starter-kit-install-if-needed 'haskell-mode)
(add-hook 'haskell-mode-hook 'run-starter-kit-coding-hook)
(when (window-system)
(add-hook 'haskell-mode-hook 'pretty-lambdas-haskell))
(add-hook 'haskell-mode-hook 'interactive-haskell-mode)
;; Ignore compiled Haskell files in filename completions
(add-to-list 'completion-ignored-extensions ".hi")
A simple Haskell code prettifier.
This tool tries to help where necessary without getting in the way.
Features
- Aligns and sorts import statements
- Groups and wraps {-# LANGUAGE #-} pragmas, can remove (some) redundant pragmas
- Removes trailing whitespace
- Replaces tabs by four spaces (turned off by default)
- Replaces some ASCII sequences by their Unicode equivalents (turned off by default)
cabal install stylish-haskell
To call it for every save, make sure you have C-x C-s rebound to haskell-mode-save-buffer.
(defadvice haskell-mode-stylish-buffer (around skip-if-flycheck-errors activate)
(unless (flycheck-has-current-errors-p 'error)
ad-do-it))
(setq haskell-stylish-on-save t)
The ghc-mod command is a backend command to enrich Haskell programming on editors including Emacs, Vim, and Sublime.
cabal install ghc-mod
(starter-kit-install-if-needed 'ghc)
This minor mode provides structured editing operations based on the syntax of Haskell. In short-hand it’s called SHM and throughout the codebase, too. It acts a bit like, and is heavily inspired by, paredit-mode for Emacs.
cabal install structured-haskell
(starter-kit-install-if-needed 'shm)
(add-hook 'haskell-mode-hook 'structured-haskell-mode)
;; The following are apparently pretty good for solarized-light.
;;(set-face-background 'shm-current-face "#eee8d5")
;;(set-face-background 'shm-quarantine-face "lemonchiffon")
(starter-kit-install-if-needed 'flycheck)
(add-hook 'flycheck-mode-hook #'flycheck-haskell-setup)
(global-flycheck-mode)
(starter-kit-install-if-needed 'flyspell)
(add-hook 'haskell-mode-hook 'flyspell-prog-mode)