Index: lib/Format/BreakableToken.cpp =================================================================== --- lib/Format/BreakableToken.cpp +++ lib/Format/BreakableToken.cpp @@ -298,8 +298,9 @@ static bool mayReflowContent(StringRef Content) { Content = Content.trim(Blanks); // Lines starting with '@' commonly have special meaning. - static const SmallVector kSpecialMeaningPrefixes = { - "@", "TODO", "FIXME", "XXX"}; + // Lines starting with '-', '-#', '+' or '*' are bulleted/numbered lists. + static const SmallVector kSpecialMeaningPrefixes = { + "@", "TODO", "FIXME", "XXX", "-# ", "- ", "+ ", "* " }; bool hasSpecialMeaningPrefix = false; for (StringRef Prefix : kSpecialMeaningPrefixes) { if (Content.startswith(Prefix)) { @@ -307,6 +308,12 @@ break; } } + + // Numbered lists may also start with a number followed by '.' + static llvm::Regex kNumberedListRegexp = llvm::Regex("^[1-9][0-9]*\\. "); + hasSpecialMeaningPrefix = hasSpecialMeaningPrefix || + kNumberedListRegexp.match(Content); + // Simple heuristic for what to reflow: content should contain at least two // characters and either the first or second character must be // non-punctuation. Index: unittests/Format/FormatTestComments.cpp =================================================================== --- unittests/Format/FormatTestComments.cpp +++ unittests/Format/FormatTestComments.cpp @@ -1534,7 +1534,7 @@ " *\n" " * long */", getLLVMStyleWithColumns(20))); - + // Don't reflow lines having content that is a single character. EXPECT_EQ("// long long long\n" "// long\n" @@ -1559,7 +1559,7 @@ format("// long long long long\n" "// @param arg", getLLVMStyleWithColumns(20))); - + // Don't reflow lines starting with 'TODO'. EXPECT_EQ("// long long long\n" "// long\n" @@ -1628,6 +1628,54 @@ "// long", getLLVMStyleWithColumns(20))); + // Don't reflow separate bullets in list + EXPECT_EQ("// - long long long\n" + "// long\n" + "// - long", + format("// - long long long long\n" + "// - long", + getLLVMStyleWithColumns(20))); + EXPECT_EQ("// * long long long\n" + "// long\n" + "// * long", + format("// * long long long long\n" + "// * long", + getLLVMStyleWithColumns(20))); + EXPECT_EQ("// + long long long\n" + "// long\n" + "// + long", + format("// + long long long long\n" + "// + long", + getLLVMStyleWithColumns(20))); + EXPECT_EQ("// 1. long long long\n" + "// long\n" + "// 2. long", + format("// 1. long long long long\n" + "// 2. long", + getLLVMStyleWithColumns(20))); + EXPECT_EQ("// -# long long long\n" + "// long\n" + "// -# long", + format("// -# long long long long\n" + "// -# long", + getLLVMStyleWithColumns(20))); + + EXPECT_EQ("// - long long long\n" + "// long long long\n" + "// - long", + format("// - long long long long\n" + "// long long\n" + "// - long", + getLLVMStyleWithColumns(20))); + EXPECT_EQ("// - long long long\n" + "// long long long\n" + "// long\n" + "// - long", + format("// - long long long long\n" + "// long long long\n" + "// - long", + getLLVMStyleWithColumns(20))); + // Don't break or reflow after implicit string literals. verifyFormat("#include // l l l\n" " // l",