Jump to content

Code folding: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
HKL47 (talk | contribs)
HKL47 (talk | contribs)
Line 162: Line 162:
| {{?}}
| {{?}}
|-
|-
! {{rh}} | [[Mansfield KEditWin]]
! {{rh}} | [[Mansfield Software KEdit]]
| {{?}}
| {{?}}
| {{?}}
| {{?}}
| {{?}}
| {{?}}
| {Yes}
| {{Yes}}
|-
|-
! {{rh}} | [[CodeGear Delphi IDE]]
! {{rh}} | [[Borland Delphi|CodeGear Delphi IDE]]
| {{?}}
| {{?}}
| {{?}}
| {{?}}
| {Yes}
| {{Yes}}
| {{?}}
| {{?}}
|}
|}

Revision as of 14:19, 4 February 2008

Code folding is a feature of some text editors, source code editors and IDEs that allows the user to selectively hide and display sections of a currently-edited file as a part of routine edit operations. This allows the user to manage large regions of potentially complicated text within one window, while still viewing only those subsections of the text that are specifically relevant during a particular editing session.

This type of feature is customarily popular among developers who routinely manage a high volume and variety of source code files. Nonetheless, text editors that include this feature, known as folding editors, often provide enough flexibility to allow uses for purposes other than source code management. Consequently, the term "code folding" is only one among various other common terms for this feature, such as "outlining", "code hiding", and "expand and collapse". Another variation, called "data folding", is implemented in some hex editors and is used to structure a binary file or hide inaccessible data sections in a RAM-editor.[1]

Conventions

In order to support code folding, the text editor must provide a mechanism for identifying "folding points" within a text file. Some text editors provide this mechanism automatically, while others provide defaults that can either be overridden or augmented by the user.

Folding points are usually specified with one or more of the following conventions. Each of these conventions has its own distinct advantages and difficulties, and it is essentially up to the developers who create the text editor software to decide which conventions to follow. Text editors that provide support for multiple folding conventions typically allow the user to choose which is most appropriate for the file being edited.

Token-based

Token-based folding points are specified using special delimiters that serve no other purpose in the text than to identify the boundaries of folding points. This convention can be compared to indentation-based folding points, where printable characters are used instead of whitespace. The most common delimiter tokens are {{{ for the beginning of the fold and }}} to end the fold.

Indentation-based

Indentation-based folding points are generally specified by the position and sequence of non-printing whitespace, such as tabs and spaces, within the text. This convention is particularly suitable to syntaxes and text files that require indentation as a rule by themselves.

Syntax-dependent

Syntax-dependent folding points are those that rely on the content of the file being edited in order to specify where specific folding regions should begin and end. Syntax-based folding points are typically defined around any or all of the standard sub-features of the markup language or programming language in use.

User-specified

User-specified folding typically allows the user to fold sections of text using a generic selection method. Folded text might be anonymous or named.

Examples

The following document contains folding tokens ({{{ ... }}}):

 Heading 1
 {{{
 Body
 }}}

 Heading 2
 {{{
 Body
 }}}

 Heading 3
 {{{
 Body
 }}}

When loaded into a folding editor, the outline structure will be shown:

 Heading 1
 {{{ ...

 Heading 2
 {{{ ...

 Heading 3
 {{{ ...

Usually clicking on the {{{ marks makes the appropriate body text appear.

Software with code folding capability

Token Indentation Syntax User
STET[2] ? ? ? ?
Vim Yes Yes Yes Yes
Emacs ? ? ? ?
Eclipse Yes Yes Yes Yes
NetBeans IDE ? ? ? ?
MS Visual Studio .NET Yes Yes Yes Yes
Code::Blocks IDE ? ? ? ?
UltraEdit ? ? ? ?
Zeus IDE ? ? ? ?
TextMate ? ? ? ?
EditPlus ? ? ? ?
BBEdit ? ? ? ?
Kate Yes Yes Yes Yes
Macromedia Dreamweaver ? ? ? ?
SciTE ? ? ? ?
Anjuta IDE ? ? ? ?
Mansfield Software KEdit ? ? ? Yes
CodeGear Delphi IDE ? ? Yes ?

Notes

  1. ^ "Data folding in HxD hex editor (listed as feature of RAM-Editor)". Retrieved 2007-04-30.
  2. ^ STET was the first text editor that supported folding[citation needed]

See also