<p dir="ltr">I'm pretty sure I don't intentionally hand-format code after clang-format. But I also don't specially clang-format everything before commit. So assume that anything not clang-formatted you find in my commits is purely unintentional. If you want to avoid this, we should probably think of an automated way to run clang-format over itself as a part of tests or something.</p>
<div class="gmail_quote">On May 13, 2013 12:22 PM, "Daniel Jasper" <<a href="mailto:djasper@google.com">djasper@google.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Sorry, turns out, I was just not able to use clang-format with the right parameters .. :-/</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, May 13, 2013 at 12:20 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"><br><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div>On Fri, May 10, 2013 at 8:12 PM, Alexander Kornienko <span dir="ltr"><<a href="mailto:alexfh@google.com" target="_blank">alexfh@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: alexfh<br>
Date: Fri May 10 13:12:00 2013<br>
New Revision: 181617<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=181617&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=181617&view=rev</a><br>
Log:<br>
Reformat clang-format help strings, filter out irrelevant options.<br>
<br>
Summary: +updated ClangFormat.rst<br>
<br>
Reviewers: djasper, klimek<br>
<br>
Reviewed By: klimek<br>
<br>
CC: cfe-commits<br>
<br>
Differential Revision: <a href="http://llvm-reviews.chandlerc.com/D780" target="_blank">http://llvm-reviews.chandlerc.com/D780</a><br>
<br>
Modified:<br>
cfe/trunk/docs/ClangFormat.rst<br>
cfe/trunk/tools/clang-format/ClangFormat.cpp<br>
<br>
Modified: cfe/trunk/docs/ClangFormat.rst<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormat.rst?rev=181617&r1=181616&r2=181617&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormat.rst?rev=181617&r1=181616&r2=181617&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/docs/ClangFormat.rst (original)<br>
+++ cfe/trunk/docs/ClangFormat.rst Fri May 10 13:12:00 2013<br>
@@ -20,21 +20,43 @@ to format C/C++/Obj-C code.<br>
<br>
If no arguments are specified, it formats the code from standard input<br>
and writes the result to the standard output.<br>
- If <file> is given, it reformats the file. If -i is specified together<br>
- with <file>, the file is edited in-place. Otherwise, the result is<br>
- written to the standard output.<br>
+ If <file>s are given, it reformats the files. If -i is specified<br>
+ together with <file>s, the files are edited in-place. Otherwise, the<br>
+ result is written to the standard output.<br>
<br>
- USAGE: clang-format [options] [<file>]<br>
+ USAGE: clang-format [options] [<file> ...]<br>
<br>
OPTIONS:<br>
- -fatal-assembler-warnings - Consider warnings as error<br>
- -help - Display available options (-help-hidden for more)<br>
- -i - Inplace edit <file>, if specified.<br>
- -length=<int> - Format a range of this length, -1 for end of file.<br>
- -offset=<int> - Format a range starting at this file offset.<br>
- -stats - Enable statistics output from program<br>
- -style=<string> - Coding style, currently supports: LLVM, Google, Chromium.<br>
- -version - Display the version of this program<br>
+<br>
+ Clang-format options:<br>
+<br>
+ -dump-config - Dump configuration options to stdout and exit.<br>
+ Can be used with -style option.<br>
+ -i - Inplace edit <file>s, if specified.<br>
+ -length=<uint> - Format a range of this length (in bytes).<br>
+ Multiple ranges can be formatted by specifying<br>
+ several -offset and -length pairs.<br>
+ When only a single -offset is specified without<br>
+ -length, clang-format will format up to the end<br>
+ of the file.<br>
+ Can only be used with one input file.<br>
+ -offset=<uint> - Format a range starting at this byte offset.<br>
+ Multiple ranges can be formatted by specifying<br>
+ several -offset and -length pairs.<br>
+ Can only be used with one input file.<br>
+ -output-replacements-xml - Output replacements as XML.<br>
+ -style=<string> - Coding style, currently supports:<br>
+ LLVM, Google, Chromium, Mozilla.<br>
+ Use '-style file' to load style configuration from<br>
+ .clang-format file located in one of the parent<br>
+ directories of the source file (or current<br>
+ directory for stdin).<br>
+<br>
+ General options:<br>
+<br>
+ -help - Display available options (-help-hidden for more)<br>
+ -help-list - Display list of available options (-help-list-hidden for more)<br>
+ -version - Display the version of this program<br>
<br>
<br>
Vim Integration<br>
<br>
Modified: cfe/trunk/tools/clang-format/ClangFormat.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=181617&r1=181616&r2=181617&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=181617&r1=181616&r2=181617&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/tools/clang-format/ClangFormat.cpp (original)<br>
+++ cfe/trunk/tools/clang-format/ClangFormat.cpp Fri May 10 13:12:00 2013<br>
@@ -23,43 +23,57 @@<br>
#include "llvm/Support/Debug.h"<br>
#include "llvm/Support/FileSystem.h"<br>
#include "llvm/Support/Signals.h"<br>
+#include "llvm/ADT/StringMap.h"<br>
<br>
using namespace llvm;<br>
<br>
static cl::opt<bool> Help("h", cl::desc("Alias for -help"), cl::Hidden);<br>
<br>
-static cl::list<unsigned> Offsets(<br>
- "offset",<br>
- cl::desc(<br>
- "Format a range starting at this byte offset. Multiple ranges can be "<br>
- "formatted by specifying several -offset and -length pairs. Can "<br>
- "only be used with one input file."));<br>
-static cl::list<unsigned> Lengths(<br>
- "length",<br>
- cl::desc("Format a range of this length (in bytes). Multiple ranges can be "<br>
- "formatted by specifying several -offset and -length pairs. When "<br>
- "only a single -offset is specified without -length, clang-format "<br>
- "will format up to the end of the file. Can only be used with one "<br>
- "input file."));<br>
-static cl::opt<std::string> Style(<br>
- "style",<br>
- cl::desc(<br>
- "Coding style, currently supports: LLVM, Google, Chromium, Mozilla. "<br>
- "Use '-style file' to load style configuration from .clang-format file "<br>
- "located in one of the parent directories of the source file (or "<br>
- "current directory for stdin)."),<br>
- cl::init("LLVM"));<br>
+// Mark all our options with this category, everything else (except for -version<br>
+// and -help) will be hidden.<br>
+cl::OptionCategory ClangFormatCategory("Clang-format options");<br>
+<br>
+static cl::list<unsigned><br>
+ Offsets("offset",<br>
+ cl::desc("Format a range starting at this byte offset.\n"<br>
+ "Multiple ranges can be formatted by specifying\n"<br>
+ "several -offset and -length pairs.\n"<br>
+ "Can only be used with one input file."),<br>
+ cl::cat(ClangFormatCategory));<br></blockquote><div><br></div></div></div><div>I think we should try to keep clang-format's files "clang-format clean". Is there something you found particularly bad about the way clang-format formats this? Can we fix it? </div>
<div><div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+static cl::list<unsigned><br>
+ Lengths("length",<br>
+ cl::desc("Format a range of this length (in bytes).\n"<br>
+ "Multiple ranges can be formatted by specifying\n"<br>
+ "several -offset and -length pairs.\n"<br>
+ "When only a single -offset is specified without\n"<br>
+ "-length, clang-format will format up to the end\n"<br>
+ "of the file.\n"<br>
+ "Can only be used with one input file."),<br>
+ cl::cat(ClangFormatCategory));<br>
+static cl::opt<std::string><br>
+ Style("style",<br>
+ cl::desc("Coding style, currently supports:\n"<br>
+ " LLVM, Google, Chromium, Mozilla.\n"<br>
+ "Use '-style file' to load style configuration from\n"<br>
+ ".clang-format file located in one of the parent\n"<br>
+ "directories of the source file (or current\n"<br>
+ "directory for stdin)."),<br>
+ cl::init("LLVM"), cl::cat(ClangFormatCategory));<br>
static cl::opt<bool> Inplace("i",<br>
- cl::desc("Inplace edit <file>s, if specified."));<br>
+ cl::desc("Inplace edit <file>s, if specified."),<br>
+ cl::cat(ClangFormatCategory));<br>
<br>
-static cl::opt<bool> OutputXML(<br>
- "output-replacements-xml", cl::desc("Output replacements as XML."));<br>
+static cl::opt<bool> OutputXML("output-replacements-xml",<br>
+ cl::desc("Output replacements as XML."),<br>
+ cl::cat(ClangFormatCategory));<br>
static cl::opt<bool><br>
DumpConfig("dump-config",<br>
- cl::desc("Dump configuration options to stdout and exit. Can be used with -style option."));<br>
+ cl::desc("Dump configuration options to stdout and exit.\n"<br>
+ "Can be used with -style option."),<br>
+ cl::cat(ClangFormatCategory));<br>
<br>
-static cl::list<std::string> FileNames(cl::Positional,<br>
- cl::desc("[<file> ...]"));<br>
+static cl::list<std::string> FileNames(cl::Positional, cl::desc("[<file> ...]"),<br>
+ cl::cat(ClangFormatCategory));<br>
<br>
namespace clang {<br>
namespace format {<br>
@@ -196,6 +210,17 @@ static bool format(std::string FileName)<br>
<br>
int main(int argc, const char **argv) {<br>
llvm::sys::PrintStackTraceOnErrorSignal();<br>
+<br>
+ // Hide unrelated options.<br>
+ StringMap<cl::Option*> Options;<br>
+ cl::getRegisteredOptions(Options);<br>
+ for (StringMap<cl::Option *>::iterator I = Options.begin(), E = Options.end();<br>
+ I != E; ++I) {<br>
+ if (I->second->Category != &ClangFormatCategory && I->first() != "help" &&<br>
+ I->first() != "version")<br>
+ I->second->setHiddenFlag(cl::ReallyHidden);<br>
+ }<br>
+<br>
cl::ParseCommandLineOptions(<br>
argc, argv,<br>
"A tool to format C/C++/Obj-C code.\n\n"<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div></div></div><br></div></div>
</blockquote></div><br></div>
</blockquote></div>