Aside: I don't know if this is necessary, but I'm going to start by
describing / defining folding, at least at some level. (When I started my
transition from the dos/Windows/non-*nix world about 8 years ago, I was
looking for (among other things) an editor / word processor with collapsible
outlining features like Microsoft Word has. It was quite a while before I
realized that folding was what I needed to look for in the *nix world.)
There can be a variety of descriptions / definitions of what folding is. Let
me see what I can find by Googling--oops, no useful definitions by searching
[define:folding]--those definitions all relate to other things.
Ok, so I'll try:
In a folding editor (or word processor), folding is a means to temporarily
hide selected portions of text to make other operations (navigation, reading
(skimming), or editing) easier. The "easier" comes about by hiding portions
of the text that you are currently not interested in.
Other names for folding:
* Microsoft Word calls the similar feature "collapsible outlining"
* I believe some outline processors or editors (Leo) (and maybe even some
mind mappers?) call the act of temporarily hiding text "hoisting"--I can't
recall what they call the act of unfolding--maybe some say "dehoisting"?
Basis and examples of folding:
* In an editor set up for editing a particular programming language (e.g.,
nedit in C "language mode"), folding can work based on selected features of
the programming language. For example, folding might detect features of the
language like (for C) curly braces and, on demand, fold (hide) everything
between a given { and } (or fold everything between all {s and }s). Or fold
the contents (code within) a function, or the "clauses" of a case statement,
or the contents of an if statement (or any else clauses).
* In an editor or word processor set up for editing text with markup
(varying down to text with little or no markup like some of the wiki
markups), folding can work based on features of the markup. For example,
when set up for editing HTML, folding might detect headings at various levels
(H1 thru H6) and fold everything between a given H2 heading and the next H2
heading (or fold everything after each H2 heading and the next H2 heading (or
eof).)
* Folding can optionally also work to hide text between arbitrary locations
established by the user.
For example, with a C function something like this:
static Rangeset *rangesetInclMaintain(Rangeset *rangeset, int pos, int ins,
int del)
{
int i, j, n, *rangeTable = (int *)rangeset->ranges;
int end_del, movement;
n = 2 * rangeset->n_ranges;
i = rangesetWeightedAtOrBefore(rangeset, pos);
if (i == n)
return rangesetFixMaxpos(rangeset, ins, del); /* all beyond the end */
/* if the insert occurs at the start of a range, the following lines will
extend the range, leaving the start of the range at pos. */
if (is_start(i) && rangeTable[i] == pos && ins > 0)
i++;
end_del = pos + del;
movement = ins - del;
<code truncated as the above is more than enough for this example>
}
Note: Typically, enough text is left visible in the folded condition so that
you can understand what is going on, although folding at a higher level might
hide that for lower levels.
You might fold at the function level, which (for the example code above) might
look something like the following (including an ASCII attempt at showing the
folding marks that would typically be present in a column to the left of the
text to show the status and extent of folding, as well as an optional
horizontal line to mark the end of a folded region--the exact contents of
that column (and the horizontal line) will be discussed later):
+ static Rangeset *rangesetInclMaintain(Rangeset *rangeset, int pos, int ins,
| int del)
L---------------------------------------------------------------------------
Clicking on the + sign would change it to a minus sign and expand (show /
unhide) the text of the function, except that subparts of the function that
were hidden by other fold commands might (would probably) remain hidden until
clicking on a + at those locations which would expand those parts of the
function.
(I expect that anything that can be done by a mouseclick will also be possible
by the keyboard and by a nedit macro.)
Later I may give examples of additional levels of folding and examples for
text documents. As a simple example (or examples) of folding for a text
document, note that a table of content is essentially (almost) a folded
version of a document. (Page numbers are not relevant, so think of a table
of content without page numbers.)
Further, if you think of a variety of tables of content for the same document,
some showing only the top level headings (H1 in HTML), some showing
additional levels (H1 and H2 headings, H1, H2, and H3) headings, etc.), those
are examples of the document folded at different levels.
Note then that there is a concept of a hierarchy of folding, both for text and
code--for text it is (can be) the different levels of tables of content that
I just mentioned, for code it is that parts within a function (like the
content of an if statement or else clause) might be hidden even if the
function is generally expanded.
Also note that folding can hide multiples of whole lines (the most common, in
my experience) , but can also hide a portion of a line.
A caution (that will have to come up again) is that when editing operations
occur in a folded condition, they must either not affect the folded (hidden)
portions, or the effect on the hidden portions must be well defined and well
known.
(In older versions of Microsoft Word (perhaps only in the dos versions--my
memory is hazy--I don't recall the features available in Word97, and I
haven't used any versions of Word after 97), editing operations could affect
hidden portions of the text. There were, iirc, at least two different
editing modes--in one, editing operations on a visible heading did not affect
the contents of the heading, in the other it did. This allowed you do to
things like move (or delete) a heading and its subheadings and "plain text"
content to another location in the document in the folded condition, or just
edit (or move) the heading without its subheadings and text.)
Enough of this for now, I think.
I should mention, that my primary use for folding is in editing text files
(with TWiki markup).
Randy Kramer
--
NEdit Develop mailing list - [email protected]
http://www.nedit.org/mailman/listinfo/develop