Merge from mainline.
[emacs.git] / lisp / speedbar.el
blobdd5efd2617c6936b94f754501acf14769be3aa6d
1 ;;; speedbar --- quick access to files and tags in a frame
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011
5 ;; Free Software Foundation, Inc.
7 ;; Author: Eric M. Ludlam <zappo@gnu.org>
8 ;; Keywords: file, tags, tools
10 (defvar speedbar-version "1.0"
11 "The current version of speedbar.")
12 (defvar speedbar-incompatible-version "0.14beta4"
13 "This version of speedbar is incompatible with this version.
14 Due to massive API changes (removing the use of the word PATH)
15 this version is not backward compatible to 0.14 or earlier.")
17 ;; This file is part of GNU Emacs.
19 ;; GNU Emacs is free software: you can redistribute it and/or modify
20 ;; it under the terms of the GNU General Public License as published by
21 ;; the Free Software Foundation, either version 3 of the License, or
22 ;; (at your option) any later version.
24 ;; GNU Emacs is distributed in the hope that it will be useful,
25 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
26 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 ;; GNU General Public License for more details.
29 ;; You should have received a copy of the GNU General Public License
30 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
32 ;;; Commentary:
34 ;; The speedbar provides a frame in which files, and locations in
35 ;; files are displayed. These items can be clicked on with mouse-2 in
36 ;; to display that file location.
38 ;;; Customizing and Developing for speedbar
40 ;; Please see the speedbar manual for informaion.
42 ;;; Notes:
44 ;; Users of really old emacsen without the need timer functions
45 ;; will not have speedbar updating automatically. Use "g" to refresh
46 ;; the display after changing directories. Remember, do not interrupt
47 ;; the stealthy updates or your display may not be completely
48 ;; refreshed.
50 ;; AUC-TEX users: The imenu tags for AUC-TEX mode don't work very
51 ;; well. Use the imenu keywords from tex-mode.el for better results.
53 ;; This file requires the library package assoc (association lists)
54 ;; assoc should be available in all modern versions of Emacs.
55 ;; The custom package is optional (for easy configuration of speedbar)
56 ;; http://www.dina.kvl.dk/~abraham/custom/
57 ;; custom is available in all versions of Emacs version 20 or better.
59 ;;; Developing for speedbar
61 ;; Adding a speedbar specialized display mode:
63 ;; Speedbar can be configured to create a special display for certain
64 ;; modes that do not display traditional file/tag data. Rmail, Info,
65 ;; and the debugger are examples. These modes can, however, benefit
66 ;; from a speedbar style display in their own way.
68 ;; If your `major-mode' is `foo-mode', the only requirement is to
69 ;; create a function called `foo-speedbar-buttons' which takes one
70 ;; argument, BUFFER. BUFFER will be the buffer speedbar wants filled.
71 ;; In `foo-speedbar-buttons' there are several functions that make
72 ;; building a speedbar display easy. See the documentation for
73 ;; `speedbar-with-writable' (needed because the buffer is usually
74 ;; read-only) `speedbar-make-tag-line', `speedbar-insert-button', and
75 ;; `speedbar-insert-generic-list'. If you use
76 ;; `speedbar-insert-generic-list', also read the doc for
77 ;; `speedbar-tag-hierarchy-method' in case you wish to override it.
78 ;; The macro `speedbar-with-attached-buffer' brings you back to the
79 ;; buffer speedbar is displaying for.
81 ;; For those functions that make buttons, the "function" should be a
82 ;; symbol that is the function to call when clicked on. The "token"
83 ;; is extra data you can pass along. The "function" must take three
84 ;; parameters. They are (TEXT TOKEN INDENT). TEXT is the text of the
85 ;; button clicked on. TOKEN is the data passed in when you create the
86 ;; button. INDENT is an indentation level, or 0. You can store
87 ;; indentation levels with `speedbar-make-tag-line' which creates a
88 ;; line with an expander (eg. [+]) and a text button.
90 ;; Some useful functions when writing expand functions, and click
91 ;; functions are `speedbar-change-expand-button-char',
92 ;; `speedbar-delete-subblock', and `speedbar-center-buffer-smartly'.
93 ;; The variable `speedbar-power-click' is set to t in your functions
94 ;; when the user shift-clicks. This is an indication of anything from
95 ;; refreshing cached data to making a buffer appear in a new frame.
97 ;; If you wish to add to the default speedbar menu for the case of
98 ;; `foo-mode', create a variable `foo-speedbar-menu-items'. This
99 ;; should be a list compatible with the `easymenu' package. It will
100 ;; be spliced into the main menu. (Available with click-mouse-3). If
101 ;; you wish to have extra key bindings in your special mode, create a
102 ;; variable `foo-speedbar-key-map'. Instead of using `make-keymap',
103 ;; or `make-sparse-keymap', use the function
104 ;; `speedbar-make-specialized-keymap'. This lets you inherit all of
105 ;; speedbar's default bindings with low overhead.
107 ;; Adding a speedbar top-level display mode:
109 ;; Unlike the specialized modes, there are no name requirements,
110 ;; however the methods for writing a button display, menu, and keymap
111 ;; are the same. Once you create these items, you can call the
112 ;; function `speedbar-add-expansion-list'. It takes one parameter
113 ;; which is a list element of the form (NAME MENU KEYMAP &rest
114 ;; BUTTON-FUNCTIONS). NAME is a string that will show up in the
115 ;; Displays menu item. MENU is a symbol containing the menu items to
116 ;; splice in. KEYMAP is a symbol holding the keymap to use, and
117 ;; BUTTON-FUNCTIONS are the function names to call, in order, to create
118 ;; the display.
119 ;; Another tweakable variable is `speedbar-stealthy-function-list'
120 ;; which is of the form (NAME &rest FUNCTION ...). NAME is the string
121 ;; name matching `speedbar-add-expansion-list'. (It does not need to
122 ;; exist.). This provides additional display info which might be
123 ;; time-consuming to calculate.
124 ;; Lastly, `speedbar-mode-functions-list' allows you to set special
125 ;; function overrides.
127 ;;; TODO:
128 ;; - Timeout directories we haven't visited in a while.
130 (require 'assoc)
131 (require 'easymenu)
132 (require 'dframe)
133 (require 'sb-image)
135 ;; customization stuff
136 (defgroup speedbar nil
137 "File and tag browser frame."
138 :group 'etags
139 :group 'tools
140 :group 'convenience
141 ; :version "20.3"
144 (defgroup speedbar-faces nil
145 "Faces used in speedbar."
146 :prefix "speedbar-"
147 :group 'speedbar
148 :group 'faces)
150 (defgroup speedbar-vc nil
151 "Version control display in speedbar."
152 :prefix "speedbar-"
153 :group 'speedbar)
155 ;;; Code:
157 ;; Note: `inversion-test' requires parts of the CEDET package that are
158 ;; not included with Emacs.
160 ;; (defun speedbar-require-version (major minor &optional beta)
161 ;; "Non-nil if this version of SPEEDBAR does not satisfy a specific version.
162 ;; Arguments can be:
164 ;; (MAJOR MINOR &optional BETA)
166 ;; Values MAJOR and MINOR must be integers. BETA can be an integer, or
167 ;; excluded if a released version is required.
169 ;; It is assumed that if the current version is newer than that specified,
170 ;; everything passes. Exceptions occur when known incompatibilities are
171 ;; introduced."
172 ;; (inversion-test 'speedbar
173 ;; (concat major "." minor
174 ;; (when beta (concat "beta" beta)))))
176 (defvar speedbar-initial-expansion-mode-alist
177 '(("buffers" speedbar-buffer-easymenu-definition speedbar-buffers-key-map
178 speedbar-buffer-buttons)
179 ("quick buffers" speedbar-buffer-easymenu-definition speedbar-buffers-key-map
180 speedbar-buffer-buttons-temp)
181 ;; Files last, means first in the Displays menu
182 ("files" speedbar-easymenu-definition-special speedbar-file-key-map
183 speedbar-directory-buttons speedbar-default-directory-list)
185 "List of named expansion elements for filling the speedbar frame.
186 These expansion lists are only valid for regular files. Special modes
187 still get to override this list on a mode-by-mode basis. This list of
188 lists is of the form (NAME MENU KEYMAP FN1 FN2 ...). NAME is a string
189 representing the types of things to be displayed. MENU is an easymenu
190 structure used when in this mode. KEYMAP is a local keymap to install
191 over the regular speedbar keymap. FN1 ... are functions that will be
192 called in order. These functions will always get the default
193 directory to use passed in as the first parameter, and a 0 as the
194 second parameter. The 0 indicates the uppermost indentation level.
195 They must assume that the cursor is at the position where they start
196 inserting buttons.")
198 (defvar speedbar-initial-expansion-list-name "files"
199 "A symbol name representing the expansion list to use.
200 The expansion list `speedbar-initial-expansion-mode-alist' contains
201 the names and associated functions to use for buttons in speedbar.")
203 (defvar speedbar-previously-used-expansion-list-name "files"
204 "Save the last expansion list method.
205 This is used for returning to a previous expansion list method when
206 the user is done with the current expansion list.")
208 (defvar speedbar-stealthy-function-list
209 '(("files"
210 speedbar-update-current-file
211 speedbar-check-read-only
212 speedbar-check-vc
213 speedbar-check-objects)
215 "List of functions to periodically call stealthily.
216 This list is of the form:
217 '( (\"NAME\" FUNCTION ...)
218 ...)
219 where NAME is the name of the major display mode these functions are
220 for, and the remaining elements FUNCTION are functions to call in order.
221 Each function must return nil if interrupted, or t if completed.
222 Stealthy functions which have a single operation should always return t.
223 Functions which take a long time should maintain a state (where they
224 are in their speedbar related calculations) and permit interruption.
225 See `speedbar-check-vc' as a good example.")
227 (defvar speedbar-mode-functions-list
228 '(("files" (speedbar-item-info . speedbar-files-item-info)
229 (speedbar-line-directory . speedbar-files-line-directory))
230 ("buffers" (speedbar-item-info . speedbar-buffers-item-info)
231 (speedbar-line-directory . speedbar-buffers-line-directory))
232 ("quick buffers" (speedbar-item-info . speedbar-buffers-item-info)
233 (speedbar-line-directory . speedbar-buffers-line-directory))
235 "List of function tables to use for different major display modes.
236 It is not necessary to define any functions for a specialized mode.
237 This just provides a simple way of adding lots of customizations.
238 Each sublist is of the form:
239 (\"NAME\" (FUNCTIONSYMBOL . REPLACEMENTFUNCTION) ...)
240 Where NAME is the name of the specialized mode. The rest of the list
241 is a set of dotted pairs of the form FUNCTIONSYMBOL, which is the name
242 of a function you would like to replace, and REPLACEMENTFUNCTION,
243 which is a function you can call instead. Not all functions can be
244 replaced this way. Replaceable functions must provide that
245 functionality individually.")
247 (defcustom speedbar-mode-specific-contents-flag t
248 "Non-nil means speedbar will show special mode contents.
249 This permits some modes to create customized contents for the speedbar
250 frame."
251 :group 'speedbar
252 :type 'boolean)
254 (defcustom speedbar-query-confirmation-method 'all
255 "Query control for file operations.
256 The 'always flag means to always query before file operations.
257 The 'none-but-delete flag means to not query before any file
258 operations, except before a file deletion."
259 :group 'speedbar
260 :type '(radio (const :tag "Always Query before some file operations."
261 all)
262 (const :tag "Never Query before file operations, except for deletions."
263 none-but-delete)
264 ;;;; (const :tag "Never Every Query."
265 ;;;; none)
268 (defvar speedbar-special-mode-expansion-list nil
269 "Default function list for creating specialized button lists.
270 This list is set by modes that wish to have special speedbar displays.
271 The list is of function names. Each function is called with one
272 parameter BUFFER, the originating buffer. The current buffer is the
273 speedbar buffer.")
275 (defvar speedbar-special-mode-key-map nil
276 "Default keymap used when identifying a specialized display mode.
277 This keymap is local to each buffer that wants to define special keybindings
278 effective when its display is shown.")
280 (defcustom speedbar-before-visiting-file-hook '(push-mark)
281 "Hooks run before speedbar visits a file in the selected frame.
282 The default buffer is the buffer in the selected window in the attached frame."
283 :group 'speedbar
284 :type 'hook)
286 (defcustom speedbar-visiting-file-hook nil
287 "Hooks run when speedbar visits a file in the selected frame."
288 :group 'speedbar
289 :type 'hook)
291 (defcustom speedbar-before-visiting-tag-hook '(push-mark)
292 "Hooks run before speedbar visits a tag in the selected frame.
293 The default buffer is the buffer in the selected window in the attached frame."
294 :group 'speedbar
295 :type 'hook)
297 (defcustom speedbar-visiting-tag-hook '(speedbar-highlight-one-tag-line)
298 "Hooks run when speedbar visits a tag in the selected frame."
299 :group 'speedbar
300 :type 'hook
301 :options '(speedbar-highlight-one-tag-line
302 speedbar-recenter-to-top
303 speedbar-recenter
306 (defcustom speedbar-load-hook nil
307 "Hooks run when speedbar is loaded."
308 :group 'speedbar
309 :type 'hook)
311 (defcustom speedbar-reconfigure-keymaps-hook nil
312 "Hooks run when the keymaps are regenerated."
313 :group 'speedbar
314 :type 'hook)
316 (defcustom speedbar-show-unknown-files nil
317 "Non-nil show files we can't expand with a ? in the expand button.
318 A nil value means don't show the file in the list."
319 :group 'speedbar
320 :type 'boolean)
322 ;;; EVENTUALLY REMOVE THESE
324 ;; When I moved to a repeating timer, I had the horrible misfortune
325 ;; of losing the ability for adaptive speed choice. This update
326 ;; speed currently causes long delays when it should have been turned off.
327 (defvar speedbar-update-speed dframe-update-speed)
328 (make-obsolete-variable 'speedbar-update-speed
329 'dframe-update-speed
330 "speedbar 1.0pre3 (Emacs 23.1)")
332 (defvar speedbar-navigating-speed dframe-update-speed)
333 (make-obsolete-variable 'speedbar-navigating-speed
334 'dframe-update-speed
335 "speedbar 1.0pre3 (Emacs 23.1)")
336 ;;; END REMOVE THESE
338 (defcustom speedbar-frame-parameters '((minibuffer . nil)
339 (width . 20)
340 (border-width . 0)
341 (menu-bar-lines . 0)
342 (tool-bar-lines . 0)
343 (unsplittable . t)
344 (left-fringe . 0)
346 "Parameters to use when creating the speedbar frame in Emacs.
347 Any parameter supported by a frame may be added. The parameter `height'
348 will be initialized to the height of the frame speedbar is
349 attached to and added to this list before the new frame is initialized."
350 :group 'speedbar
351 :type '(repeat (cons :format "%v"
352 (symbol :tag "Parameter")
353 (sexp :tag "Value"))))
355 ;; These values by Hrvoje Niksic <hniksic@srce.hr>
356 (defcustom speedbar-frame-plist
357 '(minibuffer nil width 20 border-width 0
358 internal-border-width 0 unsplittable t
359 default-toolbar-visible-p nil has-modeline-p nil
360 menubar-visible-p nil
361 default-gutter-visible-p nil
363 "Parameters to use when creating the speedbar frame in XEmacs.
364 Parameters not listed here which will be added automatically are
365 `height' which will be initialized to the height of the frame speedbar
366 is attached to."
367 :group 'speedbar
368 :type '(repeat (group :inline t
369 (symbol :tag "Property")
370 (sexp :tag "Value"))))
372 (defcustom speedbar-use-imenu-flag (fboundp 'imenu)
373 "Non-nil means use imenu for file parsing, nil to use etags.
374 XEmacs prior to 20.4 doesn't support imenu, therefore the default is to
375 use etags instead. Etags support is not as robust as imenu support."
376 :tag "Use Imenu for tags"
377 :group 'speedbar
378 :type 'boolean)
380 (defvar speedbar-dynamic-tags-function-list
381 '((speedbar-fetch-dynamic-imenu . speedbar-insert-imenu-list)
382 (speedbar-fetch-dynamic-etags . speedbar-insert-etags-list))
383 "Set to a list of functions which will return and insert a list of tags.
384 Each element is of the form ( FETCH . INSERT ) where FETCH
385 is a function which takes one parameter (the file to tag) and returns a
386 list of tags. The tag list can be of any form as long as the
387 corresponding insert method can handle it. If it returns t, then an
388 error occurred, and the next fetch routine is tried.
389 INSERT is a function which takes an INDENTation level, and a LIST of
390 tags to insert. It will then create the speedbar buttons.")
392 (defcustom speedbar-use-tool-tips-flag (fboundp 'tooltip-mode)
393 "Non-nil means to use tool tips if they are available.
394 When tooltips are not available, mouse-tracking and minibuffer
395 display is used instead."
396 :group 'speedbar
397 :type 'boolean)
399 (defcustom speedbar-track-mouse-flag (not speedbar-use-tool-tips-flag)
400 "Non-nil means to display info about the line under the mouse."
401 :group 'speedbar
402 :type 'boolean)
404 (defcustom speedbar-default-position 'left-right
405 "Default position of the speedbar frame.
406 Possible values are 'left, 'right or 'left-right.
407 If value is 'left-right, the most suitable location is
408 determined automatically."
409 :group 'speedbar
410 :type '(radio (const :tag "Automatic" left-right)
411 (const :tag "Left" left)
412 (const :tag "Right" right)))
414 (defcustom speedbar-sort-tags nil
415 "If non-nil, sort tags in the speedbar display. *Obsolete*.
416 Use `semantic-tag-hierarchy-method' instead."
417 :group 'speedbar
418 :type 'boolean)
420 (defcustom speedbar-tag-hierarchy-method
421 '(speedbar-prefix-group-tag-hierarchy
422 speedbar-trim-words-tag-hierarchy)
423 "List of hooks which speedbar will use to organize tags into groups.
424 Groups are defined as expandable meta-tags. Imenu supports
425 such things in some languages, such as separating variables from
426 functions. Each hook takes one argument LST, and may destructively
427 create a new list of the same form. LST is a list of elements of the
428 form:
429 (ELT1 ELT2 ... ELTn)
430 where each ELT is of the form
431 (TAG-NAME-STRING . NUMBER-OR-MARKER)
433 (GROUP-NAME-STRING ELT1 ELT2... ELTn)"
434 :group 'speedbar
435 :type 'hook
436 :options '(speedbar-prefix-group-tag-hierarchy
437 speedbar-trim-words-tag-hierarchy
438 speedbar-simple-group-tag-hierarchy
439 speedbar-sort-tag-hierarchy)
442 (defcustom speedbar-tag-group-name-minimum-length 4
443 "The minimum length of a prefix group name before expanding.
444 Thus, if the `speedbar-tag-hierarchy-method' includes `prefix-group'
445 and one such groups common characters is less than this number of
446 characters, then the group name will be changed to the form of:
447 worda to wordb
448 instead of just
449 word
450 This way we won't get silly looking listings."
451 :group 'speedbar
452 :type 'integer)
454 (defcustom speedbar-tag-split-minimum-length 20
455 "Minimum length before we stop trying to create sub-lists in tags.
456 This is used by all tag-hierarchy methods that break large lists into
457 sub-lists."
458 :group 'speedbar
459 :type 'integer)
461 (defcustom speedbar-tag-regroup-maximum-length 10
462 "Maximum length of submenus that are regrouped.
463 If the regrouping option is used, then if two or more short subgroups
464 are next to each other, then they are combined until this number of
465 items is reached."
466 :group 'speedbar
467 :type 'integer)
469 (defcustom speedbar-directory-button-trim-method 'span
470 "Indicates how the directory button will be displayed.
471 Possible values are:
472 'span - span large directories over multiple lines.
473 'trim - trim large directories to only show the last few.
474 nil - no trimming."
475 :group 'speedbar
476 :type '(radio (const :tag "Span large directories over mutiple lines."
477 span)
478 (const :tag "Trim large directories to only show the last few."
479 trim)
480 (const :tag "No trimming." nil)))
482 (defcustom speedbar-smart-directory-expand-flag t
483 "Non-nil means speedbar should use smart expansion.
484 Smart expansion only affects when speedbar wants to display a
485 directory for a file in the attached frame. When smart expansion is
486 enabled, new directories which are children of a displayed directory
487 are expanded in the current framework. If nil, then the current
488 hierarchy would be replaced with the new directory."
489 :group 'speedbar
490 :type 'boolean)
492 (defcustom speedbar-indentation-width 1
493 "When sub-nodes are expanded, the number of spaces used for indentation."
494 :group 'speedbar
495 :type 'integer)
497 (defcustom speedbar-hide-button-brackets-flag nil
498 "Non-nil means speedbar will hide the brackets around the + or -."
499 :group 'speedbar
500 :type 'boolean)
502 (defcustom speedbar-before-popup-hook nil
503 "Hooks called before popping up the speedbar frame."
504 :group 'speedbar
505 :type 'hook)
507 (defcustom speedbar-after-create-hook '(speedbar-frame-reposition-smartly)
508 "Hooks called after popping up the speedbar frame."
509 :group 'speedbar
510 :type 'hook)
512 (defcustom speedbar-before-delete-hook nil
513 "Hooks called before deleting the speedbar frame."
514 :group 'speedbar
515 :type 'hook)
517 (defcustom speedbar-mode-hook nil
518 "Hook run after creating a speedbar buffer."
519 :group 'speedbar
520 :type 'hook)
522 (defcustom speedbar-timer-hook nil
523 "Hooks called after running the speedbar timer function."
524 :group 'speedbar
525 :type 'hook)
527 (defcustom speedbar-verbosity-level 1
528 "Verbosity level of the speedbar.
529 0 means say nothing.
530 1 means medium level verbosity.
531 2 and higher are higher levels of verbosity."
532 :group 'speedbar
533 :type 'integer)
535 (defvar speedbar-indicator-separator " "
536 "String separating file text from indicator characters.")
538 (defcustom speedbar-vc-do-check t
539 "Non-nil check all files in speedbar to see if they have been checked out.
540 Any file checked out is marked with `speedbar-vc-indicator'."
541 :group 'speedbar-vc
542 :type 'boolean)
544 (defvar speedbar-vc-indicator "*"
545 "Text used to mark files which are currently checked out.
546 Other version control systems can be added by examining the function
547 `speedbar-vc-directory-enable-hook' and `speedbar-vc-in-control-hook'.")
549 (defcustom speedbar-vc-directory-enable-hook nil
550 "Return non-nil if the current directory should be checked for Version Control.
551 Functions in this hook must accept one parameter which is the directory
552 being checked."
553 :group 'speedbar-vc
554 :type 'hook)
556 (defcustom speedbar-vc-in-control-hook nil
557 "Return non-nil if the specified file is under Version Control.
558 Functions in this hook must accept two parameters. The DIRECTORY of the
559 current file, and the FILENAME of the file being checked."
560 :group 'speedbar-vc
561 :type 'hook)
563 (defvar speedbar-vc-to-do-point nil
564 "Local variable maintaining the current version control check position.")
566 (defcustom speedbar-obj-do-check t
567 "Non-nil check all files in speedbar to see if they have an object file.
568 Any file checked out is marked with `speedbar-obj-indicator', and the
569 marking is based on `speedbar-obj-alist'"
570 :group 'speedbar-vc
571 :type 'boolean)
573 (defvar speedbar-obj-to-do-point nil
574 "Local variable maintaining the current version control check position.")
576 (defvar speedbar-obj-indicator '("#" . "!")
577 "Text used to mark files that have a corresponding hidden object file.
578 The car is for an up-to-date object. The cdr is for an out of date object.
579 The expression `speedbar-obj-alist' defines who gets tagged.")
581 (defvar speedbar-obj-alist
582 '(("\\.\\([cpC]\\|cpp\\|cc\\|cxx\\)$" . ".o")
583 ("\\.el$" . ".elc")
584 ("\\.java$" . ".class")
585 ("\\.f\\(or\\|90\\|77\\)?$" . ".o")
586 ("\\.tex$" . ".dvi")
587 ("\\.texi$" . ".info"))
588 "Alist of file extensions, and their corresponding object file type.")
590 (defvar speedbar-ro-to-do-point nil
591 "Local variable maintaining the current read only check position.")
593 (defvar speedbar-object-read-only-indicator "%"
594 "Indicator to append onto a line if that item is Read Only.")
596 ;; Note: Look for addition place to add indicator lists that
597 ;; use skip-chars instead of a regular expression.
598 (defvar speedbar-indicator-regex
599 (concat (regexp-quote speedbar-indicator-separator)
600 "\\("
601 (regexp-quote speedbar-vc-indicator)
602 "\\|"
603 (regexp-quote (car speedbar-obj-indicator))
604 "\\|"
605 (regexp-quote (cdr speedbar-obj-indicator))
606 "\\|"
607 (regexp-quote speedbar-object-read-only-indicator)
608 "\\)*")
609 "Regular expression used when identifying files.
610 Permits stripping of indicator characters from a line.")
612 (defcustom speedbar-scanner-reset-hook nil
613 "Hook called whenever generic scanners are reset.
614 Set this to implement your own scanning / rescan safe functions with
615 state data."
616 :group 'speedbar
617 :type 'hook)
619 (defvar speedbar-ignored-modes '(fundamental-mode)
620 "*List of major modes which speedbar will not switch directories for.")
622 (defun speedbar-extension-list-to-regex (extlist)
623 "Takes EXTLIST, a list of extensions and transforms it into regexp.
624 All the preceding `.' are stripped for an optimized expression starting
625 with `.' followed by extensions, followed by full-filenames."
626 (let ((regex1 nil) (regex2 nil))
627 (while extlist
628 (if (= (string-to-char (car extlist)) ?.)
629 (setq regex1 (concat regex1 (if regex1 "\\|" "")
630 (substring (car extlist) 1)))
631 (setq regex2 (concat regex2 (if regex2 "\\|" "") (car extlist))))
632 (setq extlist (cdr extlist)))
633 ;; concat all the sub-exressions together, making sure all types
634 ;; of parts exist during concatination.
635 (concat "\\("
636 (if regex1 (concat "\\(\\.\\(" regex1 "\\)\\)") "")
637 (if (and regex1 regex2) "\\|" "")
638 (if regex2 (concat "\\(" regex2 "\\)") "")
639 "\\)$")))
641 (defvar speedbar-ignored-directory-regexp nil
642 "Regular expression matching directories speedbar will not switch to.
643 Created from `speedbar-ignored-directory-expressions' with the function
644 `speedbar-extension-list-to-regex' (a misnamed function in this case.)
645 Use the function `speedbar-add-ignored-directory-regexp', or customize the
646 variable `speedbar-ignored-directory-expressions' to modify this variable.")
648 (define-obsolete-variable-alias 'speedbar-ignored-path-expressions
649 'speedbar-ignored-directory-expressions "22.1")
651 (defcustom speedbar-ignored-directory-expressions
652 '("[/\\]logs?[/\\]\\'")
653 "List of regular expressions matching directories speedbar will ignore.
654 They should included directories which are notoriously very large
655 and take a long time to load in. Use the function
656 `speedbar-add-ignored-directory-regexp' to add new items to this list after
657 speedbar is loaded. You may place anything you like in this list
658 before speedbar has been loaded."
659 :group 'speedbar
660 :type '(repeat (regexp :tag "Directory Regexp"))
661 :set (lambda (sym val)
662 (setq speedbar-ignored-directory-expressions val
663 speedbar-ignored-directory-regexp
664 (speedbar-extension-list-to-regex val))))
666 (defcustom speedbar-directory-unshown-regexp "^\\(\\..*\\)\\'"
667 "Regular expression matching directories not to show in speedbar.
668 They should include commonly existing directories which are not
669 useful. It is no longer necessary to include version-control
670 directories here; see `vc-directory-exclusion-list'."
671 :group 'speedbar
672 :type 'string)
674 (defvar speedbar-file-unshown-regexp
675 (let ((nstr "") (noext completion-ignored-extensions))
676 (while noext
677 (setq nstr (concat nstr (regexp-quote (car noext)) "\\'"
678 (if (cdr noext) "\\|" ""))
679 noext (cdr noext)))
680 ;; backup refdir lockfile
681 (concat nstr "\\|#[^#]+#$\\|\\.\\.?\\'\\|\\.#"))
682 "*Regexp matching files we don't want displayed in a speedbar buffer.
683 It is generated from the variable `completion-ignored-extensions'.")
685 (defvar speedbar-file-regexp nil
686 "Regular expression matching files we know how to expand.
687 Created from `speedbar-supported-extension-expressions' with the
688 function `speedbar-extension-list-to-regex'.")
690 ;; this is dangerous to customize, because the defaults will probably
691 ;; change in the future.
692 (defcustom speedbar-supported-extension-expressions
693 (append '(".[ch]\\(\\+\\+\\|pp\\|c\\|h\\|xx\\)?" ".tex\\(i\\(nfo\\)?\\)?"
694 ".el" ".emacs" ".l" ".lsp" ".p" ".java" ".js" ".f\\(90\\|77\\|or\\)?")
695 (if speedbar-use-imenu-flag
696 '(".ada" ".p[lm]" ".tcl" ".m" ".scm" ".pm" ".py" ".g"
697 ;; html is not supported by default, but an imenu tags package
698 ;; is available. Also, html files are nice to be able to see.
699 ".s?html"
700 ".ma?k" "[Mm]akefile\\(\\.in\\)?")))
701 "List of regular expressions which will match files supported by tagging.
702 Do not prefix the `.' char with a double \\ to quote it, as the period
703 will be stripped by a simplified optimizer when compiled into a
704 singular expression. This variable will be turned into
705 `speedbar-file-regexp' for use with speedbar. You should use the
706 function `speedbar-add-supported-extension' to add a new extension at
707 runtime, or use the configuration dialog to set it in your .emacs file.
708 If you add an extension to this list, and it does not appear, you may
709 need to also modify `completion-ignored-extension' which will also help
710 file completion."
711 :group 'speedbar
712 :type '(repeat (regexp :tag "Extension Regexp"))
713 :set (lambda (sym val)
714 (set 'speedbar-supported-extension-expressions val)
715 (set 'speedbar-file-regexp (speedbar-extension-list-to-regex val))))
717 (setq speedbar-file-regexp
718 (speedbar-extension-list-to-regex speedbar-supported-extension-expressions))
720 (defun speedbar-add-supported-extension (extension)
721 "Add EXTENSION as a new supported extension for speedbar tagging.
722 This should start with a `.' if it is not a complete file name, and
723 the dot should NOT be quoted in with \\. Other regular expression
724 matchers are allowed however. EXTENSION may be a single string or a
725 list of strings."
726 (interactive "sExtension: ")
727 (if (not (listp extension)) (setq extension (list extension)))
728 (while extension
729 (if (member (car extension) speedbar-supported-extension-expressions)
731 (setq speedbar-supported-extension-expressions
732 (cons (car extension) speedbar-supported-extension-expressions)))
733 (setq extension (cdr extension)))
734 (setq speedbar-file-regexp (speedbar-extension-list-to-regex
735 speedbar-supported-extension-expressions)))
737 (defun speedbar-add-ignored-directory-regexp (directory-expression)
738 "Add DIRECTORY-EXPRESSION as a new ignored directory for speedbar tracking.
739 This function will modify `speedbar-ignored-directory-regexp' and add
740 DIRECTORY-EXPRESSION to `speedbar-ignored-directory-expressions'."
741 (interactive "sDirectory regex: ")
742 (if (not (listp directory-expression))
743 (setq directory-expression (list directory-expression)))
744 (while directory-expression
745 (if (member (car directory-expression) speedbar-ignored-directory-expressions)
747 (setq speedbar-ignored-directory-expressions
748 (cons (car directory-expression) speedbar-ignored-directory-expressions)))
749 (setq directory-expression (cdr directory-expression)))
750 (setq speedbar-ignored-directory-regexp (speedbar-extension-list-to-regex
751 speedbar-ignored-directory-expressions)))
753 ;; If we don't have custom, then we set it here by hand.
754 (if (not (fboundp 'custom-declare-variable))
755 (setq speedbar-file-regexp (speedbar-extension-list-to-regex
756 speedbar-supported-extension-expressions)
757 speedbar-ignored-directory-regexp (speedbar-extension-list-to-regex
758 speedbar-ignored-directory-expressions)))
760 (defvar speedbar-update-flag dframe-have-timer-flag
761 "*Non-nil means to automatically update the display.
762 When this is nil then speedbar will not follow the attached frame's directory.
763 When speedbar is active, use:
765 \\<speedbar-key-map> `\\[speedbar-toggle-updates]'
767 to toggle this value.")
769 (defvar speedbar-update-flag-disable nil
770 "Permanently disable changing of the update flag.")
772 (defvar speedbar-mode-syntax-table
773 (let ((st (make-syntax-table)))
774 ;; Turn off paren matching around here.
775 (modify-syntax-entry ?\' " " st)
776 (modify-syntax-entry ?\" " " st)
777 (modify-syntax-entry ?\( " " st)
778 (modify-syntax-entry ?\) " " st)
779 (modify-syntax-entry ?\{ " " st)
780 (modify-syntax-entry ?\} " " st)
781 (modify-syntax-entry ?\[ " " st)
782 (modify-syntax-entry ?\] " " st)
784 "Syntax-table used on the speedbar.")
785 (define-obsolete-variable-alias
786 'speedbar-syntax-table 'speedbar-mode-syntax-table "24.1")
789 (defvar speedbar-mode-map
790 (let ((map (make-keymap)))
791 (suppress-keymap map t)
793 ;; Control.
794 (define-key map "t" 'speedbar-toggle-updates)
795 (define-key map "g" 'speedbar-refresh)
797 ;; Navigation.
798 (define-key map "n" 'speedbar-next)
799 (define-key map "p" 'speedbar-prev)
800 (define-key map "\M-n" 'speedbar-restricted-next)
801 (define-key map "\M-p" 'speedbar-restricted-prev)
802 (define-key map "\C-\M-n" 'speedbar-forward-list)
803 (define-key map "\C-\M-p" 'speedbar-backward-list)
804 ;; These commands never seemed useful.
805 ;; (define-key map " " 'speedbar-scroll-up)
806 ;; (define-key map [delete] 'speedbar-scroll-down)
808 ;; Short cuts I happen to find useful.
809 (define-key map "r"
810 (lambda () (interactive)
811 (speedbar-change-initial-expansion-list
812 speedbar-previously-used-expansion-list-name)))
813 (define-key map "b"
814 (lambda () (interactive)
815 (speedbar-change-initial-expansion-list "quick buffers")))
816 (define-key map "f"
817 (lambda () (interactive)
818 (speedbar-change-initial-expansion-list "files")))
820 (dframe-update-keymap map)
821 map)
822 "Keymap used in speedbar buffer.")
823 (define-obsolete-variable-alias 'speedbar-key-map 'speedbar-mode-map "24.1")
825 (defun speedbar-make-specialized-keymap ()
826 "Create a keymap for use with a speedbar major or minor display mode.
827 This basically creates a sparse keymap, and makes its parent be
828 `speedbar-mode-map'."
829 (let ((k (make-sparse-keymap)))
830 (set-keymap-parent k speedbar-mode-map)
833 (defvar speedbar-file-key-map
834 (let ((map (speedbar-make-specialized-keymap)))
836 ;; Basic tree features.
837 (define-key map "e" 'speedbar-edit-line)
838 (define-key map "\C-m" 'speedbar-edit-line)
839 (define-key map "+" 'speedbar-expand-line)
840 (define-key map "=" 'speedbar-expand-line)
841 (define-key map "-" 'speedbar-contract-line)
843 (define-key map "[" 'speedbar-expand-line-descendants)
844 (define-key map "]" 'speedbar-contract-line-descendants)
846 (define-key map " " 'speedbar-toggle-line-expansion)
848 ;; File based commands.
849 (define-key map "U" 'speedbar-up-directory)
850 (define-key map "I" 'speedbar-item-info)
851 (define-key map "B" 'speedbar-item-byte-compile)
852 (define-key map "L" 'speedbar-item-load)
853 (define-key map "C" 'speedbar-item-copy)
854 (define-key map "D" 'speedbar-item-delete)
855 (define-key map "O" 'speedbar-item-object-delete)
856 (define-key map "R" 'speedbar-item-rename)
857 (define-key map "M" 'speedbar-create-directory)
858 map)
859 "Keymap used in speedbar buffer while files are displayed.")
861 (defvar speedbar-easymenu-definition-base
862 (append
863 '("Speedbar"
864 ["Update" speedbar-refresh t]
865 ["Auto Update" speedbar-toggle-updates
866 :active (not speedbar-update-flag-disable)
867 :style toggle :selected speedbar-update-flag])
868 (if (and (or (fboundp 'defimage)
869 (fboundp 'make-image-specifier))
870 (if (fboundp 'display-graphic-p)
871 (display-graphic-p)
872 window-system))
873 (list
874 ["Use Images" speedbar-toggle-images
875 :style toggle :selected speedbar-use-images]))
877 "Base part of the speedbar menu.")
879 (defvar speedbar-easymenu-definition-special
880 '(["Edit Item On Line" speedbar-edit-line t]
881 ["Show All Files" speedbar-toggle-show-all-files
882 :style toggle :selected speedbar-show-unknown-files]
883 ["Expand File Tags" speedbar-expand-line
884 (save-excursion (beginning-of-line)
885 (looking-at "[0-9]+: *.\\+. "))]
886 ["Flush Cache & Expand" speedbar-flush-expand-line
887 (save-excursion (beginning-of-line)
888 (looking-at "[0-9]+: *.\\+. "))]
889 ["Expand All Descendants" speedbar-expand-line-descendants
890 (save-excursion (beginning-of-line)
891 (looking-at "[0-9]+: *.\\+. ")) ]
892 ["Contract File Tags" speedbar-contract-line
893 (save-excursion (beginning-of-line)
894 (looking-at "[0-9]+: *.-. "))]
895 ; ["Sort Tags" speedbar-toggle-sorting
896 ; :style toggle :selected speedbar-sort-tags]
897 "----"
898 ["File/Tag Information" speedbar-item-info t]
899 ["Load Lisp File" speedbar-item-load
900 (save-excursion
901 (beginning-of-line)
902 (looking-at "[0-9]+: *\\[[+-]\\] .+\\(\\.el\\)\\( \\|$\\)"))]
903 ["Byte Compile File" speedbar-item-byte-compile
904 (save-excursion
905 (beginning-of-line)
906 (looking-at "[0-9]+: *\\[[+-]\\] .+\\(\\.el\\)\\( \\|$\\)"))]
907 ["Copy File" speedbar-item-copy
908 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *\\["))]
909 ["Rename File" speedbar-item-rename
910 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
911 ["Create Directory" speedbar-create-directory
912 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
913 ["Delete File" speedbar-item-delete
914 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
915 ["Delete Object" speedbar-item-object-delete
916 (save-excursion (beginning-of-line)
917 (looking-at "[0-9]+: *\\[[+-]\\] [^ \n]+ \\*?[!#]$"))]
919 "Additional menu items while in file-mode.")
921 (defvar speedbar-easymenu-definition-trailer
922 (append
923 (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
924 (list ["Customize..." speedbar-customize t]))
925 (list
926 ["Close" dframe-close-frame t]
927 ["Quit" delete-frame t] ))
928 "Menu items appearing at the end of the speedbar menu.")
930 (defvar speedbar-desired-buffer nil
931 "Non-nil when speedbar is showing buttons specific to a special mode.
932 In this case it is the originating buffer.")
933 (defvar speedbar-buffer nil
934 "The buffer displaying the speedbar.")
935 (defvar speedbar-frame nil
936 "The frame displaying speedbar.")
937 (defvar speedbar-cached-frame nil
938 "The frame that was last created, then removed from the display.")
939 (defvar speedbar-full-text-cache nil
940 "The last open directory is saved in its entirety for ultra-fast switching.")
942 (defvar speedbar-last-selected-file nil
943 "The last file which was selected in speedbar buffer.")
945 (defvar speedbar-shown-directories nil
946 "Maintain list of directories simultaneously open in the current speedbar.")
948 (defvar speedbar-directory-contents-alist nil
949 "An association list of directories and their contents.
950 Each sublist was returned by `speedbar-file-lists'. This list is
951 maintained to speed up the refresh rate when switching between
952 directories.")
954 (defvar speedbar-power-click nil
955 "Never set this by hand. Value is t when S-mouse activity occurs.")
958 ;;; Compatibility
960 (defalias 'speedbar-make-overlay
961 (if (featurep 'xemacs) 'make-extent 'make-overlay))
963 (defalias 'speedbar-overlay-put
964 (if (featurep 'xemacs) 'set-extent-property 'overlay-put))
966 (defalias 'speedbar-delete-overlay
967 (if (featurep 'xemacs) 'delete-extent 'delete-overlay))
969 (defalias 'speedbar-mode-line-update
970 (if (featurep 'xemacs) 'redraw-modeline 'force-mode-line-update))
972 ;;; Mode definitions/ user commands
975 ;;;###autoload
976 (defalias 'speedbar 'speedbar-frame-mode)
977 ;;;###autoload
978 (defun speedbar-frame-mode (&optional arg)
979 "Enable or disable speedbar. Positive ARG means turn on, negative turn off.
980 A nil ARG means toggle. Once the speedbar frame is activated, a buffer in
981 `speedbar-mode' will be displayed. Currently, only one speedbar is
982 supported at a time.
983 `speedbar-before-popup-hook' is called before popping up the speedbar frame.
984 `speedbar-before-delete-hook' is called before the frame is deleted."
985 (interactive "P")
986 ;; Get the buffer to play with
987 (if (not (buffer-live-p speedbar-buffer))
988 (save-excursion
989 (setq speedbar-buffer (get-buffer-create " SPEEDBAR"))
990 (set-buffer speedbar-buffer)
991 (speedbar-mode)))
992 ;; Do the frame thing
993 (dframe-frame-mode arg
994 'speedbar-frame
995 'speedbar-cached-frame
996 'speedbar-buffer
997 "Speedbar"
998 #'speedbar-frame-mode
999 (if (featurep 'xemacs)
1000 (append speedbar-frame-plist
1001 ;; This is a hack to get speedbar to iconfiy
1002 ;; with the selected frame.
1003 (list 'parent (selected-frame)))
1004 speedbar-frame-parameters)
1005 speedbar-before-delete-hook
1006 speedbar-before-popup-hook
1007 speedbar-after-create-hook)
1008 ;; Start up the timer
1009 (if (not speedbar-frame)
1010 (speedbar-set-timer nil)
1011 (speedbar-reconfigure-keymaps)
1012 (speedbar-update-contents)
1013 (speedbar-set-timer dframe-update-speed)
1015 ;; Frame modifications
1016 (set (make-local-variable 'dframe-delete-frame-function)
1017 'speedbar-handle-delete-frame)
1018 ;; hscroll
1019 (set (make-local-variable 'automatic-hscrolling) nil) ; Emacs 21
1020 ;; reset the selection variable
1021 (setq speedbar-last-selected-file nil))
1023 (defun speedbar-frame-reposition-smartly ()
1024 "Reposition the speedbar frame to be next to the attached frame."
1025 (cond ((and (featurep 'xemacs)
1026 (or (member 'left speedbar-frame-plist)
1027 (member 'top speedbar-frame-plist)))
1028 (dframe-reposition-frame
1029 speedbar-frame
1030 (dframe-attached-frame speedbar-frame)
1031 (cons (car (cdr (member 'left speedbar-frame-plist)))
1032 (car (cdr (member 'top speedbar-frame-plist)))))
1034 ((and (not (featurep 'xemacs))
1035 (or (assoc 'left speedbar-frame-parameters)
1036 (assoc 'top speedbar-frame-parameters)))
1037 ;; if left/top were specified in the parameters, pass them
1038 ;; down to the reposition function
1039 (dframe-reposition-frame
1040 speedbar-frame
1041 (dframe-attached-frame speedbar-frame)
1042 (cons (cdr (assoc 'left speedbar-frame-parameters))
1043 (cdr (assoc 'top speedbar-frame-parameters))))
1046 (dframe-reposition-frame speedbar-frame
1047 (dframe-attached-frame speedbar-frame)
1048 speedbar-default-position))))
1050 (defsubst speedbar-current-frame ()
1051 "Return the frame to use for speedbar based on current context."
1052 (dframe-current-frame 'speedbar-frame 'speedbar-mode))
1054 (defun speedbar-handle-delete-frame (e)
1055 "Handle a delete frame event E.
1056 If the deleted frame is the frame speedbar is attached to,
1057 we need to delete speedbar also."
1058 (when (and speedbar-frame
1059 (eq (car (car (cdr e))) ;; frame to be deleted
1060 dframe-attached-frame))
1061 (delete-frame speedbar-frame)))
1063 ;;;###autoload
1064 (defun speedbar-get-focus ()
1065 "Change frame focus to or from the speedbar frame.
1066 If the selected frame is not speedbar, then speedbar frame is
1067 selected. If the speedbar frame is active, then select the attached frame."
1068 (interactive)
1069 (speedbar-reset-scanners)
1070 (dframe-get-focus 'speedbar-frame 'speedbar-frame-mode
1071 (lambda () (let ((speedbar-update-flag t))
1072 (speedbar-timer-fn)))))
1074 (defsubst speedbar-frame-width ()
1075 "Return the width of the speedbar frame in characters.
1076 Return nil if it doesn't exist."
1077 (frame-width speedbar-frame))
1079 (define-derived-mode speedbar-mode fundamental-mode "Speedbar"
1080 "Major mode for managing a display of directories and tags.
1081 \\<speedbar-key-map>
1082 The first line represents the default directory of the speedbar frame.
1083 Each directory segment is a button which jumps speedbar's default
1084 directory to that directory. Buttons are activated by clicking `\\[speedbar-click]'.
1085 In some situations using `\\[dframe-power-click]' is a `power click' which will
1086 rescan cached items, or pop up new frames.
1088 Each line starting with <+> represents a directory. Click on the <+>
1089 to insert the directory listing into the current tree. Click on the
1090 <-> to retract that list. Click on the directory name to go to that
1091 directory as the default.
1093 Each line starting with [+] is a file. If the variable
1094 `speedbar-show-unknown-files' is t, the lines starting with [?] are
1095 files which don't have imenu support, but are not expressly ignored.
1096 Files are completely ignored if they match `speedbar-file-unshown-regexp'
1097 which is generated from `completion-ignored-extensions'.
1099 Files with a `*' character after their name are files checked out of a
1100 version control system. (Currently only RCS is supported.) New
1101 version control systems can be added by examining the documentation
1102 for `speedbar-this-file-in-vc' and `speedbar-vc-check-dir-p'.
1104 Files with a `#' or `!' character after them are source files that
1105 have an object file associated with them. The `!' indicates that the
1106 files is out of date. You can control what source/object associations
1107 exist through the variable `speedbar-obj-alist'.
1109 Click on the [+] to display a list of tags from that file. Click on
1110 the [-] to retract the list. Click on the file name to edit the file
1111 in the attached frame.
1113 If you open tags, you might find a node starting with {+}, which is a
1114 category of tags. Click the {+} to expand the category. Jump-able
1115 tags start with >. Click the name of the tag to go to that position
1116 in the selected file.
1118 \\{speedbar-key-map}"
1119 (save-excursion
1120 (setq font-lock-keywords nil) ;; no font-locking please
1121 (setq truncate-lines t)
1122 (make-local-variable 'frame-title-format)
1123 (setq frame-title-format (concat "Speedbar " speedbar-version)
1124 case-fold-search nil
1125 buffer-read-only t)
1126 (speedbar-set-mode-line-format)
1127 ;; Add in our dframe hooks.
1128 (if speedbar-track-mouse-flag
1129 (setq dframe-track-mouse-function #'speedbar-track-mouse))
1130 (setq dframe-help-echo-function #'speedbar-item-info
1131 dframe-mouse-click-function #'speedbar-click
1132 dframe-mouse-position-function #'speedbar-position-cursor-on-line))
1133 speedbar-buffer)
1135 (defmacro speedbar-message (fmt &rest args)
1136 "Like `message', but for use in the speedbar frame.
1137 Argument FMT is the format string, and ARGS are the arguments for message."
1138 `(dframe-message ,fmt ,@args))
1140 (defsubst speedbar-y-or-n-p (prompt &optional deleting)
1141 "Like `y-or-n-p', but for use in the speedbar frame.
1142 Argument PROMPT is the prompt to use.
1143 Optional argument DELETING means this is a query that will delete something.
1144 The variable `speedbar-query-confirmation-method' can cause this to
1145 return true without a query."
1146 (or (and (not deleting)
1147 (eq speedbar-query-confirmation-method 'none-but-delete))
1148 (dframe-y-or-n-p prompt)))
1150 (defsubst speedbar-select-attached-frame ()
1151 "Select the frame attached to this speedbar."
1152 (dframe-select-attached-frame (speedbar-current-frame)))
1154 ;; Backwards compatibility
1155 (defalias 'speedbar-with-attached-buffer 'dframe-with-attached-buffer)
1156 (defalias 'speedbar-maybee-jump-to-attached-frame 'dframe-maybee-jump-to-attached-frame)
1158 (defun speedbar-set-mode-line-format ()
1159 "Set the format of the mode line based on the current speedbar environment.
1160 This gives visual indications of what is up. It EXPECTS the speedbar
1161 frame and window to be the currently active frame and window."
1162 (if (and (frame-live-p (speedbar-current-frame))
1163 (or (not (featurep 'xemacs))
1164 (with-no-warnings
1165 (specifier-instance has-modeline-p)))
1166 speedbar-buffer)
1167 (with-current-buffer speedbar-buffer
1168 (let* ((w (or (speedbar-frame-width) 20))
1169 (p1 "<<")
1170 (p5 ">>")
1171 (p3 (if speedbar-update-flag "#" "!"))
1172 (p35 (capitalize speedbar-initial-expansion-list-name))
1173 (blank (- w (length p1) (length p3) (length p5) (length p35)
1174 (if line-number-mode 5 1)))
1175 (p2 (if (> blank 0)
1176 (make-string (/ blank 2) ? )
1177 ""))
1178 (p4 (if (> blank 0)
1179 (make-string (+ (/ blank 2) (% blank 2)) ? )
1180 ""))
1182 (if line-number-mode
1183 (list (concat p1 p2 p3 " " p35) '(line-number-mode " %3l")
1184 (concat p4 p5))
1185 (list (concat p1 p2 p3 p4 p5)))))
1186 (if (not (equal mode-line-format tf))
1187 (progn
1188 (setq mode-line-format tf)
1189 (speedbar-mode-line-update)))))))
1191 (defvar speedbar-previous-menu nil
1192 "The menu before the last `speedbar-reconfigure-keymaps' was called.")
1194 (defun speedbar-reconfigure-keymaps ()
1195 "Reconfigure the menu-bar in a speedbar frame.
1196 Different menu items are displayed depending on the current display mode
1197 and the existence of packages."
1198 (let ((md (append
1199 speedbar-easymenu-definition-base
1200 (if speedbar-shown-directories
1201 ;; file display mode version
1202 (speedbar-initial-menu)
1203 (save-excursion
1204 (dframe-select-attached-frame speedbar-frame)
1205 (eval (nth 1 (assoc speedbar-initial-expansion-list-name
1206 speedbar-initial-expansion-mode-alist)))))
1207 ;; Dynamic menu stuff
1208 '("-")
1209 (list (cons "Displays"
1210 (let ((displays nil)
1211 (alist speedbar-initial-expansion-mode-alist))
1212 (while alist
1213 (setq displays
1214 (cons
1215 (vector
1216 (capitalize (car (car alist)))
1217 (list
1218 'speedbar-change-initial-expansion-list
1219 (car (car alist)))
1220 :style 'radio
1221 :selected
1222 `(string= ,(car (car alist))
1223 speedbar-initial-expansion-list-name)
1225 displays))
1226 (setq alist (cdr alist)))
1227 displays)))
1228 ;; The trailer
1229 speedbar-easymenu-definition-trailer))
1230 (localmap (save-excursion
1231 (let ((cf (selected-frame)))
1232 (prog2
1233 (dframe-select-attached-frame speedbar-frame)
1234 (if (local-variable-p
1235 'speedbar-special-mode-key-map
1236 (current-buffer))
1237 speedbar-special-mode-key-map)
1238 (select-frame cf))))))
1239 (with-current-buffer speedbar-buffer
1240 (use-local-map (or localmap
1241 (speedbar-initial-keymap)
1242 ;; This creates a small keymap we can glom the
1243 ;; menu adjustments into.
1244 (speedbar-make-specialized-keymap)))
1245 ;; Delete the old menu if applicable.
1246 (if speedbar-previous-menu (easy-menu-remove speedbar-previous-menu))
1247 (setq speedbar-previous-menu md)
1248 ;; Now add the new menu
1249 (if (not (featurep 'xemacs))
1250 (easy-menu-define speedbar-menu-map (current-local-map)
1251 "Speedbar menu" md)
1252 (easy-menu-add md (current-local-map))
1253 ;; XEmacs-specific:
1254 (if (fboundp 'set-buffer-menubar)
1255 (set-buffer-menubar (list md)))))
1257 (run-hooks 'speedbar-reconfigure-keymaps-hook)))
1260 ;;; User Input stuff
1262 (defun speedbar-customize ()
1263 "Customize speedbar using the Custom package."
1264 (interactive)
1265 (let ((sf (selected-frame)))
1266 (dframe-select-attached-frame speedbar-frame)
1267 (customize-group 'speedbar)
1268 (select-frame sf))
1269 (dframe-maybee-jump-to-attached-frame))
1271 (defun speedbar-track-mouse (event)
1272 "For motion EVENT, display info about the current line."
1273 (if (not speedbar-track-mouse-flag)
1275 (save-excursion
1276 (save-window-excursion
1277 (condition-case nil
1278 (progn
1279 (mouse-set-point event)
1280 (if (eq major-mode 'speedbar-mode)
1281 ;; XEmacs may let us get in here in other mode buffers.
1282 (speedbar-item-info)))
1283 (error (speedbar-message nil)))))))
1285 (defun speedbar-show-info-under-mouse ()
1286 "Call the info function for the line under the mouse."
1287 (let ((pos (mouse-position))) ; we ignore event until I use it later.
1288 (if (equal (car pos) speedbar-frame)
1289 (save-excursion
1290 (save-window-excursion
1291 (apply 'set-mouse-position pos)
1292 (speedbar-item-info))))))
1294 (defun speedbar-next (arg)
1295 "Move to the next ARGth line in a speedbar buffer."
1296 (interactive "p")
1297 (forward-line (or arg 1))
1298 (speedbar-item-info)
1299 (speedbar-position-cursor-on-line))
1301 (defun speedbar-prev (arg)
1302 "Move to the previous ARGth line in a speedbar buffer."
1303 (interactive "p")
1304 (speedbar-next (if arg (- arg) -1)))
1306 (defun speedbar-restricted-move (arg)
1307 "Move to the next ARGth line in a speedbar buffer at the same depth.
1308 This means that movement is restricted to a subnode, and that siblings
1309 of intermediate nodes are skipped."
1310 (if (not (numberp arg)) (signal 'wrong-type-argument (list 'numberp arg)))
1311 ;; First find the extent for which we are allowed to move.
1312 (let ((depth (save-excursion (beginning-of-line)
1313 (if (looking-at "[0-9]+:")
1314 (string-to-number (match-string 0))
1315 0)))
1316 (crement (if (< arg 0) 1 -1)) ; decrement or increment
1317 (lastmatch (point)))
1318 (while (/= arg 0)
1319 (forward-line (- crement))
1320 (let ((subdepth (save-excursion (beginning-of-line)
1321 (if (looking-at "[0-9]+:")
1322 (string-to-number (match-string 0))
1323 0))))
1324 (cond ((or (< subdepth depth)
1325 (progn (end-of-line) (eobp))
1326 (progn (beginning-of-line) (bobp)))
1327 ;; We have reached the end of this block.
1328 (goto-char lastmatch)
1329 (setq arg 0)
1330 (error "End of sub-list"))
1331 ((= subdepth depth)
1332 (setq lastmatch (point)
1333 arg (+ arg crement))))))
1334 (speedbar-position-cursor-on-line)))
1336 (defun speedbar-restricted-next (arg)
1337 "Move to the next ARGth line in a speedbar buffer at the same depth.
1338 This means that movement is restricted to a subnode, and that siblings
1339 of intermediate nodes are skipped."
1340 (interactive "p")
1341 (speedbar-restricted-move (or arg 1))
1342 (speedbar-item-info))
1344 (defun speedbar-restricted-prev (arg)
1345 "Move to the previous ARGth line in a speedbar buffer at the same depth.
1346 This means that movement is restricted to a subnode, and that siblings
1347 of intermediate nodes are skipped."
1348 (interactive "p")
1349 (speedbar-restricted-move (if arg (- arg) -1))
1350 (speedbar-item-info))
1352 (defun speedbar-navigate-list (arg)
1353 "Move across ARG groups of similarly typed items in speedbar.
1354 Stop on the first line of the next type of item, or on the last or first item
1355 if we reach a buffer boundary."
1356 (interactive "p")
1357 (beginning-of-line)
1358 (if (looking-at "[0-9]+: *[[<{][-+?][]>}] ")
1359 (let ((str (regexp-quote (match-string 0))))
1360 (while (looking-at str)
1361 (speedbar-restricted-move arg)
1362 (beginning-of-line))))
1363 (speedbar-position-cursor-on-line))
1365 (defun speedbar-forward-list ()
1366 "Move forward over the current list.
1367 A LIST in speedbar is a group of similarly typed items, such as directories,
1368 files, or the directory button."
1369 (interactive)
1370 (speedbar-navigate-list 1)
1371 (speedbar-item-info))
1373 (defun speedbar-backward-list ()
1374 "Move backward over the current list.
1375 A LIST in speedbar is a group of similarly typed items, such as directories,
1376 files, or the directory button."
1377 (interactive)
1378 (speedbar-navigate-list -1)
1379 (speedbar-item-info))
1381 (defun speedbar-scroll-up (&optional arg)
1382 "Page down one screen-full of the speedbar, or ARG lines."
1383 (interactive "P")
1384 (scroll-up arg)
1385 (speedbar-position-cursor-on-line))
1387 (defun speedbar-scroll-down (&optional arg)
1388 "Page up one screen-full of the speedbar, or ARG lines."
1389 (interactive "P")
1390 (scroll-down arg)
1391 (speedbar-position-cursor-on-line))
1393 (defun speedbar-up-directory ()
1394 "Keyboard accelerator for moving the default directory up one.
1395 Assumes that the current buffer is the speedbar buffer."
1396 (interactive)
1397 (setq default-directory (expand-file-name (concat default-directory "../")))
1398 (speedbar-update-contents))
1400 ;;; Speedbar file activity (aka creeping featurism)
1402 (defun speedbar-refresh (&optional arg)
1403 "Refresh the current speedbar display, disposing of any cached data.
1404 Argument ARG represents to force a refresh past any caches that may exist."
1405 (interactive "P")
1406 (let ((dl speedbar-shown-directories)
1407 (dframe-power-click arg)
1408 deactivate-mark)
1409 ;; We need to hack something so this works in detached frames.
1410 (while dl
1411 (adelete 'speedbar-directory-contents-alist (car dl))
1412 (setq dl (cdr dl)))
1413 (if (<= 1 speedbar-verbosity-level)
1414 (speedbar-message "Refreshing speedbar..."))
1415 (speedbar-update-contents)
1416 (speedbar-stealthy-updates)
1417 ;; Reset the timer in case it got really hosed for some reason...
1418 (speedbar-set-timer dframe-update-speed)
1419 (if (<= 1 speedbar-verbosity-level)
1420 (speedbar-message "Refreshing speedbar...done"))))
1422 (defun speedbar-item-load ()
1423 "Load the item under the cursor or mouse if it is a Lisp file."
1424 (interactive)
1425 (let ((f (speedbar-line-file)))
1426 (if (and (file-exists-p f) (string-match "\\.el\\'" f))
1427 (if (and (file-exists-p (concat f "c"))
1428 (speedbar-y-or-n-p (format "Load %sc? " f)))
1429 ;; If the compiled version exists, load that instead...
1430 (load-file (concat f "c"))
1431 (load-file f))
1432 (error "Not a loadable file"))))
1434 (defun speedbar-item-byte-compile ()
1435 "Byte compile the item under the cursor or mouse if it is a Lisp file."
1436 (interactive)
1437 (let ((f (speedbar-line-file))
1438 (sf (selected-frame)))
1439 (if (and (file-exists-p f) (string-match "\\.el\\'" f))
1440 (progn
1441 (dframe-select-attached-frame speedbar-frame)
1442 (byte-compile-file f nil)
1443 (select-frame sf)
1444 (speedbar-reset-scanners)))
1447 (defun speedbar-mouse-item-info (event)
1448 "Provide information about what the user clicked on.
1449 This should be bound to a mouse EVENT."
1450 (interactive "e")
1451 (mouse-set-point event)
1452 (speedbar-item-info))
1454 (defun speedbar-generic-item-info ()
1455 "Attempt to derive, and then display information about this line item.
1456 File style information is displayed with `speedbar-item-info'."
1457 (save-excursion
1458 (beginning-of-line)
1459 ;; Skip invisible number info.
1460 (if (looking-at "\\([0-9]+\\):") (goto-char (match-end 0)))
1461 ;; Skip items in "folder" type text characters.
1462 (if (looking-at "\\s-*[[<({].[]>)}] ") (goto-char (match-end 0)))
1463 ;; Get the text
1464 (speedbar-message "Text: %s" (buffer-substring-no-properties
1465 (point) (line-end-position)))))
1467 (defun speedbar-item-info ()
1468 "Display info in the minibuffer about the button the mouse is over.
1469 This function can be replaced in `speedbar-mode-functions-list' as
1470 `speedbar-item-info'."
1471 (interactive)
1472 (let (message-log-max)
1473 (funcall (or (speedbar-fetch-replacement-function 'speedbar-item-info)
1474 'speedbar-generic-item-info))))
1476 (defun speedbar-item-info-file-helper (&optional filename)
1477 "Display info about a file that is on the current line.
1478 Return nil if not applicable. If FILENAME, then use that
1479 instead of reading it from the speedbar buffer."
1480 (let* ((item (or filename (speedbar-line-file)))
1481 (attr (if item (file-attributes item) nil)))
1482 (if (and item attr) (speedbar-message "%s %-6d %s" (nth 8 attr)
1483 (nth 7 attr) item)
1484 nil)))
1486 (defun speedbar-item-info-tag-helper ()
1487 "Display info about a tag that is on the current line.
1488 Return nil if not applicable."
1489 (save-excursion
1490 (beginning-of-line)
1491 (if (re-search-forward " [-+=]?> \\([^\n]+\\)" (line-end-position) t)
1492 (let* ((tag (match-string 1))
1493 (attr (speedbar-line-token))
1494 (item nil)
1495 (semantic-tagged (if (fboundp 'semantic-tag-p)
1496 (semantic-tag-p attr))))
1497 (if semantic-tagged
1498 (with-no-warnings
1499 (save-excursion
1500 (when (and (semantic-tag-overlay attr)
1501 (semantic-tag-buffer attr))
1502 (set-buffer (semantic-tag-buffer attr)))
1503 (speedbar-message
1504 (funcall semantic-sb-info-format-tag-function attr)
1506 (looking-at "\\([0-9]+\\):")
1507 (setq item (file-name-nondirectory (speedbar-line-directory)))
1508 (speedbar-message "Tag: %s in %s" tag item)))
1509 (if (re-search-forward "{[+-]} \\([^\n]+\\)$" (line-end-position) t)
1510 (speedbar-message "Group of tags \"%s\"" (match-string 1))
1511 (if (re-search-forward " [+-]?[()|@] \\([^\n]+\\)$" nil t)
1512 (let* ((detailtext (match-string 1))
1513 (detail (or (speedbar-line-token) detailtext))
1514 (parent (save-excursion
1515 (beginning-of-line)
1516 (let ((dep (if (looking-at "[0-9]+:")
1517 (1- (string-to-number (match-string 0)))
1518 0)))
1519 (re-search-backward (concat "^"
1520 (int-to-string dep)
1521 ":")
1522 nil t))
1523 (if (looking-at "[0-9]+: +[-+=>]> \\([^\n]+\\)$")
1524 (speedbar-line-token)
1525 nil))))
1526 (if (featurep 'semantic)
1527 (with-no-warnings
1528 (if (semantic-tag-p detail)
1529 (speedbar-message
1530 (funcall semantic-sb-info-format-tag-function detail parent))
1531 (if parent
1532 (speedbar-message "Detail: %s of tag %s" detail
1533 (if (semantic-tag-p parent)
1534 (semantic-format-tag-name parent nil t)
1535 parent))
1536 (speedbar-message "Detail: %s" detail))))
1537 ;; Not using `semantic':
1538 (if parent
1539 (speedbar-message "Detail: %s of tag %s" detail parent)
1540 (speedbar-message "Detail: %s" detail))))
1541 nil)))))
1543 (defun speedbar-files-item-info ()
1544 "Display info in the minibuffer about the button the mouse is over."
1545 (if (not speedbar-shown-directories)
1546 (speedbar-generic-item-info)
1547 (or (speedbar-item-info-file-helper)
1548 (speedbar-item-info-tag-helper)
1549 (speedbar-generic-item-info))))
1551 (defun speedbar-item-copy ()
1552 "Copy the item under the cursor.
1553 Files can be copied to new names or places."
1554 (interactive)
1555 (let ((f (speedbar-line-file)))
1556 (if (not f) (error "Not a file"))
1557 (if (file-directory-p f)
1558 (error "Cannot copy directory")
1559 (let* ((rt (read-file-name (format "Copy %s to: "
1560 (file-name-nondirectory f))
1561 (file-name-directory f)))
1562 (refresh (member (expand-file-name (file-name-directory rt))
1563 speedbar-shown-directories)))
1564 ;; Create the right file name part
1565 (if (file-directory-p rt)
1566 (setq rt
1567 (concat (expand-file-name rt)
1568 (if (string-match "[/\\]$" rt) "" "/")
1569 (file-name-nondirectory f))))
1570 (if (or (not (file-exists-p rt))
1571 (speedbar-y-or-n-p (format "Overwrite %s with %s? " rt f)
1573 (progn
1574 (copy-file f rt t t)
1575 ;; refresh display if the new place is currently displayed.
1576 (if refresh
1577 (progn
1578 (speedbar-refresh)
1579 (if (not (speedbar-goto-this-file rt))
1580 (speedbar-goto-this-file f))))
1581 ))))))
1583 (defun speedbar-item-rename ()
1584 "Rename the item under the cursor or mouse.
1585 Files can be renamed to new names or moved to new directories."
1586 (interactive)
1587 (let ((f (speedbar-line-file)))
1588 (if f
1589 (let* ((rt (read-file-name (format "Rename %s to: "
1590 (file-name-nondirectory f))
1591 (file-name-directory f)))
1592 (refresh (member (expand-file-name (file-name-directory rt))
1593 speedbar-shown-directories)))
1594 ;; Create the right file name part
1595 (if (file-directory-p rt)
1596 (setq rt
1597 (concat (expand-file-name rt)
1598 (if (string-match "[/\\]\\'" rt) "" "/")
1599 (file-name-nondirectory f))))
1600 (if (or (not (file-exists-p rt))
1601 (speedbar-y-or-n-p (format "Overwrite %s with %s? " rt f)
1603 (progn
1604 (rename-file f rt t)
1605 ;; refresh display if the new place is currently displayed.
1606 (if refresh
1607 (progn
1608 (speedbar-refresh)
1609 (speedbar-goto-this-file rt)
1610 )))))
1611 (error "Not a file"))))
1613 (defun speedbar-create-directory ()
1614 "Create a directory in speedbar."
1615 (interactive)
1616 (let ((f (speedbar-line-file)))
1617 (if f
1618 (let* ((basedir (file-name-directory f))
1619 (nd (read-file-name "Create directory: "
1620 basedir)))
1621 ;; Make the directory
1622 (make-directory nd t)
1623 (speedbar-refresh)
1624 (speedbar-goto-this-file nd)
1626 (error "Not a file"))))
1628 (defun speedbar-item-delete ()
1629 "Delete the item under the cursor. Files are removed from disk."
1630 (interactive)
1631 (let ((f (speedbar-line-file)))
1632 (if (not f) (error "Not a file"))
1633 (if (speedbar-y-or-n-p (format "Delete %s? " f) t)
1634 (progn
1635 (if (file-directory-p f)
1636 (delete-directory f t t)
1637 (delete-file f t))
1638 (speedbar-message "Okie dokie.")
1639 (let ((p (point)))
1640 (speedbar-refresh)
1641 (goto-char p))
1645 (defun speedbar-item-object-delete ()
1646 "Delete the object associated from the item under the cursor.
1647 The file is removed from disk. The object is determined from the
1648 variable `speedbar-obj-alist'."
1649 (interactive)
1650 (let* ((f (speedbar-line-file))
1651 (obj nil)
1652 (oa speedbar-obj-alist))
1653 (if (not f) (error "Not a file"))
1654 (while (and oa (not (string-match (car (car oa)) f)))
1655 (setq oa (cdr oa)))
1656 (setq obj (concat (file-name-sans-extension f) (cdr (car oa))))
1657 (if (and oa (file-exists-p obj)
1658 (speedbar-y-or-n-p (format "Delete %s? " obj) t))
1659 (progn
1660 (delete-file obj)
1661 (speedbar-reset-scanners)))))
1663 (defun speedbar-enable-update ()
1664 "Enable automatic updating in speedbar via timers."
1665 (interactive)
1666 (setq speedbar-update-flag t)
1667 (speedbar-set-mode-line-format)
1668 (speedbar-set-timer dframe-update-speed))
1670 (defun speedbar-disable-update ()
1671 "Disable automatic updating and stop consuming resources."
1672 (interactive)
1673 (setq speedbar-update-flag nil)
1674 (speedbar-set-mode-line-format)
1675 (speedbar-set-timer nil))
1677 (defun speedbar-toggle-updates ()
1678 "Toggle automatic update for the speedbar frame."
1679 (interactive)
1680 (if speedbar-update-flag
1681 (speedbar-disable-update)
1682 (speedbar-enable-update)))
1684 (defun speedbar-toggle-images ()
1685 "Toggle use of images in the speedbar frame."
1686 (interactive)
1687 (setq speedbar-use-images (not speedbar-use-images))
1688 (speedbar-refresh))
1690 (defun speedbar-toggle-sorting ()
1691 "Toggle tag sorting."
1692 (interactive)
1693 (setq speedbar-sort-tags (not speedbar-sort-tags)))
1695 (defun speedbar-toggle-show-all-files ()
1696 "Toggle display of files speedbar can not tag."
1697 (interactive)
1698 (setq speedbar-show-unknown-files (not speedbar-show-unknown-files))
1699 (speedbar-refresh))
1701 (defmacro speedbar-with-writable (&rest forms)
1702 "Allow the buffer to be writable and evaluate FORMS."
1703 (list 'let '((inhibit-read-only t))
1704 (cons 'progn forms)))
1705 (put 'speedbar-with-writable 'lisp-indent-function 0)
1707 (defun speedbar-insert-button (text face mouse function
1708 &optional token prevline)
1709 "Insert TEXT as the next logical speedbar button.
1710 FACE is the face to put on the button, MOUSE is the highlight face to use.
1711 When the user clicks on TEXT, FUNCTION is called with the TOKEN parameter.
1712 This function assumes that the current buffer is the speedbar buffer.
1713 If PREVLINE, then put this button on the previous line.
1715 This is a convenience function for special modes that create their own
1716 specialized speedbar displays."
1717 (goto-char (point-max))
1718 (let ((start (point)))
1719 (if (/= (current-column) 0) (insert "\n"))
1720 (put-text-property start (point) 'invisible nil))
1721 (if prevline (progn (delete-char -1)
1722 (insert " ") ;back up if desired...
1723 (put-text-property (1- (point)) (point) 'invisible nil)))
1724 (let ((start (point)))
1725 (insert text)
1726 (speedbar-make-button start (point) face mouse function token))
1727 (let ((start (point)))
1728 (insert "\n")
1729 (add-text-properties
1730 start (point) '(face nil invisible nil mouse-face nil))))
1732 (defun speedbar-insert-separator (text)
1733 "Insert a separation label of TEXT.
1734 Separators are not active, have no labels, depth, or actions."
1735 (if speedbar-use-images
1736 (let ((start (point)))
1737 (insert "//")
1738 (speedbar-insert-image-button-maybe start 2)))
1739 (let ((start (point)))
1740 (insert text "\n")
1741 (speedbar-make-button start (point)
1742 'speedbar-separator-face
1743 nil nil nil)))
1745 (defun speedbar-make-button (start end face mouse function &optional token)
1746 "Create a button from START to END, with FACE as the display face.
1747 MOUSE is the mouse face. When this button is clicked on FUNCTION
1748 will be run with the TOKEN parameter (any Lisp object). If FACE
1749 is t use the text properties of the string that is passed as an
1750 argument."
1751 (unless (eq face t)
1752 (put-text-property start end 'face face))
1753 (add-text-properties
1754 start end `(mouse-face ,mouse invisible nil
1755 speedbar-text ,(buffer-substring-no-properties start end)))
1756 (if speedbar-use-tool-tips-flag
1757 (put-text-property start end 'help-echo #'dframe-help-echo))
1758 (if function (put-text-property start end 'speedbar-function function))
1759 (if token (put-text-property start end 'speedbar-token token))
1760 ;; So far the only text we have is less that 3 chars.
1761 (if (<= (- end start) 3)
1762 (speedbar-insert-image-button-maybe start (- end start)))
1765 ;;; Initial Expansion list management
1767 (defun speedbar-initial-expansion-list ()
1768 "Return the current default expansion list.
1769 This is based on `speedbar-initial-expansion-list-name' referencing
1770 `speedbar-initial-expansion-mode-alist'."
1771 ;; cdr1 - name, cdr2 - menu
1772 (cdr (cdr (cdr (assoc speedbar-initial-expansion-list-name
1773 speedbar-initial-expansion-mode-alist)))))
1775 (defun speedbar-initial-menu ()
1776 "Return the current default menu data.
1777 This is based on `speedbar-initial-expansion-list-name' referencing
1778 `speedbar-initial-expansion-mode-alist'."
1779 (symbol-value
1780 (car (cdr (assoc speedbar-initial-expansion-list-name
1781 speedbar-initial-expansion-mode-alist)))))
1783 (defun speedbar-initial-keymap ()
1784 "Return the current default menu data.
1785 This is based on `speedbar-initial-expansion-list-name' referencing
1786 `speedbar-initial-expansion-mode-alist'."
1787 (symbol-value
1788 (car (cdr (cdr (assoc speedbar-initial-expansion-list-name
1789 speedbar-initial-expansion-mode-alist))))))
1791 (defun speedbar-initial-stealthy-functions ()
1792 "Return a list of functions to call stealthily.
1793 This is based on `speedbar-initial-expansion-list-name' referencing
1794 `speedbar-stealthy-function-list'."
1795 (cdr (assoc speedbar-initial-expansion-list-name
1796 speedbar-stealthy-function-list)))
1798 (defun speedbar-add-expansion-list (new-list)
1799 "Add NEW-LIST to the list of expansion lists."
1800 (add-to-list 'speedbar-initial-expansion-mode-alist new-list))
1802 (defun speedbar-change-initial-expansion-list (new-default)
1803 "Change speedbar's default expansion list to NEW-DEFAULT."
1804 (interactive
1805 (list
1806 (completing-read (format "Speedbar Mode (default %s): "
1807 speedbar-previously-used-expansion-list-name)
1808 speedbar-initial-expansion-mode-alist
1809 nil t "" nil
1810 speedbar-previously-used-expansion-list-name)))
1811 (setq speedbar-previously-used-expansion-list-name
1812 speedbar-initial-expansion-list-name
1813 speedbar-initial-expansion-list-name new-default)
1814 (if (and (speedbar-current-frame) (frame-live-p (speedbar-current-frame)))
1815 (progn
1816 (speedbar-refresh)
1817 (speedbar-reconfigure-keymaps))))
1819 (defun speedbar-fetch-replacement-function (function)
1820 "Return a current mode-specific replacement for function, or nil.
1821 Scans `speedbar-mode-functions-list' first for the current mode, then
1822 for FUNCTION."
1823 (cdr (assoc function
1824 (cdr (assoc speedbar-initial-expansion-list-name
1825 speedbar-mode-functions-list)))))
1827 (defun speedbar-add-mode-functions-list (new-list)
1828 "Add NEW-LIST to the list of mode functions.
1829 See `speedbar-mode-functions-list' for details."
1830 (add-to-list 'speedbar-mode-functions-list new-list))
1833 ;;; Special speedbar display management
1835 (defun speedbar-maybe-add-localized-support (buffer)
1836 "Quick check function called on BUFFERs by the speedbar timer function.
1837 Maintains the value of local variables which control speedbar's use
1838 of the special mode functions."
1839 (or speedbar-special-mode-expansion-list
1840 (speedbar-add-localized-speedbar-support buffer)))
1842 (defun speedbar-add-localized-speedbar-support (buffer)
1843 "Add localized speedbar support to BUFFER's mode if it is available."
1844 (interactive "bBuffer: ")
1845 (if (stringp buffer) (setq buffer (get-buffer buffer)))
1846 (if (not (buffer-live-p buffer))
1848 (with-current-buffer buffer
1849 (save-match-data
1850 (let ((ms (symbol-name major-mode)) v)
1851 (if (not (string-match "-mode$" ms))
1852 nil ;; do nothing to broken mode
1853 (setq ms (substring ms 0 (match-beginning 0)))
1854 (setq v (intern-soft (concat ms "-speedbar-buttons")))
1855 (make-local-variable 'speedbar-special-mode-expansion-list)
1856 (if (not v)
1857 (setq speedbar-special-mode-expansion-list t)
1858 ;; If it is autoloaded, we need to load it now so that
1859 ;; we have access to the varialbe -speedbar-menu-items.
1860 ;; Is this XEmacs safe?
1861 (let ((sf (symbol-function v)))
1862 (if (and (listp sf) (eq (car sf) 'autoload))
1863 (load-library (car (cdr sf)))))
1864 (setq speedbar-special-mode-expansion-list (list v))
1865 (setq v (intern-soft (concat ms "-speedbar-key-map")))
1866 (if (not v)
1867 nil ;; don't add special keymap
1868 (make-local-variable 'speedbar-special-mode-key-map)
1869 (setq speedbar-special-mode-key-map
1870 (symbol-value v)))
1871 (setq v (intern-soft (concat ms "-speedbar-menu-items")))
1872 (if (not v)
1873 nil ;; don't add special menus
1874 (make-local-variable 'speedbar-easymenu-definition-special)
1875 (setq speedbar-easymenu-definition-special
1876 (symbol-value v)))
1877 )))))))
1879 (defun speedbar-remove-localized-speedbar-support (buffer)
1880 "Remove any traces that BUFFER supports speedbar in a specialized way."
1881 (with-current-buffer buffer
1882 (kill-local-variable 'speedbar-special-mode-expansion-list)
1883 (kill-local-variable 'speedbar-special-mode-key-map)
1884 (kill-local-variable 'speedbar-easymenu-definition-special)))
1886 ;;; File button management
1888 (defun speedbar-file-lists (directory)
1889 "Create file lists for DIRECTORY.
1890 The car is the list of directories, the cdr is list of files not
1891 matching ignored headers. Cache any directory files found in
1892 `speedbar-directory-contents-alist' and use that cache before scanning
1893 the file-system."
1894 (setq directory (expand-file-name directory))
1895 ;; If in powerclick mode, then the directory we are getting
1896 ;; should be rescanned.
1897 (if dframe-power-click
1898 (adelete 'speedbar-directory-contents-alist directory))
1899 ;; find the directory, either in the cache, or build it.
1900 (or (cdr-safe (assoc directory speedbar-directory-contents-alist))
1901 (let ((default-directory directory)
1902 (dir (directory-files directory nil))
1903 (dirs nil)
1904 (files nil))
1905 (while dir
1906 (if (not
1907 (or (string-match speedbar-file-unshown-regexp (car dir))
1908 (member (car dir) vc-directory-exclusion-list)
1909 (string-match speedbar-directory-unshown-regexp (car dir))))
1910 (if (file-directory-p (car dir))
1911 (setq dirs (cons (car dir) dirs))
1912 (setq files (cons (car dir) files))))
1913 (setq dir (cdr dir)))
1914 (let ((nl (cons (nreverse dirs) (list (nreverse files)))))
1915 (aput 'speedbar-directory-contents-alist directory nl)
1916 nl))
1919 (defun speedbar-directory-buttons (directory index)
1920 "Insert a single button group at point for DIRECTORY.
1921 Each directory part is a different button. If part of the directory
1922 matches the user directory ~, then it is replaced with a ~.
1923 INDEX is not used, but is required by the caller."
1924 (let* ((tilde (expand-file-name "~/"))
1925 (dd (expand-file-name directory))
1926 (junk (string-match (regexp-quote tilde) dd))
1927 (displayme (if junk
1928 (concat "~/" (substring dd (match-end 0)))
1929 dd))
1930 (p (point)))
1931 (if (string-match "^~[/\\]?\\'" displayme) (setq displayme tilde))
1932 (insert displayme)
1933 (save-excursion
1934 (goto-char p)
1935 (while (re-search-forward "\\([^/\\]+\\)[/\\]" nil t)
1936 (speedbar-make-button (match-beginning 1) (match-end 1)
1937 'speedbar-directory-face
1938 'speedbar-highlight-face
1939 'speedbar-directory-buttons-follow
1940 (if (and (= (match-beginning 1) p)
1941 (not (char-equal (char-after (+ p 1)) ?:)))
1942 (expand-file-name "~/") ;the tilde
1943 (buffer-substring-no-properties
1944 p (match-end 0)))))
1945 ;; Nuke the beginning of the directory if it's too long...
1946 (cond ((eq speedbar-directory-button-trim-method 'span)
1947 (beginning-of-line)
1948 (let ((ww (or (speedbar-frame-width) 20)))
1949 (move-to-column ww nil)
1950 (while (>= (current-column) ww)
1951 (re-search-backward "[/\\]" nil t)
1952 (if (<= (current-column) 2)
1953 (progn
1954 (re-search-forward "[/\\]" nil t)
1955 (if (< (current-column) 4)
1956 (re-search-forward "[/\\]" nil t))
1957 (forward-char -1)))
1958 (if (looking-at "[/\\]?$")
1959 (beginning-of-line)
1960 (insert "/...\n ")
1961 (move-to-column ww nil)))))
1962 ((eq speedbar-directory-button-trim-method 'trim)
1963 (end-of-line)
1964 (let ((ww (or (speedbar-frame-width) 20))
1965 (tl (current-column)))
1966 (if (< ww tl)
1967 (progn
1968 (move-to-column (- tl ww))
1969 (if (re-search-backward "[/\\]" nil t)
1970 (progn
1971 (delete-region (point-min) (point))
1972 (insert "$")
1973 )))))))
1975 (if (string-match "\\`[/\\][^/\\]+[/\\]\\'" displayme)
1976 (progn
1977 (insert " ")
1978 (let ((p (point)))
1979 (insert "<root>")
1980 (speedbar-make-button p (point)
1981 'speedbar-directory-face
1982 'speedbar-highlight-face
1983 'speedbar-directory-buttons-follow
1984 "/"))))
1985 (end-of-line)
1986 (insert-char ?\n 1 nil)))
1988 (defun speedbar-make-tag-line (exp-button-type
1989 exp-button-char exp-button-function
1990 exp-button-data
1991 tag-button tag-button-function tag-button-data
1992 tag-button-face depth)
1993 "Create a tag line with EXP-BUTTON-TYPE for the small expansion button.
1994 This is the button that expands or contracts a node (if applicable),
1995 and EXP-BUTTON-CHAR the character in it (+, -, ?, etc). EXP-BUTTON-FUNCTION
1996 is the function to call if it's clicked on. Button types are
1997 'bracket, 'angle, 'curly, 'expandtag, 'statictag, t, or nil.
1998 EXP-BUTTON-DATA is extra data attached to the text forming the expansion
1999 button.
2001 Next, TAG-BUTTON is the text of the tag. TAG-BUTTON-FUNCTION is the
2002 function to call if clicked on, and TAG-BUTTON-DATA is the data to
2003 attach to the text field (such a tag positioning, etc).
2004 TAG-BUTTON-FACE is a face used for this type of tag.
2006 Lastly, DEPTH shows the depth of expansion.
2008 This function assumes that the cursor is in the speedbar window at the
2009 position to insert a new item, and that the new item will end with a CR."
2010 (let ((start (point))
2011 (end (progn
2012 (insert (int-to-string depth) ":")
2013 (point)))
2014 (depthspacesize (* depth speedbar-indentation-width)))
2015 (put-text-property start end 'invisible t)
2016 (insert-char ? depthspacesize nil)
2017 (put-text-property (- (point) depthspacesize) (point) 'invisible nil)
2018 (let* ((exp-button (cond ((eq exp-button-type 'bracket) "[%c]")
2019 ((eq exp-button-type 'angle) "<%c>")
2020 ((eq exp-button-type 'curly) "{%c}")
2021 ((eq exp-button-type 'expandtag) " %c>")
2022 ((eq exp-button-type 'statictag) " =>")
2023 (t ">")))
2024 (buttxt (format exp-button exp-button-char))
2025 (start (point))
2026 (end (progn (insert buttxt) (point)))
2027 (bf (if (and exp-button-type (not (eq exp-button-type 'statictag)))
2028 'speedbar-button-face nil))
2029 (mf (if exp-button-function 'speedbar-highlight-face nil))
2031 (speedbar-make-button start end bf mf exp-button-function exp-button-data)
2032 (if speedbar-hide-button-brackets-flag
2033 (progn
2034 (put-text-property start (1+ start) 'invisible t)
2035 (put-text-property end (1- end) 'invisible t)))
2037 (insert-char ? 1 nil)
2038 (put-text-property (1- (point)) (point) 'invisible nil)
2039 (let ((start (point))
2040 (end (progn (insert tag-button) (point))))
2041 (insert-char ?\n 1 nil)
2042 (put-text-property (1- (point)) (point) 'invisible nil)
2043 (speedbar-make-button start end tag-button-face
2044 (if tag-button-function 'speedbar-highlight-face nil)
2045 tag-button-function tag-button-data))
2048 (defun speedbar-change-expand-button-char (char)
2049 "Change the expansion button character to CHAR for the current line."
2050 (save-excursion
2051 (beginning-of-line)
2052 (if (re-search-forward ":\\s-*.\\([-+?]\\)" (line-end-position) t)
2053 (speedbar-with-writable
2054 (goto-char (match-end 1))
2055 (insert-char char 1 t)
2056 (forward-char -1)
2057 (delete-char -1)
2058 ;;(put-text-property (point) (1- (point)) 'invisible nil)
2059 ;; make sure we fix the image on the text here.
2060 (speedbar-insert-image-button-maybe (- (point) 1) 3)))))
2063 ;;; Build button lists
2065 (defun speedbar-insert-files-at-point (files level)
2066 "Insert list of FILES starting at point, and indenting all files to LEVEL.
2067 Tag expandable items with a +, otherwise a ?. Don't highlight ? as we
2068 don't know how to manage them. The input parameter FILES is a cons
2069 cell of the form ( 'DIRLIST . 'FILELIST )."
2070 ;; Start inserting all the directories
2071 (let ((dirs (car files)))
2072 (while dirs
2073 (speedbar-make-tag-line 'angle ?+ 'speedbar-dired (car dirs)
2074 (car dirs) 'speedbar-dir-follow nil
2075 'speedbar-directory-face level)
2076 (setq dirs (cdr dirs))))
2077 (let ((lst (car (cdr files)))
2078 (case-fold-search t))
2079 (while lst
2080 (let* ((known (string-match speedbar-file-regexp (car lst)))
2081 (expchar (if known ?+ ??))
2082 (fn (if known 'speedbar-tag-file nil)))
2083 (if (or speedbar-show-unknown-files (/= expchar ??))
2084 (speedbar-make-tag-line 'bracket expchar fn (car lst)
2085 (car lst) 'speedbar-find-file nil
2086 'speedbar-file-face level)))
2087 (setq lst (cdr lst)))))
2089 (defun speedbar-default-directory-list (directory index)
2090 "Insert files for DIRECTORY with level INDEX at point."
2091 (speedbar-insert-files-at-point
2092 (speedbar-file-lists directory) index)
2093 (speedbar-reset-scanners)
2094 (if (= index 0)
2095 ;; If the shown files variable has extra directories, then
2096 ;; it is our responsibility to redraw them all
2097 ;; Luckilly, the nature of inserting items into this list means
2098 ;; that by reversing it, we can easilly go in the right order
2099 (let ((sf (cdr (reverse speedbar-shown-directories))))
2100 (setq speedbar-shown-directories
2101 (list (expand-file-name default-directory)))
2102 ;; exand them all as we find them
2103 (while sf
2104 (if (speedbar-goto-this-file (car sf))
2105 (progn
2106 (beginning-of-line)
2107 (if (looking-at "[0-9]+:[ ]*<")
2108 (progn
2109 (goto-char (match-end 0))
2110 (speedbar-do-function-pointer)))))
2111 (setq sf (cdr sf)))
2113 ;;; Generic List support
2115 ;; Generic lists are hierarchies of tags which we may need to permute
2116 ;; in order to make it look nice.
2118 ;; A generic list is of the form:
2119 ;; ( ("name" . marker-or-number) <-- one tag at this level
2120 ;; ("name" ("name" . mon) ("name" . mon) ) <-- one group of tags
2121 ;; ("name" mon ("name" . mon) ) <-- group w/ a position and tags
2122 (defun speedbar-generic-list-group-p (sublst)
2123 "Non-nil if SUBLST is a group.
2124 Groups may optionally contain a position."
2125 (and (stringp (car-safe sublst))
2126 (or (and (listp (cdr-safe sublst))
2127 (or (speedbar-generic-list-tag-p (car-safe (cdr-safe sublst)))
2128 (speedbar-generic-list-group-p (car-safe (cdr-safe sublst))
2130 (and (number-or-marker-p (car-safe (cdr-safe sublst)))
2131 (listp (cdr-safe (cdr-safe sublst)))
2132 (speedbar-generic-list-tag-p
2133 (car-safe (cdr-safe (cdr-safe sublst)))))
2136 (defun speedbar-generic-list-positioned-group-p (sublst)
2137 "Non-nil if SUBLST is a group with a position."
2138 (and (stringp (car-safe sublst))
2139 (number-or-marker-p (car-safe (cdr-safe sublst)))
2140 (listp (cdr-safe (cdr-safe sublst)))
2141 (let ((rest (car-safe (cdr-safe (cdr-safe sublst)))))
2142 (or (speedbar-generic-list-tag-p rest)
2143 (speedbar-generic-list-group-p rest)
2144 (speedbar-generic-list-positioned-group-p rest)
2145 ))))
2147 (defun speedbar-generic-list-tag-p (sublst)
2148 "Non-nil if SUBLST is a tag."
2149 (and (stringp (car-safe sublst))
2150 (or (and (number-or-marker-p (cdr-safe sublst))
2151 (not (cdr-safe (cdr-safe sublst))))
2152 ;; For semantic/bovine items, this is needed
2153 (symbolp (car-safe (cdr-safe sublst))))
2156 (defun speedbar-sort-tag-hierarchy (lst)
2157 "Sort all elements of tag hierarchy LST."
2158 (sort (copy-alist lst)
2159 (lambda (a b) (string< (car a) (car b)))))
2161 (defun speedbar-try-completion (string alist)
2162 "A wrapper for `try-completion'.
2163 Passes STRING and ALIST to `try-completion' if ALIST
2164 passes some tests."
2165 (if (and (consp alist)
2166 (listp (car alist)) (stringp (car (car alist))))
2167 (try-completion string alist)
2168 nil))
2170 (defun speedbar-prefix-group-tag-hierarchy (lst)
2171 "Prefix group names for tag hierarchy LST."
2172 (let ((newlst nil)
2173 (sublst nil)
2174 (work-list nil)
2175 (junk-list nil)
2176 (short-group-list nil)
2177 (short-start-name nil)
2178 (short-end-name nil)
2179 (num-shorts-grouped 0)
2180 (bins (make-vector 256 nil))
2181 (diff-idx 0))
2182 (if (<= (length lst) speedbar-tag-regroup-maximum-length)
2183 ;; Do nothing. Too short to bother with.
2185 ;; Break out sub-lists
2186 (while lst
2187 (if (speedbar-generic-list-group-p (car-safe lst))
2188 (setq newlst (cons (car lst) newlst))
2189 (setq sublst (cons (car lst) sublst)))
2190 (setq lst (cdr lst)))
2191 ;; Reverse newlst because it was made backwards.
2192 ;; Sublist doesn't need reversing because the act
2193 ;; of binning things will reverse it for us.
2194 (setq newlst (nreverse newlst)
2195 sublst sublst)
2196 ;; Now, first find out how long our list is. Never let a
2197 ;; list get-shorter than our minimum.
2198 (if (<= (length sublst) speedbar-tag-split-minimum-length)
2199 (setq work-list sublst)
2200 (setq diff-idx (length (speedbar-try-completion "" sublst)))
2201 ;; Sort the whole list into bins.
2202 (while sublst
2203 (let ((e (car sublst))
2204 (s (car (car sublst))))
2205 (cond ((<= (length s) diff-idx)
2206 ;; 0 storage bin for shorty.
2207 (aset bins 0 (cons e (aref bins 0))))
2209 ;; stuff into a bin based on ascii value at diff
2210 (aset bins (aref s diff-idx)
2211 (cons e (aref bins (aref s diff-idx)))))))
2212 (setq sublst (cdr sublst)))
2213 ;; Go through all our bins Stick singles into our
2214 ;; junk-list, everything else as sublsts in work-list.
2215 ;; If two neighboring lists are both small, make a grouped
2216 ;; group combinding those two sub-lists.
2217 (setq diff-idx 0)
2218 (while (> 256 diff-idx)
2219 ;; The bins contents are currently in forward order.
2220 (let ((l (aref bins diff-idx)))
2221 (if l
2222 (let ((tmp (cons (speedbar-try-completion "" l) l)))
2223 (if (or (> (length l) speedbar-tag-regroup-maximum-length)
2224 (> (+ (length l) (length short-group-list))
2225 speedbar-tag-split-minimum-length))
2226 (progn
2227 ;; We have reached a longer list, so we
2228 ;; must finish off a grouped group.
2229 (cond
2230 ((and short-group-list
2231 (= (length short-group-list)
2232 num-shorts-grouped))
2233 ;; All singles? Junk list
2234 (setq junk-list (append (nreverse short-group-list)
2235 junk-list)))
2236 ((= num-shorts-grouped 1)
2237 ;; Only one short group? Just stick it in
2238 ;; there by itself. Make a group, and find
2239 ;; a subexpression
2240 (let ((subexpression (speedbar-try-completion
2241 "" short-group-list)))
2242 (if (< (length subexpression)
2243 speedbar-tag-group-name-minimum-length)
2244 (setq subexpression
2245 (concat short-start-name
2246 " ("
2247 (substring
2248 (car (car short-group-list))
2249 (length short-start-name))
2250 ")")))
2251 (setq work-list
2252 (cons (cons subexpression
2253 short-group-list)
2254 work-list ))))
2255 (short-group-list
2256 ;; Multiple groups to be named in a special
2257 ;; way by displaying the range over which we
2258 ;; have grouped them.
2259 (setq work-list
2260 (cons (cons (concat short-start-name
2261 " to "
2262 short-end-name)
2263 short-group-list)
2264 work-list))))
2265 ;; Reset short group list information every time.
2266 (setq short-group-list nil
2267 short-start-name nil
2268 short-end-name nil
2269 num-shorts-grouped 0)))
2270 ;; Ok, now that we cleaned up the short-group-list,
2271 ;; we can deal with this new list, to decide if it
2272 ;; should go on one of these sub-lists or not.
2273 (if (< (length l) speedbar-tag-regroup-maximum-length)
2274 (setq short-group-list (append l short-group-list)
2275 num-shorts-grouped (1+ num-shorts-grouped)
2276 short-end-name (car tmp)
2277 short-start-name (if short-start-name
2278 short-start-name
2279 (car tmp)))
2280 (setq work-list (cons tmp work-list))))))
2281 (setq diff-idx (1+ diff-idx))))
2282 ;; Did we run out of things? Drop our new list onto the end.
2283 (cond
2284 ((and short-group-list (= (length short-group-list) num-shorts-grouped))
2285 ;; All singles? Junk list
2286 (setq junk-list (append short-group-list junk-list)))
2287 ((= num-shorts-grouped 1)
2288 ;; Only one short group? Just stick it in
2289 ;; there by itself.
2290 (setq work-list
2291 (cons (cons (speedbar-try-completion "" short-group-list)
2292 short-group-list)
2293 work-list)))
2294 (short-group-list
2295 ;; Multiple groups to be named in a special
2296 ;; way by displaying the range over which we
2297 ;; have grouped them.
2298 (setq work-list
2299 (cons (cons (concat short-start-name " to " short-end-name)
2300 short-group-list)
2301 work-list))))
2302 ;; Reverse the work list nreversed when consing.
2303 (setq work-list (nreverse work-list))
2304 ;; Now, stick our new list onto the end of
2305 (if work-list
2306 (if junk-list
2307 (append newlst work-list junk-list)
2308 (append newlst work-list))
2309 (append newlst junk-list)))))
2311 (defun speedbar-trim-words-tag-hierarchy (lst)
2312 "Trim all words in a tag hierarchy.
2313 Base trimming information on word separators, and group names.
2314 Argument LST is the list of tags to trim."
2315 (let ((newlst nil)
2316 (sublst nil)
2317 (trim-prefix nil)
2318 (trim-chars 0)
2319 (trimlst nil))
2320 (while lst
2321 (if (speedbar-generic-list-group-p (car-safe lst))
2322 (setq newlst (cons (car lst) newlst))
2323 (setq sublst (cons (car lst) sublst)))
2324 (setq lst (cdr lst)))
2325 ;; Get the prefix to trim by. Make sure that we don't trim
2326 ;; off silly pieces, only complete understandable words.
2327 (setq trim-prefix (speedbar-try-completion "" sublst)
2328 newlst (nreverse newlst))
2329 (if (or (= (length sublst) 1)
2330 (not trim-prefix)
2331 (not (string-match "\\(\\w+\\W+\\)+" trim-prefix)))
2332 (append newlst (nreverse sublst))
2333 (setq trim-prefix (substring trim-prefix (match-beginning 0)
2334 (match-end 0)))
2335 (setq trim-chars (length trim-prefix))
2336 (while sublst
2337 (setq trimlst (cons
2338 (cons (substring (car (car sublst)) trim-chars)
2339 (cdr (car sublst)))
2340 trimlst)
2341 sublst (cdr sublst)))
2342 ;; Put the lists together
2343 (append newlst trimlst))))
2345 (defun speedbar-simple-group-tag-hierarchy (lst)
2346 "Create a simple 'Tags' group with orphaned tags.
2347 Argument LST is the list of tags to sort into groups."
2348 (let ((newlst nil)
2349 (sublst nil))
2350 (while lst
2351 (if (speedbar-generic-list-group-p (car-safe lst))
2352 (setq newlst (cons (car lst) newlst))
2353 (setq sublst (cons (car lst) sublst)))
2354 (setq lst (cdr lst)))
2355 (if (not newlst)
2356 (nreverse sublst)
2357 (setq newlst (cons (cons "Tags" (nreverse sublst)) newlst))
2358 (nreverse newlst))))
2360 (defun speedbar-create-tag-hierarchy (lst)
2361 "Adjust the tag hierarchy in LST, and return it.
2362 This uses `speedbar-tag-hierarchy-method' to determine how to adjust
2363 the list."
2364 (let* ((f (save-excursion
2365 (forward-line -1)
2366 (or (speedbar-line-file)
2367 (speedbar-line-directory))))
2368 (methods (if (get-file-buffer f)
2369 (with-current-buffer (get-file-buffer f)
2370 speedbar-tag-hierarchy-method)
2371 speedbar-tag-hierarchy-method))
2372 (lst (if (fboundp 'copy-tree)
2373 (copy-tree lst)
2374 lst)))
2375 (while methods
2376 (setq lst (funcall (car methods) lst)
2377 methods (cdr methods)))
2378 lst))
2380 (defvar speedbar-generic-list-group-expand-button-type 'curly
2381 "The type of button created for groups of tags.
2382 Good values for this are `curly' and `expandtag'.
2383 Make buffer local for your mode.")
2385 (defvar speedbar-generic-list-tag-button-type nil
2386 "The type of button created for tags in generic lists.
2387 Good values for this are nil and `statictag'.
2388 Make buffer local for your mode.")
2390 (defun speedbar-insert-generic-list (level lst expand-fun find-fun)
2391 "At LEVEL, insert a generic multi-level alist LST.
2392 Associations with lists get {+} tags (to expand into more nodes) and
2393 those with positions just get a > as the indicator. {+} buttons will
2394 have the function EXPAND-FUN and the token is the cdr list. The token
2395 name will have the function FIND-FUN and not token."
2396 ;; Remove imenu rescan button
2397 (if (string= (car (car lst)) "*Rescan*")
2398 (setq lst (cdr lst)))
2399 ;; Get, and set up variables that define how we treat these tags.
2400 (let ((f (save-excursion (forward-line -1)
2401 (or (speedbar-line-file)
2402 (speedbar-line-directory))))
2403 expand-button tag-button)
2404 (save-excursion
2405 (if (get-file-buffer f)
2406 (set-buffer (get-file-buffer f)))
2407 (setq expand-button speedbar-generic-list-group-expand-button-type
2408 tag-button speedbar-generic-list-tag-button-type))
2409 ;; Adjust the list.
2410 (setq lst (speedbar-create-tag-hierarchy lst))
2411 ;; insert the parts
2412 (while lst
2413 (cond ((null (car-safe lst)) nil) ;this would be a separator
2414 ((speedbar-generic-list-tag-p (car lst))
2415 (speedbar-make-tag-line tag-button
2416 nil nil nil ;no expand button data
2417 (car (car lst)) ;button name
2418 find-fun ;function
2419 (cdr (car lst)) ;token is position
2420 'speedbar-tag-face
2421 (1+ level)))
2422 ((speedbar-generic-list-positioned-group-p (car lst))
2423 (speedbar-make-tag-line expand-button
2424 ?+ expand-fun (cdr (cdr (car lst)))
2425 (car (car lst)) ;button name
2426 find-fun ;function
2427 (car (cdr (car lst))) ;token is posn
2428 'speedbar-tag-face
2429 (1+ level)))
2430 ((speedbar-generic-list-group-p (car lst))
2431 (speedbar-make-tag-line expand-button
2432 ?+ expand-fun (cdr (car lst))
2433 (car (car lst)) ;button name
2434 nil nil 'speedbar-tag-face
2435 (1+ level)))
2436 (t (speedbar-message "speedbar-insert-generic-list: malformed list!")
2438 (setq lst (cdr lst)))))
2440 (defun speedbar-insert-imenu-list (indent lst)
2441 "At level INDENT, insert the imenu generated LST."
2442 (speedbar-insert-generic-list indent lst
2443 'speedbar-tag-expand
2444 'speedbar-tag-find))
2446 (defun speedbar-insert-etags-list (indent lst)
2447 "At level INDENT, insert the etags generated LST."
2448 (speedbar-insert-generic-list indent lst
2449 'speedbar-tag-expand
2450 'speedbar-tag-find))
2452 ;;; Timed functions
2454 (defun speedbar-update-contents ()
2455 "Generically update the contents of the speedbar buffer."
2456 (interactive)
2457 ;; Set the current special buffer
2458 (setq speedbar-desired-buffer nil)
2460 ;; Check for special modes
2461 (speedbar-maybe-add-localized-support (current-buffer))
2463 ;; Choose the correct method of doodling.
2464 (if (and speedbar-mode-specific-contents-flag
2465 (consp speedbar-special-mode-expansion-list)
2466 (local-variable-p
2467 'speedbar-special-mode-expansion-list
2468 (current-buffer)))
2469 ;;(eq (get major-mode 'mode-class 'special)))
2470 (speedbar-update-special-contents)
2471 (speedbar-update-directory-contents)))
2473 (defun speedbar-update-localized-contents ()
2474 "Update the contents of the speedbar buffer for the current situation."
2475 ;; Due to the historical growth of speedbar, we need to do something
2476 ;; special for "files" mode. Too bad.
2477 (let ((name speedbar-initial-expansion-list-name)
2478 (funclst (speedbar-initial-expansion-list))
2480 (if (string= name "files")
2481 ;; Do all the files type work. It still goes through the
2482 ;; expansion list stuff. :(
2483 (if (or (member (expand-file-name default-directory)
2484 speedbar-shown-directories)
2485 (and speedbar-ignored-directory-regexp
2486 (string-match
2487 speedbar-ignored-directory-regexp
2488 (expand-file-name default-directory))))
2490 (if (<= 1 speedbar-verbosity-level)
2491 (speedbar-message "Updating speedbar to: %s..."
2492 default-directory))
2493 (speedbar-update-directory-contents)
2494 (if (<= 1 speedbar-verbosity-level)
2495 (progn
2496 (speedbar-message "Updating speedbar to: %s...done"
2497 default-directory)
2498 (speedbar-message nil))))
2499 ;; Else, we can do a short cut. No text cache.
2500 (let ((cbd (expand-file-name default-directory)))
2501 (set-buffer speedbar-buffer)
2502 (speedbar-with-writable
2503 (let* ((window (get-buffer-window speedbar-buffer 0))
2504 (p (window-point window))
2505 (start (window-start window)))
2506 (erase-buffer)
2507 (dolist (func funclst)
2508 (setq default-directory cbd)
2509 (funcall func cbd 0))
2510 (speedbar-reconfigure-keymaps)
2511 (set-window-point window p)
2512 (set-window-start window start)))))))
2514 (defun speedbar-update-directory-contents ()
2515 "Update the contents of the speedbar buffer based on the current directory."
2516 (let ((cbd (expand-file-name default-directory))
2517 cbd-parent
2518 (funclst (speedbar-initial-expansion-list))
2519 (cache speedbar-full-text-cache)
2520 ;; disable stealth during update
2521 (speedbar-stealthy-function-list nil)
2522 (use-cache nil)
2523 (expand-local nil)
2524 ;; Because there is a bug I can't find just yet
2525 (inhibit-quit nil))
2526 (set-buffer speedbar-buffer)
2527 ;; If we are updating contents to where we are, then this is
2528 ;; really a request to update existing contents, so we must be
2529 ;; careful with our text cache!
2530 (if (member cbd speedbar-shown-directories)
2531 (progn
2532 (setq cache nil)
2533 ;; If the current directory is not the last element in the dir
2534 ;; list, then we ALSO need to zap the list of expanded directories
2535 (if (/= (length (member cbd speedbar-shown-directories)) 1)
2536 (setq speedbar-shown-directories (list cbd))))
2538 ;; Build cbd-parent, and see if THAT is in the current shown
2539 ;; directories. First, go through pains to get the parent directory
2540 (if (and speedbar-smart-directory-expand-flag
2541 (save-match-data
2542 (setq cbd-parent cbd)
2543 (if (string-match "[/\\]$" cbd-parent)
2544 (setq cbd-parent (substring cbd-parent 0
2545 (match-beginning 0))))
2546 (setq cbd-parent (file-name-directory cbd-parent)))
2547 (member cbd-parent speedbar-shown-directories))
2548 (setq expand-local t)
2550 ;; If this directory is NOT in the current list of available
2551 ;; directories, then use the cache, and set the cache to our new
2552 ;; value. Make sure to unhighlight the current file, or if we
2553 ;; come back to this directory, it might be a different file
2554 ;; and then we get a mess!
2555 (if (> (point-max) 1)
2556 (progn
2557 (speedbar-clear-current-file)
2558 (setq speedbar-full-text-cache
2559 (cons speedbar-shown-directories (buffer-string)))))
2561 ;; Check if our new directory is in the list of directories
2562 ;; shown in the text-cache
2563 (if (member cbd (car cache))
2564 (setq speedbar-shown-directories (car cache)
2565 use-cache t)
2566 ;; default the shown directories to this list...
2567 (setq speedbar-shown-directories (list cbd)))
2569 (if (not expand-local) (setq speedbar-last-selected-file nil))
2570 (speedbar-with-writable
2571 (if (and expand-local
2572 ;; Find this directory as a speedbar node.
2573 (speedbar-directory-line cbd))
2574 ;; Open it.
2575 (speedbar-expand-line)
2576 (let* ((window (get-buffer-window speedbar-buffer 0))
2577 (p (window-point window))
2578 (start (window-start window)))
2579 (erase-buffer)
2580 (cond (use-cache
2581 (setq default-directory
2582 (nth (1- (length speedbar-shown-directories))
2583 speedbar-shown-directories))
2584 (insert (cdr cache)))
2586 (dolist (func funclst)
2587 (setq default-directory cbd)
2588 (funcall func cbd 0))))
2589 (set-window-point window p)
2590 (set-window-start window start)))))
2591 (speedbar-reconfigure-keymaps))
2593 (defun speedbar-update-special-contents ()
2594 "Use the mode-specific variable to fill in the speedbar buffer.
2595 This should only be used by modes classified as special."
2596 (let ((funclst speedbar-special-mode-expansion-list)
2597 (specialbuff (current-buffer)))
2598 (setq speedbar-desired-buffer specialbuff)
2599 (with-current-buffer speedbar-buffer
2600 ;; If we are leaving a directory, cache it.
2601 (if (not speedbar-shown-directories)
2602 ;; Do nothing
2604 ;; Clean up directory maintenance stuff
2605 (speedbar-clear-current-file)
2606 (setq speedbar-full-text-cache
2607 (cons speedbar-shown-directories (buffer-string))
2608 speedbar-shown-directories nil))
2609 ;; Now fill in the buffer with our newly found specialized list.
2610 (speedbar-with-writable
2611 (dolist (func funclst)
2612 ;; We do not erase the buffer because these functions may
2613 ;; decide NOT to update themselves.
2614 (funcall func specialbuff)))))
2615 (speedbar-reconfigure-keymaps))
2617 (defun speedbar-set-timer (timeout)
2618 "Set up the speedbar timer with TIMEOUT.
2619 Uses `dframe-set-timer'.
2620 Also resets scanner functions."
2621 (dframe-set-timer timeout 'speedbar-timer-fn 'speedbar-update-flag)
2622 ;; Apply a revert hook that will reset the scanners. We attach to revert
2623 ;; because most reverts occur during VC state change, and this lets our
2624 ;; VC scanner fix itself.
2625 (if timeout
2626 (add-hook 'after-revert-hook 'speedbar-reset-scanners)
2627 (remove-hook 'after-revert-hook 'speedbar-reset-scanners))
2628 ;; change this if it changed for some reason
2629 (speedbar-set-mode-line-format))
2631 (defun speedbar-timer-fn ()
2632 "Run whenever Emacs is idle to update the speedbar item."
2633 (if (or (not (speedbar-current-frame))
2634 (not (frame-live-p (speedbar-current-frame))))
2635 (speedbar-set-timer nil)
2636 ;; Save all the match data so that we don't mess up executing fns
2637 (save-match-data
2638 ;; Only do stuff if the frame is visible, not an icon, and if
2639 ;; it is currently flagged to do something.
2640 (if (and speedbar-update-flag
2641 (speedbar-current-frame)
2642 (frame-visible-p (speedbar-current-frame))
2643 (not (eq (frame-visible-p (speedbar-current-frame)) 'icon)))
2644 (let ((af (selected-frame)))
2645 (dframe-select-attached-frame speedbar-frame)
2646 ;; make sure we at least choose a window to
2647 ;; get a good directory from
2648 (if (window-minibuffer-p (selected-window))
2650 ;; Check for special modes
2651 (speedbar-maybe-add-localized-support (current-buffer))
2652 ;; Update for special mode all the time!
2653 (if (and speedbar-mode-specific-contents-flag
2654 (consp speedbar-special-mode-expansion-list)
2655 (local-variable-p
2656 'speedbar-special-mode-expansion-list
2657 (current-buffer)))
2658 ;;(eq (get major-mode 'mode-class 'special)))
2659 (progn
2660 (if (<= 2 speedbar-verbosity-level)
2661 (speedbar-message
2662 "Updating speedbar to special mode: %s..."
2663 major-mode))
2664 (speedbar-update-special-contents)
2665 (if (<= 2 speedbar-verbosity-level)
2666 (progn
2667 (speedbar-message
2668 "Updating speedbar to special mode: %s...done"
2669 major-mode)
2670 (speedbar-message nil))))
2672 ;; Update all the contents if directories change!
2673 (unless (and (or (member major-mode speedbar-ignored-modes)
2674 (eq af (speedbar-current-frame))
2675 (not (buffer-file-name)))
2676 ;; Always update for GUD.
2677 (not (string-equal "GUD"
2678 speedbar-initial-expansion-list-name)))
2679 (speedbar-update-localized-contents)))
2680 (select-frame af))
2681 ;; Now run stealthy updates of time-consuming items
2682 (speedbar-stealthy-updates)))))
2683 (run-hooks 'speedbar-timer-hook))
2686 ;;; Stealthy activities
2688 (defvar speedbar-stealthy-update-recurse nil
2689 "Recursion avoidance variable for stealthy update.")
2691 (defun speedbar-stealthy-updates ()
2692 "For a given speedbar, run all items in the stealthy function list.
2693 Each item returns t if it completes successfully, or nil if
2694 interrupted by the user."
2695 (if (not speedbar-stealthy-update-recurse)
2696 (let ((l (speedbar-initial-stealthy-functions))
2697 (speedbar-stealthy-update-recurse t))
2698 (unwind-protect
2699 (speedbar-with-writable
2700 (while (and l (funcall (car l)))
2701 ;;(sit-for 0)
2702 (setq l (cdr l))))
2703 ;;(speedbar-message "Exit with %S" (car l))
2704 ))))
2706 (defun speedbar-reset-scanners ()
2707 "Reset any variables used by functions in the stealthy list as state.
2708 If new functions are added, their state needs to be updated here."
2709 (setq speedbar-vc-to-do-point t
2710 speedbar-obj-to-do-point t
2711 speedbar-ro-to-do-point t)
2712 (run-hooks 'speedbar-scanner-reset-hook)
2715 (defun speedbar-find-selected-file (file)
2716 "Go to the line where FILE is."
2718 (set-buffer speedbar-buffer)
2720 (goto-char (point-min))
2721 (let ((m nil))
2722 (while (and (setq m (re-search-forward
2723 (concat " \\(" (regexp-quote (file-name-nondirectory file))
2724 "\\)\\(" speedbar-indicator-regex "\\)?\n")
2725 nil t))
2726 (not (string= file
2727 (concat
2728 (speedbar-line-directory
2729 (save-excursion
2730 (goto-char (match-beginning 0))
2731 (beginning-of-line)
2732 (save-match-data
2733 (looking-at "[0-9]+:")
2734 (string-to-number (match-string 0)))))
2735 (match-string 1))))))
2736 (if m
2737 (progn
2738 (goto-char (match-beginning 1))
2739 (match-string 1)))))
2741 (defun speedbar-clear-current-file ()
2742 "Locate the file thought to be current, and remove its highlighting."
2743 (save-excursion
2744 ;;(set-buffer speedbar-buffer)
2745 (if speedbar-last-selected-file
2746 (speedbar-with-writable
2747 (if (speedbar-find-selected-file speedbar-last-selected-file)
2748 (put-text-property (match-beginning 1)
2749 (match-end 1)
2750 'face
2751 'speedbar-file-face))))))
2753 (defun speedbar-update-current-file ()
2754 "Find the current file, and update our visuals to indicate its name.
2755 This is specific to file names. If the file name doesn't show up, but
2756 it should be in the list, then the directory cache needs to be updated."
2757 (let* ((lastf (selected-frame))
2758 (newcfd (save-excursion
2759 (dframe-select-attached-frame speedbar-frame)
2760 (let ((rf (if (buffer-file-name)
2761 (buffer-file-name)
2762 nil)))
2763 (select-frame lastf)
2764 rf)))
2765 (newcf (if newcfd newcfd))
2766 (lastb (current-buffer))
2767 (sucf-recursive (boundp 'sucf-recursive))
2768 (case-fold-search t))
2769 (if (and newcf
2770 ;; check here, that way we won't refresh to newcf until
2771 ;; its been written, thus saving ourselves some time
2772 (file-exists-p newcf)
2773 (not (string= newcf speedbar-last-selected-file)))
2774 (progn
2775 ;; It is important to select the frame, otherwise the window
2776 ;; we want the cursor to move in will not be updated by the
2777 ;; search-forward command.
2778 (select-frame (speedbar-current-frame))
2779 ;; Remove the old file...
2780 (speedbar-clear-current-file)
2781 ;; now highlight the new one.
2782 ;; (set-buffer speedbar-buffer)
2783 (speedbar-with-writable
2784 (if (speedbar-find-selected-file newcf)
2785 ;; put the property on it
2786 (put-text-property (match-beginning 1)
2787 (match-end 1)
2788 'face
2789 'speedbar-selected-face)
2790 ;; Oops, it's not in the list. Should it be?
2791 (if (and (string-match speedbar-file-regexp newcf)
2792 (string= (file-name-directory newcfd)
2793 (expand-file-name default-directory)))
2794 ;; yes, it is (we will ignore unknowns for now...)
2795 (progn
2796 (speedbar-refresh)
2797 (if (speedbar-find-selected-file newcf)
2798 ;; put the property on it
2799 (put-text-property (match-beginning 1)
2800 (match-end 1)
2801 'face
2802 'speedbar-selected-face)))
2803 ;; if it's not in there now, whatever...
2805 (setq speedbar-last-selected-file newcf))
2806 (if (not sucf-recursive)
2807 (progn
2809 ;;Sat Dec 15 2001 12:40 AM (burton@openprivacy.org): this
2810 ;;doesn't need to be in. We don't want to recenter when we are
2811 ;;updating files.
2813 ;;(speedbar-center-buffer-smartly)
2815 (speedbar-position-cursor-on-line)
2817 (set-buffer lastb)
2818 (select-frame lastf)
2820 ;; return that we are done with this activity.
2823 (defun speedbar-add-indicator (indicator-string &optional replace-this)
2824 "Add INDICATOR-STRING to the end of this speedbar line.
2825 If INDICATOR-STRING is space, and REPLACE-THIS is a character,
2826 then the existing indicator is removed. If there is already an
2827 indicator, then do not add a space."
2828 (beginning-of-line)
2829 ;; The nature of the beast: Assume we are in "the right place"
2830 (end-of-line)
2831 (skip-chars-backward (concat " " speedbar-vc-indicator
2832 speedbar-object-read-only-indicator
2833 (car speedbar-obj-indicator)
2834 (cdr speedbar-obj-indicator)))
2835 (if (and (not (looking-at speedbar-indicator-regex))
2836 (not (string= indicator-string " ")))
2837 (insert speedbar-indicator-separator))
2838 (speedbar-with-writable
2839 (save-excursion
2840 (if (and replace-this
2841 (re-search-forward replace-this (line-end-position) t))
2842 (delete-region (match-beginning 0) (match-end 0))))
2843 (end-of-line)
2844 (if (not (string= " " indicator-string))
2845 (let ((start (point)))
2846 (insert indicator-string)
2847 (speedbar-insert-image-button-maybe start (length indicator-string))
2848 ))))
2850 (defun speedbar-check-read-only ()
2851 "Scan all the files in a directory, and for each see if it is read only."
2852 ;; Check for to-do to be reset. If reset but no RCS is available
2853 ;; then set to nil (do nothing) otherwise, start at the beginning
2854 (save-excursion
2855 (if speedbar-buffer (set-buffer speedbar-buffer))
2856 (if (eq speedbar-ro-to-do-point t)
2857 (setq speedbar-ro-to-do-point 0))
2858 (if (numberp speedbar-ro-to-do-point)
2859 (progn
2860 (goto-char speedbar-ro-to-do-point)
2861 (while (and (not (input-pending-p))
2862 (re-search-forward "^\\([0-9]+\\):\\s-*[[<][+-\?][]>] "
2863 nil t))
2864 (setq speedbar-ro-to-do-point (point))
2865 (let ((f (speedbar-line-file)))
2866 (if f
2867 (if (not (file-writable-p f))
2868 (speedbar-add-indicator
2869 speedbar-object-read-only-indicator
2870 (regexp-quote speedbar-object-read-only-indicator))
2871 (speedbar-add-indicator
2872 " " (regexp-quote
2873 speedbar-object-read-only-indicator))))))
2874 (if (input-pending-p)
2875 ;; return that we are incomplete
2877 ;; we are done, set to-do to nil
2878 (setq speedbar-ro-to-do-point nil)
2879 ;; and return t
2881 t)))
2883 (defun speedbar-check-vc ()
2884 "Scan all files in a directory, and for each see if it's checked out.
2885 See `speedbar-this-file-in-vc' and `speedbar-vc-check-dir-p' for how
2886 to add more types of version control systems."
2887 ;; Check for to-do to be reset. If reset but no RCS is available
2888 ;; then set to nil (do nothing) otherwise, start at the beginning
2889 (save-excursion
2890 (if speedbar-buffer (set-buffer speedbar-buffer))
2891 (if (and speedbar-vc-do-check (eq speedbar-vc-to-do-point t)
2892 (speedbar-vc-check-dir-p default-directory)
2893 (not (or (and (featurep 'ange-ftp)
2894 (string-match
2895 (car (symbol-value
2896 (if (featurep 'xemacs)
2897 'ange-ftp-directory-format
2898 'ange-ftp-name-format)))
2899 (expand-file-name default-directory)))
2900 ;; efs support: Bob Weiner
2901 (and (featurep 'efs)
2902 (string-match
2903 (let ((reg (symbol-value 'efs-directory-regexp)))
2904 (if (stringp reg)
2906 (car reg)))
2907 (expand-file-name default-directory))))))
2908 (setq speedbar-vc-to-do-point 0))
2909 (if (numberp speedbar-vc-to-do-point)
2910 (progn
2911 (goto-char speedbar-vc-to-do-point)
2912 (while (and (not (input-pending-p))
2913 (re-search-forward "^\\([0-9]+\\):\\s-*\\[[+-?]\\] "
2914 nil t))
2915 (setq speedbar-vc-to-do-point (point))
2916 (if (speedbar-check-vc-this-line (match-string 1))
2917 (speedbar-add-indicator speedbar-vc-indicator
2918 (regexp-quote speedbar-vc-indicator))
2919 (speedbar-add-indicator " "
2920 (regexp-quote speedbar-vc-indicator))))
2921 (if (input-pending-p)
2922 ;; return that we are incomplete
2924 ;; we are done, set to-do to nil
2925 (setq speedbar-vc-to-do-point nil)
2926 ;; and return t
2928 t)))
2930 (defun speedbar-check-vc-this-line (depth)
2931 "Return t if the file on this line is checked out of a version control system.
2932 Parameter DEPTH is a string with the current depth of indentation of
2933 the file being checked."
2934 (let* ((d (string-to-number depth))
2935 (f (speedbar-line-directory d))
2936 (fn (buffer-substring-no-properties
2937 ;; Skip-chars: thanks ptype@dra.hmg.gb
2938 (point) (progn
2939 (skip-chars-forward "^ " (line-end-position))
2940 (point))))
2941 (fulln (concat f fn)))
2942 (if (<= 2 speedbar-verbosity-level)
2943 (speedbar-message "Speedbar vc check...%s" fulln))
2944 (and (file-writable-p fulln)
2945 (speedbar-this-file-in-vc f fn))))
2947 (defun speedbar-vc-check-dir-p (directory)
2948 "Return t if we should bother checking DIRECTORY for version control files.
2949 This can be overloaded to add new types of version control systems."
2951 (catch t (dolist (vcd vc-directory-exclusion-list)
2952 (if (file-exists-p (concat directory vcd)) (throw t t))) nil)
2953 ;; User extension
2954 (run-hook-with-args-until-success 'speedbar-vc-directory-enable-hook
2955 directory)
2958 (defun speedbar-this-file-in-vc (directory name)
2959 "Check to see if the file in DIRECTORY with NAME is in a version control system.
2960 Automatically recognizes all VCs supported by VC mode. You can
2961 optimize this function by overriding it and only doing those checks
2962 that will occur on your system."
2964 (vc-backend (concat directory "/" name))
2965 ;; User extension
2966 (run-hook-with-args 'speedbar-vc-in-control-hook directory name)
2969 ;; Objet File scanning
2970 (defun speedbar-check-objects ()
2971 "Scan all files in a directory, and for each see if there is an object.
2972 See `speedbar-check-obj-this-line' and `speedbar-obj-alist' for how
2973 to add more object types."
2974 ;; Check for to-do to be reset. If reset but no RCS is available
2975 ;; then set to nil (do nothing) otherwise, start at the beginning
2976 (save-excursion
2977 (if speedbar-buffer (set-buffer speedbar-buffer))
2978 (if (and speedbar-obj-do-check (eq speedbar-obj-to-do-point t))
2979 (setq speedbar-obj-to-do-point 0))
2980 (if (numberp speedbar-obj-to-do-point)
2981 (progn
2982 (goto-char speedbar-obj-to-do-point)
2983 (while (and (not (input-pending-p))
2984 (re-search-forward "^\\([0-9]+\\):\\s-*\\[[+-]\\] "
2985 nil t))
2986 (setq speedbar-obj-to-do-point (point))
2987 (let ((ind (speedbar-check-obj-this-line (match-string 1))))
2988 (if (not ind) (setq ind " "))
2989 (speedbar-add-indicator ind (concat
2990 (car speedbar-obj-indicator)
2991 "\\|"
2992 (cdr speedbar-obj-indicator)))))
2993 (if (input-pending-p)
2994 ;; return that we are incomplete
2996 ;; we are done, set to-do to nil
2997 (setq speedbar-obj-to-do-point nil)
2998 ;; and return t
3000 t)))
3002 (defun speedbar-check-obj-this-line (depth)
3003 "Return t if the file on this line has an associated object.
3004 Parameter DEPTH is a string with the current depth of indentation of
3005 the file being checked."
3006 (let* ((d (string-to-number depth))
3007 (f (speedbar-line-directory d))
3008 (fn (buffer-substring-no-properties
3009 ;; Skip-chars: thanks ptype@dra.hmg.gb
3010 (point) (progn
3011 (skip-chars-forward "^ " (line-end-position))
3012 (point))))
3013 (fulln (concat f fn)))
3014 (if (<= 2 speedbar-verbosity-level)
3015 (speedbar-message "Speedbar obj check...%s" fulln))
3016 (let ((oa speedbar-obj-alist))
3017 (while (and oa (not (string-match (car (car oa)) fulln)))
3018 (setq oa (cdr oa)))
3019 (if (not (and oa (file-exists-p (concat (file-name-sans-extension fulln)
3020 (cdr (car oa))))))
3022 ;; Find out if the object is out of date or not.
3023 (let ((date1 (nth 5 (file-attributes fulln)))
3024 (date2 (nth 5 (file-attributes (concat
3025 (file-name-sans-extension fulln)
3026 (cdr (car oa)))))))
3027 (if (or (< (car date1) (car date2))
3028 (and (= (car date1) (car date2))
3029 (< (nth 1 date1) (nth 1 date2))))
3030 (car speedbar-obj-indicator)
3031 (cdr speedbar-obj-indicator)))))))
3033 ;;; Clicking Activity
3035 (defun speedbar-position-cursor-on-line ()
3036 "Position the cursor on a line."
3037 (let ((oldpos (point)))
3038 (beginning-of-line)
3039 (if (looking-at "[0-9]+:\\s-*..?.? ")
3040 (goto-char (1- (match-end 0)))
3041 (goto-char oldpos))))
3043 (defun speedbar-click (e)
3044 "Activate any speedbar buttons where the mouse is clicked.
3045 This must be bound to a mouse event. A button is any location of text
3046 with a mouse face that has a text property called `speedbar-function'.
3047 Argument E is the click event."
3048 ;; Backward compatibility let statement.
3049 (let ((speedbar-power-click dframe-power-click))
3050 (speedbar-do-function-pointer))
3051 (dframe-quick-mouse e))
3053 (defun speedbar-do-function-pointer ()
3054 "Look under the cursor and examine the text properties.
3055 From this extract the file/tag name, token, indentation level and call
3056 a function if appropriate."
3057 (let* ((speedbar-frame (speedbar-current-frame))
3058 (fn (get-text-property (point) 'speedbar-function))
3059 (tok (get-text-property (point) 'speedbar-token))
3060 ;; The 1-,+ is safe because scaning starts AFTER the point
3061 ;; specified. This lets the search include the character the
3062 ;; cursor is on.
3063 (tp (previous-single-property-change
3064 (1+ (point)) 'speedbar-function))
3065 (np (next-single-property-change
3066 (point) 'speedbar-function))
3067 (txt (buffer-substring-no-properties (or tp (point-min))
3068 (or np (point-max))))
3069 (dent (save-excursion (beginning-of-line)
3070 (string-to-number
3071 (if (looking-at "[0-9]+")
3072 (buffer-substring-no-properties
3073 (match-beginning 0) (match-end 0))
3074 "0")))))
3075 ;;(speedbar-message "%S:%S:%S:%s" fn tok txt dent)
3076 (and fn (funcall fn txt tok dent)))
3077 (speedbar-position-cursor-on-line))
3079 ;;; Reading info from the speedbar buffer
3081 (defun speedbar-line-text (&optional p)
3082 "Retrieve the text after prefix junk for the current line.
3083 Optional argument P is where to start the search from."
3084 (save-excursion
3085 (if p (goto-char p))
3086 (beginning-of-line)
3087 (if (looking-at (concat
3088 "\\([0-9]+\\): *[[<{]?[-+?= ][]>}@()|] \\([^ \n]+\\)"))
3089 (get-text-property (match-beginning 2) 'speedbar-text)
3090 nil)))
3092 (defun speedbar-line-token (&optional p)
3093 "Retrieve the token information after the prefix junk for the current line.
3094 Optional argument P is where to start the search from."
3095 (save-excursion
3096 (if p (goto-char p))
3097 (beginning-of-line)
3098 (if (looking-at (concat
3099 "\\([0-9]+\\): *[[<{]?[-+?= ][]>}@()|] \\([^ \n]+\\)\\("
3100 speedbar-indicator-regex "\\)?"))
3101 (progn
3102 (goto-char (match-beginning 2))
3103 (get-text-property (point) 'speedbar-token))
3104 nil)))
3106 (defun speedbar-line-file (&optional p)
3107 "Retrieve the file or whatever from the line at point P.
3108 The return value is a string representing the file. If it is a
3109 directory, then it is the directory name."
3110 (save-match-data
3111 (save-restriction
3112 (widen)
3113 (let ((f (speedbar-line-text p)))
3114 (if f
3115 (let* ((depth (string-to-number (match-string 1)))
3116 (directory (speedbar-line-directory depth)))
3117 (if (file-exists-p (concat directory f))
3118 (concat directory f)
3119 nil))
3120 nil)))))
3122 (defun speedbar-goto-this-file (file)
3123 "If FILE is displayed, go to this line and return t.
3124 Otherwise do not move and return nil."
3125 (let ((directory (substring (file-name-directory (expand-file-name file))
3126 (length (expand-file-name default-directory))))
3127 (dest (point)))
3128 (save-match-data
3129 (goto-char (point-min))
3130 ;; scan all the directories
3131 (while (and directory (not (eq directory t)))
3132 (if (string-match "^[/\\]?\\([^/\\]+\\)" directory)
3133 (let ((pp (match-string 1 directory)))
3134 (if (save-match-data
3135 (re-search-forward (concat "> " (regexp-quote pp) "$")
3136 nil t))
3137 (setq directory (substring directory (match-end 1)))
3138 (setq directory nil)))
3139 (setq directory t)))
3140 ;; find the file part
3141 (if (or (not directory) (string= (file-name-nondirectory file) ""))
3142 ;; only had a dir part
3143 (if directory
3144 (progn
3145 (speedbar-position-cursor-on-line)
3147 (goto-char dest) nil)
3148 ;; find the file part
3149 (let ((nd (file-name-nondirectory file)))
3150 (if (re-search-forward
3151 (concat "] \\(" (regexp-quote nd)
3152 "\\)\\(" speedbar-indicator-regex "\\)$")
3153 nil t)
3154 (progn
3155 (speedbar-position-cursor-on-line)
3157 (goto-char dest)
3158 nil))))))
3160 (defun speedbar-line-directory (&optional depth)
3161 "Retrieve the directory name associated with the current line.
3162 This may require traversing backwards from DEPTH and combining the default
3163 directory with these items. This function is replaceable in
3164 `speedbar-mode-functions-list' as `speedbar-line-directory'."
3165 (save-restriction
3166 (widen)
3167 (let ((rf (speedbar-fetch-replacement-function 'speedbar-line-directory)))
3168 (if rf (funcall rf depth) default-directory))))
3170 (defun speedbar-files-line-directory (&optional depth)
3171 "Retrieve the directory associated with the current line.
3172 This may require traversing backwards from DEPTH and combining the default
3173 directory with these items."
3174 (save-excursion
3175 (save-match-data
3176 (if (not depth)
3177 (progn
3178 (beginning-of-line)
3179 (looking-at "^\\([0-9]+\\):")
3180 (setq depth (string-to-number (match-string 1)))))
3181 (let ((directory nil))
3182 (setq depth (1- depth))
3183 (while (/= depth -1)
3184 (if (not (re-search-backward (format "^%d:" depth) nil t))
3185 (error "Error building filename of tag")
3186 (cond ((looking-at "[0-9]+:\\s-*<->\\s-+\\([^\n]+\\)")
3187 (setq directory (concat (speedbar-line-text)
3189 directory)))
3190 ((looking-at "[0-9]+:\\s-*[-]\\s-+\\([^\n]+\\)")
3191 ;; This is the start of our directory.
3192 (setq directory (speedbar-line-text)))))
3193 (setq depth (1- depth)))
3194 (if (and directory
3195 (string-match (concat speedbar-indicator-regex "$")
3196 directory))
3197 (setq directory (substring directory 0 (match-beginning 0))))
3198 (concat default-directory directory)))))
3200 (defun speedbar-directory-line (directory)
3201 "Position the cursor on the line specified by DIRECTORY."
3202 (save-match-data
3203 (if (string-match "[/\\]$" directory)
3204 (setq directory (substring directory 0 (match-beginning 0))))
3205 (let ((nomatch t) (depth 0)
3206 (fname (file-name-nondirectory directory))
3207 (pname (file-name-directory directory)))
3208 (if (not (member pname speedbar-shown-directories))
3209 (error "Internal Error: File %s not shown in speedbar" directory))
3210 (goto-char (point-min))
3211 (while (and nomatch
3212 (re-search-forward
3213 (concat "[]>] \\(" (regexp-quote fname)
3214 "\\)\\(" speedbar-indicator-regex "\\)?$")
3215 nil t))
3216 (beginning-of-line)
3217 (looking-at "\\([0-9]+\\):")
3218 (setq depth (string-to-number (match-string 0))
3219 nomatch (not (string= pname (speedbar-line-directory depth))))
3220 (end-of-line))
3221 (beginning-of-line)
3222 (not nomatch))))
3224 (defun speedbar-edit-line ()
3225 "Edit whatever tag or file is on the current speedbar line."
3226 (interactive)
3227 (or (save-excursion
3228 (beginning-of-line)
3229 ;; If this fails, then it is a non-standard click, and as such,
3230 ;; perfectly allowed.
3231 (if (re-search-forward "[]>?}] [^ ]"
3232 (line-end-position)
3234 (progn
3235 (forward-char -1)
3236 (speedbar-do-function-pointer))
3237 nil))
3238 (speedbar-do-function-pointer)))
3240 (defun speedbar-expand-line (&optional arg)
3241 "Expand the line under the cursor.
3242 With universal argument ARG, flush cached data."
3243 (interactive "P")
3244 (beginning-of-line)
3245 (let* ((dframe-power-click arg)
3246 (speedbar-power-click arg))
3247 (condition-case nil
3248 (progn
3249 (re-search-forward ":\\s-*.\\+. "
3250 (line-end-position))
3251 (forward-char -2)
3252 (speedbar-do-function-pointer))
3253 (error (speedbar-position-cursor-on-line)))))
3255 (defun speedbar-flush-expand-line ()
3256 "Expand the line under the cursor and flush any cached information."
3257 (interactive)
3258 (speedbar-expand-line 1))
3260 (defun speedbar-contract-line ()
3261 "Contract the line under the cursor."
3262 (interactive)
3263 (beginning-of-line)
3264 (condition-case nil
3265 (progn
3266 (re-search-forward ":\\s-*.-. "
3267 (line-end-position))
3268 (forward-char -2)
3269 (speedbar-do-function-pointer))
3270 (error (speedbar-position-cursor-on-line))))
3272 (defun speedbar-toggle-line-expansion ()
3273 "Contract or expand the line under the cursor."
3274 (interactive)
3275 (beginning-of-line)
3276 (condition-case nil
3277 (progn
3278 (re-search-forward ":\\s-*.[-+]. "
3279 (line-end-position))
3280 (forward-char -2)
3281 (speedbar-do-function-pointer))
3282 (error (speedbar-position-cursor-on-line))))
3284 (defun speedbar-expand-line-descendants (&optional arg)
3285 "Expand the line under the cursor and all descendants.
3286 Optional argument ARG indicates that any cache should be flushed."
3287 (interactive "P")
3288 (speedbar-expand-line arg)
3289 ;; Now, inside the area expaded here, expand all subnodes of
3290 ;; the same descendant type.
3291 (save-excursion
3292 (speedbar-next 1) ;; Move into the list.
3293 (let ((err nil))
3294 (while (not err)
3295 (condition-case nil
3296 (progn
3297 (speedbar-expand-line-descendants arg)
3298 (speedbar-restricted-next 1))
3299 (error (setq err t))))))
3302 (defun speedbar-contract-line-descendants ()
3303 "Expand the line under the cursor and all descendants."
3304 (interactive)
3305 (speedbar-contract-line)
3306 ;; Don't need to do anything else since all descendants are
3307 ;; hidden by default anyway. Yay! It's easy.
3310 (defun speedbar-find-file (text token indent)
3311 "Speedbar click handler for filenames.
3312 TEXT, the file will be displayed in the attached frame.
3313 TOKEN is unused, but required by the click handler. INDENT is the
3314 current indentation level."
3315 (let ((cdd (speedbar-line-directory indent)))
3316 ;; Run before visiting file hook here.
3317 (let ((f (selected-frame)))
3318 (dframe-select-attached-frame speedbar-frame)
3319 (run-hooks 'speedbar-before-visiting-file-hook)
3320 (select-frame f))
3321 (speedbar-find-file-in-frame (concat cdd text))
3322 (speedbar-stealthy-updates)
3323 (run-hooks 'speedbar-visiting-file-hook)
3324 ;; Reset the timer with a new timeout when cliking a file
3325 ;; in case the user was navigating directories, we can cancel
3326 ;; that other timer.
3327 (speedbar-set-timer dframe-update-speed))
3328 (dframe-maybee-jump-to-attached-frame))
3330 (defun speedbar-dir-follow (text token indent)
3331 "Speedbar click handler for directory names.
3332 Clicking a directory will cause the speedbar to list files in
3333 the subdirectory TEXT. TOKEN is an unused requirement. The
3334 subdirectory chosen will be at INDENT level."
3335 (setq default-directory
3336 (concat (expand-file-name (concat (speedbar-line-directory indent) text))
3337 "/"))
3338 ;; Because we leave speedbar as the current buffer,
3339 ;; update contents will change directory without
3340 ;; having to touch the attached frame. Turn off smart expand just
3341 ;; in case.
3342 (let ((speedbar-smart-directory-expand-flag nil))
3343 (speedbar-update-contents))
3344 (speedbar-set-timer speedbar-navigating-speed)
3345 (setq speedbar-last-selected-file nil)
3346 (speedbar-stealthy-updates))
3348 (defun speedbar-delete-subblock (indent)
3349 "Delete text from point to indentation level INDENT or greater.
3350 Handles end-of-sublist smartly."
3351 (speedbar-with-writable
3352 (save-excursion
3353 (end-of-line) (forward-char 1)
3354 (let ((start (point)))
3355 (while (and (looking-at "^\\([0-9]+\\):")
3356 (> (string-to-number (match-string 1)) indent)
3357 (not (eobp)))
3358 (forward-line 1)
3359 (beginning-of-line))
3360 (delete-region start (point))))))
3362 (defun speedbar-dired (text token indent)
3363 "Speedbar click handler for directory expand button.
3364 Clicking this button expands or contracts a directory. TEXT is the
3365 button clicked which has either a + or -. TOKEN is the directory to be
3366 expanded. INDENT is the current indentation level."
3367 (cond ((string-match "+" text) ;we have to expand this dir
3368 (setq speedbar-shown-directories
3369 (cons (expand-file-name
3370 (concat (speedbar-line-directory indent) token "/"))
3371 speedbar-shown-directories))
3372 (speedbar-change-expand-button-char ?-)
3373 (speedbar-reset-scanners)
3374 (save-excursion
3375 (end-of-line) (forward-char 1)
3376 (speedbar-with-writable
3377 (speedbar-default-directory-list
3378 (concat (speedbar-line-directory indent) token "/")
3379 (1+ indent)))))
3380 ((string-match "-" text) ;we have to contract this node
3381 (speedbar-reset-scanners)
3382 (let ((oldl speedbar-shown-directories)
3383 (newl nil)
3384 (td (expand-file-name
3385 (concat (speedbar-line-directory indent) token))))
3386 (while oldl
3387 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
3388 (setq newl (cons (car oldl) newl)))
3389 (setq oldl (cdr oldl)))
3390 (setq speedbar-shown-directories (nreverse newl)))
3391 (speedbar-change-expand-button-char ?+)
3392 (speedbar-delete-subblock indent)
3394 (t (error "Ooops... not sure what to do")))
3395 (speedbar-center-buffer-smartly)
3396 (save-excursion (speedbar-stealthy-updates)))
3398 (defun speedbar-directory-buttons-follow (text token indent)
3399 "Speedbar click handler for default directory buttons.
3400 TEXT is the button clicked on. TOKEN is the directory to follow.
3401 INDENT is the current indentation level and is unused."
3402 (if (string-match "^[A-z]:$" token)
3403 (setq default-directory (concat token "/"))
3404 (setq default-directory token))
3405 ;; Because we leave speedbar as the current buffer,
3406 ;; update contents will change directory without
3407 ;; having to touch the attached frame.
3408 (speedbar-update-contents)
3409 (speedbar-set-timer speedbar-navigating-speed))
3411 (defun speedbar-tag-file (text token indent)
3412 "The cursor is on a selected line. Expand the tags in the specified file.
3413 The parameter TEXT and TOKEN are required, where TEXT is the button
3414 clicked, and TOKEN is the file to expand. INDENT is the current
3415 indentation level."
3416 (cond ((string-match "+" text) ;we have to expand this file
3417 (let* ((fn (expand-file-name (concat (speedbar-line-directory indent)
3418 token)))
3419 (mode nil)
3420 (lst (speedbar-fetch-dynamic-tags fn)))
3421 ;; if no list, then remove expando button
3422 (if (not lst)
3423 (speedbar-change-expand-button-char ??)
3424 (speedbar-change-expand-button-char ?-)
3425 (speedbar-with-writable
3426 (save-excursion
3427 (end-of-line) (forward-char 1)
3428 (funcall (car lst) indent (cdr lst)))))))
3429 ((string-match "-" text) ;we have to contract this node
3430 (speedbar-change-expand-button-char ?+)
3431 (speedbar-delete-subblock indent))
3432 (t (error "Ooops... not sure what to do")))
3433 (speedbar-center-buffer-smartly))
3435 (defun speedbar-tag-find (text token indent)
3436 "For the tag TEXT in a file TOKEN, go to that position.
3437 INDENT is the current indentation level."
3438 (let ((file (speedbar-line-directory indent)))
3439 (let ((f (selected-frame)))
3440 (dframe-select-attached-frame speedbar-frame)
3441 (run-hooks 'speedbar-before-visiting-tag-hook)
3442 (select-frame f))
3443 (speedbar-find-file-in-frame file)
3444 (save-excursion (speedbar-stealthy-updates))
3445 ;; Reset the timer with a new timeout when cliking a file
3446 ;; in case the user was navigating directories, we can cancel
3447 ;; that other timer.
3448 (speedbar-set-timer dframe-update-speed)
3449 (goto-char token)
3450 (run-hooks 'speedbar-visiting-tag-hook)
3451 (dframe-maybee-jump-to-attached-frame)
3454 (defun speedbar-tag-expand (text token indent)
3455 "Expand a tag sublist. Imenu will return sub-lists of specialized tag types.
3456 Etags does not support this feature. TEXT will be the button string.
3457 TOKEN will be the list, and INDENT is the current indentation level."
3458 (cond ((string-match "+" text) ;we have to expand this file
3459 (speedbar-change-expand-button-char ?-)
3460 (speedbar-with-writable
3461 (save-excursion
3462 (end-of-line) (forward-char 1)
3463 (speedbar-insert-generic-list indent token 'speedbar-tag-expand
3464 'speedbar-tag-find))))
3465 ((string-match "-" text) ;we have to contract this node
3466 (speedbar-change-expand-button-char ?+)
3467 (speedbar-delete-subblock indent))
3468 (t (error "Ooops... not sure what to do")))
3469 (speedbar-center-buffer-smartly))
3471 ;;; Loading files into the attached frame.
3473 (defcustom speedbar-select-frame-method 'attached
3474 "Specify how to select a frame for displaying a file.
3475 A value of 'attached means to use the attached frame (the frame
3476 that speedbar was started from.) A number such as 1 or -1 means to
3477 pass that number to `other-frame' while selecting a frame from speedbar."
3478 :group 'speedbar
3479 :type 'sexp)
3481 (defun speedbar-find-file-in-frame (file)
3482 "This will load FILE into the speedbar attached frame.
3483 If the file is being displayed in a different frame already, then raise that
3484 frame instead."
3485 (let* ((buff (find-file-noselect file))
3486 (bwin (get-buffer-window buff 0)))
3487 (if bwin
3488 (progn
3489 (select-window bwin)
3490 (raise-frame (window-frame bwin)))
3491 (if dframe-power-click
3492 (let ((pop-up-frames t)) (select-window (display-buffer buff)))
3493 (if (numberp speedbar-select-frame-method)
3494 (other-frame speedbar-select-frame-method)
3495 (dframe-select-attached-frame speedbar-frame))
3496 (switch-to-buffer buff))))
3499 ;;; Centering Utility
3501 (defun speedbar-center-buffer-smartly ()
3502 "Recenter a speedbar buffer so the current indentation level is all visible.
3503 This assumes that the cursor is on a file, or tag of a file which the user is
3504 interested in."
3506 (save-selected-window
3508 (select-window (get-buffer-window speedbar-buffer t))
3510 (set-buffer speedbar-buffer)
3512 (if (<= (count-lines (point-min) (point-max))
3513 (1- (window-height (selected-window))))
3514 ;; whole buffer fits
3515 (let ((cp (point)))
3517 (goto-char (point-min))
3518 (recenter 0)
3519 (goto-char cp))
3520 ;; too big
3521 (let (depth start end exp p)
3522 (save-excursion
3523 (beginning-of-line)
3524 (setq depth (if (looking-at "[0-9]+")
3525 (string-to-number (buffer-substring-no-properties
3526 (match-beginning 0) (match-end 0)))
3528 (setq exp (format "^%d:" depth)))
3529 (save-excursion
3530 (end-of-line)
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.
3535 (end-of-line)
3536 (setq p (point))
3537 (while (and (not (re-search-forward exp nil t))
3538 (>= depth 0))
3539 (setq depth (1- depth))
3540 (setq exp (format "^%d:" depth)))
3541 (if (/= (point) p)
3542 (setq end (point))
3543 (setq end (point-max)))))
3544 ;; Now work out the details of centering
3545 (let ((nl (count-lines start end))
3546 (wl (1- (window-height (selected-window))))
3547 (cp (point)))
3548 (if (> nl wl)
3549 ;; We can't fit it all, so just center on cursor
3550 (progn (goto-char start)
3551 (recenter 1))
3552 ;; we can fit everything on the screen, but...
3553 (if (and (pos-visible-in-window-p start (selected-window))
3554 (pos-visible-in-window-p end (selected-window)))
3555 ;; we are all set!
3557 ;; we need to do something...
3558 (goto-char start)
3559 (let ((newcent (/ (- (window-height (selected-window)) nl) 2))
3560 (lte (count-lines start (point-max))))
3561 (if (and (< (+ newcent lte) (window-height (selected-window)))
3562 (> (- (window-height (selected-window)) lte 1)
3563 newcent))
3564 (setq newcent (- (window-height (selected-window))
3565 lte 1)))
3566 (recenter newcent))))
3567 (goto-char cp))))))
3569 ;;; Tag Management -- List of expanders:
3571 (defun speedbar-fetch-dynamic-tags (file)
3572 "Return a list of tags generated dynamically from FILE.
3573 This uses the entries in `speedbar-dynamic-tags-function-list'
3574 to find the proper tags. It is up to each of those individual
3575 functions to do caching and flushing if appropriate."
3576 (save-excursion
3577 ;; If a file is in memory, switch to that buffer. This allows
3578 ;; us to use the local variable. If the file is on disk, we
3579 ;; can try a few of the defaults that can get tags without
3580 ;; opening the file.
3581 (if (get-file-buffer file)
3582 (set-buffer (get-file-buffer file)))
3583 ;; If there is a buffer-local value of
3584 ;; speedbar-dynamic-tags-function-list, it will now be available.
3585 (let ((dtf speedbar-dynamic-tags-function-list)
3586 (ret t))
3587 (while (and (eq ret t) dtf)
3588 (setq ret
3589 (if (fboundp (car (car dtf)))
3590 (funcall (car (car dtf)) file)
3592 (if (eq ret t)
3593 (setq dtf (cdr dtf))))
3594 (if (eq ret t)
3595 ;; No valid tag list, return nil
3597 ;; We have some tags. Return the list with the insert fn
3598 ;; prepended
3599 (cons (cdr (car dtf)) ret)))))
3601 ;;; Tag Management -- Imenu
3603 (if (not speedbar-use-imenu-flag)
3607 (eval-when-compile (condition-case nil (require 'imenu) (error nil)))
3609 (defun speedbar-fetch-dynamic-imenu (file)
3610 "Load FILE into a buffer, and generate tags using Imenu.
3611 Returns the tag list, or t for an error."
3612 ;; Load this AND compile it in
3613 (require 'imenu)
3614 (set-buffer (find-file-noselect file))
3615 (if dframe-power-click (setq imenu--index-alist nil))
3616 (condition-case nil
3617 (let ((index-alist (imenu--make-index-alist t)))
3618 (if speedbar-sort-tags
3619 (sort (copy-alist index-alist)
3620 (lambda (a b) (string< (car a) (car b))))
3621 index-alist))
3622 (error t)))
3625 ;;; Tag Management -- etags (old XEmacs compatibility part)
3627 (defvar speedbar-fetch-etags-parse-list
3628 '(;; Note that java has the same parse-group as c
3629 ("\\.\\([cChH]\\|c\\+\\+\\|cpp\\|cc\\|hh\\|java\\|cxx\\|hxx\\)\\'" .
3630 speedbar-parse-c-or-c++tag)
3631 ("^\\.emacs$\\|.\\(el\\|l\\|lsp\\)\\'" .
3632 "def[^i]+\\s-+\\(\\(\\w\\|[-_]\\)+\\)\\s-*\C-?")
3633 ; ("\\.\\([fF]\\|for\\|FOR\\|77\\|90\\)\\'" .
3634 ; speedbar-parse-fortran77-tag)
3635 ("\\.tex\\'" . speedbar-parse-tex-string)
3636 ("\\.p\\'" .
3637 "\\(\\(FUNCTION\\|function\\|PROCEDURE\\|procedure\\)\\s-+\\([a-zA-Z0-9_.:]+\\)\\)\\s-*(?^?")
3639 "Associations of file extensions and expressions for extracting tags.
3640 To add a new file type, you would want to add a new association to the
3641 list, where the car is the file match, and the cdr is the way to
3642 extract an element from the tags output. If the output is complex,
3643 use a function symbol instead of regexp. The function should expect
3644 to be at the beginning of a line in the etags buffer.
3646 This variable is ignored if `speedbar-use-imenu-flag' is non-nil.")
3648 (defvar speedbar-fetch-etags-command "etags"
3649 "*Command used to create an etags file.
3651 This variable is ignored if `speedbar-use-imenu-flag' is t.")
3653 (defvar speedbar-fetch-etags-arguments '("-D" "-I" "-o" "-")
3654 "*List of arguments to use with `speedbar-fetch-etags-command'.
3655 This creates an etags output buffer. Use `speedbar-toggle-etags' to
3656 modify this list conveniently.
3658 This variable is ignored if `speedbar-use-imenu-flag' is t.")
3660 (defun speedbar-toggle-etags (flag)
3661 "Toggle FLAG in `speedbar-fetch-etags-arguments'.
3662 FLAG then becomes a member of etags command line arguments. If flag
3663 is \"sort\", then toggle the value of `speedbar-sort-tags'. If its
3664 value is \"show\" then toggle the value of
3665 `speedbar-show-unknown-files'.
3667 This function is a convenience function for XEmacs menu created by
3668 Farzin Guilak <farzin@protocol.com>."
3669 (interactive)
3670 (cond
3671 ((equal flag "sort")
3672 (setq speedbar-sort-tags (not speedbar-sort-tags)))
3673 ((equal flag "show")
3674 (setq speedbar-show-unknown-files (not speedbar-show-unknown-files)))
3675 ((or (equal flag "-C")
3676 (equal flag "-S")
3677 (equal flag "-D"))
3678 (if (member flag speedbar-fetch-etags-arguments)
3679 (setq speedbar-fetch-etags-arguments
3680 (delete flag speedbar-fetch-etags-arguments))
3681 (add-to-list 'speedbar-fetch-etags-arguments flag)))
3682 (t nil)))
3684 (defun speedbar-fetch-dynamic-etags (file)
3685 "For FILE, run etags and create a list of symbols extracted.
3686 Each symbol will be associated with its line position in FILE."
3687 (let ((newlist nil))
3688 (unwind-protect
3689 (save-excursion
3690 (if (get-buffer "*etags tmp*")
3691 (kill-buffer "*etags tmp*")) ;kill to clean it up
3692 (if (<= 1 speedbar-verbosity-level)
3693 (speedbar-message "Fetching etags..."))
3694 (set-buffer (get-buffer-create "*etags tmp*"))
3695 (apply 'call-process speedbar-fetch-etags-command nil
3696 (current-buffer) nil
3697 (append speedbar-fetch-etags-arguments (list file)))
3698 (goto-char (point-min))
3699 (if (<= 1 speedbar-verbosity-level)
3700 (speedbar-message "Fetching etags..."))
3701 (let ((expr
3702 (let ((exprlst speedbar-fetch-etags-parse-list)
3703 (ans nil))
3704 (while (and (not ans) exprlst)
3705 (if (string-match (car (car exprlst)) file)
3706 (setq ans (car exprlst)))
3707 (setq exprlst (cdr exprlst)))
3708 (cdr ans))))
3709 (if expr
3710 (let (tnl)
3711 (set-buffer (get-buffer-create "*etags tmp*"))
3712 (while (not (save-excursion (end-of-line) (eobp)))
3713 (save-excursion
3714 (setq tnl (speedbar-extract-one-symbol expr)))
3715 (if tnl (setq newlist (cons tnl newlist)))
3716 (forward-line 1)))
3717 (speedbar-message
3718 "Sorry, no support for a file of that extension"))))
3720 (if speedbar-sort-tags
3721 (sort newlist (lambda (a b) (string< (car a) (car b))))
3722 (reverse newlist))))
3724 ;; This bit donated by Farzin Guilak <farzin@protocol.com> but I'm not
3725 ;; sure it's needed with the different sorting method.
3727 ;(defun speedbar-clean-etags()
3728 ; "Removes spaces before the ^? character, and removes `#define',
3729 ;return types, etc. preceding tags. This ensures that the sort operation
3730 ;works on the tags, not the return types."
3731 ; (save-excursion
3732 ; (goto-char (point-min))
3733 ; (while
3734 ; (re-search-forward "(?[ \t](?\C-?" nil t)
3735 ; (replace-match "\C-?" nil nil))
3736 ; (goto-char (point-min))
3737 ; (while
3738 ; (re-search-forward "\\(.*[ \t]+\\)\\([^ \t\n]+.*\C-?\\)" nil t)
3739 ; (delete-region (match-beginning 1) (match-end 1)))))
3741 (defun speedbar-extract-one-symbol (expr)
3742 "At point, return nil, or one alist in the form (SYMBOL . POSITION).
3743 The line should contain output from etags. Parse the output using the
3744 regular expression EXPR."
3745 (let* ((sym (if (stringp expr)
3746 (if (save-excursion
3747 (re-search-forward expr (line-end-position) t))
3748 (buffer-substring-no-properties (match-beginning 1)
3749 (match-end 1)))
3750 (funcall expr)))
3751 (pos (let ((j (re-search-forward "[\C-?\C-a]\\([0-9]+\\),\\([0-9]+\\)"
3752 (line-end-position) t)))
3753 (if (and j sym)
3754 (1+ (string-to-number (buffer-substring-no-properties
3755 (match-beginning 2)
3756 (match-end 2))))
3757 0))))
3758 (if (/= pos 0)
3759 (cons sym pos)
3760 nil)))
3762 (defun speedbar-parse-c-or-c++tag ()
3763 "Parse a C or C++ tag, which tends to be a little complex."
3764 (save-excursion
3765 (let ((bound (line-end-position)))
3766 (cond ((re-search-forward "\C-?\\([^\C-a]+\\)\C-a" bound t)
3767 (buffer-substring-no-properties (match-beginning 1)
3768 (match-end 1)))
3769 ((re-search-forward "\\<\\([^ \t]+\\)\\s-+new(" bound t)
3770 (buffer-substring-no-properties (match-beginning 1)
3771 (match-end 1)))
3772 ((re-search-forward "\\<\\([^ \t(]+\\)\\s-*(\C-?" bound t)
3773 (buffer-substring-no-properties (match-beginning 1)
3774 (match-end 1)))
3775 (t nil))
3778 (defun speedbar-parse-tex-string ()
3779 "Parse a Tex string. Only find data which is relevant."
3780 (save-excursion
3781 (let ((bound (line-end-position)))
3782 (cond ((re-search-forward "\\(\\(sub\\)*section\\|chapter\\|cite\\)\\s-*{[^\C-?}]*}?" bound t)
3783 (buffer-substring-no-properties (match-beginning 0)
3784 (match-end 0)))
3785 (t nil)))))
3788 ;;; BUFFER DISPLAY mode.
3790 (defvar speedbar-buffers-key-map nil
3791 "Keymap used when in the buffers display mode.")
3793 (if speedbar-buffers-key-map
3795 (setq speedbar-buffers-key-map (speedbar-make-specialized-keymap))
3797 ;; Basic tree features
3798 (define-key speedbar-buffers-key-map "e" 'speedbar-edit-line)
3799 (define-key speedbar-buffers-key-map "\C-m" 'speedbar-edit-line)
3800 (define-key speedbar-buffers-key-map "+" 'speedbar-expand-line)
3801 (define-key speedbar-buffers-key-map "=" 'speedbar-expand-line)
3802 (define-key speedbar-buffers-key-map "-" 'speedbar-contract-line)
3803 (define-key speedbar-buffers-key-map " " 'speedbar-toggle-line-expansion)
3805 ;; Buffer specific keybindings
3806 (define-key speedbar-buffers-key-map "k" 'speedbar-buffer-kill-buffer)
3807 (define-key speedbar-buffers-key-map "r" 'speedbar-buffer-revert-buffer)
3811 (defvar speedbar-buffer-easymenu-definition
3812 '(["Jump to buffer" speedbar-edit-line t]
3813 ["Expand File Tags" speedbar-expand-line
3814 (save-excursion (beginning-of-line)
3815 (looking-at "[0-9]+: *.\\+. "))]
3816 ["Flush Cache & Expand" speedbar-flush-expand-line
3817 (save-excursion (beginning-of-line)
3818 (looking-at "[0-9]+: *.\\+. "))]
3819 ["Contract File Tags" speedbar-contract-line
3820 (save-excursion (beginning-of-line)
3821 (looking-at "[0-9]+: *.-. "))]
3822 "----"
3823 ["Kill Buffer" speedbar-buffer-kill-buffer
3824 (save-excursion (beginning-of-line)
3825 (looking-at "[0-9]+: *.[-+?]. "))]
3826 ["Revert Buffer" speedbar-buffer-revert-buffer
3827 (save-excursion (beginning-of-line)
3828 (looking-at "[0-9]+: *.[-+?]. "))]
3830 "Menu item elements shown when displaying a buffer list.")
3832 (defun speedbar-buffer-buttons (directory zero)
3833 "Create speedbar buttons based on the buffers currently loaded.
3834 DIRECTORY is the directory of the currently active buffer, and ZERO is 0."
3835 (speedbar-buffer-buttons-engine nil))
3837 (defun speedbar-buffer-buttons-temp (directory zero)
3838 "Create speedbar buttons based on the buffers currently loaded.
3839 DIRECTORY is the directory of the currently active buffer, and ZERO is 0."
3840 (speedbar-buffer-buttons-engine t))
3842 (defun speedbar-buffer-buttons-engine (temp)
3843 "Create speedbar buffer buttons.
3844 If TEMP is non-nil, then clicking on a buffer restores the previous display."
3845 (speedbar-insert-separator "Active Buffers:")
3846 (let ((bl (buffer-list))
3847 (case-fold-search t))
3848 (while bl
3849 (if (string-match "^[ *]" (buffer-name (car bl)))
3851 (let* ((known (string-match speedbar-file-regexp
3852 (buffer-name (car bl))))
3853 (expchar (if known ?+ ??))
3854 (fn (if known 'speedbar-tag-file nil))
3855 (fname (with-current-buffer (car bl)
3856 (buffer-file-name))))
3857 (speedbar-make-tag-line 'bracket expchar fn
3858 (if fname (file-name-nondirectory fname))
3859 (buffer-name (car bl))
3860 'speedbar-buffer-click temp
3861 'speedbar-file-face 0)
3862 (speedbar-buffers-tail-notes (car bl))))
3863 (setq bl (cdr bl)))
3864 (setq bl (buffer-list))
3865 (speedbar-insert-separator "Scratch Buffers:")
3866 (while bl
3867 (if (not (string-match "^\\*" (buffer-name (car bl))))
3869 (if (eq (car bl) speedbar-buffer)
3871 (speedbar-make-tag-line 'bracket ?? nil nil
3872 (buffer-name (car bl))
3873 'speedbar-buffer-click temp
3874 'speedbar-file-face 0)
3875 (speedbar-buffers-tail-notes (car bl))))
3876 (setq bl (cdr bl)))
3877 (setq bl (buffer-list))
3878 ;;(speedbar-insert-separator "Hidden Buffers:")
3879 ;;(while bl
3880 ;; (if (not (string-match "^ " (buffer-name (car bl))))
3881 ;; nil
3882 ;; (if (eq (car bl) speedbar-buffer)
3883 ;; nil
3884 ;; (speedbar-make-tag-line 'bracket ?? nil nil
3885 ;; (buffer-name (car bl))
3886 ;; 'speedbar-buffer-click temp
3887 ;; 'speedbar-file-face 0)
3888 ;; (speedbar-buffers-tail-notes (car bl))))
3889 ;; (setq bl (cdr bl)))
3892 (defun speedbar-buffers-tail-notes (buffer)
3893 "Add a note to the end of the last tag line.
3894 Argument BUFFER is the buffer being tested."
3895 (let (mod ro)
3896 (with-current-buffer buffer
3897 (setq mod (buffer-modified-p)
3898 ro buffer-read-only))
3899 (if ro (speedbar-insert-button "%" nil nil nil nil t))))
3901 (defun speedbar-buffers-item-info ()
3902 "Display information about the current buffer on the current line."
3903 (or (speedbar-item-info-tag-helper)
3904 (let* ((item (speedbar-line-text))
3905 (buffer (if item (get-buffer item) nil)))
3906 (and buffer
3907 (speedbar-message "%s%s %S %d %s"
3908 (if (buffer-modified-p buffer) "* " "")
3909 item
3910 (with-current-buffer buffer major-mode)
3911 (with-current-buffer buffer (buffer-size))
3912 (or (buffer-file-name buffer) "<No file>"))))))
3914 (defun speedbar-buffers-line-directory (&optional depth)
3915 "Fetch the directory of the file (buffer) specified on the current line.
3916 Optional argument DEPTH specifies the current depth of the back search."
3917 (save-excursion
3918 (end-of-line)
3919 (let ((start (point)))
3920 ;; Buffers are always at level 0
3921 (if (not (re-search-backward "^0:" nil t))
3923 (let* ((bn (speedbar-line-text))
3924 (buffer (if bn (get-buffer bn))))
3925 (if buffer
3926 (if (eq start (line-end-position))
3927 (or (with-current-buffer buffer default-directory)
3929 (buffer-file-name buffer))))))))
3931 (defun speedbar-buffer-click (text token indent)
3932 "When the users clicks on a buffer-button in speedbar.
3933 TEXT is the buffer's name, TOKEN and INDENT are unused."
3934 (if dframe-power-click
3935 (let ((pop-up-frames t)) (select-window (display-buffer text)))
3936 (dframe-select-attached-frame speedbar-frame)
3937 (switch-to-buffer text)
3938 (if token (speedbar-change-initial-expansion-list
3939 speedbar-previously-used-expansion-list-name))))
3941 (defun speedbar-buffer-kill-buffer ()
3942 "Kill the buffer the cursor is on in the speedbar buffer."
3943 (interactive)
3944 (or (save-excursion
3945 (let ((text (speedbar-line-text)))
3946 (if (and (get-buffer text)
3947 (speedbar-y-or-n-p (format "Kill buffer %s? " text)))
3948 (kill-buffer text))
3949 (speedbar-refresh)))))
3951 (defun speedbar-buffer-revert-buffer ()
3952 "Revert the buffer the cursor is on in the speedbar buffer."
3953 (interactive)
3954 (save-excursion
3955 (beginning-of-line)
3956 ;; If this fails, then it is a non-standard click, and as such,
3957 ;; perfectly allowed
3958 (if (re-search-forward "[]>?}] [^ ]" (line-end-position) t)
3959 (let ((text (progn
3960 (forward-char -1)
3961 (buffer-substring (point) (line-end-position)))))
3962 (if (get-buffer text)
3963 (progn
3964 (set-buffer text)
3965 (revert-buffer t)))))))
3968 ;;; Useful hook values and such.
3970 (defvar speedbar-highlight-one-tag-line nil
3971 "Overlay used for highlighting the most recently jumped to tag line.")
3973 (defun speedbar-highlight-one-tag-line ()
3974 "Highlight the current line, unhighlighting a previously jumped to line."
3975 (speedbar-unhighlight-one-tag-line)
3976 (setq speedbar-highlight-one-tag-line
3977 (speedbar-make-overlay (line-beginning-position)
3978 (1+ (line-end-position))))
3979 (speedbar-overlay-put speedbar-highlight-one-tag-line 'face
3980 'speedbar-highlight-face)
3981 (add-hook 'pre-command-hook 'speedbar-unhighlight-one-tag-line))
3983 (defun speedbar-unhighlight-one-tag-line ()
3984 "Unhighlight the currently highlighted line."
3985 (if speedbar-highlight-one-tag-line
3986 (progn
3987 (speedbar-delete-overlay speedbar-highlight-one-tag-line)
3988 (setq speedbar-highlight-one-tag-line nil)))
3989 (remove-hook 'pre-command-hook 'speedbar-unhighlight-one-tag-line))
3991 (defun speedbar-recenter-to-top ()
3992 "Recenter the current buffer so point is on the top of the window."
3993 (recenter 1))
3995 (defun speedbar-recenter ()
3996 "Recenter the current buffer so point is in the center of the window."
3997 (recenter (/ (window-height (selected-window)) 2)))
4000 ;;; Color loading section.
4002 (defface speedbar-button-face '((((class color) (background light))
4003 (:foreground "green4"))
4004 (((class color) (background dark))
4005 (:foreground "green3")))
4006 "Face used for +/- buttons."
4007 :group 'speedbar-faces)
4009 (defface speedbar-file-face '((((class color) (background light))
4010 (:foreground "cyan4"))
4011 (((class color) (background dark))
4012 (:foreground "cyan"))
4013 (t (:bold t)))
4014 "Face used for file names."
4015 :group 'speedbar-faces)
4017 (defface speedbar-directory-face '((((class color) (background light))
4018 (:foreground "blue4"))
4019 (((class color) (background dark))
4020 (:foreground "light blue")))
4021 "Face used for directory names."
4022 :group 'speedbar-faces)
4023 (defface speedbar-tag-face '((((class color) (background light))
4024 (:foreground "brown"))
4025 (((class color) (background dark))
4026 (:foreground "yellow")))
4027 "Face used for displaying tags."
4028 :group 'speedbar-faces)
4030 (defface speedbar-selected-face '((((class color) (background light))
4031 (:foreground "red" :underline t))
4032 (((class color) (background dark))
4033 (:foreground "red" :underline t))
4034 (t (:underline t)))
4035 "Face used to underline the file in the active window."
4036 :group 'speedbar-faces)
4038 (defface speedbar-highlight-face '((((class color) (background light))
4039 (:background "green"))
4040 (((class color) (background dark))
4041 (:background "sea green"))
4042 (((class grayscale monochrome)
4043 (background light))
4044 (:background "black"))
4045 (((class grayscale monochrome)
4046 (background dark))
4047 (:background "white")))
4048 "Face used for highlighting buttons with the mouse."
4049 :group 'speedbar-faces)
4051 (defface speedbar-separator-face '((((class color) (background light))
4052 (:background "blue"
4053 :foreground "white"
4054 :overline "gray"))
4055 (((class color) (background dark))
4056 (:background "blue"
4057 :foreground "white"
4058 :overline "gray"))
4059 (((class grayscale monochrome)
4060 (background light))
4061 (:background "black"
4062 :foreground "white"
4063 :overline "white"))
4064 (((class grayscale monochrome)
4065 (background dark))
4066 (:background "white"
4067 :foreground "black"
4068 :overline "black")))
4069 "Face used for separator labels in a display."
4070 :group 'speedbar-faces)
4072 ;; some edebug hooks
4073 (add-hook 'edebug-setup-hook
4074 (lambda ()
4075 (def-edebug-spec speedbar-with-writable def-body)))
4077 ;; Fix a font lock problem for some versions of Emacs
4078 (and (boundp 'font-lock-global-modes)
4079 font-lock-global-modes
4080 (if (eq font-lock-global-modes t)
4081 (setq font-lock-global-modes '(not speedbar-mode))
4082 (if (eq (car font-lock-global-modes) 'not)
4083 (add-to-list 'font-lock-global-modes 'speedbar-mode t)
4084 (setq font-lock-global-modes (delq 'speedbar-mode
4085 font-lock-global-modes)))))
4087 ;;; Obsolete variables and functions
4089 (define-obsolete-variable-alias
4090 'speedbar-ignored-path-regexp 'speedbar-ignored-directory-regexp "22.1")
4092 (define-obsolete-function-alias 'speedbar-add-ignored-path-regexp
4093 'speedbar-add-ignored-directory-regexp "22.1")
4095 (define-obsolete-function-alias 'speedbar-line-path
4096 'speedbar-line-directory "22.1")
4098 (define-obsolete-function-alias 'speedbar-buffers-line-path
4099 'speedbar-buffers-line-directory "22.1")
4101 (define-obsolete-function-alias 'speedbar-path-line
4102 'speedbar-directory-line "22.1")
4104 (define-obsolete-function-alias 'speedbar-buffers-line-path
4105 'speedbar-buffers-line-directory "22.1")
4107 (provide 'speedbar)
4109 ;; run load-time hooks
4110 (run-hooks 'speedbar-load-hook)
4112 ;;; speedbar ends here