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