]> code.delx.au - gnu-emacs/blobdiff - lisp/speedbar.el
(completion-common-substring): Use `completion-common-substring' prior to `completion...
[gnu-emacs] / lisp / speedbar.el
index 89397f11c91d1ab30e92e49c703c548fc2f06d4a..e09c0d734ccaaa7281f0b8a8eec92f9d8f66d637 100644 (file)
-;;; speedbar --- quick access to files and tags
+;;; speedbar --- quick access to files and tags in a frame
 
-;;; Copyright (C) 1996, 97, 98 Free Software Foundation
-;;
-;; Author: Eric M. Ludlam <zappo@gnu.ai.mit.edu>
-;; Version: 0.6.2
+;;; Copyright (C) 1996, 97, 98, 99, 00, 01, 02, 03, 04, 05 Free Software Foundation
+
+;; Author: Eric M. Ludlam <zappo@gnu.org>
 ;; Keywords: file, tags, tools
-;;
+
+(defvar speedbar-version "1.0"
+  "The current version of speedbar.")
+(defvar speedbar-incompatible-version "0.14beta4"
+  "This version of speedbar is incompatible with this version.
+Due to massive API changes (removing the use of the word PATH) 
+this version is not backward compatible to 0.14 or earlier.")
+
 ;; This file is part of GNU Emacs.
-;;
+
 ;; GNU Emacs 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.
-;;
+
 ;; GNU Emacs 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 GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 ;;
 ;;   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.
-;;
-;; Starting Speedbar:
-;;
-;;   If speedbar came to you as a part of Emacs, simply type
-;; `M-x speedbar', and it will be autoloaded for you. A "Speedbar"
-;; submenu will be added under "Tools".
-;;
-;;   If speedbar is not a part of your distribution, then add
-;; this to your .emacs file:
-;;
-;;   (autoload 'speedbar-frame-mode "speedbar" "Popup a speedbar frame" t)
-;;   (autoload 'speedbar-get-focus "speedbar" "Jump to speedbar frame" t)
-;;
-;;   If you want to choose it from a menu, you can do this:
+;; files are displayed.  These items can be clicked on with mouse-2 in
+;; to display that file location.
 ;;
-;;   Emacs:
-;;   (define-key-after (lookup-key global-map [menu-bar tools])
-;;      [speedbar] '("Speedbar" . speedbar-frame-mode) [calendar])
+;;; Customizing and Developing for speedbar
 ;;
-;;   XEmacs:
-;;   (add-menu-button '("Tools")
-;;                   ["Speedbar" speedbar-frame-mode
-;;                    :style toggle
-;;                    :selected (and (boundp 'speedbar-frame)
-;;                                   (frame-live-p speedbar-frame)
-;;                                   (frame-visible-p speedbar-frame))]
-;;                   "--")
+;; Please see the speedbar manual for informaion.
 ;;
-;;   If you want to access speedbar using only the keyboard, do this:
+;;; Notes:
 ;;
-;;   (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 it again will bring you back
-;; to the attached 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.
-;;
-;; Customizing Speedbar:
-;;
-;;   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 XEmacs previous to 20 may want to change the default
-;; timeouts for `speedbar-update-speed' to something longer as XEmacs
-;; doesn't have idle timers, the speedbar timer keeps going off
-;; arbitrarily while you're typing.  It's quite pesky.
-;;
-;;    Users of really old emacsen without the needed timers will not
-;; have speedbar updating automatically.  Use "r" to refresh the
-;; display after changing directories.  Remember, do not interrupt the
-;; stealthy updates or your 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.
+;;    Users of really old emacsen without the need timer functions
+;; will not have speedbar updating automatically.  Use "g" to refresh
+;; the display after changing directories.  Remember, do not interrupt
+;; the stealthy updates or your display may not be completely
+;; refreshed.
 ;;
 ;;    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)
-;; and the package custom (for easy configuration of speedbar)
+;;     assoc should be available in all modern versions of Emacs.
+;; The custom package is optional (for easy configuration of speedbar)
 ;;     http://www.dina.kvl.dk/~abraham/custom/
+;;     custom is available in all versions of Emacs version 20 or better.
 ;;
-;; If you do not have custom installed, you can still get face colors
-;; by modifying the faces directly in your .emacs file, or setting
-;; them in your .Xdefaults file.
-;; Here is an example .Xdefaults for a dark background:
-;;
-;; emacs*speedbar-button-face.attributeForeground:     Aquamarine
-;; emacs*speedbar-selected-face.attributeForeground:   red
-;; emacs*speedbar-selected-face.attributeUnderline:    true
-;; emacs*speedbar-directory-face.attributeForeground:  magenta
-;; emacs*speedbar-file-face.attributeForeground:       green3
-;; emacs*speedbar-highlight-face.attributeBackground:  sea green
-;; emacs*speedbar-tag-face.attributeForeground:                yellow
-
-;;; 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.
-;; 0.5.5 Fixed so that there can be no ignored paths
-;;       Added .l & .lsp as lisp, suggested by: sshteingold@cctrading.com
-;;       You can now adjust height in `speedbar-frame-parameters'
-;;       XEmacs fix for use of `local-variable-p'
-;; 0.5.6 Folded in XEmacs suggestions from Hrvoje Niksic <hniksic@srce.hr>
-;;         Several custom changes (group definitions, trim-method & others)
-;;         Keymap changes, and ways to add menu items.
-;;         Timer use changes for XEmacs 20.4
-;;         Regular expression enhancements.
-;; 0.6   Fixed up some frame definition stuff, use more convenience fns.
-;;       Rehashed frame creation code for better compatibility.
-;;       Fixed setting of kill-buffer hook.
-;;       Default speedbar has no menubar, mouse-3 is popup menu,
-;;       XEmacs double-click capability (Hrvoje Niksic <hniksic@srce.hr>)
-;;       General documentation fixup.
-;; 0.6.1 Fixed button-3 menu for Emacs 20.
-;; 0.6.2 Added autoload tag to `speedbar-get-focus'
 
 ;;; 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))))))
+(require 'dframe)
+(require 'sb-image)
 
 ;; customization stuff
 (defgroup speedbar nil
   "File and tag browser frame."
-  :group 'tags
+  :group 'etags
   :group 'tools
-  :version "20.3")
+  :group 'convenience
+;  :version "20.3"
+  )
 
 (defgroup speedbar-faces nil
   "Faces used in speedbar."
   :group 'speedbar)
 
 ;;; Code:
-(defvar speedbar-xemacsp (string-match "XEmacs" emacs-version)
-  "Non-nil if we are running in the XEmacs environment.")
-(defvar speedbar-xemacs20p (and speedbar-xemacsp (= emacs-major-version 20)))
-
-(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.")
+
+;; Note: `inversion-test' requires parts of the CEDET package that are
+;; not included with Emacs.
+;;
+;; (defun speedbar-require-version (major minor &optional beta)
+;;   "Non-nil if this version of SPEEDBAR does not satisfy a specific version.
+;; Arguments can be:
+;;
+;;   (MAJOR MINOR &optional BETA)
+;;
+;;   Values MAJOR and MINOR must be integers.  BETA can be an integer, or
+;; excluded if a released version is required.
+;;
+;; It is assumed that if the current version is newer than that specified,
+;; everything passes.  Exceptions occur when known incompatibilities are
+;; introduced."
+;;   (inversion-test 'speedbar
+;;               (concat major "." minor
+;;                       (when beta (concat "beta" beta)))))
+
+(defvar speedbar-initial-expansion-mode-alist
+  '(("buffers" speedbar-buffer-easymenu-definition speedbar-buffers-key-map
+     speedbar-buffer-buttons)
+    ("quick buffers" speedbar-buffer-easymenu-definition speedbar-buffers-key-map
+     speedbar-buffer-buttons-temp)
+    ;; Files last, means first in the Displays menu
+    ("files" speedbar-easymenu-definition-special speedbar-file-key-map
+     speedbar-directory-buttons speedbar-default-directory-list)
+    )
+  "List of named expansion elements for filling the speedbar frame.
+These expansion lists are only valid for regular files.  Special modes
+still get to override this list on a mode-by-mode basis.  This list of
+lists is of the form (NAME MENU KEYMAP FN1 FN2 ...).  NAME is a string
+representing the types of things to be displayed.  MENU is an easymenu
+structure used when in this mode.  KEYMAP is a local keymap to install
+over the regular speedbar keymap.  FN1 ...  are functions that will be
+called in order.  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-initial-expansion-list-name "files"
+  "A symbol name representing the expansion list to use.
+The expansion list `speedbar-initial-expansion-mode-alist' contains
+the names and associated functions to use for buttons in speedbar.")
+
+(defvar speedbar-previously-used-expansion-list-name "files"
+  "Save the last expansion list method.
+This is used for returning to a previous expansion list method when
+the user is done with the current expansion list.")
 
 (defvar speedbar-stealthy-function-list
-  '(speedbar-update-current-file speedbar-check-vc)
+  '(("files"
+     speedbar-update-current-file
+     speedbar-check-read-only
+     speedbar-check-vc
+     speedbar-check-objects)
+    )
   "List of functions to periodically call stealthily.
+This list is of the form:
+ '( (\"NAME\" FUNCTION ...)
+    ...)
+where NAME is the name of the major display mode these functions are
+for, and the remaining elements FUNCTION are functions to call in order.
 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.")
 
+(defvar speedbar-mode-functions-list
+  '(("files" (speedbar-item-info . speedbar-files-item-info)
+     (speedbar-line-directory . speedbar-files-line-directory))
+    ("buffers" (speedbar-item-info . speedbar-buffers-item-info)
+     (speedbar-line-directory . speedbar-buffers-line-directory))
+    ("quick buffers" (speedbar-item-info . speedbar-buffers-item-info)
+     (speedbar-line-directory . speedbar-buffers-line-directory))
+    )
+  "List of function tables to use for different major display modes.
+It is not necessary to define any functions for a specialized mode.
+This just provides a simple way of adding lots of customizations.
+Each sublist is of the form:
+  (\"NAME\" (FUNCTIONSYMBOL . REPLACEMENTFUNCTION) ...)
+Where NAME is the name of the specialized mode.  The rest of the list
+is a set of dotted pairs of the form FUNCTIONSYMBOL, which is the name
+of a function you would like to replace, and REPLACEMENTFUNCTION,
+which is a function you can call instead.  Not all functions can be
+replaced this way.  Replaceable functions must provide that
+functionality individually.")
+
 (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
@@ -390,30 +184,65 @@ 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.
+(defcustom speedbar-query-confirmation-method 'all
+  "*Query control for file operations.
+The 'always flag means to always query before file operations.
+The 'none-but-delete flag means to not query before any file
+operations, except before a file deletion."
+  :group 'speedbar
+  :type '(radio (const :tag "Always Query before some file operations."
+                      all)
+               (const :tag "Never Query before file operations, except for deletions."
+                      none-but-delete)
+;;;;           (const :tag "Never Every Query."
+;;;;                  none)
+               ))
 
-  Each function is called with the default and frame belonging to
-speedbar, and with one parameter; the buffer requesting
-the speedbar display.")
+(defvar speedbar-special-mode-expansion-list nil
+  "Default function list for creating specialized button lists.
+This list is set by modes that wish to have special speedbar displays.
+The list is of function names.  Each function is called with one
+parameter BUFFER, the originating buffer.  The current buffer is the
+speedbar buffer.")
+
+(defvar speedbar-special-mode-key-map nil
+  "Default keymap used when identifying a specialized display mode.
+This keymap is local to each buffer that wants to define special keybindings
+effective when its display is shown.")
+
+(defcustom speedbar-before-visiting-file-hook '(push-mark)
+  "*Hooks run before speedbar visits a file in the selected frame.
+The default buffer is the buffer in the selected window in the attached frame."
+  :group 'speedbar
+  :type 'hook)
 
 (defcustom speedbar-visiting-file-hook nil
-  "Hooks run when speedbar visits a file in the selected frame."
+  "*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."
+(defcustom speedbar-before-visiting-tag-hook '(push-mark)
+  "*Hooks run before speedbar visits a tag in the selected frame.
+The default buffer is the buffer in the selected window in the attached frame."
   :group 'speedbar
   :type 'hook)
 
+(defcustom speedbar-visiting-tag-hook '(speedbar-highlight-one-tag-line)
+  "*Hooks run when speedbar visits a tag in the selected frame."
+  :group 'speedbar
+  :type 'hook
+  :options '(speedbar-highlight-one-tag-line
+            speedbar-recenter-to-top
+            speedbar-recenter
+            ))
+
 (defcustom speedbar-load-hook nil
-  "Hooks run when speedbar is loaded."
+  "*Hooks run when speedbar is loaded."
+  :group 'speedbar
+  :type 'hook)
+
+(defcustom speedbar-reconfigure-keymaps-hook nil
+  "*Hooks run when the keymaps are regenerated."
   :group 'speedbar
   :type 'hook)
 
@@ -423,37 +252,34 @@ nil means don't show the file in the list."
   :group 'speedbar
   :type 'boolean)
 
-(defcustom speedbar-update-speed
-  (if speedbar-xemacsp
-      (if speedbar-xemacs20p
-         2                             ; 1 is too obrusive in XEmacs
-       5)                              ; when no idleness, need long delay
-    1)
-  "*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)
+;;; EVENTUALLY REMOVE THESE
 
-(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)
+;; When I moved to a repeating timer, I had the horrible missfortune
+;; of loosing the ability for adaptive speed choice.  This update
+;; speed currently causes long delays when it should have been turned off.
+(defvar speedbar-update-speed dframe-update-speed
+  "*Obsoleted variable.  Use `dframe-update-speed'.")
+
+(defvar speedbar-navigating-speed dframe-update-speed
+  "*Obsoleted variable.  Use `dframe-update-speed'.")
+;;; END REMOVE THESE
 
 (defcustom speedbar-frame-parameters '((minibuffer . nil)
                                       (width . 20)
-                                      (scroll-bar-width . 10)
                                       (border-width . 0)
                                       (menu-bar-lines . 0)
-                                      (unsplittable . t))
+                                      (tool-bar-lines . 0)
+                                      (unsplittable . t)
+                                      (left-fringe . 0)
+                                      )
   "*Parameters to use when creating the speedbar frame in Emacs.
-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."
+Any parameter supported by a frame may be added.  The parameter `height'
+will be initialized to the height of the frame speedbar is
+attached to and added to this list before the new frame is initialized."
   :group 'speedbar
-  :type '(repeat (sexp :tag "Parameter:")))
+  :type '(repeat (cons :format "%v"
+                      (symbol :tag "Parameter")
+                      (sexp :tag "Value"))))
 
 ;; These values by Hrvoje Niksic <hniksic@srce.hr>
 (defcustom speedbar-frame-plist
@@ -461,10 +287,8 @@ is attached to."
               internal-border-width 0 unsplittable t
               default-toolbar-visible-p nil has-modeline-p nil
               menubar-visible-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"])
+              default-gutter-visible-p nil
+              )
   "*Parameters to use when creating the speedbar frame in XEmacs.
 Parameters not listed here which will be added automatically are
 `height' which will be initialized to the height of the frame speedbar
@@ -474,26 +298,94 @@ is attached to."
                        (symbol :tag "Property")
                        (sexp :tag "Value"))))
 
