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


7 Indentation

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:

For general information about indentation support in GNU Emacs, see (emacs)Indentation.

7.1 Rectangle Commands

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 haskell-mode-hook).

7.2 Region indent is a no-op

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-region is:

  1. Alter first line of code in region.
  2. Call indent-region to 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 no-op in haskell-mode.


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