Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cabal format adds empty lines with trailing whitespace #1966

Closed
tibbe opened this issue Jun 26, 2014 · 11 comments
Closed

cabal format adds empty lines with trailing whitespace #1966

tibbe opened this issue Jun 26, 2014 · 11 comments

Comments

@tibbe
Copy link
Member

tibbe commented Jun 26, 2014

If you run cabal format on e.g. in the cabal-install/ directory, you'll see that cabal format adds empty lines with trailing whitespace (i.e. 4 spaces). It shouldn't do that.

@ddssff
Copy link
Contributor

ddssff commented Jun 26, 2014

I think this might be the same as #1921

@23Skidoo
Copy link
Member

23Skidoo commented Aug 2, 2014

The Text.PrettyPrint module may be the cause of the problem - it doesn't do a very good job of avoiding trailing whitespace. Which can be annoying - one example is cabal init.

@osa1
Copy link

osa1 commented Mar 9, 2015

Cabal file generators(cabal format, cabal init, probably some other commands?) always do this. As also pointed out by @23Skidoo this is related with pretty library, which generates trailing space if we have a code like nest 4 (text "" $+$ ...).

I can think several solutions:

  1. We can modify pretty library and add a new EmptyLine constructor to Doc, then handle that in vertical composition functions specially to not generate any whitespace, only generate a "\n". Then we can use emptyLine instead of text "".
  2. We can make significant refactoring in Cabal pretty printer to not have any text "" inside nest. (this is probably very hard to do, and resulting code may not be very good)
  3. We can wrap writeCabalFile and writeGenericPackageDescription with a function that removes trailing white space with the cost of an extra copy.

(3) seems to be the easiest solution, however I think (1) is the best, because as far as I can understand from the API docs of pretty, it doesn't provide a way to insert newlines, without having them indented and this seems to be a limitation of the library.

What do you think? Should we go with (3) for now?

@23Skidoo
Copy link
Member

23Skidoo commented Mar 9, 2015

I like option (1) best, (3) could be a temporary workaround.

@osa1
Copy link

osa1 commented Mar 14, 2015

I implemented (1), but I need some reviewers. I'm trying to get in contact with pretty maintainers, hopefully we can fix this in a principled way.

@23Skidoo
Copy link
Member

@osa1 Great, thank you for working on this.

@byorgey
Copy link
Member

byorgey commented Mar 30, 2015

What's the status of this? @osa1 , can you post here a link to your implementation of (1)?

@osa1
Copy link

osa1 commented Mar 30, 2015

I feel like it's trivial to implement for someone who knows internals of pretty, and I asked for help here haskell/pretty#26 because I don't know the internals, and lack of documentation is a problem. Main problem is that even though it's possible to do without adding any new Doc constructor, some internals, documentation and maybe even invariants need to be changed, and it's not trivial for me to figure out what to change. I think I can spare some time for this after tomorrow.

@gbaz
Copy link
Collaborator

gbaz commented Nov 27, 2018

Is this resolved?

@phadej
Copy link
Collaborator

phadej commented Nov 27, 2018

Not yet. #5737 resolve this though.

@jneira
Copy link
Member

jneira commented Jul 15, 2021

#5737 is merged so I am gonna close it, @tibbe feel free to reopen if it is not resolved for you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants