vim-codefmt icon indicating copy to clipboard operation
vim-codefmt copied to clipboard

Add option to touch only changed lines

Open dbarnett opened this issue 9 years ago • 4 comments

It would be nice to have a mode to detect which lines you had touched in this editing session and only format those ranges.

We'd need a way to decide between this behavior and formatting the whole buffer. One option would be a new :FormatChangedLines and :AutoFormatChangedLines command that would work as variants of :FormatCode and :AutoFormatBuffer.

dbarnett avatar Jan 24 '15 07:01 dbarnett

BTW, fine-grained range formatting will be really annoying for formatters that don't natively support ranges, like gofmt. The hacks we use to approximate range formatting will show errors if the range starts or ends in the middle of a code block. We could just leave it to users whether they decide to enable it anyway, but I foresee frustrated users not understanding why it doesn't work and filing bugs about it.

dbarnett avatar Jan 24 '15 07:01 dbarnett

How about this?

  • For formatters which don't support ranges, choosing this option means "format the whole file".
  • Show a warning explaining this behaviour, with see :help codefmt-foobarbaz at the end. (Either on buffer open or autoformat enable.)

It's just that for formatters which do support ranges, this feature is super useful, so I'd like to see it not held up. My annoyed code reviewers and I thank you in advance. :)

chiphogg avatar Feb 23 '15 14:02 chiphogg

Ugh, this is why all formatters should just have good range formatting support… I think I agree the fallback should be to format the whole file (only if the file was actually changed), but either way I'm expecting confused users reporting "that's not what I asked it to do".

dbarnett avatar Feb 23 '15 17:02 dbarnett

I don't know if you can win, I get confused when lines I didn't change are formatted, particularly in languages without a canonical formatter like gofmt. I tried using codefmt and it introduced a lot of format churn into my CLs.

wffurr avatar Mar 06 '18 22:03 wffurr