How to collapse all blocks of #ifdefs that will not be compiled in Visual Studio?
Asked Answered
E

1

8

The problem is the following: the codebase have many files with multiple blocks compiled conditionally for each of target platforms using the #if defined(...) directive. Since the typical programmer is working mainly on one of the platforms it is quite hard to read and navigate the code with these large blocks of inactive code blocks even if the code blocks are greyed out in the Visual Studio 2005 editor.

Have someone have an idea of a functionality for collapsing only the blocks of code which are not compiled but still present in the source file.

Egghead answered 16/6, 2010 at 12:11 Comment(0)
T
4

As far as I know, you cannot collapse inactive pre-processor regions by default and there doesn't seem to be an extension that provides the functionality.

That said, what you can do is change how inactive pre-processor text is rendered (at least on VS2012), so it is less distracting and so that the code that is actually compiled is easier to read.

Try these settings:

Tools > Options > Text Editor > C/C++ > Formatting:
Show Inactive Blocks : true
Disable Inactive Code Opacity : false
Inactive Code Opacity Percent: 30 

The default is 65, but I find 30 works better if you use the dark theme.

You can also further tweak the colours with the Visual Studio 2012 Color Theme Editor, to further increase readability (for example, if you prefer the way Sublime Text renders your code)

Tavish answered 14/10, 2013 at 22:27 Comment(1)
@foobar: Yes it is. It's under View instead of Formatting.Lisettelisha

© 2022 - 2024 — McMap. All rights reserved.