简体   繁体   English

如何折叠所有不会在Visual Studio中编译的#ifdef块?

[英]How to collapse all blocks of #ifdefs that will not be compiled in Visual Studio?

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. 问题如下:代码库使用#if define(...)指令为每个目标平台有条件地编译了带有多个块的文件。 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. 由于典型的程序员主要在一种平台上工作,因此即使这些代码块在Visual Studio 2005编辑器中显示为灰色,也很难使用这些大块的非活动代码块来阅读和导航代码。

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. 让某人对仅折叠未编译但仍存在于源文件中的代码块的功能有所了解。

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. 也就是说,您可以做的是更改呈现不活动的预处理器文本的方式(至少在VS2012上如此),这样可以减少干扰,并使得实际编译的代码更易于阅读。

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. 默认值为65,但是如果您使用深色主题,我发现30效果更好。

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) 您还可以使用Visual Studio 2012颜色主题编辑器进一步调整颜色,以进一步提高可读性(例如,如果您更喜欢Sublime Text呈现代码的方式)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 折叠Visual Studio中的所有非活动预处理程序块 - Collapse all inactive preprocessor blocks in Visual Studio 我可以在Visual Studio 2012中以编程方式折叠/展开某个名称的所有预处理器块吗? - Can I programmatically collapse/expand all preprocessor blocks of a certain name in Visual Studio 2012? 突出显示所有@块的视觉工作室 - visual studio highlighting all @ blocks 如何使用Visual Studio 2017折叠代码的所有部分? - How to I collapse all sections of code with Visual Studio 2017? 如何将 Visual Studio 配置为默认折叠所有区域? - How to configure Visual Studio to collapse all regions by default? 以编程方式折叠来自 Visual Studio 扩展的源代码块 - Programmatically collapse source code blocks from a Visual Studio extension Visual Studio - 折叠代码的所有部分的首选项? - Visual Studio - Preference to collapse all sections of code? 宏在解决方案 Visual Studio 2010 中全部折叠 - macro collapse all in solution visual studio 2010 折叠所有Visual Studio工具箱区域快捷方式 - Collapse all Visual Studio toolbox regions shortcut 如何使用Visual Studio 2008扩展或折叠项目中的所有区域? - How do I expand or collapse all the regions in a project using Visual Studio 2008?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM