Outline

From WikEmacs
Revision as of 16:42, 15 May 2013 by Elvince (talk | contribs) (outline-mode and outline-magic for code folding)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
outline
Description show and hide fragments of code
Part of Emacs yes


Outline-[minor-]mode 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.

Outline-(minor-)mode

It is included in Emacs.

Once you load it :

M-x outline-minor-mode

you can learn the commands thanks to the menu (menu-bar-mode).


Outline-magic

outline-magic implements extensions for outline(-minor)-mode. Its main features are :

  • VISIBILITY CYCLING: A single command to replace the many outline commands for showing and hiding parts of a document.
  • STRUCTURE EDITING: Promotion, demotion and transposition of subtrees.

Installation

Download outline-magic.el, put it on the load path and copy the following into .emacs (adapting keybindings to your own preferences)

(add-hook 'outline-mode-hook 
          (lambda () 
            (require 'outline-cycle)))
            
(add-hook 'outline-minor-mode-hook 
          (lambda () 
            (require 'outline-magic)
            (define-key outline-minor-mode-map  (kbd "<C-tab>") 'outline-cycle)))

If you want to add this feature by default to your programming language mode, say python :

(add-hook 'python-mode-hook
          (lambda ()
            (outline-minor-mode)
))

Usage

Visibility cycling

The command `outline-cycle' changes the visibility of text and headings in the buffer. Instead of using many different commands to show and hide buffer parts, `outline-cycle' cycles through the most important states of an outline buffer. In the major `outline-mode', it will be bound to the TAB key. In `outline-minor-mode', the user can choose a different keybinding. The action of the command depends on the current cursor location:

1. When point is at the beginning of the buffer, `outline-cycle' cycles the entire buffer through 3 different states:

  • OVERVIEW: Only top-level headlines are shown.
  • CONTENTS: All headlines are shown, but no body text.
  • SHOW ALL: Everything is shown.

2. When point in a headline, `outline-cycle' cycles the subtree started by this line through the following states:

  • FOLDED: Only the headline is shown.
  • CHILDREN: The headline and its direct children are shown. From

this state, you can move to one of the children and zoom in further.

  • SUBTREE: The entire subtree under the heading is shown.

3. At other positions, `outline-cycle' jumps back to the current heading. It can also be configured to emulate TAB at those positions, see the option `outline-cycle-emulate-tab'.

Structure editing

Four commands are provided for structure editing. The commands work on the current subtree (the current headline plus all inferior ones). In addition to menu access, the commands are assigned to the four arrow keys pressed with a modifier (META by default) in the following way:

                               move up
                                  ^
                      promote  <- | ->  demote 
                                  v
                              move down

Thus, M-left will promote a subtree, M-up will move it up vertically throught the structure. Configure the variable `outline-structedit-modifiers' to use different modifier keys.

Read more

Read the documentation included in outline-magic.el.

See also

Narrowing and hiding text in Emacs : http://wikemacs.org/index.php/Emacs_Terminology#Narrow_and_widen