I have text file with c++ code fragments and I want to format only these fragments. I'm trying to use clang-format on/off for these purposes. Example of text file:
// clang-format on
for(const auto& element: elements){if(element > 0){element++;}}
// clang-format off
some text
// clang-format on
for(const auto& element: elements){if(element > 0){element++;}}
// clang-format off
some text
and after clang-format i have:
// clang-format on
for(const auto& element: elements)
{
if(element > 0)
{
element++;
}
}
// clang-format off
some text
// clang-format on <---------------
for(const auto& element: elements) <---------------
{
if(element > 0)
{
element++;
}
}
// clang-format off
some text
if there is no any text before '// clang-format on' formatting is good, but if there is some text before - first lines have additional shift to the right.
How can I resolve this issue?