neovimhaskell/haskell-vim

Indentation on `where`

cloudhead opened this issue · 3 comments

I've noticed the haskell_indent_where variable only applies to:

where foo = 123
      |

But not to:

where
   |

In the second case, &shiftwidth is used. This is a problem for a common style of where clause indentation that looks like this:

foobar =
    map f xs
  where
    f = ...

In other words, shiftwidth=4 and the where clause is indented half way, to 2.

Any ideas how this could be solved? It seems like it would need two separate settings instead of one?

It seems like the current setting, which defaults at 6 is more of an alignment helper than an indentation setting, since it tries to help us align the lines after the where clause, and is only ever useful with a value of 6.

The problem is that is nearly impossible to figure out which context you are in VimL, at least not in an efficient way. One thing I'd like to have would be being able to discover if I am in a do block or a where clause. Vim indenters usually make things work by analyzing the current and previous line. I already do some backtracking when I discover that I'm in between brackets etc, this is possible because brackets and alike have a distinguished start and end, this is not true in the case of whitespace indentation (you would need to backtrack all the time which is pretty inefficient and costly).
Maybe better indentation can be done in the future using external tools until now I can only work with what Vim gives me out of the box.

I've started playing around with the indentation code and it is indeed almost impossible to guess the right indentation without the full context. I'm inclined to use a 'dumb' indenter for now, as I've found myself fighting the auto-indent more often than not. For now, I've disabled a bunch of the more problematic rules and adding my own when it makes sense, but I'm not confident this will end well.