Commits

Anonymous committed ddc5396

Created

  • Participants
  • Tags xemacs

Comments (0)

Files changed (9)

+1998-01-03  SL Baur  <steve@altair.xemacs.org>
+
+	* Makefile: Update to newer package interface.
+
+1997-12-24  SL Baur  <steve@altair.xemacs.org>
+
+	* Makefile: Created.
+# Makefile for Speedbar lisp code
+
+# This file is part of XEmacs.
+
+# XEmacs 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.
+
+# XEmacs 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 XEmacs; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+VERSION = 1.02
+PACKAGE = speedbar
+PKG_TYPE = regular
+REQUIRES = xemacs-base
+CATEGORY = oa
+
+ELCS = sb-gud.elc sb-info.elc sb-rmail.elc sb-w3.elc speedbar.elc \
+	speedbspec.elc
+
+include ../../XEmacs.rules
+
+all:: $(ELCS) auto-autoloads.elc custom-load.elc
+
+srckit: srckit-std
+
+binkit: binkit-sourceonly

File package-info.in

+(speedbar
+  (version VERSION
+   description "??? Document me."
+   filename FILENAME
+   md5sum MD5SUM
+   size SIZE
+   provides (speedbar)
+   requires (REQUIRES)
+   type regular
+))
+;;; sb-gud --- Speedbar support for the Grand Unified Debugger
+
+;; Copyright (C) 1997 Free Software Foundation
+;;
+;; Author: Eric M. Ludlam <zappo@gnu.ai.mit.edu>
+;; Version: 0.1
+;; Keywords: tools, gud
+;; 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 zappo@gnu.ai.mit.edu.
+;;
+
+;;; Commentary:
+;;
+;;   Speedbar provides a frame in which files, and locations in
+;; files are displayed.  These functions provide gud specific support,
+;; showing stacks, files, and the like in the side-bar.
+;;
+;;   To provide special service to all the modes supported by this file,
+;; put the following in your .emacs file.
+;;
+;; (require 'speedbspec)
+;;
+;;   This will load in the known functions, and the mode-enabling code
+;; into 'change-major-mode-hook.
+;;
+;;   This file requires speedbar.
+
+;;; Change log:
+;; 0.1 - Revision
+
+(require 'speedbspec)
+
+;;; Code:
+(defvar gud-last-speedbar-buffer nil
+  "The last GUD buffer used.")
+
+(defvar gud-last-speedbar-stackframe nil
+  "Description of the currently displayed GUD stack.
+t means that there is no stack, and we are in display-file mode.")
+
+(defvar gud-speedbar-menu-items
+  ;; Note to self.  Add expand, and turn off items when not available.
+  '(["Jump to stack frame" speedbar-edit-line t])
+  "Additional menu items to add the the speedbar frame.")
+
+(defun gud-speedbar-buttons (buffer)
+  "Create a speedbar display based on the current state of GUD.
+If the GUD BUFFER is not running a supported debugger, then turn
+off the specialized speedbar mode."
+  (if (and (save-excursion (goto-char (point-min))
+			   (looking-at "Current Stack"))
+	   (equal gud-last-last-frame gud-last-speedbar-stackframe))
+      nil
+    (setq gud-last-speedbar-buffer buffer)
+    (let* ((ff (save-excursion (set-buffer buffer) gud-find-file))
+	   ;;(lf (save-excursion (set-buffer buffer) gud-last-last-frame))
+	   (frames
+	    (cond ((eq ff 'gud-gdb-find-file)
+		   (gud-gdb-get-stackframe buffer)
+		   )
+		  ;; Add more debuggers here!
+		  (t
+		   (speedbar-remove-localized-speedbar-support buffer)
+		   nil))))
+      (erase-buffer)
+      (if (not frames)
+	  (insert "No Stack frames\n")
+	(insert "Current Stack:\n"))
+      (while frames
+	(insert (nth 1 (car frames)) ":\n")
+	(if (= (length (car frames)) 2)
+	    (progn
+;	      (speedbar-insert-button "[?]"
+;				      'speedbar-button-face
+;				      nil nil nil t)
+	      (speedbar-insert-button (car (car frames))
+				      'speedbar-directory-face
+				      nil nil nil t))
+;	  (speedbar-insert-button "[+]"
+;				  'speedbar-button-face
+;				  'speedbar-highlight-face
+;				  'gud-gdb-get-scope-data
+;				  (car frames) t)
+	  (speedbar-insert-button (car (car frames))
+				  'speedbar-file-face
+				  'speedbar-highlight-face
+				  (cond ((eq ff 'gud-gdb-find-file)
+					 'gud-gdb-goto-stackframe)
+					(t (error "Should never be here.")))
+				  (car frames) t))
+	(setq frames (cdr frames)))
+      (let ((selected-frame
+	     (cond ((eq ff 'gud-gdb-find-file)
+		    (gud-gdb-selected-frame-info buffer))
+		   (t (error "Should never be here.")))))))
+    (setq gud-last-speedbar-stackframe gud-last-last-frame)))
+
+(defun gud-gdb-goto-stackframe (text token indent)
+  "Goto the stackframe described by TEXT, TOKEN, and INDENT."
+  (speedbar-with-attached-buffer
+   (gud-basic-call (concat "frame " (nth 1 token)))
+   (sit-for 1)))
+
+(defvar gud-gdb-fetched-stack-frame nil
+  "Stack frames we are fetching from GDB.")
+
+(defvar gud-gdb-fetched-stack-frame-list nil
+  "List of stack frames we are fetching from GDB.")
+
+;(defun gud-gdb-get-scope-data (text token indent)
+;  ;; checkdoc-params: (indent)
+;  "Fetch data associated with a stack frame, and expand/contract it.
+;Data to do this is retrieved from TEXT and TOKEN."
+;  (let ((args nil) (scope nil))
+;    (gud-gdb-run-command-fetch-lines "info args")
+;
+;    (gud-gdb-run-command-fetch-lines "info local")
+;
+;    ))
+
+(defun gud-gdb-get-stackframe (buffer)
+  "Extract the current stack frame out of the GUD GDB BUFFER."
+  (let ((newlst nil)
+	(gud-gdb-fetched-stack-frame-list nil))
+    (gud-gdb-run-command-fetch-lines "backtrace" buffer)
+    (if (string-match "No stack" (car gud-gdb-fetched-stack-frame-list))
+	;; Go into some other mode???
+	nil
+      (while gud-gdb-fetched-stack-frame-list
+	(let ((e (car gud-gdb-fetched-stack-frame-list))
+	      (name nil) (num nil))
+	  (if (not (or
+		    (string-match "^#\\([0-9]+\\) +[0-9a-fx]+ in \\([0-9a-zA-Z_]+\\) (" e)
+		    (string-match "^#\\([0-9]+\\) +\\([0-9a-zA-Z_]+\\) (" e)))
+	      (if (not (string-match
+			"at \\([-0-9a-zA-Z_.]+\\):\\([0-9]+\\)$" e))
+		  nil
+		(setcar newlst
+			(list (nth 0 (car newlst))
+			      (nth 1 (car newlst))
+			      (match-string 1 e)
+			      (match-string 2 e))))
+	    (setq num (match-string 1 e)
+		  name (match-string 2 e))
+	    (setq newlst
+		  (cons
+		   (if (string-match
+			"at \\([-0-9a-zA-Z_.]+\\):\\([0-9]+\\)$" e)
+		       (list name num (match-string 1 e)
+			     (match-string 2 e))
+		     (list name num))
+		   newlst))))
+	(setq gud-gdb-fetched-stack-frame-list
+	      (cdr gud-gdb-fetched-stack-frame-list)))
+      (nreverse newlst))))
+
+;(defun gud-gdb-selected-frame-info (buffer)
+;  "Learn GDB information for the currently selected stack frame in BUFFER."
+;  )
+
+(defun gud-gdb-run-command-fetch-lines (command buffer)
+  "Run COMMAND, and return when `gud-gdb-fetched-stack-frame-list' is full.
+BUFFER is the GUD buffer in which to run the command."
+  (save-excursion
+    (set-buffer buffer)
+    (if (save-excursion
+	  (goto-char (point-max))
+	  (beginning-of-line)
+	  (not (looking-at comint-prompt-regexp)))
+	nil
+      ;; Much of this copied from GDB complete, but I'm grabbing the stack
+      ;; frame instead.
+      (let ((gud-marker-filter 'gud-gdb-speedbar-stack-filter))
+	;; Issue the command to GDB.
+	(gud-basic-call command)
+	(setq gud-gdb-complete-in-progress t ;; use this flag for our purposes.
+	      gud-gdb-complete-string nil
+	      gud-gdb-complete-list nil)
+	;; Slurp the output.
+	(while gud-gdb-complete-in-progress
+	  (accept-process-output (get-buffer-process gud-comint-buffer)))
+	(setq gud-gdb-fetched-stack-frame nil
+	      gud-gdb-fetched-stack-frame-list
+	      (nreverse gud-gdb-fetched-stack-frame-list))))))
+  
+(defun gud-gdb-speedbar-stack-filter (string)
+  ;; checkdoc-params: (string)
+  "Filter used to read in the current GDB stack."
+  (setq string (concat gud-gdb-fetched-stack-frame string))
+  (while (string-match "\n" string)
+    (setq gud-gdb-fetched-stack-frame-list
+	  (cons (substring string 0 (match-beginning 0))
+		gud-gdb-fetched-stack-frame-list))
+    (setq string (substring string (match-end 0))))
+  (if (string-match comint-prompt-regexp string)
+      (progn
+	(setq gud-gdb-complete-in-progress nil)
+	string)
+    (progn
+      (setq gud-gdb-complete-string string)
+      "")))
+
+(provide 'sb-gud)
+;;; sb-gud.el ends here
+;;; sb-info --- Speedbar support for Info
+
+;; Copyright (C) 1997 Free Software Foundation
+;;
+;; Author: Eric M. Ludlam <zappo@gnu.ai.mit.edu>
+;; Version: 0.1
+;; Keywords: file, tags, tools
+;; 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 zappo@gnu.ai.mit.edu.
+;;
+
+;;; Commentary:
+;;
+;;   Speedbar provides a frame in which files, and locations in
+;; files are displayed.  These functions provide Info specific support,
+;; showing links and addresses in the side-bar.
+;;
+;;   To provide special service to all the modes supported by this file,
+;; put the following in your .emacs file.
+;;
+;; (require 'speedbspec)
+;;
+;;   This will load in the known functions, and the mode-enabling code
+;; into 'change-major-mode-hook.
+;;
+;;   This file requires speedbar.
+
+;;; Change log:
+;; 0.1 - first revision copied from speedbspec.el V 0.1.1
+
+(require 'speedbspec)
+
+;;; Code:
+(defvar Info-last-speedbar-node nil
+  "Last node viewed with speedbar in the form '(NODE FILE).")
+
+(defvar Info-speedbar-menu-items
+  '(["Browse Item On Line" speedbar-edit-line t])
+  "Additional menu-items to add to speedbar frame.")
+
+(defun Info-speedbar-buttons (buffer)
+  "Create a speedbar display to help navigation in an Info file.
+BUFFER is the buffer speedbar is requesting buttons for."
+  (goto-char (point-min))
+  (if (and (looking-at "<Directory>")
+	   (save-excursion
+	     (set-buffer buffer)
+	     (and (equal (car Info-last-speedbar-node) Info-current-node)
+		  (equal (cdr Info-last-speedbar-node) Info-current-file))))
+      nil
+    (erase-buffer)
+    (speedbar-insert-button "<Directory>" 'info-xref 'highlight
+			    'Info-speedbar-button
+			    'Info-directory)
+    (speedbar-insert-button "<Top>" 'info-xref 'highlight
+			    'Info-speedbar-button
+			    'Info-top-node)
+    (speedbar-insert-button "<Last>" 'info-xref 'highlight
+			    'Info-speedbar-button
+			    'Info-last)
+    (speedbar-insert-button "<Up>" 'info-xref 'highlight
+			    'Info-speedbar-button
+			    'Info-up)
+    (speedbar-insert-button "<Next>" 'info-xref 'highlight
+			    'Info-speedbar-button
+			    'Info-next)
+    (speedbar-insert-button "<Prev>" 'info-xref 'highlight
+			    'Info-speedbar-button
+			    'Info-prev)
+    (let ((completions nil))
+      (save-excursion
+	(set-buffer buffer)
+	(setq Info-last-speedbar-node
+	      (cons Info-current-node Info-current-file))
+	(goto-char (point-min))
+	;; Always skip the first one...
+	(re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
+	(while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
+	  (setq completions (cons (buffer-substring (match-beginning 1)
+						    (match-end 1))
+				  completions))))
+      (setq completions (nreverse completions))
+      (while completions
+	(speedbar-make-tag-line nil nil nil nil
+				(car completions) 'Info-speedbar-menu
+				nil 'info-node 0)
+	(setq completions (cdr completions))))))
+
+(defun Info-speedbar-button (text token indent)
+  "Called when user clicks <Directory> from speedbar.
+TEXT, TOKEN, and INDENT are unused."
+  (speedbar-with-attached-buffer
+   (funcall token)
+   (setq Info-last-speedbar-node nil)
+   (speedbar-update-contents)))
+
+(defun Info-speedbar-menu (text token indent)
+  "Goto the menu node specified in TEXT.
+TOKEN and INDENT are not used."
+  (speedbar-with-attached-buffer
+   (Info-menu text)
+   (setq Info-last-speedbar-node nil)
+   (speedbar-update-contents)))
+
+(provide 'sb-info)
+;;; sb-info.el ends here
+;;; sb-rmail --- Speedbar support for rmail
+
+;; Copyright (C) 1997 Free Software Foundation
+;;
+;; Author: Eric M. Ludlam <zappo@gnu.ai.mit.edu>
+;; Version: 0.1
+;; Keywords: file, tags, tools
+;; 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 zappo@gnu.ai.mit.edu.
+;;
+
+;;; Commentary:
+;;
+;;   Speedbar provides a frame in which files, and locations in
+;; files are displayed.  These functions provide rmail specific support,
+;; showing links and addresses in the side-bar.
+;;
+;;   To provide special service to all the modes supported by this file,
+;; put the following in your .emacs file.
+;;
+;; (require 'speedbspec)
+;;
+;;   This will load in the known functions, and the mode-enabling code
+;; into 'change-major-mode-hook.
+;;
+;;   This file requires speedbar.
+
+;;; Change log:
+;; 0.1 - first revision copied from speedbspec.el V 0.1.1
+
+(require 'speedbspec)
+
+;;; Code:
+(defvar rmail-speedbar-last-user nil
+  "The last user to be displayed in the speedbar.")
+
+(defvar rmail-speedbar-menu-items
+  '(["Browse Item On Line" speedbar-edit-line t]
+    ["Move message to folder" rmail-move-message-to-folder-on-line
+     (save-excursion (beginning-of-line)
+		     (looking-at "<M> "))])
+  "Additional menu-items to add to speedbar frame.")
+
+(defun rmail-speedbar-buttons (buffer)
+  "Create buttons for BUFFER containing rmail messages.
+Click on the address under Reply to: to reply to this person.
+Under Folders: Click a name to read it, or on the <M> to move the
+current message into that RMAIL folder."
+  (let ((from nil))
+    (save-excursion
+      (set-buffer buffer)
+      (goto-char (point-min))
+      (if (not (re-search-forward "^Reply-To: " nil t))
+	  (if (not (re-search-forward "^From:? " nil t))
+	      (setq from t)))
+      (if from
+	  nil
+	(setq from (buffer-substring (point) (save-excursion
+					       (end-of-line)
+					       (point))))))
+    (goto-char (point-min))
+    (if (and (looking-at "Reply to:")
+	     (equal from rmail-speedbar-last-user))
+	nil
+      (setq rmail-speedbar-last-user from)
+      (erase-buffer)
+      (insert "Reply To:\n")
+      (if (stringp from)
+	  (speedbar-insert-button from 'speedbar-directory-face 'highlight
+				  'rmail-speedbar-button 'rmail-reply))
+      (insert "Folders:\n")
+      (let* ((case-fold-search nil)
+	     (df (directory-files (save-excursion (set-buffer buffer)
+						  default-directory)
+				  nil "^[A-Z0-9]+\\(\\.[A-Z0-9]+\\)?$")))
+	(while df
+	  (speedbar-insert-button "<M>" 'speedbar-button-face 'highlight
+				  'rmail-speedbar-move-message (car df))
+	  (speedbar-insert-button (car df) 'speedbar-file-face 'highlight
+				  'rmail-speedbar-find-file nil t)
+	  (setq df (cdr df)))))))
+
+(defun rmail-speedbar-button (text token indent)
+  "Execute an rmail command specified by TEXT.
+The command used is TOKEN.  INDENT is not used."
+  (speedbar-with-attached-buffer
+   (funcall token t)))
+
+(defun rmail-speedbar-find-file (text token indent)
+  "Load in the rmail file TEXT.
+TOKEN and INDENT are not used."
+  (speedbar-with-attached-buffer
+   (message "Loading in RMAIL file %s..." text)
+   (find-file text)))
+
+(defun rmail-move-message-to-folder-on-line ()
+  "If the current line is a folder, move current message to it."
+  (interactive)
+  (save-excursion
+    (beginning-of-line)
+    (if (re-search-forward "<M> " (save-excursion (end-of-line) (point)) t)
+	(progn
+	  (forward-char -2)
+	  (speedbar-do-function-pointer)))))
+
+(defun rmail-speedbar-move-message (text token indent)
+  "From button TEXT, copy current message to the rmail file specified by TOKEN.
+TEXT and INDENT are not used."
+  (speedbar-with-attached-buffer
+   (message "Moving message to %s" token)
+   (rmail-output-to-rmail-file token)))
+
+(provide 'sb-rmail)
+;;; sb-rmail.el ends here
+;;; sb-w3 --- Speedbar support for w3.
+
+;; Copyright (C) 1997 Free Software Foundation
+;;
+;; Author: Eric M. Ludlam <zappo@gnu.ai.mit.edu>
+;; Version: 0.1
+;; Keywords: file, tags, tools
+;; 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 zappo@gnu.ai.mit.edu.
+;;
+
+;;; Commentary:
+;;
+;;   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 provide special service to all the modes supported by this file,
+;; put the following in your .emacs file.
+;;
+;; (require 'speedbspec)
+;;
+;;   This will load in the known functions, and the mode-enabling code
+;; into 'change-major-mode-hook.
+;;
+;;   This file requires speedbar.
+
+;;; Change log:
+;; 0.1 - first revision copied from speedbspec.el V 0.1.1
+
+(require 'speedbspec)
+
+;;; Code:
+(defvar w3-speedbar-last-buffer nil
+  "The last buffer shown by w3-speedbar.")
+
+(defun w3-speedbar-buttons (buffer)
+  "Create speedbar buttons for the current web BUFFER displayed in w3 mode."
+  (save-excursion
+    (goto-char (point-min))
+    (if (and (looking-at "History:") (equal w3-speedbar-last-buffer buffer))
+	nil
+      (setq w3-speedbar-last-buffer buffer)
+      (erase-buffer)
+      (let ((links (save-excursion (set-buffer buffer) (w3-only-links)))
+	    (part nil))
+	(insert "History:\n")
+	;; This taken out of w3 which was used to create the history list,
+	;; and is here modified to create the speedbar buttons
+	(cl-maphash
+	 (function
+	  (lambda (url desc)
+	    (speedbar-insert-button (w3-speedbar-shorten-button url)
+				    'speedbar-directory-face 'highlight
+				    'w3-speedbar-link url)))
+	 url-history-list)
+	(insert "Links:\n")
+	(while links
+	  (setq part (car (cdr (member 'href (car links))))
+		links (cdr links))
+	  (speedbar-insert-button (w3-speedbar-shorten-button part)
+				  'speedbar-file-face 'highlight
+				  'w3-speedbar-link part))))))
+    
+(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 how...
+  (let ((fnnd (file-name-nondirectory button)))
+    (if (< 0 (length fnnd))
+	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))))
+      button)))
+
+(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)))
+
+
+(provide 'sb-w3)
+;;; sb-w3.el ends here
+;;; speedbar --- quick access to files and tags -*-byte-compile-warnings:nil;-*-
+
+;;; Copyright (C) 1996, 97 Free Software Foundation
+;;
+;; Author: Eric M. Ludlam <zappo@gnu.ai.mit.edu>
+;; Version: 0.5.4-x
+;; Keywords: file, tags, tools
+;; 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 zappo@gnu.ai.mit.edu.
+;;
+
+;;; Commentary:
+;;
+;;   To use speedbar, simply type `M-x speedbar', and it will be
+;;   autoloaded for you.  A "Speedbar" submenu will be added under
+;;   "Tools".
+;;
+;;   The speedbar provides a frame in which files, and locations in
+;; files are displayed.  These items can be clicked on with mouse-2
+;; in order to make the last active frame display that file location.
+;;
+;;   If you want to choose Speedbar from a menu, you can do something
+;; like this:
+;;
+;;   (add-menu-button '("Buffers")
+;;		      ["Speedbar" speedbar-frame-mode
+;;		       :style toggle
+;;		       :selected (and (boundp 'speedbar-frame)
+;;				      (frame-live-p speedbar-frame)
+;;				      (frame-visible-p speedbar-frame))]
+;;		      "--")
+;;
+;;
+;;   If you want to access speedbar using only the keyboard, do this:
+;;
+;;   (global-set-key [f4] 'speedbar-get-focus)
+;;
+;;   This will let you hit f4 (or whatever key you choose) to jump
+;; focus to the speedbar frame.  Pressing RET or e to jump to a file
+;; or tag will move you back to the attached frame.  The command
+;; `speedbar-get-focus' will also create a speedbar frame if it does
+;; not exist.
+;;
+;;   Once a speedbar frame is active, it takes advantage of idle time
+;; to keep its contents updated.  The contents is usually a list of
+;; files in the directory of the currently active buffer.  When
+;; applicable, tags in the active file can be expanded.
+;;
+;;   To add new supported files types into speedbar, use the function
+;; `speedbar-add-supported-extension' If speedbar complains that the
+;; file type is not supported, that means there is no built in
+;; support from imenu, and the etags part wasn't set up correctly.  You
+;; may add elements to `speedbar-supported-extension-expressions' as long
+;; as it is done before speedbar is loaded.
+;;
+;;   To prevent speedbar from following you into certain directories
+;; use the function `speedbar-add-ignored-path-regexp' too add a new
+;; regular expression matching a type of path.  You may add list
+;; elements to `speedbar-ignored-path-expressions' as long as it is
+;; done before speedbar is loaded.
+;;
+;;   To add new file types to imenu, see the documentation in the
+;; file imenu.el that comes with emacs.  To add new file types which
+;; etags supports, you need to modify the variable
+;; `speedbar-fetch-etags-parse-list'.
+;;
+;;    If the updates are going too slow for you, modify the variable
+;; `speedbar-update-speed' to a longer idle time before updates.
+;;
+;;    If you navigate directories, you will probably notice that you
+;; will navigate to a directory which is eventually replaced after
+;; you go back to editing a file (unless you pull up a new file.)
+;; The delay time before this happens is in
+;; `speedbar-navigating-speed', and defaults to 10 seconds.
+;;
+;;    Users of emacs previous to to v 19.31 (when idle timers
+;; where introduced) will not have speedbar updating automatically.
+;; Use "r" to refresh the display after changing directories.
+;; Remember, do not interrupt the stealthy updates or you display may
+;; not be completely refreshed.
+;;
+;;    See optional file `speedbspec.el' for additional configurations
+;; which allow speedbar to create specialized lists for special modes
+;; that are not file-related.
+;;
+;;    See optional file `speedbcfg.el' for interactive buffers
+;; allowing simple configuration of colors and features of speedbar.
+;;
+;;    AUC-TEX users: The imenu tags for AUC-TEX mode don't work very
+;; well.  Use the imenu keywords from tex-mode.el for better results.
+;;
+;; This file requires the library package assoc (association lists)
+
+;;; Speedbar updates can be found at:
+;; ftp://ftp.ultranet.com/pub/zappo/speedbar*.tar.gz
+;;
+
+;;; Change log:
+;; 0.1   Initial Revision
+;; 0.2   Fixed problem with x-pointer-shape causing future frames not
+;;         to be created.
+;;       Fixed annoying habit of `speedbar-update-contents' to make
+;;         it possible to accidentally kill the speedbar buffer.
+;;       Clicking directory names now only changes the contents of
+;;         the speedbar, and does not cause a dired mode to appear.
+;;         Clicking the <+> next to the directory does cause dired to
+;;         be run.
+;;       Added XEmacs support, which means timer support moved to a
+;;         platform independant call.
+;;       Added imenu support.  Now modes are supported by imenu
+;;         first, and etags only if the imenu call doesn't work.
+;;         Imenu is a little faster than etags, and is more emacs
+;;         friendly.
+;;       Added more user control variables described in the commentary.
+;;       Added smart recentering when nodes are opened and closed.
+;; 0.3   x-pointer-shape fixed for emacs 19.35, so I put that check in.
+;;       Added invisible codes to the beginning of each line.
+;;       Added list aproach to node expansion for easier addition of new
+;;         types of things to expand by
+;;       Added multi-level path name support
+;;       Added multi-level tag name support.
+;;       Only mouse-2 is now used for node expansion
+;;       Added keys e + - to edit expand, and contract node lines
+;;       Added longer legal file regexp for all those modes which support
+;;         imenu. (pascal, fortran90, ada, pearl)
+;;       Added pascal support to etags from Dave Penkler <dave_penkler@grenoble.hp.com>
+;;       Fixed centering algorithm
+;;       Tried to choose background independent colors.  Made more robust.
+;;       Rearranged code into a more logical order
+;; 0.3.1 Fixed doc & broken keybindings
+;;       Added mode hooks.
+;;       Improved color selection to be background mode smart
+;;       `nil' passed to `speedbar-frame-mode' now toggles the frame as
+;;         advertised in the doc string
+;; 0.4a  Added modified patch from Dan Schmidt <dfan@lglass.com> allowing a
+;;         directory cache to be maintained speeding up revisiting of files.
+;;       Default raise-lower behavior is now off by default.
+;;       Added some menu items for edit expand and contract.
+;;       Pre 19.31 emacsen can run without idle timers.
+;;       Added some patch information from Farzin Guilak <farzin@protocol.com>
+;;         adding xemacs specifics, and some etags upgrades.
+;;       Added ability to set a faces symbol-value to a string
+;;         representing the desired foreground color.  (idea from
+;;         Farzin Guilak, but implemented differently)
+;;       Fixed problem with 1 character buttons.
+;;       Added support for new Imenu marker technique.
+;;       Added `speedbar-load-hooks' for things to run only once on
+;;         load such as updating one of the many lists.
+;;       Added `speedbar-supported-extension-expressions' which is a
+;;         list of extensions that speedbar will tag.  This variable
+;;         should only be updated with `speedbar-add-supported-extension'
+;;       Moved configure dialog support to a separate file so
+;;         speedbar is not dependant on eieio to run
+;;       Fixed list-contraction problem when the item was at the end
+;;         of a sublist.
+;;       Fixed XEmacs multi-frame timer selecting bug problem.
+;;       Added `speedbar-ignored-modes' which is a list of major modes
+;;         speedbar will not follow when it is displayed in the selected frame
+;; 0.4   When the file being edited is not in the list, and is a file
+;;         that should be in the list, the speedbar cache is replaced.
+;;       Temp buffers are now shown in the attached frame not the
+;;         speedbar frame
+;;       New variables `speedbar-vc-*' and `speedbar-stealthy-function-list'
+;;         added.  `speedbar-update-current-file' is now a member of
+;;         the stealthy list.  New function `speedbar-check-vc' will
+;;         examine each file and mark it if it is checked out.  To
+;;         add new version control types, override the function
+;;         `speedbar-this-file-in-vc' and `speedbar-vc-check-dir-p'.
+;;         The stealth list is interruptible so that long operations
+;;         do not interrupt someones editing flow.  Other long
+;;         speedbar updates will be added to the stealthy list in the
+;;         future should interesting ones be needed.
+;;       Added many new functions including:
+;;         `speedbar-item-byte-compile' `speedbar-item-load'
+;;         `speedbar-item-copy' `speedbar-item-rename' `speedbar-item-delete'
+;;         and `speedbar-item-info'
+;;       If the user kills the speedbar buffer in some way, the frame will
+;;         be removed.
+;; 0.4.1 Bug fixes
+;;       <mark.jeffries@nomura.co.uk> added `speedbar-update-flag',
+;;         XEmacs fixes for menus, and tag sorting, and quit key.
+;;       Modeline now updates itself based on window-width.
+;;       Frame is cached when closed to make pulling it up again faster.
+;;       Speedbars window is now marked as dedicated.
+;;       Added bindings: <grossjoh@charly.informatik.uni-dortmund.de>
+;;       Long directories are now span multiple lines autmoatically
+;;       Added `speedbar-directory-button-trim-method' to specify how to
+;;         sorten the directory button to fit on the screen.
+;; 0.4.2 Add one level of full-text cache.
+;;       Add `speedbar-get-focus' to switchto/raise the speedbar frame.
+;;       Editing thing-on-line will auto-raise the attached frame.
+;;       Bound `U' to `speedbar-up-directory' command.
+;;       Refresh will now maintain all subdirectories that were open
+;;        when the refresh was requested.  (This does not include the
+;;        tags, only the directories)
+;; 0.4.3 Bug fixes
+;; 0.4.4 Added `speedbar-ignored-path-expressions' and friends.
+;;       Configuration menu items not displayed if dialog-mode not present
+;;       Speedbar buffer now starts with a space, and is not deleted
+;;        ewhen the speedbar frame is closed.  This prevents the invisible
+;;        frame from preventing buffer switches with other buffers.
+;;       Fixed very bad bug in the -add-[extension|path] functions.
+;;       Added `speedbar-find-file-in-frame' which will always pop up a frame
+;;        that is already display a buffer selected in the speedbar buffer.
+;;       Added S-mouse2 as "power click" for always poping up a new frame.
+;;        and always rescanning with imenu (ditching the imenu cache), and
+;;        always rescanning directories.
+;; 0.4.5 XEmacs bugfixes and enhancements.
+;;       Window Title simplified.
+;; 0.4.6 Fixed problems w/ dedicated minibuffer frame.
+;;       Fixed errors reported by checkdoc.
+;; 0.5   Mode-specific contents added.  Controlled w/ the variable
+;;         `speedbar-mode-specific-contents-flag'.  See speedbspec
+;;         for info on enabling this feature.
+;;       `speedbar-load-hook' name change and pointer check against
+;;         major-mode.  Suggested by Sam Steingold <sds@ptc.com>
+;;       Quit auto-selects the attached frame.
+;;       Ranamed `speedbar-do-updates' to `speedbar-update-flag'
+;;       Passes checkdoc.
+;; 0.5.1 Advice from ptype@dra.hmg.gb:
+;;          Use `post-command-idle-hook' in older emacsen
+;;         `speedbar-sort-tags' now works with imenu.
+;;          Unknown files (marked w/ ?) can now be operated on w/
+;;            file commands.
+;;       `speedbar-vc-*-hook's for easilly adding new version control systems.
+;;       Checkin/out w/ vc will reset the scanners and update the * marker.
+;;       Fixed ange-ftp require compile time problem.
+;;       Fixed XEmacs menu bar bug.
+;;       Added `speedbar-activity-change-focus-flag' to control if the
+;;         focus changes w/ mouse events.
+;;       Added `speedbar-sort-tags' toggle to the menubar.
+;;       Added `speedbar-smart-directory-expand-flag' to toggle how
+;;         new directories might be inserted into the speedbar hierarchy.
+;;       Added `speedbar-visiting-[tag|file]hook' which is called whenever
+;;         speedbar pulls up a file or tag in the attached frame.  Setting
+;;         this to `reposition-window' will do nice things to function tags.
+;;       Fixed text-cache default-directory bug.
+;;       Emacs 20 char= support.
+;; 0.5.2 Customization
+;;         For older emacsen, you will need to download the new defcustom
+;;         package to get nice faces for speedbar
+;;       mouse1 Double-click is now the same as middle click.
+;;       No mouse pointer shape stuff for XEmacs (is there any?)
+;; 0.5.3 Regressive support for non-custom enabled emacsen.
+;;       Fixed serious problem w/ 0.5.2 and ignored paths.
+;;       `condition-case' no longer used in timer fcn.
+;;       `speedbar-edit-line' is now smarter w/ special modes.
+;; 0.5.4 Fixed more problems for Emacs 20 so speedbar loads correctly.
+;;       Updated some documentation strings.
+;;       Added customization menu item, and customized some more variables.
+
+;;; TODO:
+;; - More functions to create buttons and options
+;; - filtering algorithms to reduce the number of tags/files displayed.
+;; - Timeout directories we haven't visited in a while.
+;; - Remeber tags when refreshing the display.  (Refresh tags too?)
+;; - More 'special mode support.
+;; - C- Mouse 3 menu too much indirection
+
+(require 'assoc)
+(require 'easymenu)
+
+;; From custom web page for compatibility between versions of custom:
+(eval-and-compile
+  (condition-case ()
+      (require 'custom)
+    (error nil))
+  (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
+      nil ;; We've got what we needed
+    ;; We have the old custom-library, hack around it!
+    (defmacro defgroup (&rest args)
+      nil)
+    (defmacro defface (var values doc &rest args)
+      (` (progn
+	   (defvar (, var) (quote (, var)))
+	   ;; To make colors for your faces you need to set your .Xdefaults
+	   ;; or set them up ahead of time in your .emacs file.
+	   (make-face (, var))
+	   )))
+    (defmacro defcustom (var value doc &rest args)
+      (` (defvar (, var) (, value) (, doc))))))
+
+;; customization stuff
+(defgroup speedbar nil
+  "File and tag browser frame."
+  :group 'tools
+  :group 'tags)
+
+(defgroup speedbar-faces nil
+  "Faces used in speedbar."
+  :prefix "speedbar-"
+  :group 'speedbar
+  :group 'faces)
+
+(defgroup speedbar-vc nil
+  "Version control display in speedbar."
+  :prefix "speedbar-"
+  :group 'speedbar)
+
+;;; Code:
+(defvar speedbar-xemacsp (string-match "XEmacs" emacs-version)
+  "Non-nil if we are running in the XEmacs environment.")
+
+;; compatibility
+;; #### I don't understand this.  If this aims to be compatible with
+;; XEmacs 20 (FSFmacs doesn't have char=), then I don't see the point,
+;; because `=' works with characters.  --hniksic
+;(if (fboundp 'char=)
+;    (defalias 'speedbar-char= 'char=)
+;  (defalias 'speedbar-char= '=))
+
+(defvar speedbar-initial-expansion-list
+  '(speedbar-directory-buttons speedbar-default-directory-list)
+  "List of functions to call to fill in the speedbar buffer.
+Whenever a top level update is issued all functions in this list are
+run.  These functions will always get the default directory to use
+passed in as the first parameter, and a 0 as the second parameter.
+The 0 indicates the uppermost indentation level.  They must assume
+that the cursor is at the position where they start inserting
+buttons.")
+
+(defvar speedbar-stealthy-function-list
+  '(speedbar-update-current-file speedbar-check-vc)
+  "List of functions to periodically call stealthily.
+Each function must return nil if interrupted, or t if completed.
+Stealthy functions which have a single operation should always return
+t.  Functions which take a long time should maintain a state (where
+they are in their speedbar related calculations) and permit
+interruption.  See `speedbar-check-vc' as a good example.")
+
+(defcustom speedbar-mode-specific-contents-flag t
+  "*Non-nil means speedbar will show special-mode contents.
+This permits some modes to create customized contents for the speedbar
+frame."
+  :group 'speedbar
+  :type 'boolean)
+
+(defvar speedbar-special-mode-expansion-list nil
+  "Mode specific list of functions to call to fill in speedbar.
+Some modes, such as Info or RMAIL, do not relate quite as easily into
+a simple list of files.  When this variable is non-nil and buffer-local,
+then these functions are used, creating specialized contents.  These
+functions are called each time the speedbar timer is called.  This
+allows a mode to update its contents regularly.
+
+  Each function is called with the default and frame belonging to
+speedbar, and with one parameter; the buffer requesting
+the speedbar display.")
+
+(defcustom speedbar-visiting-file-hook nil
+  "Hooks run when speedbar visits a file in the selected frame."
+  :group 'speedbar
+  :type 'hook)
+
+(defcustom speedbar-visiting-tag-hook nil
+  "Hooks run when speedbar visits a tag in the selected frame."
+  :group 'speedbar
+  :type 'hook)
+
+(defcustom speedbar-load-hook nil
+  "Hooks run when speedbar is loaded."
+  :group 'speedbar
+  :type 'hook)
+
+(defcustom speedbar-show-unknown-files nil
+  "*Non-nil show files we can't expand with a ? in the expand button.
+nil means don't show the file in the list."
+  :group 'speedbar
+  :type 'boolean)
+
+;; XEmacs: setting this to 1 is two obtrusive in our implementation.
+(defcustom speedbar-update-speed 2
+  "*Idle time in seconds needed before speedbar will update itself.
+Updates occur to allow speedbar to display directory information
+relevant to the buffer you are currently editing."
+  :group 'speedbar
+  :type 'integer)
+
+(defcustom speedbar-navigating-speed 10
+  "*Idle time to wait after navigation commands in speedbar are executed.
+Navigation commands included expanding/contracting nodes, and moving
+between different directories."
+  :group 'speedbar
+  :type 'integer)
+
+;; I won't enable the code to support the old variable, because there
+;; have simply been too many changes.
+;(and (boundp 'speedbar-frame-parameters)
+;     (not (boundp 'speedbar-frame-plist))
+;     ;; #### Should use custom instead of setq.
+;     (setq speedbar-frame-plist
+;	   (alist-to-plist speedbar-frame-parameters)))
+
+(defcustom speedbar-frame-plist
+  '(minibuffer nil width 20 border-width 0
+    internal-border-width 0 unsplittable t
+    default-toolbar-visible-p nil has-modeline-p nil
+    ;; I don't see the particular value of these three, but...
+    text-pointer-glyph [cursor-font :data "top_left_arrow"]
+    nontext-pointer-glyph [cursor-font :data "top_left_arrow"]
+    selection-pointer-glyph [cursor-font :data "hand2"])
+  "*Parameters to use when creating the speedbar frame.
+Parameters not listed here which will be added automatically are
+`height' which will be initialized to the height of the frame speedbar
+is attached to."
+  :group 'speedbar
+  :type '(repeat (group :inline t
+			(symbol :tag "Property")
+			(sexp :tag "Value"))))
+
+(defcustom speedbar-use-imenu-flag (stringp (locate-library "imenu"))
+  "*Non-nil means use imenu for file parsing.  nil to use etags.
+Etags support is not as robust as imenu support."
+  :tag "Use Imenu"
+  :group 'speedbar
+  :type 'boolean)
+
+(defcustom speedbar-sort-tags nil
+  "*If Non-nil, sort tags in the speedbar display."
+  :group 'speedbar
+  :type 'boolean)
+
+(defcustom speedbar-activity-change-focus-flag nil
+  "*Non-nil means the selected frame will change based on activity.
+Thus, if a file is selected for edit, the buffer will appear in the
+selected frame and the focus will change to that frame."
+  :group 'speedbar
+  :type 'boolean)
+
+(defcustom speedbar-directory-button-trim-method 'span
+  "*Indicates how the directory button will be displayed.
+Possible values are:
+ 'span - span large directories over multiple lines.
+ 'trim - trim large directories to only show the last few.
+ nil   - no trimming."
+  :group 'speedbar
+  :type '(radio (const :tag "Span large directories over mutiple lines."
+		       span)
+		(const :tag "Trim large directories to only show the last few."
+		       trim)
+		(const :tag "No trimming." nil)))
+
+(defcustom speedbar-smart-directory-expand-flag t
+  "*Non-nil means speedbar should use smart expansion.
+Smart expansion only affects when speedbar wants to display a
+directory for a file in the attached frame.  When smart expansion is
+enabled, new directories which are children of a displayed directory
+are expanded in the current framework.  If nil, then the current
+heirarchy would be replaced with the new directory."
+  :group 'speedbar
+  :type 'boolean)
+
+(defcustom speedbar-before-popup-hook nil
+  "*Hooks called before popping up the speedbar frame."
+  :group 'speedbar
+  :type 'hook)
+
+(defcustom speedbar-before-delete-hook nil
+  "*Hooks called before deleting the speedbar frame."
+  :group 'speedbar
+  :type 'hook)
+
+(defcustom speedbar-mode-hook nil
+  "*Hooks called after creating a speedbar buffer."
+  :group 'speedbar
+  :type 'hook)
+
+(defcustom speedbar-timer-hook nil
+  "*Hooks called after running the speedbar timer function."
+  :group 'speedbar
+  :type 'hook)
+
+(defcustom speedbar-verbosity-level 1
+  "*Verbosity level of the speedbar.  0 means say nothing.
+1 means medium level verbosity.  2 and higher are higher levels of
+verbosity."
+  :group 'speedbar
+  :type 'integer)
+
+(defcustom speedbar-vc-do-check t
+  "*Non-nil check all files in speedbar to see if they have been checked out.
+Any file checked out is marked with `speedbar-vc-indicator'"
+  :group 'speedbar-vc
+  :type 'boolean)
+
+(defvar speedbar-vc-indicator " *"
+  "Text used to mark files which are currently checked out.
+Currently only RCS is supported.  Other version control systems can be
+added by examining the function `speedbar-this-file-in-vc' and
+`speedbar-vc-check-dir-p'")
+
+(defcustom speedbar-scanner-reset-hook nil
+  "*Hook called whenever generic scanners are reset.
+Set this to implement your own scanning / rescan safe functions with
+state data."
+  :group 'speedbar
+  :type 'hook)
+
+(defcustom speedbar-vc-path-enable-hook nil
+  "*Return non-nil if the current path should be checked for Version Control.
+Functions in this hook must accept one paramter which is the path
+being checked."
+  :group 'speedbar-vc
+  :type 'hook)
+
+(defcustom speedbar-vc-in-control-hook nil
+  "*Return non-nil if the specified file is under Version Control.
+Functions in this hook must accept two paramters.  The PATH of the
+current file, and the FILENAME of the file being checked."
+  :group 'speedbar-vc
+  :type 'hook)
+
+(defvar speedbar-vc-to-do-point nil
+  "Local variable maintaining the current version control check position.")
+
+(defvar speedbar-ignored-modes nil
+  "*List of major modes which speedbar will not switch directories for.")
+
+(defun speedbar-extension-list-to-regex (extlist)
+  "Takes EXTLIST, a list of extensions and transforms it into regexp.
+All the preceding . are stripped for an optimized expression starting
+with . followed by extensions, followed by full-filenames."
+  (let ((regex1 nil) (regex2 nil))
+    (while extlist
+      (if (= (string-to-char (car extlist)) ?.)
+	  (setq regex1 (concat regex1 (if regex1 "\\|" "")
+			       (substring (car extlist) 1)))
+	(setq regex2 (concat regex2 (if regex2 "\\|" "") (car extlist))))
+      (setq extlist (cdr extlist)))
+    ;; concat all the sub-exressions together, making sure all types
+    ;; of parts exist during concatination.
+    (concat "\\("
+	    (if regex1 (concat "\\(\\.\\(" regex1 "\\)\\)") "")
+	    (if (and regex1 regex2) "\\|" "")
+	    (if regex2 (concat "\\(" regex2 "\\)") "")
+	    "\\)\\'")))
+
+(defcustom speedbar-ignored-path-expressions
+  '("/logs?/\\'")
+  "*List of regular expressions matching directories speedbar will ignore.
+They should included paths to directories which are notoriously very
+large and take a long time to load in.  Use the function
+`speedbar-add-ignored-path-regexp' to add new items to this list after
+speedbar is loaded.  You may place anything you like in this list
+before speedbar has been loaded."
+  :group 'speedbar
+  :type '(repeat (regexp :tag "Path Regexp"))
+  :set (lambda (sym val)
+	 (setq speedbar-ignored-path-expressions val
+	       speedbar-ignored-path-regexp
+	       (speedbar-extension-list-to-regex val))))
+
+(defvar speedbar-file-unshown-regexp
+  (let ((nstr "") (noext completion-ignored-extensions))
+    (while noext
+      (setq nstr (concat nstr (regexp-quote (car noext)) "\\'"
+			 (if (cdr noext) "\\|" ""))
+	    noext (cdr noext)))
+    (concat nstr "\\|#[^#]+#\\'\\|\\.\\.?\\'"))
+  "*Regexp matching files we don't want displayed in a speedbar buffer.
+It is generated from the variable `completion-ignored-extensions'")
+
+(defvar speedbar-ignored-path-regexp nil
+  "Regular expression matching paths speedbar will not switch to.
+Created from `speedbar-ignored-path-expressions' with the function
+`speedbar-extension-list-to-regex' (A misnamed function in this case.)
+Use the function `speedbar-add-ignored-path-regexp' to modify this
+variable.")
+
+;; XEmacs: this is dangerous to customize, because we may well want to
+;; change the defaults in the future.
+(defcustom speedbar-supported-extension-expressions
+  (append '(".[CcHh]\\(\\+\\+\\|pp\\|c\\|h\\)?" ".tex\\(i\\(nfo\\)?\\)?"
+	    ".el" ".emacs" ".p" ".java")
+	  (if speedbar-use-imenu-flag
+	      '(".f90" ".ada" ".pl" ".tcl" ".m"
+		"Makefile\\(\\.in\\)?")))
+  "*List of regular expressions which will match files supported by tagging.
+Do not prefix the `.' char with a double \\ to quote it, as the period
+will be stripped by a simplified optimizer when compiled into a
+singular expression.  This variable will be turned into
+`speedbar-file-regexp' for use with speedbar.  You should use the
+function `speedbar-add-supported-extension' to add a new extension at
+runtime, or use the configuration dialog to set it in your .emacs
+file."
+  :group 'speedbar
+  :type '(repeat (regexp :tag "Extension Regexp"))
+  :set (lambda (sym val)
+	 (setq speedbar-supported-extension-expressions val
+	       speedbar-file-regexp (speedbar-extension-list-to-regex val)))
+  )
+
+(defvar speedbar-file-regexp
+  (speedbar-extension-list-to-regex speedbar-supported-extension-expressions)
+  "Regular expression matching files we know how to expand.
+Created from `speedbar-supported-extension-expression' with the
+function `speedbar-extension-list-to-regex'")
+
+(defun speedbar-add-supported-extension (extension)
+  "Add EXTENSION as a new supported extension for speedbar tagging.
+This should start with a `.' if it is not a complete file name, and
+the dot should NOT be quoted in with \\.  Other regular expression
+matchers are allowed however.  EXTENSION may be a single string or a
+list of strings."
+  (if (not (listp extension)) (setq extension (list extension)))
+  (while extension
+    (if (member (car extension) speedbar-supported-extension-expressions)
+	nil
+      (setq speedbar-supported-extension-expressions
+	    (cons (car extension) speedbar-supported-extension-expressions)))
+    (setq extension (cdr extension)))
+  (setq speedbar-file-regexp (speedbar-extension-list-to-regex
+			      speedbar-supported-extension-expressions)))
+
+(defun speedbar-add-ignored-path-regexp (path-expression)
+  "Add PATH-EXPRESSION as a new ignored path for speedbar tracking.
+This function will modify `speedbar-ignored-path-regexp' and add
+PATH-EXPRESSION to `speedbar-ignored-path-expressions'."
+  (if (not (listp path-expression))
+      (setq path-expression (list path-expression)))
+  (while path-expression
+    (if (member (car path-expression) speedbar-ignored-path-expressions)
+	nil
+      (setq speedbar-ignored-path-expressions
+	    (cons (car path-expression) speedbar-ignored-path-expressions)))
+    (setq path-expression (cdr path-expression)))
+  (setq speedbar-ignored-path-regexp (speedbar-extension-list-to-regex
+				      speedbar-ignored-path-expressions)))
+
+;; If we don't have custom, then we set it here by hand.
+(if (not (fboundp 'custom-declare-variable))
+    (setq speedbar-file-regexp (speedbar-extension-list-to-regex
+				speedbar-supported-extension-expressions)
+	  speedbar-ignored-path-regexp (speedbar-extension-list-to-regex
+					speedbar-ignored-path-expressions)))
+
+(defvar speedbar-update-flag (or (fboundp 'run-with-idle-timer)
+				 (fboundp 'start-itimer)
+				 (boundp 'post-command-idle-hook))
+  "*Non-nil means to automatically update the display.
+When this is nil then speedbar will not follow the attached frame's path.
+When speedbar is active, use:
+
+\\<speedbar-key-map> `\\[speedbar-toggle-updates]'
+
+to toggle this value.")
+
+(defvar speedbar-syntax-table nil
+  "Syntax-table used on the speedbar.")
+
+(if speedbar-syntax-table
+    nil
+  (setq speedbar-syntax-table (make-syntax-table))
+  ;; turn off paren matching around here.
+  (modify-syntax-entry ?\' " " speedbar-syntax-table)
+  (modify-syntax-entry ?\" " " speedbar-syntax-table)
+  (modify-syntax-entry ?( " " speedbar-syntax-table)
+  (modify-syntax-entry ?) " " speedbar-syntax-table)
+  (modify-syntax-entry ?[ " " speedbar-syntax-table)
+  (modify-syntax-entry ?] " " speedbar-syntax-table))
+
+
+(defvar speedbar-key-map nil
+  "Keymap used in speedbar buffer.")
+
+;(autoload 'speedbar-configure-options "speedbcfg" "Configure speedbar variables" t)
+;(autoload 'speedbar-configure-faces "speedbcfg" "Configure speedbar faces" t)
+
+(if speedbar-key-map
+    nil
+  (setq speedbar-key-map (make-keymap))
+  (suppress-keymap speedbar-key-map t)
+
+  ;; control
+  (define-key speedbar-key-map "e" 'speedbar-edit-line)
+  (define-key speedbar-key-map "\C-m" 'speedbar-edit-line)
+  (define-key speedbar-key-map "+" 'speedbar-expand-line)
+  (define-key speedbar-key-map "-" 'speedbar-contract-line)
+  (define-key speedbar-key-map "g" 'speedbar-refresh)
+  (define-key speedbar-key-map "t" 'speedbar-toggle-updates)
+  (define-key speedbar-key-map "q" 'speedbar-close-frame)
+  (define-key speedbar-key-map "U" 'speedbar-up-directory)
+
+  ;; navigation
+  (define-key speedbar-key-map "n" 'speedbar-next)
+  (define-key speedbar-key-map "p" 'speedbar-prev)
+  (define-key speedbar-key-map " " 'speedbar-scroll-up)
+  (define-key speedbar-key-map [delete] 'speedbar-scroll-down)
+
+  ;; After much use, I suddenly desired in my heart to perform dired
+  ;; style operations since the directory was RIGHT THERE!
+  (define-key speedbar-key-map "I" 'speedbar-item-info)
+  (define-key speedbar-key-map "B" 'speedbar-item-byte-compile)
+  (define-key speedbar-key-map "L" 'speedbar-item-load)
+  (define-key speedbar-key-map "C" 'speedbar-item-copy)
+  (define-key speedbar-key-map "D" 'speedbar-item-delete)
+  (define-key speedbar-key-map "R" 'speedbar-item-rename)
+
+  (if (string-match "XEmacs" emacs-version)
+      (progn
+	;; bind mouse bindings so we can manipulate the items on each line
+	(define-key speedbar-key-map 'button2 'speedbar-click)
+	;; I hate myself for this unholy binding.
+	(define-key speedbar-key-map 'button1 'speedbar-click)
+	(define-key speedbar-key-map '(shift button2) 'speedbar-power-click)
+	(define-key speedbar-key-map '(meta button3) 'speedbar-mouse-item-info)
+	(define-key speedbar-key-map 'button3 'speedbar-popup-kludge))
+    ;; bind mouse bindings so we can manipulate the items on each line
+    (define-key speedbar-key-map [down-mouse-1] 'speedbar-double-click)
+    (define-key speedbar-key-map [mouse-2] 'speedbar-click)
+    ;; This is the power click for poping up new frames
+    (define-key speedbar-key-map [S-mouse-2] 'speedbar-power-click)
+    ;; This adds a small unecessary visual effect
+    ;;(define-key speedbar-key-map [down-mouse-2] 'speedbar-quick-mouse)
+    (define-key speedbar-key-map [M-mouse-2] 'speedbar-mouse-item-info)
+
+    ;; disable all menus - we don't have a lot of space to play with
+    ;; in such a skinny frame.  This will cleverly find and nuke some
+    ;; user-defined menus as well if they are there.  Too bad it
+    ;; rely's on the structure of a keymap to work.
+    (let ((k (lookup-key global-map [menu-bar])))
+      (while k
+	(if (and (listp (car k)) (listp (cdr (car k))))
+	    (define-key speedbar-key-map (vector 'menu-bar (car (car k)))
+	      'undefined))
+	(setq k (cdr k))))
+
+    ;; This lets the user scroll as if we had a scrollbar... well maybe not
+    (define-key speedbar-key-map [mode-line mouse-2] 'speedbar-mouse-hscroll)
+    ))
+
+(defvar speedbar-easymenu-definition-base
+  '("Speedbar"
+    ["Update" speedbar-refresh t]
+    ["Auto Update" speedbar-toggle-updates
+     :style toggle :selected speedbar-update-flag]
+    )
+  "Base part of the speedbar menu.")
+
+(defvar speedbar-easymenu-definition-special
+  '(["Edit Item On Line" speedbar-edit-line t]
+    ["Show All Files" speedbar-toggle-show-all-files
+     :style toggle :selected speedbar-show-unknown-files]
+    ["Expand Item" speedbar-expand-line
+     (save-excursion (beginning-of-line)
+		     (looking-at "[0-9]+: *.\\+. "))]
+    ["Contract Item" speedbar-contract-line
+     (save-excursion (beginning-of-line)
+		     (looking-at "[0-9]+: *.-. "))]
+    ["Sort Tags" speedbar-toggle-sorting
+     :style toggle :selected speedbar-sort-tags]
+    "----"
+    ["Item Information" speedbar-item-info t]
+    ["Load Lisp File" speedbar-item-load
+     (save-excursion
+       (beginning-of-line)
+       (looking-at "[0-9]+: *\\[[+-]\\] .+\\(\\.el\\)\\( \\*\\)?$"))]
+    ["Byte Compile File" speedbar-item-byte-compile
+     (save-excursion
+       (beginning-of-line)
+       (looking-at "[0-9]+: *\\[[+-]\\] .+\\(\\.el\\)\\( \\*\\)?$"))]
+    ["Copy Item" speedbar-item-copy
+     (save-excursion (beginning-of-line) (looking-at "[0-9]+: *\\["))]
+    ["Rename Item" speedbar-item-rename
+     (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
+    ["Delete Item" speedbar-item-delete
+     (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))])
+  "Additional menu items while in file-mode.")
+ 
+(defvar speedbar-easymenu-definition-trailer
+  (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
+      '("----"
+	["Customize..." speedbar-customize t]
+	["Close" speedbar-close-frame t])
+    '("----"
+      ["Close" speedbar-close-frame t]))
+  "Menu items appearing at the end of the speedbar menu.")
+
+(defvar speedbar-desired-buffer nil
+  "Non-nil when speedbar is showing buttons specific a special mode.
+In this case it is the originating buffer.")
+(defvar speedbar-buffer nil
+  "The buffer displaying the speedbar.")
+(defvar speedbar-frame nil
+  "The frame displaying speedbar.")
+(defvar speedbar-cached-frame nil
+  "The frame that was last created, then removed from the display.")
+(defvar speedbar-full-text-cache nil
+  "The last open directory is saved in its entirety for ultra-fast switching.")
+(defvar speedbar-timer nil
+  "The speedbar timer used for updating the buffer.")
+(defvar speedbar-attached-frame nil
+  "The frame which started speedbar mode.
+This is the frame from which all data displayed in the speedbar is
+gathered, and in which files and such are displayed.")
+
+(defvar speedbar-last-selected-file nil
+  "The last file which was selected in speedbar buffer.")
+
+(defvar speedbar-shown-directories nil
+  "Maintain list of directories simultaneously open in the current speedbar.")
+
+(defvar speedbar-directory-contents-alist nil
+  "An association list of directories and their contents.
+Each sublist was returned by `speedbar-file-lists'.  This list is
+maintained to speed up the refresh rate when switching between
+directories.")
+
+(defvar speedbar-power-click nil
+  "Never set this by hand.  Value is t when S-mouse activity occurs.")
+
+
+;;; Mode definitions/ user commands
+;;
+;;;###autoload
+(defalias 'speedbar 'speedbar-frame-mode)
+;;;###autoload
+(defun speedbar-frame-mode (&optional arg)
+  "Enable or disable speedbar.  Positive ARG means turn on, negative turn off.
+nil means toggle.  Once the speedbar frame is activated, a buffer in
+`speedbar-mode' will be displayed.  Currently, only one speedbar is
+supported at a time.
+`speedbar-before-popup-hook' is called before popping up the speedbar frame.
+`speedbar-before-delete-hook' is called before the frame is deleted."
+  (interactive "P")
+  (or (console-on-window-system-p)
+      (error "Speedbar is not useful outside of a windowing environment"))
+  ;; XEmacs: add entry to menubar.
+  (add-menu-button '("Buffers")
+		   ["Speedbar" speedbar-frame-mode
+		    :style toggle
+		    :selected (and (boundp 'speedbar-frame)
+				   (frame-live-p speedbar-frame)
+				   (frame-visible-p speedbar-frame))]
+		   "--")
+  ;; toggle frame on and off.
+  (if (not arg) (if (and (frame-live-p speedbar-frame)
+			 (frame-visible-p speedbar-frame))
+		    (setq arg -1) (setq arg 1)))
+  ;; turn the frame off on neg number
+  (if (and (numberp arg) (< arg 0))
+      (progn
+	(run-hooks 'speedbar-before-delete-hook)
+	;; XEmacs: I am not sure this frame caching is needed at all,
+	;; because frame creation is pretty fast in XEmacs.  -hniksic
+	(when (and speedbar-frame (frame-live-p speedbar-frame))
+	  (setq speedbar-cached-frame speedbar-frame)
+	  (make-frame-invisible speedbar-frame))
+	(setq speedbar-frame nil)
+	(speedbar-set-timer nil)
+	;; Used to delete the buffer.  This has the annoying affect of
+	;; preventing whatever took its place from ever appearing
+	;; as the default after a C-x b was typed
+	;;(if (bufferp speedbar-buffer)
+	;;    (kill-buffer speedbar-buffer))
+	)
+    ;; Set this as our currently attached frame
+    (setq speedbar-attached-frame (selected-frame))
+    (run-hooks 'speedbar-before-popup-hook)
+    ;; Get the frame to work in
+    (if (frame-live-p speedbar-cached-frame)
+	(progn
+	  (setq speedbar-frame speedbar-cached-frame)
+	  ;; Choose the width
+	  (set-frame-height speedbar-frame (speedbar-needed-height))
+	  (make-frame-visible speedbar-frame)
+	  ;; Get the buffer to play with
+	  (speedbar-mode)
+	  (select-frame speedbar-frame)
+	  (if (not (eq (current-buffer) speedbar-buffer))
+	      (switch-to-buffer speedbar-buffer))
+	  (set-window-dedicated-p (selected-window) t)
+	  (raise-frame speedbar-frame)
+	  (speedbar-set-timer speedbar-update-speed)
+	  )
+      (if (frame-live-p speedbar-frame)
+	  (raise-frame speedbar-frame)
+	;; XEmacs: use plist.  Which is where we handle the pointer
+	;; shapes, too.
+	(setq speedbar-frame
+	      (make-frame (nconc (list 'height
+				       (speedbar-needed-height))
+				 speedbar-frame-plist)))
+	;; reset the selection variable
+	(setq speedbar-last-selected-file nil)
+	;; Put the buffer into the frame
+	(save-window-excursion
+	  ;; Get the buffer to play with
+	  (speedbar-mode)
+	  (select-frame speedbar-frame)
+	  (switch-to-buffer speedbar-buffer)
+	  (set-window-dedicated-p (selected-window) t))
+	(speedbar-set-timer speedbar-update-speed)))))
+
+(defun speedbar-close-frame ()
+  "Turn off a currently active speedbar."
+  (interactive)
+  (speedbar-frame-mode -1)
+  (select-frame speedbar-attached-frame)
+  (other-frame 0))
+
+(defun speedbar-frame-width ()
+  "Return the width of the speedbar frame in characters.
+nil if it doesn't exist."
+  (and speedbar-frame (frame-property speedbar-frame 'width)))
+
+(defun speedbar-needed-height (&optional frame)
+  "The needed height for the toolbar frame (in characters)."
+  (or frame (setq frame (selected-frame)))
+  (/ (frame-pixel-height frame)
+     (face-height 'default frame)))
+
+(defun speedbar-mode ()
+  "Major mode for managing a display of directories and tags.
+\\<speedbar-key-map>
+The first line represents the default path of the speedbar frame.
+Each directory segment is a button which jumps speedbar's default
+directory to that path.  Buttons are activated by clicking `\\[speedbar-click]'.
+In some situations using `\\[speedbar-power-click]' is a `power click' which will
+rescan cached items, or pop up new frames.
+
+Each line starting with <+> represents a directory.  Click on the <+>
+to insert the directory listing into the current tree.  Click on the
+<-> to retract that list.  Click on the directory name to go to that
+directory as the default.
+
+Each line starting with [+] is a file.  If the variable
+`speedbar-show-unknown-files' is t, the lines starting with [?] are
+files which don't have imenu support, but are not expressly ignored.
+Files are completely ignored if they match `speedbar-file-unshown-regexp'
+which is generated from `completion-ignored-extensions'.
+
+Files with a `*' character after their name are files checked out of a
+version control system.  (currently only RCS is supported.)  New
+version control systems can be added by examining the documentation
+for `speedbar-this-file-in-vc' and `speedbar-vc-check-dir-p'
+
+Click on the [+] to display a list of tags from that file.  Click on
+the [-] to retract the list.  Click on the file name to edit the file
+in the attached frame.
+
+If you open tags, you might find a node starting with {+}, which is a
+category of tags.  Click the {+} to expand the category.  Jump-able
+tags start with >.  Click the name of the tag to go to that position
+in the selected file.
+
+\\{speedbar-key-map}"
+  ;; NOT interactive
+  (save-current-buffer
+    (setq speedbar-buffer (set-buffer (get-buffer-create " SPEEDBAR")))
+    (kill-all-local-variables)
+    (setq major-mode 'speedbar-mode)
+    (setq mode-name "Speedbar")
+    (use-local-map speedbar-key-map)
+    (set-syntax-table speedbar-syntax-table)
+    (setq font-lock-keywords nil) ;; no font-locking please
+    (setq truncate-lines t)
+    (make-local-variable 'frame-title-format)
+    (setq frame-title-format "Speedbar")
+    ;; Set this up special just for the speedbar buffer
+    (if (null default-minibuffer-frame)
+	(progn
+	  (make-local-variable 'default-minibuffer-frame)
+	  (setq default-minibuffer-frame speedbar-attached-frame)))
+    (make-local-variable 'temp-buffer-show-function)
+    (setq temp-buffer-show-function 'speedbar-temp-buffer-show-function)
+    (make-local-hook 'kill-buffer-hook)
+    (add-hook 'kill-buffer-hook
+	      (lambda () (let ((skilling (boundp 'skilling)))
+			   (if skilling
+			       nil
+			     (if (eq (current-buffer)
+				     speedbar-buffer)
+				 (speedbar-frame-mode -1)))))
+	      nil t)
+    (when (specifier-instance has-modeline-p)
+      (speedbar-set-mode-line-format))
+    (if (not speedbar-xemacsp)
+	(setq auto-show-mode nil))	;no auto-show for Emacs
+    (run-hooks 'speedbar-mode-hook))
+  (speedbar-update-contents)
+  speedbar-buffer)
+
+(defun speedbar-set-mode-line-format ()
+  "Set the format of the mode line based on the current speedbar environment.
+This gives visual indications of what is up.  It EXPECTS the speedbar
+frame and window to be the currently active frame and window."
+  (if (frame-live-p speedbar-frame)
+      (save-excursion
+	(set-buffer speedbar-buffer)
+	(let* ((w (or (speedbar-frame-width) 20))
+	       (p1 "<<")
+	       (p5 ">>")
+	       (p3 (if speedbar-update-flag "SPEEDBAR" "SLOWBAR"))
+	       (blank (- w (length p1) (length p3) (length p5)
+			 (if line-number-mode 4 0)))
+	       (p2 (if (> blank 0)
+		       (make-string (/ blank 2) ? )
+		     ""))
+	       (p4 (if (> blank 0)
+		       (make-string (+ (/ blank 2) (% blank 2)) ? )
+		     ""))
+	       (tf
+		(if line-number-mode
+		    (list (concat p1 p2 p3) '(line-number-mode " %3l")
+			  (concat p4 p5))
+		  (list (concat p1 p2 p3 p4 p5)))))
+	  (if (not (equal mode-line-format tf))
+	      (progn
+		(setq mode-line-format tf)
+		(force-mode-line-update)))))))
+
+(defun speedbar-temp-buffer-show-function (buffer)
+  "Placed in the variable `temp-buffer-show-function' in `speedbar-mode'.
+If a user requests help using \\[help-command] <Key> the temp BUFFER will be
+redirected into a window on the attached frame."
+  (if speedbar-attached-frame (select-frame speedbar-attached-frame))
+  (pop-to-buffer buffer nil)
+  (other-window -1)
+  (run-hooks 'temp-buffer-show-hook))
+
+(defun speedbar-reconfigure-menubar ()
+  "Reconfigure the menu-bar in a speedbar frame.
+Different menu items are displayed depending on the current display mode
+and the existence of packages."
+  (let ((cf (selected-frame))
+	(md (append speedbar-easymenu-definition-base
+		    (if speedbar-shown-directories
+			;; file display mode version
+			speedbar-easymenu-definition-special
+		      (save-excursion
+			(select-frame speedbar-attached-frame)
+			(if (local-variable-p
+			     'speedbar-easymenu-definition-special
+			     (current-buffer))
+			    ;; If bound locally, we can use it
+			    speedbar-easymenu-definition-special)))
+		    ;; The trailer
+		    speedbar-easymenu-definition-trailer)))
+    (easy-menu-define speedbar-menu-map speedbar-key-map "Speedbar menu" md)
+    (if speedbar-xemacsp
+	(save-excursion
+	  (set-buffer speedbar-buffer)
+	  ;; For the benefit of button3
+	  (unless (assoc "Speedbar" mode-popup-menu)
+	    (easy-menu-add md))
+	  (set-buffer-menubar (list md))))))
+
+
+;;; User Input stuff
+;;
+
+;; XEmacs: this can be implemented using modeline keymaps, but there
+;; is no use, as we have horizontal scrollbar (as the docstring
+;; hints.)
+;(defun speedbar-mouse-hscroll (e)
+;  "Read a mouse event E from the mode line, and horizontally scroll.
+;If the mouse is being clicked on the far left, or far right of the
+;mode-line.  This is only useful for non-XEmacs"
+;  (interactive "e")
+;  (let* ((xp (car (nth 2 (car (cdr e)))))
+;	 (cpw (/ (frame-pixel-width)
+;		 (frame-width)))
+;	 (oc (1+ (/ xp cpw)))
+;	 )
+;    (cond ((< oc 3)
+;	   (scroll-left 2))
+;	  ((> oc (- (window-width) 3))
+;	   (scroll-right 2))
+;	  (t (message "Click on the edge of the modeline to scroll left/right")))
+;    ;;(message "X: Pixel %d Char Pixels %d On char %d" xp cpw oc)
+;    ))
+
+(defun speedbar-customize ()
+  "Customize speedbar using the Custom package."
+  (interactive)
+  (let ((sf (selected-frame)))
+    (select-frame speedbar-attached-frame)
+    (customize-group 'speedbar)
+    (select-frame sf))
+  (speedbar-maybee-jump-to-attached-frame))
+
+(defun speedbar-get-focus ()
+  "Change frame focus to or from the speedbar frame.
+If the selected frame is not speedbar, then speedbar frame is
+selected.  If the speedbar frame is active, then select the attached frame."
+  (interactive)
+  (if (eq (selected-frame) speedbar-frame)
+      (if (frame-live-p speedbar-attached-frame)
+	  (select-frame speedbar-attached-frame))
+    ;; make sure we have a frame
+    (if (not (frame-live-p speedbar-frame)) (speedbar-frame-mode 1))
+    ;; go there
+    (select-frame speedbar-frame))
+  (other-frame 0))
+
+;; In XEmacs, we make popup menus work on the item over mouse (as
+;; opposed to where the point happens to be.)  We attain this by
+;; temporarily moving the point to that place.
+(defun speedbar-popup-kludge (event)
+  (interactive "e")
+  (save-excursion
+    (goto-char (event-closest-point event))
+    (beginning-of-line)
+    (forward-char (min 5 (- (point-at-eol)
+			    (point-at-bol))))
+    (popup-mode-menu)
+    ;; Wait for menu to bail out.  `popup-mode-menu' (and other popup
+    ;; menu functions) return immediately.
+    (let (new)
+      (while (not (misc-user-event-p (setq new (next-event))))
+	(dispatch-event new))
+      (dispatch-event new))))
+
+(defun speedbar-next (arg)
+  "Move to the next ARGth line in a speedbar buffer."
+  (interactive "p")
+  (forward-line (or arg 1))
+  (speedbar-item-info)
+  (speedbar-position-cursor-on-line))
+
+(defun speedbar-prev (arg)
+  "Move to the previous ARGth line in a speedbar buffer."
+  (interactive "p")
+  (speedbar-next (if arg (- arg) -1)))
+
+(defun speedbar-scroll-up (&optional arg)
+  "Page down one screen-full of the speedbar, or ARG lines."
+  (interactive "P")
+  (scroll-up arg)
+  (speedbar-position-cursor-on-line))
+
+(defun speedbar-scroll-down (&optional arg)
+  "Page up one screen-full of the speedbar, or ARG lines."
+  (interactive "P")
+  (scroll-down arg)
+  (speedbar-position-cursor-on-line))
+
+(defun speedbar-up-directory ()
+  "Keyboard accelerator for moving the default directory up one.
+Assumes that the current buffer is the speedbar buffer"
+  (interactive)
+  (setq default-directory (expand-file-name (concat default-directory "../")))
+  (speedbar-update-contents))
+
+;;; Speedbar file activity (aka creeping featurism)
+;;
+(defun speedbar-refresh ()
+  "Refresh the current speedbar display, disposing of any cached data."
+  (interactive)
+  (let ((dl speedbar-shown-directories))
+    (while dl
+      (adelete 'speedbar-directory-contents-alist (car dl))
+      (setq dl (cdr dl))))
+  (if (<= 1 speedbar-verbosity-level) (message "Refreshing speedbar..."))
+  (speedbar-update-contents)
+  (speedbar-stealthy-updates)
+  ;; Reset the timer in case it got really hosed for some reason...
+  (speedbar-set-timer speedbar-update-speed)
+  (if (<= 1 speedbar-verbosity-level) (message "Refreshing speedbar...done")))
+
+(defun speedbar-item-load ()
+  "Load the item under the cursor or mouse if it is a lisp file."
+  (interactive)
+  (let ((f (speedbar-line-file)))
+    (if (and (file-exists-p f) (string-match "\\.el\\'" f))
+	(if (and (file-exists-p (concat f "c"))
+		 (y-or-n-p (format "Load %sc? " f)))
+	    ;; If the compiled version exists, load that instead...
+	    (load-file (concat f "c"))
+	  (load-file f))
+      (error "Not a loadable file..."))))
+
+(defun speedbar-item-byte-compile ()
+  "Byte compile the item under the cursor or mouse if it is a lisp file."
+  (interactive)
+  (let ((f (speedbar-line-file))
+	(sf (selected-frame)))
+    (if (and (file-exists-p f) (string-match "\\.el\\'" f))
+	(progn
+	  (select-frame speedbar-attached-frame)
+	  (byte-compile-file f nil)
+	  (select-frame sf)))
+    ))
+
+(defun speedbar-mouse-item-info (event)
+  "Provide information about what the user clicked on.
+This should be bound to a mouse EVENT."
+  (interactive "e")
+  (mouse-set-point event)
+  (speedbar-item-info))
+
+(defun speedbar-item-info ()
+  "Display info in the mini-buffer about the button the mouse is over."
+  (interactive)
+  (if (not speedbar-shown-directories)
+      nil
+    (let* ((item (speedbar-line-file))
+	   (attr (if item (file-attributes item) nil)))
+      (if item (message "%s %d %s" (nth 8 attr) (nth 7 attr) item)
+	(save-excursion
+	  (beginning-of-line)
+	  (looking-at "\\([0-9]+\\):")
+	  (setq item (speedbar-line-path (string-to-int (match-string 1))))
+	  (if (re-search-forward "> \\([^ ]+\\)$"
+				 (save-excursion(end-of-line)(point)) t)
+	      (progn
+		(setq attr (get-text-property (match-beginning 1)
+					      'speedbar-token))
+		(message "Tag %s in %s at position %s"
+			 (match-string 1) item (if attr attr 0)))
+	    (message "No special info for this line.")))
+	))))
+
+(defun speedbar-item-copy ()
+  "Copy the item under the cursor.
+Files can be copied to new names or places."
+  (interactive)
+  (let ((f (speedbar-line-file)))
+    (if (not f)	(error "Not a file."))
+    (if (file-directory-p f)
+	(error "Cannot copy directory.")
+      (let* ((rt (read-file-name (format "Copy %s to: "
+					 (file-name-nondirectory f))
+				 (file-name-directory f)))
+	     (refresh (member (expand-file-name (file-name-directory rt))
+			      speedbar-shown-directories)))
+	;; Create the right file name part
+	(if (file-directory-p rt)
+	    (setq rt
+		  (concat (expand-file-name rt)
+			  (if (string-match "/\\'" rt) "" "/")
+			  (file-name-nondirectory f))))
+	(if (or (not (file-exists-p rt))
+		(y-or-n-p (format "Overwrite %s with %s? " rt f)))
+	    (progn
+	      (copy-file f rt t t)
+	      ;; refresh display if the new place is currently displayed.
+	      (if refresh
+		  (progn
+		    (speedbar-refresh)
+		    (if (not (speedbar-goto-this-file rt))
+			(speedbar-goto-this-file f))))
+	      ))))))
+
+(defun speedbar-item-rename ()
+  "Rename the item under the cursor or mouse.
+Files can be renamed to new names or moved to new directories."
+  (interactive)
+  (let ((f (speedbar-line-file)))
+    (if f
+	(let* ((rt (read-file-name (format "Rename %s to: "
+					   (file-name-nondirectory f))
+				   (file-name-directory f)))
+	       (refresh (member (expand-file-name (file-name-directory rt))
+				speedbar-shown-directories)))
+	  ;; Create the right file name part
+	  (if (file-directory-p rt)
+	      (setq rt
+		    (concat (expand-file-name rt)
+			    (if (string-match "/\\'" rt) "" "/")
+			    (file-name-nondirectory f))))
+	  (if (or (not (file-exists-p rt))
+		  (y-or-n-p (format "Overwrite %s with %s? " rt f)))
+	      (progn
+		(rename-file f rt t)
+		;; refresh display if the new place is currently displayed.
+		(if refresh
+		    (progn
+		      (speedbar-refresh)
+		      (speedbar-goto-this-file rt)
+		      )))))
+      (error "Not a file."))))
+
+(defun speedbar-item-delete ()
+  "Delete the item under the cursor.  Files are removed from disk."
+  (interactive)
+  (let ((f (speedbar-line-file)))
+    (if (not f) (error "Not a file."))
+    (if (y-or-n-p (format "Delete %s? " f))
+	(progn
+	  (if (file-directory-p f)
+	      (delete-directory f)
+	    (delete-file f))
+	  (message "Okie dokie..")
+	  (let ((p (point)))
+	    (speedbar-refresh)
+	    (goto-char p))
+	  ))
+    ))
+
+(defun speedbar-enable-update ()
+  "Enable automatic updating in speedbar via timers."
+  (interactive)
+  (setq speedbar-update-flag t)
+  (speedbar-set-mode-line-format)
+  (speedbar-set-timer speedbar-update-speed))
+
+(defun speedbar-disable-update ()
+  "Disable automatic updating and stop consuming resources."
+  (interactive)
+  (setq speedbar-update-flag nil)
+  (speedbar-set-mode-line-format)
+  (speedbar-set-timer nil))
+
+(defun speedbar-toggle-updates ()
+  "Toggle automatic update for the speedbar frame."
+  (interactive)
+  (if speedbar-update-flag
+      (speedbar-disable-update)
+    (speedbar-enable-update)))
+
+(defun speedbar-toggle-sorting ()
+  "Toggle automatic update for the speedbar frame."
+  (interactive)
+  (setq speedbar-sort-tags (not speedbar-sort-tags)))
+
+(defun speedbar-toggle-show-all-files ()
+  "Toggle display of files speedbar can not tag."
+  (interactive)
+  (setq speedbar-show-unknown-files (not speedbar-show-unknown-files))
+  (speedbar-refresh))
+
+;;; Utility functions
+;;
+(defun speedbar-set-timer (timeout)
+  "Apply a timer with TIMEOUT, or remove a timer if TIMOUT is nil.
+TIMEOUT is the number of seconds until the speedbar timer is called
+again.  When TIMEOUT is nil, turn off all timeouts.
+This function will also enable or disable the `vc-checkin-hook' used
+to track file check ins, and will change the mode line to match
+`speedbar-update-flag'."
+  (cond
+   ;; XEmacs
+   (speedbar-xemacsp
+    (if speedbar-timer
+	(progn (delete-itimer speedbar-timer)
+	       (setq speedbar-timer nil)))
+    (if timeout
+	(setq speedbar-timer (start-itimer "speedbar"
+					   'speedbar-timer-fn
+					   timeout
+					   timeout
+					   t))))
+   ;; Post 19.31 Emacs
+   ((fboundp 'run-with-idle-timer)
+    (if speedbar-timer
+	(progn (cancel-timer speedbar-timer)
+	       (setq speedbar-timer nil)))
+    (if timeout
+	(setq speedbar-timer
+	      (run-with-idle-timer timeout nil 'speedbar-timer-fn))))
+   ;; Emacs 19.30 (Thanks twice: ptype@dra.hmg.gb)
+   ((fboundp 'post-command-idle-hook)
+    (if timeout
+	(add-hook 'post-command-idle-hook 'speedbar-timer-fn)
+      (remove-hook 'post-command-idle-hook 'speedbar-timer-fn)))
+   ;; Older or other Emacsen with no timers.  Set up so that it's
+   ;; obvious this emacs can't handle the updates
+   (t
+    (setq speedbar-update-flag nil)))
+  ;; Apply a revert hook that will reset the scanners.  We attach to revert
+  ;; because most reverts occur during VC state change, and this lets our
+  ;; VC scanner fix itself.
+  (if timeout
+      (add-hook 'after-revert-hook 'speedbar-reset-scanners)
+    (remove-hook 'after-revert-hook 'speedbar-reset-scanners)
+    )
+  ;; change this if it changed for some reason
+  (speedbar-set-mode-line-format))
+
+(defmacro speedbar-with-writable (&rest forms)
+  "Allow the buffer to be writable and evaluate FORMS.
+Turn read only back on when done."
+  ;; XEmacs: the original implementation used `toggle-read-only'.  I
+  ;; may be missing something obvious here, but IMHO this should
+  ;; suffice:
+  `(let ((inhibit-read-only t))
+     ,@forms))
+(put 'speedbar-with-writable 'lisp-indent-function 0)
+
+(defun speedbar-select-window (buffer)
+  "Select a window in which BUFFER is show.
+If it is not shown, force it to appear in the default window."
+  (let ((win (get-buffer-window buffer speedbar-attached-frame)))
+    (if win
+	(select-window win)
+      (show-buffer (selected-window) buffer))))
+
+(defmacro speedbar-with-attached-buffer (&rest forms)
+  "Execute FORMS in the attached frame's special buffer.
+Optionally select that frame if necessary."
+  ;; Reset the timer with a new timeout when cliking a file
+  ;; in case the user was navigating directories, we can cancel
+  ;; that other timer.
+  (list
+   'progn
+   '(speedbar-set-timer speedbar-update-speed)
+   (list
+    'let '((cf (selected-frame)))
+    '(select-frame speedbar-attached-frame)
+    '(speedbar-select-window speedbar-desired-buffer)
+    (cons 'progn forms)
+    '(select-frame cf)
+    '(speedbar-maybee-jump-to-attached-frame)
+    )))
+
+(defun speedbar-insert-button (text face mouse function
+				    &optional token prevline)
+  "Insert TEXT as the next logical speedbar button.
+FACE is the face to put on the button, MOUSE is the highlight face to use.
+When the user clicks on TEXT, FUNCTION is called with the TOKEN parameter.
+This function assumes that the current buffer is the speedbar buffer.
+If PREVLINE, then put this button on the previous line.
+
+This is a convenience function for special mode that create their own
+specialized speedbar displays."
+  (goto-char (point-max))
+  (if (/= (current-column) 0) (insert "\n"))
+  (if prevline (progn (delete-char -1) (insert " "))) ;back up if desired...
+  (let ((start (point)))
+    (insert text)
+    (speedbar-make-button start (point) face mouse function token))
+  (let ((start (point)))
+    (insert "\n")
+    (put-text-property start (point) 'face nil)
+    (put-text-property start (point) 'mouse-face nil)))
+
+(defun speedbar-make-button (start end face mouse function &optional token)
+  "Create a button from START to END, with FACE as the display face.
+MOUSE is the mouse face.  When this button is clicked on FUNCTION
+will be run with the TOKEN parameter (any lisp object)"
+  (put-text-property start end 'face face)
+  (put-text-property start end 'mouse-face mouse)
+  (put-text-property start end 'invisible nil)
+  (if function (put-text-property start end 'speedbar-function function))
+  (if token (put-text-property start end 'speedbar-token token))
+  )
+
+;;; File button management
+;;
+(defun speedbar-file-lists (directory)
+  "Create file lists for DIRECTORY.
+The car is the list of directories, the cdr is list of files not
+matching ignored headers.  Cache any directory files found in
+`speedbar-directory-contents-alist' and use that cache before scanning
+the file-system"
+  (setq directory (expand-file-name directory))
+  ;; If in powerclick mode, then the directory we are getting
+  ;; should be rescanned.
+  (if speedbar-power-click
+      (adelete 'speedbar-directory-contents-alist directory))
+  ;; find the directory, either in the cache, or build it.
+  (or (cdr-safe (assoc directory speedbar-directory-contents-alist))
+      (let ((default-directory directory)
+	    (dir (directory-files directory nil))
+	    (dirs nil)
+	    (files nil))
+	(while dir
+	  (if (not (string-match speedbar-file-unshown-regexp (car dir)))
+	      (if (file-directory-p (car dir))
+		  (setq dirs (cons (car dir) dirs))
+		(setq files (cons (car dir) files))))
+	  (setq dir (cdr dir)))
+	(let ((nl (cons (nreverse dirs) (list (nreverse files)))))
+	  (aput 'speedbar-directory-contents-alist directory nl)
+	  nl))
+      ))
+
+(defun speedbar-directory-buttons (directory index)
+  "Insert a single button group at point for DIRECTORY.
+Each directory path part is a different button.  If part of the path
+matches the user directory ~, then it is replaced with a ~.
+INDEX is not used, but is required by the caller."
+  (let* ((tilde (expand-file-name "~"))
+	 (dd (expand-file-name directory))
+	 (junk (string-match (regexp-quote tilde) dd))
+	 (displayme (if junk
+			(concat "~" (substring dd (match-end 0)))
+		      dd))
+	 (p (point)))
+    (if (string-match "\\`~/?\\'" displayme) (setq displayme (concat tilde "/")))
+    (insert displayme)
+    (save-excursion
+      (goto-char p)
+      (while (re-search-forward "\\([^/]+\\)/" nil t)
+	(speedbar-make-button (match-beginning 1) (match-end 1)
+			      'speedbar-directory-face
+			      'speedbar-highlight-face
+			      'speedbar-directory-buttons-follow
+			      (if (= (match-beginning 1) p)
+				  (expand-file-name "~/")  ;the tilde
+				(buffer-substring-no-properties
+				 p (match-end 0)))))
+      ;; Nuke the beginning of the directory if it's too long...
+      (cond ((eq speedbar-directory-button-trim-method 'span)
+	     (beginning-of-line)
+	     (let ((ww (or (speedbar-frame-width) 20)))
+	       (move-to-column ww nil)
+	       (while (>= (current-column) ww)
+		 (re-search-backward "/" nil t)
+		 (if (<= (current-column) 2)
+		     (progn
+		       (re-search-forward "/" nil t)
+		       (if (< (current-column) 4)
+			   (re-search-forward "/" nil t))
+		       (forward-char -1)))
+		 (if (looking-at "/?$")
+		     (beginning-of-line)
+		   (insert "/...\n ")
+		   (move-to-column ww nil)))))
+	    ((eq speedbar-directory-button-trim-method 'trim)
+	     (end-of-line)
+	     (let ((ww (or (speedbar-frame-width) 20))
+		   (tl (current-column)))
+	       (if (< ww tl)
+		   (progn
+		     (move-to-column (- tl ww))
+		     (if (re-search-backward "/" nil t)
+			 (progn
+			   (delete-region (point-min) (point))
+			   (insert "$")
+			   )))))))
+      )
+    (if (string-match "\\`/[^/]+/\\'" displayme)
+	(progn
+	  (insert "  ")
+	  (let ((p (point)))
+	    (insert "<root>")
+	    (speedbar-make-button p (point)
+				  'speedbar-directory-face
+				  'speedbar-highlight-face
+				  'speedbar-directory-buttons-follow
+				  "/"))))
+    (end-of-line)
+    (insert-char ?\n 1 nil)))
+
+(defun speedbar-make-tag-line (exp-button-type
+			       exp-button-char exp-button-function
+			       exp-button-data
+			       tag-button tag-button-function tag-button-data
+			       tag-button-face depth)
+  "Create