In Haskell, code indentation has semantic meaning as it defines the block structure. Haskell also supports braces and semicolons notation for conveying the block structure. However, most Haskell programs written by humans use indentation for block structuring.
Haskell Mode ships with two indentation modes:
This is a semi-intelligent indentation mode doing a decent job at recognizing Haskell syntactical constructs. It is based on a recursive descent Haskell parser. TAB selects the next potential indentation position, S-TAB selects the previous one. If a block is selected you can use TAB to indent the block more and S-TAB to indent the block less.
electric-indent-mode is enabled or the variable
haskell-indentation-electric-flag is non-nil, the insertion of
some characters (by default , ; ) } ])
may trigger auto reindentation under appropriate conditions. See the
This is a semi-intelligent indentation mode doing a decent job at recognizing Haskell syntactical constructs. It is based on a decision table. Sadly it is no longer developed and does not recognize newer Haskell syntax. TAB cycles through all available indentation positions.
haskell-indent-mode, add this to your ~/.emacs
(add-hook 'haskell-mode-hook 'turn-on-haskell-indent)
turn-on-haskell-indent will disable
For general information about indentation support in GNU Emacs, see (emacs)Indentation.
GNU Emacs provides so-called rectangle commands which operate on rectangular areas of text, which are particularly useful for languages with a layout rule such as Haskell. See (emacs)Rectangles, to learn more about rectangle commands.
Moreover, CUA mode (see (emacs)CUA Bindings) provides enhanced
rectangle support with visible rectangle highlighting. When CUA mode is
active, you can initiate a rectangle selection by C-RET and extend
it simply by movement commands. You don’t have to enable full CUA mode
to benefit from these enhanced rectangle commands; you can activate CUA
selection mode (without redefining C-x,C-c,C-v, and
C-z) by calling M-x cua-selection-mode (or adding
(cua-selection-mode nil) to your
There is a
indent-region function that supposedly could be used
to indent code region without changing its semantics. Sadly it does not
work that way because usual use case for
indent-regionto fix indentation for remaining lines.
Note that between 1 and 2 program is already semantically broken and knowing how to indent it preserving semantic from before step 1 would require time travel.
To stay on the safe side
indent-region-function is bound to a