
On 8 March 2013 23:10, Peter Simons
Hi guys,
it seems to me like the HughesPJ pretty printer has trouble dealing with empty lines in a nested environment. Consider the following example:
import Text.PrettyPrint.HughesPJ test1 = putStrLn $ render $ nest 4 $ vcat $ map text [ "line 1", "", "line 2" ]
The 'test1' function prints the following output, where blanks have been replaced by underscores to make them visible:
*Main> test1 ____line_1 ____ ____line_2
Now, I would like to avoid this kind of trailing whitespace in the document I'm generated -- but how? My first thought was to replace text "" by empty, but that change effectively removes the empty line altogether:
test2 = putStrLn $ render $ nest 4 $ vcat $ [ text "line 1", empty , text "line 2" ]
*Main> test2 ____line_1 ____line_2
Is there another way to accomplish what I want?
The pretty-printer is doing what it _should_ be doing here (namely indenting everything in that block); to get rid of unneeded trailing whitespace the only thing I can think of is to post-process the output (e.g.: unlines . reverse . dropWhile isSpace . reverse . lines).
Take care, Peter
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
-- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com http://IvanMiljenovic.wordpress.com