emacsemacs-speedbar

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.


Solution

  • 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.