How to mark a region so clang-format won't touch it?

C++Clang Format

C++ Problem Overview


For example, in the MySQL++ library there are macros that can be used to define simple structs based on sql table definition, like this:

sql_create_6(stock, 1, 6,
    mysqlpp::sql_char, item,
    mysqlpp::sql_bigint, num,
    mysqlpp::sql_double, weight,
    mysqlpp::sql_decimal, price,
    mysqlpp::sql_date, sdate,
    mysqlpp::Null<mysqlpp::sql_mediumtext>, description)

The problem is that clang-format will reformat this in a way that is much more difficult to read (every param on a new line). Most code formatters can recognize special format-off / format-on comments, but I haven't found anything like that in the clang-format manual.

C++ Solutions


Solution 1 - C++

In newer version, you can surround a section of code with:

// clang-format off
...
// clang-format on

Solution 2 - C++

Try adding a // comment marker after each line, this may do it. I had the same issue in Eclipse and learned this trick.

sql_create_6(stock, 1, 6, //
    mysqlpp::sql_char, item, //
    mysqlpp::sql_bigint, num, //
    mysqlpp::sql_double, weight, //
    mysqlpp::sql_decimal, price, //
    mysqlpp::sql_date, sdate, //
    mysqlpp::Null<mysqlpp::sql_mediumtext>, description)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlexView Question on Stackoverflow
Solution 1 - C++djasperView Answer on Stackoverflow
Solution 2 - C++vsoftcoView Answer on Stackoverflow