diff options
author | Hiromi Ishii <konn.jinro@gmail.com> | 2012-09-16 14:25:31 +0900 |
---|---|---|
committer | Hiromi Ishii <konn.jinro@gmail.com> | 2012-09-16 14:25:31 +0900 |
commit | 56542d7fb0fc99caa4251378be1ce7567a50d822 (patch) | |
tree | ca7f6ad88740e1a82ebf97a15eb2f40564fd1fa9 /src | |
parent | 4f528a7aafb29fcb726e1289c41a484b5b0599c6 (diff) | |
download | stylish-haskell-56542d7fb0fc99caa4251378be1ce7567a50d822.tar.gz |
Added `line' language pragma style. It is similar to `compact` but put "{-# LANGUAGE " for each line instead of padding.
Diffstat (limited to 'src')
-rw-r--r-- | src/Language/Haskell/Stylish/Config.hs | 2 | ||||
-rw-r--r-- | src/Language/Haskell/Stylish/Step/LanguagePragmas.hs | 21 |
2 files changed, 22 insertions, 1 deletions
diff --git a/src/Language/Haskell/Stylish/Config.hs b/src/Language/Haskell/Stylish/Config.hs index 346fcad..07b89e0 100644 --- a/src/Language/Haskell/Stylish/Config.hs +++ b/src/Language/Haskell/Stylish/Config.hs @@ -174,7 +174,7 @@ parseLanguagePragmas config o = LanguagePragmas.step styles = [ ("vertical", LanguagePragmas.Vertical) , ("compact", LanguagePragmas.Compact) - ] + , ("line", LanguagePragmas.Line)] -------------------------------------------------------------------------------- diff --git a/src/Language/Haskell/Stylish/Step/LanguagePragmas.hs b/src/Language/Haskell/Stylish/Step/LanguagePragmas.hs index 8d71c68..53657e0 100644 --- a/src/Language/Haskell/Stylish/Step/LanguagePragmas.hs +++ b/src/Language/Haskell/Stylish/Step/LanguagePragmas.hs @@ -24,6 +24,7 @@ import Language.Haskell.Stylish.Util data Style = Vertical | Compact + | Line deriving (Eq, Show) @@ -57,9 +58,29 @@ compactPragmas columns pragmas' = wrap columns "{-# LANGUAGE" 13 $ -------------------------------------------------------------------------------- +linePragmas :: Int -> [String] -> Lines +linePragmas _ [] = [] +linePragmas columns (p:pragmas') = + let (ls, curr, _) = foldl step ([], p, length p) pragmas' + ps = ls ++ [curr] + longest = maximum $ map length ps + in map (wrapLANGUAGE . padRight longest) ps + where + maxWidth = columns - 17 + step (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 ++ " #-}" + + +-------------------------------------------------------------------------------- prettyPragmas :: Int -> Style -> [String] -> Lines prettyPragmas _ Vertical = verticalPragmas prettyPragmas columns Compact = compactPragmas columns +prettyPragmas columns Line = linePragmas columns -------------------------------------------------------------------------------- |