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