summaryrefslogtreecommitdiffstats
path: root/clang/tools/clang-format
diff options
context:
space:
mode:
Diffstat (limited to 'clang/tools/clang-format')
-rw-r--r--clang/tools/clang-format/ClangFormat.cpp14
-rw-r--r--clang/tools/clang-format/clang-format-sublime.py7
-rw-r--r--clang/tools/clang-format/clang-format.el2
-rw-r--r--clang/tools/clang-format/clang-format.py7
4 files changed, 16 insertions, 14 deletions
diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp
index faf96fdf784..b76504db1d6 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -27,8 +27,8 @@
using namespace llvm;
-// Default style to use when no style specified or specified style not found.
-static const char *DefaultStyle = "LLVM";
+// Fallback style when no style specified or found in a .clang-format file.
+static const char FallbackStyle[] = "LLVM";
static cl::opt<bool> Help("h", cl::desc("Alias for -help"), cl::Hidden);
@@ -72,7 +72,7 @@ static cl::opt<std::string>
"Use -style=\"{key: value, ...}\" to set specific\n"
"parameters, e.g.:\n"
" -style=\"{BasedOnStyle: llvm, IndentWidth: 8}\""),
- cl::init(DefaultStyle), cl::cat(ClangFormatCategory));
+ cl::init("file"), cl::cat(ClangFormatCategory));
static cl::opt<bool> Inplace("i",
cl::desc("Inplace edit <file>s, if specified."),
cl::cat(ClangFormatCategory));
@@ -108,20 +108,20 @@ static FileID createInMemoryFile(StringRef FileName, const MemoryBuffer *Source,
FormatStyle getStyle(StringRef StyleName, StringRef FileName) {
FormatStyle Style;
- getPredefinedStyle(DefaultStyle, &Style);
+ getPredefinedStyle(FallbackStyle, &Style);
if (StyleName.startswith("{")) {
// Parse YAML/JSON style from the command line.
if (error_code ec = parseConfiguration(StyleName, &Style)) {
llvm::errs() << "Error parsing -style: " << ec.message()
- << ", using " << DefaultStyle << " style\n";
+ << ", using " << FallbackStyle << " style\n";
}
return Style;
}
if (!StyleName.equals_lower("file")) {
if (!getPredefinedStyle(StyleName, &Style))
- llvm::errs() << "Invalid value for -style, using " << DefaultStyle
+ llvm::errs() << "Invalid value for -style, using " << FallbackStyle
<< " style\n";
return Style;
}
@@ -153,7 +153,7 @@ FormatStyle getStyle(StringRef StyleName, StringRef FileName) {
return Style;
}
}
- llvm::errs() << "Can't find usable .clang-format, using " << DefaultStyle
+ llvm::errs() << "Can't find usable .clang-format, using " << FallbackStyle
<< " style\n";
return Style;
}
diff --git a/clang/tools/clang-format/clang-format-sublime.py b/clang/tools/clang-format/clang-format-sublime.py
index d41404ed0f5..73ff3dc8239 100644
--- a/clang/tools/clang-format/clang-format-sublime.py
+++ b/clang/tools/clang-format/clang-format-sublime.py
@@ -19,9 +19,10 @@ import subprocess
# Change this to the full path if clang-format is not on the path.
binary = 'clang-format'
-# Change this to format according to other formatting styles
-# (see clang-format -help).
-style = 'LLVM'
+# Change this to format according to other formatting styles. See the output of
+# 'clang-format --help' for a list of supported styles. The default looks for
+# a '.clang-format' file to indicate the style that should be used.
+style = 'file'
class ClangFormatCommand(sublime_plugin.TextCommand):
def run(self, edit):
diff --git a/clang/tools/clang-format/clang-format.el b/clang/tools/clang-format/clang-format.el
index b0131ed3194..531635e8ecf 100644
--- a/clang/tools/clang-format/clang-format.el
+++ b/clang/tools/clang-format/clang-format.el
@@ -36,7 +36,7 @@
(let* ((orig-windows (get-buffer-window-list (current-buffer)))
(orig-window-starts (mapcar #'window-start orig-windows))
(orig-point (point))
- (style "LLVM"))
+ (style "file"))
(unwind-protect
(call-process-region (point-min) (point-max) clang-format-binary t t nil
"-offset" (number-to-string (1- begin))
diff --git a/clang/tools/clang-format/clang-format.py b/clang/tools/clang-format/clang-format.py
index 1d27985ea08..4077b4180cf 100644
--- a/clang/tools/clang-format/clang-format.py
+++ b/clang/tools/clang-format/clang-format.py
@@ -26,9 +26,10 @@ import vim
# Change this to the full path if clang-format is not on the path.
binary = 'clang-format'
-# Change this to format according to other formatting styles (see
-# clang-format -help)
-style = 'LLVM'
+# Change this to format according to other formatting styles. See the output of
+# 'clang-format --help' for a list of supported styles. The default looks for
+# a '.clang-format' file to indicate the style that should be used.
+style = 'file'
# Get the current text.
buf = vim.current.buffer
OpenPOWER on IntegriCloud