[PATCH] D68569: [clang-format] Also look for .{ext}.clang-format file
Anders Waldenborg via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 7 04:10:11 PDT 2019
wanders created this revision.
wanders added a reviewer: clang-format.
wanders added a project: clang-format.
Herald added a project: clang.
E.g: When formatting foo.cpp it will look for .cpp.clang-format
This makes it easy to different formatting for .c/.h files and
.cpp/.hpp files within the same directories.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D68569
Files:
clang/docs/ClangFormat.rst
clang/lib/Format/Format.cpp
Index: clang/lib/Format/Format.cpp
===================================================================
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2601,6 +2601,11 @@
return make_string_error(EC.message());
llvm::SmallVector<std::string, 2> 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");
Index: clang/docs/ClangFormat.rst
===================================================================
--- clang/docs/ClangFormat.rst
+++ 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:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68569.223491.patch
Type: text/x-patch
Size: 1404 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191007/fb9e5657/attachment-0001.bin>
More information about the cfe-commits
mailing list