r189741 - Switch the default mode for clang-format to '-file'. Make 'LLVM' the
Daniel Jasper
djasper at google.com
Mon Sep 2 00:51:32 PDT 2013
I think we should make FallbackStyle a command line parameter. What do you
think?
On Mon, Sep 2, 2013 at 9:42 AM, Chandler Carruth <chandlerc at gmail.com>wrote:
> Author: chandlerc
> Date: Mon Sep 2 02:42:02 2013
> New Revision: 189741
>
> URL: http://llvm.org/viewvc/llvm-project?rev=189741&view=rev
> Log:
> Switch the default mode for clang-format to '-file'. Make 'LLVM' the
> fallback syntax used when we fail to find a '.clang-format' file. Adjust
> variable names appropriately.
>
> Update the editor integration pieces that specify a '-style' option to
> specify it as '-style=file'. I left the functionality in place because
> even if the preferred method is to use '.clang-format' files, this way
> if someone needs to clobber the style in their editor we show how to do
> so in these examples.
>
> Also check in a '.clang-format' file for Clang to ensure that separate
> checkouts and builds of Clang from LLVM can still get the nice
> formatting. =] This unfortunately required nuking the test for the
> absence of a '.clang-format' file as now the directory happening to be
> under your clang source tree will cause there to always be a file. ;]
>
> Added:
> cfe/trunk/.clang-format
> Modified:
> cfe/trunk/test/Format/style-on-command-line.cpp
> cfe/trunk/tools/clang-format/ClangFormat.cpp
> cfe/trunk/tools/clang-format/clang-format-sublime.py
> cfe/trunk/tools/clang-format/clang-format.el
> cfe/trunk/tools/clang-format/clang-format.py
>
> Added: cfe/trunk/.clang-format
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/.clang-format?rev=189741&view=auto
>
> ==============================================================================
> --- cfe/trunk/.clang-format (added)
> +++ cfe/trunk/.clang-format Mon Sep 2 02:42:02 2013
> @@ -0,0 +1 @@
> +BasedOnStyle: LLVM
>
> Modified: cfe/trunk/test/Format/style-on-command-line.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Format/style-on-command-line.cpp?rev=189741&r1=189740&r2=189741&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/Format/style-on-command-line.cpp (original)
> +++ cfe/trunk/test/Format/style-on-command-line.cpp Mon Sep 2 02:42:02
> 2013
> @@ -4,9 +4,8 @@
> // RUN: clang-format -style="{BasedOnStyle: invalid, IndentWidth: 7}"
> %t.cpp 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK3 %s
> // RUN: clang-format -style="{lsjd}" %t.cpp 2>&1 | FileCheck
> -strict-whitespace -check-prefix=CHECK4 %s
> // RUN: [ ! -e %T/.clang-format ] || rm %T/.clang-format
> -// RUN: clang-format -style=file %t.cpp 2>&1 | FileCheck
> -strict-whitespace -check-prefix=CHECK5 %s
> // RUN: printf "BasedOnStyle: google\nIndentWidth: 5\n" > %T/.clang-format
> -// RUN: clang-format -style=file %t.cpp 2>&1 | FileCheck
> -strict-whitespace -check-prefix=CHECK6 %s
> +// RUN: clang-format -style=file %t.cpp 2>&1 | FileCheck
> -strict-whitespace -check-prefix=CHECK5 %s
> void f() {
> // CHECK1: {{^ int\* i;$}}
> // CHECK2: {{^ int \*i;$}}
> @@ -15,9 +14,7 @@ void f() {
> // CHECK3: {{^ int \*i;$}}
> // CHECK4: Error parsing -style: Invalid argument, using LLVM style
> // CHECK4: {{^ int \*i;$}}
> -// CHECK5: Can't find usable .clang-format, using LLVM style
> -// CHECK5: {{^ int \*i;$}}
> -// CHECK6: {{^ int\* i;$}}
> +// CHECK5: {{^ int\* i;$}}
> int*i;
> int j;
> }
>
> Modified: cfe/trunk/tools/clang-format/ClangFormat.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=189741&r1=189740&r2=189741&view=diff
>
> ==============================================================================
> --- cfe/trunk/tools/clang-format/ClangFormat.cpp (original)
> +++ cfe/trunk/tools/clang-format/ClangFormat.cpp Mon Sep 2 02:42:02 2013
> @@ -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(StringR
>
> 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
> 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;
> }
>
> Modified: cfe/trunk/tools/clang-format/clang-format-sublime.py
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/clang-format-sublime.py?rev=189741&r1=189740&r2=189741&view=diff
>
> ==============================================================================
> --- cfe/trunk/tools/clang-format/clang-format-sublime.py (original)
> +++ cfe/trunk/tools/clang-format/clang-format-sublime.py Mon Sep 2
> 02:42:02 2013
> @@ -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):
>
> Modified: cfe/trunk/tools/clang-format/clang-format.el
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/clang-format.el?rev=189741&r1=189740&r2=189741&view=diff
>
> ==============================================================================
> --- cfe/trunk/tools/clang-format/clang-format.el (original)
> +++ cfe/trunk/tools/clang-format/clang-format.el Mon Sep 2 02:42:02 2013
> @@ -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))
>
> Modified: cfe/trunk/tools/clang-format/clang-format.py
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/clang-format.py?rev=189741&r1=189740&r2=189741&view=diff
>
> ==============================================================================
> --- cfe/trunk/tools/clang-format/clang-format.py (original)
> +++ cfe/trunk/tools/clang-format/clang-format.py Mon Sep 2 02:42:02 2013
> @@ -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
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130902/39e04b67/attachment.html>
More information about the cfe-commits
mailing list