summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2012-07-31 10:39:24 +0200
committerJasper Van der Jeugt <m@jaspervdj.be>2012-07-31 10:39:24 +0200
commitb5f31ec2845ac5ebe3fb1f5b63f8723f072e46b6 (patch)
treefbc802b9633fb88593501952d57955ec2a46864c /src
parent1db6cc5767608e7512d1d0e02807d36c7c2355cb (diff)
downloadstylish-haskell-b5f31ec2845ac5ebe3fb1f5b63f8723f072e46b6.tar.gz
Clean up and test case for long imports
Diffstat (limited to 'src')
-rw-r--r--src/StylishHaskell/Step/Imports.hs33
1 files changed, 12 insertions, 21 deletions
diff --git a/src/StylishHaskell/Step/Imports.hs b/src/StylishHaskell/Step/Imports.hs
index 25be81e..3760e97 100644
--- a/src/StylishHaskell/Step/Imports.hs
+++ b/src/StylishHaskell/Step/Imports.hs
@@ -6,10 +6,9 @@ module StylishHaskell.Step.Imports
--------------------------------------------------------------------------------
-import Control.Applicative ((<$>))
import Control.Arrow ((&&&))
import Data.Char (isAlpha, toLower)
-import Data.List (sortBy)
+import Data.List (intercalate, sortBy)
import Data.Maybe (isJust, maybeToList)
import Data.Ord (comparing)
import qualified Language.Haskell.Exts.Annotated as H
@@ -94,7 +93,14 @@ sortImportSpecs imp = imp {H.importSpecs = fmap sort $ H.importSpecs imp}
--------------------------------------------------------------------------------
prettyImport :: Bool -> Bool -> Int -> H.ImportDecl l -> String
prettyImport padQualified padName longest imp =
- unlines specs
+ intercalate "\n" $
+ wrap 80 base (length base + 1) $
+ (if hiding then ("hiding" :) else id) $
+ withInit (++ ",") $
+ withHead ("(" ++) $
+ withLast (++ ")") $
+ map H.prettyPrint $
+ importSpecs
where
base = unwords $ concat
[ ["import"]
@@ -104,23 +110,9 @@ prettyImport padQualified padName longest imp =
, ["as " ++ as | H.ModuleName _ as <- maybeToList $ H.importAs imp]
]
-
- -- specs = unlines . indentSpecs . lines . H.prettyPrint <$> H.importSpecs imp
- specs = wrap 80 base (length base + 1) $
- (if hiding then ("hiding" :) else id) $
- withInit (++ ",") $
- withHead ("(" ++) $
- withLast (++ ")") $
- map H.prettyPrint $
- importSpecs
-
- hiding = case H.importSpecs imp of
- Just (H.ImportSpecList _ h _) -> h
- _ -> False
-
- importSpecs = case H.importSpecs imp of
- Just (H.ImportSpecList _ _ l) -> l
- _ -> []
+ (hiding, importSpecs) = case H.importSpecs imp of
+ Just (H.ImportSpecList _ h l) -> (h, l)
+ _ -> (False, [])
hasExtras = isJust (H.importAs imp) || isJust (H.importSpecs imp)
@@ -130,7 +122,6 @@ prettyImport padQualified padName longest imp =
| otherwise = []
-
--------------------------------------------------------------------------------
prettyImportGroup :: Align -> Int -> [H.ImportDecl LineBlock] -> Lines
prettyImportGroup align longest imps =