<div dir="ltr"><div><div><div><div><div>Hi Daniel,<br><br></div>Thanks for the response. I understand the clang maintainer's perspective on this issue but I'd still like to attempt to support my formatting styles. <br>If clang devs decide its not the direction they'd like to take that's cool but its probably still worth my time to make the modifications to support it - it will save me lots of time :)<br><br></div>So if you have any pointers or where to embark on this I'd appreciate it otherwise I'll continue to wade/experiment my way through.<br><br></div>If I get to a place where its working and its not a dog's breakfast I'll give you guys a look and you can make your own mind up, no hard feelings.<br><br></div>Thanks,<br></div>Andrew<br><div><div><div><div><div><br><br></div></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Oct 31, 2015 at 3:12 PM, Daniel Jasper <span dir="ltr"><<a href="mailto:djasper@google.com" target="_blank">djasper@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">First off, please read:<div><a href="http://clang.llvm.org/docs/ClangFormatStyleOptions.html#adding-additional-style-options" target="_blank">http://clang.llvm.org/docs/ClangFormatStyleOptions.html#adding-additional-style-options</a><br></div><div><br></div><div>My initial thoughts on the two requested changes:</div><div><br></div><div>Namespaces: This isn't worth adding the complexity for. Yes, it wastes a bit of vertical space, but it is also in a place in the file where vertical space really doesn't matter this much. Plus, with C++17, this is going to become a non-issue as you can just declare "namespace a::b::c {". I feel like there has been an argument about this before.</div><div><br></div><div>Function parameters: This goes against some quite fundamental assumptions, that clang-format is making. While it certainly can be done, I'd be hesitant to get this in unless there is strong evidence that the requirements presented in the link are fulfilled.</div><div><br></div><div>Sorry, I actually hate being so negative. However, I also want clang-format to remain maintainable and provide the best possible experience for most people.</div><div><br></div><div>Cheers,<br>Daniel</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Fri, Oct 30, 2015 at 6:23 PM, Andrew Hankins via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div>Hi all,<br><br></div>First post.<br><br></div>I've found clang-format to be a very powerful and useful tool and I'd like to start extending it to support some other formatting styles that I have to work with. The two changes I'd like to start with are to namespaces and function parameters.<br></div>For namespaces I'd like create a configuration parameter that would allow nested namespaces all on one line.<br></div><br>Rather than<br></div><br>namespace a {<br></div>namespace b {<br></div>namespace c{<br>}<br>}<br></div>};<br><br></div>Support<br><br></div>namespace a { namespace b { namespace c {<br>}}};<br><br></div>and for functions rather than<br><br></div>int foo(int param1,<br></div>          int param2)<br>{<br>}<br><br></div>Support<br><br></div>int foo<br>(<br></div>    int param1,<br></div>    int pararm2<br>)<br>{<br>}<br><div><div><div><div><div><div>       <br><br></div><div>I've started to poke around in the clang lib/Format code but I'm finding it difficult to figure out where the best place to make the changes is and there isn't much documentation on the clang-format design/code I can find.<br></div><div>I think the rough idea in clang-format is to use the UnwrappedLineParser to separate the code into the appropriate lines, then using the UnwrappedLineFormatter annotate the tokens, merge lines where possible and delete unnecessary lines then finally dump it all.<br><br></div><div>Taking my namespace change for example I've made modifications to the UnwrappedLineParser::parseBlock so it won't always add a newline from parseNamespace<br><br>-----------------------------------------------------<br>@@ -399,7 +399,7 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {<br> }<br> <br> void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel,<br>-                                     bool MunchSemi) {<br>+                                     bool MunchSemi, bool AddLine) {<br>   assert(FormatTok->isOneOf(tok::l_brace, TT_MacroBlockBegin) &&<br>          "'{' or macro block token expected");<br>   const bool MacroBlock = FormatTok->is(TT_MacroBlockBegin);<br>@@ -410,7 +410,7 @@ void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel,<br>   if (MacroBlock && FormatTok->is(tok::l_paren))<br>     parseParens();<br> <br>-  addUnwrappedLine();<br>+  if (AddLine) addUnwrappedLine();<br> <br>   ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack,<br>                                           MustBeDeclaration);<br>---------------------------------<br><br></div><div>and this works somewhat but the namespaces are now missing whitespaces and you get<br></div><div><br>namespace a{namespace b{namespace c{<br>}<br>}<br>}<br></div><div><br></div><div>So instead should I write a line merger for namespaces? Or should I find a way to update the insert whitespace before/after flag?<br><br></div><div>I guess I'm just looking for some guidance on how to best approach this kind of work or to be pointed in the direction of more doco.<br><br></div><div>Thanks in advance,<br><br></div><div>Andrew<br></div></div></div></div></div></div></div>
<br></div></div>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>