Code folding

From Wikipedia, the free encyclopedia

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 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. Terms such as 'Outlining' 'Code Hiding' 'Expand and Collapse' (among others) are also common.

Contents

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 overidden or augmented by the user.

Generally, folding points are specified with one or more of the following conventions:

  • token-based
  • indentation-based
  • syntax-dependent

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.

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 folding points are those that rely on the specific source code or programming language of the currently-edited file 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.

Each of these conventions has its own distinct advantages and difficulties, and it is essentially up to the developer(s) who create the text editor software to decide which conventions to follow (if any).

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

 Heading 1
 {{{
 Body
 }}}

 Heading 2
 {{{
 Body
 }}}

 Heading 3
 {{{
 Body
 }}}

When loaded into a folding editor, the outline structure will be shown (just the headings):

 Heading 1
 {{{ ...

 Heading 2
 {{{ ...

 Heading 3
 {{{ ...

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

Recent versions of the open-source text editor Vim, Emacs, and the Java IDE Eclipse offer highly-configurable support for code folding. EditPad Pro supports code folding through fully editable file navigation schemes. Sun's NetBeans IDE, Microsoft's Visual Studio.NET, the Code::Blocks IDE, the UltraEdit text editor, the Zeus IDE , the Mac OS X editors TextMate and BBEdit, the KDE text editor Kate, Macromedia Dreamweaver, The cross-platform SciTE editor based on the Scintilla editing component, the GNOME IDE Anjuta and the general source code editor Notepad++ offer code folding as well.

Advanced Search
Included Web Search Engines


Safe Search

close

Top Matching Results

Occasionally Search.com will highlight specialized results that are based on the context of your query. Examples of specialized results include specific links to news, images, or video.

Top Matching Results may highlight information from other Search.com pages, content from the CNET Network of sites, or third party content. The listings are based purely on relevance. Search.com does not receive payment for listings in this section but our partners that provide this data may get paid for listing these products.

Sponsored Links

This section contains paid listings which have been purchased by companies that want to have their sites appear for specific search terms and related content. These listings are administered, sorted and maintained by a third party and are not endorsed by Search.com.

Search Results

Search.com sends your search query to several search engines at one time and integrates the results into one list which has been sorted by relevance using Search.com's proprietary algorithm. You can customize the list of search engines included in your metasearch from the preferences.

The search engines that are used in your metasearch may allow companies to pay to have their Web sites included within the results. To view the Paid Inclusion policy for a specific search engine, please visit their Web site. Search.com does not accept payment or share revenue with any search engine partner for listings in this section.