Emacs AllOut is a powerful outliner. It is included with newer versions of Emacs (21 and 22), but you may want to grab the latest version from Ken's web site. It's similar to, but much more powerful than, outline-mode (which is also included with Emacs). See also the Emacs Wiki page, which includes lots of additional tips.
To use the latest version downloaded from the web site, put lines similar to these in your .emacs file:
(load "~/lib/emacs/allout.el") (require 'allout) (allout-init t)
(To use the version that came with your Emacs, drop the first line. In Emacs 21, also replace "allout-init" with "outline-init".)
Try C-h f allout-mode RET to see help text about AllOut mode. From there, click on "allout.el" to play with its source code, which has AllOut markup so you can expand, collapse and rearrange it.
You may wish to redefine the command prefix, which in the latest version of AllOut is defined as C-c SPC to get out of the way of other C-c keybindings you may have. To redefine the prefix to simply C-c, add this line to your .emacs file:
(setq allout-command-prefix "^C")
where ^C is the actual Control-C character, typed as C-q C-c.
Let's do a related Newbie Emacs Tip...
An Emacs buffer always operates in a "major mode," a set of features specific to the kind of data you are editing. For example, if you're editing a text file, you might use "text-mode". You can always type M-x followed by the name of the mode, such as M-x text-mode RET, to force a change in major mode for a buffer.
Emacs also has "minor modes," which add functionality to the buffer without affecting the major mode. AllOut is implemented as a minor mode, so you can use its outlining features in many different kinds of files. AllOut's source code (allout.el) is Emacs Lisp source code with AllOut markup in it, and when you edit it, the Emacs-Lisp major mode is activated, along with the AllOut minor mode. Like major modes, minor modes can be toggled on and off with M-x, as in M-x allout-mode RET.
When you open a file for editing, Emacs attempts to select an appropriate major mode automatically. Often, it uses the name of the file, or sometimes the contents of the file, to select a major mode based on certain rules. For example, if you open a file named "mystuff.txt", it will open with text-mode.
If you want Emacs to always use a specific mode with a specific file, regardless of its other guesses, you can include instructions for Emacs within the file itself. One way is to mention the name of a major mode in the first line of the file, like this:
-*- text -*-
This can appear anywhere on the first line, such as in a source code comment so a compiler won't get confused. In the specific case of a file that begins with a Unix shebang line (such as #!/usr/bin/weirdosh), Emacs will also check the second line for the -*- expression.
While it is possible to use this to activate AllOut mode for a file (-*- allout -*-), only one mode can be specified with this syntax, and you probably want to use the AllOut minor mode with some other major mode. There are two options to do this from within the file.
One is to use an alternate syntax for specifying the mode in a -*- line which lets you specify more than one, like this:
-*- mode:text; mode:allout; -*-
You can also use this syntax to define local variables to be set when the file is loaded, such as:
-*- mode:text; mode:autofill; fill-column: 70; -*-
The other option is to use a different method for defining local variables, which can also activate modes. For this method, put something like this at the end of the file:
Local Variables: mode: text mode: allout End:
For files that need this kind of text commented out, the variables comment-start and comment-end specify what ought to appear before and after each of these lines. Most major modes define these for you. For example, cc-mode defines these as /* and */, so you can do this in C source code:
/* Local Variables: */ /* mode: cc */ /* mode: allout */ /* End: */
(The Emacs manual gives an example which appears to set the mode as well as the comment-start and comment-end variables within the Local Variables lines. It seems weird to me that that would actually work, but if it's really that smart, then well OK. :) )
Emacs manual entries: Major Modes, File Variables
Thank you very, very much. I've been googling for an update to outline-mode for a month and still hadn't seen allout. This is wonderful.