Sign in Join
Wiki copytemporary

IDE Window: Editor Options Code Folding: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11This is part of the online help for the IDE. \
22It describes the section: "Editor" / "Code Folding". You can open the described dialog in your IDE via:\
33*The menu: "Tools" =\> "Options" / Editor options ...
44
55- The source-editor pop-up context menu: "Options"
66
77Navigation\
88
99- [[IDE Window: Editor Options|Editor Options]] Overview of all Editor Options
1010
1111     
1212
1313- [[IDE Window: IDE Options Dialog|IDE Options]] Overview of all options for the IDE
1414
1515------------------------------------------------------------------------
1616
1717# About
1818
1919Code folding allows certain structure or blocks of text to be "collapsed". This will hide all but the first line of the block, and the first line will be marked with the folded-symbol "\[...\]" at the end of that line.
2020
2121Code folding is done by using a special area in the Gutter which displays the code folding tree. This tree has a node corresponding to each line of text at which a foldable region starts.
2222
2323- \[-\] denotes the beginning of an unfolded foldable block, also termed an expanded block. Clicking on the \[-\] symbol will fold (collapse) this block.
2424- \[+\] denotes the beginning of a folded foldable block, i.e. a collapsed block in which all but the first line is already folded (hidden). Clicking on the \[+\] symbol will unfold (expand) this block.
2525- \| A vertical line is shown to the left of all foldable lines except the top line of such a foldable region. The vertical line begins immediately below the \[+\] sign and continues to the last line of the foldable block. On the last line it displays a tiny edge.
2626
2727Foldable blocks can be nested or overlapped.
2828
2929# Settings
3030
3131## Code folding
3232
3333The checkbox at the top enables or disables code folding globally in all source code windows. If disabled, folding functionality is removed, and the Gutter no longer displays a fold tree.
3434
3535## Language specific options
3636
3737Currently code folding is only supported for source code editors which are showing Object Pascal files (*.pas, *.pp, *.lpr etc.), HTML, XML, standard text diff format files, or form files created by the Designer (usually named *.lfm or *.dfm). For the editor to know which kind of lines and blocks of Pascal code should be foldable you have to specify what you want. At first installation, the Lazarus IDE sets a few of the following as defaults, but all are optional.
3838
3939Select (tick) the Pascal sections you want to be foldable.
4040
4141Procedure
4242Folds entire procedures or functions
4343
4444Var/Type (local)
4545Folds any var, type or const declaration block that is local to a procedure
4646
4747Begin/End (procedure)
4848Folds the begin-end block of a procedure or function. This is the outermost block (the one enclosing the whole procedure)
4949
5050Begin/End (nested)
5151Folds any other begin-end block
5252
5353Repeat
5454
5555Case
5656
5757Try
5858Folds any entire Try-finally/except-end block
5959
6060Except/Finally
6161Lets you fold any code between the "except" or "finally" keyword and the closing "end" of the "try" block
6262
6363Asm
6464
6565Program
6666Folds the entire code up to the "end." statement. This applies to program files (.lpr, .dpr) not to units.
6767
6868unit
6969Folds the entire unit up to the "end."
7070
7171unit section
7272Folds any interface, implementation, initialization or finalization block
7373
7474uses
7575If your uses clause goes over more than one line, you can fold it with this option
7676
7777Var/Type (global)
7878Folds any var, type or const declaration block not local to a procedure/function/method
7979
8080Class/Object
8181
8282public/private
8383
8484Record
8585
8686Nested comments
8787
8888{\$IFDEF}
8989Folds any IFDEF-ELSE-ENDIF
9090
9191{%Region}
9292This lets you define your own blocks, by inserting this special IDE directive into your code. It needs a matching {%Endregion} directive later at the appropriate point. IDE directives are special comments recognised by the Lazarus IDE, but ignored by the compiler. As with standard Pascal syntax the character case of "region" and "endregion" does not matter. However, to be recognised as a fold directive there can be no spaces in the directive ({%ReGiOn} works, but {% Region} does not).
9393
9494# Usage
9595
9696## Using the Mouse
9797
9898You can click the left mouse buttons on the \[+\] and \[-\] symbols to fold/unfold code.
9999
100100If you have nested nodes a click on a \[+\]/\[-\] node will only fold the node starting on this line. Outer or inner nodes are not affected. Inner nodes that were folded will keep their original state.
101101
102102Sometimes you have more than one node starting on the same line. For Example
103103
104-` {$IFDEF WithFoo} for a := i to 10 do begin`
104+``` pascal
105+ {$IFDEF WithFoo} for a := i to 10 do begin
106+```
105107
106108In this case you may want to fold the nodes individually.
107109
108110Note: If any of the nodes on the line is folded, the default action is to unfold, and the Gutter shows a \[+\] sign (even though there may be more nodes that can still be folded).
109111
110112The default mouse settings allow you to change various mouse/key combinations. Note that any clicks apply only to folds starting on this line. Nested folds starting on a different line must be folded by clicking the symbol on their line.
111113
112114Left Click on \[-\]
113115Fold one node starting on this line. This will fold the node which starts closest to the end of the line ("begin" in the example above)
114116
115117Ctrl-Left Click on \[-\]
116118Fold all nodes starting on this line.
117119
118120Alt-Left Click on \[-\]/\[+\]
119121Folds onenode on this line. Each click will fold the next node traversing from the node starting closest to the end of the line to the one closest to the start of the line. This can be used to fold more than one node, because it always folds even if the gutter has a\[+\] sign.
120122
121123Middle Click on \[-\] or \[+\]
122124The same as alt-Left, but saves you having to pressing Ctrl.
123125
124126Left Click on \[+\]
125127Unfold one Node starting on this line. It will unfold the (folded) node closest to the start of the line. Repeated clicks unfold further nodes (if any)
126128
127129Ctrl-Left Click on \[+\]
128130Unfold all nodes starting on this line.
129131
130132Why are nodes folded from the end towards the start of the line? If you have several nodes nested (such as two {\$ifdef}s, or two repeat...until blocks) then the inner node must end first (because it probably has fewer lines). This inner node is the one that starts second on the line
131133
132-` Repeat {<<outer}   Repeat {<<inner}`\
133-`   // do something`\
134-`   Until InnerFlag = true;`\
135-` Until OuterFlag = true;`
134+```text
135+ Repeat {<<outer} Repeat {<<inner}
136+ // do something
137+ Until InnerFlag = true;
138+ Until OuterFlag = true;
139+```
136140
137141If you folded the outer (first) "repeat" node first, the inner one would be hidden too.
138142
139143However, this nesting is not always the case if you mix {\$ifdef} {%region} and Pascal language nodes. If you need more control you can use the context menu, or see the [[IDE Window: EditorMouseOptionsAdvanced|Advanced Mouse options]].
140144
141145Notes:
142146
143147- Mouse middle clicks are unavailable, if the [[IDE Window: Editor Options Mouse|Mouse settings]] for the middle button are set to "ignore"
144148- You can read [[IDE Window: EditorMouseOptionsAdvanced|Advanced Mouse options]] to see how to add further mouse settings, or change existing mouse settings.
145149
146150## Using the Context Menu
147151
148152The Fold-Tree has a special context menu (accessed via a right mouse button click) which allows you to select any node starting on the current line to fold or unfold.
149153
150154It also shows all nodes that include the current line (all nodes that can hide the current line) and lets you fold them.
151155
152156## Using Keyboard
153157
154158Bindings for the Keyboard can be changed in the Options dialog (Tools -\> Options...), under Editor/"Key Mappings". There is a section "Text Folding commands".
155159
156160The defaults are
157161
158162- `Alt`+`Shift`+`- (minus)`: Fold at the current line. Or if no fold node starts on this line, fold at previous line with a fold node.
159163- `Alt`+`Shift`+`+ (plus)`: Unfold at the current line
160164- `Alt`+`Shift`+`0`: Unfold all
161165- `Alt`+`Shift`+`1..9`: Fold at the level corresponding with the number
162166
163167
164168only act on Pascal fold nodes (IFDEF and REGION are ignored)
165169
166170e.g `Alt`+`Shift`+`2` will fold all nodes that are inside ONE outer fold node
167171
168172`Alt`+`Shift`+`1` will fold everything
169173
170174# About {%Region}
171175
172-` {%region}`\
173-` // some code`\
174-` {%endregion}`\
175-`  `
176+```text
177+ {%region}
178+ // some code
179+ {%endregion}
180+```
176181
177182This directive lets you fold arbitrary blocks of code or text. It also accepts {\$region}, but this will give a compiler warning.
178183
179184{%region} is not recognized if it occurs inside a comment or string, so
180185
181-` a := ' {%region} ';`
186+``` pascal
187+ a := ' {%region} ';
188+```
182189
183190does not start a foldable block
184191
185192You can specify
186193
187-` {%region /fold}`
194+```text
195+ {%region /fold}
196+```
188197
189198if you want the fold to start out collapsed on first loading the file.
190199
191200---
192201*From the Free Pascal wiki, page "IDE Window: Editor Options Code Folding", as it stood on 2021-01-30 after a change by FTurtle, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history