samedi 3 juin 2023

How to configure .clang-format to skip formatting lines starting with certain strings like LOGGING_INFO in C++11?

I don't want clang-format to format the code starts with LOGGING_INFO. My expect format is:

LOGGING_INFO(LOGGING_TYPE, "some strings" LOGGING_PRAMS(PARAM_TYPE0, variable0,
                                                        PARAM_TYPE1, variable1));

But if I enable the clang-format for this part. It will be formatted as:

LOGGING_INFO(LOGGING_TYPE, "some strings" LOGGING_PRAMS(PARAM_TYPE0, 
                                                        variable0,
                                                        PARAM_TYPE1,
                                                        variable1));

OR

LOGGING_INFO(LOGGING_TYPE, 
             "some strings" LOGGING_PRAMS(PARAM_TYPE0, variable0, PARAM_TYPE1, variable1));

I can use // clang-format to disable the format of the code, but so it is too much effort because it is used very frequently in my code.

What I expect is to find any method to tell the clang-format that when met the code starts with LOGGINF_INFO, the auto format will disable it.

For example, any regular expression written in the .clang-format to achieve the goals.

Aucun commentaire:

Enregistrer un commentaire