6 Oct 2011 ryuslash   » (Journeyer)

I've been trying out several types of code folding in emacs, but I've never found a very good one. Folding mode seemed clunky and could sometimes break font locking it seemed. HideShow actually removes (doesn't delete of course) the lines, so the line numbers get screwed up and things like goto-line get messed up.

This time I'm trying out outline-minor-mode. I've tried it before and didn't really like it, but this time I've combined it with some, IMO, nice header comments.

I've written a simple skeleton to help me write these comment lines:

(define-skeleton outline-skeleton
"Insert command"
"Text: "
'(beginning-of-line)
'(setq beginning-of-line-point (point))
'(indent-according-to-mode)
'(setq beginning-of-indent-point (point))
comment-start "-----[ " str " ]"
(let ((len (- fill-column
(length comment-start)
(length comment-end)
(length str)
9
(- beginning-of-indent-point
beginning-of-line-point))))
(insert-char ?- len))
comment-end)

And then I add this hook:
(add-hook
'prog-mode-hook
(lambda ()
(outline-minor-mode 1)
(set (make-local-variable 'outline-regexp)
(concat "\\s *" (regexp-opt `(,comment-start)) "-----\\["))
(hide-body)
(local-set-key [C-tab] 'outline-toggle-children)))

And whenever I load a file with these comments I get a nice and clean outline of my file.

Also, since it uses the variables comment-start and comment-end it works for multiple programming languages. I've tried it in both emacs-lisp and php.

Looks like:
;-----[ Prog mode ]---------------------------------------------------

What are some of the other options people use?

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!