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