diff options
author | Hans Wennborg <hans@hanshq.net> | 2013-09-10 15:41:12 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2013-09-10 15:41:12 +0000 |
commit | 9a7a50eef777765e4d20e3b1f3670b32582114fb (patch) | |
tree | 65ffa709a3a39fce2c7bf0dfe72e59d2bd368dc6 /tools/clang-format | |
parent | daa07e9ee76d438efa3c7e2c54b4d3d3ed19ea27 (diff) | |
download | clang-9a7a50eef777765e4d20e3b1f3670b32582114fb.tar.gz clang-9a7a50eef777765e4d20e3b1f3670b32582114fb.tar.bz2 clang-9a7a50eef777765e4d20e3b1f3670b32582114fb.tar.xz |
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
Diffstat (limited to 'tools/clang-format')
-rw-r--r-- | tools/clang-format/ClangFormat.cpp | 10 | ||||
-rw-r--r-- | tools/clang-format/clang-format-sublime.py | 3 | ||||
-rw-r--r-- | tools/clang-format/clang-format.py | 3 |
3 files changed, 14 insertions, 2 deletions
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<MemoryBuffer> 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. |