1 ;;; speedbar --- quick access to files and tags in a frame
3 ;;; Copyright (C) 1996, 97, 98, 99 Free Software Foundation
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
7 ;; Keywords: file, tags, tools
8 ;; X-RCS: $Id: speedbar.el,v 1.19 1999/01/23 13:23:26 zappo Exp rms $
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 ;; The speedbar provides a frame in which files, and locations in
30 ;; files are displayed. These items can be clicked on with mouse-2
31 ;; in order to make the last active frame display that file location.
35 ;; If speedbar came to you as a part of Emacs, simply type
36 ;; `M-x speedbar', and it will be autoloaded for you.
38 ;; If speedbar is not a part of your distribution, then add
39 ;; this to your .emacs file:
41 ;; (autoload 'speedbar-frame-mode "speedbar" "Popup a speedbar frame" t)
42 ;; (autoload 'speedbar-get-focus "speedbar" "Jump to speedbar frame" t)
44 ;; If you want to choose it from a menu, such as "Tools", you can do this:
47 ;; (define-key-after (lookup-key global-map [menu-bar tools])
48 ;; [speedbar] '("Speedbar" . speedbar-frame-mode) [calendar])
51 ;; (add-menu-button '("Tools")
52 ;; ["Speedbar" speedbar-frame-mode
54 ;; :selected (and (boundp 'speedbar-frame)
55 ;; (frame-live-p speedbar-frame)
56 ;; (frame-visible-p speedbar-frame))]
59 ;; If you want to access speedbar using only the keyboard, do this:
61 ;; (global-set-key [(f4)] 'speedbar-get-focus)
63 ;; This will let you hit f4 (or whatever key you choose) to jump
64 ;; focus to the speedbar frame. Pressing it again will bring you back
65 ;; to the attached frame. Pressing RET or e to jump to a file
66 ;; or tag will move you back to the attached frame. The command
67 ;; `speedbar-get-focus' will also create a speedbar frame if it does
70 ;; Customizing Speedbar:
72 ;; Once a speedbar frame is active, it takes advantage of idle time
73 ;; to keep its contents updated. The contents is usually a list of
74 ;; files in the directory of the currently active buffer. When
75 ;; applicable, tags in the active file can be expanded.
77 ;; To add new supported files types into speedbar, use the function
78 ;; `speedbar-add-supported-extension' If speedbar complains that the
79 ;; file type is not supported, that means there is no built in
80 ;; support from imenu, and the etags part wasn't set up correctly. You
81 ;; may add elements to `speedbar-supported-extension-expressions' as long
82 ;; as it is done before speedbar is loaded.
84 ;; To prevent speedbar from following you into certain directories
85 ;; use the function `speedbar-add-ignored-path-regexp' too add a new
86 ;; regular expression matching a type of path. You may add list
87 ;; elements to `speedbar-ignored-path-expressions' as long as it is
88 ;; done before speedbar is loaded.
90 ;; To add new file types to imenu, see the documentation in the
91 ;; file imenu.el that comes with Emacs. To add new file types which
92 ;; etags supports, you need to modify the variable
93 ;; `speedbar-fetch-etags-parse-list'.
95 ;; If the updates are going too slow for you, modify the variable
96 ;; `speedbar-update-speed' to a longer idle time before updates.
98 ;; If you navigate directories, you will probably notice that you
99 ;; will navigate to a directory which is eventually replaced after
100 ;; you go back to editing a file (unless you pull up a new file.)
101 ;; The delay time before this happens is in
102 ;; `speedbar-navigating-speed', and defaults to 10 seconds.
104 ;; To enable mouse tracking with information in the minibuffer of
105 ;; the attached frame, use the variable `speedbar-track-mouse-flag'.
107 ;; Tag layout can be modified through `speedbar-tag-hierarchy-method',
108 ;; which controls how tags are layed out. It is actually a list of
109 ;; functions that filter the data. The default groups large tag lists
110 ;; into sub-lists. A long flat list can be used instead if needed.
111 ;; Other filters could be easily added.
113 ;; Users of XEmacs previous to 20 may want to change the default
114 ;; timeouts for `speedbar-update-speed' to something longer as XEmacs
115 ;; doesn't have idle timers, the speedbar timer keeps going off
116 ;; arbitrarily while you're typing. It's quite pesky.
118 ;; Users of really old emacsen without the needed timers will not
119 ;; have speedbar updating automatically. Use "r" to refresh the
120 ;; display after changing directories. Remember, do not interrupt the
121 ;; stealthy updates or your display may not be completely refreshed.
123 ;; AUC-TEX users: The imenu tags for AUC-TEX mode don't work very
124 ;; well. Use the imenu keywords from tex-mode.el for better results.
126 ;; This file requires the library package assoc (association lists)
127 ;; and the package custom (for easy configuration of speedbar)
128 ;; http://www.dina.kvl.dk/~abraham/custom/
130 ;;; Developing for speedbar
132 ;; Adding a speedbar specialized display mode:
134 ;; Speedbar can be configured to create a special display for certain
135 ;; modes that do not display tradition file/tag data. Rmail, Info,
136 ;; and the debugger are examples. These modes can, however, benefit
137 ;; from a speedbar style display in their own way.
139 ;; If your `major-mode' is `foo-mode', the only requirement is to
140 ;; create a function called `foo-speedbar-buttons' which takes one
141 ;; argument, BUFFER. BUFFER will be the buffer speedbar wants filled.
142 ;; In `foo-speedbar-buttons' there are several functions that make
143 ;; building a speedbar display easy. See the documentation for
144 ;; `speedbar-with-writable' (needed because the buffer is usually
145 ;; read-only) `speedbar-make-tag-line', `speedbar-insert-button', and
146 ;; `speedbar-insert-generic-list'. If you use
147 ;; `speedbar-insert-generic-list', also read the doc for
148 ;; `speedbar-tag-hierarchy-method' in case you wish to override it.
149 ;; The function `speedbar-with-attached-buffer' brings you back to the
150 ;; buffer speedbar is displaying for.
152 ;; For those functions that make buttons, the "function" should be a
153 ;; symbol that is the function to call when clicked on. The "token"
154 ;; is extra data you can pass along. The "function" must take three
155 ;; parameters. They are (TEXT TOKEN INDENT). TEXT is the text of the
156 ;; button clicked on. TOKEN is the data passed in when you create the
157 ;; button. INDENT is an indentation level, or 0. You can store
158 ;; indentation levels with `speedbar-make-tag-line' which creates a
159 ;; line with an expander (eg. [+]) and a text button.
161 ;; Some useful functions when writing expand functions, and click
162 ;; functions are `speedbar-change-expand-button-char',
163 ;; `speedbar-delete-subblock', and `speedbar-center-buffer-smartly'.
164 ;; The variable `speedbar-power-click' is set to t in your functions
165 ;; when the user shift-clicks. This indications anything from
166 ;; refreshing cached data to making a buffer appear in a new frame.
168 ;; If you wish to add to the default speedbar menu for the case of
169 ;; `foo-mode', create a variable `foo-speedbar-menu-items'. This
170 ;; should be a list compatible with the `easymenu' package. It will
171 ;; be spliced into the main menu. (Available with click-mouse-3). If
172 ;; you wish to have extra key bindings in your special mode, create a
173 ;; variable `foo-speedbar-key-map'. Instead of using `make-keymap',
174 ;; or `make-sparse-keymap', use the function
175 ;; `speedbar-make-specialized-keymap'. This lets you inherit all of
176 ;; speedbar's default bindings with low overhead.
178 ;; Adding a speedbar top-level display mode:
180 ;; Unlike the specialized modes, there are no name requirements,
181 ;; however the methods for writing a button display, menu, and keymap
182 ;; are the same. Once you create these items, you can call the
183 ;; function `speedbar-add-expansion-list'. It takes one parameter
184 ;; which is a list element of the form (NAME MENU KEYMAP &rest
185 ;; BUTTON-FUNCTIONS). NAME is a string that will show up in the
186 ;; Displays menu item. MENU is a symbol containing the menu items to
187 ;; splice in. KEYMAP is a symbol holding the keymap to use, and
188 ;; BUTTON-FUNCTIONS are the function names to call, in order, to create
192 ;; - More functions to create buttons and options
193 ;; - Timeout directories we haven't visited in a while.
194 ;; - Remeber tags when refreshing the display. (Refresh tags too?)
195 ;; - More 'special mode support.
200 (defvar speedbar-xemacsp (string-match "XEmacs" emacs-version)
201 "Non-nil if we are running in the XEmacs environment.")
202 (defvar speedbar-xemacs20p (and speedbar-xemacsp
203 (= emacs-major-version 20)))
205 ;; From custom web page for compatibility between versions of custom:
210 (if (and (featurep 'custom) (fboundp 'custom-declare-variable)
211 ;; Some XEmacsen w/ custom don't have :set keyword.
212 ;; This protects them against custom.
213 (fboundp 'custom-initialize-set))
214 nil ;; We've got what we needed
215 ;; We have the old custom-library, hack around it!
216 (defmacro defgroup (&rest args)
218 (defmacro defface (var values doc &rest args)
220 (defvar (, var) (quote (, var)))
221 ;; To make colors for your faces you need to set your .Xdefaults
222 ;; or set them up ahead of time in your .emacs file.
225 (defmacro defcustom (var value doc &rest args)
226 (` (defvar (, var) (, value) (, doc))))))
228 ;; customization stuff
229 (defgroup speedbar nil
230 "File and tag browser frame."
236 (defgroup speedbar-faces nil
237 "Faces used in speedbar."
242 (defgroup speedbar-vc nil
243 "Version control display in speedbar."
248 (defvar speedbar-initial-expansion-mode-alist
249 '(("buffers" speedbar-buffer-easymenu-definition speedbar-buffers-key-map
250 speedbar-buffer-buttons)
251 ("quick buffers" speedbar-buffer-easymenu-definition speedbar-buffers-key-map
252 speedbar-buffer-buttons-temp)
253 ;; Files last, means first in the Displays menu
254 ("files" speedbar-easymenu-definition-special speedbar-file-key-map
255 speedbar-directory-buttons speedbar-default-directory-list)
257 "List of named expansion elements for filling the speedbar frame.
258 These expansion lists are only valid for regular files. Special modes
259 still get to override this list on a mode-by-mode basis. This list of
260 lists is of the form (NAME MENU KEYMAP FN1 FN2 ...). NAME is a string
261 representing the types of things to be displayed. MENU is an easymenu
262 structure used when in this mode. KEYMAP is a local keymap to install
263 over the regular speedbar keymap. FN1 ... are functions that will be
264 called in order. These functions will always get the default
265 directory to use passed in as the first parameter, and a 0 as the
266 second parameter. The 0 indicates the uppermost indentation level.
267 They must assume that the cursor is at the position where they start
270 (defvar speedbar-initial-expansion-list-name "files"
271 "A symbol name representing the expansion list to use.
272 The expansion list `speedbar-initial-expansion-mode-alist' contains
273 the names and associated functions to use for buttons in speedbar.")
275 (defvar speedbar-previously-used-expansion-list-name "files"
276 "Save the last expansion list method.
277 This is used for returning to a previous expansion list method when
278 the user is done with the current expansion list.")
280 (defvar speedbar-stealthy-function-list
282 speedbar-update-current-file speedbar-check-vc speedbar-check-objects)
284 "List of functions to periodically call stealthily.
285 This list is of the form:
286 '( (\"NAME\" FUNCTION ...)
288 where NAME is the name of the major display mode these functions are
289 for, and the remaining elements FUNCTION are functions to call in order.
290 Each function must return nil if interrupted, or t if completed.
291 Stealthy functions which have a single operation should always return
292 t. Functions which take a long time should maintain a state (where
293 they are in their speedbar related calculations) and permit
294 interruption. See `speedbar-check-vc' as a good example.")
296 (defvar speedbar-mode-functions-list
297 '(("files" (speedbar-item-info . speedbar-files-item-info)
298 (speedbar-line-path . speedbar-files-line-path))
299 ("buffers" (speedbar-item-info . speedbar-buffers-item-info)
300 (speedbar-line-path . speedbar-buffers-line-path))
301 ("quick buffers" (speedbar-item-info . speedbar-buffers-item-info)
302 (speedbar-line-path . speedbar-buffers-line-path))
304 "List of function tables to use for different major display modes.
305 It is not necessary to define any functions for a specialized mode.
306 This just provides a simple way of adding lots of customizations.
307 Each sublist is of the form:
308 (\"NAME\" (FUNCTIONSYMBOL . REPLACEMENTFUNCTION) ...)
309 Where NAME is the name of the specialized mode. The rest of the list
310 is a set of dotted pairs of the form FUNCTIONSYMBOL, which is the name
311 of a function you would like to replace, and REPLACEMENTFUNCTION,
312 which is a function you can call instead. Not all functions can be
313 replaced this way. Replaceable functions must provide that
314 functionality individually.")
316 (defcustom speedbar-mode-specific-contents-flag t
317 "*Non-nil means speedbar will show special mode contents.
318 This permits some modes to create customized contents for the speedbar
323 (defvar speedbar-special-mode-expansion-list nil
324 "Default function list for creating specialized button lists.
325 This list is set by modes that wish to have special speedbar displays.
326 The list is of function names. Each function is called with one
327 parameter BUFFER, the originating buffer. The current buffer is the
330 (defvar speedbar-special-mode-key-map nil
331 "Default keymap used when identifying a specialized display mode.
332 This keymap is local to each buffer that wants to define special keybindings
333 effective when it's display is shown.")
335 (defcustom speedbar-visiting-file-hook nil
336 "Hooks run when speedbar visits a file in the selected frame."
340 (defcustom speedbar-visiting-tag-hook nil
341 "Hooks run when speedbar visits a tag in the selected frame."
345 (defcustom speedbar-load-hook nil
346 "Hooks run when speedbar is loaded."
350 (defcustom speedbar-show-unknown-files nil
351 "*Non-nil show files we can't expand with a ? in the expand button.
352 nil means don't show the file in the list."
356 (defcustom speedbar-update-speed
358 (if speedbar-xemacs20p
359 2 ; 1 is too obrusive in XEmacs
360 5) ; when no idleness, need long delay
362 "*Idle time in seconds needed before speedbar will update itself.
363 Updates occur to allow speedbar to display directory information
364 relevant to the buffer you are currently editing."
368 ;; When I moved to a repeating timer, I had the horrible missfortune
369 ;; of loosing the ability for adaptive speed choice. This update
370 ;; speed currently causes long delays when it should have been turned off.
371 (defcustom speedbar-navigating-speed speedbar-update-speed
372 "*Idle time to wait after navigation commands in speedbar are executed.
373 Navigation commands included expanding/contracting nodes, and moving
374 between different directories."
378 (defcustom speedbar-frame-parameters '((minibuffer . nil)
383 "*Parameters to use when creating the speedbar frame in Emacs.
384 Parameters not listed here which will be added automatically are
385 `height' which will be initialized to the height of the frame speedbar
388 :type '(repeat (sexp :tag "Parameter:")))
390 ;; These values by Hrvoje Niksic <hniksic@srce.hr>
391 (defcustom speedbar-frame-plist
392 '(minibuffer nil width 20 border-width 0
393 internal-border-width 0 unsplittable t
394 default-toolbar-visible-p nil has-modeline-p nil
395 menubar-visible-p nil)
396 "*Parameters to use when creating the speedbar frame in XEmacs.
397 Parameters not listed here which will be added automatically are
398 `height' which will be initialized to the height of the frame speedbar
401 :type '(repeat (group :inline t
402 (symbol :tag "Property")
403 (sexp :tag "Value"))))
405 (defcustom speedbar-use-imenu-flag (stringp (locate-library "imenu"))
406 "*Non-nil means use imenu for file parsing. nil to use etags.
407 XEmacs prior to 20.4 doesn't support imenu, therefore the default is to
408 use etags instead. Etags support is not as robust as imenu support."
413 (defcustom speedbar-track-mouse-flag t
414 "*Non-nil means to display info about the line under the mouse."
418 (defcustom speedbar-sort-tags nil
419 "*If Non-nil, sort tags in the speedbar display. *Obsolete*."
423 (defcustom speedbar-tag-hierarchy-method
424 '(prefix-group trim-words)
425 "*List of methods which speedbar will use to organize tags into groups.
426 Groups are defined as expandable meta-tags. Imenu supports such
427 things in some languages, such as separating variables from functions.
428 Available methods are:
429 sort - Sort tags. (sometimes unnecessary)
430 trim-words - Trim all tags by a common prefix, broken @ word sections.
431 prefix-group - Try to guess groups by prefix.
432 simple-group - If imenu already returned some meta groups, stick all
433 tags that are not in a group into a sub-group."
437 (const :tag "Sort the tags." sort)
438 (const :tag "Trim words to common prefix." trim-words)
439 (const :tag "Create groups from common prefixes." prefix-group)
440 (const :tag "Group loose tags into their own group." simple-group))
443 (defcustom speedbar-tag-group-name-minimum-length 4
444 "*The minimum length of a prefix group name before expanding.
445 Thus, if the `speedbar-tag-hierarchy-method' includes `prefix-group'
446 and one such groups common characters is less than this number of
447 characters, then the group name will be changed to the form of:
451 This way we won't get silly looking listings."
455 (defcustom speedbar-tag-split-minimum-length 20
456 "*Minimum length before we stop trying to create sub-lists in tags.
457 This is used by all tag-hierarchy methods that break large lists into
462 (defcustom speedbar-tag-regroup-maximum-length 10
463 "*Maximum length of submenus that are regrouped.
464 If the regrouping option is used, then if two or more short subgroups
465 are next to each other, then they are combined until this number of
470 (defcustom speedbar-activity-change-focus-flag nil
471 "*Non-nil means the selected frame will change based on activity.
472 Thus, if a file is selected for edit, the buffer will appear in the
473 selected frame and the focus will change to that frame."
477 (defcustom speedbar-directory-button-trim-method 'span
478 "*Indicates how the directory button will be displayed.
480 'span - span large directories over multiple lines.
481 'trim - trim large directories to only show the last few.
484 :type '(radio (const :tag "Span large directories over mutiple lines."
486 (const :tag "Trim large directories to only show the last few."
488 (const :tag "No trimming." nil)))
490 (defcustom speedbar-smart-directory-expand-flag t
491 "*Non-nil means speedbar should use smart expansion.
492 Smart expansion only affects when speedbar wants to display a
493 directory for a file in the attached frame. When smart expansion is
494 enabled, new directories which are children of a displayed directory
495 are expanded in the current framework. If nil, then the current
496 hierarchy would be replaced with the new directory."
500 (defvar speedbar-hide-button-brackets-flag nil
501 "*Non-nil means speedbar will hide the brackets around the + or -.")
503 (defcustom speedbar-before-popup-hook nil
504 "*Hooks called before popping up the speedbar frame."
508 (defcustom speedbar-before-delete-hook nil
509 "*Hooks called before deleting the speedbar frame."
513 (defcustom speedbar-mode-hook nil
514 "*Hooks called after creating a speedbar buffer."
518 (defcustom speedbar-timer-hook nil
519 "*Hooks called after running the speedbar timer function."
523 (defcustom speedbar-verbosity-level 1
524 "*Verbosity level of the speedbar. 0 means say nothing.
525 1 means medium level verbosity. 2 and higher are higher levels of
530 (defvar speedbar-indicator-separator " "
531 "String separating file text from indicator characters.")
533 (defcustom speedbar-vc-do-check t
534 "*Non-nil check all files in speedbar to see if they have been checked out.
535 Any file checked out is marked with `speedbar-vc-indicator'"
539 (defvar speedbar-vc-indicator "*"
540 "Text used to mark files which are currently checked out.
541 Currently only RCS is supported. Other version control systems can be
542 added by examining the function `speedbar-this-file-in-vc' and
543 `speedbar-vc-check-dir-p'")
545 (defcustom speedbar-vc-path-enable-hook nil
546 "*Return non-nil if the current path should be checked for Version Control.
547 Functions in this hook must accept one parameter which is the path
552 (defcustom speedbar-vc-in-control-hook nil
553 "*Return non-nil if the specified file is under Version Control.
554 Functions in this hook must accept two parameters. The PATH of the
555 current file, and the FILENAME of the file being checked."
559 (defvar speedbar-vc-to-do-point nil
560 "Local variable maintaining the current version control check position.")
562 (defcustom speedbar-obj-do-check t
563 "*Non-nil check all files in speedbar to see if they have an object file.
564 Any file checked out is marked with `speedbar-obj-indicator', and the
565 marking is based on `speedbar-obj-alist'"
569 (defvar speedbar-obj-to-do-point nil
570 "Local variable maintaining the current version control check position.")
572 (defvar speedbar-obj-indicator '("#" . "!")
573 "Text used to mark files that have a corresponding hidden object file.
574 The car is for an up-to-date object. The cdr is for an out of date object.
575 The expression `speedbar-obj-alist' defines who gets tagged.")
577 (defvar speedbar-obj-alist
578 '(("\\.\\([cpC]\\|cpp\\|cc\\)$" . ".o")
580 ("\\.java$" . ".class")
581 ("\\.f\\(or\\|90\\|77\\)?$" . ".o")
583 ("\\.texi$" . ".info"))
584 "Alist of file extensions, and their corresponding object file type.")
586 (defvar speedbar-indicator-regex
587 (concat (regexp-quote speedbar-indicator-separator)
589 (regexp-quote speedbar-vc-indicator)
591 (regexp-quote (car speedbar-obj-indicator))
593 (regexp-quote (cdr speedbar-obj-indicator))
595 "Regular expression used when identifying files.
596 Permits stripping of indicator characters from a line.")
598 (defcustom speedbar-scanner-reset-hook nil
599 "*Hook called whenever generic scanners are reset.
600 Set this to implement your own scanning / rescan safe functions with
605 (defvar speedbar-ignored-modes nil
606 "*List of major modes which speedbar will not switch directories for.")
608 (defun speedbar-extension-list-to-regex (extlist)
609 "Takes EXTLIST, a list of extensions and transforms it into regexp.
610 All the preceding `.' are stripped for an optimized expression starting
611 with `.' followed by extensions, followed by full-filenames."
612 (let ((regex1 nil) (regex2 nil))
614 (if (= (string-to-char (car extlist)) ?.)
615 (setq regex1 (concat regex1 (if regex1 "\\|" "")
616 (substring (car extlist) 1)))
617 (setq regex2 (concat regex2 (if regex2 "\\|" "") (car extlist))))
618 (setq extlist (cdr extlist)))
619 ;; concat all the sub-exressions together, making sure all types
620 ;; of parts exist during concatination.
622 (if regex1 (concat "\\(\\.\\(" regex1 "\\)\\)") "")
623 (if (and regex1 regex2) "\\|" "")
624 (if regex2 (concat "\\(" regex2 "\\)") "")
627 (defvar speedbar-ignored-path-regexp nil
628 "Regular expression matching paths speedbar will not switch to.
629 Created from `speedbar-ignored-path-expressions' with the function
630 `speedbar-extension-list-to-regex' (A misnamed function in this case.)
631 Use the function `speedbar-add-ignored-path-regexp', or customize the
632 variable `speedbar-ignored-path-expressions' to modify this variable.")
634 (defcustom speedbar-ignored-path-expressions
636 "*List of regular expressions matching directories speedbar will ignore.
637 They should included paths to directories which are notoriously very
638 large and take a long time to load in. Use the function
639 `speedbar-add-ignored-path-regexp' to add new items to this list after
640 speedbar is loaded. You may place anything you like in this list
641 before speedbar has been loaded."
643 :type '(repeat (regexp :tag "Path Regexp"))
644 :set (lambda (sym val)
645 (setq speedbar-ignored-path-expressions val
646 speedbar-ignored-path-regexp
647 (speedbar-extension-list-to-regex val))))
649 (defcustom speedbar-directory-unshown-regexp "^\\(CVS\\|RCS\\|SCCS\\)\\'"
650 "*Regular expression matching directories not to show in speedbar.
651 They should include commonly existing directories which are not
652 useful, such as version control."
656 (defvar speedbar-file-unshown-regexp
657 (let ((nstr "") (noext completion-ignored-extensions))
659 (setq nstr (concat nstr (regexp-quote (car noext)) "\\'"
660 (if (cdr noext) "\\|" ""))
662 ;; backup refdir lockfile
663 (concat nstr "\\|#[^#]+#$\\|\\.\\.?\\'\\|\\.#"))
664 "*Regexp matching files we don't want displayed in a speedbar buffer.
665 It is generated from the variable `completion-ignored-extensions'")
667 ;; this is dangerous to customize, because the defaults will probably
668 ;; change in the future.
669 (defcustom speedbar-supported-extension-expressions
670 (append '(".[ch]\\(\\+\\+\\|pp\\|c\\|h\\|xx\\)?" ".tex\\(i\\(nfo\\)?\\)?"
671 ".el" ".emacs" ".l" ".lsp" ".p" ".java" ".f\\(90\\|77\\|or\\)?")
672 (if speedbar-use-imenu-flag
673 '(".ada" ".pl" ".tcl" ".m" ".scm" ".pm" ".py"
674 ;; html is not supported by default, but an imenu tags package
675 ;; is available. Also, html files are nice to be able to see.
677 "Makefile\\(\\.in\\)?")))
678 "*List of regular expressions which will match files supported by tagging.
679 Do not prefix the `.' char with a double \\ to quote it, as the period
680 will be stripped by a simplified optimizer when compiled into a
681 singular expression. This variable will be turned into
682 `speedbar-file-regexp' for use with speedbar. You should use the
683 function `speedbar-add-supported-extension' to add a new extension at
684 runtime, or use the configuration dialog to set it in your .emacs
687 :type '(repeat (regexp :tag "Extension Regexp"))
688 :set (lambda (sym val)
689 (setq speedbar-supported-extension-expressions val
690 speedbar-file-regexp (speedbar-extension-list-to-regex val)))
693 (defvar speedbar-file-regexp
694 (speedbar-extension-list-to-regex speedbar-supported-extension-expressions)
695 "Regular expression matching files we know how to expand.
696 Created from `speedbar-supported-extension-expression' with the
697 function `speedbar-extension-list-to-regex'")
699 (defun speedbar-add-supported-extension (extension)
700 "Add EXTENSION as a new supported extension for speedbar tagging.
701 This should start with a `.' if it is not a complete file name, and
702 the dot should NOT be quoted in with \\. Other regular expression
703 matchers are allowed however. EXTENSION may be a single string or a
705 (interactive "sExtionsion: ")
706 (if (not (listp extension)) (setq extension (list extension)))
708 (if (member (car extension) speedbar-supported-extension-expressions)
710 (setq speedbar-supported-extension-expressions
711 (cons (car extension) speedbar-supported-extension-expressions)))
712 (setq extension (cdr extension)))
713 (setq speedbar-file-regexp (speedbar-extension-list-to-regex
714 speedbar-supported-extension-expressions)))
716 (defun speedbar-add-ignored-path-regexp (path-expression)
717 "Add PATH-EXPRESSION as a new ignored path for speedbar tracking.
718 This function will modify `speedbar-ignored-path-regexp' and add
719 PATH-EXPRESSION to `speedbar-ignored-path-expressions'."
720 (interactive "sPath regex: ")
721 (if (not (listp path-expression))
722 (setq path-expression (list path-expression)))
723 (while path-expression
724 (if (member (car path-expression) speedbar-ignored-path-expressions)
726 (setq speedbar-ignored-path-expressions
727 (cons (car path-expression) speedbar-ignored-path-expressions)))
728 (setq path-expression (cdr path-expression)))
729 (setq speedbar-ignored-path-regexp (speedbar-extension-list-to-regex
730 speedbar-ignored-path-expressions)))
732 ;; If we don't have custom, then we set it here by hand.
733 (if (not (fboundp 'custom-declare-variable))
734 (setq speedbar-file-regexp (speedbar-extension-list-to-regex
735 speedbar-supported-extension-expressions)
736 speedbar-ignored-path-regexp (speedbar-extension-list-to-regex
737 speedbar-ignored-path-expressions)))
739 (defvar speedbar-update-flag (and
740 (or (fboundp 'run-with-idle-timer)
741 (fboundp 'start-itimer)
742 (boundp 'post-command-idle-hook))
744 "*Non-nil means to automatically update the display.
745 When this is nil then speedbar will not follow the attached frame's path.
746 When speedbar is active, use:
748 \\<speedbar-key-map> `\\[speedbar-toggle-updates]'
750 to toggle this value.")
752 (defvar speedbar-syntax-table nil
753 "Syntax-table used on the speedbar.")
755 (if speedbar-syntax-table
757 (setq speedbar-syntax-table (make-syntax-table))
758 ;; turn off paren matching around here.
759 (modify-syntax-entry ?\' " " speedbar-syntax-table)
760 (modify-syntax-entry ?\" " " speedbar-syntax-table)
761 (modify-syntax-entry ?( " " speedbar-syntax-table)
762 (modify-syntax-entry ?) " " speedbar-syntax-table)
763 (modify-syntax-entry ?[ " " speedbar-syntax-table)
764 (modify-syntax-entry ?] " " speedbar-syntax-table))
766 (defvar speedbar-key-map nil
767 "Keymap used in speedbar buffer.")
771 (setq speedbar-key-map (make-keymap))
772 (suppress-keymap speedbar-key-map t)
775 (define-key speedbar-key-map "g" 'speedbar-refresh)
776 (define-key speedbar-key-map "t" 'speedbar-toggle-updates)
777 (define-key speedbar-key-map "q" 'speedbar-close-frame)
778 (define-key speedbar-key-map "Q" 'delete-frame)
781 (define-key speedbar-key-map "n" 'speedbar-next)
782 (define-key speedbar-key-map "p" 'speedbar-prev)
783 (define-key speedbar-key-map "\M-n" 'speedbar-restricted-next)
784 (define-key speedbar-key-map "\M-p" 'speedbar-restricted-prev)
785 (define-key speedbar-key-map "\C-\M-n" 'speedbar-forward-list)
786 (define-key speedbar-key-map "\C-\M-p" 'speedbar-backward-list)
787 (define-key speedbar-key-map " " 'speedbar-scroll-up)
788 (define-key speedbar-key-map [delete] 'speedbar-scroll-down)
790 ;; Short cuts I happen to find useful
791 (define-key speedbar-key-map "r"
792 (lambda () (interactive)
793 (speedbar-change-initial-expansion-list
794 speedbar-previously-used-expansion-list-name)))
795 (define-key speedbar-key-map "b"
796 (lambda () (interactive)
797 (speedbar-change-initial-expansion-list "quick buffers")))
798 (define-key speedbar-key-map "f"
799 (lambda () (interactive)
800 (speedbar-change-initial-expansion-list "files")))
803 (substitute-key-definition 'switch-to-buffer
804 'speedbar-switch-buffer-attached-frame
805 speedbar-key-map global-map)
809 ;; mouse bindings so we can manipulate the items on each line
810 (define-key speedbar-key-map 'button2 'speedbar-click)
811 (define-key speedbar-key-map '(shift button2) 'speedbar-power-click)
812 ;; Info doc fix from Bob Weiner
813 (if (featurep 'infodoc)
815 (define-key speedbar-key-map 'button3 'speedbar-xemacs-popup-kludge))
816 (define-key speedbar-key-map '(meta button3) 'speedbar-mouse-item-info)
819 ;; mouse bindings so we can manipulate the items on each line
820 (define-key speedbar-key-map [down-mouse-1] 'speedbar-double-click)
821 (define-key speedbar-key-map [mouse-2] 'speedbar-click)
822 ;; This is the power click for new frames, or refreshing a cache
823 (define-key speedbar-key-map [S-mouse-2] 'speedbar-power-click)
824 ;; This adds a small unecessary visual effect
825 ;;(define-key speedbar-key-map [down-mouse-2] 'speedbar-quick-mouse)
826 (define-key speedbar-key-map [M-mouse-2] 'speedbar-mouse-item-info)
828 (define-key speedbar-key-map [down-mouse-3] 'speedbar-emacs-popup-kludge)
830 ;; This lets the user scroll as if we had a scrollbar... well maybe not
831 (define-key speedbar-key-map [mode-line mouse-2] 'speedbar-mouse-hscroll)
832 ;; another handy place users might click to get our menu.
833 (define-key speedbar-key-map [mode-line down-mouse-1]
834 'speedbar-emacs-popup-kludge)
836 ;; We can't switch buffers with the buffer mouse menu. Lets hack it.
837 (define-key speedbar-key-map [C-down-mouse-1] 'speedbar-hack-buffer-menu)
839 ;; Lastly, we want to track the mouse. Play here
840 (define-key speedbar-key-map [mouse-movement] 'speedbar-track-mouse)
843 (defun speedbar-make-specialized-keymap ()
844 "Create a keymap for use w/ a speedbar major or minor display mode.
845 This basically creates a sparse keymap, and makes it's parent be
847 (let ((k (make-sparse-keymap)))
848 (set-keymap-parent k speedbar-key-map)
851 (defvar speedbar-file-key-map nil
852 "Keymap used in speedbar buffer while files are displayed.")
854 (if speedbar-file-key-map
856 (setq speedbar-file-key-map (speedbar-make-specialized-keymap))
858 ;; Basic tree features
859 (define-key speedbar-file-key-map "e" 'speedbar-edit-line)
860 (define-key speedbar-file-key-map "\C-m" 'speedbar-edit-line)
861 (define-key speedbar-file-key-map "+" 'speedbar-expand-line)
862 (define-key speedbar-file-key-map "-" 'speedbar-contract-line)
864 ;; file based commands
865 (define-key speedbar-file-key-map "U" 'speedbar-up-directory)
866 (define-key speedbar-file-key-map "I" 'speedbar-item-info)
867 (define-key speedbar-file-key-map "B" 'speedbar-item-byte-compile)
868 (define-key speedbar-file-key-map "L" 'speedbar-item-load)
869 (define-key speedbar-file-key-map "C" 'speedbar-item-copy)
870 (define-key speedbar-file-key-map "D" 'speedbar-item-delete)
871 (define-key speedbar-file-key-map "O" 'speedbar-item-object-delete)
872 (define-key speedbar-file-key-map "R" 'speedbar-item-rename)
875 (defvar speedbar-easymenu-definition-base
877 ["Update" speedbar-refresh t]
878 ["Auto Update" speedbar-toggle-updates
879 :style toggle :selected speedbar-update-flag]
881 "Base part of the speedbar menu.")
883 (defvar speedbar-easymenu-definition-special
884 '(["Edit Item On Line" speedbar-edit-line t]
885 ["Show All Files" speedbar-toggle-show-all-files
886 :style toggle :selected speedbar-show-unknown-files]
887 ["Expand File Tags" speedbar-expand-line
888 (save-excursion (beginning-of-line)
889 (looking-at "[0-9]+: *.\\+. "))]
890 ["Contract File Tags" speedbar-contract-line
891 (save-excursion (beginning-of-line)
892 (looking-at "[0-9]+: *.-. "))]
893 ; ["Sort Tags" speedbar-toggle-sorting
894 ; :style toggle :selected speedbar-sort-tags]
896 ["File/Tag Information" speedbar-item-info t]
897 ["Load Lisp File" speedbar-item-load
900 (looking-at "[0-9]+: *\\[[+-]\\] .+\\(\\.el\\)\\( \\|$\\)"))]
901 ["Byte Compile File" speedbar-item-byte-compile
904 (looking-at "[0-9]+: *\\[[+-]\\] .+\\(\\.el\\)\\( \\|$\\)"))]
905 ["Copy File" speedbar-item-copy
906 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *\\["))]
907 ["Rename File" speedbar-item-rename
908 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
909 ["Delete File" speedbar-item-delete
910 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
911 ["Delete Object" speedbar-item-object-delete
912 (save-excursion (beginning-of-line)
913 (looking-at "[0-9]+: *\\[[+-]\\] [^ \n]+ \\*?[!#]$"))]
915 "Additional menu items while in file-mode.")
917 (defvar speedbar-easymenu-definition-trailer
919 (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
920 (list ["Customize..." speedbar-customize t]))
922 ["Close" speedbar-close-frame t]
923 ["Quit" delete-frame t] ))
924 "Menu items appearing at the end of the speedbar menu.")
926 (defvar speedbar-desired-buffer nil
927 "Non-nil when speedbar is showing buttons specific a special mode.
928 In this case it is the originating buffer.")
929 (defvar speedbar-buffer nil
930 "The buffer displaying the speedbar.")
931 (defvar speedbar-frame nil
932 "The frame displaying speedbar.")
933 (defvar speedbar-cached-frame nil
934 "The frame that was last created, then removed from the display.")
935 (defvar speedbar-full-text-cache nil
936 "The last open directory is saved in its entirety for ultra-fast switching.")
937 (defvar speedbar-timer nil
938 "The speedbar timer used for updating the buffer.")
939 (defvar speedbar-attached-frame nil
940 "The frame which started speedbar mode.
941 This is the frame from which all data displayed in the speedbar is
942 gathered, and in which files and such are displayed.")
944 (defvar speedbar-last-selected-file nil
945 "The last file which was selected in speedbar buffer.")
947 (defvar speedbar-shown-directories nil
948 "Maintain list of directories simultaneously open in the current speedbar.")
950 (defvar speedbar-directory-contents-alist nil
951 "An association list of directories and their contents.
952 Each sublist was returned by `speedbar-file-lists'. This list is
953 maintained to speed up the refresh rate when switching between
956 (defvar speedbar-power-click nil
957 "Never set this by hand. Value is t when S-mouse activity occurs.")
962 (if (fboundp 'frame-parameter)
964 (defalias 'speedbar-frame-parameter 'frame-parameter)
966 (defun speedbar-frame-parameter (frame parameter)
967 "Return FRAME's PARAMETER value."
968 (cdr (assoc parameter (frame-parameters frame)))))
970 ;;; Mode definitions/ user commands
974 (defalias 'speedbar 'speedbar-frame-mode)
976 (defun speedbar-frame-mode (&optional arg)
977 "Enable or disable speedbar. Positive ARG means turn on, negative turn off.
978 nil means toggle. Once the speedbar frame is activated, a buffer in
979 `speedbar-mode' will be displayed. Currently, only one speedbar is
981 `speedbar-before-popup-hook' is called before popping up the speedbar frame.
982 `speedbar-before-delete-hook' is called before the frame is deleted."
984 ;; toggle frame on and off.
985 (if (not arg) (if (and (frame-live-p speedbar-frame)
986 (frame-visible-p speedbar-frame))
987 (setq arg -1) (setq arg 1)))
988 ;; turn the frame off on neg number
989 (if (and (numberp arg) (< arg 0))
991 (run-hooks 'speedbar-before-delete-hook)
992 (if (and speedbar-frame (frame-live-p speedbar-frame))
994 (setq speedbar-cached-frame speedbar-frame)
995 (make-frame-invisible speedbar-frame)))
996 (setq speedbar-frame nil)
997 (speedbar-set-timer nil)
998 ;; Used to delete the buffer. This has the annoying affect of
999 ;; preventing whatever took its place from ever appearing
1000 ;; as the default after a C-x b was typed
1001 ;;(if (bufferp speedbar-buffer)
1002 ;; (kill-buffer speedbar-buffer))
1004 ;; Set this as our currently attached frame
1005 (setq speedbar-attached-frame (selected-frame))
1006 (run-hooks 'speedbar-before-popup-hook)
1007 ;; Get the frame to work in
1008 (if (frame-live-p speedbar-cached-frame)
1010 (setq speedbar-frame speedbar-cached-frame)
1011 (make-frame-visible speedbar-frame)
1012 ;; Get the buffer to play with
1014 (select-frame speedbar-frame)
1015 (if (not (eq (current-buffer) speedbar-buffer))
1016 (switch-to-buffer speedbar-buffer))
1017 (set-window-dedicated-p (selected-window) t)
1018 (raise-frame speedbar-frame)
1019 (speedbar-set-timer speedbar-update-speed)
1021 (if (frame-live-p speedbar-frame)
1022 (raise-frame speedbar-frame)
1023 (setq speedbar-frame
1024 (if speedbar-xemacsp
1025 ;; Only guess height if it is not specified.
1026 (if (member 'height speedbar-frame-plist)
1027 (make-frame speedbar-frame-plist)
1028 (make-frame (nconc (list 'height
1029 (speedbar-needed-height))
1030 speedbar-frame-plist)))
1031 (let* ((mh (speedbar-frame-parameter nil 'menu-bar-lines))
1032 (cfx (speedbar-frame-parameter nil 'left))
1033 (cfy (speedbar-frame-parameter nil 'top))
1034 (cfw (frame-pixel-width))
1036 ;; Only add a guessed height if one is not specified
1037 ;; in the input parameters.
1038 (if (assoc 'height speedbar-frame-parameters)
1039 speedbar-frame-parameters
1041 speedbar-frame-parameters
1042 (list (cons 'height (+ mh (frame-height)))))))
1044 (if (or (< emacs-major-version 20)
1045 (not (eq window-system 'x)))
1047 (let ((x-pointer-shape x-pointer-top-left-arrow)
1048 (x-sensitive-text-pointer-shape
1050 (make-frame params)))))
1051 ;; Position speedbar frame.
1052 (if (or (not window-system) (eq window-system 'pc)
1053 (assoc 'left speedbar-frame-parameters)
1054 (assoc 'top speedbar-frame-parameters))
1055 ;; Do no positioning if not on a windowing system,
1056 ;; or if left/top were specified in the parameters.
1059 (if (not (consp cfx))
1061 ;; If cfx is a list, that means we grow
1062 ;; from a specific edge of the display.
1063 ;; Convert that to the distance from the
1064 ;; left side of the display.
1065 (if (eq (car cfx) '-)
1066 ;; A - means distance from the right edge
1067 ;; of the display, or DW - cfx - framewidth
1068 (- (x-display-pixel-width) (car (cdr cfx))
1069 (frame-pixel-width))
1071 (modify-frame-parameters
1076 ;; Decide which side to put it
1077 ;; on. 200 is just a buffer
1078 ;; for the left edge of the
1079 ;; screen. The extra 10 is just
1080 ;; dressings for window decorations.
1081 (let ((sfw (frame-pixel-width frame)))
1082 (let ((left-guess (- cfx 10 sfw))
1083 (right-guess (+ cfx cfw 5)))
1084 (let ((left-margin left-guess)
1086 (- (x-display-pixel-width)
1087 right-guess 5 sfw)))
1088 (cond ((>= left-margin 0) left-guess)
1089 ((>= right-margin 0) right-guess)
1090 ;; otherwise choose side we overlap less
1091 ((> left-margin right-margin) 0)
1092 (t (- (x-display-pixel-width) sfw 5)))))))
1095 ;; reset the selection variable
1096 (setq speedbar-last-selected-file nil)
1097 ;; Put the buffer into the frame
1098 (save-window-excursion
1099 ;; Get the buffer to play with
1101 (select-frame speedbar-frame)
1102 (switch-to-buffer speedbar-buffer)
1103 (set-window-dedicated-p (selected-window) t))
1104 (if (and (or (null window-system) (eq window-system 'pc))
1105 (fboundp 'set-frame-name))
1107 (select-frame speedbar-frame)
1108 (set-frame-name "Speedbar")))
1109 (speedbar-set-timer speedbar-update-speed)))))
1112 (defun speedbar-get-focus ()
1113 "Change frame focus to or from the speedbar frame.
1114 If the selected frame is not speedbar, then speedbar frame is
1115 selected. If the speedbar frame is active, then select the attached frame."
1117 (if (eq (selected-frame) speedbar-frame)
1118 (if (frame-live-p speedbar-attached-frame)
1119 (select-frame speedbar-attached-frame))
1120 ;; If updates are off, then refresh the frame (they want it now...)
1121 (if (not speedbar-update-flag)
1122 (let ((speedbar-update-flag t))
1123 (speedbar-timer-fn)))
1124 ;; make sure we have a frame
1125 (if (not (frame-live-p speedbar-frame)) (speedbar-frame-mode 1))
1127 (select-frame speedbar-frame)
1131 (defun speedbar-close-frame ()
1132 "Turn off a currently active speedbar."
1134 (speedbar-frame-mode -1)
1135 (select-frame speedbar-attached-frame)
1138 (defun speedbar-switch-buffer-attached-frame (&optional buffer)
1139 "Switch to BUFFER in speedbar's attached frame, and raise that frame.
1140 This overrides the default behavior of `switch-to-buffer' which is
1141 broken because of the dedicated speedbar frame."
1143 ;; Assume we are in the speedbar frame.
1144 (speedbar-get-focus)
1145 ;; Now switch buffers
1147 (switch-to-buffer buffer)
1148 (call-interactively 'switch-to-buffer nil nil)))
1150 (defmacro speedbar-frame-width ()
1151 "Return the width of the speedbar frame in characters.
1152 nil if it doesn't exist."
1153 '(frame-width speedbar-frame))
1155 ;; XEmacs function only.
1156 (defun speedbar-needed-height (&optional frame)
1157 "The needed height for the tool bar FRAME (in characters)."
1158 (or frame (setq frame (selected-frame)))
1159 ;; The 1 is the missing modeline/minibuffer
1160 (+ 1 (/ (frame-pixel-height frame)
1161 (face-height 'default frame))))
1163 (defun speedbar-mode ()
1164 "Major mode for managing a display of directories and tags.
1165 \\<speedbar-key-map>
1166 The first line represents the default path of the speedbar frame.
1167 Each directory segment is a button which jumps speedbar's default
1168 directory to that path. Buttons are activated by clicking `\\[speedbar-click]'.
1169 In some situations using `\\[speedbar-power-click]' is a `power click' which will
1170 rescan cached items, or pop up new frames.
1172 Each line starting with <+> represents a directory. Click on the <+>
1173 to insert the directory listing into the current tree. Click on the
1174 <-> to retract that list. Click on the directory name to go to that
1175 directory as the default.
1177 Each line starting with [+] is a file. If the variable
1178 `speedbar-show-unknown-files' is t, the lines starting with [?] are
1179 files which don't have imenu support, but are not expressly ignored.
1180 Files are completely ignored if they match `speedbar-file-unshown-regexp'
1181 which is generated from `completion-ignored-extensions'.
1183 Files with a `*' character after their name are files checked out of a
1184 version control system. (currently only RCS is supported.) New
1185 version control systems can be added by examining the documentation
1186 for `speedbar-this-file-in-vc' and `speedbar-vc-check-dir-p'
1188 Files with a `#' or `!' character after them are source files that
1189 have an object file associated with them. The `!' indicates that the
1190 files is out of date. You can control what source/object associations
1191 exist through the variable `speedbar-obj-alist'.
1193 Click on the [+] to display a list of tags from that file. Click on
1194 the [-] to retract the list. Click on the file name to edit the file
1195 in the attached frame.
1197 If you open tags, you might find a node starting with {+}, which is a
1198 category of tags. Click the {+} to expand the category. Jump-able
1199 tags start with >. Click the name of the tag to go to that position
1200 in the selected file.
1202 \\{speedbar-key-map}"
1205 (setq speedbar-buffer (set-buffer (get-buffer-create " SPEEDBAR")))
1206 (kill-all-local-variables)
1207 (setq major-mode 'speedbar-mode)
1208 (setq mode-name "Speedbar")
1209 (set-syntax-table speedbar-syntax-table)
1210 (setq font-lock-keywords nil) ;; no font-locking please
1211 (setq truncate-lines t)
1212 (make-local-variable 'frame-title-format)
1213 (setq frame-title-format "Speedbar")
1214 ;; Set this up special just for the speedbar buffer
1215 ;; Terminal minibuffer stuff does not require this.
1216 (if (and window-system (not (eq window-system 'pc))
1217 (null default-minibuffer-frame))
1219 (make-local-variable 'default-minibuffer-frame)
1220 (setq default-minibuffer-frame speedbar-attached-frame)))
1221 ;; Correct use of `temp-buffer-show-function': Bob Weiner
1222 (if (and (boundp 'temp-buffer-show-hook)
1223 (boundp 'temp-buffer-show-function))
1224 (progn (make-local-variable 'temp-buffer-show-hook)
1225 (setq temp-buffer-show-hook temp-buffer-show-function)))
1226 (make-local-variable 'temp-buffer-show-function)
1227 (setq temp-buffer-show-function 'speedbar-temp-buffer-show-function)
1228 (if speedbar-xemacsp
1230 ;; Argh! mouse-track-click-hook doesn't understand the
1231 ;; make-local-hook conventions.
1232 (make-local-variable 'mouse-track-click-hook)
1233 (add-hook 'mouse-track-click-hook
1234 (lambda (event count)
1235 (if (/= (event-button event) 1)
1236 nil ; Do normal operations.
1238 (speedbar-quick-mouse event))
1241 (mouse-set-point event)
1242 (speedbar-do-function-pointer)
1243 (speedbar-quick-mouse event)))
1244 ;; Don't do normal operations.
1246 (make-local-hook 'kill-buffer-hook)
1247 (add-hook 'kill-buffer-hook (lambda () (let ((skilling (boundp 'skilling)))
1250 (if (eq (current-buffer)
1252 (speedbar-frame-mode -1)))))
1254 (toggle-read-only 1)
1255 (speedbar-set-mode-line-format)
1256 (if speedbar-xemacsp
1258 (make-local-variable 'mouse-motion-handler)
1259 (setq mouse-motion-handler 'speedbar-track-mouse-xemacs))
1260 (if speedbar-track-mouse-flag
1262 (make-local-variable 'track-mouse)
1263 (setq track-mouse t))) ;this could be messy.
1264 (setq auto-show-mode nil)) ;no auto-show for Emacs
1265 (run-hooks 'speedbar-mode-hook))
1266 (speedbar-update-contents)
1269 (defun speedbar-show-info-under-mouse (&optional event)
1270 "Call the info function for the line under the mouse.
1271 Optional EVENT is currently not used."
1272 (let ((pos (mouse-position))) ; we ignore event until I use it later.
1273 (if (equal (car pos) speedbar-frame)
1275 (save-window-excursion
1276 (apply 'set-mouse-position pos)
1277 (speedbar-item-info))))))
1279 (defun speedbar-set-mode-line-format ()
1280 "Set the format of the mode line based on the current speedbar environment.
1281 This gives visual indications of what is up. It EXPECTS the speedbar
1282 frame and window to be the currently active frame and window."
1283 (if (and (frame-live-p speedbar-frame)
1284 (or (not speedbar-xemacsp)
1285 (specifier-instance has-modeline-p)))
1287 (set-buffer speedbar-buffer)
1288 (let* ((w (or (speedbar-frame-width) 20))
1291 (p3 (if speedbar-update-flag "SPEEDBAR" "SLOWBAR"))
1292 (blank (- w (length p1) (length p3) (length p5)
1293 (if line-number-mode 4 0)))
1295 (make-string (/ blank 2) ? )
1298 (make-string (+ (/ blank 2) (% blank 2)) ? )
1301 (if line-number-mode
1302 (list (concat p1 p2 p3) '(line-number-mode " %3l")
1304 (list (concat p1 p2 p3 p4 p5)))))
1305 (if (not (equal mode-line-format tf))
1307 (setq mode-line-format tf)
1308 (force-mode-line-update)))))))
1310 (defun speedbar-temp-buffer-show-function (buffer)
1311 "Placed in the variable `temp-buffer-show-function' in `speedbar-mode'.
1312 If a user requests help using \\[help-command] <Key> the temp BUFFER will be
1313 redirected into a window on the attached frame."
1314 (if speedbar-attached-frame (select-frame speedbar-attached-frame))
1315 (pop-to-buffer buffer nil)
1317 ;; Fix for using this hook on some platforms: Bob Weiner
1318 (cond ((not speedbar-xemacsp)
1319 (run-hooks 'temp-buffer-show-hook))
1320 ((fboundp 'run-hook-with-args)
1321 (run-hook-with-args 'temp-buffer-show-hook buffer))
1322 ((and (boundp 'temp-buffer-show-hook)
1323 (listp temp-buffer-show-hook))
1324 (mapcar (function (lambda (hook) (funcall hook buffer)))
1325 temp-buffer-show-hook))))
1327 (defvar speedbar-previous-menu nil
1328 "The menu before the last `speedbar-reconfigure-keymaps' was called.")
1330 (defun speedbar-reconfigure-keymaps ()
1331 "Reconfigure the menu-bar in a speedbar frame.
1332 Different menu items are displayed depending on the current display mode
1333 and the existence of packages."
1335 speedbar-easymenu-definition-base
1336 (if speedbar-shown-directories
1337 ;; file display mode version
1338 (speedbar-initial-menu)
1340 (select-frame speedbar-attached-frame)
1341 (if (local-variable-p
1342 'speedbar-easymenu-definition-special
1344 ;; If bound locally, we can use it
1345 speedbar-easymenu-definition-special)))
1346 ;; Dynamic menu stuff
1348 (list (cons "Displays"
1349 (let ((displays nil)
1350 (alist speedbar-initial-expansion-mode-alist))
1355 (capitalize (car (car alist)))
1357 'speedbar-change-initial-expansion-list
1361 (setq alist (cdr alist)))
1364 speedbar-easymenu-definition-trailer))
1365 (localmap (save-excursion
1366 (let ((cf (selected-frame)))
1368 (select-frame speedbar-attached-frame)
1369 (if (local-variable-p
1370 'speedbar-special-mode-key-map
1372 speedbar-special-mode-key-map)
1373 (select-frame cf))))))
1375 (set-buffer speedbar-buffer)
1376 (use-local-map (or localmap
1377 (speedbar-initial-keymap)
1378 ;; This creates a small keymap we can glom the
1379 ;; menu adjustments into.
1380 (speedbar-make-specialized-keymap)))
1381 ;; Delete the old menu if applicable.
1382 (if speedbar-previous-menu (easy-menu-remove speedbar-previous-menu))
1383 (setq speedbar-previous-menu md)
1384 ;; Now add the new menu
1385 (if (not speedbar-xemacsp)
1386 (easy-menu-define speedbar-menu-map (current-local-map)
1388 (easy-menu-add md (current-local-map))
1389 (set-buffer-menubar (list md))))))
1392 ;;; User Input stuff
1395 ;; XEmacs: this can be implemented using modeline keymaps, but there
1396 ;; is no use, as we have horizontal scrollbar (as the docstring
1398 (defun speedbar-mouse-hscroll (e)
1399 "Read a mouse event E from the mode line, and horizontally scroll.
1400 If the mouse is being clicked on the far left, or far right of the
1401 mode-line. This is only useful for non-XEmacs"
1403 (let* ((xp (car (nth 2 (car (cdr e)))))
1404 (cpw (/ (frame-pixel-width)
1406 (oc (1+ (/ xp cpw)))
1410 ((> oc (- (window-width) 3))
1412 (t (message "Click on the edge of the modeline to scroll left/right")))
1413 ;;(message "X: Pixel %d Char Pixels %d On char %d" xp cpw oc)
1416 (defun speedbar-customize ()
1417 "Customize speedbar using the Custom package."
1419 (let ((sf (selected-frame)))
1420 (select-frame speedbar-attached-frame)
1421 (customize-group 'speedbar)
1423 (speedbar-maybee-jump-to-attached-frame))
1425 (defun speedbar-track-mouse (event)
1426 "For motion EVENT, display info about the current line."
1428 (if (not speedbar-track-mouse-flag)
1431 (let ((char (nth 1 (car (cdr event)))))
1432 (if (not (numberp char))
1435 ;; (message "%S" event)
1436 (speedbar-item-info)
1439 (defun speedbar-track-mouse-xemacs (event)
1440 "For motion EVENT, display info about the current line."
1441 (if (functionp (default-value 'mouse-motion-handler))
1442 (funcall (default-value 'mouse-motion-handler) event))
1443 (if speedbar-track-mouse-flag
1445 (save-window-excursion
1447 (progn (mouse-set-point event)
1448 ;; Prevent focus-related bugs.
1449 (if (eq major-mode 'speedbar-mode)
1450 (speedbar-item-info)))
1453 ;; In XEmacs, we make popup menus work on the item over mouse (as
1454 ;; opposed to where the point happens to be.) We attain this by
1455 ;; temporarily moving the point to that place.
1456 ;; Hrvoje Niksic <hniksic@srce.hr>
1457 (defun speedbar-xemacs-popup-kludge (event)
1458 "Pop up a menu related to the clicked on item.
1459 Must be bound to EVENT."
1461 (select-frame speedbar-frame)
1463 (goto-char (event-closest-point event))
1465 (forward-char (min 5 (- (save-excursion (end-of-line) (point))
1466 (save-excursion (beginning-of-line) (point)))))
1468 ;; Wait for menu to bail out. `popup-mode-menu' (and other popup
1469 ;; menu functions) return immediately.
1471 (while (not (misc-user-event-p (setq new (next-event))))
1472 (dispatch-event new))
1473 (dispatch-event new))))
1475 (defun speedbar-emacs-popup-kludge (e)
1476 "Pop up a menu related to the clicked on item.
1477 Must be bound to event E."
1481 ;; This gets the cursor where the user can see it.
1482 (if (not (bolp)) (forward-char -1))
1484 (if (< emacs-major-version 20)
1485 (mouse-major-mode-menu e)
1486 (mouse-major-mode-menu e nil))))
1488 (defun speedbar-hack-buffer-menu (e)
1489 "Control mouse 1 is buffer menu.
1490 This hack overrides it so that the right thing happens in the main
1491 Emacs frame, not in the speedbar frame.
1492 Argument E is the event causing this activity."
1494 (let ((fn (lookup-key global-map (if speedbar-xemacsp
1500 (set-window-dedicated-p (selected-window) nil)
1501 (call-interactively fn)
1502 (setq newbuff (current-buffer)))
1503 (switch-to-buffer " SPEEDBAR")
1504 (set-window-dedicated-p (selected-window) t))
1505 (speedbar-with-attached-buffer
1506 (switch-to-buffer newbuff))))
1508 (defun speedbar-next (arg)
1509 "Move to the next ARGth line in a speedbar buffer."
1511 (forward-line (or arg 1))
1512 (speedbar-item-info)
1513 (speedbar-position-cursor-on-line))
1515 (defun speedbar-prev (arg)
1516 "Move to the previous ARGth line in a speedbar buffer."
1518 (speedbar-next (if arg (- arg) -1)))
1520 (defun speedbar-restricted-move (arg)
1521 "Move to the next ARGth line in a speedbar buffer at the same depth.
1522 This means that movement is restricted to a subnode, and that siblings
1523 of intermediate nodes are skipped."
1524 (if (not (numberp arg)) (signal 'wrong-type-argument (list arg 'numberp)))
1525 ;; First find the extent for which we are allowed to move.
1526 (let ((depth (save-excursion (beginning-of-line)
1527 (if (looking-at "[0-9]+:")
1528 (string-to-int (match-string 0))
1530 (crement (if (< arg 0) 1 -1)) ; decrement or increment
1531 (lastmatch (point)))
1533 (forward-line (- crement))
1534 (let ((subdepth (save-excursion (beginning-of-line)
1535 (if (looking-at "[0-9]+:")
1536 (string-to-int (match-string 0))
1538 (cond ((or (< subdepth depth)
1539 (progn (end-of-line) (eobp))
1540 (progn (beginning-of-line) (bobp)))
1541 ;; We have reached the end of this block.
1542 (goto-char lastmatch)
1544 (error "End of sub-list"))
1546 (setq lastmatch (point)
1547 arg (+ arg crement))))))
1548 (speedbar-position-cursor-on-line)))
1550 (defun speedbar-restricted-next (arg)
1551 "Move to the next ARGth line in a speedbar buffer at the same depth.
1552 This means that movement is restricted to a subnode, and that siblings
1553 of intermediate nodes are skipped."
1555 (speedbar-restricted-move (or arg 1))
1556 (speedbar-item-info))
1559 (defun speedbar-restricted-prev (arg)
1560 "Move to the previous ARGth line in a speedbar buffer at the same depth.
1561 This means that movement is restricted to a subnode, and that siblings
1562 of intermediate nodes are skipped."
1564 (speedbar-restricted-move (if arg (- arg) -1))
1565 (speedbar-item-info))
1567 (defun speedbar-navigate-list (arg)
1568 "Move across ARG groups of similarly typed items in speedbar.
1569 Stop on the first line of the next type of item, or on the last or first item
1570 if we reach a buffer boundary."
1573 (if (looking-at "[0-9]+: *[[<{][-+?][]>}] ")
1574 (let ((str (regexp-quote (match-string 0))))
1575 (while (looking-at str)
1576 (speedbar-restricted-move arg)
1577 (beginning-of-line))))
1578 (speedbar-position-cursor-on-line))
1580 (defun speedbar-forward-list ()
1581 "Move forward over the current list.
1582 A LIST in speedbar is a group of similarly typed items, such as directories,
1583 files, or the directory button."
1585 (speedbar-navigate-list 1)
1586 (speedbar-item-info))
1588 (defun speedbar-backward-list ()
1589 "Move backward over the current list.
1590 A LIST in speedbar is a group of similarly typed items, such as directories,
1591 files, or the directory button."
1593 (speedbar-navigate-list -1)
1594 (speedbar-item-info))
1596 (defun speedbar-scroll-up (&optional arg)
1597 "Page down one screen-full of the speedbar, or ARG lines."
1600 (speedbar-position-cursor-on-line))
1602 (defun speedbar-scroll-down (&optional arg)
1603 "Page up one screen-full of the speedbar, or ARG lines."
1606 (speedbar-position-cursor-on-line))
1608 (defun speedbar-up-directory ()
1609 "Keyboard accelerator for moving the default directory up one.
1610 Assumes that the current buffer is the speedbar buffer"
1612 (setq default-directory (expand-file-name (concat default-directory "../")))
1613 (speedbar-update-contents))
1615 ;;; Speedbar file activity (aka creeping featurism)
1617 (defun speedbar-refresh ()
1618 "Refresh the current speedbar display, disposing of any cached data."
1620 (let ((dl speedbar-shown-directories)
1621 (dm (and (boundp 'deactivate-mark) deactivate-mark)))
1623 (adelete 'speedbar-directory-contents-alist (car dl))
1625 (if (<= 1 speedbar-verbosity-level)
1626 (message "Refreshing speedbar..."))
1627 (speedbar-update-contents)
1628 (speedbar-stealthy-updates)
1629 ;; Reset the timer in case it got really hosed for some reason...
1630 (speedbar-set-timer speedbar-update-speed)
1631 (if (<= 1 speedbar-verbosity-level)
1632 (message "Refreshing speedbar...done"))
1633 (if (boundp 'deactivate-mark) (setq deactivate-mark dm))))
1635 (defun speedbar-item-load ()
1636 "Load the item under the cursor or mouse if it is a Lisp file."
1638 (let ((f (speedbar-line-file)))
1639 (if (and (file-exists-p f) (string-match "\\.el\\'" f))
1640 (if (and (file-exists-p (concat f "c"))
1641 (y-or-n-p (format "Load %sc? " f)))
1642 ;; If the compiled version exists, load that instead...
1643 (load-file (concat f "c"))
1645 (error "Not a loadable file"))))
1647 (defun speedbar-item-byte-compile ()
1648 "Byte compile the item under the cursor or mouse if it is a Lisp file."
1650 (let ((f (speedbar-line-file))
1651 (sf (selected-frame)))
1652 (if (and (file-exists-p f) (string-match "\\.el\\'" f))
1654 (select-frame speedbar-attached-frame)
1655 (byte-compile-file f nil)
1657 (speedbar-reset-scanners)))
1660 (defun speedbar-mouse-item-info (event)
1661 "Provide information about what the user clicked on.
1662 This should be bound to a mouse EVENT."
1664 (mouse-set-point event)
1665 (speedbar-item-info))
1667 (defun speedbar-generic-item-info ()
1668 "Attempt to derive, and then display information about thils line item.
1669 File style information is displayed with `speedbar-item-info'."
1672 ;; Skip invisible number info.
1673 (if (looking-at "\\([0-9]+\\):") (goto-char (match-end 0)))
1674 ;; Skip items in "folder" type text characters.
1675 (if (looking-at "\\s-*[[<({].[]>)}] ") (goto-char (match-end 0)))
1677 (message "Text: %s" (buffer-substring-no-properties
1678 (point) (progn (end-of-line) (point))))))
1680 (defun speedbar-item-info ()
1681 "Display info in the mini-buffer about the button the mouse is over.
1682 This function can be replaced in `speedbar-mode-functions-list' as
1683 `speedbar-item-info'"
1685 (funcall (or (speedbar-fetch-replacement-function 'speedbar-item-info)
1686 'speedbar-generic-item-info)))
1688 (defun speedbar-item-info-file-helper (&optional filename)
1689 "Display info about a file that is on the current line.
1690 nil if not applicable. If FILENAME, then use that instead of reading
1691 it from the speedbar buffer."
1692 (let* ((item (or filename (speedbar-line-file)))
1693 (attr (if item (file-attributes item) nil)))
1694 (if (and item attr) (message "%s %-6d %s" (nth 8 attr) (nth 7 attr) item)
1697 (defun speedbar-item-info-tag-helper ()
1698 "Display info about a tag that is on the current line.
1699 nil if not applicable."
1701 (if (re-search-forward " > \\([^ ]+\\)$"
1702 (save-excursion(end-of-line)(point)) t)
1703 (let ((tag (match-string 1))
1704 (attr (get-text-property (match-beginning 1)
1707 (looking-at "\\([0-9]+\\):")
1708 (setq item (speedbar-line-path (string-to-int (match-string 1))))
1709 (message "Tag: %s in %s @ %s"
1711 (if (markerp attr) (marker-position attr)
1714 (if (re-search-forward "{[+-]} \\([^\n]+\\)$"
1715 (save-excursion(end-of-line)(point)) t)
1716 (message "Group of tags \"%s\"" (match-string 1))
1719 (defun speedbar-files-item-info ()
1720 "Display info in the mini-buffer about the button the mouse is over."
1721 (if (not speedbar-shown-directories)
1722 (speedbar-generic-item-info)
1723 (or (speedbar-item-info-file-helper)
1724 (speedbar-item-info-tag-helper)
1725 (speedbar-generic-item-info))))
1727 (defun speedbar-item-copy ()
1728 "Copy the item under the cursor.
1729 Files can be copied to new names or places."
1731 (let ((f (speedbar-line-file)))
1732 (if (not f) (error "Not a file"))
1733 (if (file-directory-p f)
1734 (error "Cannot copy directory")
1735 (let* ((rt (read-file-name (format "Copy %s to: "
1736 (file-name-nondirectory f))
1737 (file-name-directory f)))
1738 (refresh (member (expand-file-name (file-name-directory rt))
1739 speedbar-shown-directories)))
1740 ;; Create the right file name part
1741 (if (file-directory-p rt)
1743 (concat (expand-file-name rt)
1744 (if (string-match "/$" rt) "" "/")
1745 (file-name-nondirectory f))))
1746 (if (or (not (file-exists-p rt))
1747 (y-or-n-p (format "Overwrite %s with %s? " rt f)))
1749 (copy-file f rt t t)
1750 ;; refresh display if the new place is currently displayed.
1754 (if (not (speedbar-goto-this-file rt))
1755 (speedbar-goto-this-file f))))
1758 (defun speedbar-item-rename ()
1759 "Rename the item under the cursor or mouse.
1760 Files can be renamed to new names or moved to new directories."
1762 (let ((f (speedbar-line-file)))
1764 (let* ((rt (read-file-name (format "Rename %s to: "
1765 (file-name-nondirectory f))
1766 (file-name-directory f)))
1767 (refresh (member (expand-file-name (file-name-directory rt))
1768 speedbar-shown-directories)))
1769 ;; Create the right file name part
1770 (if (file-directory-p rt)
1772 (concat (expand-file-name rt)
1773 (if (string-match "/\\'" rt) "" "/")
1774 (file-name-nondirectory f))))
1775 (if (or (not (file-exists-p rt))
1776 (y-or-n-p (format "Overwrite %s with %s? " rt f)))
1778 (rename-file f rt t)
1779 ;; refresh display if the new place is currently displayed.
1783 (speedbar-goto-this-file rt)
1785 (error "Not a file"))))
1787 (defun speedbar-item-delete ()
1788 "Delete the item under the cursor. Files are removed from disk."
1790 (let ((f (speedbar-line-file)))
1791 (if (not f) (error "Not a file"))
1792 (if (y-or-n-p (format "Delete %s? " f))
1794 (if (file-directory-p f)
1795 (delete-directory f)
1797 (message "Okie dokie..")
1804 (defun speedbar-item-object-delete ()
1805 "Delete the object associated from the item under the cursor.
1806 The file is removed from disk. The object is determined from the
1807 variable `speedbar-obj-alist'."
1809 (let* ((f (speedbar-line-file))
1811 (oa speedbar-obj-alist))
1812 (if (not f) (error "Not a file"))
1813 (while (and oa (not (string-match (car (car oa)) f)))
1815 (setq obj (concat (file-name-sans-extension f) (cdr (car oa))))
1816 (if (and oa (file-exists-p obj)
1817 (y-or-n-p (format "Delete %s? " obj)))
1820 (speedbar-reset-scanners)))))
1822 (defun speedbar-enable-update ()
1823 "Enable automatic updating in speedbar via timers."
1825 (setq speedbar-update-flag t)
1826 (speedbar-set-mode-line-format)
1827 (speedbar-set-timer speedbar-update-speed))
1829 (defun speedbar-disable-update ()
1830 "Disable automatic updating and stop consuming resources."
1832 (setq speedbar-update-flag nil)
1833 (speedbar-set-mode-line-format)
1834 (speedbar-set-timer nil))
1836 (defun speedbar-toggle-updates ()
1837 "Toggle automatic update for the speedbar frame."
1839 (if speedbar-update-flag
1840 (speedbar-disable-update)
1841 (speedbar-enable-update)))
1843 (defun speedbar-toggle-sorting ()
1844 "Toggle automatic update for the speedbar frame."
1846 (setq speedbar-sort-tags (not speedbar-sort-tags)))
1848 (defun speedbar-toggle-show-all-files ()
1849 "Toggle display of files speedbar can not tag."
1851 (setq speedbar-show-unknown-files (not speedbar-show-unknown-files))
1854 ;;; Utility functions
1856 (defun speedbar-set-timer (timeout)
1857 "Apply a timer with TIMEOUT, or remove a timer if TIMOUT is nil.
1858 TIMEOUT is the number of seconds until the speedbar timer is called
1859 again. When TIMEOUT is nil, turn off all timeouts.
1860 This function will also enable or disable the `vc-checkin-hook' used
1861 to track file check ins, and will change the mode line to match
1862 `speedbar-update-flag'."
1867 (progn (delete-itimer speedbar-timer)
1868 (setq speedbar-timer nil)))
1870 (if (and speedbar-xemacsp
1871 (or (>= emacs-major-version 20)
1872 (>= emacs-minor-version 15)))
1873 (setq speedbar-timer (start-itimer "speedbar"
1878 (setq speedbar-timer (start-itimer "speedbar"
1883 ((fboundp 'run-with-idle-timer)
1885 (progn (cancel-timer speedbar-timer)
1886 (setq speedbar-timer nil)))
1888 (setq speedbar-timer
1889 (run-with-idle-timer timeout t 'speedbar-timer-fn))))
1890 ;; Emacs 19.30 (Thanks twice: ptype@dra.hmg.gb)
1891 ((fboundp 'post-command-idle-hook)
1893 (add-hook 'post-command-idle-hook 'speedbar-timer-fn)
1894 (remove-hook 'post-command-idle-hook 'speedbar-timer-fn)))
1895 ;; Older or other Emacsen with no timers. Set up so that its
1896 ;; obvious this emacs can't handle the updates
1898 (setq speedbar-update-flag nil)))
1899 ;; Apply a revert hook that will reset the scanners. We attach to revert
1900 ;; because most reverts occur during VC state change, and this lets our
1901 ;; VC scanner fix itself.
1903 (add-hook 'after-revert-hook 'speedbar-reset-scanners)
1904 (remove-hook 'after-revert-hook 'speedbar-reset-scanners)
1906 ;; change this if it changed for some reason
1907 (speedbar-set-mode-line-format))
1909 (defmacro speedbar-with-writable (&rest forms)
1910 "Allow the buffer to be writable and evaluate FORMS."
1911 (list 'let '((inhibit-read-only t))
1912 (cons 'progn forms)))
1913 (put 'speedbar-with-writable 'lisp-indent-function 0)
1915 (defun speedbar-select-window (buffer)
1916 "Select a window in which BUFFER is shown.
1917 If it is not shown, force it to appear in the default window."
1918 (let ((win (get-buffer-window buffer speedbar-attached-frame)))
1921 (set-window-buffer (selected-window) buffer))))
1923 (defmacro speedbar-with-attached-buffer (&rest forms)
1924 "Execute FORMS in the attached frame's special buffer.
1925 Optionally select that frame if necessary."
1926 ;; Reset the timer with a new timeout when cliking a file
1927 ;; in case the user was navigating directories, we can cancel
1928 ;; that other timer.
1931 '(speedbar-set-timer speedbar-update-speed)
1933 'let '((cf (selected-frame)))
1934 '(select-frame speedbar-attached-frame)
1935 '(speedbar-select-window speedbar-desired-buffer)
1938 '(speedbar-maybee-jump-to-attached-frame)
1941 (defun speedbar-insert-button (text face mouse function
1942 &optional token prevline)
1943 "Insert TEXT as the next logical speedbar button.
1944 FACE is the face to put on the button, MOUSE is the highlight face to use.
1945 When the user clicks on TEXT, FUNCTION is called with the TOKEN parameter.
1946 This function assumes that the current buffer is the speedbar buffer.
1947 If PREVLINE, then put this button on the previous line.
1949 This is a convenience function for special mode that create their own
1950 specialized speedbar displays."
1951 (goto-char (point-max))
1952 (if (/= (current-column) 0) (insert "\n"))
1953 (if prevline (progn (delete-char -1) (insert " "))) ;back up if desired...
1954 (let ((start (point)))
1956 (speedbar-make-button start (point) face mouse function token))
1957 (let ((start (point)))
1959 (put-text-property start (point) 'face nil)
1960 (put-text-property start (point) 'mouse-face nil)))
1962 (defun speedbar-make-button (start end face mouse function &optional token)
1963 "Create a button from START to END, with FACE as the display face.
1964 MOUSE is the mouse face. When this button is clicked on FUNCTION
1965 will be run with the TOKEN parameter (any Lisp object)"
1966 (put-text-property start end 'face face)
1967 (put-text-property start end 'mouse-face mouse)
1968 (put-text-property start end 'invisible nil)
1969 (if function (put-text-property start end 'speedbar-function function))
1970 (if token (put-text-property start end 'speedbar-token token))
1973 ;;; Initial Expansion list management
1975 (defun speedbar-initial-expansion-list ()
1976 "Return the current default expansion list.
1977 This is based on `speedbar-initial-expansion-list-name' referencing
1978 `speedbar-initial-expansion-mode-alist'."
1979 ;; cdr1 - name, cdr2 - menu
1980 (cdr (cdr (cdr (assoc speedbar-initial-expansion-list-name
1981 speedbar-initial-expansion-mode-alist)))))
1983 (defun speedbar-initial-menu ()
1984 "Return the current default menu data.
1985 This is based on `speedbar-initial-expansion-list-name' referencing
1986 `speedbar-initial-expansion-mode-alist'."
1988 (car (cdr (assoc speedbar-initial-expansion-list-name
1989 speedbar-initial-expansion-mode-alist)))))
1991 (defun speedbar-initial-keymap ()
1992 "Return the current default menu data.
1993 This is based on `speedbar-initial-expansion-list-name' referencing
1994 `speedbar-initial-expansion-mode-alist'."
1996 (car (cdr (cdr (assoc speedbar-initial-expansion-list-name
1997 speedbar-initial-expansion-mode-alist))))))
1999 (defun speedbar-initial-stealthy-functions ()
2000 "Return a list of functions to call stealthily.
2001 This is based on `speedbar-initial-expansion-list-name' referencing
2002 `speedbar-stealthy-function-list'."
2003 (cdr (assoc speedbar-initial-expansion-list-name
2004 speedbar-stealthy-function-list)))
2006 (defun speedbar-add-expansion-list (new-list)
2007 "Add NEW-LIST to the list of expansion lists."
2008 (add-to-list 'speedbar-initial-expansion-mode-alist new-list))
2010 (defun speedbar-change-initial-expansion-list (new-default)
2011 "Change speedbar's default expansion list to NEW-DEFAULT."
2014 (completing-read (format "Speedbar Mode (default %s): "
2015 speedbar-previously-used-expansion-list-name)
2016 speedbar-initial-expansion-mode-alist
2018 speedbar-previously-used-expansion-list-name)))
2019 (setq speedbar-previously-used-expansion-list-name
2020 speedbar-initial-expansion-list-name
2021 speedbar-initial-expansion-list-name new-default)
2023 (speedbar-reconfigure-keymaps))
2025 (defun speedbar-fetch-replacement-function (function)
2026 "Return a current mode specific replacement for function, or nil.
2027 Scans `speedbar-mode-functions-list' first for the current mode, then
2029 (cdr (assoc function
2030 (cdr (assoc speedbar-initial-expansion-list-name
2031 speedbar-mode-functions-list)))))
2033 (defun speedbar-add-mode-functions-list (new-list)
2034 "Add NEW-LIST to the list of mode functions.
2035 See `speedbar-mode-functions-list' for details."
2036 (add-to-list 'speedbar-mode-functions-list new-list))
2039 ;;; Special speedbar display management
2041 (defun speedbar-maybe-add-localized-support (buffer)
2042 "Quick check function called on BUFFERs by the speedbar timer function.
2043 Maintains the value of local variables which control speedbars use
2044 of the special mode functions."
2045 (or speedbar-special-mode-expansion-list
2046 (speedbar-add-localized-speedbar-support buffer)))
2048 (defun speedbar-add-localized-speedbar-support (buffer)
2049 "Add localized speedbar support to BUFFER's mode if it is available."
2050 (interactive "bBuffer: ")
2051 (if (stringp buffer) (setq buffer (get-buffer buffer)))
2052 (if (not (buffer-live-p buffer))
2057 (let ((ms (symbol-name major-mode)) v)
2058 (if (not (string-match "-mode$" ms))
2059 nil ;; do nothing to broken mode
2060 (setq ms (substring ms 0 (match-beginning 0)))
2061 (setq v (intern-soft (concat ms "-speedbar-buttons")))
2062 (make-local-variable 'speedbar-special-mode-expansion-list)
2064 (setq speedbar-special-mode-expansion-list t)
2065 ;; If it is autoloaded, we need to load it now so that
2066 ;; we have access to the varialbe -speedbar-menu-items.
2067 ;; Is this XEmacs safe?
2068 (let ((sf (symbol-function v)))
2069 (if (and (listp sf) (eq (car sf) 'autoload))
2070 (load-library (car (cdr sf)))))
2071 (setq speedbar-special-mode-expansion-list (list v))
2072 (setq v (intern-soft (concat ms "-speedbar-key-map")))
2074 nil ;; don't add special keymap
2075 (make-local-variable 'speedbar-special-mode-key-map)
2076 (setq speedbar-special-mode-key-map
2078 (setq v (intern-soft (concat ms "-speedbar-menu-items")))
2080 nil ;; don't add special menus
2081 (make-local-variable 'speedbar-easymenu-definition-special)
2082 (setq speedbar-easymenu-definition-special
2086 (defun speedbar-remove-localized-speedbar-support (buffer)
2087 "Remove any traces that BUFFER supports speedbar in a specialized way."
2090 (kill-local-variable 'speedbar-special-mode-expansion-list)
2091 (kill-local-variable 'speedbar-special-mode-key-map)
2092 (kill-local-variable 'speedbar-easymenu-definition-special)))
2094 ;;; File button management
2096 (defun speedbar-file-lists (directory)
2097 "Create file lists for DIRECTORY.
2098 The car is the list of directories, the cdr is list of files not
2099 matching ignored headers. Cache any directory files found in
2100 `speedbar-directory-contents-alist' and use that cache before scanning
2102 (setq directory (expand-file-name directory))
2103 ;; If in powerclick mode, then the directory we are getting
2104 ;; should be rescanned.
2105 (if speedbar-power-click
2106 (adelete 'speedbar-directory-contents-alist directory))
2107 ;; find the directory, either in the cache, or build it.
2108 (or (cdr-safe (assoc directory speedbar-directory-contents-alist))
2109 (let ((default-directory directory)
2110 (dir (directory-files directory nil))
2115 (or (string-match speedbar-file-unshown-regexp (car dir))
2116 (string-match speedbar-directory-unshown-regexp (car dir))))
2117 (if (file-directory-p (car dir))
2118 (setq dirs (cons (car dir) dirs))
2119 (setq files (cons (car dir) files))))
2120 (setq dir (cdr dir)))
2121 (let ((nl (cons (nreverse dirs) (list (nreverse files)))))
2122 (aput 'speedbar-directory-contents-alist directory nl)
2126 (defun speedbar-directory-buttons (directory index)
2127 "Insert a single button group at point for DIRECTORY.
2128 Each directory path part is a different button. If part of the path
2129 matches the user directory ~, then it is replaced with a ~.
2130 INDEX is not used, but is required by the caller."
2131 (let* ((tilde (expand-file-name "~"))
2132 (dd (expand-file-name directory))
2133 (junk (string-match (regexp-quote tilde) dd))
2135 (concat "~" (substring dd (match-end 0)))
2138 (if (string-match "^~/?\\'" displayme) (setq displayme (concat tilde "/")))
2142 (while (re-search-forward "\\([^/]+\\)/" nil t)
2143 (speedbar-make-button (match-beginning 1) (match-end 1)
2144 'speedbar-directory-face
2145 'speedbar-highlight-face
2146 'speedbar-directory-buttons-follow
2147 (if (= (match-beginning 1) p)
2148 (expand-file-name "~/") ;the tilde
2149 (buffer-substring-no-properties
2151 ;; Nuke the beginning of the directory if it's too long...
2152 (cond ((eq speedbar-directory-button-trim-method 'span)
2154 (let ((ww (or (speedbar-frame-width) 20)))
2155 (move-to-column ww nil)
2156 (while (>= (current-column) ww)
2157 (re-search-backward "/" nil t)
2158 (if (<= (current-column) 2)
2160 (re-search-forward "/" nil t)
2161 (if (< (current-column) 4)
2162 (re-search-forward "/" nil t))
2164 (if (looking-at "/?$")
2167 (move-to-column ww nil)))))
2168 ((eq speedbar-directory-button-trim-method 'trim)
2170 (let ((ww (or (speedbar-frame-width) 20))
2171 (tl (current-column)))
2174 (move-to-column (- tl ww))
2175 (if (re-search-backward "/" nil t)
2177 (delete-region (point-min) (point))
2181 (if (string-match "\\`/[^/]+/\\'" displayme)
2186 (speedbar-make-button p (point)
2187 'speedbar-directory-face
2188 'speedbar-highlight-face
2189 'speedbar-directory-buttons-follow
2192 (insert-char ?\n 1 nil)))
2194 (defun speedbar-make-tag-line (exp-button-type
2195 exp-button-char exp-button-function
2197 tag-button tag-button-function tag-button-data
2198 tag-button-face depth)
2199 "Create a tag line with EXP-BUTTON-TYPE for the small expansion button.
2200 This is the button that expands or contracts a node (if applicable),
2201 and EXP-BUTTON-CHAR the character in it (+, -, ?, etc). EXP-BUTTON-FUNCTION
2202 is the function to call if it's clicked on. Button types are
2203 'bracket, 'angle, 'curly, or nil. EXP-BUTTON-DATA is extra data
2204 attached to the text forming the expansion button.
2206 Next, TAG-BUTTON is the text of the tag. TAG-BUTTON-FUNCTION is the
2207 function to call if clicked on, and TAG-BUTTON-DATA is the data to
2208 attach to the text field (such a tag positioning, etc).
2209 TAG-BUTTON-FACE is a face used for this type of tag.
2211 Lastly, DEPTH shows the depth of expansion.
2213 This function assumes that the cursor is in the speedbar window at the
2214 position to insert a new item, and that the new item will end with a CR"
2215 (let ((start (point))
2217 (insert (int-to-string depth) ":")
2219 (put-text-property start end 'invisible t)
2221 (insert-char ? depth nil)
2222 (put-text-property (- (point) depth) (point) 'invisible nil)
2223 (let* ((exp-button (cond ((eq exp-button-type 'bracket) "[%c]")
2224 ((eq exp-button-type 'angle) "<%c>")
2225 ((eq exp-button-type 'curly) "{%c}")
2227 (buttxt (format exp-button exp-button-char))
2229 (end (progn (insert buttxt) (point)))
2230 (bf (if exp-button-type 'speedbar-button-face nil))
2231 (mf (if exp-button-function 'speedbar-highlight-face nil))
2233 (speedbar-make-button start end bf mf exp-button-function exp-button-data)
2234 (if speedbar-hide-button-brackets-flag
2236 (put-text-property start (1+ start) 'invisible t)
2237 (put-text-property end (1- end) 'invisible t)))
2239 (insert-char ? 1 nil)
2240 (put-text-property (1- (point)) (point) 'invisible nil)
2241 (let ((start (point))
2242 (end (progn (insert tag-button) (point))))
2243 (insert-char ?\n 1 nil)
2244 (put-text-property (1- (point)) (point) 'invisible nil)
2245 (speedbar-make-button start end tag-button-face
2246 (if tag-button-function 'speedbar-highlight-face nil)
2247 tag-button-function tag-button-data))
2250 (defun speedbar-change-expand-button-char (char)
2251 "Change the expansion button character to CHAR for the current line."
2254 (if (re-search-forward ":\\s-*.\\([-+?]\\)" (save-excursion (end-of-line)
2256 (speedbar-with-writable
2257 (goto-char (match-beginning 1))
2259 (insert-char char 1 t)
2260 (put-text-property (point) (1- (point)) 'invisible nil)))))
2263 ;;; Build button lists
2265 (defun speedbar-insert-files-at-point (files level)
2266 "Insert list of FILES starting at point, and indenting all files to LEVEL.
2267 Tag expandable items with a +, otherwise a ?. Don't highlight ? as we
2268 don't know how to manage them. The input parameter FILES is a cons
2269 cell of the form ( 'DIRLIST . 'FILELIST )"
2270 ;; Start inserting all the directories
2271 (let ((dirs (car files)))
2273 (speedbar-make-tag-line 'angle ?+ 'speedbar-dired (car dirs)
2274 (car dirs) 'speedbar-dir-follow nil
2275 'speedbar-directory-face level)
2276 (setq dirs (cdr dirs))))
2277 (let ((lst (car (cdr files)))
2278 (case-fold-search t))
2280 (let* ((known (string-match speedbar-file-regexp (car lst)))
2281 (expchar (if known ?+ ??))
2282 (fn (if known 'speedbar-tag-file nil)))
2283 (if (or speedbar-show-unknown-files (/= expchar ??))
2284 (speedbar-make-tag-line 'bracket expchar fn (car lst)
2285 (car lst) 'speedbar-find-file nil
2286 'speedbar-file-face level)))
2287 (setq lst (cdr lst)))))
2289 (defun speedbar-default-directory-list (directory index)
2290 "Insert files for DIRECTORY with level INDEX at point."
2291 (speedbar-insert-files-at-point
2292 (speedbar-file-lists directory) index)
2293 (speedbar-reset-scanners)
2295 ;; If the shown files variable has extra directories, then
2296 ;; it is our responsibility to redraw them all
2297 ;; Luckilly, the nature of inserting items into this list means
2298 ;; that by reversing it, we can easilly go in the right order
2299 (let ((sf (cdr (reverse speedbar-shown-directories))))
2300 (setq speedbar-shown-directories
2301 (list (expand-file-name default-directory)))
2302 ;; exand them all as we find them
2304 (if (speedbar-goto-this-file (car sf))
2307 (if (looking-at "[0-9]+:[ ]*<")
2309 (goto-char (match-end 0))
2310 (speedbar-do-function-pointer)))
2311 (setq sf (cdr sf)))))
2314 (defun speedbar-apply-one-tag-hierarchy-method (lst method)
2315 "Adjust the tag hierarchy LST by METHOD."
2318 (sort (copy-alist lst)
2319 (lambda (a b) (string< (car a) (car b)))))
2320 ((eq method 'prefix-group)
2325 (short-group-list nil)
2326 (short-start-name nil)
2327 (short-end-name nil)
2328 (num-shorts-grouped 0)
2329 (bins (make-vector 256 nil))
2331 ;; Break out sub-lists
2333 (if (listp (cdr-safe (car-safe lst)))
2334 (setq newlst (cons (car lst) newlst))
2335 (setq sublst (cons (car lst) sublst)))
2336 (setq lst (cdr lst)))
2337 ;; Reverse newlst because it was made backwards.
2338 ;; Sublist doesn't need reversing because the act
2339 ;; of binning things will reverse it for us.
2340 (setq newlst (nreverse newlst))
2341 ;; Now, first find out how long our list is. Never let a
2342 ;; list get-shorter than our minimum.
2343 (if (<= (length sublst) speedbar-tag-split-minimum-length)
2344 (setq work-list (nreverse sublst))
2345 (setq diff-idx (length (try-completion "" sublst)))
2346 ;; Sort the whole list into bins.
2348 (let ((e (car sublst))
2349 (s (car (car sublst))))
2350 (cond ((<= (length s) diff-idx)
2351 ;; 0 storage bin for shorty.
2352 (aset bins 0 (cons e (aref bins 0))))
2354 ;; stuff into a bin based on ascii value at diff
2355 (aset bins (aref s diff-idx)
2356 (cons e (aref bins (aref s diff-idx)))))))
2357 (setq sublst (cdr sublst)))
2358 ;; Go through all our bins Stick singles into our
2359 ;; junk-list, everything else as sublsts in work-list.
2360 ;; If two neighboring lists are both small, make a grouped
2361 ;; group combinding those two sub-lists.
2363 (while (> 256 diff-idx)
2364 (let ((l (nreverse ;; Reverse the list since they are stuck in
2366 (aref bins diff-idx))))
2368 (let ((tmp (cons (try-completion "" l) l)))
2369 (if (or (> (length l) speedbar-tag-regroup-maximum-length)
2370 (> (+ (length l) (length short-group-list))
2371 speedbar-tag-split-minimum-length))
2373 ;; We have reached a longer list, so we
2374 ;; must finish off a grouped group.
2376 ((and short-group-list
2377 (= (length short-group-list)
2378 num-shorts-grouped))
2379 ;; All singles? Junk list
2380 (setq junk-list (append short-group-list
2382 ((= num-shorts-grouped 1)
2383 ;; Only one short group? Just stick it in
2384 ;; there by itself. Make a group, and find
2386 (let ((subexpression (try-completion
2387 "" short-group-list)))
2388 (if (< (length subexpression)
2389 speedbar-tag-group-name-minimum-length)
2391 (concat short-start-name
2394 (car (car short-group-list))
2395 (length short-start-name))
2398 (cons (cons subexpression
2402 ;; Multiple groups to be named in a special
2403 ;; way by displaying the range over which we
2404 ;; have grouped them.
2406 (cons (cons (concat short-start-name
2409 (nreverse short-group-list))
2411 ;; Reset short group list information every time.
2412 (setq short-group-list nil
2413 short-start-name nil
2415 num-shorts-grouped 0)))
2416 ;; Ok, now that we cleaned up the short-group-list,
2417 ;; we can deal with this new list, to decide if it
2418 ;; should go on one of these sub-lists or not.
2419 (if (< (length l) speedbar-tag-regroup-maximum-length)
2420 (setq short-group-list (append short-group-list l)
2421 num-shorts-grouped (1+ num-shorts-grouped)
2422 short-end-name (car tmp)
2423 short-start-name (if short-start-name
2426 (setq work-list (cons tmp work-list))))))
2427 (setq diff-idx (1+ diff-idx))))
2428 ;; Did we run out of things? Drop our new list onto the end.
2430 ((and short-group-list (= (length short-group-list) num-shorts-grouped))
2431 ;; All singles? Junk list
2432 (setq junk-list (append short-group-list junk-list)))
2433 ((= num-shorts-grouped 1)
2434 ;; Only one short group? Just stick it in
2437 (cons (cons (try-completion "" short-group-list)
2441 ;; Multiple groups to be named in a special
2442 ;; way by displaying the range over which we
2443 ;; have grouped them.
2445 (cons (cons (concat short-start-name " to " short-end-name)
2448 ;; Reverse the work list nreversed when consing.
2449 (setq work-list (nreverse work-list))
2450 ;; Now, stick our new list onto the end of
2453 (append newlst work-list junk-list)
2454 (append newlst work-list))
2455 (append newlst junk-list))))
2456 ((eq method 'trim-words)
2463 (if (listp (cdr-safe (car-safe lst)))
2464 (setq newlst (cons (car lst) newlst))
2465 (setq sublst (cons (car lst) sublst)))
2466 (setq lst (cdr lst)))
2467 ;; Get the prefix to trim by. Make sure that we don't trim
2468 ;; off silly pieces, only complete understandable words.
2469 (setq trim-prefix (try-completion "" sublst))
2470 (if (or (= (length sublst) 1)
2472 (not (string-match "\\(\\w+\\W+\\)+" trim-prefix)))
2473 (append (nreverse newlst) (nreverse sublst))
2474 (setq trim-prefix (substring trim-prefix (match-beginning 0)
2476 (setq trim-chars (length trim-prefix))
2479 (cons (substring (car (car sublst)) trim-chars)
2482 sublst (cdr sublst)))
2483 ;; Put the lists together
2484 (append (nreverse newlst) trimlst))))
2485 ((eq method 'simple-group)
2489 (if (listp (cdr-safe (car-safe lst)))
2490 (setq newlst (cons (car lst) newlst))
2491 (setq sublst (cons (car lst) sublst)))
2492 (setq lst (cdr lst)))
2495 (setq newlst (cons (cons "Tags" (nreverse sublst)) newlst))
2496 (nreverse newlst))))
2499 (defun speedbar-create-tag-hierarchy (lst)
2500 "Adjust the tag hierarchy in LST, and return it.
2501 This uses `speedbar-tag-hierarchy-method' to determine how to adjust
2502 the list. See it's value for details."
2503 (let* ((f (save-excursion
2505 (speedbar-line-path)))
2506 (methods (if (get-file-buffer f)
2507 (save-excursion (set-buffer (get-file-buffer f))
2508 speedbar-tag-hierarchy-method)
2509 speedbar-tag-hierarchy-method)))
2511 (setq lst (speedbar-apply-one-tag-hierarchy-method lst (car methods))
2512 methods (cdr methods)))
2515 (defun speedbar-insert-generic-list (level lst expand-fun find-fun)
2516 "At LEVEL, insert a generic multi-level alist LST.
2517 Associations with lists get {+} tags (to expand into more nodes) and
2518 those with positions just get a > as the indicator. {+} buttons will
2519 have the function EXPAND-FUN and the token is the CDR list. The token
2520 name will have the function FIND-FUN and not token."
2521 ;; Remove imenu rescan button
2522 (if (string= (car (car lst)) "*Rescan*")
2523 (setq lst (cdr lst)))
2525 (setq lst (speedbar-create-tag-hierarchy lst))
2528 (cond ((null (car-safe lst)) nil) ;this would be a separator
2529 ((or (numberp (cdr-safe (car-safe lst)))
2530 (markerp (cdr-safe (car-safe lst))))
2531 (speedbar-make-tag-line nil nil nil nil ;no expand button data
2532 (car (car lst)) ;button name
2534 (cdr (car lst)) ;token is position
2537 ((listp (cdr-safe (car-safe lst)))
2538 (speedbar-make-tag-line 'curly ?+ expand-fun (cdr (car lst))
2539 (car (car lst)) ;button name
2540 nil nil 'speedbar-tag-face
2542 (t (message "Ooops!")))
2543 (setq lst (cdr lst))))
2547 (defun speedbar-update-contents ()
2548 "Generically update the contents of the speedbar buffer."
2550 ;; Set the current special buffer
2551 (setq speedbar-desired-buffer nil)
2552 ;; Check for special modes
2553 (speedbar-maybe-add-localized-support (current-buffer))
2554 ;; Choose the correct method of doodling.
2555 (if (and speedbar-mode-specific-contents-flag
2556 (listp speedbar-special-mode-expansion-list)
2557 speedbar-special-mode-expansion-list
2559 'speedbar-special-mode-expansion-list
2561 ;;(eq (get major-mode 'mode-class 'special)))
2562 (speedbar-update-special-contents)
2563 (speedbar-update-directory-contents)))
2565 (defun speedbar-update-directory-contents ()
2566 "Update the contents of the speedbar buffer based on the current directory."
2567 (let ((cbd (expand-file-name default-directory))
2569 (funclst (speedbar-initial-expansion-list))
2570 (cache speedbar-full-text-cache)
2571 ;; disable stealth during update
2572 (speedbar-stealthy-function-list nil)
2575 ;; Because there is a bug I can't find just yet
2578 (set-buffer speedbar-buffer)
2579 ;; If we are updating contents to where we are, then this is
2580 ;; really a request to update existing contents, so we must be
2581 ;; careful with our text cache!
2582 (if (member cbd speedbar-shown-directories)
2585 ;; If the current directory is not the last element in the dir
2586 ;; list, then we ALSO need to zap the list of expanded directories
2587 (if (/= (length (member cbd speedbar-shown-directories)) 1)
2588 (setq speedbar-shown-directories (list cbd))))
2590 ;; Build cbd-parent, and see if THAT is in the current shown
2591 ;; directories. First, go through pains to get the parent directory
2592 (if (and speedbar-smart-directory-expand-flag
2594 (setq cbd-parent cbd)
2595 (if (string-match "/$" cbd-parent)
2596 (setq cbd-parent (substring cbd-parent 0
2597 (match-beginning 0))))
2598 (setq cbd-parent (file-name-directory cbd-parent)))
2599 (member cbd-parent speedbar-shown-directories))
2600 (setq expand-local t)
2602 ;; If this directory is NOT in the current list of available
2603 ;; paths, then use the cache, and set the cache to our new
2604 ;; value. Make sure to unhighlight the current file, or if we
2605 ;; come back to this directory, it might be a different file
2606 ;; and then we get a mess!
2607 (if (> (point-max) 1)
2609 (speedbar-clear-current-file)
2610 (setq speedbar-full-text-cache
2611 (cons speedbar-shown-directories (buffer-string)))))
2613 ;; Check if our new directory is in the list of directories
2614 ;; shown in the text-cache
2615 (if (member cbd (car cache))
2616 (setq speedbar-shown-directories (car cache)
2618 ;; default the shown directories to this list...
2619 (setq speedbar-shown-directories (list cbd)))
2621 (if (not expand-local) (setq speedbar-last-selected-file nil))
2622 (speedbar-with-writable
2623 (if (and expand-local
2624 ;; Find this directory as a speedbar node.
2625 (speedbar-path-line cbd))
2627 (speedbar-expand-line)
2630 (setq default-directory
2631 (nth (1- (length speedbar-shown-directories))
2632 speedbar-shown-directories))
2633 (insert (cdr cache)))
2636 (setq default-directory cbd)
2637 (funcall (car funclst) cbd 0)
2638 (setq funclst (cdr funclst))))))
2639 (goto-char (point-min)))))
2640 (speedbar-reconfigure-keymaps))
2642 (defun speedbar-update-special-contents ()
2643 "Used the mode-specific variable to fill in the speedbar buffer.
2644 This should only be used by modes classified as special."
2645 (let ((funclst speedbar-special-mode-expansion-list)
2646 (specialbuff (current-buffer)))
2648 (setq speedbar-desired-buffer specialbuff)
2649 (set-buffer speedbar-buffer)
2650 ;; If we are leaving a directory, cache it.
2651 (if (not speedbar-shown-directories)
2654 ;; Clean up directory maintenance stuff
2655 (speedbar-clear-current-file)
2656 (setq speedbar-full-text-cache
2657 (cons speedbar-shown-directories (buffer-string))
2658 speedbar-shown-directories nil))
2659 ;; Now fill in the buffer with our newly found specialized list.
2660 (speedbar-with-writable
2662 ;; We do not erase the buffer because these functions may
2663 ;; decide NOT to update themselves.
2664 (funcall (car funclst) specialbuff)
2665 (setq funclst (cdr funclst))))
2666 (goto-char (point-min))))
2667 (speedbar-reconfigure-keymaps))
2669 (defun speedbar-timer-fn ()
2670 "Run whenever Emacs is idle to update the speedbar item."
2671 (if (not (and (frame-live-p speedbar-frame)
2672 (frame-live-p speedbar-attached-frame)))
2673 (speedbar-set-timer nil)
2674 ;; Save all the match data so that we don't mess up executing fns
2676 ;; Only do stuff if the frame is visible, not an icon, and if
2677 ;; it is currently flagged to do something.
2678 (if (and speedbar-update-flag
2679 (frame-visible-p speedbar-frame)
2680 (not (eq (frame-visible-p speedbar-frame) 'icon)))
2681 (let ((af (selected-frame)))
2682 (save-window-excursion
2683 (select-frame speedbar-attached-frame)
2684 ;; make sure we at least choose a window to
2685 ;; get a good directory from
2686 (if (window-minibuffer-p (selected-window))
2688 ;; Check for special modes
2689 (speedbar-maybe-add-localized-support (current-buffer))
2690 ;; Update for special mode all the time!
2691 (if (and speedbar-mode-specific-contents-flag
2692 (listp speedbar-special-mode-expansion-list)
2693 speedbar-special-mode-expansion-list
2695 'speedbar-special-mode-expansion-list
2697 ;;(eq (get major-mode 'mode-class 'special)))
2699 (if (<= 2 speedbar-verbosity-level)
2700 (message "Updating speedbar to special mode: %s..."
2702 (speedbar-update-special-contents)
2703 (if (<= 2 speedbar-verbosity-level)
2705 (message "Updating speedbar to special mode: %s...done"
2708 ;; Update all the contents if directories change!
2709 (if (or (member (expand-file-name default-directory)
2710 speedbar-shown-directories)
2711 (and speedbar-ignored-path-regexp
2713 speedbar-ignored-path-regexp
2714 (expand-file-name default-directory)))
2715 (member major-mode speedbar-ignored-modes)
2716 (eq af speedbar-frame)
2717 (not (buffer-file-name)))
2719 (if (<= 1 speedbar-verbosity-level)
2720 (message "Updating speedbar to: %s..."
2722 (speedbar-update-directory-contents)
2723 (if (<= 1 speedbar-verbosity-level)
2725 (message "Updating speedbar to: %s...done"
2729 ;; Now run stealthy updates of time-consuming items
2730 (speedbar-stealthy-updates)))
2731 ;; Now run the mouse tracking system
2732 (speedbar-show-info-under-mouse)))
2733 (run-hooks 'speedbar-timer-hook))
2736 ;;; Stealthy activities
2738 (defvar speedbar-stealthy-update-recurse nil
2739 "Recursion avoidance variable for stealthy update.")
2741 (defun speedbar-stealthy-updates ()
2742 "For a given speedbar, run all items in the stealthy function list.
2743 Each item returns t if it completes successfully, or nil if
2744 interrupted by the user."
2745 (if (not speedbar-stealthy-update-recurse)
2746 (let ((l (speedbar-initial-stealthy-functions))
2747 (speedbar-stealthy-update-recurse t))
2749 (speedbar-with-writable
2750 (while (and l (funcall (car l)))
2753 ;;(message "Exit with %S" (car l))
2756 (defun speedbar-reset-scanners ()
2757 "Reset any variables used by functions in the stealthy list as state.
2758 If new functions are added, their state needs to be updated here."
2759 (setq speedbar-vc-to-do-point t
2760 speedbar-obj-to-do-point t)
2761 (run-hooks 'speedbar-scanner-reset-hook)
2764 (defun speedbar-find-selected-file (file)
2765 "Goto the line where FILE is."
2766 (goto-char (point-min))
2768 (while (and (setq m (re-search-forward
2769 (concat " \\(" (file-name-nondirectory file)
2770 "\\)\\(" speedbar-indicator-regex "\\)?\n")
2776 (goto-char (match-beginning 0))
2779 (looking-at "[0-9]+:")
2780 (string-to-number (match-string 0)))))
2781 (match-string 1))))))
2784 (goto-char (match-beginning 1))
2785 (match-string 1)))))
2787 (defun speedbar-clear-current-file ()
2788 "Locate the file thought to be current, and remove its highlighting."
2790 (set-buffer speedbar-buffer)
2791 (if speedbar-last-selected-file
2792 (speedbar-with-writable
2793 (if (speedbar-find-selected-file speedbar-last-selected-file)
2794 (put-text-property (match-beginning 1)
2797 'speedbar-file-face))))))
2799 (defun speedbar-update-current-file ()
2800 "Find the current file, and update our visuals to indicate its name.
2801 This is specific to file names. If the file name doesn't show up, but
2802 it should be in the list, then the directory cache needs to be
2804 (let* ((lastf (selected-frame))
2805 (newcfd (save-excursion
2806 (select-frame speedbar-attached-frame)
2807 (let ((rf (if (buffer-file-name)
2810 (select-frame lastf)
2812 (newcf (if newcfd newcfd))
2813 (lastb (current-buffer))
2814 (sucf-recursive (boundp 'sucf-recursive))
2815 (case-fold-search t))
2817 ;; check here, that way we won't refresh to newcf until
2818 ;; its been written, thus saving ourselves some time
2819 (file-exists-p newcf)
2820 (not (string= newcf speedbar-last-selected-file)))
2822 ;; It is important to select the frame, otherwise the window
2823 ;; we want the cursor to move in will not be updated by the
2824 ;; search-forward command.
2825 (select-frame speedbar-frame)
2826 ;; Remove the old file...
2827 (speedbar-clear-current-file)
2828 ;; now highlight the new one.
2829 (set-buffer speedbar-buffer)
2830 (speedbar-with-writable
2831 (if (speedbar-find-selected-file newcf)
2832 ;; put the property on it
2833 (put-text-property (match-beginning 1)
2836 'speedbar-selected-face)
2837 ;; Oops, it's not in the list. Should it be?
2838 (if (and (string-match speedbar-file-regexp newcf)
2839 (string= (file-name-directory newcfd)
2840 (expand-file-name default-directory)))
2841 ;; yes, it is (we will ignore unknowns for now...)
2844 (if (speedbar-find-selected-file newcf)
2845 ;; put the property on it
2846 (put-text-property (match-beginning 1)
2849 'speedbar-selected-face)))
2850 ;; if it's not in there now, whatever...
2852 (setq speedbar-last-selected-file newcf))
2853 (if (not sucf-recursive)
2855 (speedbar-center-buffer-smartly)
2856 (speedbar-position-cursor-on-line)
2859 (select-frame lastf)
2861 ;; return that we are done with this activity.
2864 (defun speedbar-add-indicator (indicator-string &optional replace-this)
2865 "Add INDICATOR-STRING to the end of this speedbar line.
2866 If INDICATOR-STRING is space, and REPLACE-THIS is a character, then
2867 an the existing indicator is removed. If there is already an
2868 indicator, then do not add a space."
2870 ;; The nature of the beast: Assume we are in "the right place"
2872 (skip-chars-backward (concat " " speedbar-vc-indicator
2873 (car speedbar-obj-indicator)
2874 (cdr speedbar-obj-indicator)))
2875 (if (and (not (looking-at speedbar-indicator-regex))
2876 (not (string= indicator-string " ")))
2877 (insert speedbar-indicator-separator))
2878 (speedbar-with-writable
2880 (if (and replace-this
2881 (re-search-forward replace-this (save-excursion (end-of-line)
2884 (delete-region (match-beginning 0) (match-end 0))))
2886 (if (not (string= " " indicator-string))
2887 (insert indicator-string))))
2889 ;; Load efs/ange-ftp only if compiling to remove byte-compiler warnings.
2890 ;; Steven L Baur <steve@xemacs.org> said this was important:
2891 (eval-when-compile (or (featurep 'xemacs)
2892 (condition-case () (require 'efs)
2893 (error (require 'ange-ftp)))))
2895 (defun speedbar-check-vc ()
2896 "Scan all files in a directory, and for each see if it's checked out.
2897 See `speedbar-this-file-in-vc' and `speedbar-vc-check-dir-p' for how
2898 to add more types of version control systems."
2899 ;; Check for to-do to be reset. If reset but no RCS is available
2900 ;; then set to nil (do nothing) otherwise, start at the beginning
2902 (set-buffer speedbar-buffer)
2903 (if (and speedbar-vc-do-check (eq speedbar-vc-to-do-point t)
2904 (speedbar-vc-check-dir-p default-directory)
2905 (not (or (and (featurep 'ange-ftp)
2907 (car (if speedbar-xemacsp
2908 ange-ftp-path-format
2909 ange-ftp-name-format))
2910 (expand-file-name default-directory)))
2911 ;; efs support: Bob Weiner
2912 (and (featurep 'efs)
2914 (car efs-path-regexp)
2915 (expand-file-name default-directory))))))
2916 (setq speedbar-vc-to-do-point 0))
2917 (if (numberp speedbar-vc-to-do-point)
2919 (goto-char speedbar-vc-to-do-point)
2920 (while (and (not (input-pending-p))
2921 (re-search-forward "^\\([0-9]+\\):\\s-*\\[[+-]\\] "
2923 (setq speedbar-vc-to-do-point (point))
2924 (if (speedbar-check-vc-this-line (match-string 1))
2925 (speedbar-add-indicator speedbar-vc-indicator
2926 (regexp-quote speedbar-vc-indicator))
2927 (speedbar-add-indicator " "
2928 (regexp-quote speedbar-vc-indicator))))
2929 (if (input-pending-p)
2930 ;; return that we are incomplete
2932 ;; we are done, set to-do to nil
2933 (setq speedbar-vc-to-do-point nil)
2938 (defun speedbar-check-vc-this-line (depth)
2939 "Return t if the file on this line is check of of a version control system.
2940 Parameter DEPTH is a string with the current depth of indentation of
2941 the file being checked."
2942 (let* ((d (string-to-int depth))
2943 (f (speedbar-line-path d))
2944 (fn (buffer-substring-no-properties
2945 ;; Skip-chars: thanks ptype@dra.hmg.gb
2947 (skip-chars-forward "^ "
2948 (save-excursion (end-of-line)
2951 (fulln (concat f fn)))
2952 (if (<= 2 speedbar-verbosity-level)
2953 (message "Speedbar vc check...%s" fulln))
2954 (and (file-writable-p fulln)
2955 (speedbar-this-file-in-vc f fn))))
2957 (defun speedbar-vc-check-dir-p (path)
2958 "Return t if we should bother checking PATH for version control files.
2959 This can be overloaded to add new types of version control systems."
2962 (file-exists-p (concat path "RCS/"))
2964 (file-exists-p (concat path "SCCS/"))
2965 ;; Remote SCCS project
2966 (let ((proj-dir (getenv "PROJECTDIR")))
2968 (file-exists-p (concat proj-dir "/SCCS"))
2971 (run-hook-with-args 'speedbar-vc-path-enable-hook path)
2974 (defun speedbar-this-file-in-vc (path name)
2975 "Check to see if the file in PATH with NAME is in a version control system.
2976 You can add new VC systems by overriding this function. You can
2977 optimize this function by overriding it and only doing those checks
2978 that will occur on your system."
2981 (file-exists-p (concat path "RCS/" name ",v"))
2982 (file-exists-p (concat path "RCS/" name))
2983 ;; Local SCCS file name
2984 (file-exists-p (concat path "SCCS/s." name))
2985 ;; Remote SCCS file name
2986 (let ((proj-dir (getenv "PROJECTDIR")))
2988 (file-exists-p (concat proj-dir "/SCCS/s." name))
2991 (run-hook-with-args 'speedbar-vc-in-control-hook path name)
2994 ;; Objet File scanning
2995 (defun speedbar-check-objects ()
2996 "Scan all files in a directory, and for each see if there is an object.
2997 See `speedbar-check-obj-this-line' and `speedbar-obj-alist' for how
2998 to add more object types."
2999 ;; Check for to-do to be reset. If reset but no RCS is available
3000 ;; then set to nil (do nothing) otherwise, start at the beginning
3002 (set-buffer speedbar-buffer)
3003 (if (and speedbar-obj-do-check (eq speedbar-obj-to-do-point t))
3004 (setq speedbar-obj-to-do-point 0))
3005 (if (numberp speedbar-obj-to-do-point)
3007 (goto-char speedbar-obj-to-do-point)
3008 (while (and (not (input-pending-p))
3009 (re-search-forward "^\\([0-9]+\\):\\s-*\\[[+-]\\] "
3011 (setq speedbar-obj-to-do-point (point))
3012 (let ((ind (speedbar-check-obj-this-line (match-string 1))))
3013 (if (not ind) (setq ind " "))
3014 (speedbar-add-indicator ind (concat
3015 (car speedbar-obj-indicator)
3017 (cdr speedbar-obj-indicator)))))
3018 (if (input-pending-p)
3019 ;; return that we are incomplete
3021 ;; we are done, set to-do to nil
3022 (setq speedbar-obj-to-do-point nil)
3027 (defun speedbar-check-obj-this-line (depth)
3028 "Return t if the file on this line has an associated object.
3029 Parameter DEPTH is a string with the current depth of indentation of
3030 the file being checked."
3031 (let* ((d (string-to-int depth))
3032 (f (speedbar-line-path d))
3033 (fn (buffer-substring-no-properties
3034 ;; Skip-chars: thanks ptype@dra.hmg.gb
3036 (skip-chars-forward "^ "
3037 (save-excursion (end-of-line)
3040 (fulln (concat f fn)))
3041 (if (<= 2 speedbar-verbosity-level)
3042 (message "Speedbar obj check...%s" fulln))
3043 (let ((oa speedbar-obj-alist))
3044 (while (and oa (not (string-match (car (car oa)) fulln)))
3046 (if (not (and oa (file-exists-p (concat (file-name-sans-extension fulln)
3049 ;; Find out if the object is out of date or not.
3050 (let ((date1 (nth 5 (file-attributes fulln)))
3051 (date2 (nth 5 (file-attributes (concat
3052 (file-name-sans-extension fulln)
3054 (if (or (< (car date1) (car date2))
3055 (and (= (car date1) (car date2))
3056 (< (nth 1 date1) (nth 1 date2))))
3057 (car speedbar-obj-indicator)
3058 (cdr speedbar-obj-indicator)))))))
3060 ;;; Clicking Activity
3062 (defun speedbar-quick-mouse (e)
3063 "Since mouse events are strange, this will keep the mouse nicely positioned.
3064 This should be bound to mouse event E."
3067 (speedbar-position-cursor-on-line)
3070 (defun speedbar-position-cursor-on-line ()
3071 "Position the cursor on a line."
3072 (let ((oldpos (point)))
3074 (if (looking-at "[0-9]+:\\s-*..?.? ")
3075 (goto-char (1- (match-end 0)))
3076 (goto-char oldpos))))
3078 (defun speedbar-power-click (e)
3079 "Activate any speedbar button as a power click.
3080 This should be bound to mouse event E."
3082 (let ((speedbar-power-click t))
3083 (speedbar-click e)))
3085 (defun speedbar-click (e)
3086 "Activate any speedbar buttons where the mouse is clicked.
3087 This must be bound to a mouse event. A button is any location of text
3088 with a mouse face that has a text property called `speedbar-function'.
3089 This should be bound to mouse event E."
3092 (speedbar-do-function-pointer)
3093 (speedbar-quick-mouse e))
3095 (defun speedbar-double-click (e)
3096 "Activate any speedbar buttons where the mouse is clicked.
3097 This must be bound to a mouse event. A button is any location of text
3098 with a mouse face that has a text property called `speedbar-function'.
3099 This should be bound to mouse event E."
3101 ;; Emacs only. XEmacs handles this via `mouse-track-click-hook'.
3102 (cond ((eq (car e) 'down-mouse-1)
3103 (mouse-set-point e))
3104 ((eq (car e) 'mouse-1)
3105 (speedbar-quick-mouse e))
3106 ((or (eq (car e) 'double-down-mouse-1)
3107 (eq (car e) 'triple-down-mouse-1))
3109 (speedbar-do-function-pointer)
3110 (speedbar-quick-mouse e))))
3112 (defun speedbar-do-function-pointer ()
3113 "Look under the cursor and examine the text properties.
3114 From this extract the file/tag name, token, indentation level and call
3115 a function if appropriate"
3116 (let* ((fn (get-text-property (point) 'speedbar-function))
3117 (tok (get-text-property (point) 'speedbar-token))
3118 ;; The 1-,+ is safe because scaning starts AFTER the point
3119 ;; specified. This lets the search include the character the
3121 (tp (previous-single-property-change
3122 (1+ (point)) 'speedbar-function))
3123 (np (next-single-property-change
3124 (point) 'speedbar-function))
3125 (txt (buffer-substring-no-properties (or tp (point-min))
3126 (or np (point-max))))
3127 (dent (save-excursion (beginning-of-line)
3129 (if (looking-at "[0-9]+")
3130 (buffer-substring-no-properties
3131 (match-beginning 0) (match-end 0))
3133 ;;(message "%S:%S:%S:%s" fn tok txt dent)
3134 (and fn (funcall fn txt tok dent)))
3135 (speedbar-position-cursor-on-line))
3137 ;;; Reading info from the speedbar buffer
3139 (defun speedbar-line-text (&optional p)
3140 "Retrieve the text after prefix junk for the current line.
3141 Optional argument P is where to start the search from."
3143 (if p (goto-char p))
3145 (if (looking-at (concat
3146 "\\([0-9]+\\): *[[<{][-+?][]>}] \\([^ \n]+\\)\\("
3147 speedbar-indicator-regex "\\)?"))
3151 (defun speedbar-line-token (&optional p)
3152 "Retrieve the token information after the prefix junk for the current line.
3153 Optional argument P is where to start the search from."
3155 (if p (goto-char p))
3157 (if (looking-at (concat
3158 "\\([0-9]+\\): *[[<{][-+?][]>}] \\([^ \n]+\\)\\("
3159 speedbar-indicator-regex "\\)?"))
3161 (goto-char (match-beginning 2))
3162 (get-text-property (point) 'speedbar-token))
3165 (defun speedbar-line-file (&optional p)
3166 "Retrieve the file or whatever from the line at P point.
3167 The return value is a string representing the file. If it is a
3168 directory, then it is the directory name."
3170 (let ((f (speedbar-line-text p)))
3172 (let* ((depth (string-to-int (match-string 1)))
3173 (path (speedbar-line-path depth)))
3177 (defun speedbar-goto-this-file (file)
3178 "If FILE is displayed, goto this line and return t.
3179 Otherwise do not move and return nil."
3180 (let ((path (substring (file-name-directory (expand-file-name file))
3181 (length (expand-file-name default-directory))))
3184 (goto-char (point-min))
3185 ;; scan all the directories
3186 (while (and path (not (eq path t)))
3187 (if (string-match "^/?\\([^/]+\\)" path)
3188 (let ((pp (match-string 1 path)))
3189 (if (save-match-data
3190 (re-search-forward (concat "> " (regexp-quote pp) "$")
3192 (setq path (substring path (match-end 1)))
3195 ;; find the file part
3196 (if (or (not path) (string= (file-name-nondirectory file) ""))
3197 ;; only had a dir part
3200 (speedbar-position-cursor-on-line)
3202 (goto-char dest) nil)
3203 ;; find the file part
3204 (let ((nd (file-name-nondirectory file)))
3205 (if (re-search-forward
3206 (concat "] \\(" (regexp-quote nd)
3207 "\\)\\(" speedbar-indicator-regex "\\)$")
3210 (speedbar-position-cursor-on-line)
3215 (defun speedbar-line-path (&optional depth)
3216 "Retrieve the pathname associated with the current line.
3217 This may require traversing backwards from DEPTH and combining the default
3218 directory with these items. This function is replaceable in
3219 `speedbar-mode-functions-list' as `speedbar-line-path'"
3220 (let ((rf (speedbar-fetch-replacement-function 'speedbar-line-path)))
3221 (if rf (funcall rf depth) default-directory)))
3223 (defun speedbar-files-line-path (&optional depth)
3224 "Retrieve the pathname associated with the current line.
3225 This may require traversing backwards from DEPTH and combining the default
3226 directory with these items."
3232 (looking-at "^\\([0-9]+\\):")
3233 (setq depth (string-to-int (match-string 1)))))
3235 (setq depth (1- depth))
3236 (while (/= depth -1)
3237 (if (not (re-search-backward (format "^%d:" depth) nil t))
3238 (error "Error building path of tag")
3239 (cond ((looking-at "[0-9]+:\\s-*<->\\s-+\\([^\n]+\\)$")
3240 (setq path (concat (buffer-substring-no-properties
3241 (match-beginning 1) (match-end 1))
3244 ((looking-at "[0-9]+:\\s-*[-]\\s-+\\([^\n]+\\)$")
3245 ;; This is the start of our path.
3246 (setq path (buffer-substring-no-properties
3247 (match-beginning 1) (match-end 1))))))
3248 (setq depth (1- depth)))
3250 (string-match (concat speedbar-indicator-regex "$")
3252 (setq path (substring path 0 (match-beginning 0))))
3253 (concat default-directory path)))))
3255 (defun speedbar-path-line (path)
3256 "Position the cursor on the line specified by PATH."
3258 (if (string-match "/$" path)
3259 (setq path (substring path 0 (match-beginning 0))))
3260 (let ((nomatch t) (depth 0)
3261 (fname (file-name-nondirectory path))
3262 (pname (file-name-directory path)))
3263 (if (not (member pname speedbar-shown-directories))
3264 (error "Internal Error: File %s not shown in speedbar" path))
3265 (goto-char (point-min))
3268 (concat "[]>] \\(" (regexp-quote fname)
3269 "\\)\\(" speedbar-indicator-regex "\\)?$")
3272 (looking-at "\\([0-9]+\\):")
3273 (setq depth (string-to-int (match-string 0))
3274 nomatch (not (string= pname (speedbar-line-path depth))))
3279 (defun speedbar-edit-line ()
3280 "Edit whatever tag or file is on the current speedbar line."
3284 ;; If this fails, then it is a non-standard click, and as such,
3285 ;; perfectly allowed.
3286 (if (re-search-forward "[]>?}] [^ ]"
3287 (save-excursion (end-of-line) (point))
3289 (speedbar-do-function-pointer)
3291 (speedbar-do-function-pointer)))
3293 (defun speedbar-expand-line ()
3294 "Expand the line under the cursor."
3297 (re-search-forward ":\\s-*.\\+. " (save-excursion (end-of-line) (point)))
3299 (speedbar-do-function-pointer))
3301 (defun speedbar-contract-line ()
3302 "Contract the line under the cursor."
3305 (re-search-forward ":\\s-*.-. " (save-excursion (end-of-line) (point)))
3307 (speedbar-do-function-pointer))
3309 (if speedbar-xemacsp
3310 (defalias 'speedbar-mouse-event-p 'button-press-event-p)
3311 (defun speedbar-mouse-event-p (event)
3312 "Return t if the event is a mouse related event"
3313 ;; And Emacs does it this way
3314 (if (and (listp event)
3315 (member (event-basic-type event)
3316 '(mouse-1 mouse-2 mouse-3)))
3320 (defun speedbar-maybee-jump-to-attached-frame ()
3321 "Jump to the attached frame ONLY if this was not a mouse event."
3322 (if (or (not (speedbar-mouse-event-p last-input-event))
3323 speedbar-activity-change-focus-flag)
3325 (select-frame speedbar-attached-frame)
3328 (defun speedbar-find-file (text token indent)
3329 "Speedbar click handler for filenames.
3330 TEXT, the file will be displayed in the attached frame.
3331 TOKEN is unused, but required by the click handler. INDENT is the
3332 current indentation level."
3333 (let ((cdd (speedbar-line-path indent)))
3334 (speedbar-find-file-in-frame (concat cdd text))
3335 (speedbar-stealthy-updates)
3336 (run-hooks 'speedbar-visiting-file-hook)
3337 ;; Reset the timer with a new timeout when cliking a file
3338 ;; in case the user was navigating directories, we can cancel
3339 ;; that other timer.
3340 (speedbar-set-timer speedbar-update-speed))
3341 (speedbar-maybee-jump-to-attached-frame))
3343 (defun speedbar-dir-follow (text token indent)
3344 "Speedbar click handler for directory names.
3345 Clicking a directory will cause the speedbar to list files in the
3346 the subdirectory TEXT. TOKEN is an unused requirement. The
3347 subdirectory chosen will be at INDENT level."
3348 (setq default-directory
3349 (concat (expand-file-name (concat (speedbar-line-path indent) text))
3351 ;; Because we leave speedbar as the current buffer,
3352 ;; update contents will change directory without
3353 ;; having to touch the attached frame. Turn off smart expand just
3355 (let ((speedbar-smart-directory-expand-flag nil))
3356 (speedbar-update-contents))
3357 (speedbar-set-timer speedbar-navigating-speed)
3358 (setq speedbar-last-selected-file nil)
3359 (speedbar-stealthy-updates))
3361 (defun speedbar-delete-subblock (indent)
3362 "Delete text from point to indentation level INDENT or greater.
3363 Handles end-of-sublist smartly."
3364 (speedbar-with-writable
3366 (end-of-line) (forward-char 1)
3367 (let ((start (point)))
3368 (while (and (looking-at "^\\([0-9]+\\):")
3369 (> (string-to-int (match-string 1)) indent)
3372 (beginning-of-line))
3373 (delete-region start (point))))))
3375 (defun speedbar-dired (text token indent)
3376 "Speedbar click handler for directory expand button.
3377 Clicking this button expands or contracts a directory. TEXT is the
3378 button clicked which has either a + or -. TOKEN is the directory to be
3379 expanded. INDENT is the current indentation level."
3380 (cond ((string-match "+" text) ;we have to expand this dir
3381 (setq speedbar-shown-directories
3382 (cons (expand-file-name
3383 (concat (speedbar-line-path indent) token "/"))
3384 speedbar-shown-directories))
3385 (speedbar-change-expand-button-char ?-)
3386 (speedbar-reset-scanners)
3388 (end-of-line) (forward-char 1)
3389 (speedbar-with-writable
3390 (speedbar-default-directory-list
3391 (concat (speedbar-line-path indent) token "/")
3393 ((string-match "-" text) ;we have to contract this node
3394 (speedbar-reset-scanners)
3395 (let ((oldl speedbar-shown-directories)
3397 (td (expand-file-name
3398 (concat (speedbar-line-path indent) token))))
3400 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
3401 (setq newl (cons (car oldl) newl)))
3402 (setq oldl (cdr oldl)))
3403 (setq speedbar-shown-directories (nreverse newl)))
3404 (speedbar-change-expand-button-char ?+)
3405 (speedbar-delete-subblock indent)
3407 (t (error "Ooops... not sure what to do")))
3408 (speedbar-center-buffer-smartly)
3409 (setq speedbar-last-selected-file nil)
3410 (save-excursion (speedbar-stealthy-updates)))
3412 (defun speedbar-directory-buttons-follow (text token indent)
3413 "Speedbar click handler for default directory buttons.
3414 TEXT is the button clicked on. TOKEN is the directory to follow.
3415 INDENT is the current indentation level and is unused."
3416 (if (string-match "^[A-z]:$" token)
3417 (setq default-directory (concat token (char-to-string directory-sep-char)))
3418 (setq default-directory token))
3419 ;; Because we leave speedbar as the current buffer,
3420 ;; update contents will change directory without
3421 ;; having to touch the attached frame.
3422 (speedbar-update-contents)
3423 (speedbar-set-timer speedbar-navigating-speed))
3425 (defun speedbar-tag-file (text token indent)
3426 "The cursor is on a selected line. Expand the tags in the specified file.
3427 The parameter TEXT and TOKEN are required, where TEXT is the button
3428 clicked, and TOKEN is the file to expand. INDENT is the current
3430 (cond ((string-match "+" text) ;we have to expand this file
3431 (let* ((fn (expand-file-name (concat (speedbar-line-path indent)
3433 (lst (if speedbar-use-imenu-flag
3434 (let ((tim (speedbar-fetch-dynamic-imenu fn)))
3436 (speedbar-fetch-dynamic-etags fn)
3438 (speedbar-fetch-dynamic-etags fn))))
3439 ;; if no list, then remove expando button
3441 (speedbar-change-expand-button-char ??)
3442 (speedbar-change-expand-button-char ?-)
3443 (speedbar-with-writable
3445 (end-of-line) (forward-char 1)
3446 (speedbar-insert-generic-list indent
3447 lst 'speedbar-tag-expand
3448 'speedbar-tag-find))))))
3449 ((string-match "-" text) ;we have to contract this node
3450 (speedbar-change-expand-button-char ?+)
3451 (speedbar-delete-subblock indent))
3452 (t (error "Ooops... not sure what to do")))
3453 (speedbar-center-buffer-smartly))
3455 (defun speedbar-tag-find (text token indent)
3456 "For the tag TEXT in a file TOKEN, goto that position.
3457 INDENT is the current indentation level."
3458 (let ((file (speedbar-line-path indent)))
3459 (speedbar-find-file-in-frame file)
3460 (save-excursion (speedbar-stealthy-updates))
3461 ;; Reset the timer with a new timeout when cliking a file
3462 ;; in case the user was navigating directories, we can cancel
3463 ;; that other timer.
3464 (speedbar-set-timer speedbar-update-speed)
3466 (run-hooks 'speedbar-visiting-tag-hook)
3468 (speedbar-maybee-jump-to-attached-frame)
3471 (defun speedbar-tag-expand (text token indent)
3472 "Expand a tag sublist. Imenu will return sub-lists of specialized tag types.
3473 Etags does not support this feature. TEXT will be the button
3474 string. TOKEN will be the list, and INDENT is the current indentation
3476 (cond ((string-match "+" text) ;we have to expand this file
3477 (speedbar-change-expand-button-char ?-)
3478 (speedbar-with-writable
3480 (end-of-line) (forward-char 1)
3481 (speedbar-insert-generic-list indent token 'speedbar-tag-expand
3482 'speedbar-tag-find))))
3483 ((string-match "-" text) ;we have to contract this node
3484 (speedbar-change-expand-button-char ?+)
3485 (speedbar-delete-subblock indent))
3486 (t (error "Ooops... not sure what to do")))
3487 (speedbar-center-buffer-smartly))
3489 ;;; Loading files into the attached frame.
3491 (defun speedbar-find-file-in-frame (file)
3492 "This will load FILE into the speedbar attached frame.
3493 If the file is being displayed in a different frame already, then raise that
3495 (let* ((buff (find-file-noselect file))
3496 (bwin (get-buffer-window buff 0)))
3499 (select-window bwin)
3500 (raise-frame (window-frame bwin)))
3501 (if speedbar-power-click
3502 (let ((pop-up-frames t)) (select-window (display-buffer buff)))
3503 (select-frame speedbar-attached-frame)
3504 (switch-to-buffer buff))))
3507 ;;; Centering Utility
3509 (defun speedbar-center-buffer-smartly ()
3510 "Recenter a speedbar buffer so the current indentation level is all visible.
3511 This assumes that the cursor is on a file, or tag of a file which the user is
3513 (if (<= (count-lines (point-min) (point-max))
3514 (1- (window-height (selected-window))))
3515 ;; whole buffer fits
3517 (goto-char (point-min))
3521 (let (depth start end exp p)
3524 (setq depth (if (looking-at "[0-9]+")
3525 (string-to-int (buffer-substring-no-properties
3526 (match-beginning 0) (match-end 0)))
3528 (setq exp (format "^%d:\\s-*[[{<]\\([?+-]\\)[]>}]" depth)))
3531 (if (re-search-backward exp nil t)
3532 (setq start (point))
3533 (setq start (point-min)))
3534 (save-excursion ;Not sure about this part.
3537 (while (and (not (re-search-forward exp nil t))
3539 (setq depth (1- depth))
3540 (setq exp (format "^%d:\\s-*[[{<]\\([?+-]\\)[]>}]" depth)))
3543 (setq end (point-max)))))
3544 ;; Now work out the details of centering
3545 (let ((nl (count-lines start end))
3547 (if (> nl (window-height (selected-window)))
3548 ;; We can't fit it all, so just center on cursor
3549 (progn (goto-char start)
3551 ;; we can fit everything on the screen, but...
3552 (if (and (pos-visible-in-window-p start (selected-window))
3553 (pos-visible-in-window-p end (selected-window)))
3556 ;; we need to do something...
3558 (let ((newcent (/ (- (window-height (selected-window)) nl) 2))
3559 (lte (count-lines start (point-max))))
3560 (if (and (< (+ newcent lte) (window-height (selected-window)))
3561 (> (- (window-height (selected-window)) lte 1)
3563 (setq newcent (- (window-height (selected-window))
3565 (recenter newcent))))
3569 ;;; Tag Management -- Imenu
3571 (if (not speedbar-use-imenu-flag)
3575 (eval-when-compile (if (locate-library "imenu") (require 'imenu)))
3577 (defun speedbar-fetch-dynamic-imenu (file)
3578 "Load FILE into a buffer, and generate tags using Imenu.
3579 Returns the tag list, or t for an error."
3580 ;; Load this AND compile it in
3583 (set-buffer (find-file-noselect file))
3584 (if speedbar-power-click (setq imenu--index-alist nil))
3586 (let ((index-alist (imenu--make-index-alist t)))
3587 (if speedbar-sort-tags
3588 (sort (copy-alist index-alist)
3589 (lambda (a b) (string< (car a) (car b))))
3594 ;;; Tag Management -- etags (old XEmacs compatibility part)
3596 (defvar speedbar-fetch-etags-parse-list
3597 '(;; Note that java has the same parse-group as c
3598 ("\\.\\([cChH]\\|c\\+\\+\\|cpp\\|cc\\|hh\\|java\\)\\'" .
3599 speedbar-parse-c-or-c++tag)
3600 ("^\\.emacs$\\|.\\(el\\|l\\|lsp\\)\\'" .
3601 "def[^i]+\\s-+\\(\\(\\w\\|[-_]\\)+\\)\\s-*\C-?")
3602 ; ("\\.\\([fF]\\|for\\|FOR\\|77\\|90\\)\\'" .
3603 ; speedbar-parse-fortran77-tag)
3604 ("\\.tex\\'" . speedbar-parse-tex-string)
3606 "\\(\\(FUNCTION\\|function\\|PROCEDURE\\|procedure\\)\\s-+\\([a-zA-Z0-9_.:]+\\)\\)\\s-*(?^?")
3608 "Associations of file extensions and expressions for extracting tags.
3609 To add a new file type, you would want to add a new association to the
3610 list, where the car is the file match, and the cdr is the way to
3611 extract an element from the tags output. If the output is complex,
3612 use a function symbol instead of regexp. The function should expect
3613 to be at the beginning of a line in the etags buffer.
3615 This variable is ignored if `speedbar-use-imenu-flag' is non-nil.")
3617 (defvar speedbar-fetch-etags-command "etags"
3618 "*Command used to create an etags file.
3620 This variable is ignored if `speedbar-use-imenu-flag' is t")
3622 (defvar speedbar-fetch-etags-arguments '("-D" "-I" "-o" "-")
3623 "*List of arguments to use with `speedbar-fetch-etags-command'.
3624 This creates an etags output buffer. Use `speedbar-toggle-etags' to
3625 modify this list conveniently.
3627 This variable is ignored if `speedbar-use-imenu-flag' is t")
3629 (defun speedbar-toggle-etags (flag)
3630 "Toggle FLAG in `speedbar-fetch-etags-arguments'.
3631 FLAG then becomes a member of etags command line arguments. If flag
3632 is \"sort\", then toggle the value of `speedbar-sort-tags'. If its
3633 value is \"show\" then toggle the value of
3634 `speedbar-show-unknown-files'.
3636 This function is a convenience function for XEmacs menu created by
3637 Farzin Guilak <farzin@protocol.com>"
3640 ((equal flag "sort")
3641 (setq speedbar-sort-tags (not speedbar-sort-tags)))
3642 ((equal flag "show")
3643 (setq speedbar-show-unknown-files (not speedbar-show-unknown-files)))
3644 ((or (equal flag "-C")
3647 (if (member flag speedbar-fetch-etags-arguments)
3648 (setq speedbar-fetch-etags-arguments
3649 (delete flag speedbar-fetch-etags-arguments))
3650 (add-to-list 'speedbar-fetch-etags-arguments flag)))
3653 (defun speedbar-fetch-dynamic-etags (file)
3654 "For FILE, run etags and create a list of symbols extracted.
3655 Each symbol will be associated with its line position in FILE."
3656 (let ((newlist nil))
3659 (if (get-buffer "*etags tmp*")
3660 (kill-buffer "*etags tmp*")) ;kill to clean it up
3661 (if (<= 1 speedbar-verbosity-level) (message "Fetching etags..."))
3662 (set-buffer (get-buffer-create "*etags tmp*"))
3663 (apply 'call-process speedbar-fetch-etags-command nil
3664 (current-buffer) nil
3665 (append speedbar-fetch-etags-arguments (list file)))
3666 (goto-char (point-min))
3667 (if (<= 1 speedbar-verbosity-level) (message "Fetching etags..."))
3669 (let ((exprlst speedbar-fetch-etags-parse-list)
3671 (while (and (not ans) exprlst)
3672 (if (string-match (car (car exprlst)) file)
3673 (setq ans (car exprlst)))
3674 (setq exprlst (cdr exprlst)))
3678 (while (not (save-excursion (end-of-line) (eobp)))
3680 (setq tnl (speedbar-extract-one-symbol expr)))
3681 (if tnl (setq newlist (cons tnl newlist)))
3683 (message "Sorry, no support for a file of that extension"))))
3685 (if speedbar-sort-tags
3686 (sort newlist (lambda (a b) (string< (car a) (car b))))
3687 (reverse newlist))))
3689 ;; This bit donated by Farzin Guilak <farzin@protocol.com> but I'm not
3690 ;; sure it's needed with the different sorting method.
3692 ;(defun speedbar-clean-etags()
3693 ; "Removes spaces before the ^? character, and removes `#define',
3694 ;return types, etc. preceding tags. This ensures that the sort operation
3695 ;works on the tags, not the return types."
3697 ; (goto-char (point-min))
3699 ; (re-search-forward "(?[ \t](?\C-?" nil t)
3700 ; (replace-match "\C-?" nil nil))
3701 ; (goto-char (point-min))
3703 ; (re-search-forward "\\(.*[ \t]+\\)\\([^ \t\n]+.*\C-?\\)" nil t)
3704 ; (delete-region (match-beginning 1) (match-end 1)))))
3706 (defun speedbar-extract-one-symbol (expr)
3707 "At point, return nil, or one alist in the form: (SYMBOL . POSITION)
3708 The line should contain output from etags. Parse the output using the
3709 regular expression EXPR"
3710 (let* ((sym (if (stringp expr)
3712 (re-search-forward expr (save-excursion
3715 (buffer-substring-no-properties (match-beginning 1)
3718 (pos (let ((j (re-search-forward "[\C-?\C-a]\\([0-9]+\\),\\([0-9]+\\)"
3724 (1+ (string-to-int (buffer-substring-no-properties
3732 (defun speedbar-parse-c-or-c++tag ()
3733 "Parse a c or c++ tag, which tends to be a little complex."
3735 (let ((bound (save-excursion (end-of-line) (point))))
3736 (cond ((re-search-forward "\C-?\\([^\C-a]+\\)\C-a" bound t)
3737 (buffer-substring-no-properties (match-beginning 1)
3739 ((re-search-forward "\\<\\([^ \t]+\\)\\s-+new(" bound t)
3740 (buffer-substring-no-properties (match-beginning 1)
3742 ((re-search-forward "\\<\\([^ \t(]+\\)\\s-*(\C-?" bound t)
3743 (buffer-substring-no-properties (match-beginning 1)
3748 (defun speedbar-parse-tex-string ()
3749 "Parse a Tex string. Only find data which is relevant."
3751 (let ((bound (save-excursion (end-of-line) (point))))
3752 (cond ((re-search-forward "\\(\\(sub\\)*section\\|chapter\\|cite\\)\\s-*{[^\C-?}]*}?" bound t)
3753 (buffer-substring-no-properties (match-beginning 0)
3758 ;;; BUFFER DISPLAY mode.
3760 (defvar speedbar-buffers-key-map nil
3761 "Keymap used when in the buffers display mode.")
3763 (if speedbar-buffers-key-map
3765 (setq speedbar-buffers-key-map (speedbar-make-specialized-keymap))
3767 ;; Basic tree features
3768 (define-key speedbar-buffers-key-map "e" 'speedbar-edit-line)
3769 (define-key speedbar-buffers-key-map "\C-m" 'speedbar-edit-line)
3770 (define-key speedbar-buffers-key-map "+" 'speedbar-expand-line)
3771 (define-key speedbar-buffers-key-map "-" 'speedbar-contract-line)
3773 ;; Buffer specific keybindings
3774 (define-key speedbar-buffers-key-map "k" 'speedbar-buffer-kill-buffer)
3775 (define-key speedbar-buffers-key-map "r" 'speedbar-buffer-revert-buffer)
3779 (defvar speedbar-buffer-easymenu-definition
3780 '(["Jump to buffer" speedbar-edit-line t]
3781 ["Expand File Tags" speedbar-expand-line
3782 (save-excursion (beginning-of-line)
3783 (looking-at "[0-9]+: *.\\+. "))]
3784 ["Contract File Tags" speedbar-contract-line
3785 (save-excursion (beginning-of-line)
3786 (looking-at "[0-9]+: *.-. "))]
3788 "Menu item elements shown when displaying a buffer list.")
3790 (defun speedbar-buffer-buttons (directory zero)
3791 "Create speedbar buttons based on the buffers currently loaded.
3792 DIRECTORY is the path to the currently active buffer, and ZERO is 0."
3793 (speedbar-buffer-buttons-engine nil))
3795 (defun speedbar-buffer-buttons-temp (directory zero)
3796 "Create speedbar buttons based on the buffers currently loaded.
3797 DIRECTORY is the path to the currently active buffer, and ZERO is 0."
3798 (speedbar-buffer-buttons-engine t))
3800 (defun speedbar-buffer-buttons-engine (temp)
3801 "Create speedbar buffer buttons.
3802 If TEMP is non-nil, then clicking on a buffer restores the previous display."
3803 (insert "Active Buffers:\n")
3804 (let ((bl (buffer-list)))
3806 (if (string-match "^[ *]" (buffer-name (car bl)))
3808 (let* ((known (string-match speedbar-file-regexp
3809 (buffer-name (car bl))))
3810 (expchar (if known ?+ ??))
3811 (fn (if known 'speedbar-tag-file nil))
3812 (fname (save-excursion (set-buffer (car bl))
3813 (buffer-file-name))))
3814 (speedbar-make-tag-line 'bracket expchar fn fname
3815 (buffer-name (car bl))
3816 'speedbar-buffer-click temp
3817 'speedbar-file-face 0)))
3819 (setq bl (buffer-list))
3820 (insert "Scratch Buffers:\n")
3822 (if (not (string-match "^\\*" (buffer-name (car bl))))
3824 (if (eq (car bl) speedbar-buffer)
3826 (speedbar-make-tag-line 'bracket ?? nil nil
3827 (buffer-name (car bl))
3828 'speedbar-buffer-click temp
3829 'speedbar-file-face 0)))
3831 (setq bl (buffer-list))
3832 (insert "Hidden Buffers:\n")
3834 (if (not (string-match "^ " (buffer-name (car bl))))
3836 (if (eq (car bl) speedbar-buffer)
3838 (speedbar-make-tag-line 'bracket ?? nil nil
3839 (buffer-name (car bl))
3840 'speedbar-buffer-click temp
3841 'speedbar-file-face 0)))
3842 (setq bl (cdr bl)))))
3844 (defun speedbar-buffers-item-info ()
3845 "Display information about the current buffer on the current line."
3846 (or (speedbar-item-info-tag-helper)
3847 (let* ((item (speedbar-line-text))
3848 (buffer (if item (get-buffer item) nil)))
3850 (message "%s%s %S %d %s"
3851 (if (buffer-modified-p buffer) "* " "")
3852 item (save-excursion (set-buffer buffer) major-mode)
3853 (save-excursion (set-buffer buffer) (buffer-size))
3854 (or (buffer-file-name buffer) "<No file>"))))))
3856 (defun speedbar-buffers-line-path (&optional depth)
3857 "Fetch the full path to the file (buffer) specified on the current line.
3858 Optional argument DEPTH specifies the current depth of the back search."
3860 ;; Buffers are always at level 0
3861 (if (not (re-search-backward "^0:" nil t))
3863 (let* ((bn (speedbar-line-text))
3864 (buffer (if bn (get-buffer bn))))
3865 (if buffer (file-name-directory (buffer-file-name buffer))))))
3867 (defun speedbar-buffer-click (text token indent)
3868 "When the users clicks on a buffer-button in speedbar.
3869 TEXT is the buffer's name, TOKEN and INDENT are unused."
3870 (if speedbar-power-click
3871 (let ((pop-up-frames t)) (select-window (display-buffer text)))
3872 (select-frame speedbar-attached-frame)
3873 (switch-to-buffer text)
3874 (if token (speedbar-change-initial-expansion-list
3875 speedbar-previously-used-expansion-list-name))))
3877 (defun speedbar-buffer-kill-buffer ()
3878 "Kill the buffer the cursor is on in the speedbar buffer."
3882 ;; If this fails, then it is a non-standard click, and as such,
3883 ;; perfectly allowed.
3884 (if (re-search-forward "[]>?}] [^ ]"
3885 (save-excursion (end-of-line) (point))
3889 (buffer-substring (point) (save-excursion
3892 (if (and (get-buffer text)
3893 (y-or-n-p (format "Kill buffer %s? " text)))
3895 (speedbar-refresh))))))
3897 (defun speedbar-buffer-revert-buffer ()
3898 "Revert the buffer the cursor is on in the speedbar buffer."
3902 ;; If this fails, then it is a non-standard click, and as such,
3903 ;; perfectly allowed
3904 (if (re-search-forward "[]>?}] [^ ]"
3905 (save-excursion (end-of-line) (point))
3909 (buffer-substring (point) (save-excursion
3912 (if (get-buffer text)
3915 (revert-buffer t)))))))
3919 ;;; Color loading section This is messy *Blech!*
3921 (defface speedbar-button-face '((((class color) (background light))
3922 (:foreground "green4"))
3923 (((class color) (background dark))
3924 (:foreground "green3")))
3925 "Face used for +/- buttons."
3926 :group 'speedbar-faces)
3928 (defface speedbar-file-face '((((class color) (background light))
3929 (:foreground "cyan4"))
3930 (((class color) (background dark))
3931 (:foreground "cyan"))
3933 "Face used for file names."
3934 :group 'speedbar-faces)
3936 (defface speedbar-directory-face '((((class color) (background light))
3937 (:foreground "blue4"))
3938 (((class color) (background dark))
3939 (:foreground "light blue")))
3940 "Faced used for directory names."
3941 :group 'speedbar-faces)
3942 (defface speedbar-tag-face '((((class color) (background light))
3943 (:foreground "brown"))
3944 (((class color) (background dark))
3945 (:foreground "yellow")))
3946 "Face used for displaying tags."
3947 :group 'speedbar-faces)
3949 (defface speedbar-selected-face '((((class color) (background light))
3950 (:foreground "red" :underline t))
3951 (((class color) (background dark))
3952 (:foreground "red" :underline t))
3954 "Face used to underline the file in the active window."
3955 :group 'speedbar-faces)
3957 (defface speedbar-highlight-face '((((class color) (background light))
3958 (:background "green"))
3959 (((class color) (background dark))
3960 (:background "sea green"))
3961 (((class grayscale monochrome)
3963 (:background "black"))
3964 (((class grayscale monochrome)
3966 (:background "white")))
3967 "Face used for highlighting buttons with the mouse."
3968 :group 'speedbar-faces)
3970 ;; some edebug hooks
3971 (add-hook 'edebug-setup-hook
3973 (def-edebug-spec speedbar-with-writable def-body)))
3976 ;;; speedbar ends here
3978 ;; run load-time hooks
3979 (run-hooks 'speedbar-load-hook)