]> code.delx.au - gnu-emacs/blobdiff - lisp/speedbar.el
Fix typo.
[gnu-emacs] / lisp / speedbar.el
index 2bd71901c9e532e2f524ef411e728e93b3ef0b6d..6e7cd69b2cd4780cbad70853d1587d508936e118 100644 (file)
@@ -1,9 +1,9 @@
-;;; speedbar --- quick access to files and tags in a frame
+;;; speedbar.el --- quick access to files and tags in a frame
 
-;;; Copyright (C) 1996, 97, 98, 99, 00 Free Software Foundation
+;;; Copyright (C) 1996, 97, 98, 99, 2000, 01 Free Software Foundation
 
 ;; Author: Eric M. Ludlam <zappo@gnu.org>
-;; Version: 0.11
+;; Version: 0.11a
 ;; Keywords: file, tags, tools
 
 ;; This file is part of GNU Emacs.
 ;; 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
+;; `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
+;; use the function `speedbar-add-ignored-path-regexp' to 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.
@@ -90,9 +90,9 @@
 ;; which controls how tags are layed out.  It is actually a list of
 ;; functions that filter the data.  The default groups large tag lists
 ;; into sub-lists.  A long flat list can be used instead if needed.
-;; Other filters could be easily added.
+;; Other filters can be easily added.
 ;;
-;;    AUC-TEX users: The imenu tags for AUC-TEX mode don't work very
+;;    AUC-TEX users: The imenu tags for AUC-TEX mode doesn't work very
 ;; well.  Use the imenu keywords from tex-mode.el for better results.
 ;;
 ;; This file requires the library package assoc (association lists)
 ;; Adding a speedbar specialized display mode:
 ;;
 ;; Speedbar can be configured to create a special display for certain
