Reputation: 1403
I have a C and C++ code base which I format using clang format. I'd like to make my code easy to read by placing separators between functions in the following way:
//-----------------------------------------------------------------------------
void func1()
{
// body
}
//-----------------------------------------------------------------------------
void func2()
{
// body
}
//-----------------------------------------------------------------------------
void func3()
{
// body
}
Is there a way to automate the adding of this separator line automatically during formatting:
//-----------------------------------------------------------------------------
Upvotes: -1
Views: 355
Reputation: 3163
My team found these separators useful but hard to maintain in the actual code. We found a VSCode plugin that would render visual separators without us needing to manually add them everywhere. You might find this to be a different approach that achieves the same goal.
The plugin is open source if you want to tune it more than is currently possible.
Separators by Alessandro Fragnani
https://marketplace.visualstudio.com/items?itemName=alefragnani.separators
Upvotes: 0
Reputation: 39869
Based on the currently available style options, clang-format doesn't have a feature that would let you do that.
However, clang-format preserves comments, so you can manually insert the separators and they won't be reformatted or deleted. You can also add doc comments (see e.g. the LSST Stack) to your functions, which not only visually separates them, but also has uses beyond that.
If you still want this feature, you can either fork clang-format and implement it yourself, or you can request it by submitting an issue in the llvm-project repository.
Upvotes: 1