;;; sb-html.el --- provide hierarchical speedbar menu's for HTML files;; Copyright (c) 2001, 2002 Richard Y. Kim;; Author: Richard Y. Kim, <ryk@dspwiz.com>;; Maintainer: Richard Y. Kim, <ryk@dspwiz.com>;; Created: Mon Apr 09 09:44:06 2001;; Version: $Id$;; Keywords: speedbar, html;; This program is free software; you can redistribute it and/or;; modify it under the terms of the GNU General Public License as;; published by the Free Software Foundation; either version 2 of;; the License, or (at your option) any later version.;; This program is distributed in the hope that it will be;; useful, but WITHOUT ANY WARRANTY; without even the implied;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR;; PURPOSE. See the GNU General Public License for more details.;; You should have received a copy of the GNU General Public;; License along with this program; if not, write to the Free;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,;; MA 02111-1307 USA;;; Commentary:;;;; This small add-on to speedbar provides an alternate way to view HTML;; documents which shows the natural hierarchy of the document based;; on H1, H2, ... H6 tags.;;;; This code is a simple modification of sb-texinfo.el which comes;; with speedbar.;; Installation procedure:;;;; Install speedbar 0.12 or later.;; Add the following to your ~/.emacs file:;; (eval-after-load "speedbar" '(load-library "sb-html"));;;; Known Problems:;;;; Perhaps <HEAD> and <BODY> should be treated as H0 tag?;;; Change Log:;;;;;; 1.1 - modified regexp based on Eric's suggestion.;;;;;; 1.0 - sent to Eric Ludlam.;;; Code:(require'speedbar)(require'sb-texinfo); for speedbar-format-texinfo-list;; Attach these new functions to handle texinfo-mode.(add-to-list'speedbar-dynamic-tags-function-list'(speedbar-fetch-dynamic-html.speedbar-insert-html-list));; This returns t if the major mode of the current buffer is not;; 'html-helper-mode. If it is 'html-helper-mode, then this returns a;; list where each element is (LEVEL NAME . MARKER). LEVEL is 0, 1, 2,;; 3, 4, or 5 corresponding to H1, H2, H3, H4, H5 an H6;; tags. respectively. NAME is the name of the section. MARKER is;; emacs marker that points to the beginning of the section. The;; elements in the list returned are in ascending order of the;; MARKER. This function along with it's parter,;; speedbar-insert-html-list, are designed to be added to the;; speedbar-dynamic-tags-function-list list.;;;; This function is based on `speedbar-fetch-dynamic-texinfo'.(defunspeedbar-fetch-dynamic-html(filename)(set-buffer(find-file-noselectfilename))(if(not(or(eqmajor-mode'html-helper-mode)(eqmajor-mode'html-mode)))t(condition-casenil(save-excursion;; Set speedbar-tag-hierarchy-method to nil so that;; speedbar-create-tag-hierarchy won't reorder the list.;; Make it buffer local so that the global value is not touched.(make-local-variable'speedbar-tag-hierarchy-method)(setqspeedbar-tag-hierarchy-methodnil)(set(make-local-variable'speedbar-generic-list-group-expand-button-type)'expandtag)(set(make-local-variable'speedbar-generic-list-tag-button-type)'statictag)(let((case-fold-searcht); HTML tags are case insensitivepos-begtitlelevelalistbeg)(goto-char(point-min));; regexp below will not work if `>' appears within an attribute;; value, e.g., <h1 foo="I'm a weird value >"> ... </h1>(while(re-search-forward"<h\\([1-6]\\)\\b[^>]*>\\s-*"nilt)(setqbeg(match-end0))(goto-char(match-beginning0))(setqpos-beg(point-marker))(setqlevel(1-(read(match-string1))))(re-search-forward(concat"\\s-*</h"(match-string1)"\\b"))(setqtitle(buffer-substringbeg(match-beginning0)))(setqalist(cons(conslevel(constitlepos-beg))alist)))(nreversealist)))(errort))))(fset'speedbar-format-html-list'speedbar-format-texinfo-list)(defunspeedbar-insert-html-list(indentlst)(speedbar-insert-generic-listindent(speedbar-format-html-listlst0)'speedbar-tag-expand'speedbar-tag-find))(provide'sb-html);;; sb-html.el ends here