From 0a06023aee38f7c752386d6041ad6460478b389e Mon Sep 17 00:00:00 2001 From: Leonidas Loucas Date: Wed, 1 Jul 2020 13:58:54 -0700 Subject: [PATCH] Fix {- -}, multiline and not breaking layout due to whitespace trailing a Before inline comment may address last comment in #28 --- src/Floskell/Pretty.hs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Floskell/Pretty.hs b/src/Floskell/Pretty.hs index 83b5f81b..6c7e8905 100644 --- a/src/Floskell/Pretty.hs +++ b/src/Floskell/Pretty.hs @@ -29,6 +29,7 @@ import Floskell.Types import qualified Language.Haskell.Exts.Pretty as HSE import Language.Haskell.Exts.Syntax +import Data.Char (ord) -- | Like `span`, but comparing adjacent items. run :: (a -> a -> Bool) -> [a] -> ([a], [a]) @@ -164,9 +165,19 @@ printComment correction (Comment{..}, nextSpan) = do modify (\s -> s { psEolComment = True }) InlineComment -> do write $ BS.replicate padding 32 - write "{-" - string commentText - write "-}" + if srcSpanEndColumn commentSpan - 2 == srcSpanStartColumn commentSpan + then do + alCol <- getNextColumn + write "{-" + string $ case break ((==) 10 . ord) $ reverse commentText of + (pre, _:rest) | all ((==) 32 . ord) pre -> reverse rest + _ -> commentText + newline + column alCol $ write "-}" + else do + write "{-" + string commentText + write "-}" when (srcSpanEndLine commentSpan /= srcSpanStartLine nextSpan) $ modify (\s -> s { psEolComment = True }) LineComment -> do