Next: , Previous: , Up: Top   [Index]


12 Compilation

Haskell mode comes equipped with a specialized Compilation mode tailored to GHC’s compiler messages with optional support for Cabal projects. See (emacs)Compilation Mode, for more information about the basic commands provided by the Compilation mode which are available in the Haskell compilation sub-mode as well. The additional features provided compared to Emacs’ basic Compilation mode are:

In order to use it, invoke the haskell-compile command instead of compile as you would for the ordinary Compilation mode. It’s recommended to bind haskell-compile to a convenient key binding. For instance, you can add the following to your Emacs initialization to bind haskell-compile to C-c C-c.

(eval-after-load "haskell-mode"
    '(define-key haskell-mode-map (kbd "C-c C-c") 'haskell-compile))

(eval-after-load "haskell-cabal"
    '(define-key haskell-cabal-mode-map (kbd "C-c C-c") 'haskell-compile))

The following description assumes that haskell-compile has been bound to C-c C-c.

When invoked, haskell-compile tries to guess how to compile the Haskell program your currently visited buffer belongs to, by searching for a .cabal file in the current of enclosing parent folders. If a .cabal file was found, the command defined in the haskell-compile-cabal-build-command option is used. Note that to compile a stack based project you will need to set this variable to stack build. As usual you can do it using M-x customize-variable or with:

(setq haskell-compile-cabal-build-command "stack build")

Moreover, when requesting to compile a .cabal-file is detected and a negative prefix argument (e.g. C-- C-c C-c) was given, the alternative haskell-compile-cabal-build-command-alt is invoked. By default, haskell-compile-cabal-build-command-alt contains a ‘cabal clean -s’ command in order to force a full rebuild.

Otherwise if no .cabal could be found, a single-module compilation is assumed and haskell-compile-command is used (if the currently visited buffer contains Haskell source code).

You can also inspect and modify the compile command to be invoked temporarily by invoking haskell-compile with a prefix argument (e.g. C-u C-c C-c). If later-on you want to recompile using the same customized compile command, invoke recompile (bound to g) inside the ‘*haskell-compilation*’ buffer.

12.1 Keybindings

Key bindingFunction
TABcompilation-next-error
RETcompile-goto-error
C-ocompilation-display-error
SPCscroll-up-command
-negative-argument
0 .. 9digit-argument
<beginning-of-buffer
>end-of-buffer
?describe-mode
grecompile
hdescribe-mode
qquit-window
DELscroll-down-command
S-SPCscroll-down-command
<backtab>compilation-previous-error
<follow-link>mouse-face
<mouse-2>compile-goto-error
<remap>Prefix Command
M-ncompilation-next-error
M-pcompilation-previous-error
M-{compilation-previous-file
M-}compilation-next-file
C-c C-ccompile-goto-error
C-c C-fnext-error-follow-minor-mode
C-c C-kkill-compilation

Next: , Previous: , Up: Top   [Index]