1 ;;; html-imenu --- imneu suport for html modes
3 ;; This is a slightly modified version of
4 ;; html-helper-imenu.el. This version comes with nXhtml.
5 (defconst html-imenu:version "0.9") ;;Version:
6 ;; Last-Updated: 2008-09-30T19:22:05+0200 Tue
8 ;; ~/share/emacs/pkg/html/html-helper-imenu.el ---
10 ;; $Id: html-helper-imenu.el,v 1.11 2004/03/23 07:39:37 harley Exp $
13 ;; Author: Harley Gorrell <harley@panix.com>
14 ;; URL: http://www.mahalito.net/~harley/elisp/html-helper-imenu.el
16 ;; Keywords: html-helper, imenu, html, table of contents
19 ;; * Adds an indented table of contents to the menubar
20 ;; * The regexp only matches headers on a single line
21 ;; and well formed tags. (Which is pretty common.)
23 ;; Put somthing like the following in your .emacs:
24 ;; (autoload 'html-helper-imenu-setup "html-helper-imenu")
25 ;; (add-hook 'html-helper-mode-hook 'html-helper-imenu-setup)
27 ;; While this was originaly written for html-helper,
28 ;; It will work with sgml-mode and others.
30 ;; http://www.santafe.edu/~nelson/hhm-beta/html-helper-mode.el
34 ;; 1998-06-25 : added regexp
35 ;; 2003-03-18 : updated contact info
36 ;; 2004-03-22 : minor clean up
37 ;; 2007-11-23 : changed setup function to do nothing if done already
41 (eval-when-compile (require 'imenu))
43 (defvar html-imenu-title "Index"
44 "*Title of the menu which will be added to the menubar.")
46 (defvar html-imenu-regexp
47 "\\s-*<h\\([1-9]\\)[^\n<>]*>\\(<[^\n<>]*>\\)*\\s-*\\([^\n<>]*\\)"
48 "*A regular expression matching a head line to be added to the menu.
49 The first `match-string' should be a number from 1-9.
50 The second `match-string' matches extra tags and is ignored.
51 The third `match-string' will be the used in the menu.")
53 ;; Make an index for imenu
54 (defun html-imenu-index ()
55 "Return an table of contents for an html buffer for use with Imenu."
56 (let ((space ?\ ) ; a char
60 (goto-char (point-min))
62 (while (re-search-forward html-imenu-regexp nil t)
66 (* 6 (- (string-to-number (match-string 1)) 1))
70 (setq toc-index (cons (cons toc-str (point)) toc-index))
72 (nreverse toc-index)))
74 (defun html-imenu-setup ()
75 "Setup the variables to support imenu."
77 ;; Fix-me: It looks like this function has to be called every time
78 ;; switching to some html mode in mumamo. Values are "survived" by
79 ;; mumamo, but the menu item disappears.
80 ;;(message "html-imenu-setup imenu-create-index-function =%s" imenu-create-index-function)
81 (unless nil ;(eq imenu-create-index-function 'html-imenu-index)
82 (setq imenu-create-index-function 'html-imenu-index)
83 (set (make-local-variable 'imenu-sort-function) nil) ; sorting the menu defeats the purpose
84 (imenu-add-to-menubar html-imenu-title)
85 ;; Run an update to make it easier to access the menubar
86 ;;(run-with-idle-timer 5 nil 'html-imenu-update-menubar (current-buffer))
89 (defun html-imenu-update-menubar (buffer)
91 (html-imenu-update-menubar-1 buffer)
92 (error (message "html-imenu-update-menubar error: %s" err))))
94 (defun html-imenu-update-menubar-1 (buffer)
95 (with-current-buffer buffer
96 (message "HTML Imenu: update menubar...")
97 (imenu-update-menubar)
100 (provide 'html-imenu)
101 ;;; html-imenu ends here