Collapse all inactive preprocessor blocks in Visual Studio
Asked Answered
G

1

13

I am working with some third-party code that has a lot of conditional macros. Visual Studio is quite good at detecting the inactive code, i.e. code wrapped in #if...#endif that won't be compiled and I can manually collapse these individually.

I would like to hide the inactive blocks automatically - all of them. Is this possible?

EDIT: is this possible with VS2012? May be a reason to upgrade.

Gastronomy answered 1/2, 2012 at 10:39 Comment(3)
#983177Yowl
@Yowl Not the same question. There is an element of seductiveness to this question, the one linked is a solution to collapse all, regardless of whether or not the block is activeEwe
I feel like this is a well-formed question. Sad to see the responses from 2012 seem to be off the understanding. I would guess it's not possible without making a new VS extension.Ewe
C
2

I am not aware of a way to automatically collapse, but there is definitely a setting to hide inactive blocks.

The setting is under Tools->Options->Text Editor->C/C++->View

From there, just change "Show Inactive Blocks" to False.

Screen capture of C++ settings for Visual studio Editor

Corundum answered 23/9, 2016 at 4:30 Comment(2)
If you set this to true, you can have inactive blocks be colored differently, like opacity 10. Setting this to False will make no difference whatsoever. ;)Shonda
gulgi is right. The setting "Show Inactive Blocks" is really controlling the question "Should blocks of Inactive Code be shown differently from active code so that you can see that they are Inactive Blocks?" If it is changed to False, then the opacity options for Inactive Code are grayed out and the Inactive Code will be shown in the same way as active code.Hobie

© 2022 - 2024 — McMap. All rights reserved.