<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jun 27, 2016 at 5:19 PM, mlimber via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" class="gmail-cremed gmail-cremed gmail-cremed cremed">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div><div><div>This Q&A asks about using clang-format to support table-like code:<br><br><a href="http://stackoverflow.com/questions/38022831/how-to-make-clang-format-respect-table-like-code-formatting" class="gmail-cremed gmail-cremed gmail-cremed cremed">http://stackoverflow.com/questions/38022831/how-to-make-clang-format-respect-table-like-code-formatting</a><br><br></div><div>Motivating examples for this sort of thing include GUI construction code (e.g., this Qt sample code: <a href="http://doc.qt.io/qt-5/qtwidgets-widgets-groupbox-example.html#window-class-implementation" class="gmail-cremed gmail-cremed gmail-cremed cremed">http://doc.qt.io/qt-5/qtwidgets-widgets-groupbox-example.html#window-class-implementation</a> ).<br></div><div><br></div>The two cases mentioned in the Q&A could be slightly expanded to:<br></div><div><br></div>1. Braced initializers (including C++11 initializer lists).<br></div>2. Function calls<br></div><br></div>Each could include:<br><br>a. Rows and columns within a single statement (shown in Q&A)<br></div></div></div></div></blockquote><div><br></div><div>I presume that you mean the first statement with the nested braced list. </div><br class="gmail-Apple-interchange-newline"><div>I have always wanted to do this, but so far haven't been able to set aside the time. I would guess that this isn't too hard based on the work that has been done to layout non-nested braced lists in columns.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div>b. Rows in different statements with columns following the same pattern for each row (shown in the Q&A with Create() functions -- same function call, same number of params, etc.).<br></div></div></div></blockquote><div><br></div><div>This should also be reasonably hard to do if you can live with certain limitations. It could probably be implemented very similar to the style options (<a href="http://clang.llvm.org/docs/ClangFormatStyleOptions.html">http://clang.llvm.org/docs/ClangFormatStyleOptions.html</a>) AlignConsecutiveAssignments and AlignConsecutiveDeclarations.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>c. Nested tables,e.g., <br><br></div>  S s = {<br>    { { "Dubs", abc,    123 },<br>      { "X",    n,      m   },<br>      { "YZ",   ij / q, kl  } },<br><br>    { { "Dubs", abc,    123 },<br>      { "X",    n,      m   },<br>      { "YZ",   ij / q, kl  } },<br>  };<br><div><br></div><div>vs. (perhaps depending on max line length or user option)<br></div><div><br>  S s = {<br>    { { "Dubs", abc,    123 }, { "X",    n,      m   }, { "YZ",   ij / q, kl  } },<br>    { { "X",    n,      m   }, { "YZ",   ij / q, kl  }, { "Dubs", abc,    123 }  },<br>  };<br></div></div></blockquote><div><br></div><div>I don't see the fundamental difference to (a) here. I think the two could be implemented together.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div>Similar nesting could be done with function calls within function call params.<br></div></div></div></blockquote><div><br></div><div>This might get very tricky, I think. The danger I see is that it can become unexpected that clang-format starts aligning specific things. Users generally dislike if the result suddenly becomes unexpected. The question is also how to control it. Say for a certain statement you'd really not want this alignment. What do you do?</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>d. Rows and columns following a looser pattern (e.g., different function names, different number of params, optionally keeping return values):<br><br></div>  w  = CreateDubs( "Dubs", abc,    123 );<br>  x  = CreateEx(   "X",    n           ); // Two params!<br>  CreateWhyZed(    "YZ",   ij / q, kl  ); // Ignore return value<br></div></blockquote><div><br></div><div>Here also, the precise cases in which it should be done are much less clear to me.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div><div>My question is, how hard would it be to modify LibFormat to support some or all of these cases? <br><br>I'm an experienced developer, but I've not done LLVM development before. I'm potentially interested in working on it and submitting a patch, but I thought I would ask here first in case you can tell me that it would be an exercise in futility or would be unlikely to be accepted as a feature. Would it have to support all of these cases to be accepted?<br></div></div></div></div></blockquote><div><br></div><div>(a), (b) and the first half of (c) certainly. I am less convinced that we are going to find good, generally useful rules/heuristics for the rest.</div><div><br></div><div>Cheers,</div><div>Daniel</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div><div><br></div><div>Cheers!<span class="gmail-HOEnZb"><font color="#888888"><br></font></span></div><span class="gmail-HOEnZb"><font color="#888888"><div><br></div><div>M<br></div></font></span></div></div></div>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" class="gmail-cremed gmail-cremed gmail-cremed cremed">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" class="gmail-cremed gmail-cremed gmail-cremed cremed">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div></div>