<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On May 11, 2012, at 9:27 AM, Manuel Klimek wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hi,<br><br>we're working on the design of clang-format; there are quite a few open questions, but I'd rather get some early feedback to see whether we're completely off track somewhere.<br></blockquote><div><br></div><div>Wow, having something like this would be great!</div><br><blockquote type="cite">For those of you who prefer good old email, here is a copy of the current state.</blockquote><div><br></div>+1 thanks :)</div><div><br></div><div><blockquote type="cite"><div><b style="font-family:'Times New Roman';font-size:medium"><h2 dir="ltr" style="display: inline !important; "><span style="font-size:19px;font-family:Arial;vertical-align:baseline;white-space:pre-wrap">Context</span></h2></b><b><span style="font-size: 15px; font-family: Arial; font-weight: normal; vertical-align: baseline; white-space: pre-wrap; ">While many other languages have auto-formatters available, C++ is still lacking a tool that fits the needs of the majority of C++ programmers. Note that when we talk about </span><span style="font-size: 15px; font-family: Arial; vertical-align: baseline; white-space: pre-wrap; ">formatting</span><span style="font-size: 15px; font-family: Arial; font-weight: normal; vertical-align: baseline; white-space: pre-wrap; "> as part of this document, we mean both the problem of </span><span style="font-size: 15px; font-family: Arial; vertical-align: baseline; white-space: pre-wrap; ">indentation</span><span style="font-size: 15px; font-family: Arial; font-weight: normal; vertical-align: baseline; white-space: pre-wrap; "> (which has been largely solved independently by regexp-based implementations in editors / IDEs) and </span><span style="font-size: 15px; font-family: Arial; vertical-align: baseline; white-space: pre-wrap; ">line breaking</span><span style="font-size: 15px; font-family: Arial; font-weight: normal; vertical-align: baseline; white-space: pre-wrap; ">, which proves to be a harder problem.</span><br></b></div></blockquote><div><br></div><div>Also variable naming, use of #includes, etc? How much of <a href="http://llvm.org/docs/CodingStandards.html">http://llvm.org/docs/CodingStandards.html</a> is realistically enforcable/detectable?</div><br><blockquote type="cite"><div><b><h2 dir="ltr" style="font-family: 'Times New Roman'; font-size: medium; "><span style="font-size:19px;font-family:Arial;vertical-align:baseline;white-space:pre-wrap">Goals</span></h2>
<ul style="font-family: 'Times New Roman'; font-size: medium; margin-top: 0pt; margin-bottom: 0pt; "><li style="list-style-type:disc;font-size:15px;font-family:Arial;font-weight:normal;vertical-align:baseline"><span style="vertical-align:baseline;white-space:pre-wrap">Format a whole file according to a configuration</span></li>
<li style="list-style-type:disc;font-size:15px;font-family:Arial;font-weight:normal;vertical-align:baseline"><span style="vertical-align:baseline;white-space:pre-wrap">Format a part of a file according to a configuration</span></li>
<li style="list-style-type:disc;font-size:15px;font-family:Arial;font-weight:normal;vertical-align:baseline"><span style="vertical-align:baseline;white-space:pre-wrap">Format a part of a file while being consistent as best as possible with the rest of the file, while falling back to a configuration for options that cannot be deduced from the current file</span></li>
<li style="list-style-type:disc;font-size:15px;font-family:Arial;font-weight:normal;vertical-align:baseline"><span style="vertical-align:baseline;white-space:pre-wrap">Integrating with editors so that you can just type away until you’re far past the column limit, and then hit a key and have the editor layout the code for you, including placing the right line breaks</span></li></ul></b></div></blockquote><div><br></div><div>Some wishlist items from me:</div><div> - A "enforcer" mode that could be used in a post-commit script to find violations of the style.</div><div> - A "scanner" mode that could be used to scan a corpus of existing code to find the dominant style, instead of having to manually configure a thousand arguments like indent.</div><br><blockquote type="cite"><div><b><ul style="font-family: 'Times New Roman'; font-size: medium; margin-top: 0pt; margin-bottom: 0pt; ">
</ul><h2 dir="ltr" style="font-family: 'Times New Roman'; font-size: medium; "><span style="font-size:19px;font-family:Arial;vertical-align:baseline;white-space:pre-wrap">Non-goals</span></h2><ul style="font-family: 'Times New Roman'; font-size: medium; margin-top: 0pt; margin-bottom: 0pt; "><li style="list-style-type:disc;font-size:15px;font-family:Arial;font-weight:normal;vertical-align:baseline">
<span style="vertical-align:baseline;white-space:pre-wrap">Indenting code while you type; this is a much simpler problem, but has even stronger performance requirements - the current editors should be good enough, and we’ll allow new workflows that don’t ever require the user to break lines</span></li></ul></b></div></blockquote><div><br></div><div>Make sense, this is a different problem.</div><br><blockquote type="cite"><div><b><ul style="font-family: 'Times New Roman'; font-size: medium; margin-top: 0pt; margin-bottom: 0pt; ">
<li style="list-style-type:disc;font-size:15px;font-family:Arial;font-weight:normal;vertical-align:baseline"><span style="vertical-align:baseline;white-space:pre-wrap">The only lexical elements clang-format should touch are: whitespaces, string-literals and comments. Any other changes ranging from ordering includes to removing superfluous paranthesis are not in the scope of this tool.</span></li></ul></b></div></blockquote><blockquote type="cite"><div><b><ul style="font-family: 'Times New Roman'; font-size: medium; margin-top: 0pt; margin-bottom: 0pt; "><li style="list-style-type:disc;font-size:15px;font-family:Arial;font-weight:normal;vertical-align:baseline"><span style="vertical-align:baseline;white-space:pre-wrap">Per-file configuration: be able to annotate a file with a style which it adheres to (?)</span></li></ul></b></div></blockquote><div><br></div><div>If successful, the tool will probably be feature crept to support these. I think it is completely sensible to subset these out from any initial implementation though: best to solve some small problems well (and then grow in scope) than to try to solve all problems and never got to a point where it is useful.</div><br><blockquote type="cite"><div><b><ul style="font-family: 'Times New Roman'; font-size: medium; margin-top: 0pt; margin-bottom: 0pt; ">
</ul><h2 dir="ltr" style="font-family: 'Times New Roman'; font-size: medium; "><span style="font-size:19px;font-family:Arial;vertical-align:baseline;white-space:pre-wrap">Code location</span></h2><span style="font-size: 15px; font-family: Arial; font-weight: normal; vertical-align: baseline; white-space: pre-wrap; ">Clang-format is a very basic tool, so it might warrant living in clang mainstream. On the other hand it would also fit nicely with other clang refactoring tools. </span><span style="font-size: 15px; font-family: Arial; vertical-align: baseline; white-space: pre-wrap; ">TODO: Where do we want clang-format to live?</span><br></b></div></blockquote><div><br></div><div>No strong feeling.</div><br><blockquote type="cite"><div><b>
<h2 dir="ltr" style="font-family: 'Times New Roman'; font-size: medium; "><span style="font-size:19px;font-family:Arial;vertical-align:baseline;white-space:pre-wrap">Parsing approach</span></h2><span style="font-size: 15px; font-family: Arial; font-weight: normal; vertical-align: baseline; white-space: pre-wrap; ">The key consideration is whether clang-format can be based </span><span style="font-size: 15px; font-family: Arial; vertical-align: baseline; white-space: pre-wrap; ">purely on a lexer</span><span style="font-size: 15px; font-family: Arial; font-weight: normal; vertical-align: baseline; white-space: pre-wrap; ">, or whether it needs type information, and we need the full </span><span style="font-size: 15px; font-family: Arial; vertical-align: baseline; white-space: pre-wrap; ">AST</span><span style="font-size: 15px; font-family: Arial; font-weight: normal; vertical-align: baseline; white-space: pre-wrap; ">. </span><br>
<span style="font-size:15px;font-family:Arial;font-weight:normal;vertical-align:baseline;white-space:pre-wrap"></span><br><span style="font-size: 15px; font-family: Arial; font-weight: normal; vertical-align: baseline; white-space: pre-wrap; ">We believe that we will need the full AST information to correctly indent code, break lines, and fix whitespace within a line.</span><br></b></div></blockquote><div><br></div><div>The major tradeoff here is that requiring an AST "requires" valid code and information on how to simulate the build. If you can use just the lexer, then you can run on a random header file in isolation.</div><div><br></div><div>Perhaps it is possible to subset and layer things so that some stuff works with just the lexer (e.g. 80 column detection) but other stuff requires more integration with AST and build info?</div><br><blockquote type="cite"><div><b><h2 dir="ltr" style="font-family: 'Times New Roman'; font-size: medium; "><span style="font-size:19px;font-family:Arial;vertical-align:baseline;white-space:pre-wrap">Configuration</span></h2><span style="font-size: 15px; font-family: Arial; font-weight: normal; vertical-align: baseline; white-space: pre-wrap; ">To support a majority of developers, being able to configure the desired style is key. We propose using a YAML configuration file, as there’s already a YAML parser readily available in LLVM. Proposals for more specific ideas welcome.</span><br></b></div></blockquote><div><br></div>Makes sense to me.</div><div><br><blockquote type="cite"><div><b><h2 dir="ltr" style="font-family: 'Times New Roman'; font-size: medium; "><span style="font-size:19px;font-family:Arial;vertical-align:baseline;white-space:pre-wrap">Style deduction</span></h2><span style="font-size: 15px; font-family: Arial; font-weight: normal; vertical-align: baseline; white-space: pre-wrap; ">When changing the format of code that does not conform to a given style configuration, we will optionally try to deduce style options from the file first, and fall back to the configured layout when there was no clear style deducible from the context.</span><br></b></div></blockquote><div><br></div><div>+100 :)</div><br></div><div>-Chris</div><br></body></html>