UltraEdit PowerTips
Code Folding
Code folding allows you to hide a section of code, which is indispensable for managing complex or nested code structures in your source files. The collapsible sections are based on the structure of your file and code.
How does code folding work?
Code folding just works “out of the box” for most popular programming languages. You can see the “—” code folding boxes in the left margin next to the line numbers. Clicking these will collapse the corresponding section of code.
Configuring code folding
There are several options for configuring code folding in Advanced − Configuration − Editor Display − Code Folding.
Folding indent lines
UltraEdit/UEStudio will display a dashed visual fold line in the indented space of a collapsible section so that you can see how many lines a particular fold section spans. Position your caret next to the brace that begins the fold, and you’ll see the fold line highlight to show you how far it spans:
- Save folded lines
If checked, UltraEdit/UEStudio will maintain folded sections of text and code between sessions. - Enable show/hide lines and code folding
This setting enables/disables code folding completely. - Enable show/hide lines in non syntax highlighted files
If you want to hide a section of text in a file that is not being parsed as any particular coding language, you can check this. Then select the text in the file and press Ctrl + — (Subtract on numeric keypad) to collapse/expand it. - Show last line of fold in syntax highlighted files
This controls whether or not the editor displays the last line of a collapsed section of code. - Automatically unfold hidden areas on Find and Goto
When you’re doing a Find or Goto, if the target is inside of a collapsed section of text, this setting will cause UltraEdit/UEStudio to automatically show it. - Detect XHTML from DTD on file load
If checked, the editor will check your file for a DOCTYPE declaration. If either XHTML 1.0 Strict or XHTML 1.1 is specified in the file as the DOCTYPE, special code folding rules are used for the file to support this. - Draw graphical lines
This controls whether or not vertical lines are shown in the code folding margin from the top to the bottom of a fold section. - Draw indent lines
This controls whether or not vertical lines are shown in the edit area in the indented space of a foldable section (see next paragraph).
Advanced code folding configuration
UltraEdit/UEStudio’s code folding is based on unique open/close strings, and defaults are already provided for many languages. If you have a wordfile without any code folding strings specified, the default open strings “{,” “If,” and “ElseIf” and corresponding close strings “},” “ElseIf,” and “End If” are used.
Sometimes you may want to add support for folding of sections of code not handled by the defaults. For example, you may want to be able to fold C++ preprocessor directives like “#if” to “#else” and “#endif”.
Setting this up is easy, as the Open Fold Strings and Close Fold Strings strings are defined in the programming language’s wordfile, and you can easily modify them. To open the wordfile, go to Advanced − Configuration − Editor Display − Syntax Highlighting, then select the language (it should be pre-selected for you), and click Open.
The C++ wordfile will open. Near the top, you should see lines similar to the following:
/Close Fold Strings = "}"
Since “#if” should open a fold, and “#else” should close it, we’ll need to add these to Open Fold Strings and Close Fold Strings, respectively:
/Close Fold Strings = "}" "#else"
Save the wordfile, restart, and take a look at our file. This change has only gotten us part of the way there. We still need “#else” to fold to “#endif”.
To do this, we need to add “#else” to the Open Fold Strings and “#endif” to the Close Fold Strings.
/Close Fold Strings = "}" "#else" "#endif"
Save the wordfile and restart and – perfect! The preprocesser conditional now folds as we want it to.