Skip to content

Commit f1fe0d0

Browse files
Chris Perivolaropoulosjaspervdj
authored andcommitted
Respect page breaks alone in a line
Page breaks are an old but effective way of bookmarking a file. They usually are single character lines. Stylish removes them as whitespace characters, and they are from the compiler's point of view but not from an editor's perspective.
1 parent 660b0c8 commit f1fe0d0

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/Language/Haskell/Stylish/Step/TrailingWhitespace.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,9 @@ dropTrailingWhitespace = reverse . dropWhile isSpace . reverse
1919

2020
--------------------------------------------------------------------------------
2121
step :: Step
22-
step = makeStep "TrailingWhitespace" $ \ls _ -> map dropTrailingWhitespace ls
22+
step = makeStep "TrailingWhitespace" $ \ls _ -> map dropTrailingWhitespace' ls
23+
where
24+
dropTrailingWhitespace' l = case l of
25+
-- Preserve page breaks
26+
"\12" -> l
27+
_ -> dropTrailingWhitespace l

tests/Language/Haskell/Stylish/Step/TrailingWhitespace/Tests.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@ case01 = expected @=? testStep step input
2828
where
2929
input = unlines
3030
[ "module Main where"
31-
, " "
31+
, " \t"
3232
, "data Foo = Bar | Qux\t "
33+
, "\12" -- page break
34+
, " \12" -- malformed page break
3335
]
3436

3537
expected = unlines
3638
[ "module Main where"
3739
, ""
3840
, "data Foo = Bar | Qux"
41+
, "\12" -- page break
42+
, ""
3943
]

0 commit comments

Comments
 (0)