Folding mode is a MinorMode that uses a special string to find the regions to hide: {{{ and }}}. The variable fold-mode-marks-alist defines the strings for each MajorMode separately. From the folding menu you can enter, show, hide, etc. regions. With the Mouse-3 (the rightmost mouse button) when there is no other context menu defined a right mouse click will toggle the visibility of fold.

Folding mode was originally written by Jamie Lokier and later extended by Jari Aalto and Anders Lindgren.


The latest code is maintained by JariAalto. Report bugs to Savannah bug tracker.


Add the following to your ~/.emacs InitFile and then every opened file will be searched for folding marks:

    (if (require 'folding nil 'noerror)
      (message "Library `folding' not found"))

Folding mode is based on comments, and it uses the folding-top-mark and folding-bottom-mark to distinguish which region should be folded.

Example of How to Use it with Ruby

After adding those two lines above, also add:

  (folding-add-to-marks-list 'ruby-mode "#{{{" "#}}}" nil t)

Now say you have some ruby code you want to make foldable. Wrap it in #{{{ #}}} thus:

  # this code does blah
  def blah
    do some blah
    do some more blah

Remember to M-x folding-mode <RET> to enable FoldingMode. Now, anywhere within those boundaries you can do C-c @ C-q to toggle it open and closed.


Always make sure that you have a closing fold mark for every opening mark! Otherwise the opening of files might be difficult. Using M-x occur to search for opening and closing marks is a good idea for this.

To set own folding marks for a given mode, study the following example.

  (folding-add-to-marks-list 'php-mode                "//{"  "//}"  nil t)
  (folding-add-to-marks-list 'prolog-mode             "%{{{" "%}}}" nil t)
  (folding-add-to-marks-list 'html-mode               "<!-- {{{ " "<!-- }}} -->" " -->" nil t)

Note: In plain text mode the symbol for open fold is “{{{ “ (that is, with a space at the end).

An example - Folding Mode for C Code

While editing C programs, folding-mode use ‘/* {{{ ‘ and ‘/* }}}’ as the top and bottom mark. And it is easy for you to use the interactive function fold-fold-region to fold a region marked by Emacs set-mark. If you want a many level folded file, you have to do nothing but to fold a region in a folded region like this:

     /* {{{ This is the parent level */
	/* {{{ This is the first child level (var initialized) */
	int i,j,k;
	float l,m,n;
	char a,b,c;
	/* }}} child level ended */
	/* {{{ Here is the second child level (function) */
	/* {{{ grand-son level (function used to get character) */
	char getChar()
	/* }}} grand-son level ended */
	int getInt()
	float getFloat()
	/* }}} second child level ended */
	/* and so on */
	/* }}} */

After folding this buffer in Emacs, it looks like that:

  /* {{{ This is the parent level ...

When you use enter this level, you will see:

  /* {{{ This is the first child level ...
  /* {{{ Here is the second child level ...
  /* {{{ and so on ...

Note: Actually, hs-minor-mode which comes with Emacs CVS (as of May 25th 2003) does work like this, hiding only the first containing block. I guess it also works correctly with “older” Emacs 21.2 and 21.3.


Michael Grasso suggested `C-u 2 C-x $' (`C-x $' to clear), see Groups:folding&

See also HideShow.

If you want to see how you can use FoldingMode to organize your file you might consider Lisp:eukleides.el and Lisp:moikrug.el as examples.


Both 2.107 and the older 2.99 appear to work perfectly with my GNU Emacs CVS. – TimAnderson

The folding.el (version: 2.117+) from the XEmacs CVS does not appear to be working on my GNU Emacs – RudiGrinberg

I found folding-mode is not compatiable with GNU Emacs The newlines of file save with folding-mode often replace with ^M and this will lead to many problems for some files, such as elisp. fold.el works in my emacs. I recommend use it in GNU Emacs. Download: I add some command in Lisp:fold.el – Ye_Wenbin

folding.el (version 2006.1118), folding-2.107.el, and folding-2.99 all work on plain text in GNU Emacs (GNU Emacs (powerpc-apple-darwin8.11.0, Carbon Version 1.6.0) of 2008-01-17 on However all have unpleasant interaction with narrowing and widening in LaTeX.

Is there a way to change the face of the folding indicator (i.e. the “…”)? I would also like to change that folding indicator text if possible…

And while I’m at it, any way of not narrowing every time I enter a fold?

(setq folding-narrow-by-default nil)

CategoryHideStuff CategoryOutline