在代码编辑器中折叠 If-Then-Else 语句 (Delphi 2007)

发布于 2024-07-16 17:06:32 字数 654 浏览 5 评论 0原文

每隔一段时间,我就会编辑一些很长的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

掐死时间 2024-07-23 17:06:32

使用开箱即用的普通 Delphi,您必须包围您的开始...结束,

  {$region 'begin...end'}
  .... 
  {$endregion}

这可以通过代码模板完成...

我记得 Castalia 代码块的漂亮彩色可视化(开始..结束),但我不记得是否可折叠。

With plain Delphi out of the box, you would have to surround your begin...end with

  {$region 'begin...end'}
  .... 
  {$endregion}

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.

单调的奢华 2024-07-23 17:06:32

使用重构工具将条件分支的代码移动到单独的函数中。 然后你就不需要折叠任何东西了。 您可能还会发现可以合并两个分支通用的代码,例如对 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.

迷途知返 2024-07-23 17:06:32

这里的另一个大帮手是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文