Difference between revisions of "Folding"

From WikEmacs
Jump to navigation Jump to search
(introduce folding solutions)
 
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
'''Folding''' is a way to hide and show text in an emacs buffer, i.e. to do code folding. For example, we can do the same thing than with org-mode but with source code.
+
'''Folding''' is a way to hide and show text in an emacs buffer, i.e. to do code folding. For example, we can do the same thing as with org-mode but with source code.
  
 
You may look at the differences between narrowing and hiding text in Emacs : http://wikemacs.org/index.php/Emacs_Terminology#Narrow_and_widen
 
You may look at the differences between narrowing and hiding text in Emacs : http://wikemacs.org/index.php/Emacs_Terminology#Narrow_and_widen
Line 6: Line 6:
  
 
[[outline]] is a built in mode to cycle visibility and edit the code structure. You should check it out !
 
[[outline]] is a built in mode to cycle visibility and edit the code structure. You should check it out !
 +
 +
It works with headings, so it is more geared towards documents than code. For example, it works very well with markdown documents to hide or show document sections (even if the TAB key on a markdown header already does this). We can also move sections around. For example, move a h1 section and all its subsections up, with one keypresse ('''outline-move-subtree-up''').
 +
 +
Once you enabled the minor mode ('''outline-minor-mode'''), you can discover commands with the menu entry.
  
 
= Evil users =
 
= Evil users =
  
[[evil]]-mode users also have a built-in solution: use '''za''' to toggle visibility, '''zc''' (close), '''zm''' (close all), '''zr''' (open all).
+
[[evil]]-mode users have pre-defined keys: use '''za''' to toggle visibility, '''zc''' (close), '''zm''' (close all), '''zr''' (open all). They are an interface to other folding packages, most notably hideshow. The value of the variable <code>evil-fold-list</code> determines which backend is used for which major or minor modes, and what functions are available for those backends.
 +
 
 +
You might also like [https://github.com/mrkkrp/vimish-fold vimish-fold]: it works with regions, it is persistent, it has mouse support, avy support, …
  
 
= Third party packages =
 
= Third party packages =
Line 21: Line 27:
 
[https://github.com/gregsexton/origami.el origami] works well with languages that use braces to delimit blocks.
 
[https://github.com/gregsexton/origami.el origami] works well with languages that use braces to delimit blocks.
  
 +
== Fold this region ==
 +
 +
To fold the active region, see [https://github.com/magnars/fold-this.el fold-this] (in Melpa).
  
 +
[[File:yafolding.png]]
  
  

Latest revision as of 12:03, 30 July 2021

Folding is a way to hide and show text in an emacs buffer, i.e. to do code folding. For example, we can do the same thing as with org-mode but with source code.

You may look at the differences between narrowing and hiding text in Emacs : http://wikemacs.org/index.php/Emacs_Terminology#Narrow_and_widen

Outline-minor-mode

outline is a built in mode to cycle visibility and edit the code structure. You should check it out !

It works with headings, so it is more geared towards documents than code. For example, it works very well with markdown documents to hide or show document sections (even if the TAB key on a markdown header already does this). We can also move sections around. For example, move a h1 section and all its subsections up, with one keypresse (outline-move-subtree-up).

Once you enabled the minor mode (outline-minor-mode), you can discover commands with the menu entry.

Evil users

evil-mode users have pre-defined keys: use za to toggle visibility, zc (close), zm (close all), zr (open all). They are an interface to other folding packages, most notably hideshow. The value of the variable evil-fold-list determines which backend is used for which major or minor modes, and what functions are available for those backends.

You might also like vimish-fold: it works with regions, it is persistent, it has mouse support, avy support, …

Third party packages

Yafolding

yafolding, in melpa, is based on indentation.

Origami

origami works well with languages that use braces to delimit blocks.

Fold this region

To fold the active region, see fold-this (in Melpa).

Yafolding.png