[clang] [clang-format] Allow specifying the language for `.h` files (PR #128122)

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 20 23:22:46 PST 2025


owenca wrote:

> a bit old school..
> 
> ```
> /* -*- Mode: C++; -*- */
> /* -*- Mode: C; -*- */
> /* -*- Mode: objc; -*- */
> ```

We support the following now:
```cpp
// clang-format off
// clang-format off: reason
// clang-format on
// clang-format on: reason
/* clang-format off */
/* clang-format on */
```
and in configuration:
```
Language: Cpp
Language: ObjC
# After adding LK_C:
# Language: C
```
So to make it simple and consistent, I chose `// clang-format Language: ObjC`, etc. IMO, we must include `// clang-format` as a prefix in order to not interfere with comment directives from other tools like clang-tidy and lint.

https://github.com/llvm/llvm-project/pull/128122


More information about the cfe-commits mailing list