neovimhaskell/haskell-vim

Re-indenting lines already containing text

jonascarpay opened this issue · 12 comments

Is there a way to stop the re-indentation of lines already containing text? Problems occur after manually fixing ambiguities. For example, after manually fixing the indentation for

where foo = do do1
               do2

adding a space after do2 turns it into

where foo = do do1
      do2 <- ...

Looks like the indentation precedence was not right for where blocks. Please try again.

Thanks for the quick response. I'm getting correct indentation for do! But it looks like where no longer indents :/

foo = bar
where bar = do do1
               do2 =

Arg, looks like there was a missing endif somewhere in the code which was silently ignored. Gotta love VimL. I'm somewhat curious if this is going to break something else. I wish Vim could handle proper parsing.

Indentation on where block now works correctly 👍. There are other places where I'm having trouble with the automatic re-indentation that I suspect might not just be a bug, but ambiguities in indentation? For example:
After manually fixing

foo = do do1
         let var1 = undefined
             do2

to

foo = do do1
         let var1 = undefined
         do2

typing a space after do2 re-indents it to

foo = do do1
         let var1 = undefined
             do2 var1

Yep, that's somewhat hard to disambiguate because you could write something like:

foo = do do1
         let var1 = undefined
             do2 var1
          in 

I don't think I made the issue entirely clear, it's not the indentation itself. I'll see if I can record a quick demonstration tonight!

You've made the issue clear. The thing is that with the tools that Vim has to offer this is pretty hard to do. And it's not efficient, I've elaborated this in several issue reports.
Re-indentation after space might be odd but I haven't found a way to make some of the indentations work without it. I could add a special case for let to not re-indent when both lines line up.

https://github.com/neovimhaskell/haskell-vim/blob/master/indent/haskell.vim#L61
change this to not include space, might improve this plugin to remove that( assuming it isn't completely necessary for something)

This won't fix the problem of wrong indentation. It would only defer the wrong indentation to a later point in time.

true, though it is less of a problem when you can type a space and not need to again manually reindent

Do you think it's feasible to have Ctrl-D or < work by snapping to either 1) possible indentations suggested by the syntax or 2) the same indentation levels as nearby lines? I might give nr 2 a shot over the weekend if there's no reason why it shouldn't work, but it sounds like there might be some pitfalls.

Also, sorry for reopening and closing the issue, that was not on purpose.

I'm not entirely sure what you are trying to do, so I can't tell if it makes sense or if I would even merge it :)