Code folding in emacs

5 December 2009

;;; You may also want to bind hide-body, hide-subtree, show-substree,
;;; show-all, show-children, ... to some keys easy folding and unfolding
(add-hook 'ruby-mode-hook
              '(lambda ()
                 (outline-minor-mode)
                 (setq outline-regexp " *\\(def \\|class\\|module\\)")))
 
 ; Outline-minor-mode key map
(global-set-key [M-left] 'hide-body)
(global-set-key [M-right] 'show-all)
(global-set-key [M-up] 'hide-entry)
(global-set-key [M-down] 'show-entry)

Then use M plus arrow keys to fold and open method/class/module blocks.

 M-left       # will fold all.  
 M-right      # will open all.  
 M-down       # will open current block.  
 M-up         # will close current block.