-;; modes that do not display tradition file/tag data.  Rmail, Info,
+;; modes that do not display traditional file/tag data.  Rmail, Info,
 ;; and the debugger are examples.  These modes can, however, benefit
 ;; from a speedbar style display in their own way.
 ;;
 ;; `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 macro `speedbar-with-attached-buffer' brings you back to the
 ;; buffer speedbar is displaying for.
 ;;
 ;; For those functions that make buttons, the "function" should be a
 ;; functions are `speedbar-change-expand-button-char',
 ;; `speedbar-delete-subblock', and `speedbar-center-buffer-smartly'.
 ;; The variable `speedbar-power-click' is set to t in your functions
-;; when the user shift-clicks.  This indications anything from
+;; when the user shift-clicks.  This is an indication of anything from
 ;; refreshing cached data to making a buffer appear in a new frame.
 ;;
 ;; If you wish to add to the default speedbar menu for the case of
 ;; splice in.  KEYMAP is a symbol holding the keymap to use, and
 ;; BUTTON-FUNCTIONS are the function names to call, in order, to create
 ;; the display.
-;;  Another tweekable variable is `speedbar-stealthy-function-list'
+;;  Another tweakable variable is `speedbar-stealthy-function-list'
 ;; which is of the form (NAME &rest FUNCTION ...).  NAME is the string
 ;; name matching `speedbar-add-expansion-list'.  (It does not need to
 ;; exist.). This provides additional display info which might be
 ;; time-consuming to calculate.
 ;;  Lastly, `speedbar-mode-functions-list' allows you to set special
-;; function overrides.  At the moment very few functions are
-;; over ridable, but more will be added as the need is discovered.
+;; function overrides.  At the moment very few functions may be
+;; overridden, but more will be added as the need is discovered.
 
 ;;; TODO:
 ;; - More functions to create buttons and options
@@ -298,6 +298,7 @@ effective when it's display is shown.")
   "Hooks run when speedbar visits a tag in the selected frame."
   :group 'speedbar
   :type 'hook
+  :version "21.1"
   :options '(speedbar-highlight-one-tag-line
             speedbar-recenter-to-top
             speedbar-recenter
@@ -311,6 +312,7 @@ effective when it's display is shown.")
 (defcustom speedbar-reconfigure-keymaps-hook nil
   "Hooks run when the keymaps are regenerated."
   :group 'speedbar
+  :version "21.1"
   :type 'hook)
 
 (defcustom speedbar-show-unknown-files nil
@@ -345,6 +347,7 @@ between different directories."
                                       (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'
@@ -394,7 +397,7 @@ tags to insert.  It will then create the speedbar buttons.")
   :type 'boolean)
 
 (defcustom speedbar-sort-tags nil
-  "*If Non-nil, sort tags in the speedbar display.  *Obsolete*."
+  "*If non-nil, sort tags in the speedbar display.  *Obsolete*."
   :group 'speedbar
   :type 'boolean)
 
@@ -411,7 +414,7 @@ form:
 where each ELT is of the form
   (TAG-NAME-STRING . NUMBER-OR-MARKER)
 or
-  (GROUP-NAME-STRING ELT1 EL2... ELTn)"
+  (GROUP-NAME-STRING ELT1 ELR2... ELTn)"
   :group 'speedbar
   :type 'hook
   :options '(speedbar-sort-tag-hierarchy
@@ -480,18 +483,23 @@ hierarchy would be replaced with the new directory."
 (defcustom speedbar-indentation-width 1
   "*When sub-nodes are expanded, the number of spaces used for indentation."
   :group 'speedbar
+  :version "21.1"
   :type 'integer)
 
 (defcustom speedbar-hide-button-brackets-flag nil
   "*Non-nil means speedbar will hide the brackets around the + or -."
   :group 'speedbar
+  :version "21.1"
   :type 'boolean)
 
 (defcustom speedbar-use-images (and (or (fboundp 'defimage)
                                        (fboundp 'make-image-specifier))
-                                   window-system)
+                                   (if (fboundp 'display-graphic-p)
+                                       (display-graphic-p)
+                                     window-system))
   "*Non nil if speedbar should display icons."
   :group 'speedbar
+  :version "21.1"
   :type 'boolean)
 
 (defcustom speedbar-before-popup-hook nil
@@ -663,7 +671,7 @@ It is generated from the variable `completion-ignored-extensions'")
   (append '(".[ch]\\(\\+\\+\\|pp\\|c\\|h\\|xx\\)?" ".tex\\(i\\(nfo\\)?\\)?"
            ".el" ".emacs" ".l" ".lsp" ".p" ".java" ".f\\(90\\|77\\|or\\)?")
          (if speedbar-use-imenu-flag
-             '(".ada" ".p[lm]" ".tcl" ".m" ".scm" ".pm" ".py"
+             '(".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"
@@ -677,6 +685,7 @@ function `speedbar-add-supported-extension' to add a new extension at
 runtime, or use the configuration dialog to set it in your .emacs
 file."
   :group 'speedbar
+  :version "21.1"
   :type '(repeat (regexp :tag "Extension Regexp"))
   :set (lambda (sym val)
         (setq speedbar-supported-extension-expressions val
@@ -695,7 +704,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 "sExtionsion: ")
+  (interactive "sExtension: ")
   (if (not (listp extension)) (setq extension (list extension)))
   (while extension
     (if (member (car extension) speedbar-supported-extension-expressions)
@@ -733,7 +742,9 @@ PATH-EXPRESSION to `speedbar-ignored-path-expressions'."
                              (or (fboundp 'run-with-idle-timer)
                                  (fboundp 'start-itimer)
                                  (boundp 'post-command-idle-hook))
-                             window-system)
+                             (if (fboundp 'display-graphic-p)
+                                 (display-graphic-p)
+                               window-system))
   "*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:
@@ -869,16 +880,20 @@ This basically creates a sparse keymap, and makes it's parent be
   )
 
 (defvar speedbar-easymenu-definition-base
-  `("Speedbar"
-    ["Update" speedbar-refresh t]
-    ["Auto Update" speedbar-toggle-updates
-     :style toggle :selected speedbar-update-flag]
-    ,(if (and (or (fboundp 'defimage)
-                 (fboundp 'make-image-specifier))
-             window-system)
-        ["Use Images" speedbar-toggle-images
-         :style toggle :selected speedbar-use-images])
-    )
+  (append
+   '("Speedbar"
+     ["Update" speedbar-refresh t]
+     ["Auto Update" speedbar-toggle-updates
+      :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
@@ -1262,7 +1277,6 @@ in the selected file.
                               (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
@@ -1273,13 +1287,10 @@ in the selected file.
     (toggle-read-only 1)
     (speedbar-set-mode-line-format)
     (if speedbar-xemacsp
-       (progn
-         (make-local-variable 'mouse-motion-handler)
-         (setq mouse-motion-handler 'speedbar-track-mouse-xemacs))
+       (set (make-local-variable 'mouse-motion-handler)
+            'speedbar-track-mouse-xemacs)
       (if speedbar-track-mouse-flag
-         (progn
-           (make-local-variable 'track-mouse)
-           (setq track-mouse t)))      ;this could be messy.
+         (set (make-local-variable 'track-mouse) t))   ;this could be messy.
       (setq auto-show-mode nil))       ;no auto-show for Emacs
     (run-hooks 'speedbar-mode-hook))
   (speedbar-update-contents)
@@ -1712,7 +1723,7 @@ This should be bound to a mouse EVENT."
   (speedbar-item-info))
 
 (defun speedbar-generic-item-info ()
-  "Attempt to derive, and then display information about thils line item.
+  "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)
@@ -1913,13 +1924,13 @@ variable `speedbar-obj-alist'."
     (speedbar-enable-update)))
 
 (defun speedbar-toggle-images ()
-  "Toggle automatic update for the speedbar frame."
+  "Toggle images for the speedbar frame."
   (interactive)
   (setq speedbar-use-images (not speedbar-use-images))
   (speedbar-refresh))
 
 (defun speedbar-toggle-sorting ()
-  "Toggle automatic update for the speedbar frame."
+  "Toggle sorting for the speedbar frame."
   (interactive)
   (setq speedbar-sort-tags (not speedbar-sort-tags)))
 
@@ -2009,14 +2020,19 @@ If PREVLINE, then put this button on the previous line.
 This is a convenience function for special mode that create their own
 specialized speedbar displays."
   (goto-char (point-max))
-  (if (/= (current-column) 0) (insert "\n"))
-  (if prevline (progn (delete-char -1) (insert " "))) ;back up if desired...
+  (let ((start (point)))
+    (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) 'invisible nil)
     (put-text-property start (point) 'mouse-face nil)))
 
 (defun speedbar-make-button (start end face mouse function &optional token)
@@ -2373,8 +2389,8 @@ 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)))
        )))
 
 (defun speedbar-sort-tag-hierarchy (lst)
@@ -2857,7 +2873,7 @@ If new functions are added, their state needs to be updated here."
   (goto-char (point-min))
   (let ((m nil))
     (while (and (setq m (re-search-forward
-                        (concat " \\(" (file-name-nondirectory file)
+                        (concat " \\(" (regexp-quote (file-name-nondirectory file))
                                 "\\)\\(" speedbar-indicator-regex "\\)?\n")
                         nil t))
                (not (string= file
@@ -3278,7 +3294,9 @@ directory, then it is the directory name."
       (if f
          (let* ((depth (string-to-int (match-string 1)))
                 (path (speedbar-line-path depth)))
-           (concat path f))
+           (if (file-exists-p (concat path f))
+               (concat path f)
+             nil))
        nil))))
 
 (defun speedbar-goto-this-file (file)
@@ -3397,7 +3415,7 @@ directory with these items."
          nil))
       (speedbar-do-function-pointer)))
 
