summaryrefslogtreecommitdiffstats
path: root/tools/clang-format
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2015-11-16 12:38:56 +0000
committerDaniel Jasper <djasper@google.com>2015-11-16 12:38:56 +0000
commitd27c92ca6f5fcafbe4c63f6e2bc440f0e86f881a (patch)
treead657c37d39a5754cb449d192ced2ad553085e3e /tools/clang-format
parent09adec2e3ceb8b9a953d543ae049870e6570b579 (diff)
clang-format: Enable #include sorting by default.
This has seen quite some usage and I am not aware of any issues. Also add a style option to enable/disable include sorting. The existing command line flag can from now on be used to override whatever is set in the style. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253202 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/clang-format')
-rw-r--r--tools/clang-format/ClangFormat.cpp27
-rw-r--r--tools/clang-format/clang-format-sublime.py2
-rw-r--r--tools/clang-format/clang-format.el1
-rw-r--r--tools/clang-format/clang-format.py2
4 files changed, 15 insertions, 17 deletions
diff --git a/tools/clang-format/ClangFormat.cpp b/tools/clang-format/ClangFormat.cpp
index 7cdb823f36..43eded20fa 100644
--- a/tools/clang-format/ClangFormat.cpp
+++ b/tools/clang-format/ClangFormat.cpp
@@ -98,9 +98,11 @@ static cl::opt<unsigned>
"clang-format from an editor integration"),
cl::init(0), cl::cat(ClangFormatCategory));
-static cl::opt<bool> SortIncludes("sort-includes",
- cl::desc("Sort touched include lines"),
- cl::cat(ClangFormatCategory));
+static cl::opt<bool> SortIncludes(
+ "sort-includes",
+ cl::desc("If set, overrides the include sorting behavior determined by the "
+ "SortIncludes style flag"),
+ cl::cat(ClangFormatCategory));
static cl::list<std::string> FileNames(cl::Positional, cl::desc("[<file> ...]"),
cl::cat(ClangFormatCategory));
@@ -252,17 +254,14 @@ static bool format(StringRef FileName) {
return true;
StringRef AssumedFileName = (FileName == "-") ? AssumeFileName : FileName;
FormatStyle FormatStyle = getStyle(Style, AssumedFileName, FallbackStyle);
- Replacements Replaces;
- std::string ChangedCode;
- if (SortIncludes) {
- Replaces =
- sortIncludes(FormatStyle, Code->getBuffer(), Ranges, AssumedFileName);
- ChangedCode = tooling::applyAllReplacements(Code->getBuffer(), Replaces);
- for (const auto &R : Replaces)
- Ranges.push_back({R.getOffset(), R.getLength()});
- } else {
- ChangedCode = Code->getBuffer().str();
- }
+ if (SortIncludes.getNumOccurrences() != 0)
+ FormatStyle.SortIncludes = SortIncludes;
+ Replacements Replaces =
+ sortIncludes(FormatStyle, Code->getBuffer(), Ranges, AssumedFileName);
+ std::string ChangedCode =
+ tooling::applyAllReplacements(Code->getBuffer(), Replaces);
+ for (const auto &R : Replaces)
+ Ranges.push_back({R.getOffset(), R.getLength()});
bool IncompleteFormat = false;
Replaces = tooling::mergeReplacements(
diff --git a/tools/clang-format/clang-format-sublime.py b/tools/clang-format/clang-format-sublime.py
index 1cffcecc39..16ff56e502 100644
--- a/tools/clang-format/clang-format-sublime.py
+++ b/tools/clang-format/clang-format-sublime.py
@@ -32,7 +32,7 @@ class ClangFormatCommand(sublime_plugin.TextCommand):
if encoding == 'Undefined':
encoding = 'utf-8'
regions = []
- command = [binary, '-sort-includes', '-style', style]
+ command = [binary, '-style', style]
for region in self.view.sel():
regions.append(region)
region_offset = min(region.a, region.b)
diff --git a/tools/clang-format/clang-format.el b/tools/clang-format/clang-format.el
index 6de45de70a..ca461444e2 100644
--- a/tools/clang-format/clang-format.el
+++ b/tools/clang-format/clang-format.el
@@ -126,7 +126,6 @@ is no active region. If no style is given uses `clang-format-style'."
nil `(,temp-buffer ,temp-file) nil
"-output-replacements-xml"
- "-sort-includes"
"-assume-filename" (or (buffer-file-name) "")
"-style" style
"-offset" (number-to-string start)
diff --git a/tools/clang-format/clang-format.py b/tools/clang-format/clang-format.py
index 1725e8659a..5cb41fcfa3 100644
--- a/tools/clang-format/clang-format.py
+++ b/tools/clang-format/clang-format.py
@@ -72,7 +72,7 @@ def main():
startupinfo.wShowWindow = subprocess.SW_HIDE
# Call formatter.
- command = [binary, '-style', style, '-cursor', str(cursor), '-sort-includes']
+ command = [binary, '-style', style, '-cursor', str(cursor)]
if lines != 'all':
command.extend(['-lines', lines])
if fallback_style: