Code folding

Code folding

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.

Contents

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 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
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 No ? No
Kate Yes Yes Yes Yes
Dreamweaver ? ? ? Yes
MATLAB No No Yes No
Notepad++ ? Yes Yes Yes
SciTE ? ? Yes ?
STET[6] ? ? ? ?
TextMate Yes Yes Yes Yes
Vim Yes Yes Yes Yes
UltraEdit No No Yes Yes
Visual Studio Yes Yes Yes Yes
Zend Studio ? ? ? ?

Notes

  1. ^ "Data folding in HxD hex editor (listed as feature of RAM-Editor)". http://mh-nexus.de/hxd/. Retrieved 2007-04-30. 
  2. ^ 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.
  3. ^ 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.
  4. ^ 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.
  5. ^ Folding of user-selected regions in Emacs is implemented by the hide-region-hide command.
  6. ^ STET was the first text editor that supported folding[citation needed]

See also

External links


Wikimedia Foundation. 2010.

Игры ⚽ Поможем сделать НИР

Look at other dictionaries:

  • Code Folding — Code Faltung oder Code Folding bezeichnet eine Funktion in Editoren, insbesondere in modernen integrierten Entwicklungsumgebungen, um logisch zusammengehörende Quelltextabschnitte wie Klassen oder Methoden in sogenannten Folds bzw. Falten zu… …   Deutsch Wikipedia

  • Code-Faltung — oder Code Folding bezeichnet eine Funktion in Editoren, insbesondere in modernen integrierten Entwicklungsumgebungen, um logisch zusammengehörende Quelltextabschnitte wie Klassen oder Methoden in sogenannten Folds bzw. Falten zu gruppieren. Man… …   Deutsch Wikipedia

  • Folding editor — A folding editor is a text editor which supports text folding or code folding, a mechanism allowing the user to hide and reveal blocks of text mdash;usually named. Typically this is done to allow the user to better picture the overall structure… …   Wikipedia

  • Code::Blocks — Not to be confused with the computer programming term code block. Code::Blocks Code::Blocks 10.05 running on Windows Vista …   Wikipedia

  • Folding@home — Original author(s) Vijay Pande Developer(s) Stanford University / Pande lab Initial release 2000 10 01 …   Wikipedia

  • Folding@home — Développeur Université Stanford Première version …   Wikipédia en Français

  • Folding@Home — est un projet de calcul réparti. Son but est d étudier le repliement de protéine dans diverses configurations de température et de pression afin de mieux comprendre ce processus et d en tirer des connaissances utiles qui pourraient, entre autres …   Wikipédia en Français

  • Folding at home — Folding@Home Folding@Home est un projet de calcul réparti. Son but est d étudier le repliement de protéine dans diverses configurations de température et de pression afin de mieux comprendre ce processus et d en tirer des connaissances utiles qui …   Wikipédia en Français

  • Folding — Fold may refer to:*Above the fold, a graphic design concept originating in newspapers *Fold (from the Saxon falod ) meaning a staked off pasture area (e.g. Sheepfold, an enclosure for sheep) and used in place names such as the Fold Villages.… …   Wikipedia

  • Code browser — A code Browser is an editor, sometimes with folding or other advanced layout capabilities, designed to structure source code or, by extension, other kinds of text file. Since it is typically aware of the syntax (and, to some extent, the… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”