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

Add option to touch only changed lines #9

Open
dbarnett opened this issue Jan 24, 2015 · 4 comments
Open

Add option to touch only changed lines #9

dbarnett opened this issue Jan 24, 2015 · 4 comments

Comments

@dbarnett
Copy link
Contributor

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
Copy link
Contributor Author

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.

@chiphogg
Copy link

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. :)

@dbarnett
Copy link
Contributor Author

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".

@wffurr
Copy link

wffurr commented Mar 6, 2018

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.

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

3 participants