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:
 


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:
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to