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

Alex picture Alex · Jul 26, 2014 · Viewed 14.4k times · Source

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.

Answer

djasper picture djasper · Sep 3, 2014

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

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