From 9a7a50eef777765e4d20e3b1f3670b32582114fb Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Tue, 10 Sep 2013 15:41:12 +0000 Subject: Allow _clang-format as alternative to .clang-format config filename Dotfiles are impractical on Windows. This makes clang-format search for the style configuration file as '_clang-format' in addition to the usual '.clang-format'. This is similar to how VIM searches for '_vimrc' on Windows. Differential Revision: http://llvm-reviews.chandlerc.com/D1629 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190413 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/clang-format/ClangFormat.cpp | 10 ++++++++++ tools/clang-format/clang-format-sublime.py | 3 ++- tools/clang-format/clang-format.py | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) (limited to 'tools/clang-format') diff --git a/tools/clang-format/ClangFormat.cpp b/tools/clang-format/ClangFormat.cpp index 2d415b358f..592d46a530 100644 --- a/tools/clang-format/ClangFormat.cpp +++ b/tools/clang-format/ClangFormat.cpp @@ -132,12 +132,22 @@ FormatStyle getStyle(StringRef StyleName, StringRef FileName) { !Directory.empty(); Directory = llvm::sys::path::parent_path(Directory)) { SmallString<128> ConfigFile(Directory); + llvm::sys::path::append(ConfigFile, ".clang-format"); DEBUG(llvm::dbgs() << "Trying " << ConfigFile << "...\n"); bool IsFile = false; // Ignore errors from is_regular_file: we only need to know if we can read // the file or not. llvm::sys::fs::is_regular_file(Twine(ConfigFile), IsFile); + + if (!IsFile) { + // Try _clang-format too, since dotfiles are not commonly used on Windows. + ConfigFile = Directory; + llvm::sys::path::append(ConfigFile, "_clang-format"); + DEBUG(llvm::dbgs() << "Trying " << ConfigFile << "...\n"); + llvm::sys::fs::is_regular_file(Twine(ConfigFile), IsFile); + } + if (IsFile) { OwningPtr Text; if (error_code ec = MemoryBuffer::getFile(ConfigFile, Text)) { diff --git a/tools/clang-format/clang-format-sublime.py b/tools/clang-format/clang-format-sublime.py index 73ff3dc823..78c8939c1b 100644 --- a/tools/clang-format/clang-format-sublime.py +++ b/tools/clang-format/clang-format-sublime.py @@ -21,7 +21,8 @@ binary = 'clang-format' # 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. +# a '.clang-format' or '_clang-format' file to indicate the style that should be +# used. style = 'file' class ClangFormatCommand(sublime_plugin.TextCommand): diff --git a/tools/clang-format/clang-format.py b/tools/clang-format/clang-format.py index 4077b4180c..d8338ab4da 100644 --- a/tools/clang-format/clang-format.py +++ b/tools/clang-format/clang-format.py @@ -28,7 +28,8 @@ binary = 'clang-format' # 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. +# a '.clang-format' or '_clang-format' file to indicate the style that should be +# used. style = 'file' # Get the current text. -- cgit v1.2.3