-(defun speedbar-expand-line (arg)
+(defun speedbar-expand-line (&optional arg)
   "Expand the line under the cursor.
 With universal argument ARG, flush cached data."
   (interactive "P")
@@ -4014,13 +4032,20 @@ If TEMP is non-nil, then clicking on a buffer restores the previous display."
 (defun speedbar-buffers-line-path (&optional depth)
   "Fetch the full path to the file (buffer) specified on the current line.
 Optional argument DEPTH specifies the current depth of the back search."
-  (end-of-line)
-  ;; 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 (file-name-directory (buffer-file-name buffer))))))
+  (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)))
+                 (file-name-directory (buffer-file-name buffer))
+               (buffer-file-name buffer))))))))
 
 (defun speedbar-buffer-click (text token indent)
   "When the users clicks on a buffer-button in speedbar.
@@ -4105,7 +4130,7 @@ TEXT is the buffer's name, TOKEN and INDENT are unused."
 
 (defun speedbar-recenter ()
   "Recenter the current buffer so POINT is in the center of the window."
-  (recenter (window-hight (/ (selected-window) 2))))
+  (recenter (/ (window-height (selected-window)) 2)))
 
 \f
 ;;; Color loading section.
@@ -4121,7 +4146,7 @@ TEXT is the buffer's name, TOKEN and INDENT are unused."
                               (:foreground "cyan4"))
                              (((class color) (background dark))
                               (:foreground "cyan"))
