[PATCH] D127484: [clang-format] Use tabs on GNU style
a4lg updated this revision to Diff 436087. a4lg added a comment. Thanks, suggestion by @owenpan is applied. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D127484/new/ https://reviews.llvm.org/D127484 Files: clang/lib/Format/Format.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -23944,6 +23944,18 @@ " int foo ();\n" "}", Style); + verifyFormat("void\n" + "foo ()\n" + "{\n" + " for (int i = 0; i < 5; i++)\n" + "{\n" + " for (int j = 0; j < 5; j++)\n" + "\t{\n" + "\t bar ();\n" + "\t}\n" + "}\n" + "}", + Style); } TEST_F(FormatTest, MozillaDefaultStyle) { FormatStyle Style = getMozillaStyle(); Index: clang/lib/Format/Format.cpp === --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -1616,6 +1616,7 @@ Style.FixNamespaceComments = false; Style.SpaceBeforeParens = FormatStyle::SBPO_Always; Style.Standard = FormatStyle::LS_Cpp03; + Style.UseTab = FormatStyle::UT_ForContinuationAndIndentation; return Style; } Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -23944,6 +23944,18 @@ " int foo ();\n" "}", Style); + verifyFormat("void\n" + "foo ()\n" + "{\n" + " for (int i = 0; i < 5; i++)\n" + "{\n" + " for (int j = 0; j < 5; j++)\n" + "\t{\n" + "\t bar ();\n" + "\t}\n" + "}\n" + "}", + Style); } TEST_F(FormatTest, MozillaDefaultStyle) { FormatStyle Style = getMozillaStyle(); Index: clang/lib/Format/Format.cpp === --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -1616,6 +1616,7 @@ Style.FixNamespaceComments = false; Style.SpaceBeforeParens = FormatStyle::SBPO_Always; Style.Standard = FormatStyle::LS_Cpp03; + Style.UseTab = FormatStyle::UT_ForContinuationAndIndentation; return Style; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D127484: [clang-format] Use tabs on GNU style
a4lg marked an inline comment as done. a4lg added a comment. Interesting. I measured some development branch (targeting `*.c`, `*.cc`, `*.cpp` and `*.h`): | Program | prefix: 8 spaces | prefix: 1 tab | 8sp percentage | | Coreutils | 23494| 461 | 98.08% | | Binutils | 128781 | 745992| 14.72% | | GCC | 155080 | 1156554 | 11.82% | | That's completely different from Coreutils (and that's why I submitted this patch because I'm a Binutils contributor). Yes, there's definitely a reason to keep this style in clang-format. In this case, following .clang-format file will work: BasedOnStyle: GNU UseTab: ForContinuationAndIndentation or following style setting on Visual Studio Code (not as JSON but a string): { BasedOnStyle: GNU, UseTab: ForContinuationAndIndentation } Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D127484/new/ https://reviews.llvm.org/D127484 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D127484: [clang-format] Use tabs on GNU style
a4lg created this revision. Herald added a project: All. a4lg requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. On default configuration of GNU Indent, it uses 8-width tabs. Because GNU Indent's indentation works like UT_ForContinuationAndIndentation in clang-format, this commit replaces UseTab value from UT_Never to it. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D127484 Files: clang/lib/Format/Format.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -23944,6 +23944,18 @@ " int foo ();\n" "}", Style); + verifyFormat("void\n" + "foo ()\n" + "{\n" + " for (int i = 0; i < 5; i++)\n" + "{\n" + " for (int j = 0; j < 5; j++)\n" + "\t{\n" + "\t printf (\"%d, %d\\n\", i, j);\n" + "\t}\n" + "}\n" + "}", + Style); } TEST_F(FormatTest, MozillaDefaultStyle) { FormatStyle Style = getMozillaStyle(); Index: clang/lib/Format/Format.cpp === --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -1616,6 +1616,7 @@ Style.FixNamespaceComments = false; Style.SpaceBeforeParens = FormatStyle::SBPO_Always; Style.Standard = FormatStyle::LS_Cpp03; + Style.UseTab = FormatStyle::UT_ForContinuationAndIndentation; return Style; } Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -23944,6 +23944,18 @@ " int foo ();\n" "}", Style); + verifyFormat("void\n" + "foo ()\n" + "{\n" + " for (int i = 0; i < 5; i++)\n" + "{\n" + " for (int j = 0; j < 5; j++)\n" + "\t{\n" + "\t printf (\"%d, %d\\n\", i, j);\n" + "\t}\n" + "}\n" + "}", + Style); } TEST_F(FormatTest, MozillaDefaultStyle) { FormatStyle Style = getMozillaStyle(); Index: clang/lib/Format/Format.cpp === --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -1616,6 +1616,7 @@ Style.FixNamespaceComments = false; Style.SpaceBeforeParens = FormatStyle::SBPO_Always; Style.Standard = FormatStyle::LS_Cpp03; + Style.UseTab = FormatStyle::UT_ForContinuationAndIndentation; return Style; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits