Yaroslav Bulatov
Yaroslav Bulatov

Reputation: 57923

customizing speedbar for custom headers

I've been keeping note files with the following header

###--- section
##-- subsection
#- subsubsection

Is there a way to customize speedbar to navigate over these? Right now M-x speedbar just gives me directory listing. So far I've been using "M-x occur #-" for this purpose.

Upvotes: 0

Views: 361

Answers (2)

Stefan
Stefan

Reputation: 28541

Add -*- mode: outline-mode; outline-regexp: "#+" -*- on the first line of your file (together with the (eval-after-load "speedbar" '(speedbar-add-supported-extension ".notes")) suggested by scottfrazer) and you should be set.

But as event_jr mentions, you might be better off renaming your file with a ".org" extension and replacing your "#" chars with "*".

Org-mode is basically a (much larger) superset of outline-mode.

Upvotes: 1

scottfrazer
scottfrazer

Reputation: 17327

You could use a simple derived mode and imenu. For example, suppose your notes are in files with the extension ".notes":

(define-derived-mode notes-mode text-mode "notes"
  "Mode for editing my notes."
  (setq imenu-generic-expression (list '(nil "^\\s-*[#]+[-]+\\s-*\\(.+\\)" 1))))

(add-to-list 'auto-mode-alist '("\\.notes" . notes-mode))

(eval-after-load "speedbar"
  '(speedbar-add-supported-extension ".notes"))

The regexp is a bit crude, but you get the idea. You could font-lock the headers too if you want to make them stand out.

Upvotes: 2

Related Questions