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:
Before: http://pastebin.com/cmGYqBcc
After: http://pastebin.com/ZiRKjMB5
Any constructive feedback and or guidance will be greatly appreciated.
Thanks!
Any reason to do use lambda here?