格式化源时如何保留代码折叠 [英] How to preserve code folding when formatting source

查看:210
本文介绍了格式化源时如何保留代码折叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

另请参阅此问题:如何在调用代码格式化程序时避免展开折叠区域?

这不是骗局,因为我有兴趣使用ToolsApi解决问题。

This is not a dupe, because I'm interested in solving the problem using the ToolsApi.

当我按 CTRL + D 时,代码格式很好(主要是)

但我所有折叠的代码部分都展开了。

有没有办法让这些部分保持折叠状态。

When I press CTRL + D the code formats nicely (mostly).
But all my folded code sections get unfolded.
Is there a way to keep these sections folded.

如果没有,是否可以在格式化之前保存代码折叠信息,以便我以后可以恢复?

我在考虑使用Open Tools api编写IDE-addin。

我正在使用XE7,但所有具有源格式的版本都存在此问题。

If not, is it possible to save the code folding info prior to formatting, so I can restore it later?
I'm thinking of writing IDE-addin using the Open Tools api.
I'm using XE7, but this problem exists in all versions that have source formatting.

可能的情况涉及:


  • 记录和重放代码折叠(hook elide 来电)。

  • 仅允许格式化处理当前块(重新定义 CTRL + D 操作)。

  • Record and replay code foldings (hook elide calls).
  • Only allow formatting to work on the current block (redefine the CTRL + D action).

推荐答案

您可以做的是创建区域并禁用代码折叠,格式化代码然后重新启用代码折叠。

What you can do is create regions and disable code folding, format code and then reenable the code folding.

要创建代码区域,请执行以下操作:

To create code regions do:

{$REGION 'Optional text that appears when the code block is folded'} 
// code 
{$ENDREGION}

要切换代码折叠选项,请按Ctrl + Shift K + O。

To toggle code folding option, press Ctrl+Shift K+O.

因此,将代码放入区域,折叠您想要的内容,按Ctrl + Shift K + O禁用折叠,按Ctrl + D格式,然后再次按Ctrl + Shift K + O重新启用折叠。

so, put your code into regions, fold what you want, press Ctrl+Shift K+O to disable the folding, format by pressing Ctrl+D then press Ctrl+Shift K+O again to re enable the folding.

你重新启用折叠,折叠的区域将保持折叠状态。

When you re enable the folding, what was folded with a region is going to stay folded.

信息来源: http://docwiki.embarcadero.com/RADStudio/XE6/en/Using_Code_Folding

我希望这会对你有所帮助。

I hope this helps you.

这篇关于格式化源时如何保留代码折叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