;;; sb-w3 --- Speedbar support for w3.
;; Copyright (C) 1997, 1998 Free Software Foundation
;; Author: Eric M. Ludlam <email@example.com>
;; Version: 0.2.1
;; Keywords: tags, tools, w3
;; X-RCS: $Id$
;; 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, 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, you can either send email to this
;; program's author (see below) or write to:
;; The Free Software Foundation, Inc.
;; 675 Mass Ave.
;; Cambridge, MA 02139, USA.
;; Please send bug reports, etc. to firstname.lastname@example.org
;; Speedbar provides a frame in which files, and locations in
;; files are displayed. These functions provide w3 specific support,
;; showing links and addresses in the side-bar.
;; To enable, add this to your .emacs file.
;; (autoload 'w3-speedbar-buttons "sb-w3"
;; "W3 specific speedbar button generator.")
;; Load w3-toc to get additional tags which represent the major
;; headers in a given web page.
;; This file requires speedbar.
;;; Change log:
;; 0.1 - first revision copied from speedbspec.el V 0.1.1
;; 0.1.1 - Removed dependency on speedbspec
;; 0.2 - T.V.Raman's addition using newer w3, and w3 imenu.
;; 0.2.1 - Added new keymap support
(defvar w3-speedbar-last-buffer nil
"The last buffer shown by w3-speedbar.")
(defvar w3-speedbar-key-map nil
"Keymap used when in the w3 display mode.")
(setq w3-speedbar-key-map (speedbar-make-specialized-keymap))
;; Basic features.
(define-key w3-speedbar-key-map "e" 'speedbar-edit-line)
(define-key w3-speedbar-key-map "r" 'speedbar-edit-line)
(define-key w3-speedbar-key-map "\C-m" 'speedbar-edit-line)
'(["Jump to link" speedbar-edit-line t]
"Extra menu items for w3 mode.")
(defun w3-speedbar-buttons (buffer)
"Create speedbar buttons for the current web BUFFER displayed in w3 mode."
(if (and (looking-at "History:") (equal w3-speedbar-last-buffer buffer))
(setq w3-speedbar-last-buffer buffer)
(let ((links (save-excursion (set-buffer buffer)
(set-buffer buffer) imenu--index-alist))
;; This taken out of w3 which was used to create the history list,
;; and is here modified to create the speedbar buttons
(lambda (url desc)
(speedbar-insert-button (w3-speedbar-shorten-button url)
(setq part (car (cdr (member ':href (car links))))
links (cdr links))
(speedbar-insert-button (w3-speedbar-shorten-button part)
(if (not (featurep 'w3-imenu))
(insert (format "Contents: %d\n" (length toc)))
(loop for e in toc do
(when (car e)
(speedbar-insert-button (car e)
(defun w3-speedbar-goto-marker (txt marker indent)
"Speedbar callback function for jumping to a marker in a w3 buffer.
TXT is unused. MARKER is the location. INDENT is unused."
(pop-to-buffer (marker-buffer marker))
(goto-char (marker-position marker)))
(defun w3-speedbar-shorten-button (button)
"Takes text BUTTON and shortens it as much as possible."
;; I should make this more complex, but I'm not sure
(let ((fnnd (file-name-nondirectory button)))
(if (< 0 (length fnnd))
(if (string-match "\\(ht\\|f\\)tp://" button)
(setq button (substring button (match-end 0))))
(if (string-match "/$" button)
(setq button (substring button 0 (match-beginning 0))))
(defun w3-speedbar-link (text token indent)
"Follow link described by TEXT which has the URL TOKEN.
INDENT is not used."
(speedbar-with-attached-buffer (w3-fetch token)))
;;; sb-w3.el ends here