-                             (t (:bold t)))
+                             (t (:weight bold)))
   "Face used for file names."
   :group 'speedbar-faces)
 
@@ -4213,36 +4238,36 @@ IMAGESPEC is the image data, and DOCSTRING is documentation for the image."
 
 )))
 
-(defimage-speedbar speedbar-directory-+
-  ((:type xpm :file "sb-dir+.xpm" :ascent center))
+(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--
-  ((:type xpm :file "sb-dir-.xpm" :ascent center))
+(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-file-+
-  ((:type xpm :file "sb-file+.xpm" :ascent center))
+(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-file--
-  ((:type xpm :file "sb-file-.xpm" :ascent center))
+(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-file-
-  ((:type xpm :file "sb-file.xpm" :ascent center))
+(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-
+(defimage-speedbar speedbar-tag
   ((:type xpm :file "sb-tag.xpm" :ascent center))
   "Image used for tags.")
 
-(defimage-speedbar speedbar-tag-+
-  ((:type xpm :file "sb-tag+.xpm" :ascent center))
+(defimage-speedbar speedbar-tag-plus
+  ((:type xpm :file "sb-tag-plus.xpm" :ascent center))
   "Image used for closed tag groups.")
 
-(defimage-speedbar speedbar-tag--
-  ((:type xpm :file "sb-tag-.xpm" :ascent center))
+(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
@@ -4262,18 +4287,18 @@ IMAGESPEC is the image data, and DOCSTRING is documentation for the image."
   "Image used for open tag groups.")
 
 (defvar speedbar-expand-image-button-alist
-  '(("<+>" . speedbar-directory-+)
-    ("<->" . speedbar-directory--)
-    ("[+]" . speedbar-file-+)
-    ("[-]" . speedbar-file--)
-    ("[?]" . speedbar-file-)
-    ("{+}" . speedbar-tag-+)
-    ("{-}" . speedbar-tag--)
+  '(("<+>" . 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)
     (" +>" . speedbar-tag-gt)
     (" ->" . speedbar-tag-v)
-    (">" . speedbar-tag-)
+    (">" . speedbar-tag)
     ("@" . speedbar-tag-type)
     ("  @" . speedbar-tag-type)
     )
@@ -4292,7 +4317,7 @@ If we have an image associated with it, use that image."
        ;; 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)
+           (if (featurep 'xemacs)
                (add-text-properties (+ start (length bt)) start
                                     (list 'end-glyph (symbol-value (cdr a))
                                           'rear-nonsticky (list 'display)
@@ -4311,7 +4336,8 @@ If we have an image associated with it, use that image."
            (def-edebug-spec speedbar-with-writable def-body)))
 
 (provide 'speedbar)
-;;; speedbar ends here
 
 ;; run load-time hooks
 (run-hooks 'speedbar-load-hook)
+
+;;; speedbar.el ends here