diff --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst --- a/clang/docs/ClangFormat.rst +++ b/clang/docs/ClangFormat.rst @@ -82,8 +82,10 @@ When the desired code formatting style is different from the available options, the style can be customized using the ``-style="{key: value, ...}"`` option or -by putting your style configuration in the ``.clang-format`` or ``_clang-format`` -file in your project's directory and using ``clang-format -style=file``. +by putting your style configuration a file named ``.{ext}.clang-format`` (``{ext}`` +is the file name extension, e.g. ``.cpp.clang-format`` is the formatted file +is named ``something.cpp``), ``.clang-format`` or ``_clang-format`` in your +project's directory and using ``clang-format -style=file``. An easy way to create the ``.clang-format`` file is: diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -2601,6 +2601,11 @@ return make_string_error(EC.message()); llvm::SmallVector FilesToLookFor; + + auto Extension(llvm::sys::path::extension(FileName)); + if (Extension != "") { + FilesToLookFor.push_back((Extension + ".clang-format").str()); + } FilesToLookFor.push_back(".clang-format"); FilesToLookFor.push_back("_clang-format");