How to mark a region so clang-format won't touch it?
C++Clang FormatC++ 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)