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