在代码编辑器中折叠 If-Then-Else 语句 (Delphi 2007)
每隔一段时间,我就会编辑一些很长的 if-then-else 语句(或更糟糕的是,嵌套 if-then-else 语句),就像这样:
if A < B then
begin
DoSomething;
DoSomethingElse;
{...and more statements going on and on and on...}
FinallyWrapUpThisBit;
end
else
begin
DoThis;
DoThat;
{...and more statements going on and on and on...}
FinallyWrapUpThisBit;
end;
...发现自己想要“折叠”第一个开始-结束对,以调出较低的“else”部分(通常是因为我指的是 if-then 语句之上的内容。也许所以它只会说“开始...... " 并在其左侧添加 [+} 符号以将其再次展开。
我已经探索了 IDE 中的“折叠”功能,但似乎没有一个命令可以执行此操作。这似乎是我的旧 D6 的 CodeRush这样做了,但我可能在想象一些事情(我的想象力非常活跃......)
是否有像 Castalia(或其他一些)这样的 IDE 插件可以做到这一点?
Every once in a while I'm editing some long pair of if-then-else statements (or worse, nested if-then-else statements) , like, say, this:
if A < B then
begin
DoSomething;
DoSomethingElse;
{...and more statements going on and on and on...}
FinallyWrapUpThisBit;
end
else
begin
DoThis;
DoThat;
{...and more statements going on and on and on...}
FinallyWrapUpThisBit;
end;
...and I find myself wanting to "collapse" the first begin-end pair, to bring up the lower "else" part (usually because I'm referring to something above the if-then statemnent. Maybe so it would just say "begin..." and have [+} sign to the left of it to expand it out again.
I've explored the "fold" functions in the IDE, but none of the commands seem to do this. It seems like my CodeRush for my old D6 did this, but I could be imagining things. (I have a very active imagination...).
Do any of the IDE plug-ins like Castalia (or some other one) do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用开箱即用的普通 Delphi,您必须包围您的开始...结束,
这可以通过代码模板完成...
我记得 Castalia 代码块的漂亮彩色可视化(开始..结束),但我不记得是否可折叠。
With plain Delphi out of the box, you would have to surround your begin...end with
which can be done through a code template...
I remember Castalia for the nice colored visualization of code blocks (begin..end) but I don't remember if it was foldable.
使用重构工具将条件分支的代码移动到单独的函数中。 然后你就不需要折叠任何东西了。 您可能还会发现可以合并两个分支通用的代码,例如对
FinallyWrapUpThisBit
的调用。Use the refactoring tools to move the conditional branches' code into separate functions. Then you won't need to fold anything. You might also find that you can merge code that's common to the two branches, such as that call to
FinallyWrapUpThisBit
.这里的另一个大帮手是 CNPack。 它是一个安装到 Delphi 中的向导,将为您的开始/结束对着色,使其更容易遵循代码。 它并不完全执行代码折叠,因为您需要使用 {$REGION} {$ENDREGION} 标签。
Another big helper here would be CNPack. It is a wizard which installs into Delphi and will colorize your begin/end pairs, making it MUCH easier to follow the code. It doesn't exactly do code folding, for that you need to use the {$REGION} {$ENDREGION} tags.