haskell-mode icon indicating copy to clipboard operation
haskell-mode copied to clipboard

Code folding swallows all empty lines at top level indentation

Open dunrix opened this issue 5 years ago • 1 comments

Not quite sure this is a bug or a feature, but (haskell-hide-toggle) from haskell-collapse calculates end of overlay region to the next same-level indented code, while ignoring all blank lines. I'd suggest blank lines have to be ignored only in nested indentation levels, not the initial one. The way how code is now folded, with losing all intended spacing between logically unrelated code, makes it overall less readable.

For example:

main = putStrLn $ greet ++ name   -- cursor on this line
  where
    greet = "Hello "

    name = "Alice"


topLevelFn = undefined

folds to

main = putStrLn $ greet ++ name...
topLevelFn = undefined

instead of to this

main = putStrLn $ greet ++ name...


topLevelFn = undefined

ie. with initial indentation level blank lines preserved.

Related code in (haskell-find-line-with-indentation) https://github.com/haskell/haskell-mode/blob/bbdbc0e9231f49a45ce787ebfb3f2b019615bf61/haskell-collapse.el#L82-L84

where blank lines are skipped despite next indentation level found (or end of file).

Maybe some backtracking for last range of empty lines, by comparison of indentation levels between their preceding and the initial one ?

dunrix avatar May 19 '20 09:05 dunrix

Yes, you might be right. I don't use folding, and can't comment on what the ideal behaviour would be. I'd imagine keeping one blank line between the folded items might be helpful, but not necessarily all of them.

purcell avatar May 19 '20 22:05 purcell