[PATCH] clang-format: Add reflow capability to line comment formatting
faisalv at gmail.com
Sun Jun 29 17:21:07 PDT 2014
Hi djasper, klimek, alexfh, rsmith,
Based on an email discussion with Manuel Klimek - (and thoughts from Daniel Jasper and Alexander Kornienko), I have hacked up a quickish patch to allow reflow of line comments (works for me reasonably well in Visual Studio) for clang-format.
The idea is to not just insert a break into a line comment if it exceeds the comment limit, but to consider its subsequent line-comments and reflow and reformat the block of line-commenst. That way you can add a word anywhere in your block of line-comments, clang-format them, and feel *reasonably*;) confident you are within your column limit without abrupt breaks.
The heuristic I have currently used to decide to merge a block of comments is as follows:
If in editor mode (which I kludge-ily/brittley detect - is there a cleaner way to determine this and exactly what text is selected?):
- for all line comments that are not separated by an additional new line, or an empty comment, or more than 3 forward slashes in sequence, they are joined and reflowed.
If in non-editor mode (which the patch actually has currently disabled - see where I have mistakenly commented out: //clang::format::isInEditorMode();), once we encounter a comment that is on a line that exceeds the column limit, only then do we start joining and then keep joining comment lines until we have enough lines to reflow the comment, and then stop (including following the rules for non-joining in editor mode).
I currently use the comment prefix of the line that is being broken (so just because the first line-comment in the block of comments is with three slashes, does not entail all of them being formatted with three, even if they were written with two) - not sure if that was the most desirable thing to do. Eitherway is ok with me.
I do not know how to run the unittests, since I've mostly worked on clang, and have not had to use the 'unittest' testing framework - so I could really use some help writing tests - Not only to show me how to write and *run* the unittests (or point me to the docs) on a windows environment but also to actually write some tests for this.
My visually confirmed tests are pasted here:
Any constructive feedback and or guidance will be greatly appreciated.
Also if this patch might be something you appreciate, and if you happen to work with or have any influence over Richard Smith - please buy him a beer and have him give me feedback on my patch for C++ member template specializations: http://reviews.llvm.org/D3445
(he did say to ping him vigorously, so i could use your help in pinging him (though I do feel slightly coldly impositional, since I know he's been trying to get to it since May ;)
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 23189 bytes
Desc: not available
More information about the cfe-commits