summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2012-10-27 15:44:17 +0200
committerJasper Van der Jeugt <m@jaspervdj.be>2012-10-27 15:44:31 +0200
commitfa53de3c7e5c21797bc8d0cc6e6330aa86fe0dee (patch)
tree7223060680c3ad32d443564c61bbf5d0733d958e /src
parentd894684b002e0c47ea6dcb559506fb9972b27cd4 (diff)
downloadstylish-haskell-fa53de3c7e5c21797bc8d0cc6e6330aa86fe0dee.tar.gz
Fix edge case wrt. to wrapping long imports
Closes #19
Diffstat (limited to 'src')
-rw-r--r--src/Language/Haskell/Stylish/Util.hs11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/Language/Haskell/Stylish/Util.hs b/src/Language/Haskell/Stylish/Util.hs
index bd0a466..004c3f1 100644
--- a/src/Language/Haskell/Stylish/Util.hs
+++ b/src/Language/Haskell/Stylish/Util.hs
@@ -65,11 +65,14 @@ wrap maxWidth leading ind strs =
-- TODO: In order to optimize this, use a difference list instead of a
-- regular list for 'ls'.
step (ls, curr, width) str
- | width' > maxWidth = (ls ++ [curr], indent ind str, ind + len)
- | otherwise = (ls, curr ++ " " ++ str, width')
+ | nextLine = (ls ++ [curr], indent ind str, ind + len)
+ | otherwise = (ls, curr ++ " " ++ str, width')
where
- len = length str
- width' = width + 1 + len
+ -- Put it on the next line if it would make the current line too long,
+ -- AND if it doesn't make the next line too long.
+ nextLine = width' > maxWidth && ind + len <= maxWidth
+ len = length str
+ width' = width + 1 + len
--------------------------------------------------------------------------------