summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorOndřej Janošík <j.ondra14@gmail.com>2015-09-21 01:12:29 +0200
committerOndřej Janošík <j.ondra14@gmail.com>2015-09-21 01:12:29 +0200
commit82ec3e1c458f01206c0230d4db1855c4fb6c64d8 (patch)
treefe13b64ab5ab40695df4ef86cb5dc19b486d46f5 /src
parent1637b47a9c773b870ac39c773c72d9dd6e01412b (diff)
downloadstylish-haskell-82ec3e1c458f01206c0230d4db1855c4fb6c64d8.tar.gz
New import list option
new line-multiline: Import list will start on new line when it's short enough to fit to single line. Otherwise it'll be multiline.
Diffstat (limited to 'src')
-rw-r--r--src/Language/Haskell/Stylish/Config.hs7
-rw-r--r--src/Language/Haskell/Stylish/Step/Imports.hs8
2 files changed, 12 insertions, 3 deletions
diff --git a/src/Language/Haskell/Stylish/Config.hs b/src/Language/Haskell/Stylish/Config.hs
index b8ae588..271a461 100644
--- a/src/Language/Haskell/Stylish/Config.hs
+++ b/src/Language/Haskell/Stylish/Config.hs
@@ -187,9 +187,10 @@ parseImports config o = Imports.step
]
longListAligns =
- [ ("inline", Imports.Inline)
- , ("new line", Imports.InlineWithBreak)
- , ("multiline", Imports.Multiline)
+ [ ("inline", Imports.Inline)
+ , ("new line", Imports.InlineWithBreak)
+ , ("new line-multiline", Imports.InlineToMultiline)
+ , ("multiline", Imports.Multiline)
]
diff --git a/src/Language/Haskell/Stylish/Step/Imports.hs b/src/Language/Haskell/Stylish/Step/Imports.hs
index db4e63e..2cd8e6c 100644
--- a/src/Language/Haskell/Stylish/Step/Imports.hs
+++ b/src/Language/Haskell/Stylish/Step/Imports.hs
@@ -52,6 +52,7 @@ data ListAlign
data LongListAlign
= Inline
| InlineWithBreak
+ | InlineToMultiline
| Multiline
deriving (Eq, Show)
@@ -141,6 +142,7 @@ prettyImport columns Align{..} padQualified padName longest imp =
case longListAlign of
Inline -> inlineWrap
InlineWithBreak -> longListWrapper inlineWrap inlineWithBreakWrap
+ InlineToMultiline -> longListWrapper inlineWrap inlineToMultilineWrap
Multiline -> longListWrapper inlineWrap multilineWrap
where
longListWrapper shortWrap longWrap
@@ -169,6 +171,12 @@ prettyImport columns Align{..} padQualified padName longest imp =
. withHead ("(" ++)
. withLast (++ ")"))
+ inlineToMultilineWrap
+ | length inlineWithBreakWrap > 2
+ || any ((> columns) . length) (tail inlineWithBreakWrap)
+ = multilineWrap
+ | otherwise = inlineWithBreakWrap
+
-- 'wrapRest 0' ensures that every item of spec list is on new line.
multilineWrap = paddedNoSpecBase : wrapRest 0 listPadding
( mapSpecs