`Folds' is a feature of stedi which is designed to help in program organization. This feature allows you to selectively display or hide various segments of a program, and so has similarities to an outline feature in a word-processor. A large program can be collapsed down to outline form using `folds', allowing you to see at a glance the full program structure. Then you can selectively open up areas of the program for local editing. Although it is in principle extremely simple, it is a feature which can revolutionize your whole approach to programming.
Briefly,a `fold' is defined as the area of a program between two specially formatted lines that mark the fold boundaries. After creating these fold boundaries, you can `open' or `close' a fold at will. Closing a fold suppresses the display of text between the fold boundaries. When a fold is closed, the text within the fold is replaced on the screen by one line that represents the fold as a whole. When a fold is opened, all lines within the fold boundaries are displayed.
To create a fold you must enter two special format lines, one at the beginning and the other at end of the section of the program which you desire to include in the fold. The lines have the same format with one exception as will be shown. The format for the opening line of a fold is as follows:
[
'
The end line of a fold must be identical in every respect to the opening
line (including the label chosen) up to and including the terminating
colon (`:') with one exception: the opening bracket `[
' must be replaced by a
closing bracket `]
'. The first three characters and those after the
colon may still be chosen arbitrarily and potentially different
from those of the opening fold line.
We can now demonstrate this format by enclosing our `Hello stedi' program in a fold. Go to the beginning of the program using the <Home> key. Now type the following line:
/* #[ Hello {\STEDI} main program: */Notice that the freedom in the the fold line format has been used to place the string ``/*'' at the beginning and ``*/'' at the end of the line so as to declare this line as commentary to a C compiler. The same thing can be accomplished in the BASIC programming language for example with the following line:
REM#[ Hello {\STEDI} main program:where 'REM' in the first three columns signifies that the line is commentary. For now we will stick to our C language example. Next go to the end of the program, insert a new line, and add an end line for the fold:
/* #] Hello {\STEDI} main program: END OF FOLD */The words 'End Of Fold' have been added in the closing fold line to illustrate that after the colon it is not necessary to repeat what is included in the opening fold line. So finally your program should look something like this:
*
*/* #[ Hello {\STEDI} main program: */ * *#include <stdio.h> * *main() *{ * printf("Hello STEDI"\n); *} * */* #] Hello STEDI main program: END OF FOLD */ *
/* #[ Hello stedi main program: */ #include <stdio.h> main() { printf("Hello stedi"\n); } /* #] Hello stedi main program: END OF FOLD */Now the fun begins. You can open and close the fold using the command line commands or the function keys. We will first illustrate the options for opening and closing with the following table of function keys:
Command | Action |
F6 | close the fold containing the cursor. |
F7 | open the fold containing the cursor. |
sh-F6 | close all folds in the file. |
sh-F7 | open all folds in the file. |
In order to try these options, make sure the cursor is somewhere between or on the fold boundaries. Now
/* ## Hello stedi main program: */This line is identical to the fold line that begins the fold with the exception that the character `
[
' is now replaced by a `#'. This format
is used to indicate a
closed fold. Now the whole program is hidden behind
this one fold line. A fold, when closed, cannot be altered (try it) but
you may yank (cut) it from the program as a unit using the yank command and
paste it somewhere else. This allows you to deal with whole segments of
your program in blocks, and facilitates a modular approach to
programming.
Next open the fold line with the following:
Now let's go over the alternative methods for opening and closing folds. From the command line the following commands are available:
Command | Action |
] |
close the fold in which the cursor lies |
(same as F6) | |
[ |
open the fold on which the cursor lies |
(same as F7) | |
]a |
close all folds in the file (same as sh-F6) |
[a |
open all folds in the file (same as sh-F7) |