-(defcustom speedbar-use-imenu-flag (stringp (locate-library "imenu"))
+(defcustom speedbar-use-imenu-flag (fboundp 'imenu)
   "*Non-nil means use imenu for file parsing.  nil to use etags.
 XEmacs prior to 20.4 doesn't support imenu, therefore the default is to
 use etags instead.  Etags support is not as robust as imenu support."
-  :tag "User Imenu"
+  :tag "Use Imenu for tags"
   :group 'speedbar
   :type 'boolean)
 
-(defcustom speedbar-sort-tags nil
-  "*If Non-nil, sort tags in the speedbar display."
+(defvar speedbar-dynamic-tags-function-list
+  '((speedbar-fetch-dynamic-imenu . speedbar-insert-imenu-list)
+    (speedbar-fetch-dynamic-etags . speedbar-insert-etags-list))
+  "Set to a list of functions which will return and insert a list of tags.
+Each element is of the form ( FETCH .  INSERT ) where FETCH
+is a function which takes one parameter (the file to tag) and returns a
+list of tags.  The tag list can be of any form as long as the
+corresponding insert method can handle it.  If it returns t, then an
+error occurred, and the next fetch routine is tried.
+INSERT is a function which takes an INDENTation level, and a LIST of
+tags to insert.  It will then create the speedbar buttons.")
+
+(defcustom speedbar-use-tool-tips-flag (and (not (featurep 'xemacs))
+                                      (>= emacs-major-version 21))
+  "*Non-nil means to use tool tips if they are avaialble.
+When tooltips are not available, mouse-tracking and minibuffer
+display is used instead."
+  :group 'speedbar
+  :type 'boolean)
+
+(defcustom speedbar-track-mouse-flag (not speedbar-use-tool-tips-flag)
+  "*Non-nil means to display info about the line under the mouse."
   :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."
+(defcustom speedbar-sort-tags nil
+  "*If non-nil, sort tags in the speedbar display.  *Obsolete*.
+Use `semantic-tag-hierarchy-method' instead."
   :group 'speedbar
   :type 'boolean)
 
+(defcustom speedbar-tag-hierarchy-method
+  '(speedbar-prefix-group-tag-hierarchy
+    speedbar-trim-words-tag-hierarchy)
+  "*List of hooks which speedbar will use to organize tags into groups.
+Groups are defined as expandable meta-tags.  Imenu supports
+such things in some languages, such as separating variables from
+functions.  Each hook takes one argument LST, and may destructively
+create a new list of the same form.  LST is a list of elements of the
+form:
+  (ELT1 ELT2 ... ELTn)
+where each ELT is of the form
+  (TAG-NAME-STRING . NUMBER-OR-MARKER)
+or
+  (GROUP-NAME-STRING ELT1 ELT2... ELTn)"
+  :group 'speedbar
+  :type 'hook
+  :options '(speedbar-prefix-group-tag-hierarchy
+            speedbar-trim-words-tag-hierarchy
+            speedbar-simple-group-tag-hierarchy
+            speedbar-sort-tag-hierarchy)
+  )
+
+(defcustom speedbar-tag-group-name-minimum-length 4
+  "*The minimum length of a prefix group name before expanding.
+Thus, if the `speedbar-tag-hierarchy-method' includes `prefix-group'
+and one such groups common characters is less than this number of
+characters, then the group name will be changed to the form of:
+  worda to wordb
+instead of just
+  word
+This way we won't get silly looking listings."
+  :group 'speedbar
+  :type 'integer)
+
+(defcustom speedbar-tag-split-minimum-length 20
+  "*Minimum length before we stop trying to create sub-lists in tags.
+This is used by all tag-hierarchy methods that break large lists into
+sub-lists."
+  :group 'speedbar
+  :type 'integer)
+
+(defcustom speedbar-tag-regroup-maximum-length 10
+  "*Maximum length of submenus that are regrouped.
+If the regrouping option is used, then if two or more short subgroups
+are next to each other, then they are combined until this number of
+items is reached."
+  :group 'speedbar
+  :type 'integer)
+
 (defcustom speedbar-directory-button-trim-method 'span
   "*Indicates how the directory button will be displayed.
 Possible values are:
@@ -517,11 +409,26 @@ hierarchy would be replaced with the new directory."
   :group 'speedbar
   :type 'boolean)
 
+(defcustom speedbar-indentation-width 1
+  "*When sub-nodes are expanded, the number of spaces used for indentation."
+  :group 'speedbar
+  :type 'integer)
+
+(defcustom speedbar-hide-button-brackets-flag nil
+  "*Non-nil means speedbar will hide the brackets around the + or -."
+  :group 'speedbar
+  :type 'boolean)
+
 (defcustom speedbar-before-popup-hook nil
   "*Hooks called before popping up the speedbar frame."
   :group 'speedbar
   :type 'hook)
 
+(defcustom speedbar-after-create-hook '(speedbar-frame-reposition-smartly)
+  "*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
@@ -544,35 +451,30 @@ verbosity."
   :group 'speedbar
   :type 'integer)
 
+(defvar speedbar-indicator-separator " "
+  "String separating file text from indicator characters.")
+
 (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'"
+Any file checked out is marked with `speedbar-vc-indicator'."
   :group 'speedbar-vc
   :type 'boolean)
 
-(defvar speedbar-vc-indicator " *"
+(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'")
+Other version control systems can be added by examining the function
+`speedbar-vc-directory-enable-hook' and `speedbar-vc-in-control-hook'.")
 
-(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 parameter which is the path
+(defcustom speedbar-vc-directory-enable-hook nil
+  "*Return non-nil if the current directory should be checked for Version Control.
+Functions in this hook must accept one parameter which is the directory
 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 parameters.  The PATH of the
+Functions in this hook must accept two parameters.  The DIRECTORY of the
 current file, and the FILENAME of the file being checked."
   :group 'speedbar-vc
   :type 'hook)
@@ -580,13 +482,66 @@ current file, and the FILENAME of the file being checked."
 (defvar speedbar-vc-to-do-point nil
   "Local variable maintaining the current version control check position.")
 
-(defvar speedbar-ignored-modes nil
+(defcustom speedbar-obj-do-check t
+  "*Non-nil check all files in speedbar to see if they have an object file.
+Any file checked out is marked with `speedbar-obj-indicator', and the
+marking is based on `speedbar-obj-alist'"
+  :group 'speedbar-vc
+  :type 'boolean)
+
+(defvar speedbar-obj-to-do-point nil
+  "Local variable maintaining the current version control check position.")
+
+(defvar speedbar-obj-indicator '("#" . "!")
+  "Text used to mark files that have a corresponding hidden object file.
+The car is for an up-to-date object.  The cdr is for an out of date object.
+The expression `speedbar-obj-alist' defines who gets tagged.")
+
+(defvar speedbar-obj-alist
+  '(("\\.\\([cpC]\\|cpp\\|cc\\|cxx\\)$" . ".o")
+    ("\\.el$" . ".elc")
+    ("\\.java$" . ".class")
+    ("\\.f\\(or\\|90\\|77\\)?$" . ".o")
+    ("\\.tex$" . ".dvi")
+    ("\\.texi$" . ".info"))
+  "Alist of file extensions, and their corresponding object file type.")
+
+(defvar speedbar-ro-to-do-point nil
+  "Local variable maintaining the current read only check position.")
+
+(defvar speedbar-object-read-only-indicator "%"
+  "Indicator to append onto a line if that item is Read Only.")
+
+;; Note: Look for addition place to add indicator lists that
+;; use skip-chars instead of a regular expression.
+(defvar speedbar-indicator-regex
+  (concat (regexp-quote speedbar-indicator-separator)
+         "\\("
+         (regexp-quote speedbar-vc-indicator)
+         "\\|"
+         (regexp-quote (car speedbar-obj-indicator))
+         "\\|"
+         (regexp-quote (cdr speedbar-obj-indicator))
+         "\\|"
+         (regexp-quote speedbar-object-read-only-indicator)
+         "\\)*")
+  "Regular expression used when identifying files.
+Permits stripping of indicator characters from a line.")
+
+(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)
+
+(defvar speedbar-ignored-modes '(fundamental-mode)
   "*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."
+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)) ?.)
@@ -602,46 +557,62 @@ with . followed by extensions, followed by full-filenames."
            (if regex2 (concat "\\(" regex2 "\\)") "")
            "\\)$")))
 
-(defvar speedbar-ignored-path-regexp nil
-  "Regular expression matching paths speedbar will not switch to.
-Created from `speedbar-ignored-path-expressions' with the function
+(defvar speedbar-ignored-directory-regexp nil
+  "Regular expression matching directorys speedbar will not switch to.
+Created from `speedbar-ignored-directory-expressions' with the function
 `speedbar-extension-list-to-regex' (A misnamed function in this case.)
-Use the function `speedbar-add-ignored-path-regexp', or customize the
-variable `speedbar-ignored-path-expressions' to modify this variable.")
+Use the function `speedbar-add-ignored-directory-regexp', or customize the
+variable `speedbar-ignored-directory-expressions' to modify this variable.")
 
-(defcustom speedbar-ignored-path-expressions
-  '("/logs?/\\'")
+(defcustom speedbar-ignored-directory-expressions
+  '("[/\\]logs?[/\\]\\'")
   "*List of regular expressions matching directories speedbar will ignore.
-They should included paths to directories which are notoriously very
+They should included directorys 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-add-ignored-directory-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"))
+  :type '(repeat (regexp :tag "Directory Regexp"))
   :set (lambda (sym val)
-        (setq speedbar-ignored-path-expressions val
-              speedbar-ignored-path-regexp
+        (setq speedbar-ignored-directory-expressions val
+              speedbar-ignored-directory-regexp
               (speedbar-extension-list-to-regex val))))
 
+(defcustom speedbar-directory-unshown-regexp "^\\(CVS\\|RCS\\|SCCS\\|\\..*\\)\\'"
+  "*Regular expression matching directories not to show in speedbar.
+They should include commonly existing directories which are not
+useful, such as version control."
+  :group 'speedbar
+  :type 'string)
+
 (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 "\\|#[^#]+#$\\|\\.\\.?\\'"))
+    ;;               backup      refdir      lockfile
+    (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-file-regexp nil
+  "Regular expression matching files we know how to expand.
+Created from `speedbar-supported-extension-expressions' with the
+function `speedbar-extension-list-to-regex'")
+
 ;; this is dangerous to customize, because the defaults will probably
 ;; change in the future.
 (defcustom speedbar-supported-extension-expressions
-  (append '(".[CcHh]\\(\\+\\+\\|pp\\|c\\|h\\)?" ".tex\\(i\\(nfo\\)?\\)?"
-           ".el" ".emacs" ".l" ".lsp" ".p" ".java")
+  (append '(".[ch]\\(\\+\\+\\|pp\\|c\\|h\\|xx\\)?" ".tex\\(i\\(nfo\\)?\\)?"
+           ".el" ".emacs" ".l" ".lsp" ".p" ".java" ".f\\(90\\|77\\|or\\)?")
          (if speedbar-use-imenu-flag
-             '(".f90" ".ada" ".pl" ".tcl" ".m"
-               "Makefile\\(\\.in\\)?")))
+             '(".ada" ".p[lm]" ".tcl" ".m" ".scm" ".pm" ".py" ".g"
+               ;; html is not supported by default, but an imenu tags package
+               ;; is available.  Also, html files are nice to be able to see.
+               ".s?html"
+               ".ma?k" "[Mm]akefile\\(\\.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
@@ -649,19 +620,18 @@ 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."
+file.
+If you add an extension to this list, and it does not appear, you may
+need to also modify `completion-ignored-extension' which will also help
+file completion."
   :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)))
-  )
+        (set 'speedbar-supported-extension-expressions val)
+        (set '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'")
+(setq speedbar-file-regexp
+      (speedbar-extension-list-to-regex speedbar-supported-extension-expressions))
 
 (defun speedbar-add-supported-extension (extension)
   "Add EXTENSION as a new supported extension for speedbar tagging.
@@ -669,6 +639,7 @@ 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."
+  (interactive "sExtension: ")
   (if (not (listp extension)) (setq extension (list extension)))
   (while extension
     (if (member (car extension) speedbar-supported-extension-expressions)
@@ -679,39 +650,41 @@ list of strings."
   (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)
+(defun speedbar-add-ignored-directory-regexp (directory-expression)
+  "Add DIRECTORY-EXPRESSION as a new ignored directory for speedbar tracking.
+This function will modify `speedbar-ignored-directory-regexp' and add
+DIRECTORY-EXPRESSION to `speedbar-ignored-directory-expressions'."
+  (interactive "sDirectory regex: ")
+  (if (not (listp directory-expression))
+      (setq directory-expression (list directory-expression)))
+  (while directory-expression
+    (if (member (car directory-expression) speedbar-ignored-directory-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)))
+      (setq speedbar-ignored-directory-expressions
+           (cons (car directory-expression) speedbar-ignored-directory-expressions)))
+    (setq directory-expression (cdr directory-expression)))
+  (setq speedbar-ignored-directory-regexp (speedbar-extension-list-to-regex
+                                     speedbar-ignored-directory-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)))
+         speedbar-ignored-directory-regexp (speedbar-extension-list-to-regex
+                                       speedbar-ignored-directory-expressions)))
 
-(defvar speedbar-update-flag (or (fboundp 'run-with-idle-timer)
-                                (fboundp 'start-itimer)
-                                (boundp 'post-command-idle-hook))
+(defvar speedbar-update-flag dframe-have-timer-flag
   "*Non-nil means to automatically update the display.
-When this is nil then speedbar will not follow the attached frame's path.
+When this is nil then speedbar will not follow the attached frame's directory.
 When speedbar is active, use:
 
 \\<speedbar-key-map> `\\[speedbar-toggle-updates]'
 
 to toggle this value.")
 
+(defvar speedbar-update-flag-disable nil
+  "Permanently disable changing of the update flag.")
+
 (defvar speedbar-syntax-table nil
   "Syntax-table used on the speedbar.")
 
@@ -723,10 +696,11 @@ to toggle this value.")
   (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)
   (modify-syntax-entry ?] " " speedbar-syntax-table))
 
-
 (defvar speedbar-key-map nil
   "Keymap used in speedbar buffer.")
 
@@ -736,113 +710,147 @@ to toggle this value.")
   (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)
+  (define-key speedbar-key-map "g" 'speedbar-refresh)
 
   ;; 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 speedbar-xemacsp
-      (progn
-       ;; mouse bindings so we can manipulate the items on each line
-       (define-key speedbar-key-map 'button2 'speedbar-click)
-       (define-key speedbar-key-map '(shift button2) 'speedbar-power-click)
-       (define-key speedbar-key-map 'button3 'speedbar-xemacs-popup-kludge)
-       (define-key speedbar-key-map '(meta button3) 'speedbar-mouse-item-info))
-    ;; 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 new frames, or refreshing a cache
-    (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)
-
-    (define-key speedbar-key-map [down-mouse-3] 'speedbar-emacs-popup-kludge)
-
-    ;;***** Disable disabling: Remove menubar completely.
-    ;; 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)
-    ))
+  (define-key speedbar-key-map "\M-n" 'speedbar-restricted-next)
+  (define-key speedbar-key-map "\M-p" 'speedbar-restricted-prev)
+  (define-key speedbar-key-map "\C-\M-n" 'speedbar-forward-list)
+  (define-key speedbar-key-map "\C-\M-p" 'speedbar-backward-list)
+;; These commands never seemed useful.
+;;  (define-key speedbar-key-map " " 'speedbar-scroll-up)
+;;  (define-key speedbar-key-map [delete] 'speedbar-scroll-down)
+
+  ;; Short cuts I happen to find useful
+  (define-key speedbar-key-map "r"
+    (lambda () (interactive)
+      (speedbar-change-initial-expansion-list
+       speedbar-previously-used-expansion-list-name)))
+  (define-key speedbar-key-map "b"
+    (lambda () (interactive)
+      (speedbar-change-initial-expansion-list "quick buffers")))
+  (define-key speedbar-key-map "f"
+    (lambda () (interactive)
+      (speedbar-change-initial-expansion-list "files")))
+
+  (dframe-update-keymap speedbar-key-map)
+)
+
+(defun speedbar-make-specialized-keymap ()
+  "Create a keymap for use with a speedbar major or minor display mode.
+This basically creates a sparse keymap, and makes it's parent be
+`speedbar-key-map'."
+  (let ((k (make-sparse-keymap)))
+    (set-keymap-parent k speedbar-key-map)
+    k))
+
+(defvar speedbar-file-key-map nil
+  "Keymap used in speedbar buffer while files are displayed.")
+
+(if speedbar-file-key-map
+    nil
+  (setq speedbar-file-key-map (speedbar-make-specialized-keymap))
+
+  ;; Basic tree features
+  (define-key speedbar-file-key-map "e" 'speedbar-edit-line)
+  (define-key speedbar-file-key-map "\C-m" 'speedbar-edit-line)
+  (define-key speedbar-file-key-map "+" 'speedbar-expand-line)
+  (define-key speedbar-file-key-map "=" 'speedbar-expand-line)
+  (define-key speedbar-file-key-map "-" 'speedbar-contract-line)
+
+  (define-key speedbar-file-key-map "[" 'speedbar-expand-line-descendants)
+  (define-key speedbar-file-key-map "]" 'speedbar-contract-line-descendants)
+
+  (define-key speedbar-file-key-map " " 'speedbar-toggle-line-expansion)
+
+  ;; file based commands
+  (define-key speedbar-file-key-map "U" 'speedbar-up-directory)
+  (define-key speedbar-file-key-map "I" 'speedbar-item-info)
+  (define-key speedbar-file-key-map "B" 'speedbar-item-byte-compile)
+  (define-key speedbar-file-key-map "L" 'speedbar-item-load)
+  (define-key speedbar-file-key-map "C" 'speedbar-item-copy)
+  (define-key speedbar-file-key-map "D" 'speedbar-item-delete)
+  (define-key speedbar-file-key-map "O" 'speedbar-item-object-delete)
+  (define-key speedbar-file-key-map "R" 'speedbar-item-rename)
+  (define-key speedbar-file-key-map "M" 'speedbar-create-directory)
+  )
 
 (defvar speedbar-easymenu-definition-base
-  '("Speedbar"
-    ["Update" speedbar-refresh t]
-    ["Auto Update" speedbar-toggle-updates
-     :style toggle :selected speedbar-update-flag]
-    )
+  (append
+   '("Speedbar"
+     ["Update" speedbar-refresh t]
+     ["Auto Update" speedbar-toggle-updates
+      :active (not speedbar-update-flag-disable)
+      :style toggle :selected speedbar-update-flag])
+   (if (and (or (fboundp 'defimage)
+               (fboundp 'make-image-specifier))
+           (if (fboundp 'display-graphic-p)
+               (display-graphic-p)
+             window-system))
+       (list
+       ["Use Images" speedbar-toggle-images
+        :style toggle :selected speedbar-use-images]))
+   )
   "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
+    ["Expand File Tags" speedbar-expand-line
      (save-excursion (beginning-of-line)
                     (looking-at "[0-9]+: *.\\+. "))]
-    ["Contract Item" speedbar-contract-line
+    ["Flush Cache & Expand" speedbar-flush-expand-line
+     (save-excursion (beginning-of-line)
+                    (looking-at "[0-9]+: *.\\+. "))]
+    ["Expand All Descendants" speedbar-expand-line-descendants
+     (save-excursion (beginning-of-line)
+                    (looking-at "[0-9]+: *.\\+. ")) ]
+    ["Contract File Tags" speedbar-contract-line
      (save-excursion (beginning-of-line)
                     (looking-at "[0-9]+: *.-. "))]
-    ["Sort Tags" speedbar-toggle-sorting
-     :style toggle :selected speedbar-sort-tags]
+;    ["Sort Tags" speedbar-toggle-sorting
+;     :style toggle :selected speedbar-sort-tags]
     "----"
-    ["Item Information" speedbar-item-info t]
+    ["File/Tag Information" speedbar-item-info t]
     ["Load Lisp File" speedbar-item-load
      (save-excursion
        (beginning-of-line)
-       (looking-at "[0-9]+: *\\[[+-]\\] .+\\(\\.el\\)\\( \\*\\)?$"))]
+       (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
+       (looking-at "[0-9]+: *\\[[+-]\\] .+\\(\\.el\\)\\( \\|$\\)"))]
+    ["Copy File" speedbar-item-copy
      (save-excursion (beginning-of-line) (looking-at "[0-9]+: *\\["))]
-    ["Rename Item" speedbar-item-rename
+    ["Rename File" speedbar-item-rename
+     (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
+    ["Create Directory" speedbar-create-directory
      (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
-    ["Delete Item" speedbar-item-delete
-     (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))])
+    ["Delete File" speedbar-item-delete
+     (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
+    ["Delete Object" speedbar-item-object-delete
+     (save-excursion (beginning-of-line)
+                    (looking-at "[0-9]+: *\\[[+-]\\] [^ \n]+ \\*?[!#]$"))]
+    )
   "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]))
+  (append
+   (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
+       (list ["Customize..." speedbar-customize t]))
+   (list
+    ["Detach" speedbar-detach (and speedbar-frame
+                                   (eq (selected-frame) speedbar-frame)) ]
+    ["Close" dframe-close-frame t]
+    ["Quit" delete-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.
+  "Non-nil when speedbar is showing buttons specific to a special mode.
 In this case it is the originating buffer.")
 (defvar speedbar-buffer nil
   "The buffer displaying the speedbar.")
@@ -852,12 +860,6 @@ In this case it is the originating buffer.")
   "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.")
@@ -875,6 +877,20 @@ directories.")
   "Never set this by hand.  Value is t when S-mouse activity occurs.")
 
 \f
+;;; Compatibility
+;;
+(defalias 'speedbar-make-overlay
+  (if (featurep 'xemacs) 'make-extent 'make-overlay))
+
+(defalias 'speedbar-overlay-put 
+  (if (featurep 'xemacs) 'set-extent-property 'overlay-put))
+
+(defalias 'speedbar-delete-overlay 
+  (if (featurep 'xemacs) 'delete-extent 'delete-overlay))
+
+(defalias 'speedbar-mode-line-update 
+  (if (featurep 'xemacs) 'redraw-modeline 'force-mode-line-update))
+\f
 ;;; Mode definitions/ user commands
 ;;
 
@@ -889,87 +905,97 @@ 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")
-  (if (if (and speedbar-xemacsp (fboundp 'console-on-window-system-p))
-         (not (console-on-window-system-p))
-       (not (symbol-value 'window-system)))
-      (error "Speedbar is not useful outside of a windowing environment"))
-;;; RMS says this should not modify the menu.
-;  (if speedbar-xemacsp
-;      (add-menu-button '("Tools")
-;                     ["Speedbar" speedbar-frame-mode
-;                      :style toggle
-;                      :selected (and (boundp 'speedbar-frame)
-;                                     (frame-live-p speedbar-frame)
-;                                     (frame-visible-p speedbar-frame))]
-;                     "--")
-;    (define-key-after (lookup-key global-map [menu-bar tools])
-;      [speedbar] '("Speedbar" . speedbar-frame-mode) [calendar]))
-  ;; 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)
-       (if (and speedbar-frame (frame-live-p speedbar-frame))
-           (progn
-             (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)
-         (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)
-       (setq speedbar-frame
-             (if speedbar-xemacsp
-                 (make-frame (nconc (list 'height
-                                          (speedbar-needed-height))
-                                    speedbar-frame-plist))
-               (let* ((mh (cdr (assoc 'menu-bar-lines (frame-parameters))))
-                      (params (append speedbar-frame-parameters
-                                      (list (cons
-                                             'height
-                                             (if speedbar-xemacsp
-                                                 (speedbar-needed-height)
-                                               (+ mh (frame-height))))))))
-                 (if (< emacs-major-version 20);;a bug is fixed in v20 & later
-                     (make-frame params)
-                   (let ((x-pointer-shape x-pointer-top-left-arrow)
-                         (x-sensitive-text-pointer-shape x-pointer-hand2))
-                     (make-frame params))))))
-       ;; 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)))))
+  ;; Get the buffer to play with
+  (if (not (buffer-live-p speedbar-buffer))
+      (save-excursion
+       (setq speedbar-buffer (get-buffer-create " SPEEDBAR"))
+       (set-buffer speedbar-buffer)
+       (speedbar-mode)))
+  ;; Do the frame thing
+  (dframe-frame-mode arg
+                    'speedbar-frame
+                    'speedbar-cached-frame
+                    'speedbar-buffer
+                    "Speedbar"
+                    #'speedbar-frame-mode
+                    (if dframe-xemacsp
+                        (append speedbar-frame-plist
+                                ;; This is a hack to get speedbar to iconfiy
+                                ;; with the selected frame.
+                                (list 'parent (selected-frame)))
+                      speedbar-frame-parameters)
+                    speedbar-before-delete-hook
+                    speedbar-before-popup-hook
+                    speedbar-after-create-hook)
+  ;; Start up the timer
+  (if (not speedbar-frame)
+      (speedbar-set-timer nil)
+    (speedbar-reconfigure-keymaps)
+    (speedbar-update-contents)
+    (speedbar-set-timer dframe-update-speed)
+    )
+  ;; Frame modifications
+  (set (make-local-variable 'dframe-delete-frame-function)
+       'speedbar-handle-delete-frame)
+  ;; hscroll
+  (set (make-local-variable 'automatic-hscrolling) nil) ; Emacs 21
+  ;; reset the selection variable
+  (setq speedbar-last-selected-file nil))
+
+(defun speedbar-frame-reposition-smartly ()
+  "Reposition the speedbar frame to be next to the attached frame."
+  (cond ((and dframe-xemacsp
+             (or (member 'left speedbar-frame-plist)
+                 (member 'top speedbar-frame-plist)))
+        (dframe-reposition-frame
+         speedbar-frame
+         (dframe-attached-frame speedbar-frame)
+         (cons (car (cdr (member 'left speedbar-frame-plist)))
+               (car (cdr (member 'top speedbar-frame-plist)))))
+        )
+       ((and (not dframe-xemacsp)
+             (or (assoc 'left speedbar-frame-parameters)
+                 (assoc 'top speedbar-frame-parameters)))
+        ;; if left/top were specified in the parameters, pass them
+        ;; down to the reposition function
+        (dframe-reposition-frame
+         speedbar-frame
+         (dframe-attached-frame speedbar-frame)
+         (cons (cdr (assoc 'left speedbar-frame-parameters))
+               (cdr (assoc 'top  speedbar-frame-parameters))))
+        )
+       (t
+        (dframe-reposition-frame speedbar-frame
+                                 (dframe-attached-frame speedbar-frame)
+                                 'left-right))))
+
+(defun speedbar-detach ()
+  "Detach the current Speedbar from auto-updating.
+Doing this allows the creation of a second speedbar."
+  (interactive)
+  (let ((buffer speedbar-buffer))
+    (dframe-detach 'speedbar-frame 'speedbar-cached-frame 'speedbar-buffer)
+    (save-excursion
+      (set-buffer buffer)
+      ;; Permanently disable auto-updating in this speedbar buffer.
+      (set (make-local-variable 'speedbar-update-flag) nil)
+      (set (make-local-variable 'speedbar-update-flag-disable) t)
+      ;; Make local copies of all the different variables to prevent
+      ;; funny stuff later...
+      )))
+
+(defsubst speedbar-current-frame ()
+  "Return the frame to use for speedbar based on current context."
+  (dframe-current-frame 'speedbar-frame 'speedbar-mode))
+
+(defun speedbar-handle-delete-frame (e)
+  "Handle a delete frame event E.
+If the deleted frame is the frame SPEEDBAR is attached to,
+we need to delete speedbar also."
+  (let ((frame-to-be-deleted (car (car (cdr e)))))
+    (if (eq frame-to-be-deleted dframe-attached-frame)
+       (delete-frame speedbar-frame)))
+  )
 
 ;;;###autoload
 (defun speedbar-get-focus ()
@@ -977,42 +1003,23 @@ supported at a time.
 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))
-
-(defun speedbar-close-frame ()
-  "Turn off a currently active speedbar."
-  (interactive)
-  (speedbar-frame-mode -1)
-  (select-frame speedbar-attached-frame)
-  (other-frame 0))
+  (speedbar-reset-scanners)
+  (dframe-get-focus 'speedbar-frame 'speedbar-frame-mode
+                   (lambda () (let ((speedbar-update-flag t))
+                                (speedbar-timer-fn)))))
 
 (defmacro speedbar-frame-width ()
   "Return the width of the speedbar frame in characters.
 nil if it doesn't exist."
-  '(frame-width speedbar-frame))
-
-;; XEmacs function only.
-(defun speedbar-needed-height (&optional frame)
-  "The needed height for the tool bar FRAME (in characters)."
-  (or frame (setq frame (selected-frame)))
-  ;; The 1 is the missing modeline/minibuffer
-  (+ 1 (/ (frame-pixel-height frame)
-         (face-height 'default frame))))
+  '(window-width (get-buffer-window speedbar-buffer)))
 
 (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.
+The first line represents the default directory 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
+directory to that directory.  Buttons are activated by clicking `\\[speedbar-click]'.
+In some situations using `\\[dframe-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 <+>
@@ -1027,9 +1034,14 @@ 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 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'
+for `speedbar-this-file-in-vc' and `speedbar-vc-check-dir-p'.
+
+Files with a `#' or `!' character after them are source files that
+have an object file associated with them.  The `!' indicates that the
+files is out of date.  You can control what source/object associations
+exist through the variable `speedbar-obj-alist'.
 
 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
@@ -1043,71 +1055,67 @@ in the selected file.
 \\{speedbar-key-map}"
   ;; NOT interactive
   (save-excursion
-    (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)
-    (if speedbar-xemacsp
-       (progn
-         ;; Argh!  mouse-track-click-hook doesn't understand the
-         ;; make-local-hook conventions.
-         (make-local-variable 'mouse-track-click-hook)
-         (add-hook 'mouse-track-click-hook
-                   (lambda (event count)
-                     (if (/= (event-button event) 1)
-                         nil           ; Do normal operations.
-                       (cond ((eq count 1)
-                              (speedbar-quick-mouse event))
-                             ((or (eq count 2)
-                                  (eq count 3))
-                              (mouse-set-point event)
-                              (speedbar-do-function-pointer)
-                              (speedbar-quick-mouse event)))
-                       ;; Don't do normal operations.
-                       t)))))
-    (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)))))
-             t t)
+    (setq frame-title-format (concat "Speedbar " speedbar-version))
+    (setq case-fold-search nil)
+    (toggle-read-only 1)
     (speedbar-set-mode-line-format)
-    (if (not speedbar-xemacsp)
-       (setq auto-show-mode nil))      ;no auto-show for Emacs
+    ;; Add in our dframe hooks.
+    (if speedbar-track-mouse-flag
+       (setq dframe-track-mouse-function #'speedbar-track-mouse))
+    (setq dframe-help-echo-function #'speedbar-item-info
+         dframe-mouse-click-function #'speedbar-click
+         dframe-mouse-position-function #'speedbar-position-cursor-on-line)
     (run-hooks 'speedbar-mode-hook))
-  (speedbar-update-contents)
   speedbar-buffer)
 
+(defmacro speedbar-message (fmt &rest args)
+  "Like message, but for use in the speedbar frame.
+Argument FMT is the format string, and ARGS are the arguments for message."
+  `(dframe-message ,fmt ,@args))
+
+(defsubst speedbar-y-or-n-p (prompt &optional deleting)
+  "Like `y-or-n-p', but for use in the speedbar frame.
+Argument PROMPT is the prompt to use.
+Optional argument DELETING means this is a query that will delete something.
+The variable `speedbar-query-confirmation-method' can cause this to
+return true without a query."
+  (or (and (not deleting)
+          (eq speedbar-query-confirmation-method 'none-but-delete))
+      (dframe-y-or-n-p prompt)))
+
+(defsubst speedbar-select-attached-frame ()
+  "Select the frame attached to this speedbar."
+  (dframe-select-attached-frame (speedbar-current-frame)))
+
+;; Backwards compatibility
+(defalias 'speedbar-with-attached-buffer 'dframe-with-attached-buffer)
+(defalias 'speedbar-maybee-jump-to-attached-frame 'dframe-maybee-jump-to-attached-frame)
 (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 (and (frame-live-p speedbar-frame)
-          (or (not speedbar-xemacsp)
-              (specifier-instance has-modeline-p)))
+  (if (and (frame-live-p (speedbar-current-frame))
+          (or (not dframe-xemacsp)
+              (with-no-warnings
+                (specifier-instance has-modeline-p)))
+          speedbar-buffer)
       (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)))
+              (p3 (if speedbar-update-flag "#" "!"))
+              (p35 (capitalize speedbar-initial-expansion-list-name))
+              (blank (- w (length p1) (length p3) (length p5) (length p35)
+                        (if line-number-mode 5 1)))
               (p2 (if (> blank 0)
                       (make-string (/ blank 2) ? )
                     ""))
@@ -1116,117 +1124,121 @@ frame and window to be the currently active frame and window."
                     ""))
               (tf
                (if line-number-mode
-                   (list (concat p1 p2 p3) '(line-number-mode " %3l")
+                   (list (concat p1 p2 p3 " " p35) '(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 ()
+               (speedbar-mode-line-update)))))))
+
+(defvar speedbar-previous-menu nil
+  "The menu before the last `speedbar-reconfigure-keymaps' was called.")
+
+(defun speedbar-reconfigure-keymaps ()
   "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 ((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
-         (if (and (not (assoc "Speedbar" mode-popup-menu)))
-             (easy-menu-add md))
-         (set-buffer-menubar (list md)))
-      (easy-menu-add md))))
+  (let ((md (append
+            speedbar-easymenu-definition-base
+            (if speedbar-shown-directories
+                ;; file display mode version
+                (speedbar-initial-menu)
+              (save-excursion
+                (dframe-select-attached-frame speedbar-frame)
+                (if (local-variable-p
+                     'speedbar-easymenu-definition-special
+                     (current-buffer))
+                    ;; If bound locally, we can use it
+                    speedbar-easymenu-definition-special)))
+            ;; Dynamic menu stuff
+            '("-")
+           (list (cons "Displays"
+                       (let ((displays nil)
+                             (alist speedbar-initial-expansion-mode-alist))
+                         (while alist
+                           (setq displays
+                                 (cons
+                                  (vector
+                                   (capitalize (car (car alist)))
+                                   (list
+                                    'speedbar-change-initial-expansion-list
+                                    (car (car alist)))
+                                   :style 'radio
+                                   :selected
+                                   `(string= ,(car (car alist))
+                                        speedbar-initial-expansion-list-name)
+                                   )
+                                  displays))
+                           (setq alist (cdr alist)))
+                         displays)))
+           ;; The trailer
+           speedbar-easymenu-definition-trailer))
+       (localmap (save-excursion
+                   (let ((cf (selected-frame)))
+                     (prog2
+                         (dframe-select-attached-frame speedbar-frame)
+                         (if (local-variable-p
+                              'speedbar-special-mode-key-map
+                              (current-buffer))
+                             speedbar-special-mode-key-map)
+                       (select-frame cf))))))
+    (save-excursion
+      (set-buffer speedbar-buffer)
+      (use-local-map (or localmap
+                        (speedbar-initial-keymap)
+                        ;; This creates a small keymap we can glom the
+                        ;; menu adjustments into.
+                        (speedbar-make-specialized-keymap)))
+      ;; Delete the old menu if applicable.
+      (if speedbar-previous-menu (easy-menu-remove speedbar-previous-menu))
+      (setq speedbar-previous-menu md)
+      ;; Now add the new menu
+      (if (not dframe-xemacsp)
+         (easy-menu-define speedbar-menu-map (current-local-map)
+                           "Speedbar menu" md)
+       (easy-menu-add md (current-local-map))
+       ;; XEmacs-specific:
+       (if (fboundp 'set-buffer-menubar)
+           (set-buffer-menubar (list md)))))
+
+    (run-hooks 'speedbar-reconfigure-keymaps-hook)))
 
 \f
 ;;; 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)
+    (dframe-select-attached-frame speedbar-frame)
     (customize-group 'speedbar)
     (select-frame sf))
-  (speedbar-maybee-jump-to-attached-frame))
-
-;; 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.
-;;    Hrvoje Niksic <hniksic@srce.hr>
-(defun speedbar-xemacs-popup-kludge (event)
-  "Pop up a menu related to the clicked on item.
-Must be bound to EVENT."
-  (interactive "e")
-  (save-excursion
-    (goto-char (event-closest-point event))
-    (beginning-of-line)
-    (forward-char (min 5 (- (save-excursion (end-of-line) (point))
-                           (save-excursion (beginning-of-line) (point)))))
-    (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-emacs-popup-kludge (e)
-  "Pop up a menu related to the clicked on item.
-Must be bound to event E."
-  (interactive "e")
-  (save-excursion
-    (mouse-set-point e)
-    ;; This gets the cursor where the user can see it.
-    (if (not (bolp)) (forward-char -1))
-    (sit-for 0)
-    (if (< emacs-major-version 20)
-       (mouse-major-mode-menu e)
-      (mouse-major-mode-menu e nil))))
+  (dframe-maybee-jump-to-attached-frame))
+
+(defun speedbar-track-mouse (event)
+  "For motion EVENT, display info about the current line."
+  (if (not speedbar-track-mouse-flag)
+      nil
+    (save-excursion
+      (save-window-excursion
+       (condition-case nil
+           (progn
+             (mouse-set-point event)
+             (if (eq major-mode 'speedbar-mode)
+                 ;; XEmacs may let us get in here in other mode buffers.
+                 (speedbar-item-info)))
+         (t (speedbar-message nil)))))))
+
+(defun speedbar-show-info-under-mouse ()
+  "Call the info function for the line under the mouse.
+Optional EVENT is currently not used."
+  (let ((pos (mouse-position)))        ; we ignore event until I use it later.
+    (if (equal (car pos) speedbar-frame)
+       (save-excursion
+         (save-window-excursion
+           (apply 'set-mouse-position pos)
+           (speedbar-item-info))))))
 
 (defun speedbar-next (arg)
   "Move to the next ARGth line in a speedbar buffer."
@@ -1240,6 +1252,81 @@ Must be bound to event E."
   (interactive "p")
   (speedbar-next (if arg (- arg) -1)))
 
+(defun speedbar-restricted-move (arg)
+  "Move to the next ARGth line in a speedbar buffer at the same depth.
+This means that movement is restricted to a subnode, and that siblings
+of intermediate nodes are skipped."
+  (if (not (numberp arg)) (signal 'wrong-type-argument (list arg 'numberp)))
+  ;; First find the extent for which we are allowed to move.
+  (let ((depth (save-excursion (beginning-of-line)
+                              (if (looking-at "[0-9]+:")
+                                  (string-to-number (match-string 0))
+                                0)))
+       (crement (if (< arg 0) 1 -1))   ; decrement or increment
+       (lastmatch (point)))
+    (while (/= arg 0)
+      (forward-line (- crement))
+      (let ((subdepth (save-excursion (beginning-of-line)
+                                     (if (looking-at "[0-9]+:")
+                                         (string-to-number (match-string 0))
+                                       0))))
+       (cond ((or (< subdepth depth)
+                  (progn (end-of-line) (eobp))
+                  (progn (beginning-of-line) (bobp)))
+              ;; We have reached the end of this block.
+              (goto-char lastmatch)
+              (setq arg 0)
+              (error "End of sub-list"))
+             ((= subdepth depth)
+              (setq lastmatch (point)
+                    arg (+ arg crement))))))
+    (speedbar-position-cursor-on-line)))
+
+(defun speedbar-restricted-next (arg)
+  "Move to the next ARGth line in a speedbar buffer at the same depth.
+This means that movement is restricted to a subnode, and that siblings
+of intermediate nodes are skipped."
+  (interactive "p")
+  (speedbar-restricted-move (or arg 1))
+  (speedbar-item-info))
+
+(defun speedbar-restricted-prev (arg)
+  "Move to the previous ARGth line in a speedbar buffer at the same depth.
+This means that movement is restricted to a subnode, and that siblings
+of intermediate nodes are skipped."
+  (interactive "p")
+  (speedbar-restricted-move (if arg (- arg) -1))
+  (speedbar-item-info))
+
+(defun speedbar-navigate-list (arg)
+  "Move across ARG groups of similarly typed items in speedbar.
+Stop on the first line of the next type of item, or on the last or first item
+if we reach a buffer boundary."
+  (interactive "p")
+  (beginning-of-line)
+  (if (looking-at "[0-9]+: *[[<{][-+?][]>}] ")
+      (let ((str (regexp-quote (match-string 0))))
+       (while (looking-at str)
+         (speedbar-restricted-move arg)
+         (beginning-of-line))))
+  (speedbar-position-cursor-on-line))
+
+(defun speedbar-forward-list ()
+  "Move forward over the current list.
+A LIST in speedbar is a group of similarly typed items, such as directories,
+files, or the directory button."
+  (interactive)
+  (speedbar-navigate-list 1)
+  (speedbar-item-info))
+
+(defun speedbar-backward-list ()
+  "Move backward over the current list.
+A LIST in speedbar is a group of similarly typed items, such as directories,
+files, or the directory button."
+  (interactive)
+  (speedbar-navigate-list -1)
+  (speedbar-item-info))
+
 (defun speedbar-scroll-up (&optional arg)
   "Page down one screen-full of the speedbar, or ARG lines."
   (interactive "P")
@@ -1254,49 +1341,56 @@ Must be bound to event E."
 
 (defun speedbar-up-directory ()
   "Keyboard accelerator for moving the default directory up one.
-Assumes that the current buffer is the speedbar buffer"
+Assumes that the current buffer is the speedbar buffer."
   (interactive)
   (setq default-directory (expand-file-name (concat default-directory "../")))
   (speedbar-update-contents))
 \f
 ;;; 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))
+(defun speedbar-refresh (&optional arg)
+  "Refresh the current speedbar display, disposing of any cached data.
+Argument ARG represents to force a refresh past any caches that may exist."
+  (interactive "P")
+  (let ((dl speedbar-shown-directories)
+       (dframe-power-click arg)
+       deactivate-mark)
+    ;; We need to hack something so this works in detached frames.
     (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")))
+      (setq dl (cdr dl)))
+    (if (<= 1 speedbar-verbosity-level)
+       (speedbar-message "Refreshing speedbar..."))
+    (speedbar-update-contents)
+    (speedbar-stealthy-updates)
+    ;; Reset the timer in case it got really hosed for some reason...
+    (speedbar-set-timer dframe-update-speed)
+    (if (<= 1 speedbar-verbosity-level)
+       (speedbar-message "Refreshing speedbar...done"))))
 
 (defun speedbar-item-load ()
-  "Load the item under the cursor or mouse if it is a lisp file."
+  "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)))
+                (speedbar-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..."))))
+      (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."
+  "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)
+         (dframe-select-attached-frame speedbar-frame)
          (byte-compile-file f nil)
-         (select-frame sf)))
+         (select-frame sf)
+         (speedbar-reset-scanners)))
     ))
 
 (defun speedbar-mouse-item-info (event)
@@ -1306,36 +1400,113 @@ This should be bound to a mouse EVENT."
   (mouse-set-point event)
   (speedbar-item-info))
 
+(defun speedbar-generic-item-info ()
+  "Attempt to derive, and then display information about this line item.
+File style information is displayed with `speedbar-item-info'."
+  (save-excursion
+    (beginning-of-line)
+    ;; Skip invisible number info.
+    (if (looking-at "\\([0-9]+\\):") (goto-char (match-end 0)))
+    ;; Skip items in "folder" type text characters.
+    (if (looking-at "\\s-*[[<({].[]>)}] ") (goto-char (match-end 0)))
+    ;; Get the text
+    (speedbar-message "Text: %s" (buffer-substring-no-properties
+                                 (point) (progn (end-of-line) (point))))))
+
 (defun speedbar-item-info ()
-  "Display info in the mini-buffer about the button the mouse is over."
+  "Display info in the mini-buffer about the button the mouse is over.
+This function can be replaced in `speedbar-mode-functions-list' as
+`speedbar-item-info'."
   (interactive)
+  (let (message-log-max)
+    (funcall (or (speedbar-fetch-replacement-function 'speedbar-item-info)
+                'speedbar-generic-item-info))))
+
+(defun speedbar-item-info-file-helper (&optional filename)
+  "Display info about a file that is on the current line.
+nil if not applicable.  If FILENAME, then use that instead of reading
+it from the speedbar buffer."
+  (let* ((item (or filename (speedbar-line-file)))
+        (attr (if item (file-attributes item) nil)))
+    (if (and item attr) (speedbar-message "%s %-6d %s" (nth 8 attr)
+                                         (nth 7 attr) item)
+      nil)))
+
+(defun speedbar-item-info-tag-helper ()
+  "Display info about a tag that is on the current line.
+nil if not applicable."
+  (save-excursion
+    (beginning-of-line)
+    (if (re-search-forward " [-+=]?> \\([^\n]+\\)"
+                          (save-excursion(end-of-line)(point)) t)
+       (let* ((tag (match-string 1))
+             (attr (speedbar-line-token))
+             (item nil)
+             (semantic-tagged (if (fboundp 'semantic-tag-p)
+                                  (semantic-tag-p attr))))
+         (if semantic-tagged
+           (with-no-warnings
+             (save-excursion
+               (when (and (semantic-tag-overlay attr)
+                          (semantic-tag-buffer attr))
+                 (set-buffer (semantic-tag-buffer attr)))
+               (speedbar-message
+                (funcall semantic-sb-info-format-tag-function attr)
+                )))
+           (looking-at "\\([0-9]+\\):")
+           (setq item (file-name-nondirectory (speedbar-line-directory)))
+           (speedbar-message "Tag: %s  in %s" tag item)))
+      (if (re-search-forward "{[+-]} \\([^\n]+\\)$"
+                            (save-excursion(end-of-line)(point)) t)
+         (speedbar-message "Group of tags \"%s\"" (match-string 1))
+       (if (re-search-forward " [+-]?[()|@] \\([^\n]+\\)$" nil t)
+           (let* ((detailtext (match-string 1))
+                  (detail (or (speedbar-line-token) detailtext))
+                  (parent (save-excursion
+                            (beginning-of-line)
+                            (let ((dep (if (looking-at "[0-9]+:")
+                                           (1- (string-to-number (match-string 0)))
+                                         0)))
+                              (re-search-backward (concat "^"
+                              (int-to-string dep)
+                              ":")
+                                                  nil t))
+                            (if (looking-at "[0-9]+: +[-+=>]> \\([^\n]+\\)$")
+                                (speedbar-line-token)
+                              nil))))
+             (if (featurep 'semantic)
+                 (with-no-warnings
+                   (if (semantic-tag-p detail)
+                       (speedbar-message
+                        (funcall semantic-sb-info-format-tag-function detail parent))
+                     (if parent
+                         (speedbar-message "Detail: %s of tag %s" detail
+                                           (if (semantic-tag-p parent)
+                                               (semantic-format-tag-name parent nil t)
+                                             parent))
+                       (speedbar-message "Detail: %s" detail))))
+               ;; Not using `semantic':
+               (if parent
+                   (speedbar-message "Detail: %s of tag %s" detail parent)
+                 (speedbar-message "Detail: %s" detail))))
+         nil)))))
+
+(defun speedbar-files-item-info ()
+  "Display info in the mini-buffer about the button the mouse is over."
   (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.")))
-       ))))
+      (speedbar-generic-item-info)
+    (or (speedbar-item-info-file-helper)
+       (speedbar-item-info-tag-helper)
+       (speedbar-generic-item-info))))
 
 (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 (not f)        (error "Not a file"))
     (if (file-directory-p f)
-       (error "Cannot copy directory.")
+       (error "Cannot copy directory")
       (let* ((rt (read-file-name (format "Copy %s to: "
                                         (file-name-nondirectory f))
                                 (file-name-directory f)))
@@ -1345,10 +1516,11 @@ Files can be copied to new names or places."
        (if (file-directory-p rt)
            (setq rt
                  (concat (expand-file-name rt)
-                         (if (string-match "/$" 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)))
+               (speedbar-y-or-n-p (format "Overwrite %s with %s? " rt f)
+                                  t))
            (progn
              (copy-file f rt t t)
              ;; refresh display if the new place is currently displayed.
@@ -1374,10 +1546,11 @@ Files can be renamed to new names or moved to new directories."
          (if (file-directory-p rt)
              (setq rt
                    (concat (expand-file-name rt)
-                           (if (string-match "/\\'" 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)))
+                 (speedbar-y-or-n-p (format "Overwrite %s with %s? " rt f)
+                                    t))
              (progn
                (rename-file f rt t)
                ;; refresh display if the new place is currently displayed.
@@ -1386,31 +1559,64 @@ Files can be renamed to new names or moved to new directories."
                      (speedbar-refresh)
                      (speedbar-goto-this-file rt)
                      )))))
-      (error "Not a file."))))
+      (error "Not a file"))))
+
+(defun speedbar-create-directory ()
+  "Create a directory in speedbar."
+  (interactive)
+  (let ((f (speedbar-line-file)))
+    (if f
+       (let* ((basedir (file-name-directory f))
+              (nd (read-file-name "Create directory: "
+                                  basedir)))
+         ;; Make the directory
+         (make-directory nd t)
+         (speedbar-refresh)
+         (speedbar-goto-this-file nd)
+         )
+      (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))
+    (if (not f) (error "Not a file"))
+    (if (speedbar-y-or-n-p (format "Delete %s? " f) t)
        (progn
          (if (file-directory-p f)
              (delete-directory f)
            (delete-file f))
-         (message "Okie dokie..")
+         (speedbar-message "Okie dokie..")
          (let ((p (point)))
            (speedbar-refresh)
            (goto-char p))
          ))
     ))
 
+(defun speedbar-item-object-delete ()
+  "Delete the object associated from the item under the cursor.
+The file is removed from disk.  The object is determined from the
+variable `speedbar-obj-alist'."
+  (interactive)
+  (let* ((f (speedbar-line-file))
+        (obj nil)
+        (oa speedbar-obj-alist))
+    (if (not f) (error "Not a file"))
+    (while (and oa (not (string-match (car (car oa)) f)))
+      (setq oa (cdr oa)))
+    (setq obj (concat (file-name-sans-extension f) (cdr (car oa))))
+    (if (and oa (file-exists-p obj)
+            (speedbar-y-or-n-p (format "Delete %s? " obj) t))
+       (progn
+         (delete-file obj)
+         (speedbar-reset-scanners)))))
+
 (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))
+  (speedbar-set-timer dframe-update-speed))
 
 (defun speedbar-disable-update ()
   "Disable automatic updating and stop consuming resources."
@@ -1426,8 +1632,15 @@ Files can be renamed to new names or moved to new directories."
       (speedbar-disable-update)
     (speedbar-enable-update)))
 
+(defun speedbar-toggle-images ()
+  "Toggle use of images in the speedbar frame.
+Images are not available in Emacs 20 or earlier."
+  (interactive)
+  (setq speedbar-use-images (not speedbar-use-images))
+  (speedbar-refresh))
+
 (defun speedbar-toggle-sorting ()
-  "Toggle automatic update for the speedbar frame."
+  "Toggle tag sorting."
   (interactive)
   (setq speedbar-sort-tags (not speedbar-sort-tags)))
 
@@ -1436,95 +1649,13 @@ Files can be renamed to new names or moved to new directories."
   (interactive)
   (setq speedbar-show-unknown-files (not speedbar-show-unknown-files))
   (speedbar-refresh))
-\f
-;;; 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
-       (if (and speedbar-xemacsp
-                (or (>= emacs-major-version 20)
-                    (>= emacs-minor-version 15)))
-           (setq speedbar-timer (start-itimer "speedbar"
-                                              'speedbar-timer-fn
-                                              timeout
-                                              timeout
-                                              t))
-         (setq speedbar-timer (start-itimer "speedbar"
-                                            'speedbar-timer-fn
-                                            timeout
-                                            nil)))))
-   ;; 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 t '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 its
-   ;; 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."
   (list 'let '((inhibit-read-only t))
-       '(toggle-read-only -1)
        (cons 'progn 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.
@@ -1533,30 +1664,175 @@ 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
+This is a convenience function for special modes 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)))
+    (if (/= (current-column) 0) (insert "\n"))
+    (put-text-property start (point) 'invisible nil))
+  (if prevline (progn (delete-char -1)
+                     (insert " ") ;back up if desired...
+                     (put-text-property (1- (point)) (point) 'invisible nil)))
   (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)))
+    (add-text-properties
+     start (point) '(face nil invisible nil mouse-face nil))))
+
+(defun speedbar-insert-separator (text)
+  "Insert a separation label of TEXT.
+Separators are not active, have no labels, depth, or actions."
+  (if speedbar-use-images
+      (let ((start (point)))
+       (insert "//")
+       (speedbar-insert-image-button-maybe start 2)))
+  (let ((start (point)))
+    (insert text "\n")
+    (speedbar-make-button start (point)
+                         'speedbar-separator-face
+                         nil nil 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)
+will be run with the TOKEN parameter (any Lisp object)"
+  (add-text-properties
+   start end `(face ,face mouse-face ,mouse invisible nil
+               speedbar-text ,(buffer-substring-no-properties start end)))
+  (if speedbar-use-tool-tips-flag
+      (put-text-property start end 'help-echo #'dframe-help-echo))
   (if function (put-text-property start end 'speedbar-function function))
   (if token (put-text-property start end 'speedbar-token token))
+  ;; So far the only text we have is less that 3 chars.
+  (if (<= (- end start) 3)
+      (speedbar-insert-image-button-maybe start (- end start)))
   )
 \f
+;;; Initial Expansion list management
+;;
+(defun speedbar-initial-expansion-list ()
+  "Return the current default expansion list.
+This is based on `speedbar-initial-expansion-list-name' referencing
+`speedbar-initial-expansion-mode-alist'."
+  ;; cdr1 - name, cdr2 - menu
+  (cdr (cdr (cdr (assoc speedbar-initial-expansion-list-name
+                       speedbar-initial-expansion-mode-alist)))))
+
+(defun speedbar-initial-menu ()
+  "Return the current default menu data.
+This is based on `speedbar-initial-expansion-list-name' referencing
+`speedbar-initial-expansion-mode-alist'."
+  (symbol-value
+   (car (cdr (assoc speedbar-initial-expansion-list-name
+                   speedbar-initial-expansion-mode-alist)))))
+
+(defun speedbar-initial-keymap ()
+  "Return the current default menu data.
+This is based on `speedbar-initial-expansion-list-name' referencing
+`speedbar-initial-expansion-mode-alist'."
+  (symbol-value
+   (car (cdr (cdr (assoc speedbar-initial-expansion-list-name
+                        speedbar-initial-expansion-mode-alist))))))
+
+(defun speedbar-initial-stealthy-functions ()
+  "Return a list of functions to call stealthily.
+This is based on `speedbar-initial-expansion-list-name' referencing
+`speedbar-stealthy-function-list'."
+  (cdr (assoc speedbar-initial-expansion-list-name
+             speedbar-stealthy-function-list)))
+
+(defun speedbar-add-expansion-list (new-list)
+  "Add NEW-LIST to the list of expansion lists."
+  (add-to-list 'speedbar-initial-expansion-mode-alist new-list))
+
+(defun speedbar-change-initial-expansion-list (new-default)
+  "Change speedbar's default expansion list to NEW-DEFAULT."
+  (interactive
+   (list
+    (completing-read (format "Speedbar Mode (default %s): "
+                            speedbar-previously-used-expansion-list-name)
+                    speedbar-initial-expansion-mode-alist
+                    nil t "" nil
+                    speedbar-previously-used-expansion-list-name)))
+  (setq speedbar-previously-used-expansion-list-name
+       speedbar-initial-expansion-list-name
+       speedbar-initial-expansion-list-name new-default)
+  (if (and (speedbar-current-frame) (frame-live-p (speedbar-current-frame)))
+      (progn
+       (speedbar-refresh)
+       (speedbar-reconfigure-keymaps))))
+
+(defun speedbar-fetch-replacement-function (function)
+  "Return a current mode specific replacement for function, or nil.
+Scans `speedbar-mode-functions-list' first for the current mode, then
+for FUNCTION."
+  (cdr (assoc function
+             (cdr (assoc speedbar-initial-expansion-list-name
+                         speedbar-mode-functions-list)))))
+
+(defun speedbar-add-mode-functions-list (new-list)
+  "Add NEW-LIST to the list of mode functions.
+See `speedbar-mode-functions-list' for details."
+  (add-to-list 'speedbar-mode-functions-list new-list))
+
+\f
+;;; Special speedbar display management
+;;
+(defun speedbar-maybe-add-localized-support (buffer)
+  "Quick check function called on BUFFERs by the speedbar timer function.
+Maintains the value of local variables which control speedbars use
+of the special mode functions."
+  (or speedbar-special-mode-expansion-list
+      (speedbar-add-localized-speedbar-support buffer)))
+
+(defun speedbar-add-localized-speedbar-support (buffer)
+  "Add localized speedbar support to BUFFER's mode if it is available."
+  (interactive "bBuffer: ")
+  (if (stringp buffer) (setq buffer (get-buffer buffer)))
+  (if (not (buffer-live-p buffer))
+      nil
+    (save-excursion
+      (set-buffer buffer)
+      (save-match-data
+       (let ((ms (symbol-name major-mode)) v)
+         (if (not (string-match "-mode$" ms))
+             nil ;; do nothing to broken mode
+           (setq ms (substring ms 0 (match-beginning 0)))
+           (setq v (intern-soft (concat ms "-speedbar-buttons")))
+           (make-local-variable 'speedbar-special-mode-expansion-list)
+           (if (not v)
+               (setq speedbar-special-mode-expansion-list t)
+             ;; If it is autoloaded, we need to load it now so that
+             ;; we have access to the varialbe -speedbar-menu-items.
+             ;; Is this XEmacs safe?
+             (let ((sf (symbol-function v)))
+               (if (and (listp sf) (eq (car sf) 'autoload))
+                   (load-library (car (cdr sf)))))
+             (setq speedbar-special-mode-expansion-list (list v))
+             (setq v (intern-soft (concat ms "-speedbar-key-map")))
+             (if (not v)
+                 nil ;; don't add special keymap
+               (make-local-variable 'speedbar-special-mode-key-map)
+               (setq speedbar-special-mode-key-map
+                     (symbol-value v)))
+             (setq v (intern-soft (concat ms "-speedbar-menu-items")))
+             (if (not v)
+                 nil ;; don't add special menus
+               (make-local-variable 'speedbar-easymenu-definition-special)
+               (setq speedbar-easymenu-definition-special
+                     (symbol-value v)))
+             )))))))
+
+(defun speedbar-remove-localized-speedbar-support (buffer)
+  "Remove any traces that BUFFER supports speedbar in a specialized way."
+  (save-excursion
+    (set-buffer buffer)
+    (kill-local-variable 'speedbar-special-mode-expansion-list)
+    (kill-local-variable 'speedbar-special-mode-key-map)
+    (kill-local-variable 'speedbar-easymenu-definition-special)))
+\f
 ;;; File button management
 ;;
 (defun speedbar-file-lists (directory)
@@ -1564,11 +1840,11 @@ will be run with the TOKEN parameter (any lisp object)"
 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"
+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
+  (if dframe-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))
@@ -1577,7 +1853,9 @@ the file-system"
            (dirs nil)
            (files nil))
        (while dir
-         (if (not (string-match speedbar-file-unshown-regexp (car dir)))
+         (if (not
+              (or (string-match speedbar-file-unshown-regexp (car dir))
+                  (string-match speedbar-directory-unshown-regexp (car dir))))
              (if (file-directory-p (car dir))
                  (setq dirs (cons (car dir) dirs))
                (setq files (cons (car dir) files))))
@@ -1589,26 +1867,27 @@ the file-system"
 
 (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
+Each directory directory part is a different button.  If part of the directory
 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 "~"))
+  (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)))
+                       (concat "~/" (substring dd (match-end 0)))
                      dd))
         (p (point)))
-    (if (string-match "^~/?\\'" displayme) (setq displayme (concat tilde "/")))
+    (if (string-match "^~[/\\]?\\'" displayme) (setq displayme tilde))
     (insert displayme)
     (save-excursion
       (goto-char p)
-      (while (re-search-forward "\\([^/]+\\)/" nil t)
+      (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)
+                             (if (and (= (match-beginning 1) p)
+                                      (not (char-equal (char-after (+ p 1)) ?:)))
                                  (expand-file-name "~/")  ;the tilde
                                (buffer-substring-no-properties
                                 p (match-end 0)))))
@@ -1618,14 +1897,14 @@ INDEX is not used, but is required by the caller."
             (let ((ww (or (speedbar-frame-width) 20)))
               (move-to-column ww nil)
               (while (>= (current-column) ww)
-                (re-search-backward "/" nil t)
+                (re-search-backward "[/\\]" nil t)
                 (if (<= (current-column) 2)
                     (progn
-                      (re-search-forward "/" nil t)
+                      (re-search-forward "[/\\]" nil t)
                       (if (< (current-column) 4)
-                          (re-search-forward "/" nil t))
+                          (re-search-forward "[/\\]" nil t))
                       (forward-char -1)))
-                (if (looking-at "/?$")
+                (if (looking-at "[/\\]?$")
                     (beginning-of-line)
                   (insert "/...\n ")
                   (move-to-column ww nil)))))
@@ -1636,13 +1915,13 @@ INDEX is not used, but is required by the caller."
               (if (< ww tl)
                   (progn
                     (move-to-column (- tl ww))
-                    (if (re-search-backward "/" nil t)
+                    (if (re-search-backward "[/\\]" nil t)
                         (progn
                           (delete-region (point-min) (point))
                           (insert "$")
                           )))))))
       )
-    (if (string-match "\\`/[^/]+/\\'" displayme)
+    (if (string-match "\\`[/\\][^/\\]+[/\\]\\'" displayme)
        (progn
          (insert "  ")
          (let ((p (point)))
@@ -1664,8 +1943,9 @@ INDEX is not used, but is required by the caller."
 This is the button that expands or contracts a node (if applicable),
 and EXP-BUTTON-CHAR the character in it (+, -, ?, etc).  EXP-BUTTON-FUNCTION
 is the function to call if it's clicked on.  Button types are
-'bracket, 'angle, 'curly, or nil.  EXP-BUTTON-DATA is extra data
-attached to the text forming the expansion button.
+'bracket, 'angle, 'curly, 'expandtag, 'statictag, t, or nil.
+EXP-BUTTON-DATA is extra data attached to the text forming the expansion
+button.
 
 Next, TAG-BUTTON is the text of the tag.  TAG-BUTTON-FUNCTION is the
 function to call if clicked on, and TAG-BUTTON-DATA is the data to
@@ -1675,38 +1955,45 @@ TAG-BUTTON-FACE is a face used for this type of tag.
 Lastly, DEPTH shows the depth of expansion.
 
 This function assumes that the cursor is in the speedbar window at the
-position to insert a new item, and that the new item will end with a CR"
+position to insert a new item, and that the new item will end with a CR."
   (let ((start (point))
        (end (progn
               (insert (int-to-string depth) ":")
-              (point))))
+              (point)))
+       (depthspacesize (* depth speedbar-indentation-width)))
     (put-text-property start end 'invisible t)
-    )
-  (insert-char ?  depth nil)
-  (put-text-property (- (point) depth) (point) 'invisible nil)
-  (let* ((exp-button (cond ((eq exp-button-type 'bracket) "[%c]")
-                          ((eq exp-button-type 'angle) "<%c>")
-                          ((eq exp-button-type 'curly) "{%c}")
-                          (t ">")))
-        (buttxt (format exp-button exp-button-char))
-        (start (point))
-        (end (progn (insert buttxt) (point)))
-        (bf (if exp-button-type 'speedbar-button-face nil))
-        (mf (if exp-button-function 'speedbar-highlight-face nil))
-        )
-    (speedbar-make-button start end bf mf exp-button-function exp-button-data)
-    )
-  (insert-char ?  1 nil)
-  (put-text-property (1- (point)) (point) 'invisible nil)
-  (let ((start (point))
-       (end (progn (insert tag-button) (point))))
-    (insert-char ?\n 1 nil)
+    (insert-char ?  depthspacesize nil)
+    (put-text-property (- (point) depthspacesize) (point) 'invisible nil)
+    (let* ((exp-button (cond ((eq exp-button-type 'bracket) "[%c]")
+                            ((eq exp-button-type 'angle) "<%c>")
+                            ((eq exp-button-type 'curly) "{%c}")
+                            ((eq exp-button-type 'expandtag) " %c>")
+                            ((eq exp-button-type 'statictag) " =>")
+                            (t ">")))
+          (buttxt (format exp-button exp-button-char))
+          (start (point))
+          (end (progn (insert buttxt) (point)))
+          (bf (if (and exp-button-type (not (eq exp-button-type 'statictag)))
+                  'speedbar-button-face nil))
+          (mf (if exp-button-function 'speedbar-highlight-face nil))
+          )
+      (speedbar-make-button start end bf mf exp-button-function exp-button-data)
+      (if speedbar-hide-button-brackets-flag
+         (progn
+           (put-text-property start (1+ start) 'invisible t)
+           (put-text-property end (1- end) 'invisible t)))
+      )
+    (insert-char ?  1 nil)
     (put-text-property (1- (point)) (point) 'invisible nil)
-    (speedbar-make-button start end tag-button-face
-                         (if tag-button-function 'speedbar-highlight-face nil)
-                         tag-button-function tag-button-data))
-)
-
+    (let ((start (point))
+         (end (progn (insert tag-button) (point))))
+      (insert-char ?\n 1 nil)
+      (put-text-property (1- (point)) (point) 'invisible nil)
+      (speedbar-make-button start end tag-button-face
+                           (if tag-button-function 'speedbar-highlight-face nil)
+                           tag-button-function tag-button-data))
+    ))
+  
 (defun speedbar-change-expand-button-char (char)
   "Change the expansion button character to CHAR for the current line."
   (save-excursion
@@ -1714,9 +2001,13 @@ position to insert a new item, and that the new item will end with a CR"
     (if (re-search-forward ":\\s-*.\\([-+?]\\)" (save-excursion (end-of-line)
                                                                (point)) t)
        (speedbar-with-writable
-         (goto-char (match-beginning 1))
-         (delete-char 1)
-         (insert-char char 1 t)))))
+         (goto-char (match-end 1))
+         (insert-char char 1 t)
+         (forward-char -1)
+         (delete-char -1)
+         ;;(put-text-property (point) (1- (point)) 'invisible nil)
+         ;; make sure we fix the image on the text here.
+         (speedbar-insert-image-button-maybe (- (point) 1) 3)))))
 
 \f
 ;;; Build button lists
@@ -1725,7 +2016,7 @@ position to insert a new item, and that the new item will end with a CR"
   "Insert list of FILES starting at point, and indenting all files to LEVEL.
 Tag expandable items with a +, otherwise a ?.  Don't highlight ? as we
 don't know how to manage them.  The input parameter FILES is a cons
-cell of the form ( 'DIRLIST . 'FILELIST )"
+cell of the form ( 'DIRLIST .  'FILELIST )."
   ;; Start inserting all the directories
   (let ((dirs (car files)))
     (while dirs
@@ -1733,7 +2024,8 @@ cell of the form ( 'DIRLIST . 'FILELIST )"
                              (car dirs) 'speedbar-dir-follow nil
                              'speedbar-directory-face level)
       (setq dirs (cdr dirs))))
-  (let ((lst (car (cdr files))))
+  (let ((lst (car (cdr files)))
+       (case-fold-search t))
     (while lst
       (let* ((known (string-match speedbar-file-regexp (car lst)))
             (expchar (if known ?+ ??))
@@ -1746,7 +2038,7 @@ cell of the form ( 'DIRLIST . 'FILELIST )"
 
 (defun speedbar-default-directory-list (directory index)
   "Insert files for DIRECTORY with level INDEX at point."
-  (speedbar-insert-files-at-point
+  (speedbar-insert-files-at-point 
    (speedbar-file-lists directory) index)
   (speedbar-reset-scanners)
   (if (= index 0)
@@ -1765,9 +2057,285 @@ cell of the form ( 'DIRLIST . 'FILELIST )"
                (if (looking-at "[0-9]+:[ ]*<")
                    (progn
                      (goto-char (match-end 0))
-                 (speedbar-do-function-pointer)))
-               (setq sf (cdr sf)))))
+                     (speedbar-do-function-pointer)))))
+         (setq sf (cdr sf)))
        )))
+;;; Generic List support
+;;
+;;  Generic lists are hierarchies of tags which we may need to permute
+;;  in order to make it look nice.
+;;
+;;  A generic list is of the form:
+;;  ( ("name" . marker-or-number)              <-- one tag at this level
+;;    ("name" ("name" . mon) ("name" . mon) )  <-- one group of tags
+;;    ("name" mon ("name" . mon) )             <-- group w/ a position and tags
+(defun speedbar-generic-list-group-p (sublst)
+  "Non-nil if SUBLST is a group.
+Groups may optionally contain a position."
+  (and (stringp (car-safe sublst))
+       (or (and (listp (cdr-safe sublst))
+               (or (speedbar-generic-list-tag-p (car-safe (cdr-safe sublst)))
+                   (speedbar-generic-list-group-p (car-safe (cdr-safe sublst))
+                                                  )))
+          (and (number-or-marker-p (car-safe (cdr-safe sublst)))
+               (listp (cdr-safe (cdr-safe sublst)))
+               (speedbar-generic-list-tag-p
+                (car-safe (cdr-safe (cdr-safe sublst)))))
+          )))
+
+(defun speedbar-generic-list-positioned-group-p (sublst)
+  "Non-nil of SUBLST is a group with a position."
+  (and (stringp (car-safe sublst))
+       (number-or-marker-p (car-safe (cdr-safe sublst)))
+       (listp (cdr-safe (cdr-safe sublst)))
+       (let ((rest (car-safe (cdr-safe (cdr-safe sublst)))))
+        (or (speedbar-generic-list-tag-p rest)
+            (speedbar-generic-list-group-p rest)
+            (speedbar-generic-list-positioned-group-p rest)
+            ))))
+
+(defun speedbar-generic-list-tag-p (sublst)
+  "Non nil if SUBLST is a tag."
+  (and (stringp (car-safe sublst))
+       (or (and (number-or-marker-p (cdr-safe sublst))
+               (not (cdr-safe (cdr-safe sublst))))
+          ;; For semantic/bovine items, this is needed
+          (symbolp (car-safe (cdr-safe sublst))))
+       ))
+
+(defun speedbar-sort-tag-hierarchy (lst)
+  "Sort all elements of tag hierarchy LST."
+  (sort (copy-alist lst)
+       (lambda (a b) (string< (car a) (car b)))))
+
+(defun speedbar-try-completion (string alist)
+  "A wrapper for `try-completion'.
+Passes STRING and ALIST to `try-completion' if ALIST
+passes some tests."
+  (if (and (listp alist) (not (null alist))
+          (listp (car alist)) (stringp (car (car alist))))
+      (try-completion string alist)
+    nil))
+
+(defun speedbar-prefix-group-tag-hierarchy (lst)
+  "Prefix group names for tag hierarchy LST."
+  (let ((newlst nil)
+       (sublst nil)
+       (work-list nil)
+       (junk-list nil)
+       (short-group-list nil)
+       (short-start-name nil)
+       (short-end-name nil)
+       (num-shorts-grouped 0)
+       (bins (make-vector 256 nil))
+       (diff-idx 0))
+    (if (<= (length lst) speedbar-tag-regroup-maximum-length)
+       ;; Do nothing.  Too short to bother with.
+       lst
+      ;; Break out sub-lists
+      (while lst
+       (if (speedbar-generic-list-group-p (car-safe lst))
+           (setq newlst (cons (car lst) newlst))
+         (setq sublst (cons (car lst) sublst)))
+       (setq lst (cdr lst)))
+      ;; Reverse newlst because it was made backwards.
+      ;; Sublist doesn't need reversing because the act
+      ;; of binning things will reverse it for us.
+      (setq newlst (nreverse newlst)
+           sublst sublst)
+      ;; Now, first find out how long our list is.  Never let a
+      ;; list get-shorter than our minimum.
+      (if (<= (length sublst) speedbar-tag-split-minimum-length)
+         (setq work-list sublst)
+       (setq diff-idx (length (speedbar-try-completion "" sublst)))
+       ;; Sort the whole list into bins.
+       (while sublst
+         (let ((e (car sublst))
+               (s (car (car sublst))))
+           (cond ((<= (length s) diff-idx)
+                  ;; 0 storage bin for shorty.
+                  (aset bins 0 (cons e (aref bins 0))))
+                 (t
+                  ;; stuff into a bin based on ascii value at diff
+                  (aset bins (aref s diff-idx)
+                        (cons e (aref bins (aref s diff-idx)))))))
+         (setq sublst (cdr sublst)))
+       ;; Go through all our bins  Stick singles into our
+       ;; junk-list, everything else as sublsts in work-list.
+       ;; If two neighboring lists are both small, make a grouped
+       ;; group combinding those two sub-lists.
+       (setq diff-idx 0)
+       (while (> 256 diff-idx)
+         ;; The bins contents are currently in forward order.
+         (let ((l (aref bins diff-idx)))
+           (if l
+               (let ((tmp (cons (speedbar-try-completion "" l) l)))
+                 (if (or (> (length l) speedbar-tag-regroup-maximum-length)
+                         (> (+ (length l) (length short-group-list))
+                            speedbar-tag-split-minimum-length))
+                     (progn
+                       ;; We have reached a longer list, so we
+                       ;; must finish off a grouped group.
+                       (cond
+                        ((and short-group-list
+                              (= (length short-group-list)
+                                 num-shorts-grouped))
+                         ;; All singles?  Junk list
+                         (setq junk-list (append (nreverse short-group-list)
+                                                 junk-list)))
+                        ((= num-shorts-grouped 1)
+                         ;; Only one short group?  Just stick it in
+                         ;; there by itself.  Make a group, and find
+                         ;; a subexpression
+                         (let ((subexpression (speedbar-try-completion
+                                               "" short-group-list)))
+                           (if (< (length subexpression)
+                                  speedbar-tag-group-name-minimum-length)
+                               (setq subexpression
+                                     (concat short-start-name
+                                             " ("
+                                             (substring
+                                              (car (car short-group-list))
+                                              (length short-start-name))
+                                             ")")))
+                           (setq work-list
+                                 (cons (cons subexpression
+                                             short-group-list)
+                                       work-list ))))
+                        (short-group-list
+                         ;; Multiple groups to be named in a special
+                         ;; way by displaying the range over which we
+                         ;; have grouped them.
+                         (setq work-list
+                               (cons (cons (concat short-start-name
+                                                   " to "
+                                                   short-end-name)
+                                           short-group-list)
+                                     work-list))))
+                    ;; Reset short group list information every time.
+                       (setq short-group-list nil
+                             short-start-name nil
+                             short-end-name nil
+                             num-shorts-grouped 0)))
+                 ;; Ok, now that we cleaned up the short-group-list,
+                 ;; we can deal with this new list, to decide if it
+                 ;; should go on one of these sub-lists or not.
+                 (if (< (length l) speedbar-tag-regroup-maximum-length)
+                     (setq short-group-list (append l short-group-list)
+                           num-shorts-grouped (1+ num-shorts-grouped)
+                           short-end-name (car tmp)
+                           short-start-name (if short-start-name
+                                                short-start-name
+                                              (car tmp)))
+                   (setq work-list (cons tmp work-list))))))
+         (setq diff-idx (1+ diff-idx))))
+      ;; Did we run out of things?  Drop our new list onto the end.
+      (cond
+       ((and short-group-list (= (length short-group-list) num-shorts-grouped))
+       ;; All singles?  Junk list
+       (setq junk-list (append short-group-list junk-list)))
+       ((= num-shorts-grouped 1)
+       ;; Only one short group?  Just stick it in
+       ;; there by itself.
+       (setq work-list
+             (cons (cons (speedbar-try-completion "" short-group-list)
+                         short-group-list)
+                   work-list)))
+       (short-group-list
+       ;; Multiple groups to be named in a special
+       ;; way by displaying the range over which we
+       ;; have grouped them.
+       (setq work-list
+             (cons (cons (concat short-start-name " to " short-end-name)
+                         short-group-list)
+                   work-list))))
+      ;; Reverse the work list nreversed when consing.
+      (setq work-list (nreverse work-list))
+      ;; Now, stick our new list onto the end of
+      (if work-list
+         (if junk-list
+             (append newlst work-list junk-list)
+           (append newlst work-list))
+       (append  newlst junk-list)))))
+
+(defun speedbar-trim-words-tag-hierarchy (lst)
+  "Trim all words in a tag hierarchy.
+Base trimming information on word separators, and group names.
+Argument LST is the list of tags to trim."
+  (let ((newlst nil)
+       (sublst nil)
+       (trim-prefix nil)
+       (trim-chars 0)
+       (trimlst nil))
+    (while lst
+      (if (speedbar-generic-list-group-p (car-safe lst))
+         (setq newlst (cons (car lst) newlst))
+       (setq sublst (cons (car lst) sublst)))
+      (setq lst (cdr lst)))
+    ;; Get the prefix to trim by.  Make sure that we don't trim
+    ;; off silly pieces, only complete understandable words.
+    (setq trim-prefix (speedbar-try-completion "" sublst)
+         newlst (nreverse newlst))
+    (if (or (= (length sublst) 1)
+           (not trim-prefix)
+           (not (string-match "\\(\\w+\\W+\\)+" trim-prefix)))
+       (append newlst (nreverse sublst))
+      (setq trim-prefix (substring trim-prefix (match-beginning 0)
+                                  (match-end 0)))
+      (setq trim-chars (length trim-prefix))
+      (while sublst
+       (setq trimlst (cons
+                      (cons (substring (car (car sublst)) trim-chars)
+                            (cdr (car sublst)))
+                      trimlst)
+             sublst (cdr sublst)))
+      ;; Put the lists together
+      (append newlst trimlst))))
+
+(defun speedbar-simple-group-tag-hierarchy (lst)
+  "Create a simple 'Tags' group with orphaned tags.
+Argument LST is the list of tags to sort into groups."
+  (let ((newlst nil)
+       (sublst nil))
+    (while lst
+      (if (speedbar-generic-list-group-p (car-safe lst))
+         (setq newlst (cons (car lst) newlst))
+       (setq sublst (cons (car lst) sublst)))
+      (setq lst (cdr lst)))
+    (if (not newlst)
+       (nreverse sublst)
+      (setq newlst (cons (cons "Tags" (nreverse sublst)) newlst))
+      (nreverse newlst))))
+
+(defun speedbar-create-tag-hierarchy (lst)
+  "Adjust the tag hierarchy in LST, and return it.
+This uses `speedbar-tag-hierarchy-method' to determine how to adjust
+the list."
+  (let* ((f (save-excursion
+             (forward-line -1)
+             (or (speedbar-line-file)
+                 (speedbar-line-directory))))
+        (methods (if (get-file-buffer f)
+                     (save-excursion (set-buffer (get-file-buffer f))
+                                     speedbar-tag-hierarchy-method)
+                   speedbar-tag-hierarchy-method))
+        (lst (if (fboundp 'copy-tree)
+                 (copy-tree lst)
+               lst)))
+    (while methods
+      (setq lst (funcall (car methods) lst)
+           methods (cdr methods)))
+    lst))
+
+(defvar speedbar-generic-list-group-expand-button-type 'curly
+  "The type of button created for groups of tags.
+Good values for this are `curly' and `expandtag'.
+Make buffer local for your mode.")
+
+(defvar speedbar-generic-list-tag-button-type nil
+  "The type of button created for tags in generic lists.
+Good values for this are nil and `statictag'.
+Make buffer local for your mode.")
 
 (defun speedbar-insert-generic-list (level lst expand-fun find-fun)
   "At LEVEL, insert a generic multi-level alist LST.
@@ -1778,24 +2346,58 @@ name will have the function FIND-FUN and not token."
   ;; Remove imenu rescan button
   (if (string= (car (car lst)) "*Rescan*")
       (setq lst (cdr lst)))
-  ;; insert the parts
-  (while lst
-    (cond ((null (car-safe lst)) nil)  ;this would be a separator
-         ((or (numberp (cdr-safe (car-safe lst)))
-              (markerp (cdr-safe (car-safe lst))))
-          (speedbar-make-tag-line nil nil nil nil ;no expand button data
-                                  (car (car lst)) ;button name
-                                  find-fun        ;function
-                                  (cdr (car lst)) ;token is position
-                                  'speedbar-tag-face
-                                  (1+ level)))
-         ((listp (cdr-safe (car-safe lst)))
-          (speedbar-make-tag-line 'curly ?+ expand-fun (cdr (car lst))
-                                  (car (car lst)) ;button name
-                                  nil nil 'speedbar-tag-face
-                                  (1+ level)))
-         (t (message "Ooops!")))
-    (setq lst (cdr lst))))
+  ;; Get, and set up variables that define how we treat these tags.
+   (let ((f (save-excursion (forward-line -1)
+                           (or (speedbar-line-file)
+                               (speedbar-line-directory))))
+        expand-button tag-button)
+     (save-excursion
+       (if (get-file-buffer f)
+          (set-buffer (get-file-buffer f)))
+       (setq expand-button speedbar-generic-list-group-expand-button-type
+            tag-button speedbar-generic-list-tag-button-type))
+     ;; Adjust the list.
+     (setq lst (speedbar-create-tag-hierarchy lst))
+     ;; insert the parts
+     (while lst
+       (cond ((null (car-safe lst)) nil)       ;this would be a separator
+           ((speedbar-generic-list-tag-p (car lst))
+            (speedbar-make-tag-line tag-button
+                                    nil nil nil ;no expand button data
+                                    (car (car lst)) ;button name
+                                    find-fun ;function
+                                    (cdr (car lst)) ;token is position
+                                    'speedbar-tag-face
+                                    (1+ level)))
+           ((speedbar-generic-list-positioned-group-p (car lst))
+            (speedbar-make-tag-line expand-button
+                                    ?+ expand-fun (cdr (cdr (car lst)))
+                                    (car (car lst)) ;button name
+                                    find-fun ;function
+                                    (car (cdr (car lst))) ;token is posn
+                                    'speedbar-tag-face
+                                    (1+ level)))
+           ((speedbar-generic-list-group-p (car lst))
+            (speedbar-make-tag-line expand-button
+                                    ?+ expand-fun (cdr (car lst))
+                                    (car (car lst)) ;button name
+                                    nil nil 'speedbar-tag-face
+                                    (1+ level)))
+           (t (speedbar-message "speedbar-insert-generic-list: malformed list!")
+              ))
+      (setq lst (cdr lst)))))
+
+(defun speedbar-insert-imenu-list (indent lst)
+  "At level INDENT, insert the imenu generated LST."
+  (speedbar-insert-generic-list indent lst
+                               'speedbar-tag-expand
+                               'speedbar-tag-find))
+                               
+(defun speedbar-insert-etags-list (indent lst)
+  "At level INDENT, insert the etags generated LST."
+  (speedbar-insert-generic-list indent lst
+                               'speedbar-tag-expand
+                               'speedbar-tag-find))
 \f
 ;;; Timed functions
 ;;
@@ -1804,7 +2406,13 @@ name will have the function FIND-FUN and not token."
   (interactive)
   ;; Set the current special buffer
   (setq speedbar-desired-buffer nil)
+
+  ;; Check for special modes
+  (speedbar-maybe-add-localized-support (current-buffer))
+
+  ;; Choose the correct method of doodling.
   (if (and speedbar-mode-specific-contents-flag
+          (listp speedbar-special-mode-expansion-list)
           speedbar-special-mode-expansion-list
           (local-variable-p
            'speedbar-special-mode-expansion-list
@@ -1813,39 +2421,86 @@ name will have the function FIND-FUN and not token."
       (speedbar-update-special-contents)
     (speedbar-update-directory-contents)))
 
+(defun speedbar-update-localized-contents ()
+  "Update the contents of the speedbar buffer for the current situation."
+  ;; Due to the historical growth of speedbar, we need to do something
+  ;; special for "files" mode.  Too bad.
+  (let ((name speedbar-initial-expansion-list-name)
+       (funclst (speedbar-initial-expansion-list))
+       )
+    (if (string= name "files")
+       ;; Do all the files type work.  It still goes through the
+       ;; expansion list stuff. :(
+       (if (or (member (expand-file-name default-directory)
+                       speedbar-shown-directories)
+               (and speedbar-ignored-directory-regexp
+                    (string-match
+                     speedbar-ignored-directory-regexp
+                     (expand-file-name default-directory))))
+           nil
+         (if (<= 1 speedbar-verbosity-level)
+             (speedbar-message "Updating speedbar to: %s..."
+                               default-directory))
+         (speedbar-update-directory-contents)
+         (if (<= 1 speedbar-verbosity-level)
+             (progn
+               (speedbar-message "Updating speedbar to: %s...done"
+                                 default-directory)
+               (speedbar-message nil))))
+      ;; Else, we can do a short cut.  No text cache.
+      (let ((cbd (expand-file-name default-directory))
+           )
+       (set-buffer speedbar-buffer)
+       (speedbar-with-writable
+         (erase-buffer)
+         (dolist (func funclst)
+           (setq default-directory cbd)
+           (funcall func cbd 0))
+       (speedbar-reconfigure-keymaps)
+       (goto-char (point-min)))
+       ))))
+
 (defun speedbar-update-directory-contents ()
   "Update the contents of the speedbar buffer based on the current directory."
-  (let ((cbd (expand-file-name default-directory))
-       cbd-parent
-       (funclst speedbar-initial-expansion-list)
-       (cache speedbar-full-text-cache)
-       ;; disable stealth during update
-       (speedbar-stealthy-function-list nil)
-       (use-cache nil)
-       (expand-local nil)
-       ;; Because there is a bug I can't find just yet
-       (inhibit-quit nil))
-    (save-excursion
+
+  (save-excursion
+
+    (let ((cbd (expand-file-name default-directory))
+         cbd-parent
+         (funclst (speedbar-initial-expansion-list))
+         (cache speedbar-full-text-cache)
+         ;; disable stealth during update
+         (speedbar-stealthy-function-list nil)
+         (use-cache nil)
+         (expand-local nil)
+         ;; Because there is a bug I can't find just yet
+         (inhibit-quit nil))
       (set-buffer speedbar-buffer)
       ;; If we are updating contents to where we are, then this is
       ;; really a request to update existing contents, so we must be
       ;; careful with our text cache!
       (if (member cbd speedbar-shown-directories)
-         (setq cache nil)
+         (progn
+           (setq cache nil)
+           ;; If the current directory is not the last element in the dir
+           ;; list, then we ALSO need to zap the list of expanded directories
+           (if (/= (length (member cbd speedbar-shown-directories)) 1)
+               (setq speedbar-shown-directories (list cbd))))
 
        ;; Build cbd-parent, and see if THAT is in the current shown
        ;; directories.  First, go through pains to get the parent directory
        (if (and speedbar-smart-directory-expand-flag
                 (save-match-data
                   (setq cbd-parent cbd)
-                  (if (string-match "/$" cbd-parent)
-                      (setq cbd-parent (substring cbd-parent 0 (match-beginning 0))))
+                  (if (string-match "[/\\]$" cbd-parent)
+                      (setq cbd-parent (substring cbd-parent 0
+                                                  (match-beginning 0))))
                   (setq cbd-parent (file-name-directory cbd-parent)))
                 (member cbd-parent speedbar-shown-directories))
            (setq expand-local t)
 
          ;; If this directory is NOT in the current list of available
-         ;; paths, then use the cache, and set the cache to our new
+         ;; directorys, then use the cache, and set the cache to our new
          ;; value.  Make sure to unhighlight the current file, or if we
          ;; come back to this directory, it might be a different file
          ;; and then we get a mess!
@@ -1863,11 +2518,11 @@ name will have the function FIND-FUN and not token."
            ;; default the shown directories to this list...
            (setq speedbar-shown-directories (list cbd)))
          ))
-      (setq speedbar-last-selected-file nil)
+      (if (not expand-local) (setq speedbar-last-selected-file nil))
       (speedbar-with-writable
        (if (and expand-local
                 ;; Find this directory as a speedbar node.
-                (speedbar-path-line cbd))
+                (speedbar-directory-line cbd))
            ;; Open it.
            (speedbar-expand-line)
          (erase-buffer)
@@ -1877,15 +2532,14 @@ name will have the function FIND-FUN and not token."
                            speedbar-shown-directories))
                 (insert (cdr cache)))
                (t
-                (while funclst
-                  (setq default-directory cbd)
-                  (funcall (car funclst) cbd 0)
-                  (setq funclst (cdr funclst))))))
+         (dolist (func funclst)
+           (setq default-directory cbd)
+           (funcall func cbd 0)))))
        (goto-char (point-min)))))
-  (speedbar-reconfigure-menubar))
+  (speedbar-reconfigure-keymaps))
 
 (defun speedbar-update-special-contents ()
-  "Used the mode-specific variable to fill in the speedbar buffer.
+  "Use the mode-specific variable to fill in the speedbar buffer.
 This should only be used by modes classified as special."
   (let ((funclst speedbar-special-mode-expansion-list)
        (specialbuff (current-buffer)))
@@ -1903,63 +2557,78 @@ This should only be used by modes classified as special."
              speedbar-shown-directories nil))
       ;; Now fill in the buffer with our newly found specialized list.
       (speedbar-with-writable
-       (while funclst
-         ;; We do not erase the buffer because these functions may
-         ;; decide NOT to update themselves.
-         (funcall (car funclst) specialbuff)
-         (setq funclst (cdr funclst))))
+         (dolist (func funclst)
+           ;; We do not erase the buffer because these functions may
+           ;; decide NOT to update themselves.
+           (funcall func specialbuff)))
+
       (goto-char (point-min))))
-  (speedbar-reconfigure-menubar))
+  (speedbar-reconfigure-keymaps))
+
+(defun speedbar-set-timer (timeout)
+  "Set up the speedbar timer with TIMEOUT.
+Uses `dframe-set-timer'.
+Also resets scanner functions."
+  (dframe-set-timer timeout 'speedbar-timer-fn 'speedbar-update-flag)
+  ;; 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))
 
 (defun speedbar-timer-fn ()
-  "Run whenever emacs is idle to update the speedbar item."
-  (if (not (and (frame-live-p speedbar-frame)
-               (frame-live-p speedbar-attached-frame)))
+  "Run whenever Emacs is idle to update the speedbar item."
+  (if (or (not (speedbar-current-frame))
+         (not (frame-live-p (speedbar-current-frame))))
       (speedbar-set-timer nil)
     ;; Save all the match data so that we don't mess up executing fns
     (save-match-data
-      (if (and (frame-visible-p speedbar-frame) speedbar-update-flag)
+      ;; Only do stuff if the frame is visible, not an icon, and if
+      ;; it is currently flagged to do something.
+      (if (and speedbar-update-flag
+              (speedbar-current-frame)
+              (frame-visible-p (speedbar-current-frame))
+              (not (eq (frame-visible-p (speedbar-current-frame)) 'icon)))
          (let ((af (selected-frame)))
            (save-window-excursion
-             (select-frame speedbar-attached-frame)
+             (dframe-select-attached-frame speedbar-frame)
              ;; make sure we at least choose a window to
              ;; get a good directory from
-             (if (string-match "\\*Minibuf-[0-9]+\\*" (buffer-name))
-                 (other-window 1))
-             ;; Update for special mode all the time!
-             (if (and speedbar-mode-specific-contents-flag
-                      speedbar-special-mode-expansion-list
-                      (local-variable-p
-                       'speedbar-special-mode-expansion-list
-                       (current-buffer)))
-                 ;;(eq (get major-mode 'mode-class 'special)))
-                 (progn
-                   (if (<= 2 speedbar-verbosity-level)
-                       (message "Updating speedbar to special mode: %s..."
-                                major-mode))
-                   (speedbar-update-special-contents)
-                   (if (<= 2 speedbar-verbosity-level)
-                       (message "Updating speedbar to special mode: %s...done"
-                                major-mode)))
-               ;; Update all the contents if directories change!
-               (if (or (member (expand-file-name default-directory)
-                               speedbar-shown-directories)
-                       (and speedbar-ignored-path-regexp
-                            (string-match
-                             speedbar-ignored-path-regexp
-                             (expand-file-name default-directory)))
-                       (member major-mode speedbar-ignored-modes)
-                       (eq af speedbar-frame)
-                       (not (buffer-file-name)))
-                   nil
-                 (if (<= 1 speedbar-verbosity-level)
-                     (message "Updating speedbar to: %s..."
-                              default-directory))
-                 (speedbar-update-directory-contents)
-                 (if (<= 1 speedbar-verbosity-level)
-                     (message "Updating speedbar to: %s...done"
-                              default-directory))))
-             (select-frame af))
+             (if (window-minibuffer-p (selected-window))
+                 nil
+               ;; Check for special modes
+               (speedbar-maybe-add-localized-support (current-buffer))
+               ;; Update for special mode all the time!
+               (if (and speedbar-mode-specific-contents-flag
+                        (listp speedbar-special-mode-expansion-list)
+                        speedbar-special-mode-expansion-list
+                        (local-variable-p
+                         'speedbar-special-mode-expansion-list
+                         (current-buffer)))
+                   ;;(eq (get major-mode 'mode-class 'special)))
+                   (progn
+                     (if (<= 2 speedbar-verbosity-level)
+                         (speedbar-message
+                          "Updating speedbar to special mode: %s..."
+                          major-mode))
+                     (speedbar-update-special-contents)
+                     (if (<= 2 speedbar-verbosity-level)
+                         (progn
+                           (speedbar-message
+                            "Updating speedbar to special mode: %s...done"
+                            major-mode)
+                           (speedbar-message nil))))
+                 ;; Update all the contents if directories change!
+                 (if (or (member major-mode speedbar-ignored-modes)
+                         (eq af (speedbar-current-frame))
+                         (not (buffer-file-name)))
+                     nil
+                   (speedbar-update-localized-contents)
+                   ))
+               (select-frame af)))
            ;; Now run stealthy updates of time-consuming items
            (speedbar-stealthy-updates)))))
   (run-hooks 'speedbar-timer-hook))
@@ -1967,39 +2636,66 @@ This should only be used by modes classified as special."
 \f
 ;;; Stealthy activities
 ;;
+(defvar speedbar-stealthy-update-recurse nil
+  "Recursion avoidance variable for stealthy update.")
+
 (defun speedbar-stealthy-updates ()
   "For a given speedbar, run all items in the stealthy function list.
 Each item returns t if it completes successfully, or nil if
 interrupted by the user."
-  (let ((l speedbar-stealthy-function-list))
-    (unwind-protect
-       (while (and l (funcall (car l)))
-         (sit-for 0)
-         (setq l (cdr l)))
-      ;(message "Exit with %S" (car l))
-      )))
+  (if (not speedbar-stealthy-update-recurse)
+      (let ((l (speedbar-initial-stealthy-functions))
+           (speedbar-stealthy-update-recurse t))
+       (unwind-protect
+           (speedbar-with-writable
+             (while (and l (funcall (car l)))
+               ;;(sit-for 0)
+               (setq l (cdr l))))
+         ;;(speedbar-message "Exit with %S" (car l))
+         ))))
 
 (defun speedbar-reset-scanners ()
   "Reset any variables used by functions in the stealthy list as state.
 If new functions are added, their state needs to be updated here."
-  (setq speedbar-vc-to-do-point t)
+  (setq speedbar-vc-to-do-point t
+       speedbar-obj-to-do-point t
+       speedbar-ro-to-do-point t)
   (run-hooks 'speedbar-scanner-reset-hook)
   )
 
+(defun speedbar-find-selected-file (file)
+  "Go to the line where FILE is."
+
+  (set-buffer speedbar-buffer)
+  
+  (goto-char (point-min))
+  (let ((m nil))
+    (while (and (setq m (re-search-forward
+                        (concat " \\(" (regexp-quote (file-name-nondirectory file))
+                                "\\)\\(" speedbar-indicator-regex "\\)?\n")
+                        nil t))
+               (not (string= file
+                             (concat
+                              (speedbar-line-directory
+                               (save-excursion
+                                 (goto-char (match-beginning 0))
+                                 (beginning-of-line)
+                                 (save-match-data
+                                   (looking-at "[0-9]+:")
+                                   (string-to-number (match-string 0)))))
+                              (match-string 1))))))
+    (if m
+       (progn
+         (goto-char (match-beginning 1))
+         (match-string 1)))))
+
 (defun speedbar-clear-current-file ()
   "Locate the file thought to be current, and remove its highlighting."
   (save-excursion
-    (set-buffer speedbar-buffer)
+    ;;(set-buffer speedbar-buffer)
     (if speedbar-last-selected-file
        (speedbar-with-writable
-         (goto-char (point-min))
-         (if (and
-              speedbar-last-selected-file
-              (re-search-forward
-               (concat " \\(" (regexp-quote speedbar-last-selected-file)
-                       "\\)\\(" (regexp-quote speedbar-vc-indicator)
-                       "\\)?\n")
-               nil t))
+         (if (speedbar-find-selected-file speedbar-last-selected-file)
              (put-text-property (match-beginning 1)
                                 (match-end 1)
                                 'face
@@ -2012,15 +2708,16 @@ it should be in the list, then the directory cache needs to be
 updated."
   (let* ((lastf (selected-frame))
         (newcfd (save-excursion
-                  (select-frame speedbar-attached-frame)
+                  (dframe-select-attached-frame speedbar-frame)
                   (let ((rf (if (buffer-file-name)
                                 (buffer-file-name)
                               nil)))
                     (select-frame lastf)
                     rf)))
-        (newcf (if newcfd (file-name-nondirectory newcfd)))
+        (newcf (if newcfd newcfd))
         (lastb (current-buffer))
-        (sucf-recursive (boundp 'sucf-recursive)))
+        (sucf-recursive (boundp 'sucf-recursive))
+        (case-fold-search t))
     (if (and newcf
             ;; check here, that way we won't refresh to newcf until
             ;; its been written, thus saving ourselves some time
@@ -2030,22 +2727,18 @@ updated."
          ;; It is important to select the frame, otherwise the window
          ;; we want the cursor to move in will not be updated by the
          ;; search-forward command.
-         (select-frame speedbar-frame)
+         (select-frame (speedbar-current-frame))
          ;; Remove the old file...
          (speedbar-clear-current-file)
          ;; now highlight the new one.
-         (set-buffer speedbar-buffer)
+         ;; (set-buffer speedbar-buffer)
          (speedbar-with-writable
-           (goto-char (point-min))
-           (if (re-search-forward
-                (concat " \\(" (regexp-quote newcf) "\\)\\("
-                        (regexp-quote speedbar-vc-indicator)
-                        "\\)?\n") nil t)
-                 ;; put the property on it
-                 (put-text-property (match-beginning 1)
-                                    (match-end 1)
-                                    'face
-                                    'speedbar-selected-face)
+           (if (speedbar-find-selected-file newcf)
+               ;; put the property on it
+               (put-text-property (match-beginning 1)
+                                  (match-end 1)
+                                  'face
+                                  'speedbar-selected-face)
              ;; Oops, it's not in the list.  Should it be?
              (if (and (string-match speedbar-file-regexp newcf)
                       (string= (file-name-directory newcfd)
@@ -2053,8 +2746,7 @@ updated."
                  ;; yes, it is (we will ignore unknowns for now...)
                  (progn
                    (speedbar-refresh)
-                   (if (re-search-forward
-                        (concat " \\(" (regexp-quote newcf) "\\)\n") nil t)
+                   (if (speedbar-find-selected-file newcf)
                        ;; put the property on it
                        (put-text-property (match-beginning 1)
                                           (match-end 1)
@@ -2065,17 +2757,88 @@ updated."
            (setq speedbar-last-selected-file newcf))
          (if (not sucf-recursive)
              (progn
-               (forward-line -1)
-               (speedbar-position-cursor-on-line)))
+
+                ;;Sat Dec 15 2001 12:40 AM (burton@openprivacy.org): this
+                ;;doesn't need to be in.  We don't want to recenter when we are
+                ;;updating files.
+
+                ;;(speedbar-center-buffer-smartly)
+
+               (speedbar-position-cursor-on-line)
+               ))
          (set-buffer lastb)
          (select-frame lastf)
          )))
   ;; return that we are done with this activity.
   t)
 
-;; Load ange-ftp only if compiling to remove errors.
+(defun speedbar-add-indicator (indicator-string &optional replace-this)
+  "Add INDICATOR-STRING to the end of this speedbar line.
+If INDICATOR-STRING is space, and REPLACE-THIS is a character, then
+the existing indicator is removed.  If there is already an
+indicator, then do not add a space."
+  (beginning-of-line)
+  ;; The nature of the beast: Assume we are in "the right place"
+  (end-of-line)
+  (skip-chars-backward (concat " " speedbar-vc-indicator
+                              speedbar-object-read-only-indicator
+                              (car speedbar-obj-indicator)
+                              (cdr speedbar-obj-indicator)))
+  (if (and (not (looking-at speedbar-indicator-regex))
+          (not (string= indicator-string " ")))
+      (insert speedbar-indicator-separator))
+  (speedbar-with-writable
+    (save-excursion
+      (if (and replace-this
+              (re-search-forward replace-this (save-excursion (end-of-line)
+                                                              (point))
+                                 t))
+         (delete-region (match-beginning 0) (match-end 0))))
+    (end-of-line)
+    (if (not (string= " " indicator-string))
+       (let ((start (point)))
+         (insert indicator-string)
+         (speedbar-insert-image-button-maybe start (length indicator-string))
+         ))))
+
+(defun speedbar-check-read-only ()
+  "Scan all the files in a directory, and for each see if it is read only."
+  ;; Check for to-do to be reset.  If reset but no RCS is available
+  ;; then set to nil (do nothing) otherwise, start at the beginning
+  (save-excursion
+    (if speedbar-buffer (set-buffer speedbar-buffer))
+    (if (eq speedbar-ro-to-do-point t)
+       (setq speedbar-ro-to-do-point 0))
+    (if (numberp speedbar-ro-to-do-point)
+       (progn
+         (goto-char speedbar-ro-to-do-point)
+         (while (and (not (input-pending-p))
+                     (re-search-forward "^\\([0-9]+\\):\\s-*[[<][+-\?][]>] "
+                                        nil t))
+           (setq speedbar-ro-to-do-point (point))
+           (let ((f (speedbar-line-file)))
+             (if f
+                 (if (not (file-writable-p f))
+                     (speedbar-add-indicator
+                      speedbar-object-read-only-indicator
+                      (regexp-quote speedbar-object-read-only-indicator))
+                   (speedbar-add-indicator
+                    " " (regexp-quote
+                         speedbar-object-read-only-indicator))))))
+         (if (input-pending-p)
+             ;; return that we are incomplete
+             nil
+           ;; we are done, set to-do to nil
+           (setq speedbar-ro-to-do-point nil)
+           ;; and return t
+           t))
+      t)))
+
+;; Load efs/ange-ftp only if compiling to remove byte-compiler warnings.
 ;; Steven L Baur <steve@xemacs.org> said this was important:
-(eval-when-compile (or (featurep 'xemacs) (require 'ange-ftp)))
+(eval-when-compile (or (featurep 'xemacs)
+                      (condition-case () (require 'efs)
+                        (error (require 'ange-ftp)))))
 
 (defun speedbar-check-vc ()
   "Scan all files in a directory, and for each see if it's checked out.
@@ -2084,29 +2847,37 @@ to add more types of version control systems."
   ;; Check for to-do to be reset.  If reset but no RCS is available
   ;; then set to nil (do nothing) otherwise, start at the beginning
   (save-excursion
-    (set-buffer speedbar-buffer)
+    (if speedbar-buffer (set-buffer speedbar-buffer))
     (if (and speedbar-vc-do-check (eq speedbar-vc-to-do-point t)
             (speedbar-vc-check-dir-p default-directory)
-            (not (and (featurep 'ange-ftp)
-                      (string-match (car
-                                     (if speedbar-xemacsp
-                                         ange-ftp-path-format
-                                       ange-ftp-name-format))
-                                    (expand-file-name default-directory)))))
+            (not (or (and (featurep 'ange-ftp)
+                          (string-match
+                           (car (symbol-value
+                                 (if dframe-xemacsp
+                                     'ange-ftp-directory-format
+                                   'ange-ftp-name-format)))
+                           (expand-file-name default-directory)))
+                     ;; efs support: Bob Weiner
+                     (and (featurep 'efs)
+                          (string-match
+                           (let ((reg (symbol-value 'efs-directory-regexp)))
+                             (if (stringp reg)
+                                 reg
+                               (car reg)))
+                           (expand-file-name default-directory))))))
        (setq speedbar-vc-to-do-point 0))
     (if (numberp speedbar-vc-to-do-point)
        (progn
          (goto-char speedbar-vc-to-do-point)
          (while (and (not (input-pending-p))
-                     (re-search-forward "^\\([0-9]+\\):\\s-*\\[[+-]\\] "
+                     (re-search-forward "^\\([0-9]+\\):\\s-*\\[[+-?]\\] "
                                         nil t))
            (setq speedbar-vc-to-do-point (point))
            (if (speedbar-check-vc-this-line (match-string 1))
-               (if (not (looking-at (regexp-quote speedbar-vc-indicator)))
-                   (speedbar-with-writable (insert speedbar-vc-indicator)))
-             (if (looking-at (regexp-quote speedbar-vc-indicator))
-                 (speedbar-with-writable
-                   (delete-region (match-beginning 0) (match-end 0))))))
+               (speedbar-add-indicator speedbar-vc-indicator
+                                       (regexp-quote speedbar-vc-indicator))
+             (speedbar-add-indicator " "
+                                     (regexp-quote speedbar-vc-indicator))))
          (if (input-pending-p)
              ;; return that we are incomplete
              nil
@@ -2120,8 +2891,8 @@ to add more types of version control systems."
   "Return t if the file on this line is check of of a version control system.
 Parameter DEPTH is a string with the current depth of indentation of
 the file being checked."
-  (let* ((d (string-to-int depth))
-        (f (speedbar-line-path d))
+  (let* ((d (string-to-number depth))
+        (f (speedbar-line-directory d))
         (fn (buffer-substring-no-properties
              ;; Skip-chars: thanks ptype@dra.hmg.gb
              (point) (progn
@@ -2131,56 +2902,128 @@ the file being checked."
                        (point))))
         (fulln (concat f fn)))
     (if (<= 2 speedbar-verbosity-level)
-       (message "Speedbar vc check...%s" fulln))
+       (speedbar-message "Speedbar vc check...%s" fulln))
     (and (file-writable-p fulln)
         (speedbar-this-file-in-vc f fn))))
 
-(defun speedbar-vc-check-dir-p (path)
-  "Return t if we should bother checking PATH for version control files.
+(defun speedbar-vc-check-dir-p (directory)
+  "Return t if we should bother checking DIRECTORY for version control files.
 This can be overloaded to add new types of version control systems."
   (or
+   ;; Local CVS available in Emacs 21
+   (and (fboundp 'vc-state)
+       (file-exists-p (concat directory "CVS/")))
    ;; Local RCS
-   (file-exists-p (concat path "RCS/"))
+   (file-exists-p (concat directory "RCS/"))
    ;; Local SCCS
-   (file-exists-p (concat path "SCCS/"))
+   (file-exists-p (concat directory "SCCS/"))
    ;; Remote SCCS project
    (let ((proj-dir (getenv "PROJECTDIR")))
      (if proj-dir
         (file-exists-p (concat proj-dir "/SCCS"))
        nil))
    ;; User extension
-   (run-hook-with-args 'speedbar-vc-path-enable-hook path)
+   (run-hook-with-args-until-success 'speedbar-vc-directory-enable-hook
+                                     directory)
    ))
 
-(defun speedbar-this-file-in-vc (path name)
-  "Check to see if the file in PATH with NAME is in a version control system.
+(defun speedbar-this-file-in-vc (directory name)
+  "Check to see if the file in DIRECTORY with NAME is in a version control system.
 You can add new VC systems by overriding this function.  You can
 optimize this function by overriding it and only doing those checks
 that will occur on your system."
   (or
-   ;; RCS file name
-   (file-exists-p (concat path "RCS/" name ",v"))
-   ;; Local SCCS file name
-   (file-exists-p (concat path "SCCS/p." name))
-   ;; Remote SCCS file name
-   (let ((proj-dir (getenv "PROJECTDIR")))
-     (if proj-dir
-         (file-exists-p (concat proj-dir "/SCCS/p." name))
-       nil))
+   (if (fboundp 'vc-state)
+       ;; Emacs 21 handles VC state in a nice way.
+       (condition-case nil
+          (let ((state  (vc-state (concat directory name))))
+            (not (or (eq 'up-to-date state)
+                     (null state))))
+        ;; An error means not in a VC system
+        (error nil))
+     (or
+      ;; RCS file name
+      (file-exists-p (concat directory "RCS/" name ",v"))
+      (file-exists-p (concat directory "RCS/" name))
+      ;; Local SCCS file name
+      (file-exists-p (concat directory "SCCS/s." name))
+      ;; Remote SCCS file name
+      (let ((proj-dir (getenv "PROJECTDIR")))
+       (if proj-dir
+           (file-exists-p (concat proj-dir "/SCCS/s." name))
+         nil))))
    ;; User extension
-   (run-hook-with-args 'speedbar-vc-in-control-hook path name)
+   (run-hook-with-args 'speedbar-vc-in-control-hook directory name)
    ))
+
+;; Objet File scanning
+(defun speedbar-check-objects ()
+  "Scan all files in a directory, and for each see if there is an object.
+See `speedbar-check-obj-this-line' and `speedbar-obj-alist' for how
+to add more object types."
+  ;; Check for to-do to be reset.  If reset but no RCS is available
+  ;; then set to nil (do nothing) otherwise, start at the beginning
+  (save-excursion
+    (if speedbar-buffer (set-buffer speedbar-buffer))
+    (if (and speedbar-obj-do-check (eq speedbar-obj-to-do-point t))
+       (setq speedbar-obj-to-do-point 0))
+    (if (numberp speedbar-obj-to-do-point)
+       (progn
+         (goto-char speedbar-obj-to-do-point)
+         (while (and (not (input-pending-p))
+                     (re-search-forward "^\\([0-9]+\\):\\s-*\\[[+-]\\] "
+                                        nil t))
+           (setq speedbar-obj-to-do-point (point))
+           (let ((ind (speedbar-check-obj-this-line (match-string 1))))
+             (if (not ind) (setq ind " "))
+             (speedbar-add-indicator ind (concat
+                                          (car speedbar-obj-indicator)
+                                          "\\|"
+                                          (cdr speedbar-obj-indicator)))))
+         (if (input-pending-p)
+             ;; return that we are incomplete
+             nil
+           ;; we are done, set to-do to nil
+           (setq speedbar-obj-to-do-point nil)
+           ;; and return t
+           t))
+      t)))
+
+(defun speedbar-check-obj-this-line (depth)
+  "Return t if the file on this line has an associated object.
+Parameter DEPTH is a string with the current depth of indentation of
+the file being checked."
+  (let* ((d (string-to-number depth))
+        (f (speedbar-line-directory d))
+        (fn (buffer-substring-no-properties
+             ;; Skip-chars: thanks ptype@dra.hmg.gb
+             (point) (progn
+                       (skip-chars-forward "^ "
+                                           (save-excursion (end-of-line)
+                                                           (point)))
+                       (point))))
+        (fulln (concat f fn)))
+    (if (<= 2 speedbar-verbosity-level)
+       (speedbar-message "Speedbar obj check...%s" fulln))
+    (let ((oa speedbar-obj-alist))
+      (while (and oa (not (string-match (car (car oa)) fulln)))
+       (setq oa (cdr oa)))
+      (if (not (and oa (file-exists-p (concat (file-name-sans-extension fulln)
+                                             (cdr (car oa))))))
+         nil
+       ;; Find out if the object is out of date or not.
+       (let ((date1 (nth 5 (file-attributes fulln)))
+             (date2 (nth 5 (file-attributes (concat
+                                             (file-name-sans-extension fulln)
+                                              (cdr (car oa)))))))
+         (if (or (< (car date1) (car date2))
+                 (and (= (car date1) (car date2))
+                      (< (nth 1 date1) (nth 1 date2))))
+             (car speedbar-obj-indicator)
+           (cdr speedbar-obj-indicator)))))))
 \f
 ;;; Clicking Activity
 ;;
-(defun speedbar-quick-mouse (e)
-  "Since mouse events are strange, this will keep the mouse nicely positioned.
-This should be bound to mouse event E."
-  (interactive "e")
-  (mouse-set-point e)
-  (speedbar-position-cursor-on-line)
-  )
-
 (defun speedbar-position-cursor-on-line ()
   "Position the cursor on a line."
   (let ((oldpos (point)))
@@ -2189,45 +3032,22 @@ This should be bound to mouse event E."
        (goto-char (1- (match-end 0)))
       (goto-char oldpos))))
 
-(defun speedbar-power-click (e)
-  "Activate any speedbar button as a power click.
-This should be bound to mouse event E."
-  (interactive "e")
-  (let ((speedbar-power-click t))
-    (speedbar-click e)))
-
 (defun speedbar-click (e)
   "Activate any speedbar buttons where the mouse is clicked.
 This must be bound to a mouse event.  A button is any location of text
 with a mouse face that has a text property called `speedbar-function'.
-This should be bound to mouse event E."
-  (interactive "e")
-  (mouse-set-point e)
-  (speedbar-do-function-pointer)
-  (speedbar-quick-mouse e))
-
-(defun speedbar-double-click (e)
-  "Activate any speedbar buttons where the mouse is clicked.
-This must be bound to a mouse event.  A button is any location of text
-with a mouse face that has a text property called `speedbar-function'.
-This should be bound to mouse event E."
-  (interactive "e")
-  ;; Emacs only.  XEmacs handles this via `mouse-track-click-hook'.
-  (cond ((eq (car e) 'down-mouse-1)
-        (mouse-set-point e))
-       ((eq (car e) 'mouse-1)
-        (speedbar-quick-mouse e))
-       ((or (eq (car e) 'double-down-mouse-1)
-            (eq (car e) 'tripple-down-mouse-1))
-        (mouse-set-point e)
-        (speedbar-do-function-pointer)
-        (speedbar-quick-mouse e))))
+Argument E is the click event."
+  ;; Backward compatibility let statement.
+  (let ((speedbar-power-click dframe-power-click))
+    (speedbar-do-function-pointer))
+  (dframe-quick-mouse e))
 
 (defun speedbar-do-function-pointer ()
   "Look under the cursor and examine the text properties.
 From this extract the file/tag name, token, indentation level and call
-a function if appropriate"
-  (let* ((fn (get-text-property (point) 'speedbar-function))
+a function if appropriate."
+  (let* ((speedbar-frame (speedbar-current-frame))
+        (fn (get-text-property (point) 'speedbar-function))
         (tok (get-text-property (point) 'speedbar-token))
         ;; The 1-,+ is safe because scaning starts AFTER the point
         ;; specified.  This lets the search include the character the
@@ -2244,51 +3064,75 @@ a function if appropriate"
                                    (buffer-substring-no-properties
                                    (match-beginning 0) (match-end 0))
                                  "0")))))
-    ;;(message "%S:%S:%S:%s" fn tok txt dent)
+    ;;(speedbar-message "%S:%S:%S:%s" fn tok txt dent)
     (and fn (funcall fn txt tok dent)))
   (speedbar-position-cursor-on-line))
 \f
 ;;; Reading info from the speedbar buffer
 ;;
+(defun speedbar-line-text (&optional p)
+  "Retrieve the text after prefix junk for the current line.
+Optional argument P is where to start the search from."
+  (save-excursion
+    (if p (goto-char p))
+    (beginning-of-line)
+    (if (looking-at (concat
+                    "\\([0-9]+\\): *[[<{]?[-+?= ][]>}@()|] \\([^ \n]+\\)"))
+       (get-text-property (match-beginning 2) 'speedbar-text)
+      nil)))
+
+(defun speedbar-line-token (&optional p)
+  "Retrieve the token information after the prefix junk for the current line.
+Optional argument P is where to start the search from."
+  (save-excursion
+    (if p (goto-char p))
+    (beginning-of-line)
+    (if (looking-at (concat
+                    "\\([0-9]+\\): *[[<{]?[-+?= ][]>}@()|] \\([^ \n]+\\)\\("
+                    speedbar-indicator-regex "\\)?"))
+       (progn
+         (goto-char (match-beginning 2))
+         (get-text-property (point) 'speedbar-token))
+      nil)))
+
 (defun speedbar-line-file (&optional p)
-  "Retrieve the file or whatever from the line at P point.
+  "Retrieve the file or whatever from the line at point P.
 The return value is a string representing the file.  If it is a
 directory, then it is the directory name."
-  (save-excursion
-    (save-match-data
-      (beginning-of-line)
-      (if (looking-at (concat
-                      "\\([0-9]+\\): *[[<][-+?][]>] \\([^ \n]+\\)\\("
-                      (regexp-quote speedbar-vc-indicator)
-                      "\\)?"))
-         (let* ((depth (string-to-int (match-string 1)))
-                (path (speedbar-line-path depth))
-                (f (match-string 2)))
-           (concat path f))
-       nil))))
+  (save-match-data
+    (save-restriction
+      (widen)
+      (let ((f (speedbar-line-text p)))
+       (if f
+           (let* ((depth (string-to-number (match-string 1)))
+                  (directory (speedbar-line-directory depth)))
+             (if (file-exists-p (concat directory f))
+                 (concat directory f)
+               nil))
+         nil)))))
 
 (defun speedbar-goto-this-file (file)
-  "If FILE is displayed, goto this line and return t.
+  "If FILE is displayed, go to this line and return t.
 Otherwise do not move and return nil."
-  (let ((path (substring (file-name-directory (expand-file-name file))
+  (let ((directory (substring (file-name-directory (expand-file-name file))
                         (length (expand-file-name default-directory))))
        (dest (point)))
     (save-match-data
       (goto-char (point-min))
       ;; scan all the directories
-      (while (and path (not (eq path t)))
-       (if (string-match "^/?\\([^/]+\\)" path)
-           (let ((pp (match-string 1 path)))
+      (while (and directory (not (eq directory t)))
+       (if (string-match "^[/\\]?\\([^/\\]+\\)" directory)
+           (let ((pp (match-string 1 directory)))
              (if (save-match-data
                    (re-search-forward (concat "> " (regexp-quote pp) "$")
                                       nil t))
-                 (setq path (substring path (match-end 1)))
-               (setq path nil)))
-         (setq path t)))
+                 (setq directory (substring directory (match-end 1)))
+               (setq directory nil)))
+         (setq directory t)))
       ;; find the file part
-      (if (or (not path) (string= (file-name-nondirectory file) ""))
+      (if (or (not directory) (string= (file-name-nondirectory file) ""))
          ;; only had a dir part
-         (if path
+         (if directory
              (progn
                (speedbar-position-cursor-on-line)
                t)
@@ -2297,7 +3141,7 @@ Otherwise do not move and return nil."
        (let ((nd (file-name-nondirectory file)))
          (if (re-search-forward
               (concat "] \\(" (regexp-quote nd)
-                      "\\)\\(" (regexp-quote speedbar-vc-indicator) "\\)?$")
+                      "\\)\\(" speedbar-indicator-regex "\\)$")
               nil t)
              (progn
                (speedbar-position-cursor-on-line)
@@ -2305,53 +3149,66 @@ Otherwise do not move and return nil."
            (goto-char dest)
            nil))))))
 
-(defun speedbar-line-path (depth)
-  "Retrieve the pathname associated with the current line.
+(defun speedbar-line-directory (&optional depth)
+  "Retrieve the directory name associated with the current line.
+This may require traversing backwards from DEPTH and combining the default
+directory with these items.  This function is replaceable in
+`speedbar-mode-functions-list' as `speedbar-line-directory'."
+  (save-restriction
+    (widen)
+    (let ((rf (speedbar-fetch-replacement-function 'speedbar-line-directory)))
+      (if rf (funcall rf depth) default-directory))))
+      
+(defun speedbar-files-line-directory (&optional depth)
+  "Retrieve the directoryname associated with the current line.
 This may require traversing backwards from DEPTH and combining the default
 directory with these items."
   (save-excursion
     (save-match-data
-      (let ((path nil))
+      (if (not depth)
+         (progn
+           (beginning-of-line)
+           (looking-at "^\\([0-9]+\\):")
+           (setq depth (string-to-number (match-string 1)))))
+      (let ((directory nil))
        (setq depth (1- depth))
        (while (/= depth -1)
          (if (not (re-search-backward (format "^%d:" depth) nil t))
-             (error "Error building path of tag")
-           (cond ((looking-at "[0-9]+:\\s-*<->\\s-+\\([^\n]+\\)$")
-                  (setq path (concat (buffer-substring-no-properties
-                                      (match-beginning 1) (match-end 1))
+             (error "Error building filename of tag")
+           (cond ((looking-at "[0-9]+:\\s-*<->\\s-+\\([^\n]+\\)")
+                  (setq directory (concat (speedbar-line-text)
                                      "/"
-                                     path)))
-                 ((looking-at "[0-9]+:\\s-*[-]\\s-+\\([^\n]+\\)$")
-                  ;; This is the start of our path.
-                  (setq path (buffer-substring-no-properties
-                              (match-beginning 1) (match-end 1))))))
+                                     directory)))
+                 ((looking-at "[0-9]+:\\s-*[-]\\s-+\\([^\n]+\\)")
+                  ;; This is the start of our directory.
+                  (setq directory (speedbar-line-text)))))
          (setq depth (1- depth)))
-       (if (and path
-                (string-match (concat (regexp-quote speedbar-vc-indicator) "$")
-                              path))
-           (setq path (substring path 0 (match-beginning 0))))
-       (concat default-directory path)))))
-
-(defun speedbar-path-line (path)
-  "Position the cursor on the line specified by PATH."
+       (if (and directory
+                (string-match (concat speedbar-indicator-regex "$")
+                              directory))
+           (setq directory (substring directory 0 (match-beginning 0))))
+       (concat default-directory directory)))))
+
+(defun speedbar-directory-line (directory)
+  "Position the cursor on the line specified by DIRECTORY."
   (save-match-data
-    (if (string-match "/$" path)
-       (setq path (substring path 0 (match-beginning 0))))
+    (if (string-match "[/\\]$" directory)
+       (setq directory (substring directory 0 (match-beginning 0))))
     (let ((nomatch t) (depth 0)
-         (fname (file-name-nondirectory path))
-         (pname (file-name-directory path)))
+         (fname (file-name-nondirectory directory))
+         (pname (file-name-directory directory)))
       (if (not (member pname speedbar-shown-directories))
-         (error "Internal Error: File %s not shown in speedbar." path))
+         (error "Internal Error: File %s not shown in speedbar" directory))
       (goto-char (point-min))
       (while (and nomatch
                  (re-search-forward
                   (concat "[]>] \\(" (regexp-quote fname)
-                          "\\)\\(" (regexp-quote speedbar-vc-indicator) "\\)?$")
+                          "\\)\\(" speedbar-indicator-regex "\\)?$")
                   nil t))
        (beginning-of-line)
        (looking-at "\\([0-9]+\\):")
-       (setq depth (string-to-int (match-string 0))
-             nomatch (not (string= pname (speedbar-line-path depth))))
+       (setq depth (string-to-number (match-string 0))
+             nomatch (not (string= pname (speedbar-line-directory depth))))
        (end-of-line))
       (beginning-of-line)
       (not nomatch))))
@@ -2363,75 +3220,119 @@ directory with these items."
        (beginning-of-line)
        ;; If this fails, then it is a non-standard click, and as such,
        ;; perfectly allowed.
-       (if (re-search-forward "[]>}] [a-zA-Z0-9]"
+       (if (re-search-forward "[]>?}] [^ ]"
                               (save-excursion (end-of-line) (point))
                               t)
-           (speedbar-do-function-pointer)
+           (progn
+             (forward-char -1)
+             (speedbar-do-function-pointer))
          nil))
       (speedbar-do-function-pointer)))
 
-(defun speedbar-expand-line ()
-  "Expand the line under the cursor."
-  (interactive)
+(defun speedbar-expand-line (&optional arg)
+  "Expand the line under the cursor.
+With universal argument ARG, flush cached data."
+  (interactive "P")
   (beginning-of-line)
-  (re-search-forward ":\\s-*.\\+. " (save-excursion (end-of-line) (point)))
-  (forward-char -2)
-  (speedbar-do-function-pointer))
-
+  (let* ((dframe-power-click arg)
+        (speedbar-power-click arg))
+    (condition-case nil
+       (progn
+         (re-search-forward ":\\s-*.\\+. "
+                            (save-excursion (end-of-line) (point)))
+         (forward-char -2)
+         (speedbar-do-function-pointer))
+      (error (speedbar-position-cursor-on-line)))))
+  
+(defun speedbar-flush-expand-line ()
+  "Expand the line under the cursor and flush any cached information."
+  (interactive)
+  (speedbar-expand-line 1))
+  
 (defun speedbar-contract-line ()
   "Contract the line under the cursor."
   (interactive)
   (beginning-of-line)
-  (re-search-forward ":\\s-*.-. " (save-excursion (end-of-line) (point)))
-  (forward-char -2)
-  (speedbar-do-function-pointer))
-
-(if speedbar-xemacsp
-    (defalias 'speedbar-mouse-event-p 'button-press-event-p)
-  (defun speedbar-mouse-event-p (event)
-    "Return t if the event is a mouse related event"
-    ;; And Emacs does it this way
-    (if (and (listp event)
-            (member (event-basic-type event)
-                    '(mouse-1 mouse-2 mouse-3)))
-       t
-      nil)))
-
-(defun speedbar-maybee-jump-to-attached-frame ()
-  "Jump to the attached frame ONLY if this was not a mouse event."
-  (if (or (not (speedbar-mouse-event-p last-input-event))
-         speedbar-activity-change-focus-flag)
+  (condition-case nil
+      (progn
+       (re-search-forward ":\\s-*.-. "
+                          (save-excursion (end-of-line) (point)))
+       (forward-char -2)
+       (speedbar-do-function-pointer))
+    (error (speedbar-position-cursor-on-line))))
+
+(defun speedbar-toggle-line-expansion ()
+  "Contract or expand the line under the cursor."
+  (interactive)
+  (beginning-of-line)
+  (condition-case nil
       (progn
-       (select-frame speedbar-attached-frame)
-       (other-frame 0))))
+       (re-search-forward ":\\s-*.[-+]. "
+                          (save-excursion (end-of-line) (point)))
+       (forward-char -2)
+       (speedbar-do-function-pointer))
+    (error (speedbar-position-cursor-on-line))))
+
+(defun speedbar-expand-line-descendants (&optional arg)
+  "Expand the line under the cursor and all descendants.
+Optional argument ARG indicates that any cache should be flushed."
+  (interactive "P")
+  (speedbar-expand-line arg)
+  ;; Now, inside the area expaded here, expand all subnodes of
+  ;; the same descendant type.
+  (save-excursion
+    (speedbar-next 1) ;; Move into the list.
+    (let ((err nil))
+      (while (not err)
+       (condition-case nil
+           (progn
+             (speedbar-expand-line-descendants arg)
+             (speedbar-restricted-next 1))
+         (error (setq err t))))))
+  )
+
+(defun speedbar-contract-line-descendants ()
+  "Expand the line under the cursor and all descendants."
+  (interactive)
+  (speedbar-contract-line)
+  ;; Don't need to do anything else since all descendants are
+  ;; hidden by default anyway.  Yay!  It's easy.
+  )
 
 (defun speedbar-find-file (text token indent)
   "Speedbar click handler for filenames.
 TEXT, the file will be displayed in the attached frame.
 TOKEN is unused, but required by the click handler.  INDENT is the
 current indentation level."
-  (let ((cdd (speedbar-line-path indent)))
+  (let ((cdd (speedbar-line-directory indent)))
+    ;; Run before visiting file hook here.
+    (let ((f (selected-frame)))
+      (dframe-select-attached-frame speedbar-frame)
+      (run-hooks 'speedbar-before-visiting-file-hook)
+      (select-frame f))
     (speedbar-find-file-in-frame (concat cdd text))
     (speedbar-stealthy-updates)
     (run-hooks 'speedbar-visiting-file-hook)
     ;; Reset the timer with a new timeout when cliking a file
     ;; in case the user was navigating directories, we can cancel
     ;; that other timer.
-    (speedbar-set-timer speedbar-update-speed))
-  (speedbar-maybee-jump-to-attached-frame))
+    (speedbar-set-timer dframe-update-speed))
+  (dframe-maybee-jump-to-attached-frame))
 
 (defun speedbar-dir-follow (text token indent)
   "Speedbar click handler for directory names.
-Clicking a directory will cause the speedbar to list files in the
+Clicking a directory will cause the speedbar to list files in
 the subdirectory TEXT.  TOKEN is an unused requirement.  The
 subdirectory chosen will be at INDENT level."
   (setq default-directory
-       (concat (expand-file-name (concat (speedbar-line-path indent) text))
+       (concat (expand-file-name (concat (speedbar-line-directory indent) text))
                "/"))
   ;; Because we leave speedbar as the current buffer,
   ;; update contents will change directory without
-  ;; having to touch the attached frame.
-  (speedbar-update-contents)
+  ;; having to touch the attached frame.  Turn off smart expand just
+  ;; in case.
+  (let ((speedbar-smart-directory-expand-flag nil))
+    (speedbar-update-contents))
   (speedbar-set-timer speedbar-navigating-speed)
   (setq speedbar-last-selected-file nil)
   (speedbar-stealthy-updates))
@@ -2442,14 +3343,13 @@ Handles end-of-sublist smartly."
   (speedbar-with-writable
     (save-excursion
       (end-of-line) (forward-char 1)
-      (while (and (not (save-excursion
-                        (re-search-forward (format "^%d:" indent)
-                                           nil t)))
-                 (>= indent 0))
-       (setq indent (1- indent)))
-      (delete-region (point) (if (>= indent 0)
-                                (match-beginning 0)
-                              (point-max))))))
+      (let ((start (point)))
+       (while (and (looking-at "^\\([0-9]+\\):")
+                   (> (string-to-number (match-string 1)) indent)
+                   (not (eobp)))
+         (forward-line 1)
+         (beginning-of-line))
+       (delete-region start (point))))))
 
 (defun speedbar-dired (text token indent)
   "Speedbar click handler for directory expand button.
@@ -2459,7 +3359,7 @@ expanded.  INDENT is the current indentation level."
   (cond ((string-match "+" text)       ;we have to expand this dir
         (setq speedbar-shown-directories
               (cons (expand-file-name
-                     (concat (speedbar-line-path indent) token "/"))
+                     (concat (speedbar-line-directory indent) token "/"))
                     speedbar-shown-directories))
         (speedbar-change-expand-button-char ?-)
         (speedbar-reset-scanners)
@@ -2467,32 +3367,33 @@ expanded.  INDENT is the current indentation level."
           (end-of-line) (forward-char 1)
           (speedbar-with-writable
             (speedbar-default-directory-list
-             (concat (speedbar-line-path indent) token "/")
+             (concat (speedbar-line-directory indent) token "/")
              (1+ indent)))))
        ((string-match "-" text)        ;we have to contract this node
         (speedbar-reset-scanners)
         (let ((oldl speedbar-shown-directories)
               (newl nil)
               (td (expand-file-name
-                   (concat (speedbar-line-path indent) token))))
+                   (concat (speedbar-line-directory indent) token))))
           (while oldl
             (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
                 (setq newl (cons (car oldl) newl)))
             (setq oldl (cdr oldl)))
-          (setq speedbar-shown-directories newl))
+          (setq speedbar-shown-directories (nreverse newl)))
         (speedbar-change-expand-button-char ?+)
         (speedbar-delete-subblock indent)
         )
-       (t (error "Ooops... not sure what to do.")))
+       (t (error "Ooops...  not sure what to do")))
   (speedbar-center-buffer-smartly)
-  (setq speedbar-last-selected-file nil)
   (save-excursion (speedbar-stealthy-updates)))
 
 (defun speedbar-directory-buttons-follow (text token indent)
   "Speedbar click handler for default directory buttons.
 TEXT is the button clicked on.  TOKEN is the directory to follow.
 INDENT is the current indentation level and is unused."
-  (setq default-directory token)
+  (if (string-match "^[A-z]:$" token)
+      (setq default-directory (concat token "/"))
+    (setq default-directory token))
   ;; Because we leave speedbar as the current buffer,
   ;; update contents will change directory without
   ;; having to touch the attached frame.
@@ -2505,14 +3406,10 @@ The parameter TEXT and TOKEN are required, where TEXT is the button
 clicked, and TOKEN is the file to expand.  INDENT is the current
 indentation level."
   (cond ((string-match "+" text)       ;we have to expand this file
-        (let* ((fn (expand-file-name (concat (speedbar-line-path indent)
+        (let* ((fn (expand-file-name (concat (speedbar-line-directory indent)
                                              token)))
-               (lst (if speedbar-use-imenu-flag
-                       (let ((tim (speedbar-fetch-dynamic-imenu fn)))
-                         (if (eq tim t)
-                             (speedbar-fetch-dynamic-etags fn)
-                           tim))
-                     (speedbar-fetch-dynamic-etags fn))))
+               (mode nil)
+               (lst (speedbar-fetch-dynamic-tags fn)))
           ;; if no list, then remove expando button
           (if (not lst)
               (speedbar-change-expand-button-char ??)
@@ -2520,29 +3417,30 @@ indentation level."
             (speedbar-with-writable
               (save-excursion
                 (end-of-line) (forward-char 1)
-                (speedbar-insert-generic-list indent
-                                              lst 'speedbar-tag-expand
-                                              'speedbar-tag-find))))))
+                (funcall (car lst) indent (cdr lst)))))))
        ((string-match "-" text)        ;we have to contract this node
         (speedbar-change-expand-button-char ?+)
         (speedbar-delete-subblock indent))
-       (t (error "Ooops... not sure what to do.")))
+       (t (error "Ooops...  not sure what to do")))
   (speedbar-center-buffer-smartly))
 
 (defun speedbar-tag-find (text token indent)
-  "For the tag TEXT in a file TOKEN, goto that position.
+  "For the tag TEXT in a file TOKEN, go to that position.
 INDENT is the current indentation level."
-  (let ((file (speedbar-line-path indent)))
+  (let ((file (speedbar-line-directory indent)))
+    (let ((f (selected-frame)))
+      (dframe-select-attached-frame speedbar-frame)
+      (run-hooks 'speedbar-before-visiting-tag-hook)
+      (select-frame f))
     (speedbar-find-file-in-frame file)
     (save-excursion (speedbar-stealthy-updates))
     ;; Reset the timer with a new timeout when cliking a file
     ;; in case the user was navigating directories, we can cancel
     ;; that other timer.
-    (speedbar-set-timer speedbar-update-speed)
+    (speedbar-set-timer dframe-update-speed)
     (goto-char token)
     (run-hooks 'speedbar-visiting-tag-hook)
-    ;;(recenter)
-    (speedbar-maybee-jump-to-attached-frame)
+    (dframe-maybee-jump-to-attached-frame)
     ))
 
 (defun speedbar-tag-expand (text token indent)
@@ -2555,17 +3453,24 @@ level."
         (speedbar-with-writable
           (save-excursion
             (end-of-line) (forward-char 1)
-            (speedbar-insert-generic-list indent
-                                          token 'speedbar-tag-expand
+            (speedbar-insert-generic-list indent token 'speedbar-tag-expand
                                           'speedbar-tag-find))))
        ((string-match "-" text)        ;we have to contract this node
         (speedbar-change-expand-button-char ?+)
         (speedbar-delete-subblock indent))
-       (t (error "Ooops... not sure what to do.")))
+       (t (error "Ooops...  not sure what to do")))
   (speedbar-center-buffer-smartly))
 \f
 ;;; Loading files into the attached frame.
 ;;
+(defcustom speedbar-select-frame-method 'attached
+  "*Specify how to select a frame for displaying a file.
+A value of 'attached means to use the attached frame (the frame
+that speedbar was started from.)  A number such as 1 or -1 means to
+pass that number to `other-frame' while selecting a frame from speedbar."
+  :group 'speedbar
+  :type 'sexp)
+
 (defun speedbar-find-file-in-frame (file)
   "This will load FILE into the speedbar attached frame.
 If the file is being displayed in a different frame already, then raise that
@@ -2576,11 +3481,13 @@ frame instead."
        (progn
          (select-window bwin)
          (raise-frame (window-frame bwin)))
-      (if speedbar-power-click
+      (if dframe-power-click
          (let ((pop-up-frames t)) (select-window (display-buffer buff)))
-       (select-frame speedbar-attached-frame)
+       (if (numberp speedbar-select-frame-method)
+           (other-frame speedbar-select-frame-method)
+         (dframe-select-attached-frame speedbar-frame))
        (switch-to-buffer buff))))
 )
+ )
 
 ;;; Centering Utility
 ;;
@@ -2588,95 +3495,136 @@ frame instead."
   "Recenter a speedbar buffer so the current indentation level is all visible.
 This assumes that the cursor is on a file, or tag of a file which the user is
 interested in."
-  (if (<= (count-lines (point-min) (point-max))
-         (window-height (selected-window)))
-      ;; whole buffer fits
-      (let ((cp (point)))
-       (goto-char (point-min))
-       (recenter 0)
-       (goto-char cp))
-    ;; too big
-    (let (depth start end exp p)
-      (save-excursion
-       (beginning-of-line)
-       (setq depth (if (looking-at "[0-9]+")
-                       (string-to-int (buffer-substring-no-properties
-                                       (match-beginning 0) (match-end 0)))
-                     0))
-       (setq exp (format "^%d:\\s-*[[{<]\\([?+-]\\)[]>}]" depth)))
-      (save-excursion
-       (end-of-line)
-       (if (re-search-backward exp nil t)
-           (setq start (point))
-         (error "Center error"))
-       (save-excursion                 ;Not sure about this part.
-         (end-of-line)
-         (setq p (point))
-         (while (and (not (re-search-forward exp nil t))
-                     (>= depth 0))
-           (setq depth (1- depth))
-           (setq exp (format "^%d:\\s-*[[{<]\\([?+-]\\)[]>}]" depth)))
-         (if (/= (point) p)
-             (setq end (point))
-           (setq end (point-max)))))
-      ;; Now work out the details of centering
-      (let ((nl (count-lines start end))
-           (cp (point)))
-       (if (> nl (window-height (selected-window)))
-           ;; We can't fit it all, so just center on cursor
-           (progn (goto-char start)
-                  (recenter 1))
-         ;; we can fit everything on the screen, but...
-         (if (and (pos-visible-in-window-p start (selected-window))
-                  (pos-visible-in-window-p end (selected-window)))
-             ;; we are all set!
-             nil
-           ;; we need to do something...
-           (goto-char start)
-           (let ((newcent (/ (- (window-height (selected-window)) nl) 2))
-                 (lte (count-lines start (point-max))))
-             (if (and (< (+ newcent lte) (window-height (selected-window)))
-                      (> (- (window-height (selected-window)) lte 1)
-                         newcent))
-                 (setq newcent (- (window-height (selected-window))
-                                  lte 1)))
-             (recenter newcent))))
-       (goto-char cp)))))
 
+  (save-selected-window
+  
+    (select-window (get-buffer-window speedbar-buffer t))
+    
+    (set-buffer speedbar-buffer)
+    
+    (if (<= (count-lines (point-min) (point-max))
+           (1- (window-height (selected-window))))
+       ;; whole buffer fits
+       (let ((cp (point)))
+
+         (goto-char (point-min))
+         (recenter 0)
+         (goto-char cp))
+      ;; too big
+      (let (depth start end exp p)
+       (save-excursion
+         (beginning-of-line)
+         (setq depth (if (looking-at "[0-9]+")
+                         (string-to-number (buffer-substring-no-properties
+                                         (match-beginning 0) (match-end 0)))
+                       0))
+         (setq exp (format "^%d:" depth)))
+       (save-excursion
+         (end-of-line)
+         (if (re-search-backward exp nil t)
+             (setq start (point))
+           (setq start (point-min)))
+         (save-excursion               ;Not sure about this part.
+           (end-of-line)
+           (setq p (point))
+           (while (and (not (re-search-forward exp nil t))
+                       (>= depth 0))
+             (setq depth (1- depth))
+             (setq exp (format "^%d:" depth)))
+           (if (/= (point) p)
+               (setq end (point))
+             (setq end (point-max)))))
+       ;; Now work out the details of centering
+       (let ((nl (count-lines start end))
+              (wl (1- (window-height (selected-window))))
+             (cp (point)))
+         (if (> nl wl)
+             ;; We can't fit it all, so just center on cursor
+             (progn (goto-char start)
+                    (recenter 1))
+           ;; we can fit everything on the screen, but...
+           (if (and (pos-visible-in-window-p start (selected-window))
+                    (pos-visible-in-window-p end (selected-window)))
+               ;; we are all set!
+               nil
+             ;; we need to do something...
+             (goto-char start)
+             (let ((newcent (/ (- (window-height (selected-window)) nl) 2))
+                   (lte (count-lines start (point-max))))
+               (if (and (< (+ newcent lte) (window-height (selected-window)))
+                        (> (- (window-height (selected-window)) lte 1)
+                           newcent))
+                   (setq newcent (- (window-height (selected-window))
+                                    lte 1)))
+               (recenter newcent))))
+          (goto-char cp))))))
 \f
+;;; Tag Management -- List of expanders:
+;;
+(defun speedbar-fetch-dynamic-tags (file)
+  "Return a list of tags generated dynamically from FILE.
+This uses the entries in `speedbar-dynamic-tags-function-list'
+to find the proper tags.  It is up to each of those individual
+functions to do caching and flushing if appropriate."
+  (save-excursion
+    ;; If a file is in memory, switch to that buffer.  This allows
+    ;; us to use the local variable.  If the file is on disk, we
+    ;; can try a few of the defaults that can get tags without
+    ;; opening the file.
+    (if (get-file-buffer file)
+       (set-buffer (get-file-buffer file)))
+    ;; If there is a buffer-local value of
+    ;; speedbar-dynamic-tags-function-list, it will now be available.
+    (let ((dtf speedbar-dynamic-tags-function-list)
+         (ret t))
+      (while (and (eq ret t) dtf)
+       (setq ret
+             (if (fboundp (car (car dtf)))
+                 (funcall (car (car dtf)) file)
+               t))
+       (if (eq ret t)
+           (setq dtf (cdr dtf))))
+      (if (eq ret t)
+         ;; No valid tag list, return nil
+         nil
+       ;; We have some tags.  Return the list with the insert fn
+       ;; prepended
+       (cons (cdr (car dtf)) ret)))))
+
 ;;; Tag Management -- Imenu
 ;;
 (if (not speedbar-use-imenu-flag)
 
     nil
 
-(eval-when-compile (if (locate-library "imenu") (require 'imenu)))
+(eval-when-compile (condition-case nil (require 'imenu) (error nil)))
 
 (defun speedbar-fetch-dynamic-imenu (file)
   "Load FILE into a buffer, and generate tags using Imenu.
 Returns the tag list, or t for an error."
   ;; Load this AND compile it in
   (require 'imenu)
-  (save-excursion
-    (set-buffer (find-file-noselect file))
-    (if speedbar-power-click (setq imenu--index-alist nil))
-    (condition-case nil
-       (let ((index-alist (imenu--make-index-alist t)))
-         (if speedbar-sort-tags
-             (sort (copy-alist index-alist)
-                   (lambda (a b) (string< (car a) (car b))))
-           index-alist))
-      (error t))))
+  (set-buffer (find-file-noselect file))
+  (if dframe-power-click (setq imenu--index-alist nil))
+  (condition-case nil
+      (let ((index-alist (imenu--make-index-alist t)))
+       (if speedbar-sort-tags
+           (sort (copy-alist index-alist)
+                 (lambda (a b) (string< (car a) (car b))))
+         index-alist))
+    (error t)))
 )
 \f
 ;;; Tag Management -- etags  (old XEmacs compatibility part)
 ;;
 (defvar speedbar-fetch-etags-parse-list
   '(;; Note that java has the same parse-group as c
-    ("\\.\\([cChH]\\|c\\+\\+\\|cpp\\|cc\\|hh\\|java\\)\\'" .
+    ("\\.\\([cChH]\\|c\\+\\+\\|cpp\\|cc\\|hh\\|java\\|cxx\\|hxx\\)\\'" .
      speedbar-parse-c-or-c++tag)
     ("^\\.emacs$\\|.\\(el\\|l\\|lsp\\)\\'" .
      "def[^i]+\\s-+\\(\\(\\w\\|[-_]\\)+\\)\\s-*\C-?")
+;    ("\\.\\([fF]\\|for\\|FOR\\|77\\|90\\)\\'" .
+;      speedbar-parse-fortran77-tag)
     ("\\.tex\\'" . speedbar-parse-tex-string)
     ("\\.p\\'" .
      "\\(\\(FUNCTION\\|function\\|PROCEDURE\\|procedure\\)\\s-+\\([a-zA-Z0-9_.:]+\\)\\)\\s-*(?^?")
@@ -2693,14 +3641,14 @@ This variable is ignored if `speedbar-use-imenu-flag' is non-nil.")
 (defvar speedbar-fetch-etags-command "etags"
   "*Command used to create an etags file.
 
-This variable is ignored if `speedbar-use-imenu-flag' is t")
+This variable is ignored if `speedbar-use-imenu-flag' is t.")
 
 (defvar speedbar-fetch-etags-arguments '("-D" "-I" "-o" "-")
   "*List of arguments to use with `speedbar-fetch-etags-command'.
 This creates an etags output buffer.  Use `speedbar-toggle-etags' to
 modify this list conveniently.
 
-This variable is ignored if `speedbar-use-imenu-flag' is t")
+This variable is ignored if `speedbar-use-imenu-flag' is t.")
 
 (defun speedbar-toggle-etags (flag)
   "Toggle FLAG in `speedbar-fetch-etags-arguments'.
@@ -2710,7 +3658,7 @@ value is \"show\" then toggle the value of
 `speedbar-show-unknown-files'.
 
   This function is a convenience function for XEmacs menu created by
-Farzin Guilak <farzin@protocol.com>"
+Farzin Guilak <farzin@protocol.com>."
   (interactive)
   (cond
    ((equal flag "sort")
@@ -2734,13 +3682,15 @@ Each symbol will be associated with its line position in FILE."
        (save-excursion
          (if (get-buffer "*etags tmp*")
              (kill-buffer "*etags tmp*"))      ;kill to clean it up
-         (if (<= 1 speedbar-verbosity-level) (message "Fetching etags..."))
+         (if (<= 1 speedbar-verbosity-level)
+             (speedbar-message "Fetching etags..."))
          (set-buffer (get-buffer-create "*etags tmp*"))
          (apply 'call-process speedbar-fetch-etags-command nil
                 (current-buffer) nil
                 (append speedbar-fetch-etags-arguments (list file)))
          (goto-char (point-min))
-         (if (<= 1 speedbar-verbosity-level) (message "Fetching etags..."))
+         (if (<= 1 speedbar-verbosity-level)
+             (speedbar-message "Fetching etags..."))
          (let ((expr
                 (let ((exprlst speedbar-fetch-etags-parse-list)
                       (ans nil))
@@ -2751,12 +3701,14 @@ Each symbol will be associated with its line position in FILE."
                   (cdr ans))))
            (if expr
                (let (tnl)
+                 (set-buffer (get-buffer-create "*etags tmp*"))
                  (while (not (save-excursion (end-of-line) (eobp)))
                    (save-excursion
                      (setq tnl (speedbar-extract-one-symbol expr)))
                    (if tnl (setq newlist (cons tnl newlist)))
                    (forward-line 1)))
-             (message "Sorry, no support for a file of that extension"))))
+             (speedbar-message
+              "Sorry, no support for a file of that extension"))))
       )
     (if speedbar-sort-tags
        (sort newlist (lambda (a b) (string< (car a) (car b))))
@@ -2780,9 +3732,9 @@ Each symbol will be associated with its line position in FILE."
 ;      (delete-region (match-beginning 1) (match-end 1)))))
 
 (defun speedbar-extract-one-symbol (expr)
-  "At point, return nil, or one alist in the form: ( symbol . position )
+  "At point, return nil, or one alist in the form: (SYMBOL .  POSITION)
 The line should contain output from etags.  Parse the output using the
-regular expression EXPR"
+regular expression EXPR."
   (let* ((sym (if (stringp expr)
                  (if (save-excursion
                        (re-search-forward expr (save-excursion
@@ -2797,7 +3749,7 @@ regular expression EXPR"
                                            (point))
                                          t)))
                (if (and j sym)
-                   (1+ (string-to-int (buffer-substring-no-properties
+                   (1+ (string-to-number (buffer-substring-no-properties
                                        (match-beginning 2)
                                        (match-end 2))))
                  0))))
@@ -2806,7 +3758,7 @@ regular expression EXPR"
       nil)))
 
 (defun speedbar-parse-c-or-c++tag ()
-  "Parse a c or c++ tag, which tends to be a little complex."
+  "Parse a C or C++ tag, which tends to be a little complex."
   (save-excursion
     (let ((bound (save-excursion (end-of-line) (point))))
       (cond ((re-search-forward "\C-?\\([^\C-a]+\\)\C-a" bound t)
@@ -2831,7 +3783,231 @@ regular expression EXPR"
            (t nil)))))
 
 \f
-;;; Color loading section  This is messy *Blech!*
+;;; BUFFER DISPLAY mode.
+;;
+(defvar speedbar-buffers-key-map nil
+  "Keymap used when in the buffers display mode.")
+
+(if speedbar-buffers-key-map
+    nil
+  (setq speedbar-buffers-key-map (speedbar-make-specialized-keymap))
+
+  ;; Basic tree features
+  (define-key speedbar-buffers-key-map "e" 'speedbar-edit-line)
+  (define-key speedbar-buffers-key-map "\C-m" 'speedbar-edit-line)
+  (define-key speedbar-buffers-key-map "+" 'speedbar-expand-line)
+  (define-key speedbar-buffers-key-map "=" 'speedbar-expand-line)
+  (define-key speedbar-buffers-key-map "-" 'speedbar-contract-line)
+  (define-key speedbar-buffers-key-map " " 'speedbar-toggle-line-expansion)
+
+  ;; Buffer specific keybindings
+  (define-key speedbar-buffers-key-map "k" 'speedbar-buffer-kill-buffer)
+  (define-key speedbar-buffers-key-map "r" 'speedbar-buffer-revert-buffer)
+
+  )
+
+(defvar speedbar-buffer-easymenu-definition
+  '(["Jump to buffer" speedbar-edit-line t]
+    ["Expand File Tags" speedbar-expand-line
+     (save-excursion (beginning-of-line)
+                    (looking-at "[0-9]+: *.\\+. "))]
+    ["Flush Cache & Expand" speedbar-flush-expand-line
+     (save-excursion (beginning-of-line)
+                    (looking-at "[0-9]+: *.\\+. "))]
+    ["Contract File Tags" speedbar-contract-line
+     (save-excursion (beginning-of-line)
+                    (looking-at "[0-9]+: *.-. "))]
+    "----"
+    ["Kill Buffer" speedbar-buffer-kill-buffer
+     (save-excursion (beginning-of-line)
+                    (looking-at "[0-9]+: *.[-+?]. "))]
+    ["Revert Buffer" speedbar-buffer-revert-buffer
+     (save-excursion (beginning-of-line)
+                    (looking-at "[0-9]+: *.[-+?]. "))]
+    )
+  "Menu item elements shown when displaying a buffer list.")
+
+(defun speedbar-buffer-buttons (directory zero)
+  "Create speedbar buttons based on the buffers currently loaded.
+DIRECTORY is the directory to the currently active buffer, and ZERO is 0."
+  (speedbar-buffer-buttons-engine nil))
+
+(defun speedbar-buffer-buttons-temp (directory zero)
+  "Create speedbar buttons based on the buffers currently loaded.
+DIRECTORY is the directory to the currently active buffer, and ZERO is 0."
+  (speedbar-buffer-buttons-engine t))
+
+(defun speedbar-buffer-buttons-engine (temp)
+  "Create speedbar buffer buttons.
+If TEMP is non-nil, then clicking on a buffer restores the previous display."
+  (speedbar-insert-separator "Active Buffers:")
+  (let ((bl (buffer-list))
+       (case-fold-search t))
+    (while bl
+      (if (string-match "^[ *]" (buffer-name (car bl)))
+         nil
+       (let* ((known (string-match speedbar-file-regexp
+                                   (buffer-name (car bl))))
+              (expchar (if known ?+ ??))
+              (fn (if known 'speedbar-tag-file nil))
+              (fname (save-excursion (set-buffer (car bl))
+                                     (buffer-file-name))))
+         (speedbar-make-tag-line 'bracket expchar fn
+                                 (if fname (file-name-nondirectory fname))
+                                 (buffer-name (car bl))
+                                 'speedbar-buffer-click temp
+                                 'speedbar-file-face 0)
+         (speedbar-buffers-tail-notes (car bl))))
+      (setq bl (cdr bl)))
+    (setq bl (buffer-list))
+    (speedbar-insert-separator "Scratch Buffers:")
+    (while bl
+      (if (not (string-match "^\\*" (buffer-name (car bl))))
+         nil
+       (if (eq (car bl) speedbar-buffer)
+           nil
+         (speedbar-make-tag-line 'bracket ?? nil nil
+                                 (buffer-name (car bl))
+                                 'speedbar-buffer-click temp
+                                 'speedbar-file-face 0)
+         (speedbar-buffers-tail-notes (car bl))))
+      (setq bl (cdr bl)))
+    (setq bl (buffer-list))
+    ;;(speedbar-insert-separator "Hidden Buffers:")
+    ;;(while bl
+    ;;  (if (not (string-match "^ " (buffer-name (car bl))))
+    ;;   nil
+    ;; (if (eq (car bl) speedbar-buffer)
+    ;;     nil
+    ;;   (speedbar-make-tag-line 'bracket ?? nil nil
+    ;;                           (buffer-name (car bl))
+    ;;                           'speedbar-buffer-click temp
+    ;;                           'speedbar-file-face 0)
+    ;;   (speedbar-buffers-tail-notes (car bl))))
+    ;;  (setq bl (cdr bl)))
+    ))
+
+(defun speedbar-buffers-tail-notes (buffer)
+  "Add a note to the end of the last tag line.
+Argument BUFFER is the buffer being tested."
+  (let (mod ro)
+    (save-excursion
+      (set-buffer buffer)
+      (setq mod (buffer-modified-p)
+           ro buffer-read-only))
+    (if ro (speedbar-insert-button "%" nil nil nil nil t))))
+
+(defun speedbar-buffers-item-info ()
+  "Display information about the current buffer on the current line."
+  (or (speedbar-item-info-tag-helper)
+      (let* ((item (speedbar-line-text))
+            (buffer (if item (get-buffer item) nil)))
+       (and buffer
+            (speedbar-message "%s%s %S %d %s"
+                              (if (buffer-modified-p buffer) "* " "")
+                              item
+                              (save-excursion (set-buffer buffer) major-mode)
+                              (save-excursion (set-buffer buffer)
+                                              (buffer-size))
+                              (or (buffer-file-name buffer) "<No file>"))))))
+
+(defun speedbar-buffers-line-directory (&optional depth)
+  "Fetch the full directory to the file (buffer) specified on the current line.
+Optional argument DEPTH specifies the current depth of the back search."
+  (save-excursion
+    (end-of-line)
+    (let ((start (point)))
+      ;; Buffers are always at level 0
+      (if (not (re-search-backward "^0:" nil t))
+         nil
+       (let* ((bn (speedbar-line-text))
+              (buffer (if bn (get-buffer bn))))
+         (if buffer
+             (if (save-excursion
+                   (end-of-line)
+                   (eq start (point)))
+                 (or (save-excursion (set-buffer buffer)
+                                     default-directory)
+                     "")
+               (buffer-file-name buffer))))))))
+
+(defun speedbar-buffer-click (text token indent)
+  "When the users clicks on a buffer-button in speedbar.
+TEXT is the buffer's name, TOKEN and INDENT are unused."
+  (if dframe-power-click
+      (let ((pop-up-frames t)) (select-window (display-buffer text)))
+    (dframe-select-attached-frame speedbar-frame)
+    (switch-to-buffer text)
+    (if token (speedbar-change-initial-expansion-list
+              speedbar-previously-used-expansion-list-name))))
+
+(defun speedbar-buffer-kill-buffer ()
+  "Kill the buffer the cursor is on in the speedbar buffer."
+  (interactive)
+  (or (save-excursion
+       (let ((text (speedbar-line-text)))
+         (if (and (get-buffer text)
+                  (speedbar-y-or-n-p (format "Kill buffer %s? " text)))
+             (kill-buffer text))
+         (speedbar-refresh)))))
+
+(defun speedbar-buffer-revert-buffer ()
+  "Revert the buffer the cursor is on in the speedbar buffer."
+  (interactive)
+  (save-excursion
+    (beginning-of-line)
+    ;; If this fails, then it is a non-standard click, and as such,
+    ;; perfectly allowed
+    (if (re-search-forward "[]>?}] [^ ]"
+                          (save-excursion (end-of-line) (point))
+                          t)
+       (let ((text (progn
+                     (forward-char -1)
+                     (buffer-substring (point) (save-excursion
+                                                 (end-of-line)
+                                                 (point))))))
+         (if (get-buffer text)
+             (progn
+               (set-buffer text)
+               (revert-buffer t)))))))
+
+\f
+;;; Useful hook values and such.
+;;
+(defvar speedbar-highlight-one-tag-line nil
+  "Overlay used for highlighting the most recently jumped to tag line.")
+
+(defun speedbar-highlight-one-tag-line ()
+  "Highlight the current line, unhighlighting a previously jumped to line."
+  (speedbar-unhighlight-one-tag-line)
+  (setq speedbar-highlight-one-tag-line
+       (speedbar-make-overlay (save-excursion (beginning-of-line) (point))
+                              (save-excursion (end-of-line)
+                                              (forward-char 1)
+                                              (point))))
+  (speedbar-overlay-put speedbar-highlight-one-tag-line 'face
+                       'speedbar-highlight-face)
+  (add-hook 'pre-command-hook 'speedbar-unhighlight-one-tag-line)
+  )
+
+(defun speedbar-unhighlight-one-tag-line ()
+  "Unhighlight the currently highlighted line."
+  (if speedbar-highlight-one-tag-line
+      (progn
+       (speedbar-delete-overlay speedbar-highlight-one-tag-line)
+       (setq speedbar-highlight-one-tag-line nil)))
+  (remove-hook 'pre-command-hook 'speedbar-unhighlight-one-tag-line))
+
+(defun speedbar-recenter-to-top ()
+  "Recenter the current buffer so POINT is on the top of the window."
+  (recenter 1))
+
+(defun speedbar-recenter ()
+  "Recenter the current buffer so POINT is in the center of the window."
+  (recenter (/ (window-height (selected-window)) 2)))
+
+\f
+;;; Color loading section.
 ;;
 (defface speedbar-button-face '((((class color) (background light))
                                 (:foreground "green4"))
@@ -2852,7 +4028,7 @@ regular expression EXPR"
                                    (:foreground "blue4"))
                                   (((class color) (background dark))
                                    (:foreground "light blue")))
-  "Faced used for directory names."
+  "Face used for directory names."
   :group 'speedbar-faces)
 (defface speedbar-tag-face '((((class color) (background light))
                              (:foreground "brown"))
@@ -2882,13 +4058,67 @@ regular expression EXPR"
   "Face used for highlighting buttons with the mouse."
   :group 'speedbar-faces)
 
+(defface speedbar-separator-face '((((class color) (background light))
+                                   (:background "blue"
+                                    :foreground "white"
+                                    :overline "gray"))
+                                  (((class color) (background dark))
+                                   (:background "blue"
+                                    :foreground "white"
+                                    :overline "gray"))
+                                  (((class grayscale monochrome)
+                                    (background light))
+                                   (:background "black"
+                                    :foreground "white"
+                                    :overline "white"))
+                                  (((class grayscale monochrome)
+                                    (background dark))
+                                   (:background "white"
+                                    :foreground "black"
+                                    :overline "black")))
+  "Face used for separator labes in a display."
+  :group 'speedbar-faces)
+
 ;; some edebug hooks
 (add-hook 'edebug-setup-hook
          (lambda ()
            (def-edebug-spec speedbar-with-writable def-body)))
 
+;; Fix a font lock problem for some versions of Emacs
+(if (boundp 'font-lock-global-modes)
+    (if (listp font-lock-global-modes)
+       (add-to-list 'font-lock-global-modes '(not speedbar-mode))
+      )
+  )
+
+\f
+;;; Obsolete variables and functions
+
+(define-obsolete-variable-alias
+  'speedbar-ignored-path-regexp 'speedbar-ignored-directory-regexp)
+
+(define-obsolete-variable-alias 'speedbar-ignored-path-expressions
+  'speedbar-ignored-directory-expressions)
+
+(define-obsolete-function-alias 'speedbar-add-ignored-path-regexp
+  'speedbar-add-ignored-directory-regexp)
+
+(define-obsolete-function-alias 'speedbar-line-path
+  'speedbar-line-directory)
+
+(define-obsolete-function-alias 'speedbar-buffers-line-path
+  'speedbar-buffers-line-directory)
+
+(define-obsolete-function-alias 'speedbar-path-line
+  'speedbar-directory-line)
+
+(define-obsolete-function-alias 'speedbar-buffers-line-path
+  'speedbar-buffers-line-directory)
+
 (provide 'speedbar)
-;;; speedbar ends here
 
 ;; run load-time hooks
 (run-hooks 'speedbar-load-hook)
+
+;; arch-tag: 4477e6d1-f78c-48b9-a503-387d3c9767d5
+;;; speedbar ends here