Code folding: Difference between revisions
Line 70: | Line 70: | ||
! User |
! User |
||
|- |
|- |
||
! {{rh}} | [[ |
! {{rh}} | [[Ajax.org Cloud9 Editor]] |
||
⚫ | |||
⚫ | |||
| {{yes}} |
| {{yes}} |
||
⚫ | |||
⚫ | |||
⚫ | |||
| {{yes}} |
| {{yes}} |
||
| {{yes}} |
| {{yes}} |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
| {{yes}} |
| {{yes}} |
||
| {{?}} |
| {{?}} |
Revision as of 12:38, 22 August 2013
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 amounts of text while viewing only those subsections of the text that are specifically relevant at any given time.
This feature is commonly used by developers to manage source code files.
Text folding is a similar feature used in folding editors and outliners. Text folding is generally distinguishable from code folding in that the latter tends to be used with the specific syntax of markup languages or programming languages, whereas the former can be used with ordinary text. 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]
Consequently, the term "code folding" is only one among various other common terms for this feature. Related terms include "expand and collapse", "code hiding", "outlining" and others.
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 {{{
to begin the folded section, and }}}
to end it.
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 such as Python 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 | |
---|---|---|---|---|
Ajax.org Cloud9 Editor | Yes | Yes | Yes | ? |
AkelPad | ? | ? | Yes | ? |
Anjuta IDE | ? | Yes | Yes | ? |
Xcode | Yes | Yes | Yes | Yes |
BBEdit | ? | ? | Yes | ? |
Delphi IDE | Yes | ? | Yes | ? |
Code::Blocks IDE | Yes | Yes | Yes | Yes |
FlashDevelop IDE | ? | ? | Yes | ? |
Eclipse | ? | ? | Yes | ? |
EditPlus | No | Yes | No | No |
Emacs | Yes[2] | ?[3] | Yes[4] | Yes[5] |
EmEditor Professional | ? | Yes | Yes | ? |
NetBeans IDE | Yes | Yes | Yes | Yes |
gedit | Yes | Yes | Yes | ? |
JED | Yes | Yes[6] | ? | No |
Kate | Yes | Yes | Yes | Yes |
Dreamweaver | ? | ? | ? | Yes |
MATLAB | No | No | Yes | No |
Notepad++ | ? | Yes | Yes | Yes |
SciTE | Yes | Yes | Yes | ? |
STET[7] | ? | ? | ? | ? |
TextMate | Yes | Yes | Yes | Yes |
Vim | Yes | Yes | Yes | Yes |
UltraEdit | No | No | Yes | Yes |
Visual Studio | Yes | Yes | Yes | Yes |
Zend Studio | ? | ? | ? | ? |
NuSphere PHPEd | ? | ? | Yes | Yes |
ISPF | ? | Yes | ? | Yes |
Sublime Text | No | Yes | No | Yes |
Notes
- ^ "Data folding in HxD hex editor (listed as feature of RAM-Editor)". Retrieved 2007-04-30.
- ^ Token-based folding in Emacs is impemented by the folding minor mode. One can also use outline and allout minor modes for sectioning program sources.
- ^ One can use the
set-selective-display
function in Emacs to hide lines based on the indentation level, as suggested in the Universal code folding note. - ^ Syntax-dependent folding in Emacs is supported by: the outline and allout modes
for special dedicated outline-syntaxes;
by the hideshow minor mode for some programming languages;
also, by the
semantic-tag-folding minor mode and the
senator-fold-tag
command for syntaxes supported by semantic (a component of CEDET), as well as by doc-mode for JavaDoc or Doxygen comments, by TeX-fold-mode,sgml-fold-element
command, nxml-outln library in the corresponding language-specific modes, and possibly in other modes for particular syntaxes. Sometimes, the standard simple outline minor mode is used to simulate syntax-based folding, cf. the use of it in properly indented Emacs Lisp source code, the use of it (see near the end of the page) for properly indented HTML. Several folding mechanisms are unified by the fold-dwim interface. See also CategoryHideStuff. - ^ Folding of user-selected regions in Emacs is implemented
by the
hide-region-hide
command. - ^ The
set_selective_display
function may be used to hide lines indented beyond a specified amount. - ^ STET may have been the first text editor that supported folding[citation needed]
See also
- The Programming features section of the Comparison of text editors article for more editors that support folding
External links
- What is a folding editor? by the author of the
fe
editor. - Description of the folding editor used in occam.
- criticism of code folding