summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--data/stylish-haskell.yaml4
-rw-r--r--src/Language/Haskell/Stylish/Step/LanguagePragmas.hs23
2 files changed, 17 insertions, 10 deletions
diff --git a/data/stylish-haskell.yaml b/data/stylish-haskell.yaml
index cc117e5..8ceb732 100644
--- a/data/stylish-haskell.yaml
+++ b/data/stylish-haskell.yaml
@@ -41,7 +41,9 @@ steps:
#
# - compact: A more compact style.
#
- # - compact_line: Similar to compact, but wrap each line by `{-#LANGUAGE #-}'.
+ # - compact_line: Similar to compact, but wrap each line with
+ # `{-#LANGUAGE #-}'.
+ #
# Default: vertical.
style: vertical
diff --git a/src/Language/Haskell/Stylish/Step/LanguagePragmas.hs b/src/Language/Haskell/Stylish/Step/LanguagePragmas.hs
index 48db19b..209b2f2 100644
--- a/src/Language/Haskell/Stylish/Step/LanguagePragmas.hs
+++ b/src/Language/Haskell/Stylish/Step/LanguagePragmas.hs
@@ -59,25 +59,30 @@ compactPragmas columns pragmas' = wrap columns "{-# LANGUAGE" 13 $
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
+ let maxWidth = columns - 16
+ longest = maximum $ map length prags
+ prags = map truncateComma $ wrap maxWidth "" 1 $
+ map (++ ",") (init pragmas') ++ [last pragmas']
+ in map (wrapLanguage . padRight longest) prags
where
- wrapLANGUAGE ps = "{-# LANGUAGE" ++ ps ++ " #-}"
+ wrapLanguage ps = "{-# LANGUAGE" ++ ps ++ " #-}"
+
+--------------------------------------------------------------------------------
truncateComma :: String -> String
-truncateComma "" = ""
+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 _ longest Vertical = verticalPragmas longest
+prettyPragmas columns _ Compact = compactPragmas columns
prettyPragmas columns _ CompactLine = compactLinePragmas columns
+
--------------------------------------------------------------------------------
-- | Filter redundant (and duplicate) pragmas out of the groups. As a side
-- effect, we also sort the pragmas in their group...