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: "
'(setq beginning-of-line-point (point))
'(setq beginning-of-indent-point (point))
comment-start "-----[ " str " ]"
(let ((len (- fill-column
(length comment-start)
(length comment-end)
(length str)
(- beginning-of-indent-point
(insert-char ?- len))

And then I add this hook:
(lambda ()
(outline-minor-mode 1)
(set (make-local-variable 'outline-regexp)
(concat "\\s *" (regexp-opt `(,comment-start)) "-----\\["))
(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!