travisjeffery / ClangFormat-Xcode

Xcode plug-in to to use clang-format from in Xcode and consistently format your code with Clang
https://twitter.com/travisjeffery
MIT License
2.89k stars 288 forks source link

Added feature to format the current statement. #102

Closed yixiang closed 8 years ago

travisjeffery commented 8 years ago

this is literally exactly the same as formatSelectedCharacters: https://github.com/yixiang/ClangFormat-Xcode/blob/ae4b492be7b59f44fb939ec124a4a20d8869cbe3/ClangFormat/TRVSFormatter.m#L52-L69

yixiang commented 8 years ago

No it is not exactly the same, see the first line, the early return condition is exactly the opposite of formatSelectedCharacters.

So formatSelectCharacters works when a range of character is selected, and formatCurrentStatement works when there is no characters selected.

yixiang commented 8 years ago

An alternatively approach could be removing the following lines from formatSelectedCharacters.

if (![TRVSXcode textViewHasSelection]) return;

But then we need to advertise the fact that it work with and WITHOUT characters selected, and explain what it does when there is no characters selected.

yixiang commented 8 years ago

This feature seems too simple to be useful, but I've been testing this feature myself for very long time. It's really handy for users who can't do file-level auto-formatting but want to keep newly added code formatted as they edit.

travisjeffery commented 8 years ago

what are the selectedRanges when there is no selection?

yixiang commented 8 years ago

Its location is cursor position and length is zero. On Wed, Oct 7, 2015 at 01:18 Travis Jeffery notifications@github.com wrote:

what is the selectedRange when there is no selected range?

— Reply to this email directly or view it on GitHub https://github.com/travisjeffery/ClangFormat-Xcode/pull/102#issuecomment-146110967 .