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