Skip to content

Haskell Interactive Mode Setup

Boris edited this page Oct 25, 2015 · 8 revisions

The most straight-forward way to get setup with Interactive Mode is to bind the right keybindings and set some customizations. This page contains a good base setup.

To enable the minor mode which activates keybindings associated with interactive mode, use:

(require 'haskell-interactive-mode)
(require 'haskell-process)
(add-hook 'haskell-mode-hook 'interactive-haskell-mode)

Customizations

This enables some handy and benign features.

(custom-set-variables
  '(haskell-process-suggest-remove-import-lines t)
  '(haskell-process-auto-import-loaded-modules t)
  '(haskell-process-log t))

Bindings

Haskell-mode bindings

This gives the basic ways to start a session. In a Haskell buffer:

  • Run C-` to make a REPL open, this will create a session, start GHCi, and open the REPL.
  • Or: run C-c C-l to load the file. This will first try to start a session as the previous command does.
  • Or: run any command which requires a running session. It will always prompt to create one if there isn't one already for the current project.
(define-key haskell-mode-map (kbd "C-c C-l") 'haskell-process-load-or-reload)
(define-key haskell-mode-map (kbd "C-`") 'haskell-interactive-bring)
(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 C-c") 'haskell-process-cabal-build)
(define-key haskell-mode-map (kbd "C-c C-k") 'haskell-interactive-mode-clear)
(define-key haskell-mode-map (kbd "C-c c") 'haskell-process-cabal)
(define-key haskell-mode-map (kbd "SPC") 'haskell-mode-contextual-space)

Cabal-mode bindings

The below commands pretty much match the ones above, but are handy to have in cabal-mode, too:

(define-key haskell-cabal-mode-map (kbd "C-`") 'haskell-interactive-bring)
(define-key haskell-cabal-mode-map (kbd "C-c C-k") 'haskell-interactive-mode-clear)
(define-key haskell-cabal-mode-map (kbd "C-c C-c") 'haskell-process-cabal-build)
(define-key haskell-cabal-mode-map (kbd "C-c c") 'haskell-process-cabal)

GHCi process type

By default haskell-process-type is set to auto. It is smart enough to pick the right type based on your project structure and installed tools, but in case something goes funky or you want to explicitly set the process type and ignore the inferred type, you can customize this setting by running M-x customize-variable RET haskell-process-type RET, or by setting the code:

(custom-set-variables
  '(haskell-process-type 'cabal-repl))

Here is a list of available process types:

  • ghci
  • cabal-repl
  • cabal-dev
  • cabal-ghci
  • stack-ghci

Please, check the documentation for haskell-process-type to see how the real type is guessed, when it's set to auto.

Troubleshooting

Launching your GHCi process can fail when you're first getting setup, depending on the type you choose. If it does fail to launch, switch to the buffer *haskell-process-log* and see what's up. The buffer contains a log of incoming/outgoing messages to the GHCi process.

See also troubleshooting the REPL.

See also architecture.

All done!

You're all done and ready to go! But wait!

There're a bunch more features to this mode and for which you might want to add configurations and keybindings. So it is suggested that once you've setup and played with the above, you continue reading what other features are available in the Haskell Interactive Mode documentation.