]> git.rkrishnan.org Git - .emacs.d.git/blob - emacs/nxhtml/nxhtml/html-imenu.el
remove toolbar and menubar
[.emacs.d.git] / emacs / nxhtml / nxhtml / html-imenu.el
1 ;;; html-imenu --- imneu suport for html modes
2 ;;
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
7 ;;
8 ;; ~/share/emacs/pkg/html/html-helper-imenu.el ---
9 ;;
10 ;; $Id: html-helper-imenu.el,v 1.11 2004/03/23 07:39:37 harley Exp $
11 ;;
12
13 ;; Author:    Harley Gorrell <harley@panix.com>
14 ;; URL:       http://www.mahalito.net/~harley/elisp/html-helper-imenu.el
15 ;; License:   GPL v2
16 ;; Keywords:  html-helper, imenu, html, table of contents
17
18 ;;; Commentary:
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.)
22 ;;
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)
26 ;;
27 ;; While this was originaly written for html-helper,
28 ;; It will work with sgml-mode and others.
29 ;;
30 ;; http://www.santafe.edu/~nelson/hhm-beta/html-helper-mode.el
31
32 ;;; History:
33 ;;
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
38
39 ;;; Code:
40
41 (eval-when-compile (require 'imenu))
42
43 (defvar html-imenu-title "Index"
44   "*Title of the menu which will be added to the menubar.")
45
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.")
52
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
57         (toc-index '())
58         toc-str)
59     (save-excursion
60       (goto-char (point-min))
61       (save-match-data
62         (while (re-search-forward html-imenu-regexp nil t)
63           (setq toc-str
64                 (concat
65                  (make-string
66                   (* 6 (- (string-to-number (match-string 1)) 1))
67                   space)
68                  (match-string 3)))
69           (beginning-of-line)
70           (setq toc-index (cons (cons toc-str (point)) toc-index))
71           (end-of-line))))
72     (nreverse toc-index)))
73
74 (defun html-imenu-setup ()
75   "Setup the variables to support imenu."
76   (interactive)
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))
87     ))
88
89 (defun html-imenu-update-menubar (buffer)
90   (condition-case err
91       (html-imenu-update-menubar-1 buffer)
92     (error (message "html-imenu-update-menubar error: %s" err))))
93
94 (defun html-imenu-update-menubar-1 (buffer)
95   (with-current-buffer buffer
96     (message "HTML Imenu: update menubar...")
97     (imenu-update-menubar)
98     (message "")))
99
100 (provide 'html-imenu)
101 ;;; html-imenu ends here