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


19 Using GHCi REPL within Emacs

To start the REPL you can run one of the following:

This repl works with Comint. So you will feel at home if you are already using M-x Shell or M-x ielm.

Inf-Haskell is a Major mode for running GHCi, with comint.

Important key bindings in Inf-haskell:

RET

invokes comint-send-input. Sends the input to the GHCi process, evaluates the line and returns the output.

C-d or <delete>

deletes the forward character

<C-up> or M-p

invokes comint-previous-input. Cycle backwards through input history, saving input.

<C-down> or M-n

invokes comint-next-input. Cycle forwards through input history.

C-c C-c

invokes comint-interrupt-subjob. Sends KeyboardInterrupt signal.

C-c C-\

invokes comint-quit-subjob. Sends KeyboardInterrupt signal.

C-c C-z

invokes comint-stop-subjob. Kills the GHCi process.

C-c M-r

invokes comint-previous-matching-input-from-input. If you are familiar with C-r in bash. This is the same as that. Searches backwards through input history for match for current input.

C-c M-s

invokes comint-next-matching-input-from-input. Searches forwards through input history for match for current input.

C-c C-l

invokes comint-dynamic-list-input-ring. Displays a list of recent inputs entered into the current buffer.

C-c M-o

invokes comint-clear-buffer. Clears the buffer (Only with Emacs 25.X and above)

C-c C-n

invokes comint-next-prompt. Goes to the start of the previous REPL prompt.

C-c C-p

invokes comint-previous-prompt. Goes to the start of the next REPL prompt.

C-c C-o

invokes comint-delete-output. Clears the output of the most recently evaluated expression.

C-c C-e

invokes comint-show-maximum-output. Moves the point to the end of the buffer.

C-c C-u

invokes comint-kill-input. Kills backward, the line at point. (Use this when you have typed in an expression into the prompt but you dont want to evaluate it.)

C-c C-w

invokes backward-kill-word. Kills backward, the word at point

C-c C-s

invokes comint-write-output. Write output from interpreter since last input to FILENAME. Any prompt at the end of the output is not written.

19.1 Relevant defcustoms:

Interpreter (defcustom)Default ValuePossible Values
haskell-process-type'auto'stack-ghci, 'cabal-repl, 'ghci, 'auto
inferior-haskell-hooknil-
haskell-process-path-ghcighci-
haskell-process-args-ghci-ferror-spans-
haskell-process-path-cabalcabal-
haskell-process-args-cabal-repl--ghc-option=-ferror-spans-
haskell-process-path-stackstack-
haskell-process-args-stack-ghci--ghci-options=-ferror-spans --no-build --no-load-

19.2 More on haskell-process-type

The Haskell interpreter used by Inf-Haskell is auto-detected by default, but is customizable with defcustom haskell-process-type. The values recognized by it are (default is ’auto):

if the haskell-process-type is 'auto, the directories are searched for cabal.sandbox.config or stack.yaml or *.cabal file. If the file is present, then appropriate process is started.

When cabal.sandbox.config is found haskell-process-type is 'cabal-repl. Similarly, when stack.yaml is found haskell-process-type is 'stack-ghci. Similarly, when xyz.cabal is found haskell-process-type is 'cabal-repl. When nothing is found haskell-process-type is 'ghci. When more than one file such as cabal.sandbox.config and stack.yaml are found the following preference is followed.

cabal.sandbox.config > stack.yaml > *.cabal


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