File tree Expand file tree Collapse file tree 4 files changed +44
-7
lines changed
lib/Language/Haskell/Stylish
tests/Language/Haskell/Stylish/Step/LanguagePragmas Expand file tree Collapse file tree 4 files changed +44
-7
lines changed Original file line number Diff line number Diff line change @@ -300,7 +300,9 @@ steps:
300300 # - compact: A more compact style.
301301 #
302302 # - compact_line: Similar to compact, but wrap each line with
303- # `{-#LANGUAGE #-}'.
303+ # `{-# LANGUAGE #-}'.
304+ #
305+ # - vertical_compact: Similar to vertical, but use only one language pragma.
304306 #
305307 # Default: vertical.
306308 style : vertical
Original file line number Diff line number Diff line change @@ -336,9 +336,10 @@ parseLanguagePragmas config o = LanguagePragmas.step
336336 <*> mkLanguage o
337337 where
338338 styles =
339- [ (" vertical" , LanguagePragmas. Vertical )
340- , (" compact" , LanguagePragmas. Compact )
341- , (" compact_line" , LanguagePragmas. CompactLine )
339+ [ (" vertical" , LanguagePragmas. Vertical )
340+ , (" compact" , LanguagePragmas. Compact )
341+ , (" compact_line" , LanguagePragmas. CompactLine )
342+ , (" vertical_compact" , LanguagePragmas. VerticalCompact )
342343 ]
343344
344345
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ data Style
3737 = Vertical
3838 | Compact
3939 | CompactLine
40+ | VerticalCompact
4041 deriving (Eq , Show )
4142
4243
@@ -73,6 +74,16 @@ compactLinePragmas lg columns align pragmas' = map (wrapLanguage . pad) prags
7374 map (++ " ," ) (init pragmas') ++ [last pragmas']
7475
7576
77+ --------------------------------------------------------------------------------
78+ verticalCompactPragmas :: String -> [String ] -> Lines
79+ verticalCompactPragmas lg pragmas' =
80+ [ " {-# " <> lg
81+ , " " <> head pragmas'
82+ ]
83+ <> [ " , " <> pragma | pragma <- tail pragmas']
84+ <> [ " #-}" ]
85+
86+
7687--------------------------------------------------------------------------------
7788truncateComma :: String -> String
7889truncateComma " " = " "
@@ -83,9 +94,10 @@ truncateComma xs
8394
8495--------------------------------------------------------------------------------
8596prettyPragmas :: String -> Maybe Int -> Int -> Bool -> Style -> [String ] -> Lines
86- prettyPragmas lp _ longest align Vertical = verticalPragmas lp longest align
87- prettyPragmas lp cols _ _ Compact = compactPragmas lp cols
88- prettyPragmas lp cols _ align CompactLine = compactLinePragmas lp cols align
97+ prettyPragmas lp _ longest align Vertical = verticalPragmas lp longest align
98+ prettyPragmas lp cols _ _ Compact = compactPragmas lp cols
99+ prettyPragmas lp cols _ align CompactLine = compactLinePragmas lp cols align
100+ prettyPragmas lp _ _ _ VerticalCompact = verticalCompactPragmas lp
89101
90102
91103--------------------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -227,3 +227,25 @@ case13 = assertSnippet
227227 , " {-# LANGUAGE DeriveFunctor #-}"
228228 , " main = let !x = 1 + 1 in print x"
229229 ]
230+
231+ --------------------------------------------------------------------------------
232+ case13 :: Assertion
233+ case13 = expected @=? testStep (step Nothing VerticalCompact False False " language" ) input
234+ where
235+ input = unlines
236+ [ " {-# LANGUAGE ViewPatterns, OverloadedStrings #-}"
237+ , " {-# LANGUAGE TemplateHaskell, ViewPatterns #-}"
238+ , " {-# LANGUAGE ScopedTypeVariables, NoImplicitPrelude #-}"
239+ , " module Main where"
240+ ]
241+
242+ expected = unlines
243+ [ " {-# language"
244+ , " NoImplicitPrelude"
245+ , " , OverloadedStrings"
246+ , " , ScopedTypeVariables"
247+ , " , TemplateHaskell"
248+ , " , ViewPatterns"
249+ , " #-}"
250+ , " module Main where"
251+ ]
You can’t perform that action at this time.
0 commit comments