diff options
author | Linus Arver <larver@imvu.com> | 2017-05-09 03:05:54 -0700 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2017-05-09 12:05:54 +0200 |
commit | 03e1712b9da40c366f459b53555963e69eb288ec (patch) | |
tree | eb6d2fef169aa1d0092cbdb0f83bfa1ca190e611 /lib | |
parent | 234431a6ac375da9bceb865f65cbe5d1b529d5ef (diff) | |
download | stylish-haskell-03e1712b9da40c366f459b53555963e69eb288ec.tar.gz |
Add space_surround option to import styling
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Language/Haskell/Stylish/Config.hs | 3 | ||||
-rw-r--r-- | lib/Language/Haskell/Stylish/Step/Imports.hs | 16 |
2 files changed, 13 insertions, 6 deletions
diff --git a/lib/Language/Haskell/Stylish/Config.hs b/lib/Language/Haskell/Stylish/Config.hs index b83cf3a..667a6eb 100644 --- a/lib/Language/Haskell/Stylish/Config.hs +++ b/lib/Language/Haskell/Stylish/Config.hs @@ -190,7 +190,8 @@ parseImports config o = Imports.step <*> (o A..:? "empty_list_align" >>= parseEnum emptyListAligns (def Imports.emptyListAlign)) <*> o A..:? "list_padding" A..!= (def Imports.listPadding) - <*> o A..:? "separate_lists" A..!= (def Imports.separateLists)) + <*> o A..:? "separate_lists" A..!= (def Imports.separateLists) + <*> o A..:? "space_surround" A..!= (def Imports.spaceSurround)) where def f = f Imports.defaultOptions diff --git a/lib/Language/Haskell/Stylish/Step/Imports.hs b/lib/Language/Haskell/Stylish/Step/Imports.hs index 78912d6..38ced99 100644 --- a/lib/Language/Haskell/Stylish/Step/Imports.hs +++ b/lib/Language/Haskell/Stylish/Step/Imports.hs @@ -42,6 +42,7 @@ data Options = Options , emptyListAlign :: EmptyListAlign , listPadding :: ListPadding , separateLists :: Bool + , spaceSurround :: Bool } deriving (Eq, Show) defaultOptions :: Options @@ -52,6 +53,7 @@ defaultOptions = Options , emptyListAlign = Inherit , listPadding = LPConstant 4 , separateLists = True + , spaceSurround = False } data ListPadding @@ -280,21 +282,21 @@ prettyImport columns Options{..} padQualified padName longest imp inlineWrap = inlineWrapper $ mapSpecs $ withInit (++ ",") - . withHead ("(" ++) - . withLast (++ ")") + . withHead (("(" ++ maybeSpace) ++) + . withLast (++ (maybeSpace ++ ")")) inlineWrapper = case listAlign of NewLine -> (paddedNoSpecBase :) . wrapRest columns listPadding' WithAlias -> wrap columns paddedBase (inlineBaseLength + 1) -- Add 1 extra space to ensure same padding as in original code. - AfterAlias -> withTail (' ' :) + AfterAlias -> withTail ((' ' : maybeSpace) ++) . wrap columns paddedBase (afterAliasBaseLength + 1) inlineWithBreakWrap = paddedNoSpecBase : wrapRest columns listPadding' ( mapSpecs $ withInit (++ ",") - . withHead ("(" ++) - . withLast (++ ")")) + . withHead (("(" ++ maybeSpace) ++) + . withLast (++ (maybeSpace ++ ")"))) inlineToMultilineWrap | length inlineWithBreakWrap > 2 @@ -370,6 +372,10 @@ prettyImport columns Options{..} padQualified padName longest imp Just [] -> ["()"] -- Instance only imports Just is -> f $ map (prettyImportSpec separateLists) is + maybeSpace = case spaceSurround of + True -> " " + False -> "" + -------------------------------------------------------------------------------- prettyImportGroup :: Int -> Options -> Bool -> Int |