sorawee / fmt

A code formatter for Racket
Other
72 stars 6 forks source link

diff-friendly formatting? #37

Open gussmith23 opened 2 years ago

gussmith23 commented 2 years ago

I use fmt all the time, and it rocks -- perhaps the only thing that bugs me is that the diffs after formatting can be huge, even after I change just a single line. For example, if I change a line such that it becomes longer than the max line length, it will get wrapped, which can cause a change of indentation in the rest of the scope. Is there any way around this?

sorawee commented 2 years ago

Can you post an example file before and after you make the change? (Slack is fine too, if you don't want to disclose the source file publicly).

In general, Racket is different from other languages in that it heavily uses dynamic alignment. For example, you would indent with 5 spaces in:

(foo arg1
     arg2
     arg3
     arg4)

where 5 = 1 (from lparen) + 3 (from foo) + 1 (from space). It's dynamic because foo is dynamic content.

So if you change foo to something else, reformatting could affect a lot of lines.

C-like languages have static alignment, and I suspect that the diff would be smaller as a result.