diff options
author | Hiromi Ishii <konn.jinro@gmail.com> | 2013-04-19 12:22:09 +0900 |
---|---|---|
committer | Hiromi Ishii <konn.jinro@gmail.com> | 2013-04-19 12:22:09 +0900 |
commit | d2773448c20fef4439080f61c5262588be3992cb (patch) | |
tree | ca202b99d5d6c22a1c873733320768961008836f /src | |
parent | 2f312f0648c71ac4b1312855d5cc6506bdd85fa0 (diff) | |
download | stylish-haskell-d2773448c20fef4439080f61c5262588be3992cb.tar.gz |
* Rewrite function using `compact'.
* Rename `compact' to `compact_line'.
* Added the description for new style in .stylish-haskell.yml
* Added test case for `compact_line'.
Diffstat (limited to 'src')
-rw-r--r-- | src/Language/Haskell/Stylish/Config.hs | 6 | ||||
-rw-r--r-- | src/Language/Haskell/Stylish/Step/LanguagePragmas.hs | 34 |
2 files changed, 20 insertions, 20 deletions
diff --git a/src/Language/Haskell/Stylish/Config.hs b/src/Language/Haskell/Stylish/Config.hs index 32eb55d..2dd79a8 100644 --- a/src/Language/Haskell/Stylish/Config.hs +++ b/src/Language/Haskell/Stylish/Config.hs @@ -178,9 +178,9 @@ parseLanguagePragmas config o = LanguagePragmas.step <*> o A..:? "remove_redundant" A..!= True where styles = - [ ("vertical", LanguagePragmas.Vertical) - , ("compact", LanguagePragmas.Compact) - , ("line", LanguagePragmas.Line)] + [ ("vertical", LanguagePragmas.Vertical) + , ("compact", LanguagePragmas.Compact) + , ("compact_line", LanguagePragmas.CompactLine)] -------------------------------------------------------------------------------- diff --git a/src/Language/Haskell/Stylish/Step/LanguagePragmas.hs b/src/Language/Haskell/Stylish/Step/LanguagePragmas.hs index c147ade..48db19b 100644 --- a/src/Language/Haskell/Stylish/Step/LanguagePragmas.hs +++ b/src/Language/Haskell/Stylish/Step/LanguagePragmas.hs @@ -24,7 +24,7 @@ import Language.Haskell.Stylish.Util data Style = Vertical | Compact - | Line + | CompactLine deriving (Eq, Show) @@ -56,27 +56,27 @@ compactPragmas columns pragmas' = wrap columns "{-# LANGUAGE" 13 $ -------------------------------------------------------------------------------- -linePragmas :: Int -> [String] -> Lines -linePragmas _ [] = [] -linePragmas columns (p:pragmas') = - let (ls, curr, _) = foldl stp ([], p, length p) pragmas' - ps = ls ++ [curr] - longest = maximum $ map length ps - in map (wrapLANGUAGE . padRight longest) ps +compactLinePragmas :: Int -> [String] -> Lines +compactLinePragmas _ [] = [] +compactLinePragmas columns pragmas' = + let maxWidth = columns - 14 + prags = map truncateComma $ wrap maxWidth "" 1 $ + map (++ ",") (init pragmas') ++ [last pragmas'] + longest = maximum $ map length prags + in map (wrapLANGUAGE . padRight longest) prags where - maxWidth = columns - 17 - stp (ls, curr, width) str - | width' > maxWidth = (ls ++ [curr], str, len) - | otherwise = (ls, curr ++ ", " ++ str, width') - where - len = length str - width' = width + 2 + len - wrapLANGUAGE ps = "{-# LANGUAGE " ++ ps ++ " #-}" + wrapLANGUAGE ps = "{-# LANGUAGE" ++ ps ++ " #-}" + +truncateComma :: String -> String +truncateComma "" = "" +truncateComma xs + | last xs == ',' = init xs + | otherwise = xs prettyPragmas :: Int -> Int -> Style -> [String] -> Lines prettyPragmas _ longest Vertical = verticalPragmas longest prettyPragmas columns _ Compact = compactPragmas columns -prettyPragmas columns _ Line = linePragmas columns +prettyPragmas columns _ CompactLine = compactLinePragmas columns -------------------------------------------------------------------------------- -- | Filter redundant (and duplicate) pragmas out of the groups. As a side |