Anonymous avatar Anonymous committed e941329

Imported Speedbar 0.13

Comments (0)

Files changed (14)

+2000-10-19  Steve Youngs  <youngs@xemacs.org>
+
+	* Import Speedbar 0.13.
+
 2000-10-05  Martin Buchholz  <martin@xemacs.org>
 
 	* *: Mega typo fix.
 # Boston, MA 02111-1307, USA.
 
 VERSION = 1.16
-AUTHOR_VERSION =  0.11.1
-MAINTAINER = XEmacs Development Team <xemacs-beta@xemacs.org>
+AUTHOR_VERSION =  0.13
+MAINTAINER = Eric M. Ludlam <zappo@gnu.org>
 PACKAGE = speedbar
 PKG_TYPE = regular
 REQUIRES = xemacs-base
 CATEGORY = oa
 
-ELCS = sb-gud.elc sb-info.elc sb-rmail.elc sb-w3.elc \
-	speedbar.elc speedbspec.elc \
-	rpm.elc
+ELCS = bigclock.elc dframe.elc rpm.elc sb-gud.elc sb-image.elc sb-info.elc \
+	sb-rmail.elc sb-texinfo.elc sb-w3.elc speedbar.elc
 
 DATA_FILES = $(wildcard *.xpm)
 
 TEXI_FILES = speedbar.texi
 MANUAL = speedbar
 
+PRELOADS = -eval "(setq load-path \
+			(nconc load-path \
+                           '((expand-file-name \"./\"))))"
+
 include ../../XEmacs.rules
 
 GENERATED += custom-load.elc

Makefile.upstream

 
 ede_FILES=Project.ede Makefile
 
-opt_LISP=rpm.el sb-gud.el sb-info.el sb-rmail.el sb-w3.el
-EMACS=emacs!
-images_MISC=sb-dir-plus.xpm sb-dir-minus.xpm sb-dir.xpm sb-pg-plus.xpm sb-pg-minus.xpm sb-pg.xpm sb-mail.xpm sb-tag-plus.xpm sb-tag-minus.xpm sb-tag.xpm sb-tag-gt.xpm sb-tag-v.xpm
-info_INFOS=speedbar.texi
-speedbar_LISP=speedbar.el
+speedbar_LISP=dframe.el speedbar.el
 EMACS=emacs
-VERSION=0.11.1
+info_TEXINFOS=speedbar.texi
+MAKEINFO=makeinfo
+opt_LISP=rpm.el sb-gud.el sb-info.el sb-rmail.el sb-w3.el sb-texinfo.el bigclock.el
+aux_AUX=INSTALL
+images_MISC=sb-dir-plus.xpm sb-dir-minus.xpm sb-dir.xpm sb-pg-plus.xpm sb-pg-minus.xpm sb-pg.xpm sb-mail.xpm sb-tag-plus.xpm sb-tag-minus.xpm sb-tag.xpm sb-tag-gt.xpm sb-tag-v.xpm sb-tag-type.xpm sb-image.el
+VERSION=0.13a
 DISTDIR=speedbar-$(VERSION)
 top_builddir = 
 
 DEP_FILES=.deps/.P
 
-all: info speedbar
+all: speedbar speedbar.info
 
 DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
 -include $(DEP_FILES)
 
-%.o: %.c
-	@echo '$(COMPILE) -c $<'; \
-	$(COMPILE) -Wp,-MD,.deps/$(*F).P -c $<
+speedbar: $(speedbar_LISP)
+	@echo "(add-to-list 'load-path nil)" > $@-compile-script
+	@for loadpath in ${LOADPATH}; do \
+	   echo "(add-to-list 'load-path \"$$loadpath\")" >> $@-compile-script; \
+	 done
+	@echo "(setq debug-on-error t)" >> $@-compile-script
+	$(EMACS) -batch -l $@-compile-script -f batch-byte-compile $^
 
-opt:
-	@echo "(add-to-list 'load-path \"$(PWD)\")" > opt-compile-script
-	@echo "(setq debug-on-error t)" >> opt-compile-script
-	$(EMACS) -batch -l opt-compile-script -f batch-byte-compile  $(opt_LISP)
+speedbar.info: $(info_TEXINFOS)
+	makeinfo -o $@ $<
+
+opt: $(opt_LISP)
+	@echo "(add-to-list 'load-path nil)" > $@-compile-script
+	@for loadpath in ${LOADPATH}; do \
+	   echo "(add-to-list 'load-path \"$$loadpath\")" >> $@-compile-script; \
+	 done
+	@echo "(setq debug-on-error t)" >> $@-compile-script
+	$(EMACS) -batch -l $@-compile-script -f batch-byte-compile $^
+
 images: 
 	@
 
+tags: $(speedbar_LISP) $(info_TEXINFOS) $(opt_LISP) $(images_MISC) 
+	etags $^
 
-info: $(info_INFOS)
-	makeinfo speedbar.texi
-speedbar:
-	@echo "(add-to-list 'load-path \"$(PWD)\")" > speedbar-compile-script
-	@echo "(setq debug-on-error t)" >> speedbar-compile-script
-	$(EMACS) -batch -l speedbar-compile-script -f batch-byte-compile  $(speedbar_LISP)
 
 clean:
 	rm -f *.elc *.info
 dist:
 	rm -rf $(DISTDIR)
 	mkdir $(DISTDIR)
-	cp $(opt_LISP) $(images_MISC) $(info_INFOS) $(speedbar_LISP) $(ede_FILES) $(DISTDIR)
+	cp $(speedbar_LISP) $(info_TEXINFOS) $(opt_LISP) $(aux_AUX) $(images_MISC) $(ede_FILES) $(DISTDIR)
 	tar -cvzf $(DISTDIR).tar.gz $(DISTDIR)
 	rm -rf $(DISTDIR)
 
