uncrustify / uncrustify

Code beautifier
http://uncrustify.sourceforge.net/
GNU General Public License v2.0
2.85k stars 566 forks source link

Disable formatting inside macro #1654

Open Leandros opened 6 years ago

Leandros commented 6 years ago

I have a macro which disables warnings, and contains the warning flags for several compilers. These flags might contain a dash, and with the option to force a space between dashes uncrustify adds a dash and breaks the functionality.

Example:

DISABLE_WARNING(switch-enum, switch-enum, 4444)

and uncrustify would transform this into:

DISABLE_WARNING(switch - enum, switch - enum, 4444)

making it invalid.

Is there a way to disable formatting inside macros?

Version: Uncrustify-0.66.1

guy-maurel commented 6 years ago

You might need:

// *INDENT-OFF*
DISABLE_WARNING(switch-enum, switch-enum, 4444)
// *INDENT-ON*
Leandros commented 6 years ago

That works, but is very tedious, and turns 2 lines to disable a warning into 6. Macros can often contain text, which is not exactly source code, and might want to be avoided to be touched by uncrustify. My DISABLE_WARNING was just a nice example.

mihaipopescu commented 6 years ago

You could use something like set CT_IGNORE DISABLE_WARNING but probably with another token that supports functions.

On the other hand, always try to enforce semicolons for all of your macros as a best practice. Uncrustify as a number of editors will get confused to parse those, but if they look like a function then it won't be a problem.

guy-maurel commented 6 years ago

May we close?

CDanU commented 6 years ago

I think this is a reasonable request, I had attempted to implement something similar here: #1460 but it was still buggy