summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Language/Haskell/Stylish/Config.hs2
-rw-r--r--src/Language/Haskell/Stylish/Step/LanguagePragmas.hs29
2 files changed, 24 insertions, 7 deletions
diff --git a/src/Language/Haskell/Stylish/Config.hs b/src/Language/Haskell/Stylish/Config.hs
index 6c05e0a..32eb55d 100644
--- a/src/Language/Haskell/Stylish/Config.hs
+++ b/src/Language/Haskell/Stylish/Config.hs
@@ -180,7 +180,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 a39e88d..c147ade 100644
--- a/src/Language/Haskell/Stylish/Step/LanguagePragmas.hs
+++ b/src/Language/Haskell/Stylish/Step/LanguagePragmas.hs
@@ -14,16 +14,17 @@ import qualified Language.Haskell.Exts.Annotated as H
--------------------------------------------------------------------------------
-import Language.Haskell.Stylish.Block
-import Language.Haskell.Stylish.Editor
-import Language.Haskell.Stylish.Step
-import Language.Haskell.Stylish.Util
+import Language.Haskell.Stylish.Block
+import Language.Haskell.Stylish.Editor
+import Language.Haskell.Stylish.Step
+import Language.Haskell.Stylish.Util
--------------------------------------------------------------------------------
data Style
= Vertical
| Compact
+ | Line
deriving (Eq, Show)
@@ -55,10 +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
+ 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 ++ " #-}"
+
prettyPragmas :: Int -> Int -> Style -> [String] -> Lines
prettyPragmas _ longest Vertical = verticalPragmas longest
prettyPragmas columns _ Compact = compactPragmas columns
-
+prettyPragmas columns _ Line = linePragmas columns
--------------------------------------------------------------------------------
-- | Filter redundant (and duplicate) pragmas out of the groups. As a side
@@ -76,7 +94,6 @@ filterRedundant isRedundant' = snd . foldr filterRedundant' (S.empty, [])
xs' = S.fromList fxs `S.difference` known
known' = xs' `S.union` known
-
--------------------------------------------------------------------------------
step :: Int -> Style -> Bool -> Step
step columns style = makeStep "LanguagePragmas" . step' columns style