lspitzner / brittany

haskell source code formatter
GNU Affero General Public License v3.0
690 stars 72 forks source link

Is it feasible to implement a layout: false option? #317

Open maralorn opened 3 years ago

maralorn commented 3 years ago

Hey, thx for brittany!

I have some reasons to suspect that I could like it more to write my code with explicit { ; } style than relying on layout. Putting those symbols at the right spot is sometimes a lot easier, than fixing my alignment. After all for alignment I have brittany. </offtopic>

I have cloned brittany and started poking at the Layouters to see if I can get it to print explicit { ; }.

I can do it, when I put the ; in front of every line, by prepending it with docSeq.

I get code like this:

do {
   ; cursorUpLine writtenLines
   ; clearFromCursorToScreenEnd
   }

But I would also like to try to append it to every line, the bridoc documentation says I shouldn‘t, and alas when I try I get syntax errors (sadly brittany didn‘t tell me what syntax errors).

My questions:

  1. Is there a way to append a ; to the last line of a possible multi line statement and what do I need to do to not append it to a comment?
  2. Have you thought about this feature before, do you think it's feasible and do you have any tips?
tfausak commented 3 years ago

I'm not exactly sure what you're asking for. Do you want Brittany to consume or produce code without layouting?

maralorn commented 3 years ago

Brittany can perfectly parse any code with or without layouting. The problem is, that it will then use layouting to print it again. So after formatting once all your { ; } is gone.

That's not a bug, but I was looking into making it possible to have an option for this.

tfausak commented 3 years ago

It is possible to disable formatting entirely, which will preserve the explicit brackets and semicolons.

$ cat gh317.hs 
-- brittany-disable-next-binding
main = do { print 1; print 2 }

$ brittany gh317.hs 
-- brittany-disable-next-binding
main = do { print 1; print 2 }
maralorn commented 3 years ago

I didn‘t know about that option, although I searched for it for a while. Is it documented somewhere?

Anyways that is nice, but I’d still love to actually have formatting on blocks with braces.

So my initial question still stands, which is "How hard would it be, to get the formater to append a symbol to the last line of a multiline element."