-tags: $(opt_LISP) $(images_MISC) $(info_INFOS) $(speedbar_LISP) 
-	etags $^
-
 Makefile: Project.ede
 	@echo Makefile is out of date!  It needs to be regenerated by EDE.
 	@false
 ;; EDE project file.
 (ede-proj-project "ede-proj-project"
   :name "speedbar"
-  :version "0.11.1"
+  :version "0.13a"
   :file "Project.ede"
-  :targets (list   (ede-proj-target-elisp "opt"
-    :name "opt"
+  :targets (list   (ede-proj-target-elisp "speedbar"
+    :name "speedbar"
     :path ""
-    :source '("rpm.el" "sb-gud.el" "sb-info.el" "sb-rmail.el" "sb-w3.el")
-    :partofall 'nil
-    )
-   (ede-proj-target-makefile-miscelaneous "images"
-    :name "images"
-    :path ""
-    :source '("sb-dir-plus.xpm" "sb-dir-minus.xpm" "sb-dir.xpm" "sb-pg-plus.xpm" "sb-pg-minus.xpm" "sb-pg.xpm" "sb-mail.xpm" "sb-tag-plus.xpm" "sb-tag-minus.xpm" "sb-tag.xpm" "sb-tag-gt.xpm" "sb-tag-v.xpm")
-    :partofall 'nil
+    :source '("dframe.el" "speedbar.el")
     )
    (ede-proj-target-makefile-info "info"
     :name "info"
     :path ""
     :source '("speedbar.texi")
     )
-   (ede-proj-target-elisp "speedbar"
-    :name "speedbar"
+   (ede-proj-target-elisp "opt"
+    :name "opt"
     :path ""
-    :source '("speedbar.el")
+    :source '("rpm.el" "sb-gud.el" "sb-info.el" "sb-rmail.el" "sb-w3.el" "sb-texinfo.el" "bigclock.el")
+    :partofall 'nil
+    )
+   (ede-proj-target-aux "aux"
+    :name "aux"
+    :path ""
+    :source '("INSTALL")
+    )
+   (ede-proj-target-makefile-miscelaneous "images"
+    :name "images"
+    :path ""
+    :source '("sb-dir-plus.xpm" "sb-dir-minus.xpm" "sb-dir.xpm" "sb-pg-plus.xpm" "sb-pg-minus.xpm" "sb-pg.xpm" "sb-mail.xpm" "sb-tag-plus.xpm" "sb-tag-minus.xpm" "sb-tag.xpm" "sb-tag-gt.xpm" "sb-tag-v.xpm" "sb-tag-type.xpm" "sb-image.el")
+    :partofall 'nil
     )
    )
   :configuration-variables 'nil
+;;; bigclock --- A great big clock
+
+;;; Copyright (C) 2000 Free Software Foundation
+
+;; Author: Eric M. Ludlam <zappo@gnu.org>
+;; Keywords: amusement
+;; X-RCS: $Id$
+
+;; 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.
+
+;;; Commentary:
+;;
+;; Display a big clock in a special frame.
+
+(require 'dframe)
+
+;;; Code:
+(defgroup bigclock nil
+  "Faces used in dframe."
+  :prefix "bigclock-"
+  :group 'bigclock)
+
+(defcustom bigclock-frame-parameters
+  '((minibuffer . nil)
+    (width . 9)
+    (height . 2)
+    (border-width . 0)
+    (menu-bar-lines . 0)
+    (unsplittable . t)
+    (font . "-*-courier-medium-r-normal-*-*-320-*-*-m-*-iso8859-1"))
+  "Frame parameters for the big clock."
+  :group 'bigclock
+  :type '(repeat (sexp :tag "Parameter:")))
+
+(defcustom bigclock-update-flag dframe-have-timer-flag
+  "Non-nil means the clock will be able to update."
+  :group 'bigclock
+  :type 'boolean)
+
+(defvar bigclock-key-map
+  (let ((km (make-sparse-keymap)))
+    (dframe-update-keymap km)
+    km)
+  "Keymap used in the big clock.")
+  
+(defvar bigclock-buffer nil
+  "Bigclocks buffer.")
+
+(defvar bigclock-frame nil
+  "Bigclock's frame.")
+
+(defvar bigclock-cached-frame nil
+  "Bigclock's cached frame.")
+
+(defcustom bigclock-before-delete-hook nil
+  "Hooks called before bigclock is deleted."
+  :group 'bigclock
+  :type 'hook)
+
+(defcustom bigclock-before-popup-hook nil
+  "Hooks called before poping up the bigclock frame."
+  :group 'bigclock
+  :type 'hook)
+
+(defcustom bigclock-after-create-hook nil
+  "Hooks called after creating the bigclock frame."
+  :group 'bigclock
+  :type 'hook)
+
+(defcustom bigclock-mode-hook nil
+  "Hook run when a bigclock buffer is created."
+  :group 'bigclock
+  :type 'hook)
+
+(defalias 'bigclock 'bigclock-frame-mode)
+(defun bigclock-frame-mode (&optional arg)
+  "Enable or disable bigclock.
+Optional argument ARG enables or disables the bigclock frame."
+  (interactive "P")
+  ;; Get the buffer to play with
+  (if (not (buffer-live-p bigclock-buffer))
+      (save-excursion
+	(setq bigclock-buffer (get-buffer-create " BIGCLOCK"))
+	(set-buffer bigclock-buffer)
+	(bigclock-mode)))
+  ;; Do the frame thing
+  (dframe-frame-mode arg
+		     'bigclock-frame
+		     'bigclock-cached-frame
+		     'bigclock-buffer
+		     "Bigclock"
+		     #'bigclock-frame-mode
+		     (if dframe-xemacsp
+			 bigclock-frame-plist
+		       bigclock-frame-parameters)
+		     bigclock-before-delete-hook
+		     bigclock-before-popup-hook
+		     bigclock-after-create-hook)
+  ;; Start up the timer
+  (if (not bigclock-frame)
+      (dframe-set-timer nil #'bigclock-timer-fn 'bigclock-update-flag)
+    (dframe-set-timer 60 #'bigclock-timer-fn 'bigclock-update-flag)
+    ))
+
+(defun bigclock-get-focus ()
+  "Change frame focus to or from the bigclock frame.
+If the selected frame is not bigclock, then bigclock frame is
+selected.  If the bigclock frame is active, then select the attached frame."
+  (interactive)
+  (dframe-get-focus 'bigclock-frame 'bigclock-frame-mode))
+
+(defun bigclock-mode ()
+  "Set the current buffer to be in BIGCLOCK mode.
+\\{bigclock-key-map}"
+  ;; NOT interactive
+  (save-excursion
+    (kill-all-local-variables)
+    (setq major-mode 'bigclock-mode)
+    (setq mode-name "BigClock")
+    (setq font-lock-keywords nil) ;; no font-locking please
+    (setq truncate-lines t)
+    (use-local-map bigclock-key-map)
+    (make-local-variable 'frame-title-format)
+    (setq frame-title-format "Bigclock "))
+    (toggle-read-only 1)
+    (setq mode-line-format "")
+    ;; Add in our dframe hooks.
+    (setq dframe-track-mouse-function nil
+	  dframe-help-echo-function nil
+	  dframe-mouse-click-function nil
+	  dframe-mouse-position-function nil)
+    ;;no auto-show for Emacs
+    (run-hooks 'bigclock-mode-hook))
+
+(defun bigclock-timer-fn ()
+  "Run whenever Emacs is idle to update bigclock."
+  (if (or (not bigclock-frame)
+	  (not (frame-live-p bigclock-frame)))
+      (dframe-set-timer nil 'bigclock-timer-fn 'bigclock-update-flag)
+    (save-excursion
+      (set-buffer bigclock-buffer)
+      (toggle-read-only -1)
+      (erase-buffer)
+      (insert (format-time-string "%2I:%M %p" (current-time))))))
+
+
+(provide 'bigclock)
+
+;;; bigclock.el ends here
+;;; dframe --- dedicate frame support modes
+
+;;; Copyright (C) 1996, 97, 98, 99, 00 Free Software Foundation
+
+;; Author: Eric M. Ludlam <zappo@gnu.org>
+;; Keywords: file, tags, tools
+;; X-RCS: $Id$
+
+(defvar dframe-version "1.0beta"
+  "The current version of the dedicated frame library.")
+
+;; 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.
+
+;;; Commentary:
+;;
+;; This code was developed and maintained as a part of speedbar since 1996.
+;; It became its own support utility in Aug 2000.
+;;
+;; Dedicated frame mode is an Emacs independent library for supporting
+;; a program/buffer combination that resides in a dedicated frame.
+;; Support of this nature requires several complex interactions with the
+;; user which this library will provide, including:
+;;
+;; * Creation of a frame.  Positioned relatively.
+;;   Includes a frame cache for User position caching.
+;; * Switching between frames.
+;; * Timed activities using idle-timers
+;; * Frame/buffer killing hooks
+;; * Mouse-3 position relative menu
+;; * Mouse motion, help-echo hacks
+;; * Mouse clicking, double clicking, & Xemacs image clicking hack
+;; * Mode line hacking
+;; * Utilities for use in a program covering:
+;;    o keymap massage for some actions
+;;    o working with an associated buffer
+;;    o shift-click
+;;    o detaching a frame
+;;    o focus-shifting & optional frame jumping
+;;    o currently active frame.
+;;    o message/y-or-n-p
+;;    o mouse set point
+;;
+;; To Use:
+;; 1) (require 'dframe)
+;; 2) Variable Setup:
+;;   -frame-parameters -- Frame parameters for Emacs.
+;;   -frame-plist -- Frame parameters for XEmacs.
+;;   -- Not on parameter lists: They can optionally include width
+;;      and height.  If width or height is not included, then it will
+;;      be provided to match the originating frame.  In general,
+;;      turning off the menu bar, mode line, and minibuffer can
+;;      provide a smaller window, or more display area.
+;;   -track-mouse-flag -- mouse tracking on/off specific to your tool.
+;;   -update-flag -- app toggle for timer use.  Init from
+;;     `dframe-have-timer-flag'.  This is nil for terminals, since
+;;     updating a frame in a terminal is not useful to the user.
+;;   -key-map -- Your keymap.  Call `dframe-update-keymap' on it.
+;;   -buffer, -frame, -cached-frame -- Variables used to track your
+;;     applications buffer, frame, or frame cache (when hidden).  See
+;;     `dframe-frame-mode' for details.
+;;   -before-delete-hook, -before-popup-hook, -after-create-hook --
+;;     Hooks to have called.  The `-after-create-hook' probably wants
+;;     to call a function which calls `dframe-reposition-frame' in an
+;;     appropriate manner.
+;; 3) Function Setup:
+;;   your-frame-mode -- function to toggle your app frame on and off.
+;;     its tasks are:
+;;       a) create a buffer
+;;       b) Call `dframe-frame-mode'.  (See its doc)
+;;       c) If successful (your -frame variable has a value), call
+;;          timer setup if applicable.
+;;   your-frame-reposition- -- Function to call from after-create-hook to
+;;     reposition your frame with `dframe-repsoition-frame'.
+;;   your-mode -- Set up the major mode of the buffer for your app.
+;;     Set these variables: dframe-track-mouse-function,
+;;                          dframe-help-echo-function,
+;;                          dframe-mouse-click-function,
+;;                          dframe-mouse-position-function.
+;;   See speedbar's implementation of these functions.
+;;    `speedbar-current-frame', `speedbar-get-focus', `speedbar-message',
+;;    `speedbar-y-or-n-p', `speedbar-set-timer', `speedbar-click',
+;;    `speedbar-position-cursor-on-line'
+;; 4) Handling mouse clicks, and help text:
+;;   dframe-track-mouse, dframe-help-echo-function --
+;;    These variables need to be set to functions that display info
+;;    based on the mouse's position.
+;;   Text propert 'help-echo, set to `dframe-help-echo', which will
+;;    call `dframe-help-echo-function'.
+;;   Have a `-click' function, it can call `dframe-quick-mouse' for
+;;    positioning.  If the variable `dframe-power-click' is non-nil,
+;;    then `shift' was held down during the click.
+
+;;; Bugs
+;;
+;;  * The timer managers doesn't handle multiple different timeouts.
+;;  * You can't specify continuous timouts (as opposed to just lidle timers.)
+
+;;; Code:
+(defvar dframe-xemacsp (string-match "XEmacs" emacs-version)
+  "Non-nil if we are running in the XEmacs environment.")
+(defvar dframe-xemacs20p (and dframe-xemacsp
+			      (>= emacs-major-version 20)))
+
+;; From custom web page for compatibility between versions of custom
+;; with help from ptype@dera.gov.uk (Proto Type)
+(eval-and-compile
+  (condition-case ()
+      (require 'custom)
+    (error nil))
+  (if (and (featurep 'custom) (fboundp 'custom-declare-variable)
+	   ;; Some XEmacsen w/ custom don't have :set keyword.
+	   ;; This protects them against custom.
+	   (fboundp 'custom-initialize-set))
+      nil ;; We've got what we needed
+    ;; We have the old custom-library, hack around it!
+    (if (boundp 'defgroup)
+	nil
+      (defmacro defgroup (&rest args)
+	nil))
+    (if (boundp 'defface)
+	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))
+	     ))))
+    (if (boundp 'defcustom)
+	nil
+      (defmacro defcustom (var value doc &rest args)
+	(` (defvar (, var) (, value) (, doc)))))))
+
+
+;;; Compatibility functions
+;;
+(if (fboundp 'frame-parameter)
+
+    (defalias 'dframe-frame-parameter 'frame-parameter)
+  
+  (defun dframe-frame-parameter (frame parameter)
+    "Return FRAME's PARAMETER value."
+    (cdr (assoc parameter (frame-parameters frame)))))
+
+
+;;; Variables
+;;
+(defgroup dframe nil
+  "Faces used in dframe."
+  :prefix "dframe-"
+  :group 'dframe)
+
+(defvar dframe-have-timer-flag
+  (and (or (fboundp 'run-with-idle-timer)
+	   (fboundp 'start-itimer)
+	   (boundp 'post-command-idle-hook))
+       (if (fboundp 'display-graphic-p)
+	   (display-graphic-p)
+	 window-system))
+  "Non-nil means that timers are available for this Emacs.")
+
+(defcustom dframe-update-speed
+  (if dframe-xemacsp
+      (if dframe-xemacs20p
+	  2				; 1 is too obrusive in XEmacs
+	5)				; when no idleness, need long delay
+    1)
+  "*Idle time in seconds needed before dframe will update itself.
+Updates occur to allow dframe to display directory information
+relevant to the buffer you are currently editing."
+  :group 'dframe
+  :type 'integer)
+
+(defcustom dframe-activity-change-focus-flag nil
+  "*Non-nil means the selected frame will change based on activity.
+Thus, if a file is selected for edit, the buffer will appear in the
+selected frame and the focus will change to that frame."
+  :group 'dframe
+  :type 'boolean)
+
+(defvar dframe-track-mouse-function nil
+  "*A function to call when the mouse is moved in the given frame.
+Typically used to display info about the line under the mouse.")
+(make-variable-buffer-local 'dframe-track-mouse-function)
+
+(defvar dframe-help-echo-function nil
+  "*A function to call when help-echo is used in newer versions of Emacs.
+Typically used to display info about the line under the mouse.")
+(make-variable-buffer-local 'dframe-help-echo-function)
+
+(defvar dframe-mouse-click-function nil
+  "*A function to call when the mouse is clicked.
+Valid clicks are mouse 2, our double mouse 1.")
+(make-variable-buffer-local 'dframe-mouse-click-function)
+
+(defvar dframe-mouse-position-function nil
+  "*A function to called to position the cursor for a mouse click.")
+(make-variable-buffer-local 'dframe-mouse-position-function)
+
+(defvar dframe-power-click nil
+  "Never set this by hand.  Value is t when S-mouse activity occurs.")
+
+(defvar dframe-timer nil
+  "The dframe timer used for updating the buffer.")
+
+(defvar dframe-attached-frame nil
+  "The frame which started a frame mode.
+This is the frame from which all interesting activities will go
+for the mode using dframe.")
+
+(defvar dframe-controlled nil
+  "Is this buffer controlled by a dedicated frame.
+Local to those buffers, as a function called that created it.")
+(make-variable-buffer-local 'dframe-controlled)
+
+(defun dframe-update-keymap (map)
+  "Update the keymap MAP for dframe default bindings."
+  ;; Frame control
+  (define-key map "q" 'dframe-close-frame)
+  (define-key map "Q" 'delete-frame)
+
+  ;; Override switch to buffer to never hack our frame.
+  (substitute-key-definition 'switch-to-buffer
+			     'dframe-switch-buffer-attached-frame
+			     map global-map)
+
+  (if dframe-xemacsp
+      (progn
+	;; mouse bindings so we can manipulate the items on each line
+	(define-key map 'button2 'dframe-click)
+	(define-key map '(shift button2) 'dframe-power-click)
+	;; Info doc fix from Bob Weiner
+	(if (featurep 'infodoc)
+	    nil
+	  (define-key map 'button3 'dframe-xemacs-popup-kludge))
+	(define-key map '(meta button3) 'dframe-mouse-item-info)
+	)
+
+    ;; mouse bindings so we can manipulate the items on each line
+    (define-key map [down-mouse-1] 'dframe-double-click)
+    (define-key map [mouse-2] 'dframe-click)
+    ;; This is the power click for new frames, or refreshing a cache
+    (define-key map [S-mouse-2] 'dframe-power-click)
+    ;; This adds a small unecessary visual effect
+    ;;(define-key map [down-mouse-2] 'dframe-quick-mouse)
+    (define-key map [M-mouse-2] 'dframe-mouse-item-info)
+
+    (define-key map [down-mouse-3] 'dframe-emacs-popup-kludge)
+
+    ;; This lets the user scroll as if we had a scrollbar... well maybe not
+    (define-key map [mode-line mouse-2] 'dframe-mouse-hscroll)
+    ;; another handy place users might click to get our menu.
+    (define-key map [mode-line down-mouse-1]
+      'dframe-emacs-popup-kludge)
+
+    ;; We can't switch buffers with the buffer mouse menu.  Lets hack it.
+    (define-key map [C-down-mouse-1] 'dframe-hack-buffer-menu)
+
+    ;; Lastly, we want to track the mouse.  Play here
+    (define-key map [mouse-movement] 'dframe-track-mouse)
+    ))
+
+(defun dframe-live-p (frame)
+  "Return non-nil if FRAME is currently available."
+  (and frame (frame-live-p frame) (frame-visible-p frame)))
+
+(defun dframe-frame-mode (arg frame-var cache-var buffer-var frame-name
+			      local-mode-fn
+			      &optional
+			      parameters
+			      delete-hook popup-hook create-hook
+			      )
+  "Manage a frame for an application, enabling it when ARG is positive.
+FRAME-VAR is a variable used to cache the frame being used.
+This frame is either resurrected, hidden, killed, etc based on
+the value.
+CACHE-VAR is a variable used to cache a cached frame.
+BUFFER-VAR is a variable used to cache the buffer being used in dframe.
+This buffer will have `dframe-mode' run on it.
+FRAME-NAME is the name of the frame to create.
+LOCAL-MODE-FN is the function used to call this one.
+PARAMETERS are frame parameters to apply to this dframe.
+DELETE-HOOK are hooks to run when deleting a frame.
+POPUP-HOOK are hooks to run before showing a frame.
+CREATE-HOOK are hooks to run after creating a frame."
+  ;; toggle frame on and off.
+  (if (not arg) (if (dframe-live-p (symbol-value frame-var))
+		    (setq arg -1) (setq arg 1)))
+  ;; Make sure the current buffer is set.
+  (set-buffer (symbol-value buffer-var))
+  ;; turn the frame off on neg number
+  (if (and (numberp arg) (< arg 0))
+      (progn
+	(run-hooks delete-hook)
+	(if (and (symbol-value frame-var)
+		 (frame-live-p (symbol-value frame-var)))
+	    (progn
+	      (set cache-var (symbol-value frame-var))
+	      (make-frame-invisible (symbol-value frame-var))))
+	(set frame-var nil)
+	(make-variable-buffer-local 'dframe-timer)
+	)
+    ;; Set this as our currently attached frame
+    (make-variable-buffer-local 'dframe-attached-frame)
+    (setq dframe-attached-frame (selected-frame))
+    (run-hooks 'popup-hook)
+    ;; Updated the buffer passed in to contain all the hacks needed
+    ;; to make it work well in a dedicated window.
+    (save-excursion
+      (set-buffer (symbol-value buffer-var))
+      ;; Declare this buffer a dedicated frame
+      (setq dframe-controlled local-mode-fn)
+
+      (if dframe-xemacsp
+	  ;; Hack the XEmacs mouse-motion handler
+	  (set (make-local-variable 'mouse-motion-handler)
+	       'dframe-track-mouse-xemacs)
+	;; Enable mouse tracking in emacs
+	(if dframe-track-mouse-function
+	    (set (make-local-variable 'track-mouse) t))	;this could be messy.
+	;; disable auto-show-mode for Emacs
+	(setq auto-show-mode nil))
+      ;; Set this up special just for the passed in buffer
+      ;; Terminal minibuffer stuff does not require this.
+      (if (and (or (assoc 'minibuffer parameters)
+		   ;; XEmacs plist is not an association list
+		   (member 'minibuffer parameters))
+	       window-system (not (eq window-system 'pc))
+	       (null default-minibuffer-frame))
+	  (progn
+	    (make-local-variable 'default-minibuffer-frame)
+	    (setq default-minibuffer-frame dframe-attached-frame)))
+      ;; Override `temp-buffer-show-hook' so that help and such
+      ;; put their stuff into a frame other than our own.
+      ;; Correct use of `temp-buffer-show-function': Bob Weiner
+      (if (and (boundp 'temp-buffer-show-hook)
+	       (boundp 'temp-buffer-show-function))
+	  (progn (make-local-variable 'temp-buffer-show-hook)
+		 (setq temp-buffer-show-hook temp-buffer-show-function)))
+      (make-local-variable 'temp-buffer-show-function)
+      (setq temp-buffer-show-function 'dframe-temp-buffer-show-function)
+      ;; If this buffer is killed, we must make sure that we destroy
+      ;; the frame the dedicated window is in.
+      (make-local-hook 'kill-buffer-hook)
+      (add-hook 'kill-buffer-hook `(lambda ()
+				     (let ((skilling (boundp 'skilling)))
+				       (if skilling
+					   nil
+					 (if dframe-controlled
+					     (progn
+					       (funcall dframe-controlled -1)
+					       (setq ,buffer-var nil)
+					       )))))
+		t t)
+      )
+    ;; Get the frame to work in
+    (if (frame-live-p (symbol-value cache-var))
+	(progn
+	  (set frame-var (symbol-value cache-var))
+	  (make-frame-visible (symbol-value frame-var))
+	  (select-frame (symbol-value frame-var))
+	  (set-window-dedicated-p (selected-window) nil)
+	  (if (not (eq (current-buffer) (symbol-value buffer-var)))
+	      (switch-to-buffer (symbol-value buffer-var)))
+	  (set-window-dedicated-p (selected-window) t)
+	  (raise-frame (symbol-value frame-var))
+	  )
+      (if (frame-live-p (symbol-value frame-var))
+	  (raise-frame (symbol-value frame-var))
+	(set frame-var
+	      (if dframe-xemacsp
+		  ;; Only guess height if it is not specified.
+		  (if (member 'height parameters)
+		      (make-frame parameters)
+		    (make-frame (nconc (list 'height
+					     (dframe-needed-height))
+				       parameters)))
+		(let* ((mh (dframe-frame-parameter dframe-attached-frame
+						   'menu-bar-lines))
+		       (paramsa
+			;; Only add a guessed height if one is not specified
+			;; in the input parameters.
+			(if (assoc 'height parameters)
+			    parameters
+			  (append
+			   parameters
+			   (list (cons 'height (+ mh (frame-height)))))))
+		       (params
+			;; Only add a guessed width if one is not specified
+			;; in the input parameters.
+			(if (assoc 'width parameters)
+			    paramsa
+			  (append
+			   paramsa
+			   (list (cons 'width (frame-width))))))
+		       (frame
+			(if (or (< emacs-major-version 20)
+				(not (eq window-system 'x)))
+			    (make-frame params)
+			  (let ((x-pointer-shape x-pointer-top-left-arrow)
+				(x-sensitive-text-pointer-shape
+				 x-pointer-hand2))
+			    (make-frame params)))))
+		  frame)))
+	;; Put the buffer into the frame
+	(save-excursion
+	  (select-frame (symbol-value frame-var))
+	  (switch-to-buffer (symbol-value buffer-var))
+	  (set-window-dedicated-p (selected-window) t))
+	;; Run hooks (like reposition)
+	(run-hooks 'create-hook)
+	;; Frame name
+	(if (and (or (null window-system) (eq window-system 'pc))
+		 (fboundp 'set-frame-name))
+	    (save-window-excursion
+	      (select-frame (symbol-value frame-var))
+	      (set-frame-name frame-name)))))) )
+
+(defun dframe-reposition-frame (new-frame parent-frame location)
+  "Move NEW-FRAME to be relative to PARENT-FRAME.
+LOCATION can be one of 'random, 'left-right, or 'top-bottom."
+  (if dframe-xemacsp
+      (dframe-reposition-frame-xemacs new-frame parent-frame location)
+    (dframe-reposition-frame-emacs new-frame parent-frame location)))
+
+(defun dframe-reposition-frame-emacs (new-frame parent-frame location)
+  "Move NEW-FRAME to be relative to PARENT-FRAME.
+LOCATION can be one of 'random, 'left-right, or 'top-bottom."
+  (let* ((pfx (dframe-frame-parameter parent-frame 'left))
+	 (pfy (dframe-frame-parameter parent-frame 'top))
+	 (pfw (frame-pixel-width parent-frame))
+	 (pfh (frame-pixel-height parent-frame))
+	 (nfw (frame-pixel-width new-frame))
+	 (nfh (frame-pixel-height new-frame))
+	 newleft newtop
+	 )
+    ;; Position dframe.
+    (if (or (not window-system) (eq window-system 'pc))
+	;; Do no positioning if not on a windowing system,
+	nil
+      ;; Rebuild pfx,pfy to be absolute positions.
+      (setq pfx (if (not (consp pfx))
+		    pfx
+		  ;; If pfx is a list, that means we grow
+		  ;; from a specific edge of the display.
+		  ;; Convert that to the distance from the
+		  ;; left side of the display.
+		  (if (eq (car pfx) '-)
+		      ;; A - means distance from the right edge
+		      ;; of the display, or DW - pfx - framewidth
+		      (- (x-display-pixel-width) (car (cdr pfx)) pfw)
+		    (car (cdr pfx))))
+	    pfy (if (not (consp pfy))
+		    pfy
+		  ;; If pfy is a list, that means we grow
+		  ;; from a specific edge of the display.
+		  ;; Convert that to the distance from the
+		  ;; left side of the display.
+		  (if (eq (car pfy) '-)
+		      ;; A - means distance from the right edge
+		      ;; of the display, or DW - pfx - framewidth
+		      (- (x-display-pixel-height) (car (cdr pfy)) pfh)
+		    (car (cdr pfy))))
+	    )
+      (cond ((eq location 'left-right)
+	     (setq newleft
+		   ;; Decide which side to put it on.  200 is just a
+		   ;; buffer for the left edge of the screen.  The
+		   ;; extra 10 is just dressings for window
+		   ;; decorations.
+		   (let* ((left-guess (- pfx 10 nfw))
+			  (right-guess (+ pfx pfw 5))
+			  (left-margin left-guess)
+			  (right-margin (- (x-display-pixel-width)
+					   right-guess 5 nfw)))
+		     (cond ((>= left-margin 0) left-guess)
+			   ((>= right-margin 0) right-guess)
+			   ;; otherwise choose side we overlap less
+			   ((> left-margin right-margin) 0)
+			   (t (- (x-display-pixel-width) nfw 5))))
+		   newtop pfy
+		   ))
+	    ((eq location 'top-bottom)
+	     )
+	    (t nil))
+      (modify-frame-parameters new-frame
+       (list (cons 'left newleft)
+	     (cons 'top newtop))))))
+
+(defun dframe-reposition-frame-xemacs (new-frame parent-frame location)
+  "Move NEW-FRAME to be relative to PARENT-FRAME.
+LOCATION can be one of 'random, 'left-right, or 'top-bottom."
+  ;; Not yet implemented
+  )
+
+;; XEmacs function only.
+(defun dframe-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))))
+
+(defun dframe-detach (frame-var cache-var buffer-var)
+  "Detatch the frame in symbol FRAME-VAR.
+CACHE-VAR and BUFFER-VAR are symbols as in `dframe-frame-mode'"
+  (save-excursion
+    (set-buffer (symbol-value buffer-var))
+    (rename-buffer (buffer-name) t)
+    (let ((oldframe (symbol-value frame-var)))
+      (set buffer-var nil)
+      (set frame-var nil)
+      (set cache-var nil)
+      (make-variable-buffer-local frame-var)
+      (set frame-var oldframe)
+      )))
+
+
+;;; Utilities
+;;
+(defun dframe-get-focus (frame-var activator &optional hook)
+  "Change frame focus to or from a dedicated frame.
+If the selected frame is not in the symbol FRAME-VAR, then FRAME-VAR
+frame is selected.  If the FRAME-VAR is active, then select the
+attached frame.  If FRAME-VAR is nil, ACTIVATOR is called to
+created it.  HOOK is an optional argument of hooks to run when
+selecting FRAME."
+  (interactive)
+  (if (eq (selected-frame) (symbol-value frame-var))
+      (if (frame-live-p dframe-attached-frame)
+	  (select-frame dframe-attached-frame))
+    ;; If updates are off, then refresh the frame (they want it now...)
+    (run-hooks 'hook)
+    ;; make sure we have a frame
+    (if (not (frame-live-p (symbol-value frame-var)))
+	(funcall activator 1))
+    ;; go there
+    (select-frame (symbol-value frame-var))
+    )
+  (other-frame 0))
+
+(defun dframe-close-frame ()
+  "Close the current frame if it is dedicated."
+  (interactive)
+  (if dframe-controlled
+      (let ((b (current-buffer)))
+	(funcall dframe-controlled -1)
+	(kill-buffer b))))
+
+(defun dframe-current-frame (frame-var desired-major-mode)
+  "Return the existing dedicated frame to use.
+FRAME-VAR is the variable storing the currently active dedicated frame.
+If the current frame's buffer uses DESIRED-MAJOR-MODE, then use that frame."
+  (if (not (eq (selected-frame) (symbol-value frame-var)))
+      (if (and (eq major-mode 'desired-major-mode)
+	       (get-buffer-window (current-buffer))
+	       (window-frame (get-buffer-window (current-buffer))))
+	  (window-frame (get-buffer-window (current-buffer)))
+	(symbol-value frame-var))
+    (symbol-value frame-var)))
+
+(defun dframe-attached-frame (frame)
+  "Return the attached frame belonging to the dframe controlled frame FRAME."
+  (save-excursion
+    (if frame (select-frame frame))
+    dframe-attached-frame))
+
+(defun dframe-select-attached-frame (frame)
+  "Switch to the frame the dframe controled frame FRAME was started from."
+  (let ((frame (dframe-attached-frame frame)))
+    (if frame (select-frame frame) nil)))
+
+(defmacro dframe-with-attached-buffer (&rest forms)
+  "Execute FORMS in the attached frame's special buffer.
+Optionally select that frame if necessary."
+  `(save-selected-window
+     ;;(speedbar-set-timer speedbar-update-speed)
+     (select-frame dframe-attached-frame)
+     ,@forms
+     (dframe-maybee-jump-to-attached-frame)))
+
+(defun dframe-maybee-jump-to-attached-frame ()
+  "Jump to the attached frame ONLY if this was not a mouse event."
+  (if (or (not (dframe-mouse-event-p last-input-event))
+	  dframe-activity-change-focus-flag)
+      (progn
+	;(select-frame dframe-attached-frame)
+	(other-frame 0))))
+
+(defvar dframe-suppress-message-flag nil
+  "Non-nil means that `dframe-message' should just return a string.")
+
+(defun dframe-message (fmt &rest args)
+  "Like message, but for use in a dedicated frame.
+Argument FMT is the format string, and ARGS are the arguments for message."
+  (save-selected-window
+    (if dframe-suppress-message-flag
+	(apply 'format fmt args)
+      (if dframe-attached-frame
+	  (select-frame dframe-attached-frame))
+      (apply 'message fmt args))))
+
+(defun dframe-y-or-n-p (prompt)
+  "Like `y-or-n-p', but for use in a dedicated frame.
+Argument PROMPT is the prompt to use."
+  (save-selected-window
+    (if (and default-minibuffer-frame
+	     dframe-attached-frame
+	     (not (eq default-minibuffer-frame dframe-attached-frame)))
+	(select-frame dframe-attached-frame))
+    (y-or-n-p prompt)))
+
+;;; timer management
+;;
+;; Unlike speedbar with a dedicated set of routines, dframe has one master
+;; timer, and all dframe users will use it.  At least until I figure out a way
+;; around that problem.
+;;
+;; Advantage 1: Two apps with timer/frames can munge the master list
+;;              to make sure they occur in order.
+;; Advantage 2: If a user hits a key between timer functions, we can
+;;	        interrupt them safely.
+(defvar dframe-client-functions nil
+  "List of client functions using the dframe timer.")
+
+(defun dframe-set-timer (timeout fn &optional null-on-error)
+  "Apply a timer TIMEOUT, to call FN, or remove a timer if TIMOUT is nil.
+TIMEOUT is the number of seconds until the dframe controled program
+timer is called again.  When TIMEOUT is nil, turn off all timeouts.
+This function must be called from the buffer belonging to the program
+who requested the timer.
+If NULL-ON-ERROR is a symbol, set it to nil if we cannot create a timer."
+  ;; First, fix up our list of client functions
+  (if timeout
+      (add-to-list 'dframe-client-functions fn)
+    (setq dframe-client-functions (delete fn dframe-client-functions)))
+  ;; Now decided what to do about the timout.
+  (if (or
+       ;; We have a timer, restart the timer with the new time.
+       timeout
+       ;; We have a timer, an off is requested, and no client
+       ;; functions are left, shut er down.
+       (and dframe-timer (not timeout) dframe-client-functions))
+      ;; Only call the low level function if we are changing the state.
+      (dframe-set-timer-internal timeout null-on-error)))
+
+(defun dframe-set-timer-internal (timeout &optional null-on-error)
+  "Apply a timer with TIMEOUT to call the dframe timer manager.
+If NULL-ON-ERROR is a symbol, set it to nil if we cannot create a timer."
+  (cond
+   ;; XEmacs
+   (dframe-xemacsp
+    (if dframe-timer
+	(progn (delete-itimer dframe-timer)
+	       (setq dframe-timer nil)))
+    (if timeout
+	(if (and dframe-xemacsp
+		 (or (>= emacs-major-version 20)
+		     (>= emacs-minor-version 15)))
+	    (setq dframe-timer (start-itimer "dframe"
+					     'dframe-timer-fn
+					     timeout
+					     timeout
+					     t))
+	  (setq dframe-timer (start-itimer "dframe"
+					   'dframe-timer-fn
+					   timeout
+					   nil)))))
+   ;; Post 19.31 Emacs
+   ((fboundp 'run-with-idle-timer)
+    (if dframe-timer
+	(progn (cancel-timer dframe-timer)
+	       (setq dframe-timer nil)))
+    (if timeout
+	(setq dframe-timer
+	      (run-with-idle-timer timeout t 'dframe-timer-fn))))
+   ;; Emacs 19.30 (Thanks twice: ptype@dra.hmg.gb)
+   ((fboundp 'post-command-idle-hook)
+    (if timeout
+	(add-hook 'post-command-idle-hook 'dframe-timer-fn)
+      (remove-hook 'post-command-idle-hook 'dframe-timer-fn)))
+   ;; Older or other Emacsen with no timers.  Set up so that its
+   ;; obvious this emacs can't handle the updates
+   ((symbolp null-on-error)
+    (set null-on-error nil)))
+  )
+
+(defun dframe-timer-fn ()
+  "Called due to the dframe timer.
+Evaluates all cached timer functions in sequence."
+  (let ((l dframe-client-functions))
+    (while (and l (sit-for 0))
+      (condition-case er
+	  (funcall (car l))
+	(error (message "DFRAME TIMER ERROR: %S" er)))
+      (setq l (cdr l)))))
+
+;;; Menu hacking for mouse-3
+;;
+;; 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 dframe-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 dframe-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))))
+
+;;; Interactive user functions for the mouse
+;;
+(if dframe-xemacsp
+    (defalias 'dframe-mouse-event-p 'button-press-event-p)
+  (defun dframe-mouse-event-p (event)
+    "Return t if the event is a mouse related event"
+    (if (and (listp event)
+	     (member (event-basic-type event)
+		     '(mouse-1 mouse-2 mouse-3)))
+	t
+      nil)))
+
+(defun dframe-track-mouse (event)
+  "For motion EVENT, display info about the current line."
+  (interactive "e")
+  (when dframe-track-mouse-function
+    (funcall dframe-track-mouse-function event)))
+
+(defun dframe-track-mouse-xemacs (event)
+  "For motion EVENT, display info about the current line."
+  (if (functionp (default-value 'mouse-motion-handler))
+      (funcall (default-value 'mouse-motion-handler) event))
+  (if dframe-track-mouse-function
+      (funcall dframe-track-mouse-function event)))
+
+(defun dframe-help-echo (window &optional buffer position)
+  "Display help based context.
+The context is in WINDOW, viewing BUFFER, at POSITION.
+BUFFER and POSITION are optional because XEmacs doesn't use them."
+  (when (and (not dframe-track-mouse-function)
+	     (bufferp buffer)
+	     dframe-help-echo-function)
+    (let ((dframe-suppress-message-flag t))
+      (with-current-buffer buffer
+	(if position (goto-char position))
+	(funcall dframe-help-echo-function)))))
+
+(defun dframe-mouse-set-point (e)
+  "Set POINT based on event E.
+Handles clicking on images in XEmacs."
+  (if (and (fboundp 'event-over-glyph-p) (event-over-glyph-p e))
+      ;; We are in XEmacs, and clicked on a picture
+      (let ((ext (event-glyph-extent e)))
+	;; This position is back inside the extent where the
+	;; junk we pushed into the property list lives.
+	(if (extent-end-position ext)
+	    (goto-char (1- (extent-end-position ext)))
+	  (mouse-set-point e)))
+    ;; We are not in XEmacs, OR we didn't click on a picture.
+    (mouse-set-point e)))
+
+(defun dframe-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")
+  (dframe-mouse-set-point e)
+  (if dframe-mouse-position-function
+      (funcall dframe-mouse-position-function)))
+
+(defun dframe-power-click (e)
+  "Activate any `dframe' mouse click as a power click.
+A power click will dispose of cached data (if available) or bring a buffer
+up into a different window.
+This should be bound to mouse event E."
+  (interactive "e")
+  (let ((dframe-power-click t))
+    (dframe-click e)))
+
+(defun dframe-click (e)
+  "Call our clients click function on a user click.
+E is the event causing the click."
+  (interactive "e")
+  (dframe-mouse-set-point e)
+  (funcall dframe-mouse-click-function e))
+
+(defun dframe-double-click (e)
+  "Activate the registered click function on a double click.
+This must be bound to a mouse event.
+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)
+	 (dframe-mouse-set-point e))
+	((eq (car e) 'mouse-1)
+	 (dframe-quick-mouse e))
+	((or (eq (car e) 'double-down-mouse-1)
+	     (eq (car e) 'triple-down-mouse-1))
+	 (dframe-click e))))
+
+;;; Hacks of normal things.
+;;
+;; Some normal things that happen in one of these dedicated frames
+;; must be handled specially, so that our dedicated frame isn't
+;; messed up.
+(defun dframe-temp-buffer-show-function (buffer)
+  "Placed in the variable `temp-buffer-show-function' in dedicated frames.
+If a user requests help using \\[help-command] <Key> the temp BUFFER will be
+redirected into a window on the attached frame."
+  (if dframe-attached-frame (select-frame dframe-attached-frame))
+  (pop-to-buffer buffer nil)
+  (other-window -1)
+  ;; Fix for using this hook on some platforms: Bob Weiner
+  (cond ((not dframe-xemacsp)
+	 (run-hooks 'temp-buffer-show-hook))
+	((fboundp 'run-hook-with-args)
+	 (run-hook-with-args 'temp-buffer-show-hook buffer))
+	((and (boundp 'temp-buffer-show-hook)
+	      (listp temp-buffer-show-hook))
+	 (mapcar (function (lambda (hook) (funcall hook buffer)))
+		 temp-buffer-show-hook))))
+
+(defun dframe-hack-buffer-menu (e)
+  "Control mouse 1 is buffer menu.
+This hack overrides it so that the right thing happens in the main
+Emacs frame, not in the dedicated frame.
+Argument E is the event causing this activity."
+  (interactive "e")
+  (let ((fn (lookup-key global-map (if dframe-xemacsp
+				              '(control button1)
+				     [C-down-mouse-1])))
+	(oldbuff (current-buffer))
+	(newbuff nil))
+    (unwind-protect
+	(save-excursion
+	  (set-window-dedicated-p (selected-window) nil)
+	  (call-interactively fn)
+	  (setq newbuff (current-buffer)))
+      (switch-to-buffer oldbuff)
+      (set-window-dedicated-p (selected-window) t))
+    (if (not (eq newbuff oldbuff))
+	(dframe-with-attached-buffer
+	 (switch-to-buffer newbuff)))))
+
+(defun dframe-switch-buffer-attached-frame (&optional buffer)
+  "Switch to BUFFER in the attached frame, and raise that frame.
+This overrides the default behavior of `switch-to-buffer' which is
+broken because of the dedicated frame."
+  (interactive)
+  ;; Assume we are in the dedicated frame.
+  (other-window 0)
+  ;; Now switch buffers
+  (if buffer
+      (switch-to-buffer buffer)
+    (call-interactively 'switch-to-buffer nil nil)))
+
+;; XEmacs: this can be implemented using modeline keymaps, but there
+;; is no use, as we have horizontal scrollbar (as the docstring
+;; hints.)
+(defun dframe-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 (dframe-message
+	      "Click on the edge of the modeline to scroll left/right")))
+    ))
+
+(provide 'dframe)
+
+;;; dframe.el ends here
 ;;; rpm.el --- Manage Red Hat packages in emacs
 
-;;; Copyright (C) 1998, 1999 Eric M. Ludlam
+;;; Copyright (C) 1998, 1999, 2000 Eric M. Ludlam
 
 ;; Author: Eric M. Ludlam <zappo@gnu.org>
 ;; Version: 1.0
 	(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)
+	(dframe-select-attached-frame speedbar-frame)
 	(switch-to-buffer buff)))
     (erase-buffer)
     (rpm-info text)))
+;;; sb-image --- Image management for speedbar
+
+;;; Copyright (C) 1999, 2000 Free Software Foundation
+
+;; Author: Eric M. Ludlam <zappo@gnu.org>
+;; Keywords: file, tags, tools
+;; X-RCS: $Id$
+
+;; 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.
+
+;;; Commentary:
+;;
+;; Supporting Image display for Emacs 20 and less, Emacs 21, and XEmacs,
+;; is a challenging task, which doesn't take kindly to being byte compiled.
+;; When sharing speedbar.elc between these three applications, the Image
+;; support can get lost.
+;;
+;; By splitting out that hard part into this file, and avoiding byte
+;; compilation, one copy speedbar can support all these platforms together.
+;;
+;; This file require the `image' package if it is available.
+
+(condition-case nil
+    (require 'image)
+  (error nil))
+
+;;; Code:
+(defcustom speedbar-use-images (and (or (fboundp 'defimage)
+					(fboundp 'make-image-specifier))
+				    (if (fboundp 'display-graphic-p)
+					(display-graphic-p)
+				      window-system))
+  "*Non nil if speedbar should display icons."
+  :group 'speedbar
+  :type 'boolean)
+
+;;; Some images if defimage is available:
+(eval-and-compile
+
+(if (fboundp 'defimage)
+    (defalias 'defimage-speedbar 'defimage)
+
+  (if (not (fboundp 'make-glyph))
+      
+(defmacro defimage-speedbar (variable imagespec docstring)
+  "Don't bother loading up an image...
+Argument VARIABLE is the varible to define.
+Argument IMAGESPEC is the list defining the image to create.
+Argument DOCSTRING is the documentation for VARIABLE."
+  `(defvar ,variable nil ,docstring))
+
+;; ELSE
+(defun speedbar-find-image-on-load-path (image)
+  "Find the image file IMAGE on the load path."
+  (let ((l load-path)
+	(r nil))
+    (while (and l (not r))
+      (if (file-exists-p (concat (car l) "/" image))
+	  (setq r (concat (car l) "/" image)))
+      (setq l (cdr l)))
+    r))
+
+(defun speedbar-convert-emacs21-imagespec-to-xemacs (spec)
+  "Convert the Emacs21 Image SPEC into an XEmacs image spec."
+  (let* ((sl (car spec))
+	 (itype (nth 1 sl))
+	 (ifile (nth 3 sl)))
+    (vector itype ':file (speedbar-find-image-on-load-path ifile))))
+
+(defmacro defimage-speedbar (variable imagespec docstring)
+  "Devine VARIABLE as an image if `defimage' is not available..
+IMAGESPEC is the image data, and DOCSTRING is documentation for the image."
+  `(defvar ,variable
+     ;; The Emacs21 version of defimage looks just like the XEmacs image
+     ;; specifier, except that it needs a :type keyword.  If we line
+     ;; stuff up right, we can use this cheat to support XEmacs specifiers.
+     (condition-case nil
+	 (make-glyph
+	  (make-image-specifier
+	   (speedbar-convert-emacs21-imagespec-to-xemacs (quote ,imagespec)))
+	  'buffer)
+       (error nil))
+     ,docstring))
+
+)))
+
+(defimage-speedbar speedbar-directory-plus
+  ((:type xpm :file "sb-dir-plus.xpm" :ascent center))
+  "Image used for closed directories with stuff in them.")
+
+(defimage-speedbar speedbar-directory-minus
+  ((:type xpm :file "sb-dir-minus.xpm" :ascent center))
+  "Image used for open directories with stuff in them.")
+
+(defimage-speedbar speedbar-page-plus
+  ((:type xpm :file "sb-pg-plus.xpm" :ascent center))
+  "Image used for closed files with stuff in them.")
+
+(defimage-speedbar speedbar-page-minus
+  ((:type xpm :file "sb-pg-minus.xpm" :ascent center))
+  "Image used for open files with stuff in them.")
+
+(defimage-speedbar speedbar-page
+  ((:type xpm :file "sb-pg.xpm" :ascent center))
+  "Image used for files that can't be opened.")
+
+(defimage-speedbar speedbar-tag
+  ((:type xpm :file "sb-tag.xpm" :ascent center))
+  "Image used for tags.")
+
+(defimage-speedbar speedbar-tag-plus
+  ((:type xpm :file "sb-tag-plus.xpm" :ascent center))
+  "Image used for closed tag groups.")
+
+(defimage-speedbar speedbar-tag-minus
+  ((:type xpm :file "sb-tag-minus.xpm" :ascent center))
+  "Image used for open tag groups.")
+
+(defimage-speedbar speedbar-tag-gt
+  ((:type xpm :file "sb-tag-gt.xpm" :ascent center))
+  "Image used for open tag groups.")
+
+(defimage-speedbar speedbar-tag-v
+  ((:type xpm :file "sb-tag-v.xpm" :ascent center))
+  "Image used for open tag groups.")
+
+(defimage-speedbar speedbar-tag-type
+  ((:type xpm :file "sb-tag-type.xpm" :ascent center))
+  "Image used for open tag groups.")
+
+(defimage-speedbar speedbar-mail
+  ((:type xpm :file "sb-mail.xpm" :ascent center))
+  "Image used for open tag groups.")
+
+(defvar speedbar-expand-image-button-alist
+  '(("<+>" . speedbar-directory-plus)
+    ("<->" . speedbar-directory-minus)
+    ("[+]" . speedbar-page-plus)
+    ("[-]" . speedbar-page-minus)
+    ("[?]" . speedbar-page)
+    ("{+}" . speedbar-tag-plus)
+    ("{-}" . speedbar-tag-minus)
+    ("<M>" . speedbar-mail)
+    (" =>" . speedbar-tag)
+    (" +>" . speedbar-tag-gt)
+    (" ->" . speedbar-tag-v)
+    (">" . speedbar-tag)
+    ("@" . speedbar-tag-type)
+    ("  @" . speedbar-tag-type)
+    )
+  "List of text and image associations.")
+
+(defun speedbar-insert-image-button-maybe (start length)
+  "Insert an image button based on text starting at START for LENGTH chars.
+If buttontext is unknown, just insert that text.
+If we have an image associated with it, use that image."
+  (if speedbar-use-images
+      (let* ((bt (buffer-substring start (+ length start)))
+	     (a (assoc bt speedbar-expand-image-button-alist)))
+	;; Regular images (created with `insert-image' are intangible
+	;; which (I suppose) make them more compatible with XEmacs 21.
+	;; Unfortunatly, there is a giant pile o code dependent on the
+	;; underlying text.  This means if we leave it tangible, then I
+	;; don't have to change said giant piles o code.
+	(if (and a (symbol-value (cdr a)))
+	    (if (fboundp 'set-extent-property)
+		(add-text-properties (+ start (length bt)) start
+				     (list 'end-glyph (symbol-value (cdr a))
+					   'rear-nonsticky (list 'display)
+					   'invisible t
+					   'detachable t))
+	      (add-text-properties start (+ start (length bt))
+				   (list 'display (symbol-value (cdr a))
+					 'rear-nonsticky (list 'display))))
+	  ;(message "Bad text [%s]" (buffer-substring start (+ start length)))
+	  ))))
+
+
+(provide 'sb-image)
+
+;;; sb-image.el ends here
     ;; being known at creation time.
     (if (not node)
 	(speedbar-with-writable (insert "Info Nodes:\n")))
-    (let ((completions nil)
-	  (cf (selected-frame)))
-      (select-frame speedbar-attached-frame)
+    (let ((completions nil))
+      (dframe-select-attached-frame speedbar-frame)
       (save-window-excursion
 	(setq completions
 	      (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
-      (select-frame cf)
+      (select-frame speedbar-frame)
       (if completions
 	  (speedbar-with-writable
 	   (while completions
 (defun Info-speedbar-goto-node (text node indent)
   "When user clicks on TEXT, goto an info NODE.
 The INDENT level is ignored."
-    (select-frame speedbar-attached-frame)
-    (let* ((buff (or (get-buffer "*info*")
-		     (progn (info) (get-buffer "*info*"))))
-	   (bwin (get-buffer-window buff 0)))
-      (if bwin
-	  (progn
-	    (select-window bwin)
-	    (raise-frame (window-frame bwin)))
-	(if speedbar-power-click
-	    (let ((pop-up-frames t)) (select-window (display-buffer buff)))
-	  (select-frame speedbar-attached-frame)
-	  (switch-to-buffer buff)))
-      (if (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node)
-	  (let ((file (match-string 1 node))
-		(node (match-string 2 node)))
-	    (Info-find-node file node)
-	    ;; If we do a find-node, and we were in info mode, restore
-	    ;; the old default method.  Once we are in info mode, it makes
-	    ;; sense to return to whatever method the user was using before.
-	    (if (string= speedbar-initial-expansion-list-name "Info")
-		(speedbar-change-initial-expansion-list
-		 speedbar-previously-used-expansion-list-name))))))
+  (dframe-select-attached-frame speedbar-frame)
+  (let* ((buff (or (get-buffer "*info*")
+		   (progn (info) (get-buffer "*info*"))))
+	 (bwin (get-buffer-window buff 0)))
+    (if bwin
+	(progn
+	  (select-window bwin)
+	  (raise-frame (window-frame bwin)))
+      (if dframe-power-click
+	  (let ((pop-up-frames t)) (select-window (display-buffer buff)))
+	(dframe-select-attached-frame speedbar-frame)
+	(switch-to-buffer buff)))
+    (if (string-match "^(\\([^)]+\\))\\([^,:]+\\)$" node)
+	(let ((file (match-string 1 node))
+	      (node (match-string 2 node)))
+	  (Info-find-node file node)
+	  ;; If we do a find-node, and we were in info mode, restore
+	  ;; the old default method.  Once we are in info mode, it makes
+	  ;; sense to return to whatever method the user was using before.
+	  (if (string= speedbar-initial-expansion-list-name "Info")
+	      (speedbar-change-initial-expansion-list
+	       speedbar-previously-used-expansion-list-name))))))
 
 (defun Info-speedbar-expand-node (text token indent)
   "Expand the node the user clicked on.
 (defun Info-speedbar-fetch-file-nodes (nodespec)
   "Fetch the subnodes from the info NODESPEC.
 NODESPEC is a string of the form: (file)node.
-Optional THISFILE represents the filename of"
+Optional THISFILE represends the filename of"
   (save-excursion
     ;; Set up a buffer we can use to fake-out Info.
     (set-buffer (get-buffer-create "*info-browse-tmp*"))
     (if (not (equal major-mode 'Info-mode))
 	(Info-mode))
     ;; Get the node into this buffer
-    (if (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec)
+    (if (string-match "^(\\([^)]+\\))\\([^,:]+\\)$" nodespec)
 	(let ((file (match-string 1 nodespec))
 	      (node (match-string 2 nodespec)))
 	  (Info-find-node file node))
+;;; sb-texinfo.el --- provide hierarchical speedbar menu's for texinfo files
+
+;; Copyright (c) 2000 Richard Y. Kim
+
+;; Author: Richard Y. Kim, <ryk@ap.com>
+;; Maintainer: Richard Y. Kim, <ryk@ap.com>
+;; Created: Fri Jun 16 17:23:11 2000
+;; Version: $Id$
+;; Keywords:
+
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as
+;; published by the Free Software Foundation; either version 2 of
+;; the License, or (at your option) any later version.
+
+;; This program is distributed in the hope that it will be
+;; useful, but WITHOUT ANY WARRANTY; without even the implied
+;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+;; PURPOSE.  See the GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public
+;; License along with this program; if not, write to the Free
+;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+;; MA 02111-1307 USA
+
+;;; Commentary:
+;;
+;; The speedbar mode provides support for texinfo files by creating
+;; tags using imenu.  This presentation do not reflect the natural
+;; hierarchy of the texinfo document.
+;;
+;; This small add-on to speedbar provides an alternate way to view the
+;; document which shows the natural hierarchy of the document.  This
+;; shows the same information that `M-x texinfo-show-structure'
+;; displays, but in the speedbar frame with the speedbar user
+;; interface.
+
+;; Installtation procedure:
+;;   Install speedbar 0.12 or later.
+;;   Add the following to your ~/.emacs file:
+;;   (eval-after-load "speedbar" '(load-library "sb-texinfo"))
+
+;; Known Problems:
+;;   Does not look inside files included via @include directive.
+;;
+;;   The indentations of nodes with and without subnodes could be better.
+;;
+;;   Clicking on nodes with subnodes only shows subnodes rather than
+;;   displaying the node content on the target frame.  Instead the first
+;;   subnode on the speedbar has to be clicked.  I believe this can be
+;;   fixed if a custom speedbar button display routine is written rather
+;;   than using the built-in function speedbar-insert-generic-list.
+;;   If I learn to do this, I will, but I make no promises.
+;;
+;;   Potential problem with auctex 9.9p users.  Auctex provides it's
+;;   own texinfo mode which does not use texinfo-mode-hook.  Make sure
+;;   you do not use texinfo mode provided by auctex!
+
+;;; Change Log:
+;;;
+;;; 1.6 - By Eric Ludlam <zappo@gnu.org>
+;;;       speedbar-insert-texinfo-list no longer sets sthm to nil.
+;;;       speedbar-format-texinfo-list uses new positioned group for
+;;;       any chapter w/ sections (etc)  Also set new
+;;;       speedbar-generic-list-{group-expand|tag}-button-list to
+;;;       nice values.
+;;;
+;;; 1.5 - speedbar-tag-hierarchy-method is set to nil by
+;;;       speedbar-insert-texinfo-list as well as
+;;;       speedbar-fetch-dynamic-texinfo.  This is needed in order to
+;;;       have the texinfo nodes displayed in correct order.
+;;;
+;;; 1.4 - speedbar-tag-hierarchy-method is now set to nil by
+;;;       speedbar-fetch-dynamic-texinfo after making it buffer local
+;;;       first.  I thought this was buffer-local variable alread, but
+;;;       it is not.  Also added installation instruction.
+;;;
+;;; 1.3 - Added bunch of comments in the code as well as installation
+;;;       instruction.  speedbar-texinfo-mode-hook now turns on the
+;;;       speedbar mode.
+;;;
+;;; 1.2 - Use newly created variable speedbar-texinfo-section-regexp rather
+;;;       than texinfo-section-types-regexp, because the latter does not
+;;;       have "top" in it.
+;;;
+;;;       Also added a hook to texinfo-mode-hook which sets
+;;;       speedbar-tag-hierarchy-method to nil at Eric Ludlam's
+;;;       suggestion.
+;;;
+;;; 1.1 - first draft sent to Eric. on June 16, 2000.
+
+;;; Code:
+
+(require 'speedbar)
+
+;; GNU Emacs 20.7 comes with speedbar 0.8.1 bundled which does not work
+;; with sb-texinfo.  Lacking speedbar-version variable, check whether
+;; speedbar-dynamic-tags-function-list is bound which was introduced after
+;; 0.8.1.
+(or (boundp 'speedbar-dynamic-tags-function-list)
+    (error "Speedbar 0.11 or newer is required to use sb-texinfo."))
+
+;; Attach these new functions to handle texinfo-mode.
+(add-to-list 'speedbar-dynamic-tags-function-list
+	     '(speedbar-fetch-dynamic-texinfo . speedbar-insert-texinfo-list))
+
+;; speedbar-texinfo-section-regexp is same as texinfo-section-types-regexp
+;; except that it has "top" entry.
+(defconst speedbar-texinfo-section-regexp
+  "^@\\(top \\|chapter \\|sect\\|subs\\|subh\\|unnum\\|major\\|chapheading \\|heading \\|appendix\\)")
+
+;; This returns t if the major mode of the current buffer is not 'texinfo-mode.
+;; If it is 'texinfo-mode, then this returns a list where each element is
+;; (LEVEL NAME . MARKER).
+;; LEVEL is 0, 1, 2, or 3 corresponding to chapter section,
+;; subsection, and subsubsection respectively.
+;; NAME is the name of the node.
+;; MARKER is emacs marker that points to the beginning of the node.
+;; The elements in the the list returned are in ascending order of the MARKER.
+;; This function along with it's parter, speedbar-insert-texinfo-list, are
+;; designed to be added to the speedbar-dynamic-tags-function-list list.
+(defun speedbar-fetch-dynamic-texinfo ( filename )
+  (if (not (eq major-mode 'texinfo-mode))
+      t
+    (condition-case nil
+	(save-excursion
+
+	  ;; Set speedbar-tag-hierarchy-method to nil so that 
+	  ;; speedbar-create-tag-hierarchy won't reorder the list.
+	  ;; Make it buffer local so that the global value is not touched.
+	  (make-local-variable 'speedbar-tag-hierarchy-method)
+	  (setq speedbar-tag-hierarchy-method nil)
+
+	  (set (make-local-variable
+		'speedbar-generic-list-group-expand-button-type)
+	       'expandtag)
+	  (set (make-local-variable
+		'speedbar-generic-list-tag-button-type)
+	       'statictag)
+
+	  (let ((heading-to-level
+		 '(("top" . 0)
+		   ("chapter" . 0) ("section" . 1)
+		   ("subsection" . 2) ("subsubsection" . 3)
+		   ("unnumbered" . 0) ("unnumberedsec" . 1)
+		   ("unnumberedsubsec" . 2) ("unnumberedsubsubsec" . 3)
+		   ("chapheading" . 0) ("heading" . 1)
+		   ("subheading" . 2) ("subsubheading" . 3)
+		   ("appendix" . 0) ("appendixsec" . 1)
+		   ("appendixsubsec" . 2) ("appendixsubsubsec" . 3)
+		   ("centerchap" . 0) ("majorheading" . 0)))
+		pos-beg title level section alist)
+	    ;; Create a list of all nodes
+	    (goto-char (point-min))
+	    (while (re-search-forward speedbar-texinfo-section-regexp nil t)
+	      (goto-char (1+ (match-beginning 0))) ;right after @
+	      (setq pos-beg (point-marker))
+	      (setq section (symbol-name (read (current-buffer))))
+	      (setq level (cdr (assoc section heading-to-level)))
+	      (setq title (buffer-substring
+			   (progn (skip-chars-forward " \t")
+				  (point))
+			   (progn (skip-chars-forward "^,\n")
+				  (skip-chars-backward " \t")
+				  (point))))
+	      (setq alist (cons (cons level (cons title pos-beg)) alist)))
+	    (nreverse alist)))
+      (error t))))
+
+;; See speedbar-fetch-dynamic-texinfo for description of LST.
+;; LEVEL should be 0 unless this is called recursively.
+;; This function converts LST from a flat list structure into
+;; a hierarchical list suitable to be passed on to speedbar-insert-texinfo-list.
+;; This function creates the hierarchical list recursively.
+;; On first pass all the nodes of each chapter are grouped into a list.
+;; Then each of these lists are recursively converted so that all nodes
+;; of each section are grouped together.
+(defun speedbar-format-texinfo-list ( lst level )
+  (let (new-list elem section-list)
+    (while lst
+      (setq section-list (list (cdr (car lst))))
+      (setq lst  (cdr lst))
+      (while (and lst (> (car (car lst)) level))
+	(setq section-list (cons (car lst) section-list))
+	(setq lst  (cdr lst)))
+      (setq new-list (cons (nreverse section-list) new-list)))
+    (setq new-list (nreverse new-list))
+    ;; Each member of new-list is a list of all chapters (on first pass), i.e.,
+    ;; ( ((chap1 marker) (1 sec1 marker) ...)  ((chap2 marker) ...) ... )
+
+    ;; Start recursion.
+    (setq level (1+ level))
+    (mapcar '(lambda (x)
+	       (if (eq (length x) 1)
+		   ;;(cons (car (car x)) x)
+		   (car x)
+		 (let ((head (car x)))
+		   (cons (car head)
+			 (cons (cdr head)
+			       (speedbar-format-texinfo-list (cdr x) level))))))
+	    new-list)))
+
+(defun speedbar-insert-texinfo-list (indent lst)
+  (speedbar-insert-generic-list indent (speedbar-format-texinfo-list lst indent)
+				'speedbar-tag-expand
+				'speedbar-tag-find))
+
+(provide 'sb-texinfo)
+;;; sb-texinfo.el ends here
+
 ;;; Copyright (C) 1996, 97, 98, 99, 00 Free Software Foundation
 
 ;; Author: Eric M. Ludlam <zappo@gnu.org>
-;; Version: 0.11
 ;; Keywords: file, tags, tools
 ;; X-RCS: $Id$
 
+(defvar speedbar-version "0.13"
+  "The current version of speedbar.")
+
 ;; This file is part of GNU Emacs.
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; 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.
-;;
-;;   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, such as "Tools", you can do this:
-;;
-;;   Emacs:
-;;   (define-key-after (lookup-key global-map [menu-bar tools])
-;;      [speedbar] '("Speedbar" . speedbar-frame-mode) [calendar])
-;;
-;;   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))]
-;;		      "--")
-;;
-;;   If you want to access speedbar using only the keyboard, do this:
-;;
-;;   (global-set-key [(f4)] 'speedbar-get-focus)
-;;
-;;   This will let you hit f4 (or whatever key you choose) to jump
-;; focus to the speedbar frame.  Pressing 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
 ;; `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.
+;; `dframe-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
 ;; Other filters could be easily added.
 ;;
 ;;    Users of XEmacs previous to 20 may want to change the default
-;; timeouts for `speedbar-update-speed' to something longer as XEmacs
+;; timeouts for `dframe-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.
 ;;
 ;; `speedbar-insert-generic-list'.  If you use
 ;; `speedbar-insert-generic-list', also read the doc for
 ;; `speedbar-tag-hierarchy-method' in case you wish to override it.
-;; The function `speedbar-with-attached-buffer' brings you back to the
+;; The function `dframe-with-attached-buffer' brings you back to the
 ;; buffer speedbar is displaying for.
 ;;
 ;; For those functions that make buttons, the "function" should be a
 
 (require 'assoc)
 (require 'easymenu)
-
-(condition-case nil
-    (require 'image)
-  (error nil))
-
-(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)))
-
-;; From custom web page for compatibility between versions of custom
-;; with help from ptype@dera.gov.uk (Proto Type)
-(eval-and-compile
-  (condition-case ()
-      (require 'custom)
-    (error nil))
-  (if (and (featurep 'custom) (fboundp 'custom-declare-variable)
-	   ;; Some XEmacsen w/ custom don't have :set keyword.
-	   ;; This protects them against custom.
-	   (fboundp 'custom-initialize-set))
-      nil ;; We've got what we needed
-    ;; We have the old custom-library, hack around it!
-    (if (boundp 'defgroup)
-	nil
-      (defmacro defgroup (&rest args)
-	nil))
-    (if (boundp 'defface)
-	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))
-	     ))))
-    (if (boundp 'defcustom)
-	nil
-      (defmacro defcustom (var value doc &rest args)
-	(` (defvar (, var) (, value) (, doc)))))))
+(require 'dframe)
+(require 'sb-image)
 
 ;; customization stuff
 (defgroup speedbar nil
   :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
 
 ;; 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.
-(defcustom speedbar-navigating-speed speedbar-update-speed
-  "*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)
+(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)
 				       (border-width . 0)
 				       (menu-bar-lines . 0)
+				       (tool-bar-lines . 0)
 				       (unsplittable . t))
   "*Parameters to use when creating the speedbar frame in Emacs.
 Any parameter supported by a frame may be added.  The parameter `height'
     (speedbar-fetch-dynamic-etags . speedbar-insert-etags-list))
   "Set to a 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
+is a funciotn 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 occured, 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-track-mouse-flag t
+(defcustom speedbar-track-mouse-flag (< emacs-major-version 21)
   "*Non-nil means to display info about the line under the mouse."
   :group 'speedbar
   :type 'boolean)
   "*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
+functions.  Each hook takes one argument LST, and may destructivly
 create a new list of the same form.  LST is a list of elements of the
 form:
   (ELT1 ELT2 ... ELTn)
   :group 'speedbar
   :type 'integer)
 
-(defcustom speedbar-activity-change-focus-flag nil
-  "*Non-nil means the selected frame will change based on activity.
-Thus, if a file is selected for edit, the buffer will appear in the
-selected frame and the focus will change to that frame."
-  :group 'speedbar
-  :type 'boolean)
-
 (defcustom speedbar-directory-button-trim-method 'span
   "*Indicates how the directory button will be displayed.
 Possible values are:
   :group 'speedbar
   :type 'boolean)
 
-(defcustom speedbar-use-images (and (or (fboundp 'defimage)
-					(fboundp 'make-image-specifier))
-				    (if (fboundp 'display-graphic-p)
-					(display-graphic-p)
-				      window-system))
-  "*Non nil if speedbar should display icons."
+(defcustom speedbar-before-popup-hook nil
+  "*Hooks called before popping up the speedbar frame."
   :group 'speedbar
-  :type 'boolean)
-
-(defcustom speedbar-before-popup-hook nil
+  :type 'hook)
+
+(defcustom speedbar-after-create-hook '(speedbar-frame-reposition-smartly)
   "*Hooks called before popping up the speedbar frame."
   :group 'speedbar
   :type 'hook)
 	  speedbar-ignored-path-regexp (speedbar-extension-list-to-regex
 					speedbar-ignored-path-expressions)))
 
-(defvar speedbar-update-flag (and
-			      (or (fboundp 'run-with-idle-timer)
-				  (fboundp 'start-itimer)
-				  (boundp 'post-command-idle-hook))
-			      (if (fboundp 'display-graphic-p)
-				  (display-graphic-p)
-				window-system))
+(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 speedbar is active, use:
   (suppress-keymap speedbar-key-map t)
 
   ;; control
+  (define-key speedbar-key-map "t" 'speedbar-toggle-updates)
   (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 "Q" 'delete-frame)
 
   ;; navigation
   (define-key speedbar-key-map "n" 'speedbar-next)
     (lambda () (interactive)
       (speedbar-change-initial-expansion-list "files")))
 
-  ;; Overrides
-  (substitute-key-definition 'switch-to-buffer
-			     'speedbar-switch-buffer-attached-frame
-			     speedbar-key-map global-map)
-
-  (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)
-	;; Info doc fix from Bob Weiner
-	(if (featurep 'infodoc)
-	    nil
-	  (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)
-
-    ;; 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)
-    ;; another handy place users might click to get our menu.
-    (define-key speedbar-key-map [mode-line down-mouse-1]
-      'speedbar-emacs-popup-kludge)
-
-    ;; We can't switch buffers with the buffer mouse menu.  Lets hack it.
-    (define-key speedbar-key-map [C-down-mouse-1] 'speedbar-hack-buffer-menu)
-
-    ;; Lastly, we want to track the mouse.  Play here
-    (define-key speedbar-key-map [mouse-movement] 'speedbar-track-mouse)
-   ))
+  (dframe-update-keymap speedbar-key-map)
+)
 
 (defun speedbar-make-specialized-keymap ()
   "Create a keymap for use w/ a speedbar major or minor display mode.
    (list
     ["Detach" speedbar-detach (and speedbar-frame
 				    (eq (selected-frame) speedbar-frame)) ]
-    ["Close" speedbar-close-frame t]
+    ["Close" dframe-close-frame t]
     ["Quit" delete-frame t] ))
   "Menu items appearing at the end of the speedbar menu.")
 
   "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.")
 
 ;;; Compatibility
 ;;
-(if (fboundp 'frame-parameter)
-
-    (defalias 'speedbar-frame-parameter 'frame-parameter)
-  
-  (defun speedbar-frame-parameter (frame parameter)
-    "Return FRAME's PARAMETER value."
-    (cdr (assoc parameter (frame-parameters frame)))))
-
 (if (fboundp 'make-overlay)
     (progn
       (defalias 'speedbar-make-overlay 'make-overlay)
 `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")
-  ;; 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
-		  ;; Only guess height if it is not specified.
-		  (if (member 'height speedbar-frame-plist)
-		      (make-frame speedbar-frame-plist)
-		    (make-frame (nconc (list 'height
-					     (speedbar-needed-height))
-				       speedbar-frame-plist)))
-		(let* ((mh (speedbar-frame-parameter nil 'menu-bar-lines))
-		       (cfx (speedbar-frame-parameter nil 'left))
-		       (cfy (speedbar-frame-parameter nil 'top))
-		       (cfw (frame-pixel-width))
-		       (params
-			;; Only add a guessed height if one is not specified
-			;; in the input parameters.
-			(if (assoc 'height speedbar-frame-parameters)
-			    speedbar-frame-parameters
-			  (append
-			   speedbar-frame-parameters
-			   (list (cons 'height (+ mh (frame-height)))))))
-		       (frame
-			(if (or (< emacs-major-version 20)
-				(not (eq window-system 'x)))
-			    (make-frame params)
-			  (let ((x-pointer-shape x-pointer-top-left-arrow)
-				(x-sensitive-text-pointer-shape
-				 x-pointer-hand2))
-			    (make-frame params)))))
-		  ;; Position speedbar frame.
-		  (if (or (not window-system) (eq window-system 'pc)
-			  (assoc 'left speedbar-frame-parameters)
-			  (assoc 'top speedbar-frame-parameters))
-		      ;; Do no positioning if not on a windowing system,
-		      ;; or if left/top were specified in the parameters.
-		      frame
-		    (let ((cfx
-			   (if (not (consp cfx))
-			       cfx
-			     ;; If cfx is a list, that means we grow
-			     ;; from a specific edge of the display.
-			     ;; Convert that to the distance from the
-			     ;; left side of the display.
-			     (if (eq (car cfx) '-)
-				 ;; A - means distance from the right edge
-				 ;; of the display, or DW - cfx - framewidth
-				 (- (x-display-pixel-width) (car (cdr cfx))
-				    (frame-pixel-width))
-			       (car (cdr cfx))))))
-		      (modify-frame-parameters
-		       frame
-		       (list
-			(cons
-			 'left
-			 ;; Decide which side to put it
-			 ;; on.  200 is just a buffer
-			 ;; for the left edge of the
-			 ;; screen.  The extra 10 is just
-			 ;; dressings for window decorations.
-			 (let ((sfw (frame-pixel-width frame)))
-			   (let ((left-guess (- cfx 10 sfw))
-				 (right-guess (+ cfx cfw 5)))
-			     (let ((left-margin left-guess)
-				   (right-margin
-				    (- (x-display-pixel-width)
-				       right-guess 5 sfw)))
-			       (cond ((>= left-margin 0) left-guess)
-				     ((>= right-margin 0) right-guess)
-				     ;; otherwise choose side we overlap less
-				     ((> left-margin right-margin) 0)
-				     (t (- (x-display-pixel-width) sfw 5)))))))
-			(cons 'top cfy)))
-		      frame)))))
-	;; 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))
-	(if (and (or (null window-system) (eq window-system 'pc))
-		 (fboundp 'set-frame-name))
-	    (progn
-	      (select-frame speedbar-frame)
-	      (set-frame-name "Speedbar")))
-	(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
+			 speedbar-frame-plist
+		       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)
+    )
+  (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)))
+	 )
+	((and (not dframe-xemacsp)
+	      (or (assoc 'left speedbar-frame-parameters)
+		  (assoc 'top speedbar-frame-parameters))
+	      ;; if left/top were specified in the parameters, do nothing.
+	      )
+	 )
+	(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)
-  (save-excursion
-    (set-buffer speedbar-buffer)
-    (rename-buffer (buffer-name) t)
-    (setq speedbar-buffer nil
-	  speedbar-frame nil
-	  speedbar-cached-frame nil)
-    ;; 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...
-    ))
+  (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))
 
 ;;;###autoload
 (defun speedbar-get-focus ()
 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)