How to mark a region so that clang-format does not touch it?

For example, the MySQL ++ library has macros that can be used to define simple structures based on the definition of the sql table, for example:

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 it in a way that is much harder to read (each parameter on a new line). Most code formatters can recognize special off-format / format-on comments, but I haven't found anything like this in the clang format guide.

+7
c ++ clang-format
source share
2 answers

In a newer version, you can merge a section of code with

 // clang-format off ... // clang-format on 
+9
source share

Try adding a comment marker // after each line, this can do it. I had the same problem in Eclipse and I found out about it.

 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) 
+2
source share

All Articles