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