How do I avoid expanding folded regions when I invoke the code formatter?

后端 未结 2 1068
清酒与你
清酒与你 2021-01-21 23:05

As you know, Delphi 2010 has built-in code formatting. However, formatting unfolds all folded code blocks. Any ideas how to fix it? This \"feature\" is particularly annoying for

2条回答
  •  野性不改
    2021-01-21 23:11

    Well, this question is really old, but as it was mentioned here:

    How to preserve code folding when formatting source

    and there is no answer, I thought I could answer both, here is the answer I posted there:

    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}
    

    To toggle code folding option, press 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.

    information source: http://docwiki.embarcadero.com/RADStudio/XE6/en/Using_Code_Folding

    I hope this helps you.

提交回复
热议问题