Sane haskell-mode indentation setup?

Curious if anybody has already figured out satisfying (auto)indentation settings for coding in Emacs?

In accordance to common standard - basic indent of 4 spaces, 2 spaces indent for where,2 spaces after where and let/in etc. Alternatively by Haskell Style Guide .

I have in that sense configured external formatter fourmolu, which exactly does the job, but for the sake of me I can’t get the same within haskell-mode. Only partial results, both in default haskell-indentation-mode and haskell-indent-mode.

Can you share your setup or it is just not possible in current state of affairs. unless resort to own hacking in elisp?

2 Likes

I’ve found Treesitter-based indentation to be much saner than hand-rolled parsers in the `haskell-mode`, which I attempted to extend and fix for the cases I cared about. Not being satisfied with available treesitter indentations I’ve made one for myself (dotemacs/src/haskell/haskell-ts-indent.el at master · sergv/dotemacs · GitHub which plugs into dotemacs/src/haskell/haskell-ts-mode.el at master · sergv/dotemacs · GitHub). Not sure how much effort you’d like to spend on setting it all up though.

However, haskell-mode indentations were pretty reasonable in last 10 years and still hold up well w.r.t. supported Haskell syntax features. Perhaps you’ll get better bung for the buck by identifying specific instances of indentation you don’t like and finding parameters that make them right.

4 Likes

idk i’ve used stock for years

haskell-mode indent isn’t meant to automate your whitespace. it’s meant to facilitate it. you still have to be a smart human being with taste :slight_smile:

manual indentation isn’t a sin

1 Like

I use haskell-indentation-mode, and I set haskell-indentation-left-offset to 4. (Note: IIRC that “4” means e.g. 4 under “do”; some other defaults already ensure 2 for “where”, 2 more under “where”.)

It is already almost perfect and flexible. There are just a few corner cases I need to manually override.

Cool, that could probably go on melpa :slight_smile: (or even better get it merged into the official GitHub - haskell/haskell-mode: Emacs mode for Haskell )