1 ;;; speedbar --- quick access to files and tags in a frame
3 ;; Copyright (C) 1996-2015 Free Software Foundation, Inc.
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
6 ;; Keywords: file, tags, tools
8 (defvar speedbar-version
"1.0"
9 "The current version of speedbar.")
10 (defvar speedbar-incompatible-version
"0.14beta4"
11 "This version of speedbar is incompatible with this version.
12 Due to massive API changes (removing the use of the word PATH)
13 this version is not backward compatible to 0.14 or earlier.")
15 ;; This file is part of GNU Emacs.
17 ;; GNU Emacs is free software: you can redistribute it and/or modify
18 ;; it under the terms of the GNU General Public License as published by
19 ;; the Free Software Foundation, either version 3 of the License, or
20 ;; (at your option) any later version.
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.
27 ;; You should have received a copy of the GNU General Public License
28 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
32 ;; The speedbar provides a frame in which files, and locations in
33 ;; files are displayed. These items can be clicked on with mouse-2 in
34 ;; to display that file location.
36 ;;; Customizing and Developing for speedbar
38 ;; Please see the speedbar manual for information.
42 ;; Users of really old emacsen without the need timer functions
43 ;; will not have speedbar updating automatically. Use "g" to refresh
44 ;; the display after changing directories. Remember, do not interrupt
45 ;; the stealthy updates or your display may not be completely
48 ;; AUC-TEX users: The imenu tags for AUC-TEX mode don't work very
49 ;; well. Use the imenu keywords from tex-mode.el for better results.
51 ;; This file requires the library package assoc (association lists)
52 ;; assoc should be available in all modern versions of Emacs.
53 ;; The custom package is optional (for easy configuration of speedbar)
54 ;; http://www.dina.kvl.dk/~abraham/custom/
55 ;; custom is available in all versions of Emacs version 20 or better.
57 ;;; Developing for speedbar
59 ;; Adding a speedbar specialized display mode:
61 ;; Speedbar can be configured to create a special display for certain
62 ;; modes that do not display traditional file/tag data. Rmail, Info,
63 ;; and the debugger are examples. These modes can, however, benefit
64 ;; from a speedbar style display in their own way.
66 ;; If your `major-mode' is `foo-mode', the only requirement is to
67 ;; create a function called `foo-speedbar-buttons' which takes one
68 ;; argument, BUFFER. BUFFER will be the buffer speedbar wants filled.
69 ;; In `foo-speedbar-buttons' there are several functions that make
70 ;; building a speedbar display easy. See the documentation for
71 ;; `speedbar-with-writable' (needed because the buffer is usually
72 ;; read-only) `speedbar-make-tag-line', `speedbar-insert-button', and
73 ;; `speedbar-insert-generic-list'. If you use
74 ;; `speedbar-insert-generic-list', also read the doc for
75 ;; `speedbar-tag-hierarchy-method' in case you wish to override it.
76 ;; The macro `dframe-with-attached-buffer' brings you back to the
77 ;; buffer speedbar is displaying for.
79 ;; For those functions that make buttons, the "function" should be a
80 ;; symbol that is the function to call when clicked on. The "token"
81 ;; is extra data you can pass along. The "function" must take three
82 ;; parameters. They are (TEXT TOKEN INDENT). TEXT is the text of the
83 ;; button clicked on. TOKEN is the data passed in when you create the
84 ;; button. INDENT is an indentation level, or 0. You can store
85 ;; indentation levels with `speedbar-make-tag-line' which creates a
86 ;; line with an expander (eg. [+]) and a text button.
88 ;; Some useful functions when writing expand functions, and click
89 ;; functions are `speedbar-change-expand-button-char',
90 ;; `speedbar-delete-subblock', and `speedbar-center-buffer-smartly'.
91 ;; The variable `speedbar-power-click' is set to t in your functions
92 ;; when the user shift-clicks. This is an indication of anything from
93 ;; refreshing cached data to making a buffer appear in a new frame.
95 ;; If you wish to add to the default speedbar menu for the case of
96 ;; `foo-mode', create a variable `foo-speedbar-menu-items'. This
97 ;; should be a list compatible with the `easymenu' package. It will
98 ;; be spliced into the main menu. (Available with click-mouse-3). If
99 ;; you wish to have extra key bindings in your special mode, create a
100 ;; variable `foo-speedbar-key-map'. Instead of using `make-keymap',
101 ;; or `make-sparse-keymap', use the function
102 ;; `speedbar-make-specialized-keymap'. This lets you inherit all of
103 ;; speedbar's default bindings with low overhead.
105 ;; Adding a speedbar top-level display mode:
107 ;; Unlike the specialized modes, there are no name requirements,
108 ;; however the methods for writing a button display, menu, and keymap
109 ;; are the same. Once you create these items, you can call the
110 ;; function `speedbar-add-expansion-list'. It takes one parameter
111 ;; which is a list element of the form (NAME MENU KEYMAP &rest
112 ;; BUTTON-FUNCTIONS). NAME is a string that will show up in the
113 ;; Displays menu item. MENU is a symbol containing the menu items to
114 ;; splice in. KEYMAP is a symbol holding the keymap to use, and
115 ;; BUTTON-FUNCTIONS are the function names to call, in order, to create
117 ;; Another tweakable variable is `speedbar-stealthy-function-list'
118 ;; which is of the form (NAME &rest FUNCTION ...). NAME is the string
119 ;; name matching `speedbar-add-expansion-list'. (It does not need to
120 ;; exist.). This provides additional display info which might be
121 ;; time-consuming to calculate.
122 ;; Lastly, `speedbar-mode-functions-list' allows you to set special
123 ;; function overrides.
126 ;; - Timeout directories we haven't visited in a while.
132 ;; customization stuff
133 (defgroup speedbar nil
134 "File and tag browser frame."
138 :link
'(custom-manual "(speedbar) Top")
139 :link
'(info-link "(speedbar) Customizing")
143 (defgroup speedbar-faces nil
144 "Faces used in speedbar."
146 :link
'(info-link "(speedbar) Frames and Faces")
150 (defgroup speedbar-vc nil
151 "Version control display in speedbar."
152 :link
'(info-link "(speedbar) Version Control")
158 ;; Note: `inversion-test' requires parts of the CEDET package that are
159 ;; not included with Emacs.
161 ;; (defun speedbar-require-version (major minor &optional beta)
162 ;; "Non-nil if this version of SPEEDBAR does not satisfy a specific version.
165 ;; (MAJOR MINOR &optional BETA)
167 ;; Values MAJOR and MINOR must be integers. BETA can be an integer, or
168 ;; excluded if a released version is required.
170 ;; It is assumed that if the current version is newer than that specified,
171 ;; everything passes. Exceptions occur when known incompatibilities are
173 ;; (inversion-test 'speedbar
174 ;; (concat major "." minor
175 ;; (when beta (concat "beta" beta)))))
177 (defvar speedbar-initial-expansion-mode-alist
178 '(("buffers" speedbar-buffer-easymenu-definition speedbar-buffers-key-map
179 speedbar-buffer-buttons
)
180 ("quick buffers" speedbar-buffer-easymenu-definition speedbar-buffers-key-map
181 speedbar-buffer-buttons-temp
)
182 ;; Files last, means first in the Displays menu
183 ("files" speedbar-easymenu-definition-special speedbar-file-key-map
184 speedbar-directory-buttons speedbar-default-directory-list
)
186 "List of named expansion elements for filling the speedbar frame.
187 These expansion lists are only valid for regular files. Special modes
188 still get to override this list on a mode-by-mode basis. This list of
189 lists is of the form (NAME MENU KEYMAP FN1 FN2 ...). NAME is a string
190 representing the types of things to be displayed. MENU is an easymenu
191 structure used when in this mode. KEYMAP is a local keymap to install
192 over the regular speedbar keymap. FN1 ... are functions that will be
193 called in order. These functions will always get the default
194 directory to use passed in as the first parameter, and a 0 as the
195 second parameter. The 0 indicates the uppermost indentation level.
196 They must assume that the cursor is at the position where they start
199 (defvar speedbar-initial-expansion-list-name
"files"
200 "A symbol name representing the expansion list to use.
201 The expansion list `speedbar-initial-expansion-mode-alist' contains
202 the names and associated functions to use for buttons in speedbar.")
204 (defvar speedbar-previously-used-expansion-list-name
"files"
205 "Save the last expansion list method.
206 This is used for returning to a previous expansion list method when
207 the user is done with the current expansion list.")
209 (defvar speedbar-stealthy-function-list
211 speedbar-update-current-file
212 speedbar-check-read-only
214 speedbar-check-objects
)
216 "List of functions to periodically call stealthily.
217 This list is of the form:
218 '( (\"NAME\" FUNCTION ...)
220 where NAME is the name of the major display mode these functions are
221 for, and the remaining elements FUNCTION are functions to call in order.
222 Each function must return nil if interrupted, or t if completed.
223 Stealthy functions which have a single operation should always return t.
224 Functions which take a long time should maintain a state (where they
225 are in their speedbar related calculations) and permit interruption.
226 See `speedbar-check-vc' as a good example.")
228 (defvar speedbar-mode-functions-list
229 '(("files" (speedbar-item-info . speedbar-files-item-info
)
230 (speedbar-line-directory . speedbar-files-line-directory
))
231 ("buffers" (speedbar-item-info . speedbar-buffers-item-info
)
232 (speedbar-line-directory . speedbar-buffers-line-directory
))
233 ("quick buffers" (speedbar-item-info . speedbar-buffers-item-info
)
234 (speedbar-line-directory . speedbar-buffers-line-directory
))
236 "List of function tables to use for different major display modes.
237 It is not necessary to define any functions for a specialized mode.
238 This just provides a simple way of adding lots of customizations.
239 Each sublist is of the form:
240 (\"NAME\" (FUNCTIONSYMBOL . REPLACEMENTFUNCTION) ...)
241 Where NAME is the name of the specialized mode. The rest of the list
242 is a set of dotted pairs of the form FUNCTIONSYMBOL, which is the name
243 of a function you would like to replace, and REPLACEMENTFUNCTION,
244 which is a function you can call instead. Not all functions can be
245 replaced this way. Replaceable functions must provide that
246 functionality individually.")
248 (defcustom speedbar-mode-specific-contents-flag t
249 "Non-nil means speedbar will show special mode contents.
250 This permits some modes to create customized contents for the speedbar
255 (defcustom speedbar-query-confirmation-method
'all
256 "Query control for file operations.
257 The 'all flag means to always query before file operations.
258 The 'none-but-delete flag means to not query before any file
259 operations, except before a file deletion."
261 :type
'(radio (const :tag
"Always Query before some file operations."
263 (const :tag
"Never Query before file operations, except for deletions."
265 ;;;; (const :tag "Never Every Query."
269 (defvar speedbar-special-mode-expansion-list nil
270 "Default function list for creating specialized button lists.
271 This list is set by modes that wish to have special speedbar displays.
272 The list is of function names. Each function is called with one
273 parameter BUFFER, the originating buffer. The current buffer is the
276 (defvar speedbar-special-mode-key-map nil
277 "Default keymap used when identifying a specialized display mode.
278 This keymap is local to each buffer that wants to define special keybindings
279 effective when its display is shown.")
281 (defcustom speedbar-before-visiting-file-hook
'(push-mark)
282 "Hooks run before speedbar visits a file in the selected frame.
283 The default buffer is the buffer in the selected window in the attached frame."
287 (defcustom speedbar-visiting-file-hook nil
288 "Hooks run when speedbar visits a file in the selected frame."
292 (defcustom speedbar-before-visiting-tag-hook
'(push-mark)
293 "Hooks run before speedbar visits a tag in the selected frame.
294 The default buffer is the buffer in the selected window in the attached frame."
298 (defcustom speedbar-visiting-tag-hook
'(speedbar-highlight-one-tag-line)
299 "Hooks run when speedbar visits a tag in the selected frame."
302 :options
'(speedbar-highlight-one-tag-line
303 speedbar-recenter-to-top
307 (defcustom speedbar-load-hook nil
308 "Hooks run when speedbar is loaded."
312 (defcustom speedbar-reconfigure-keymaps-hook nil
313 "Hooks run when the keymaps are regenerated."
317 (defcustom speedbar-show-unknown-files nil
318 "Non-nil show files we can't expand with a ? in the expand button.
319 A nil value means don't show the file in the list."
323 ;;; EVENTUALLY REMOVE THESE
325 ;; When I moved to a repeating timer, I had the horrible misfortune
326 ;; of losing the ability for adaptive speed choice. This update
327 ;; speed currently causes long delays when it should have been turned off.
328 (defvar speedbar-update-speed dframe-update-speed
)
329 (make-obsolete-variable 'speedbar-update-speed
331 "speedbar 1.0pre3 (Emacs 23.1)")
333 (defvar speedbar-navigating-speed dframe-update-speed
)
334 (make-obsolete-variable 'speedbar-navigating-speed
336 "speedbar 1.0pre3 (Emacs 23.1)")
339 (defcustom speedbar-frame-parameters
'((minibuffer . nil
)
347 "Parameters to use when creating the speedbar frame in Emacs.
348 Any parameter supported by a frame may be added. The parameter `height'
349 will be initialized to the height of the frame speedbar is
350 attached to and added to this list before the new frame is initialized."
352 :type
'(repeat (cons :format
"%v"
353 (symbol :tag
"Parameter")
354 (sexp :tag
"Value"))))
356 ;; These values by Hrvoje Niksic <hniksic@srce.hr>
357 (defcustom speedbar-frame-plist
358 '(minibuffer nil width
20 border-width
0
359 internal-border-width
0 unsplittable t
360 default-toolbar-visible-p nil has-modeline-p nil
361 menubar-visible-p nil
362 default-gutter-visible-p nil
364 "Parameters to use when creating the speedbar frame in XEmacs.
365 Parameters not listed here which will be added automatically are
366 `height' which will be initialized to the height of the frame speedbar
369 :type
'(repeat (group :inline t
370 (symbol :tag
"Property")
371 (sexp :tag
"Value"))))
373 (defcustom speedbar-use-imenu-flag
(fboundp 'imenu
)
374 "Non-nil means use imenu for file parsing, nil to use etags.
375 XEmacs prior to 20.4 doesn't support imenu, therefore the default is to
376 use etags instead. Etags support is not as robust as imenu support."
377 :tag
"Use Imenu for tags"
381 (defvar speedbar-dynamic-tags-function-list
382 '((speedbar-fetch-dynamic-imenu . speedbar-insert-imenu-list
)
383 (speedbar-fetch-dynamic-etags . speedbar-insert-etags-list
))
384 "Set to a list of functions which will return and insert a list of tags.
385 Each element is of the form ( FETCH . INSERT ) where FETCH
386 is a function which takes one parameter (the file to tag) and returns a
387 list of tags. The tag list can be of any form as long as the
388 corresponding insert method can handle it. If it returns t, then an
389 error occurred, and the next fetch routine is tried.
390 INSERT is a function which takes an INDENTation level, and a LIST of
391 tags to insert. It will then create the speedbar buttons.")
393 (defcustom speedbar-use-tool-tips-flag
(fboundp 'tooltip-mode
)
394 "Non-nil means to use tool tips if they are available.
395 When tooltips are not available, mouse-tracking and minibuffer
396 display is used instead."
400 (defcustom speedbar-track-mouse-flag
(not speedbar-use-tool-tips-flag
)
401 "Non-nil means to display info about the line under the mouse."
405 (defcustom speedbar-default-position
'left-right
406 "Default position of the speedbar frame.
407 Possible values are 'left, 'right or 'left-right.
408 If value is 'left-right, the most suitable location is
409 determined automatically."
411 :type
'(radio (const :tag
"Automatic" left-right
)
412 (const :tag
"Left" left
)
413 (const :tag
"Right" right
)))
415 (defcustom speedbar-sort-tags nil
416 "If non-nil, sort tags in the speedbar display. *Obsolete*.
417 Use `semantic-tag-hierarchy-method' instead."
421 (defcustom speedbar-tag-hierarchy-method
422 '(speedbar-prefix-group-tag-hierarchy
423 speedbar-trim-words-tag-hierarchy
)
424 "List of hooks which speedbar will use to organize tags into groups.
425 Groups are defined as expandable meta-tags. Imenu supports
426 such things in some languages, such as separating variables from
427 functions. Each hook takes one argument LST, and may destructively
428 create a new list of the same form. LST is a list of elements of the
431 where each ELT is of the form
432 (TAG-NAME-STRING . NUMBER-OR-MARKER)
434 (GROUP-NAME-STRING ELT1 ELT2... ELTn)"
437 :options
'(speedbar-prefix-group-tag-hierarchy
438 speedbar-trim-words-tag-hierarchy
439 speedbar-simple-group-tag-hierarchy
440 speedbar-sort-tag-hierarchy
)
443 (defcustom speedbar-tag-group-name-minimum-length
4
444 "The minimum length of a prefix group name before expanding.
445 Thus, if the `speedbar-tag-hierarchy-method' includes `prefix-group'
446 and one such groups common characters is less than this number of
447 characters, then the group name will be changed to the form of:
451 This way we won't get silly looking listings."
455 (defcustom speedbar-tag-split-minimum-length
20
456 "Minimum length before we stop trying to create sub-lists in tags.
457 This is used by all tag-hierarchy methods that break large lists into
462 (defcustom speedbar-tag-regroup-maximum-length
10
463 "Maximum length of submenus that are regrouped.
464 If the regrouping option is used, then if two or more short subgroups
465 are next to each other, then they are combined until this number of
470 (defcustom speedbar-directory-button-trim-method
'span
471 "Indicates how the directory button will be displayed.
473 'span - span large directories over multiple lines.
474 'trim - trim large directories to only show the last few.
477 :type
'(radio (const :tag
"Span large directories over multiple lines."
479 (const :tag
"Trim large directories to only show the last few."
481 (const :tag
"No trimming." nil
)))
483 (defcustom speedbar-smart-directory-expand-flag t
484 "Non-nil means speedbar should use smart expansion.
485 Smart expansion only affects when speedbar wants to display a
486 directory for a file in the attached frame. When smart expansion is
487 enabled, new directories which are children of a displayed directory
488 are expanded in the current framework. If nil, then the current
489 hierarchy would be replaced with the new directory."
493 (defcustom speedbar-indentation-width
1
494 "When sub-nodes are expanded, the number of spaces used for indentation."
498 (defcustom speedbar-hide-button-brackets-flag nil
499 "Non-nil means speedbar will hide the brackets around the + or -."
503 (defcustom speedbar-before-popup-hook nil
504 "Hooks called before popping up the speedbar frame."
508 (defcustom speedbar-after-create-hook
'(speedbar-frame-reposition-smartly)
509 "Hooks called after popping up the speedbar frame."
513 (defcustom speedbar-before-delete-hook nil
514 "Hooks called before deleting the speedbar frame."
518 (defcustom speedbar-mode-hook nil
519 "Hook run after creating a speedbar buffer."
523 (defcustom speedbar-timer-hook nil
524 "Hooks called after running the speedbar timer function."
528 (defcustom speedbar-verbosity-level
1
529 "Verbosity level of the speedbar.
531 1 means medium level verbosity.
532 2 and higher are higher levels of verbosity."
536 (defvar speedbar-indicator-separator
" "
537 "String separating file text from indicator characters.")
539 (defcustom speedbar-vc-do-check t
540 "Non-nil check all files in speedbar to see if they have been checked out.
541 Any file checked out is marked with `speedbar-vc-indicator'."
545 (defvar speedbar-vc-indicator
"*"
546 "Text used to mark files which are currently checked out.
547 Other version control systems can be added by examining the function
548 `speedbar-vc-directory-enable-hook' and `speedbar-vc-in-control-hook'.")
550 (defcustom speedbar-vc-directory-enable-hook nil
551 "Return non-nil if the current directory should be checked for Version Control.
552 Functions in this hook must accept one parameter which is the directory
557 (defcustom speedbar-vc-in-control-hook nil
558 "Return non-nil if the specified file is under Version Control.
559 Functions in this hook must accept two parameters. The DIRECTORY of the
560 current file, and the FILENAME of the file being checked."
564 (defvar speedbar-vc-to-do-point nil
565 "Local variable maintaining the current version control check position.")
567 (defcustom speedbar-obj-do-check t
568 "Non-nil check all files in speedbar to see if they have an object file.
569 Any file checked out is marked with `speedbar-obj-indicator', and the
570 marking is based on `speedbar-obj-alist'"
574 (defvar speedbar-obj-to-do-point nil
575 "Local variable maintaining the current version control check position.")
577 (defvar speedbar-obj-indicator
'("#" .
"!")
578 "Text used to mark files that have a corresponding hidden object file.
579 The car is for an up-to-date object. The cdr is for an out of date object.
580 The expression `speedbar-obj-alist' defines who gets tagged.")
582 (defvar speedbar-obj-alist
583 '(("\\.\\([cpC]\\|cpp\\|cc\\|cxx\\)$" .
".o")
585 ("\\.java$" .
".class")
586 ("\\.f\\(or\\|90\\|77\\)?$" .
".o")
588 ("\\.texi$" .
".info"))
589 "Alist of file extensions, and their corresponding object file type.")
591 (defvar speedbar-ro-to-do-point nil
592 "Local variable maintaining the current read only check position.")
594 (defvar speedbar-object-read-only-indicator
"%"
595 "Indicator to append onto a line if that item is Read Only.")
597 ;; Note: Look for addition place to add indicator lists that
598 ;; use skip-chars instead of a regular expression.
599 (defvar speedbar-indicator-regex
600 (concat (regexp-quote speedbar-indicator-separator
)
602 (regexp-quote speedbar-vc-indicator
)
604 (regexp-quote (car speedbar-obj-indicator
))
606 (regexp-quote (cdr speedbar-obj-indicator
))
608 (regexp-quote speedbar-object-read-only-indicator
)
610 "Regular expression used when identifying files.
611 Permits stripping of indicator characters from a line.")
613 (defcustom speedbar-scanner-reset-hook nil
614 "Hook called whenever generic scanners are reset.
615 Set this to implement your own scanning / rescan safe functions with
620 (defcustom speedbar-ignored-modes
'(fundamental-mode)
621 "List of major modes which speedbar will not switch directories for."
623 :type
'(choice (const nil
)
624 (repeat :tag
"List of modes" (symbol :tag
"Major mode"))))
626 (defun speedbar-extension-list-to-regex (extlist)
627 "Takes EXTLIST, a list of extensions and transforms it into regexp.
628 All the preceding `.' are stripped for an optimized expression starting
629 with `.' followed by extensions, followed by full-filenames."
630 (let ((regex1 nil
) (regex2 nil
))
632 (if (= (string-to-char (car extlist
)) ?.
)
633 (setq regex1
(concat regex1
(if regex1
"\\|" "")
634 (substring (car extlist
) 1)))
635 (setq regex2
(concat regex2
(if regex2
"\\|" "") (car extlist
))))
636 (setq extlist
(cdr extlist
)))
637 ;; Concatenate all the subexpressions together, making sure all types
638 ;; of parts exist during concatenation.
640 (if regex1
(concat "\\(\\.\\(" regex1
"\\)\\)") "")
641 (if (and regex1 regex2
) "\\|" "")
642 (if regex2
(concat "\\(" regex2
"\\)") "")
645 (defvar speedbar-ignored-directory-regexp nil
646 "Regular expression matching directories speedbar will not switch to.
647 Created from `speedbar-ignored-directory-expressions' with the function
648 `speedbar-extension-list-to-regex' (a misnamed function in this case.)
649 Use the function `speedbar-add-ignored-directory-regexp', or customize the
650 variable `speedbar-ignored-directory-expressions' to modify this variable.")
652 (define-obsolete-variable-alias 'speedbar-ignored-path-expressions
653 'speedbar-ignored-directory-expressions
"22.1")
655 (defcustom speedbar-ignored-directory-expressions
656 '("[/\\]logs?[/\\]\\'")
657 "List of regular expressions matching directories speedbar will ignore.
658 They should included directories which are notoriously very large
659 and take a long time to load in. Use the function
660 `speedbar-add-ignored-directory-regexp' to add new items to this list after
661 speedbar is loaded. You may place anything you like in this list
662 before speedbar has been loaded."
664 :type
'(repeat (regexp :tag
"Directory Regexp"))
665 :set
(lambda (_sym val
)
666 (setq speedbar-ignored-directory-expressions val
667 speedbar-ignored-directory-regexp
668 (speedbar-extension-list-to-regex val
))))
670 (defcustom speedbar-directory-unshown-regexp
"^\\(\\..*\\)\\'"
671 "Regular expression matching directories not to show in speedbar.
672 They should include commonly existing directories which are not
673 useful. It is no longer necessary to include version-control
674 directories here; see `vc-directory-exclusion-list'."
678 (defcustom speedbar-file-unshown-regexp
679 (let ((nstr "") (noext completion-ignored-extensions
))
681 (setq nstr
(concat nstr
(regexp-quote (car noext
)) "\\'"
682 (if (cdr noext
) "\\|" ""))
684 ;; backup refdir lockfile
685 (concat nstr
"\\|#[^#]+#$\\|\\.\\.?\\'\\|\\.#"))
686 "Regexp matching files we don't want displayed in a speedbar buffer.
687 It is generated from the variable `completion-ignored-extensions'."
691 (defvar speedbar-file-regexp nil
692 "Regular expression matching files we know how to expand.
693 Created from `speedbar-supported-extension-expressions' with the
694 function `speedbar-extension-list-to-regex'.")
696 ;; this is dangerous to customize, because the defaults will probably
697 ;; change in the future.
698 (defcustom speedbar-supported-extension-expressions
699 (append '(".[ch]\\(\\+\\+\\|pp\\|c\\|h\\|xx\\)?" ".tex\\(i\\(nfo\\)?\\)?"
700 ".el" ".emacs" ".l" ".lsp" ".p" ".java" ".js" ".f\\(90\\|77\\|or\\)?")
701 (if speedbar-use-imenu-flag
702 '(".ad[abs]" ".p[lm]" ".tcl" ".m" ".scm" ".pm" ".py" ".g"
703 ;; html is not supported by default, but an imenu tags package
704 ;; is available. Also, html files are nice to be able to see.
706 ".ma?k" "[Mm]akefile\\(\\.in\\)?")))
707 "List of regular expressions which will match files supported by tagging.
708 Do not prefix the `.' char with a double \\ to quote it, as the period
709 will be stripped by a simplified optimizer when compiled into a
710 singular expression. This variable will be turned into
711 `speedbar-file-regexp' for use with speedbar. You should use the
712 function `speedbar-add-supported-extension' to add a new extension at
713 runtime, or use the configuration dialog to set it in your init file.
714 If you add an extension to this list, and it does not appear, you may
715 need to also modify `completion-ignored-extension' which will also help
718 :type
'(repeat (regexp :tag
"Extension Regexp"))
719 :set
(lambda (_sym val
)
720 (set 'speedbar-supported-extension-expressions val
)
721 (set 'speedbar-file-regexp
(speedbar-extension-list-to-regex val
))))
723 (setq speedbar-file-regexp
724 (speedbar-extension-list-to-regex speedbar-supported-extension-expressions
))
726 (defun speedbar-add-supported-extension (extension)
727 "Add EXTENSION as a new supported extension for speedbar tagging.
728 This should start with a `.' if it is not a complete file name, and
729 the dot should NOT be quoted in with \\. Other regular expression
730 matchers are allowed however. EXTENSION may be a single string or a
732 (interactive "sExtension: ")
733 (if (not (listp extension
)) (setq extension
(list extension
)))
735 (if (member (car extension
) speedbar-supported-extension-expressions
)
737 (setq speedbar-supported-extension-expressions
738 (cons (car extension
) speedbar-supported-extension-expressions
)))
739 (setq extension
(cdr extension
)))
740 (setq speedbar-file-regexp
(speedbar-extension-list-to-regex
741 speedbar-supported-extension-expressions
)))
743 (defun speedbar-add-ignored-directory-regexp (directory-expression)
744 "Add DIRECTORY-EXPRESSION as a new ignored directory for speedbar tracking.
745 This function will modify `speedbar-ignored-directory-regexp' and add
746 DIRECTORY-EXPRESSION to `speedbar-ignored-directory-expressions'."
747 (interactive "sDirectory regex: ")
748 (if (not (listp directory-expression
))
749 (setq directory-expression
(list directory-expression
)))
750 (while directory-expression
751 (if (member (car directory-expression
) speedbar-ignored-directory-expressions
)
753 (setq speedbar-ignored-directory-expressions
754 (cons (car directory-expression
) speedbar-ignored-directory-expressions
)))
755 (setq directory-expression
(cdr directory-expression
)))
756 (setq speedbar-ignored-directory-regexp
(speedbar-extension-list-to-regex
757 speedbar-ignored-directory-expressions
)))
759 ;; If we don't have custom, then we set it here by hand.
760 (if (not (fboundp 'custom-declare-variable
))
761 (setq speedbar-file-regexp
(speedbar-extension-list-to-regex
762 speedbar-supported-extension-expressions
)
763 speedbar-ignored-directory-regexp
(speedbar-extension-list-to-regex
764 speedbar-ignored-directory-expressions
)))
766 (defcustom speedbar-update-flag dframe-have-timer-flag
767 "Non-nil means to automatically update the display.
768 When this is nil then speedbar will not follow the attached frame's directory.
769 If you want to change this while speedbar is active, either use
770 \\[customize] or call \\<speedbar-mode-map> `\\[speedbar-toggle-updates]'."
772 :initialize
'custom-initialize-default
773 :set
(lambda (sym val
)
775 (speedbar-toggle-updates))
778 (defvar speedbar-update-flag-disable nil
779 "Permanently disable changing of the update flag.")
781 (define-obsolete-variable-alias
782 'speedbar-syntax-table
'speedbar-mode-syntax-table
"24.1")
783 (defvar speedbar-mode-syntax-table
784 (let ((st (make-syntax-table)))
785 ;; Turn off paren matching around here.
786 (modify-syntax-entry ?
\' " " st
)
787 (modify-syntax-entry ?
\" " " st
)
788 (modify-syntax-entry ?\
( " " st
)
789 (modify-syntax-entry ?\
) " " st
)
790 (modify-syntax-entry ?\
{ " " st
)
791 (modify-syntax-entry ?\
} " " st
)
792 (modify-syntax-entry ?\
[ " " st
)
793 (modify-syntax-entry ?\
] " " st
)
795 "Syntax-table used on the speedbar.")
798 (define-obsolete-variable-alias 'speedbar-key-map
'speedbar-mode-map
"24.1")
799 (defvar speedbar-mode-map
800 (let ((map (make-keymap)))
801 (suppress-keymap map t
)
804 (define-key map
"t" 'speedbar-toggle-updates
)
805 (define-key map
"g" 'speedbar-refresh
)
808 (define-key map
"n" 'speedbar-next
)
809 (define-key map
"p" 'speedbar-prev
)
810 (define-key map
"\M-n" 'speedbar-restricted-next
)
811 (define-key map
"\M-p" 'speedbar-restricted-prev
)
812 (define-key map
"\C-\M-n" 'speedbar-forward-list
)
813 (define-key map
"\C-\M-p" 'speedbar-backward-list
)
814 ;; These commands never seemed useful.
815 ;; (define-key map " " 'speedbar-scroll-up)
816 ;; (define-key map [delete] 'speedbar-scroll-down)
818 ;; Short cuts I happen to find useful.
820 (lambda () (interactive)
821 (speedbar-change-initial-expansion-list
822 speedbar-previously-used-expansion-list-name
)))
824 (lambda () (interactive)
825 (speedbar-change-initial-expansion-list "quick buffers")))
827 (lambda () (interactive)
828 (speedbar-change-initial-expansion-list "files")))
830 (dframe-update-keymap map
)
832 "Keymap used in speedbar buffer.")
834 (defun speedbar-make-specialized-keymap ()
835 "Create a keymap for use with a speedbar major or minor display mode.
836 This basically creates a sparse keymap, and makes its parent be
837 `speedbar-mode-map'."
838 (let ((k (make-sparse-keymap)))
839 (set-keymap-parent k speedbar-mode-map
)
842 (defvar speedbar-file-key-map
843 (let ((map (speedbar-make-specialized-keymap)))
845 ;; Basic tree features.
846 (define-key map
"e" 'speedbar-edit-line
)
847 (define-key map
"\C-m" 'speedbar-edit-line
)
848 (define-key map
"+" 'speedbar-expand-line
)
849 (define-key map
"=" 'speedbar-expand-line
)
850 (define-key map
"-" 'speedbar-contract-line
)
852 (define-key map
"[" 'speedbar-expand-line-descendants
)
853 (define-key map
"]" 'speedbar-contract-line-descendants
)
855 (define-key map
" " 'speedbar-toggle-line-expansion
)
857 ;; File based commands.
858 (define-key map
"U" 'speedbar-up-directory
)
859 (define-key map
"I" 'speedbar-item-info
)
860 (define-key map
"B" 'speedbar-item-byte-compile
)
861 (define-key map
"L" 'speedbar-item-load
)
862 (define-key map
"C" 'speedbar-item-copy
)
863 (define-key map
"D" 'speedbar-item-delete
)
864 (define-key map
"O" 'speedbar-item-object-delete
)
865 (define-key map
"R" 'speedbar-item-rename
)
866 (define-key map
"M" 'speedbar-create-directory
)
868 "Keymap used in speedbar buffer while files are displayed.")
870 (defvar speedbar-easymenu-definition-base
873 ["Update" speedbar-refresh t
]
874 ["Auto Update" speedbar-toggle-updates
875 :active
(not speedbar-update-flag-disable
)
876 :style toggle
:selected speedbar-update-flag
])
877 (if (and (or (fboundp 'defimage
)
878 (fboundp 'make-image-specifier
))
879 (if (fboundp 'display-graphic-p
)
883 ["Use Images" speedbar-toggle-images
884 :style toggle
:selected speedbar-use-images
]))
886 "Base part of the speedbar menu.")
888 (defvar speedbar-easymenu-definition-special
889 '(["Edit Item On Line" speedbar-edit-line t
]
890 ["Show All Files" speedbar-toggle-show-all-files
891 :style toggle
:selected speedbar-show-unknown-files
]
892 ["Expand File Tags" speedbar-expand-line
893 (save-excursion (beginning-of-line)
894 (looking-at "[0-9]+: *.\\+. "))]
895 ["Flush Cache & Expand" speedbar-flush-expand-line
896 (save-excursion (beginning-of-line)
897 (looking-at "[0-9]+: *.\\+. "))]
898 ["Expand All Descendants" speedbar-expand-line-descendants
899 (save-excursion (beginning-of-line)
900 (looking-at "[0-9]+: *.\\+. ")) ]
901 ["Contract File Tags" speedbar-contract-line
902 (save-excursion (beginning-of-line)
903 (looking-at "[0-9]+: *.-. "))]
904 ; ["Sort Tags" speedbar-toggle-sorting
905 ; :style toggle :selected speedbar-sort-tags]
907 ["File/Tag Information" speedbar-item-info t
]
908 ["Load Lisp File" speedbar-item-load
911 (looking-at "[0-9]+: *\\[[+-]\\] .+\\(\\.el\\)\\( \\|$\\)"))]
912 ["Byte Compile File" speedbar-item-byte-compile
915 (looking-at "[0-9]+: *\\[[+-]\\] .+\\(\\.el\\)\\( \\|$\\)"))]
916 ["Copy File" speedbar-item-copy
917 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *\\["))]
918 ["Rename File" speedbar-item-rename
919 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
920 ["Create Directory" speedbar-create-directory
921 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
922 ["Delete File" speedbar-item-delete
923 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
924 ["Delete Object" speedbar-item-object-delete
925 (save-excursion (beginning-of-line)
926 (looking-at "[0-9]+: *\\[[+-]\\] [^ \n]+ \\*?[!#]$"))]
928 "Additional menu items while in file-mode.")
930 (defvar speedbar-easymenu-definition-trailer
932 (if (and (featurep 'custom
) (fboundp 'custom-declare-variable
))
933 (list ["Customize..." speedbar-customize t
]))
935 ["Close" dframe-close-frame t
]
936 ["Quit" delete-frame t
] ))
937 "Menu items appearing at the end of the speedbar menu.")
939 (defvar speedbar-desired-buffer nil
940 "Non-nil when speedbar is showing buttons specific to a special mode.
941 In this case it is the originating buffer.")
942 (defvar speedbar-buffer nil
943 "The buffer displaying the speedbar.")
944 (defvar speedbar-frame nil
945 "The frame displaying speedbar.")
946 (defvar speedbar-cached-frame nil
947 "The frame that was last created, then removed from the display.")
948 (defvar speedbar-full-text-cache nil
949 "The last open directory is saved in its entirety for ultra-fast switching.")
951 (defvar speedbar-last-selected-file nil
952 "The last file which was selected in speedbar buffer.")
954 (defvar speedbar-shown-directories nil
955 "Maintain list of directories simultaneously open in the current speedbar.")
957 (defvar speedbar-directory-contents-alist nil
958 "An association list of directories and their contents.
959 Each sublist was returned by `speedbar-file-lists'. This list is
960 maintained to speed up the refresh rate when switching between
963 (defvar speedbar-power-click nil
964 "Never set this by hand. Value is t when S-mouse activity occurs.")
969 (defalias 'speedbar-make-overlay
970 (if (featurep 'xemacs
) 'make-extent
'make-overlay
))
972 (defalias 'speedbar-overlay-put
973 (if (featurep 'xemacs
) 'set-extent-property
'overlay-put
))
975 (defalias 'speedbar-delete-overlay
976 (if (featurep 'xemacs
) 'delete-extent
'delete-overlay
))
978 (defalias 'speedbar-mode-line-update
979 (if (featurep 'xemacs
) 'redraw-modeline
'force-mode-line-update
))
981 ;;; Mode definitions/ user commands
985 (defalias 'speedbar
'speedbar-frame-mode
)
987 (defun speedbar-frame-mode (&optional arg
)
988 "Enable or disable speedbar. Positive ARG means turn on, negative turn off.
989 A nil ARG means toggle. Once the speedbar frame is activated, a buffer in
990 `speedbar-mode' will be displayed. Currently, only one speedbar is
992 `speedbar-before-popup-hook' is called before popping up the speedbar frame.
993 `speedbar-before-delete-hook' is called before the frame is deleted."
995 ;; Get the buffer to play with
996 (if (not (buffer-live-p speedbar-buffer
))
998 (setq speedbar-buffer
(get-buffer-create " SPEEDBAR"))
999 (set-buffer speedbar-buffer
)
1001 ;; Do the frame thing
1002 (dframe-frame-mode arg
1004 'speedbar-cached-frame
1007 #'speedbar-frame-mode
1008 (if (featurep 'xemacs
)
1009 (append speedbar-frame-plist
1010 ;; This is a hack to get speedbar to iconify
1011 ;; with the selected frame.
1012 (list 'parent
(selected-frame)))
1013 speedbar-frame-parameters
)
1014 'speedbar-before-delete-hook
1015 'speedbar-before-popup-hook
1016 'speedbar-after-create-hook
)
1017 ;; Start up the timer
1018 (if (not speedbar-frame
)
1019 (speedbar-set-timer nil
)
1020 (speedbar-reconfigure-keymaps)
1021 (speedbar-update-contents)
1022 (speedbar-set-timer dframe-update-speed
)
1024 ;; Frame modifications
1025 (set (make-local-variable 'dframe-delete-frame-function
)
1026 'speedbar-handle-delete-frame
)
1028 (set (make-local-variable 'auto-hscroll-mode
) nil
)
1029 ;; reset the selection variable
1030 (setq speedbar-last-selected-file nil
))
1032 (defun speedbar-frame-reposition-smartly ()
1033 "Reposition the speedbar frame to be next to the attached frame."
1034 (cond ((and (featurep 'xemacs
)
1035 (or (member 'left speedbar-frame-plist
)
1036 (member 'top speedbar-frame-plist
)))
1037 (dframe-reposition-frame
1039 (dframe-attached-frame speedbar-frame
)
1040 (cons (car (cdr (member 'left speedbar-frame-plist
)))
1041 (car (cdr (member 'top speedbar-frame-plist
)))))
1043 ((and (not (featurep 'xemacs
))
1044 (or (assoc 'left speedbar-frame-parameters
)
1045 (assoc 'top speedbar-frame-parameters
)))
1046 ;; if left/top were specified in the parameters, pass them
1047 ;; down to the reposition function
1048 (dframe-reposition-frame
1050 (dframe-attached-frame speedbar-frame
)
1051 (cons (cdr (assoc 'left speedbar-frame-parameters
))
1052 (cdr (assoc 'top speedbar-frame-parameters
))))
1055 (dframe-reposition-frame speedbar-frame
1056 (dframe-attached-frame speedbar-frame
)
1057 speedbar-default-position
))))
1059 (defsubst speedbar-current-frame
()
1060 "Return the frame to use for speedbar based on current context."
1061 (dframe-current-frame 'speedbar-frame
'speedbar-mode
))
1063 (defun speedbar-handle-delete-frame (e)
1064 "Handle a delete frame event E.
1065 If the deleted frame is the frame speedbar is attached to,
1066 we need to delete speedbar also."
1067 (when (and speedbar-frame
1068 (eq (car (car (cdr e
))) ;; frame to be deleted
1069 dframe-attached-frame
))
1070 (delete-frame speedbar-frame
)))
1073 (defun speedbar-get-focus ()
1074 "Change frame focus to or from the speedbar frame.
1075 If the selected frame is not speedbar, then speedbar frame is
1076 selected. If the speedbar frame is active, then select the attached frame."
1078 (speedbar-reset-scanners)
1079 (dframe-get-focus 'speedbar-frame
'speedbar-frame-mode
)
1080 (let ((speedbar-update-flag t
))
1081 (speedbar-timer-fn)))
1083 (defsubst speedbar-frame-width
()
1084 "Return the width of the speedbar frame in characters.
1085 Return nil if it doesn't exist."
1086 (frame-width speedbar-frame
))
1088 (define-derived-mode speedbar-mode fundamental-mode
"Speedbar"
1089 "Major mode for managing a display of directories and tags.
1090 \\<speedbar-mode-map>
1091 The first line represents the default directory of the speedbar frame.
1092 Each directory segment is a button which jumps speedbar's default
1093 directory to that directory. Buttons are activated by clicking `\\[speedbar-click]'.
1094 In some situations using `\\[dframe-power-click]' is a `power click' which will
1095 rescan cached items, or pop up new frames.
1097 Each line starting with <+> represents a directory. Click on the <+>
1098 to insert the directory listing into the current tree. Click on the
1099 <-> to retract that list. Click on the directory name to go to that
1100 directory as the default.
1102 Each line starting with [+] is a file. If the variable
1103 `speedbar-show-unknown-files' is t, the lines starting with [?] are
1104 files which don't have imenu support, but are not expressly ignored.
1105 Files are completely ignored if they match `speedbar-file-unshown-regexp'
1106 which is generated from `completion-ignored-extensions'.
1108 Files with a `*' character after their name are files checked out of a
1109 version control system. (Currently only RCS is supported.) New
1110 version control systems can be added by examining the documentation
1111 for `speedbar-this-file-in-vc' and `speedbar-vc-check-dir-p'.
1113 Files with a `#' or `!' character after them are source files that
1114 have an object file associated with them. The `!' indicates that the
1115 files is out of date. You can control what source/object associations
1116 exist through the variable `speedbar-obj-alist'.
1118 Click on the [+] to display a list of tags from that file. Click on
1119 the [-] to retract the list. Click on the file name to edit the file
1120 in the attached frame.
1122 If you open tags, you might find a node starting with {+}, which is a
1123 category of tags. Click the {+} to expand the category. Jump-able
1124 tags start with >. Click the name of the tag to go to that position
1125 in the selected file.
1127 \\{speedbar-mode-map}"
1129 (setq font-lock-keywords nil
) ;; no font-locking please
1130 (setq truncate-lines t
)
1131 (make-local-variable 'frame-title-format
)
1132 (setq frame-title-format
(concat "Speedbar " speedbar-version
)
1133 case-fold-search nil
1135 (speedbar-set-mode-line-format)
1136 ;; Add in our dframe hooks.
1137 (if speedbar-track-mouse-flag
1138 (setq dframe-track-mouse-function
#'speedbar-track-mouse
))
1139 (setq dframe-help-echo-function
#'speedbar-item-info
1140 dframe-mouse-click-function
#'speedbar-click
1141 dframe-mouse-position-function
#'speedbar-position-cursor-on-line
))
1144 (define-obsolete-function-alias 'speedbar-message
'dframe-message
"24.4")
1146 (defsubst speedbar-y-or-n-p
(prompt &optional deleting
)
1147 "Like `y-or-n-p', but for use in the speedbar frame.
1148 Argument PROMPT is the prompt to use.
1149 Optional argument DELETING means this is a query that will delete something.
1150 The variable `speedbar-query-confirmation-method' can cause this to
1151 return true without a query."
1152 (or (and (not deleting
)
1153 (eq speedbar-query-confirmation-method
'none-but-delete
))
1154 (dframe-y-or-n-p prompt
)))
1156 (defsubst speedbar-select-attached-frame
()
1157 "Select the frame attached to this speedbar."
1158 (dframe-select-attached-frame (speedbar-current-frame)))
1160 ;; Backwards compatibility
1161 (define-obsolete-function-alias 'speedbar-with-attached-buffer
1162 'dframe-with-attached-buffer
"24.4") ; macro
1163 (define-obsolete-function-alias 'speedbar-maybee-jump-to-attached-frame
1164 'dframe-maybee-jump-to-attached-frame
"24.4")
1166 (defun speedbar-set-mode-line-format ()
1167 "Set the format of the mode line based on the current speedbar environment.
1168 This gives visual indications of what is up. It EXPECTS the speedbar
1169 frame and window to be the currently active frame and window."
1170 (if (and (frame-live-p (speedbar-current-frame))
1171 (or (not (featurep 'xemacs
))
1173 (specifier-instance has-modeline-p
)))
1175 (with-current-buffer speedbar-buffer
1176 (let* ((w (or (speedbar-frame-width) 20))
1179 (p3 (if speedbar-update-flag
"#" "!"))
1180 (p35 (capitalize speedbar-initial-expansion-list-name
))
1181 (blank (- w
(length p1
) (length p3
) (length p5
) (length p35
)
1182 (if line-number-mode
5 1)))
1184 (make-string (/ blank
2) ?
)
1187 (make-string (+ (/ blank
2) (% blank
2)) ?
)
1190 (if line-number-mode
1191 (list (concat p1 p2 p3
" " p35
) '(line-number-mode " %3l")
1193 (list (concat p1 p2 p3 p4 p5
)))))
1194 (if (not (equal mode-line-format tf
))
1196 (setq mode-line-format tf
)
1197 (speedbar-mode-line-update)))))))
1199 (defvar speedbar-previous-menu nil
1200 "The menu before the last `speedbar-reconfigure-keymaps' was called.")
1202 (defun speedbar-reconfigure-keymaps ()
1203 "Reconfigure the menu-bar in a speedbar frame.
1204 Different menu items are displayed depending on the current display mode
1205 and the existence of packages."
1207 speedbar-easymenu-definition-base
1208 (if speedbar-shown-directories
1209 ;; file display mode version
1210 (speedbar-initial-menu)
1212 (dframe-select-attached-frame speedbar-frame
)
1213 (eval (nth 1 (assoc speedbar-initial-expansion-list-name
1214 speedbar-initial-expansion-mode-alist
)))))
1215 ;; Dynamic menu stuff
1217 (list (cons "Displays"
1218 (let ((displays nil
)
1219 (alist speedbar-initial-expansion-mode-alist
))
1224 (capitalize (car (car alist
)))
1226 'speedbar-change-initial-expansion-list
1230 `(string= ,(car (car alist
))
1231 speedbar-initial-expansion-list-name
)
1234 (setq alist
(cdr alist
)))
1237 speedbar-easymenu-definition-trailer
))
1238 (localmap (save-excursion
1239 (let ((cf (selected-frame)))
1241 (dframe-select-attached-frame speedbar-frame
)
1242 (if (local-variable-p
1243 'speedbar-special-mode-key-map
1245 speedbar-special-mode-key-map
)
1246 (select-frame cf
))))))
1247 (with-current-buffer speedbar-buffer
1248 (use-local-map (or localmap
1249 (speedbar-initial-keymap)
1250 ;; This creates a small keymap we can glom the
1251 ;; menu adjustments into.
1252 (speedbar-make-specialized-keymap)))
1253 ;; Delete the old menu if applicable.
1254 (if speedbar-previous-menu
(easy-menu-remove speedbar-previous-menu
))
1255 (setq speedbar-previous-menu md
)
1256 ;; Now add the new menu
1257 (if (not (featurep 'xemacs
))
1258 (easy-menu-define speedbar-menu-map
(current-local-map)
1260 (easy-menu-add md
(current-local-map))
1262 (if (fboundp 'set-buffer-menubar
)
1263 (set-buffer-menubar (list md
)))))
1265 (run-hooks 'speedbar-reconfigure-keymaps-hook
)))
1268 ;;; User Input stuff
1270 (defun speedbar-customize ()
1271 "Customize speedbar using the Custom package."
1273 (let ((sf (selected-frame)))
1274 (dframe-select-attached-frame speedbar-frame
)
1275 (customize-group 'speedbar
)
1277 (dframe-maybee-jump-to-attached-frame))
1279 (defun speedbar-track-mouse (event)
1280 "For motion EVENT, display info about the current line."
1281 (if (not speedbar-track-mouse-flag
)
1284 (save-window-excursion
1287 (mouse-set-point event
)
1288 (if (eq major-mode
'speedbar-mode
)
1289 ;; XEmacs may let us get in here in other mode buffers.
1290 (speedbar-item-info)))
1291 (error (dframe-message nil
)))))))
1293 (defun speedbar-show-info-under-mouse ()
1294 "Call the info function for the line under the mouse."
1295 (let ((pos (mouse-position))) ; we ignore event until I use it later.
1296 (if (equal (car pos
) speedbar-frame
)
1298 (save-window-excursion
1299 (apply 'set-mouse-position pos
)
1300 (speedbar-item-info))))))
1302 (defun speedbar-next (arg)
1303 "Move to the next ARGth line in a speedbar buffer."
1305 (forward-line (or arg
1))
1306 (speedbar-item-info)
1307 (speedbar-position-cursor-on-line))
1309 (defun speedbar-prev (arg)
1310 "Move to the previous ARGth line in a speedbar buffer."
1312 (speedbar-next (if arg
(- arg
) -
1)))
1314 (defun speedbar-restricted-move (arg)
1315 "Move to the next ARGth line in a speedbar buffer at the same depth.
1316 This means that movement is restricted to a subnode, and that siblings
1317 of intermediate nodes are skipped."
1318 (if (not (numberp arg
)) (signal 'wrong-type-argument
(list 'numberp arg
)))
1319 ;; First find the extent for which we are allowed to move.
1320 (let ((depth (save-excursion (beginning-of-line)
1321 (if (looking-at "[0-9]+:")
1322 (string-to-number (match-string 0))
1324 (crement (if (< arg
0) 1 -
1)) ; decrement or increment
1325 (lastmatch (point)))
1327 (forward-line (- crement
))
1328 (let ((subdepth (save-excursion (beginning-of-line)
1329 (if (looking-at "[0-9]+:")
1330 (string-to-number (match-string 0))
1332 (cond ((or (< subdepth depth
)
1333 (progn (end-of-line) (eobp))
1334 (progn (beginning-of-line) (bobp)))
1335 ;; We have reached the end of this block.
1336 (goto-char lastmatch
)
1338 (error "End of sub-list"))
1340 (setq lastmatch
(point)
1341 arg
(+ arg crement
))))))
1342 (speedbar-position-cursor-on-line)))
1344 (defun speedbar-restricted-next (arg)
1345 "Move to the next ARGth line in a speedbar buffer at the same depth.
1346 This means that movement is restricted to a subnode, and that siblings
1347 of intermediate nodes are skipped."
1349 (speedbar-restricted-move (or arg
1))
1350 (speedbar-item-info))
1352 (defun speedbar-restricted-prev (arg)
1353 "Move to the previous ARGth line in a speedbar buffer at the same depth.
1354 This means that movement is restricted to a subnode, and that siblings
1355 of intermediate nodes are skipped."
1357 (speedbar-restricted-move (if arg
(- arg
) -
1))
1358 (speedbar-item-info))
1360 (defun speedbar-navigate-list (arg)
1361 "Move across ARG groups of similarly typed items in speedbar.
1362 Stop on the first line of the next type of item, or on the last or first item
1363 if we reach a buffer boundary."
1366 (if (looking-at "[0-9]+: *[[<{][-+?][]>}] ")
1367 (let ((str (regexp-quote (match-string 0))))
1368 (while (looking-at str
)
1369 (speedbar-restricted-move arg
)
1370 (beginning-of-line))))
1371 (speedbar-position-cursor-on-line))
1373 (defun speedbar-forward-list ()
1374 "Move forward over the current list.
1375 A LIST in speedbar is a group of similarly typed items, such as directories,
1376 files, or the directory button."
1378 (speedbar-navigate-list 1)
1379 (speedbar-item-info))
1381 (defun speedbar-backward-list ()
1382 "Move backward over the current list.
1383 A LIST in speedbar is a group of similarly typed items, such as directories,
1384 files, or the directory button."
1386 (speedbar-navigate-list -
1)
1387 (speedbar-item-info))
1389 (defun speedbar-scroll-up (&optional arg
)
1390 "Page down one screen-full of the speedbar, or ARG lines."
1393 (speedbar-position-cursor-on-line))
1395 (defun speedbar-scroll-down (&optional arg
)
1396 "Page up one screen-full of the speedbar, or ARG lines."
1399 (speedbar-position-cursor-on-line))
1401 (defun speedbar-up-directory ()
1402 "Keyboard accelerator for moving the default directory up one.
1403 Assumes that the current buffer is the speedbar buffer."
1405 (setq default-directory
(expand-file-name (concat default-directory
"../")))
1406 (speedbar-update-contents))
1408 ;;; Speedbar file activity (aka creeping featurism)
1410 (defun speedbar-refresh (&optional arg
)
1411 "Refresh the current speedbar display, disposing of any cached data.
1412 Argument ARG represents to force a refresh past any caches that may exist."
1414 (let ((dl speedbar-shown-directories
)
1415 (dframe-power-click arg
)
1417 ;; We need to hack something so this works in detached frames.
1419 (setq speedbar-directory-contents-alist
1420 (delq (assoc d speedbar-directory-contents-alist
)
1421 speedbar-directory-contents-alist
)))
1422 (if (<= 1 speedbar-verbosity-level
)
1423 (dframe-message "Refreshing speedbar..."))
1424 (speedbar-update-contents)
1425 (speedbar-stealthy-updates)
1426 ;; Reset the timer in case it got really hosed for some reason...
1427 (speedbar-set-timer dframe-update-speed
)
1428 (if (<= 1 speedbar-verbosity-level
)
1429 (dframe-message "Refreshing speedbar...done"))))
1431 (defun speedbar-item-load ()
1432 "Load the item under the cursor or mouse if it is a Lisp file."
1434 (let ((f (speedbar-line-file)))
1435 (if (and (file-exists-p f
) (string-match "\\.el\\'" f
))
1436 (if (and (file-exists-p (concat f
"c"))
1437 (speedbar-y-or-n-p (format "Load %sc? " f
)))
1438 ;; If the compiled version exists, load that instead...
1439 (load-file (concat f
"c"))
1441 (error "Not a loadable file"))))
1443 (defun speedbar-item-byte-compile ()
1444 "Byte compile the item under the cursor or mouse if it is a Lisp file."
1446 (let ((f (speedbar-line-file))
1447 (sf (selected-frame)))
1448 (if (and (file-exists-p f
) (string-match "\\.el\\'" f
))
1450 (dframe-select-attached-frame speedbar-frame
)
1451 (byte-compile-file f nil
)
1453 (speedbar-reset-scanners)))
1456 (defun speedbar-mouse-item-info (event)
1457 "Provide information about what the user clicked on.
1458 This should be bound to a mouse EVENT."
1460 (mouse-set-point event
)
1461 (speedbar-item-info))
1463 (defun speedbar-generic-item-info ()
1464 "Attempt to derive, and then display information about this line item.
1465 File style information is displayed with `speedbar-item-info'."
1468 ;; Skip invisible number info.
1469 (if (looking-at "\\([0-9]+\\):") (goto-char (match-end 0)))
1470 ;; Skip items in "folder" type text characters.
1471 (if (looking-at "\\s-*[[<({].[]>)}] ") (goto-char (match-end 0)))
1473 (dframe-message "Text: %s" (buffer-substring-no-properties
1474 (point) (line-end-position)))))
1476 (defun speedbar-item-info ()
1477 "Display info in the minibuffer about the button the mouse is over.
1478 This function can be replaced in `speedbar-mode-functions-list' as
1479 `speedbar-item-info'."
1481 (let (message-log-max)
1482 (funcall (or (speedbar-fetch-replacement-function 'speedbar-item-info
)
1483 'speedbar-generic-item-info
))))
1485 (defun speedbar-item-info-file-helper (&optional filename
)
1486 "Display info about a file that is on the current line.
1487 Return nil if not applicable. If FILENAME, then use that
1488 instead of reading it from the speedbar buffer."
1489 (let* ((item (or filename
(speedbar-line-file)))
1490 (attr (if item
(file-attributes item
) nil
)))
1491 (if (and item attr
) (dframe-message "%s %-6d %s" (nth 8 attr
)
1495 (defun speedbar-item-info-tag-helper ()
1496 "Display info about a tag that is on the current line.
1497 Return nil if not applicable."
1500 (if (re-search-forward " [-+=]?> \\([^\n]+\\)" (line-end-position) t
)
1501 (let* ((tag (match-string 1))
1502 (attr (speedbar-line-token))
1504 (semantic-tagged (if (fboundp 'semantic-tag-p
)
1505 (semantic-tag-p attr
))))
1509 (when (and (semantic-tag-overlay attr
)
1510 (semantic-tag-buffer attr
))
1511 (set-buffer (semantic-tag-buffer attr
)))
1513 (funcall semantic-sb-info-format-tag-function attr
)
1515 (looking-at "\\([0-9]+\\):")
1516 (setq item
(file-name-nondirectory (speedbar-line-directory)))
1517 (dframe-message "Tag: %s in %s" tag item
)))
1518 (if (re-search-forward "{[+-]} \\([^\n]+\\)$" (line-end-position) t
)
1519 (dframe-message "Group of tags \"%s\"" (match-string 1))
1520 (if (re-search-forward " [+-]?[()|@] \\([^\n]+\\)$" nil t
)
1521 (let* ((detailtext (match-string 1))
1522 (detail (or (speedbar-line-token) detailtext
))
1523 (parent (save-excursion
1525 (let ((dep (if (looking-at "[0-9]+:")
1526 (1- (string-to-number (match-string 0)))
1528 (re-search-backward (concat "^"
1532 (if (looking-at "[0-9]+: +[-+=>]> \\([^\n]+\\)$")
1533 (speedbar-line-token)
1535 (if (featurep 'semantic
)
1537 (if (semantic-tag-p detail
)
1539 (funcall semantic-sb-info-format-tag-function detail parent
))
1541 (dframe-message "Detail: %s of tag %s" detail
1542 (if (semantic-tag-p parent
)
1543 (semantic-format-tag-name parent nil t
)
1545 (dframe-message "Detail: %s" detail
))))
1546 ;; Not using `semantic':
1548 (dframe-message "Detail: %s of tag %s" detail parent
)
1549 (dframe-message "Detail: %s" detail
))))
1552 (defun speedbar-files-item-info ()
1553 "Display info in the minibuffer about the button the mouse is over."
1554 (if (not speedbar-shown-directories
)
1555 (speedbar-generic-item-info)
1556 (or (speedbar-item-info-file-helper)
1557 (speedbar-item-info-tag-helper)
1558 (speedbar-generic-item-info))))
1560 (defun speedbar-item-copy ()
1561 "Copy the item under the cursor.
1562 Files can be copied to new names or places."
1564 (let ((f (speedbar-line-file)))
1565 (if (not f
) (error "Not a file"))
1566 (if (file-directory-p f
)
1567 (error "Cannot copy directory")
1568 (let* ((rt (read-file-name (format "Copy %s to: "
1569 (file-name-nondirectory f
))
1570 (file-name-directory f
)))
1571 (refresh (member (expand-file-name (file-name-directory rt
))
1572 speedbar-shown-directories
)))
1573 ;; Create the right file name part
1574 (if (file-directory-p rt
)
1576 (concat (expand-file-name rt
)
1577 (if (string-match "[/\\]$" rt
) "" "/")
1578 (file-name-nondirectory f
))))
1579 (if (or (not (file-exists-p rt
))
1580 (speedbar-y-or-n-p (format "Overwrite %s with %s? " rt f
)
1583 (copy-file f rt t t
)
1584 ;; refresh display if the new place is currently displayed.
1588 (if (not (speedbar-goto-this-file rt
))
1589 (speedbar-goto-this-file f
))))
1592 (defun speedbar-item-rename ()
1593 "Rename the item under the cursor or mouse.
1594 Files can be renamed to new names or moved to new directories."
1596 (let ((f (speedbar-line-file)))
1598 (let* ((rt (read-file-name (format "Rename %s to: "
1599 (file-name-nondirectory f
))
1600 (file-name-directory f
)))
1601 (refresh (member (expand-file-name (file-name-directory rt
))
1602 speedbar-shown-directories
)))
1603 ;; Create the right file name part
1604 (if (file-directory-p rt
)
1606 (concat (expand-file-name rt
)
1607 (if (string-match "[/\\]\\'" rt
) "" "/")
1608 (file-name-nondirectory f
))))
1609 (if (or (not (file-exists-p rt
))
1610 (speedbar-y-or-n-p (format "Overwrite %s with %s? " rt f
)
1613 (rename-file f rt t
)
1614 ;; refresh display if the new place is currently displayed.
1618 (speedbar-goto-this-file rt
)
1620 (error "Not a file"))))
1622 (defun speedbar-create-directory ()
1623 "Create a directory in speedbar."
1625 (let ((f (speedbar-line-file)))
1627 (let* ((basedir (file-name-directory f
))
1628 (nd (read-directory-name "Create directory: "
1630 ;; Make the directory
1631 (make-directory nd t
)
1633 (speedbar-goto-this-file nd
)
1635 (error "Not a file"))))
1637 (defun speedbar-item-delete ()
1638 "Delete the item under the cursor. Files are removed from disk."
1640 (let ((f (speedbar-line-file)))
1641 (if (not f
) (error "Not a file"))
1642 (if (speedbar-y-or-n-p (format "Delete %s? " f
) t
)
1644 (if (file-directory-p f
)
1645 (delete-directory f t t
)
1647 (dframe-message "Okie dokie.")
1654 (defun speedbar-item-object-delete ()
1655 "Delete the object associated from the item under the cursor.
1656 The file is removed from disk. The object is determined from the
1657 variable `speedbar-obj-alist'."
1659 (let* ((f (speedbar-line-file))
1661 (oa speedbar-obj-alist
))
1662 (if (not f
) (error "Not a file"))
1663 (while (and oa
(not (string-match (car (car oa
)) f
)))
1665 (setq obj
(concat (file-name-sans-extension f
) (cdr (car oa
))))
1666 (if (and oa
(file-exists-p obj
)
1667 (speedbar-y-or-n-p (format "Delete %s? " obj
) t
))
1670 (speedbar-reset-scanners)))))
1672 (defun speedbar-enable-update ()
1673 "Enable automatic updating in speedbar via timers."
1675 (setq speedbar-update-flag t
)
1676 (speedbar-set-mode-line-format)
1677 (speedbar-set-timer dframe-update-speed
))
1679 (defun speedbar-disable-update ()
1680 "Disable automatic updating and stop consuming resources."
1682 (setq speedbar-update-flag nil
)
1683 (speedbar-set-mode-line-format)
1684 (speedbar-set-timer nil
))
1686 (defun speedbar-toggle-updates ()
1687 "Toggle automatic update for the speedbar frame."
1689 (if speedbar-update-flag
1690 (speedbar-disable-update)
1691 (speedbar-enable-update)))
1693 (defun speedbar-toggle-images ()
1694 "Toggle use of images in the speedbar frame."
1696 (setq speedbar-use-images
(not speedbar-use-images
))
1699 (defun speedbar-toggle-sorting ()
1700 "Toggle tag sorting."
1702 (setq speedbar-sort-tags
(not speedbar-sort-tags
)))
1704 (defun speedbar-toggle-show-all-files ()
1705 "Toggle display of files speedbar can not tag."
1707 (setq speedbar-show-unknown-files
(not speedbar-show-unknown-files
))
1710 (defmacro speedbar-with-writable
(&rest forms
)
1711 "Allow the buffer to be writable and evaluate FORMS."
1712 (declare (indent 0))
1713 `(let ((inhibit-read-only t
))
1716 (defun speedbar-insert-button (text face mouse function
1717 &optional token prevline
)
1718 "Insert TEXT as the next logical speedbar button.
1719 FACE is the face to put on the button, MOUSE is the highlight face to use.
1720 When the user clicks on TEXT, FUNCTION is called with the TOKEN parameter.
1721 This function assumes that the current buffer is the speedbar buffer.
1722 If PREVLINE, then put this button on the previous line.
1724 This is a convenience function for special modes that create their own
1725 specialized speedbar displays."
1726 (goto-char (point-max))
1727 (let ((start (point)))
1728 (if (/= (current-column) 0) (insert "\n"))
1729 (put-text-property start
(point) 'invisible nil
))
1730 (if prevline
(progn (delete-char -
1)
1731 (insert " ") ;back up if desired...
1732 (put-text-property (1- (point)) (point) 'invisible nil
)))
1733 (let ((start (point)))
1735 (speedbar-make-button start
(point) face mouse function token
))
1736 (let ((start (point)))
1738 (add-text-properties
1739 start
(point) '(face nil invisible nil mouse-face nil
))))
1741 (defun speedbar-insert-separator (text)
1742 "Insert a separation label of TEXT.
1743 Separators are not active, have no labels, depth, or actions."
1744 (if speedbar-use-images
1745 (let ((start (point)))
1747 (speedbar-insert-image-button-maybe start
2)))
1748 (let ((start (point)))
1750 (speedbar-make-button start
(point)
1751 'speedbar-separator-face
1754 (defun speedbar-make-button (start end face mouse function
&optional token
)
1755 "Create a button from START to END, with FACE as the display face.
1756 MOUSE is the mouse face. When this button is clicked on FUNCTION
1757 will be run with the TOKEN parameter (any Lisp object). If FACE
1758 is t use the text properties of the string that is passed as an
1761 (put-text-property start end
'face face
))
1762 (add-text-properties
1763 start end
`(mouse-face ,mouse invisible nil
1764 speedbar-text
,(buffer-substring-no-properties start end
)))
1765 (if speedbar-use-tool-tips-flag
1766 (put-text-property start end
'help-echo
#'dframe-help-echo
))
1767 (if function
(put-text-property start end
'speedbar-function function
))
1768 (if token
(put-text-property start end
'speedbar-token token
))
1769 ;; So far the only text we have is less that 3 chars.
1770 (if (<= (- end start
) 3)
1771 (speedbar-insert-image-button-maybe start
(- end start
)))
1774 ;;; Initial Expansion list management
1776 (defun speedbar-initial-expansion-list ()
1777 "Return the current default expansion list.
1778 This is based on `speedbar-initial-expansion-list-name' referencing
1779 `speedbar-initial-expansion-mode-alist'."
1780 ;; cdr1 - name, cdr2 - menu
1781 (cdr (cdr (cdr (assoc speedbar-initial-expansion-list-name
1782 speedbar-initial-expansion-mode-alist
)))))
1784 (defun speedbar-initial-menu ()
1785 "Return the current default menu data.
1786 This is based on `speedbar-initial-expansion-list-name' referencing
1787 `speedbar-initial-expansion-mode-alist'."
1789 (car (cdr (assoc speedbar-initial-expansion-list-name
1790 speedbar-initial-expansion-mode-alist
)))))
1792 (defun speedbar-initial-keymap ()
1793 "Return the current default menu data.
1794 This is based on `speedbar-initial-expansion-list-name' referencing
1795 `speedbar-initial-expansion-mode-alist'."
1797 (car (cdr (cdr (assoc speedbar-initial-expansion-list-name
1798 speedbar-initial-expansion-mode-alist
))))))
1800 (defun speedbar-initial-stealthy-functions ()
1801 "Return a list of functions to call stealthily.
1802 This is based on `speedbar-initial-expansion-list-name' referencing
1803 `speedbar-stealthy-function-list'."
1804 (cdr (assoc speedbar-initial-expansion-list-name
1805 speedbar-stealthy-function-list
)))
1807 (defun speedbar-add-expansion-list (new-list)
1808 "Add NEW-LIST to the list of expansion lists."
1809 (add-to-list 'speedbar-initial-expansion-mode-alist new-list
))
1811 (defun speedbar-change-initial-expansion-list (new-default)
1812 "Change speedbar's default expansion list to NEW-DEFAULT."
1815 (completing-read (format "Speedbar Mode (default %s): "
1816 speedbar-previously-used-expansion-list-name
)
1817 speedbar-initial-expansion-mode-alist
1819 speedbar-previously-used-expansion-list-name
)))
1820 (setq speedbar-previously-used-expansion-list-name
1821 speedbar-initial-expansion-list-name
1822 speedbar-initial-expansion-list-name new-default
)
1823 (if (and (speedbar-current-frame) (frame-live-p (speedbar-current-frame)))
1826 (speedbar-reconfigure-keymaps))))
1828 (defun speedbar-fetch-replacement-function (function)
1829 "Return a current mode-specific replacement for function, or nil.
1830 Scans `speedbar-mode-functions-list' first for the current mode, then
1832 (cdr (assoc function
1833 (cdr (assoc speedbar-initial-expansion-list-name
1834 speedbar-mode-functions-list
)))))
1836 (defun speedbar-add-mode-functions-list (new-list)
1837 "Add NEW-LIST to the list of mode functions.
1838 See `speedbar-mode-functions-list' for details."
1839 (add-to-list 'speedbar-mode-functions-list new-list
))
1842 ;;; Special speedbar display management
1844 (defun speedbar-maybe-add-localized-support (buffer)
1845 "Quick check function called on BUFFERs by the speedbar timer function.
1846 Maintains the value of local variables which control speedbar's use
1847 of the special mode functions."
1848 (or speedbar-special-mode-expansion-list
1849 (speedbar-add-localized-speedbar-support buffer
)))
1851 (defun speedbar-add-localized-speedbar-support (buffer)
1852 "Add localized speedbar support to BUFFER's mode if it is available."
1853 (interactive "bBuffer: ")
1854 (if (stringp buffer
) (setq buffer
(get-buffer buffer
)))
1855 (if (not (buffer-live-p buffer
))
1857 (with-current-buffer buffer
1859 (let ((ms (symbol-name major-mode
)) v
)
1860 (if (not (string-match "-mode$" ms
))
1861 nil
;; do nothing to broken mode
1862 (setq ms
(substring ms
0 (match-beginning 0)))
1863 (setq v
(intern-soft (concat ms
"-speedbar-buttons")))
1864 (make-local-variable 'speedbar-special-mode-expansion-list
)
1866 (setq speedbar-special-mode-expansion-list t
)
1867 ;; If it is autoloaded, we need to load it now so that
1868 ;; we have access to the variable -speedbar-menu-items.
1869 ;; Is this XEmacs safe?
1870 (autoload-do-load (symbol-function v
) v
)
1871 (setq speedbar-special-mode-expansion-list
(list v
))
1872 (setq v
(intern-soft (concat ms
"-speedbar-key-map")))
1874 nil
;; don't add special keymap
1875 (make-local-variable 'speedbar-special-mode-key-map
)
1876 (setq speedbar-special-mode-key-map
1878 (setq v
(intern-soft (concat ms
"-speedbar-menu-items")))
1880 nil
;; don't add special menus
1881 (make-local-variable 'speedbar-easymenu-definition-special
)
1882 (setq speedbar-easymenu-definition-special
1886 (defun speedbar-remove-localized-speedbar-support (buffer)
1887 "Remove any traces that BUFFER supports speedbar in a specialized way."
1888 (with-current-buffer buffer
1889 (kill-local-variable 'speedbar-special-mode-expansion-list
)
1890 (kill-local-variable 'speedbar-special-mode-key-map
)
1891 (kill-local-variable 'speedbar-easymenu-definition-special
)))
1893 ;;; File button management
1895 (defun speedbar-file-lists (directory)
1896 "Create file lists for DIRECTORY.
1897 The car is the list of directories, the cdr is list of files not
1898 matching ignored headers. Cache any directory files found in
1899 `speedbar-directory-contents-alist' and use that cache before scanning
1901 (setq directory
(expand-file-name directory
))
1902 ;; find the directory, either in the cache, or build it.
1903 (or (and (not dframe-power-click
) ;; In powerclick mode, always rescan.
1904 (cdr-safe (assoc directory speedbar-directory-contents-alist
)))
1905 (let ((default-directory directory
)
1906 (dir (directory-files directory nil
))
1911 (or (string-match speedbar-file-unshown-regexp
(car dir
))
1912 (member (car dir
) vc-directory-exclusion-list
)
1913 (string-match speedbar-directory-unshown-regexp
(car dir
))))
1914 (if (file-directory-p (car dir
))
1915 (setq dirs
(cons (car dir
) dirs
))
1916 (setq files
(cons (car dir
) files
))))
1917 (setq dir
(cdr dir
)))
1918 (let ((nl (cons (nreverse dirs
) (list (nreverse files
))))
1919 (ae (assoc directory speedbar-directory-contents-alist
)))
1920 (if ae
(setcdr ae nl
)
1921 (push (cons directory nl
)
1922 speedbar-directory-contents-alist
))
1926 (defun speedbar-directory-buttons (directory _index
)
1927 "Insert a single button group at point for DIRECTORY.
1928 Each directory part is a different button. If part of the directory
1929 matches the user directory ~, then it is replaced with a ~.
1930 INDEX is not used, but is required by the caller."
1931 (let* ((tilde (expand-file-name "~/"))
1932 (dd (expand-file-name directory
))
1933 (junk (string-match (regexp-quote tilde
) dd
))
1935 (concat "~/" (substring dd
(match-end 0)))
1938 (if (string-match "^~[/\\]?\\'" displayme
) (setq displayme tilde
))
1942 (while (re-search-forward "\\([^/\\]+\\)[/\\]" nil t
)
1943 (speedbar-make-button (match-beginning 1) (match-end 1)
1944 'speedbar-directory-face
1945 'speedbar-highlight-face
1946 'speedbar-directory-buttons-follow
1947 (if (and (= (match-beginning 1) p
)
1948 (not (char-equal (char-after (+ p
1)) ?
:)))
1949 (expand-file-name "~/") ;the tilde
1950 (buffer-substring-no-properties
1952 ;; Nuke the beginning of the directory if it's too long...
1953 (cond ((eq speedbar-directory-button-trim-method
'span
)
1955 (let ((ww (or (speedbar-frame-width) 20)))
1956 (move-to-column ww nil
)
1957 (while (>= (current-column) ww
)
1958 (re-search-backward "[/\\]" nil t
)
1959 (if (<= (current-column) 2)
1961 (re-search-forward "[/\\]" nil t
)
1962 (if (< (current-column) 4)
1963 (re-search-forward "[/\\]" nil t
))
1965 (if (looking-at "[/\\]?$")
1968 (move-to-column ww nil
)))))
1969 ((eq speedbar-directory-button-trim-method
'trim
)
1971 (let ((ww (or (speedbar-frame-width) 20))
1972 (tl (current-column)))
1975 (move-to-column (- tl ww
))
1976 (if (re-search-backward "[/\\]" nil t
)
1978 (delete-region (point-min) (point))
1982 (if (string-match "\\`[/\\][^/\\]+[/\\]\\'" displayme
)
1987 (speedbar-make-button p
(point)
1988 'speedbar-directory-face
1989 'speedbar-highlight-face
1990 'speedbar-directory-buttons-follow
1993 (insert-char ?
\n 1 nil
)))
1995 (defun speedbar-make-tag-line (exp-button-type
1996 exp-button-char exp-button-function
1998 tag-button tag-button-function tag-button-data
1999 tag-button-face depth
)
2000 "Create a tag line with EXP-BUTTON-TYPE for the small expansion button.
2001 This is the button that expands or contracts a node (if applicable),
2002 and EXP-BUTTON-CHAR the character in it (+, -, ?, etc). EXP-BUTTON-FUNCTION
2003 is the function to call if it's clicked on. Button types are
2004 'bracket, 'angle, 'curly, 'expandtag, 'statictag, t, or nil.
2005 EXP-BUTTON-DATA is extra data attached to the text forming the expansion
2008 Next, TAG-BUTTON is the text of the tag. TAG-BUTTON-FUNCTION is the
2009 function to call if clicked on, and TAG-BUTTON-DATA is the data to
2010 attach to the text field (such a tag positioning, etc).
2011 TAG-BUTTON-FACE is a face used for this type of tag.
2013 Lastly, DEPTH shows the depth of expansion.
2015 This function assumes that the cursor is in the speedbar window at the
2016 position to insert a new item, and that the new item will end with a CR."
2017 (let ((start (point))
2019 (insert (int-to-string depth
) ":")
2021 (depthspacesize (* depth speedbar-indentation-width
)))
2022 (put-text-property start end
'invisible t
)
2023 (insert-char ? depthspacesize nil
)
2024 (put-text-property (- (point) depthspacesize
) (point) 'invisible nil
)
2025 (let* ((exp-button (cond ((eq exp-button-type
'bracket
) "[%c]")
2026 ((eq exp-button-type
'angle
) "<%c>")
2027 ((eq exp-button-type
'curly
) "{%c}")
2028 ((eq exp-button-type
'expandtag
) " %c>")
2029 ((eq exp-button-type
'statictag
) " =>")
2031 (buttxt (format exp-button exp-button-char
))
2033 (end (progn (insert buttxt
) (point)))
2034 (bf (if (and exp-button-type
(not (eq exp-button-type
'statictag
)))
2035 'speedbar-button-face nil
))
2036 (mf (if exp-button-function
'speedbar-highlight-face nil
))
2038 (speedbar-make-button start end bf mf exp-button-function exp-button-data
)
2039 (if speedbar-hide-button-brackets-flag
2041 (put-text-property start
(1+ start
) 'invisible t
)
2042 (put-text-property end
(1- end
) 'invisible t
)))
2044 (insert-char ?
1 nil
)
2045 (put-text-property (1- (point)) (point) 'invisible nil
)
2046 (let ((start (point))
2047 (end (progn (insert tag-button
) (point))))
2048 (insert-char ?
\n 1 nil
)
2049 (put-text-property (1- (point)) (point) 'invisible nil
)
2050 (speedbar-make-button start end tag-button-face
2051 (if tag-button-function
'speedbar-highlight-face nil
)
2052 tag-button-function tag-button-data
))
2055 (defun speedbar-change-expand-button-char (char)
2056 "Change the expansion button character to CHAR for the current line."
2059 (if (re-search-forward ":\\s-*.\\([-+?]\\)" (line-end-position) t
)
2060 (speedbar-with-writable
2061 (goto-char (match-end 1))
2062 (insert-char char
1 t
)
2065 ;;(put-text-property (point) (1- (point)) 'invisible nil)
2066 ;; make sure we fix the image on the text here.
2067 (speedbar-insert-image-button-maybe (- (point) 1) 3)))))
2070 ;;; Build button lists
2072 (defun speedbar-insert-files-at-point (files level
)
2073 "Insert list of FILES starting at point, and indenting all files to LEVEL.
2074 Tag expandable items with a +, otherwise a ?. Don't highlight ? as we
2075 don't know how to manage them. The input parameter FILES is a cons
2076 cell of the form ( 'DIRLIST . 'FILELIST )."
2077 ;; Start inserting all the directories
2078 (let ((dirs (car files
)))
2080 (speedbar-make-tag-line 'angle ?
+ 'speedbar-dired
(car dirs
)
2081 (car dirs
) 'speedbar-dir-follow nil
2082 'speedbar-directory-face level
)
2083 (setq dirs
(cdr dirs
))))
2084 (let ((lst (car (cdr files
)))
2085 (case-fold-search t
))
2087 (let* ((known (string-match speedbar-file-regexp
(car lst
)))
2088 (expchar (if known ?
+ ??
))
2089 (fn (if known
'speedbar-tag-file nil
)))
2090 (if (or speedbar-show-unknown-files
(/= expchar ??
))
2091 (speedbar-make-tag-line 'bracket expchar fn
(car lst
)
2092 (car lst
) 'speedbar-find-file nil
2093 'speedbar-file-face level
)))
2094 (setq lst
(cdr lst
)))))
2096 (defun speedbar-default-directory-list (directory index
)
2097 "Insert files for DIRECTORY with level INDEX at point."
2098 (speedbar-insert-files-at-point
2099 (speedbar-file-lists directory
) index
)
2100 (speedbar-reset-scanners)
2102 ;; If the shown files variable has extra directories, then
2103 ;; it is our responsibility to redraw them all
2104 ;; Luckily, the nature of inserting items into this list means
2105 ;; that by reversing it, we can easily go in the right order
2106 (let ((sf (cdr (reverse speedbar-shown-directories
))))
2107 (setq speedbar-shown-directories
2108 (list (expand-file-name default-directory
)))
2109 ;; Expand them all as we find them.
2111 (if (speedbar-goto-this-file (car sf
))
2114 (if (looking-at "[0-9]+:[ ]*<")
2116 (goto-char (match-end 0))
2117 (speedbar-do-function-pointer)))))
2120 ;;; Generic List support
2122 ;; Generic lists are hierarchies of tags which we may need to permute
2123 ;; in order to make it look nice.
2125 ;; A generic list is of the form:
2126 ;; ( ("name" . marker-or-number) <-- one tag at this level
2127 ;; ("name" marker-or-number goto-fun . args) <-- one tag at this level
2128 ;; ("name" ("name" . mon) ("name" . mon) ) <-- one group of tags
2129 ;; ("name" mon ("name" . mon) ) <-- group w/ a position and tags
2130 (defun speedbar-generic-list-group-p (sublst)
2131 "Non-nil if SUBLST is a group.
2132 Groups may optionally contain a position."
2133 (and (stringp (car-safe sublst
))
2134 (or (and (listp (cdr-safe sublst
))
2135 (or (speedbar-generic-list-tag-p (car-safe (cdr-safe sublst
)))
2136 (speedbar-generic-list-group-p (car-safe (cdr-safe sublst
))
2138 (and (number-or-marker-p (car-safe (cdr-safe sublst
)))
2139 (listp (cdr-safe (cdr-safe sublst
)))
2140 (speedbar-generic-list-tag-p
2141 (car-safe (cdr-safe (cdr-safe sublst
)))))
2144 (defun speedbar-generic-list-positioned-group-p (sublst)
2145 "Non-nil if SUBLST is a group with a position."
2146 (and (stringp (car-safe sublst
))
2147 (number-or-marker-p (car-safe (cdr-safe sublst
)))
2148 (listp (cdr-safe (cdr-safe sublst
)))
2149 (let ((rest (car-safe (cdr-safe (cdr-safe sublst
)))))
2150 (or (speedbar-generic-list-tag-p rest
)
2151 (speedbar-generic-list-group-p rest
)
2152 (speedbar-generic-list-positioned-group-p rest
)
2155 (defun speedbar-generic-list-tag-p (sublst)
2156 "Non-nil if SUBLST is a tag."
2157 (and (stringp (car-safe sublst
))
2158 (or (and (number-or-marker-p (cdr-safe sublst
))
2159 (not (cdr-safe (cdr-safe sublst
))))
2160 (ignore-errors (and (number-or-marker-p (nth 1 sublst
))
2161 (functionp (nth 2 sublst
))))
2162 ;; For semantic/bovine items, this is needed
2163 (symbolp (car-safe (cdr-safe sublst
))))
2166 (defun speedbar-sort-tag-hierarchy (lst)
2167 "Sort all elements of tag hierarchy LST."
2168 (sort (copy-alist lst
)
2169 (lambda (a b
) (string< (car a
) (car b
)))))
2171 (defun speedbar-try-completion (string alist
)
2172 "A wrapper for `try-completion'.
2173 Passes STRING and ALIST to `try-completion' if ALIST
2175 (if (and (consp alist
)
2176 (listp (car alist
)) (stringp (car (car alist
))))
2177 (try-completion string alist
)
2180 (defun speedbar-prefix-group-tag-hierarchy (lst)
2181 "Prefix group names for tag hierarchy LST."
2186 (short-group-list nil
)
2187 (short-start-name nil
)
2188 (short-end-name nil
)
2189 (num-shorts-grouped 0)
2190 (bins (make-vector 256 nil
))
2192 (if (<= (length lst
) speedbar-tag-regroup-maximum-length
)
2193 ;; Do nothing. Too short to bother with.
2195 ;; Break out sub-lists
2197 (if (speedbar-generic-list-group-p (car-safe lst
))
2198 (setq newlst
(cons (car lst
) newlst
))
2199 (setq sublst
(cons (car lst
) sublst
)))
2200 (setq lst
(cdr lst
)))
2201 ;; Reverse newlst because it was made backwards.
2202 ;; Sublist doesn't need reversing because the act
2203 ;; of binning things will reverse it for us.
2204 (setq newlst
(nreverse newlst
)
2206 ;; Now, first find out how long our list is. Never let a
2207 ;; list get-shorter than our minimum.
2208 (if (<= (length sublst
) speedbar-tag-split-minimum-length
)
2209 (setq work-list sublst
)
2210 (setq diff-idx
(length (speedbar-try-completion "" sublst
)))
2211 ;; Sort the whole list into bins.
2213 (let ((e (car sublst
))
2214 (s (car (car sublst
))))
2215 (cond ((<= (length s
) diff-idx
)
2216 ;; 0 storage bin for shorty.
2217 (aset bins
0 (cons e
(aref bins
0))))
2219 ;; stuff into a bin based on ascii value at diff
2220 (aset bins
(aref s diff-idx
)
2221 (cons e
(aref bins
(aref s diff-idx
)))))))
2222 (setq sublst
(cdr sublst
)))
2223 ;; Go through all our bins Stick singles into our
2224 ;; junk-list, everything else as sublsts in work-list.
2225 ;; If two neighboring lists are both small, make a grouped
2226 ;; group combining those two sub-lists.
2228 (while (> 256 diff-idx
)
2229 ;; The bins contents are currently in forward order.
2230 (let ((l (aref bins diff-idx
)))
2232 (let ((tmp (cons (speedbar-try-completion "" l
) l
)))
2233 (if (or (> (length l
) speedbar-tag-regroup-maximum-length
)
2234 (> (+ (length l
) (length short-group-list
))
2235 speedbar-tag-split-minimum-length
))
2237 ;; We have reached a longer list, so we
2238 ;; must finish off a grouped group.
2240 ((and short-group-list
2241 (= (length short-group-list
)
2242 num-shorts-grouped
))
2243 ;; All singles? Junk list
2244 (setq junk-list
(append (nreverse short-group-list
)
2246 ((= num-shorts-grouped
1)
2247 ;; Only one short group? Just stick it in
2248 ;; there by itself. Make a group, and find
2250 (let ((subexpression (speedbar-try-completion
2251 "" short-group-list
)))
2252 (if (< (length subexpression
)
2253 speedbar-tag-group-name-minimum-length
)
2255 (concat short-start-name
2258 (car (car short-group-list
))
2259 (length short-start-name
))
2262 (cons (cons subexpression
2266 ;; Multiple groups to be named in a special
2267 ;; way by displaying the range over which we
2268 ;; have grouped them.
2270 (cons (cons (concat short-start-name
2275 ;; Reset short group list information every time.
2276 (setq short-group-list nil
2277 short-start-name nil
2279 num-shorts-grouped
0)))
2280 ;; Ok, now that we cleaned up the short-group-list,
2281 ;; we can deal with this new list, to decide if it
2282 ;; should go on one of these sub-lists or not.
2283 (if (< (length l
) speedbar-tag-regroup-maximum-length
)
2284 (setq short-group-list
(append l short-group-list
)
2285 num-shorts-grouped
(1+ num-shorts-grouped
)
2286 short-end-name
(car tmp
)
2287 short-start-name
(if short-start-name
2290 (setq work-list
(cons tmp work-list
))))))
2291 (setq diff-idx
(1+ diff-idx
))))
2292 ;; Did we run out of things? Drop our new list onto the end.
2294 ((and short-group-list
(= (length short-group-list
) num-shorts-grouped
))
2295 ;; All singles? Junk list
2296 (setq junk-list
(append short-group-list junk-list
)))
2297 ((= num-shorts-grouped
1)
2298 ;; Only one short group? Just stick it in
2301 (cons (cons (speedbar-try-completion "" short-group-list
)
2305 ;; Multiple groups to be named in a special
2306 ;; way by displaying the range over which we
2307 ;; have grouped them.
2309 (cons (cons (concat short-start-name
" to " short-end-name
)
2312 ;; Reverse the work list nreversed when consing.
2313 (setq work-list
(nreverse work-list
))
2314 ;; Now, stick our new list onto the end of
2317 (append newlst work-list junk-list
)
2318 (append newlst work-list
))
2319 (append newlst junk-list
)))))
2321 (defun speedbar-trim-words-tag-hierarchy (lst)
2322 "Trim all words in a tag hierarchy.
2323 Base trimming information on word separators, and group names.
2324 Argument LST is the list of tags to trim."
2331 (if (speedbar-generic-list-group-p (car-safe lst
))
2332 (setq newlst
(cons (car lst
) newlst
))
2333 (setq sublst
(cons (car lst
) sublst
)))
2334 (setq lst
(cdr lst
)))
2335 ;; Get the prefix to trim by. Make sure that we don't trim
2336 ;; off silly pieces, only complete understandable words.
2337 (setq trim-prefix
(speedbar-try-completion "" sublst
)
2338 newlst
(nreverse newlst
))
2339 (if (or (= (length sublst
) 1)
2341 (not (string-match "\\(\\w+\\W+\\)+" trim-prefix
)))
2342 (append newlst
(nreverse sublst
))
2343 (setq trim-prefix
(substring trim-prefix
(match-beginning 0)
2345 (setq trim-chars
(length trim-prefix
))
2348 (cons (substring (car (car sublst
)) trim-chars
)
2351 sublst
(cdr sublst
)))
2352 ;; Put the lists together
2353 (append newlst trimlst
))))
2355 (defun speedbar-simple-group-tag-hierarchy (lst)
2356 "Create a simple 'Tags' group with orphaned tags.
2357 Argument LST is the list of tags to sort into groups."
2361 (if (speedbar-generic-list-group-p (car-safe lst
))
2362 (setq newlst
(cons (car lst
) newlst
))
2363 (setq sublst
(cons (car lst
) sublst
)))
2364 (setq lst
(cdr lst
)))
2367 (setq newlst
(cons (cons "Tags" (nreverse sublst
)) newlst
))
2368 (nreverse newlst
))))
2370 (defun speedbar-create-tag-hierarchy (lst)
2371 "Adjust the tag hierarchy in LST, and return it.
2372 This uses `speedbar-tag-hierarchy-method' to determine how to adjust
2374 (let* ((f (save-excursion
2376 (or (speedbar-line-file)
2377 (speedbar-line-directory))))
2378 (methods (if (get-file-buffer f
)
2379 (with-current-buffer (get-file-buffer f
)
2380 speedbar-tag-hierarchy-method
)
2381 speedbar-tag-hierarchy-method
))
2382 (lst (if (fboundp 'copy-tree
)
2386 (setq lst
(funcall (car methods
) lst
)
2387 methods
(cdr methods
)))
2390 (defvar speedbar-generic-list-group-expand-button-type
'curly
2391 "The type of button created for groups of tags.
2392 Good values for this are `curly' and `expandtag'.
2393 Make buffer local for your mode.")
2395 (defvar speedbar-generic-list-tag-button-type nil
2396 "The type of button created for tags in generic lists.
2397 Good values for this are nil and `statictag'.
2398 Make buffer local for your mode.")
2400 (defun speedbar-insert-generic-list (level lst expand-fun find-fun
)
2401 "At LEVEL, insert a generic multi-level alist LST.
2402 Associations with lists get {+} tags (to expand into more nodes) and
2403 those with positions just get a > as the indicator. {+} buttons will
2404 have the function EXPAND-FUN and the token is the cdr list. The token
2405 name will have the function FIND-FUN and not token."
2406 ;; Remove imenu rescan button
2407 (if (string= (car (car lst
)) "*Rescan*")
2408 (setq lst
(cdr lst
)))
2409 ;; Get, and set up variables that define how we treat these tags.
2410 (let ((f (save-excursion (forward-line -
1)
2411 (or (speedbar-line-file)
2412 (speedbar-line-directory))))
2413 expand-button tag-button
)
2415 (if (get-file-buffer f
)
2416 (set-buffer (get-file-buffer f
)))
2417 (setq expand-button speedbar-generic-list-group-expand-button-type
2418 tag-button speedbar-generic-list-tag-button-type
))
2420 (setq lst
(speedbar-create-tag-hierarchy lst
))
2423 (cond ((null (car-safe lst
)) nil
) ;this would be a separator
2424 ((speedbar-generic-list-tag-p (car lst
))
2425 (speedbar-make-tag-line tag-button
2426 nil nil nil
;no expand button data
2427 (car (car lst
)) ;button name
2429 (cdr (car lst
)) ;token is position
2432 ((speedbar-generic-list-positioned-group-p (car lst
))
2433 (speedbar-make-tag-line expand-button
2434 ?
+ expand-fun
(cdr (cdr (car lst
)))
2435 (car (car lst
)) ;button name
2437 (car (cdr (car lst
))) ;token is posn
2440 ((speedbar-generic-list-group-p (car lst
))
2441 (speedbar-make-tag-line expand-button
2442 ?
+ expand-fun
(cdr (car lst
))
2443 (car (car lst
)) ;button name
2444 nil nil
'speedbar-tag-face
2446 (t (dframe-message "speedbar-insert-generic-list: malformed list!")
2448 (setq lst
(cdr lst
)))))
2450 (defun speedbar-insert-imenu-list (indent lst
)
2451 "At level INDENT, insert the imenu generated LST."
2452 (speedbar-insert-generic-list indent lst
2453 'speedbar-tag-expand
2454 'speedbar-tag-find
))
2456 (defun speedbar-insert-etags-list (indent lst
)
2457 "At level INDENT, insert the etags generated LST."
2458 (speedbar-insert-generic-list indent lst
2459 'speedbar-tag-expand
2460 'speedbar-tag-find
))
2464 (defun speedbar-update-contents ()
2465 "Generically update the contents of the speedbar buffer."
2467 ;; Set the current special buffer
2468 (setq speedbar-desired-buffer nil
)
2470 ;; Check for special modes
2471 (speedbar-maybe-add-localized-support (current-buffer))
2473 ;; Choose the correct method of doodling.
2474 (if (and speedbar-mode-specific-contents-flag
2475 (consp speedbar-special-mode-expansion-list
)
2477 'speedbar-special-mode-expansion-list
2479 ;;(eq (get major-mode 'mode-class 'special)))
2480 (speedbar-update-special-contents)
2481 (speedbar-update-directory-contents)))
2483 (defun speedbar-update-localized-contents ()
2484 "Update the contents of the speedbar buffer for the current situation."
2485 ;; Due to the historical growth of speedbar, we need to do something
2486 ;; special for "files" mode. Too bad.
2487 (let ((name speedbar-initial-expansion-list-name
)
2488 (funclst (speedbar-initial-expansion-list))
2490 (if (string= name
"files")
2491 ;; Do all the files type work. It still goes through the
2492 ;; expansion list stuff. :(
2493 (if (or (member (expand-file-name default-directory
)
2494 speedbar-shown-directories
)
2495 (and speedbar-ignored-directory-regexp
2497 speedbar-ignored-directory-regexp
2498 (expand-file-name default-directory
))))
2500 (if (<= 1 speedbar-verbosity-level
)
2501 (dframe-message "Updating speedbar to: %s..."
2503 (speedbar-update-directory-contents)
2504 (if (<= 1 speedbar-verbosity-level
)
2506 (dframe-message "Updating speedbar to: %s...done"
2508 (dframe-message nil
))))
2509 ;; Else, we can do a short cut. No text cache.
2510 (let ((cbd (expand-file-name default-directory
)))
2511 (set-buffer speedbar-buffer
)
2512 (speedbar-with-writable
2513 (let* ((window (get-buffer-window speedbar-buffer
0))
2514 (p (window-point window
))
2515 (start (window-start window
)))
2517 (dolist (func funclst
)
2518 (setq default-directory cbd
)
2519 (funcall func cbd
0))
2520 (speedbar-reconfigure-keymaps)
2521 (set-window-point window p
)
2522 (set-window-start window start
)))))))
2524 (defun speedbar-update-directory-contents ()
2525 "Update the contents of the speedbar buffer based on the current directory."
2526 (let ((cbd (expand-file-name default-directory
))
2528 (funclst (speedbar-initial-expansion-list))
2529 (cache speedbar-full-text-cache
)
2530 ;; disable stealth during update
2531 (speedbar-stealthy-function-list nil
)
2534 ;; Because there is a bug I can't find just yet
2536 (set-buffer speedbar-buffer
)
2537 ;; If we are updating contents to where we are, then this is
2538 ;; really a request to update existing contents, so we must be
2539 ;; careful with our text cache!
2540 (if (member cbd speedbar-shown-directories
)
2543 ;; If the current directory is not the last element in the dir
2544 ;; list, then we ALSO need to zap the list of expanded directories
2545 (if (/= (length (member cbd speedbar-shown-directories
)) 1)
2546 (setq speedbar-shown-directories
(list cbd
))))
2548 ;; Build cbd-parent, and see if THAT is in the current shown
2549 ;; directories. First, go through pains to get the parent directory
2550 (if (and speedbar-smart-directory-expand-flag
2552 (setq cbd-parent cbd
)
2553 (if (string-match "[/\\]$" cbd-parent
)
2554 (setq cbd-parent
(substring cbd-parent
0
2555 (match-beginning 0))))
2556 (setq cbd-parent
(file-name-directory cbd-parent
)))
2557 (member cbd-parent speedbar-shown-directories
))
2558 (setq expand-local t
)
2560 ;; If this directory is NOT in the current list of available
2561 ;; directories, then use the cache, and set the cache to our new
2562 ;; value. Make sure to unhighlight the current file, or if we
2563 ;; come back to this directory, it might be a different file
2564 ;; and then we get a mess!
2565 (if (> (point-max) 1)
2567 (speedbar-clear-current-file)
2568 (setq speedbar-full-text-cache
2569 (cons speedbar-shown-directories
(buffer-string)))))
2571 ;; Check if our new directory is in the list of directories
2572 ;; shown in the text-cache
2573 (if (member cbd
(car cache
))
2574 (setq speedbar-shown-directories
(car cache
)
2576 ;; default the shown directories to this list...
2577 (setq speedbar-shown-directories
(list cbd
)))
2579 (if (not expand-local
) (setq speedbar-last-selected-file nil
))
2580 (speedbar-with-writable
2581 (if (and expand-local
2582 ;; Find this directory as a speedbar node.
2583 (speedbar-directory-line cbd
))
2585 (speedbar-expand-line)
2586 (let* ((window (get-buffer-window speedbar-buffer
0))
2587 (p (window-point window
))
2588 (start (window-start window
)))
2591 (setq default-directory
2592 (nth (1- (length speedbar-shown-directories
))
2593 speedbar-shown-directories
))
2594 (insert (cdr cache
)))
2596 (dolist (func funclst
)
2597 (setq default-directory cbd
)
2598 (funcall func cbd
0))))
2599 (set-window-point window p
)
2600 (set-window-start window start
)))))
2601 (speedbar-reconfigure-keymaps))
2603 (defun speedbar-update-special-contents ()
2604 "Use the mode-specific variable to fill in the speedbar buffer.
2605 This should only be used by modes classified as special."
2606 (let ((funclst speedbar-special-mode-expansion-list
)
2607 (specialbuff (current-buffer)))
2608 (setq speedbar-desired-buffer specialbuff
)
2609 (with-current-buffer speedbar-buffer
2610 ;; If we are leaving a directory, cache it.
2611 (if (not speedbar-shown-directories
)
2614 ;; Clean up directory maintenance stuff
2615 (speedbar-clear-current-file)
2616 (setq speedbar-full-text-cache
2617 (cons speedbar-shown-directories
(buffer-string))
2618 speedbar-shown-directories nil
))
2619 ;; Now fill in the buffer with our newly found specialized list.
2620 (speedbar-with-writable
2621 (dolist (func funclst
)
2622 ;; We do not erase the buffer because these functions may
2623 ;; decide NOT to update themselves.
2624 (funcall func specialbuff
)))))
2625 (speedbar-reconfigure-keymaps))
2627 (defun speedbar-set-timer (timeout)
2628 "Set up the speedbar timer with TIMEOUT.
2629 Uses `dframe-set-timer'.
2630 Also resets scanner functions."
2631 (dframe-set-timer timeout
'speedbar-timer-fn
'speedbar-update-flag
)
2632 ;; Apply a revert hook that will reset the scanners. We attach to revert
2633 ;; because most reverts occur during VC state change, and this lets our
2634 ;; VC scanner fix itself.
2636 (add-hook 'after-revert-hook
'speedbar-reset-scanners
)
2637 (remove-hook 'after-revert-hook
'speedbar-reset-scanners
))
2638 ;; change this if it changed for some reason
2639 (speedbar-set-mode-line-format))
2641 (defun speedbar-timer-fn ()
2642 "Run whenever Emacs is idle to update the speedbar item."
2643 (if (or (not (speedbar-current-frame))
2644 (not (frame-live-p (speedbar-current-frame))))
2645 (speedbar-set-timer nil
)
2646 ;; Save all the match data so that we don't mess up executing fns
2648 ;; Only do stuff if the frame is visible, not an icon, and if
2649 ;; it is currently flagged to do something.
2650 (if (and speedbar-update-flag
2651 (speedbar-current-frame)
2652 (frame-visible-p (speedbar-current-frame))
2653 (not (eq (frame-visible-p (speedbar-current-frame)) 'icon
)))
2654 (let ((af (selected-frame)))
2655 (dframe-select-attached-frame speedbar-frame
)
2656 ;; make sure we at least choose a window to
2657 ;; get a good directory from
2658 (if (window-minibuffer-p)
2660 ;; Check for special modes
2661 (speedbar-maybe-add-localized-support (current-buffer))
2662 ;; Update for special mode all the time!
2663 (if (and speedbar-mode-specific-contents-flag
2664 (consp speedbar-special-mode-expansion-list
)
2666 'speedbar-special-mode-expansion-list
2668 ;;(eq (get major-mode 'mode-class 'special)))
2670 (if (<= 2 speedbar-verbosity-level
)
2672 "Updating speedbar to special mode: %s..."
2674 (speedbar-update-special-contents)
2675 (if (<= 2 speedbar-verbosity-level
)
2678 "Updating speedbar to special mode: %s...done"
2680 (dframe-message nil
))))
2682 ;; Update all the contents if directories change!
2683 (unless (and (or (member major-mode speedbar-ignored-modes
)
2684 (eq af
(speedbar-current-frame))
2685 (not (buffer-file-name)))
2686 ;; Always update for GUD.
2687 (not (string-equal "GUD"
2688 speedbar-initial-expansion-list-name
)))
2689 (speedbar-update-localized-contents)))
2691 ;; Now run stealthy updates of time-consuming items
2692 (speedbar-stealthy-updates)))))
2693 (run-hooks 'speedbar-timer-hook
))
2696 ;;; Stealthy activities
2698 (defvar speedbar-stealthy-update-recurse nil
2699 "Recursion avoidance variable for stealthy update.")
2701 (defun speedbar-stealthy-updates ()
2702 "For a given speedbar, run all items in the stealthy function list.
2703 Each item returns t if it completes successfully, or nil if
2704 interrupted by the user."
2705 (if (not speedbar-stealthy-update-recurse
)
2706 (let ((l (speedbar-initial-stealthy-functions))
2707 (speedbar-stealthy-update-recurse t
))
2709 (speedbar-with-writable
2710 (while (and l
(funcall (car l
)))
2713 ;;(dframe-message "Exit with %S" (car l))
2716 (defun speedbar-reset-scanners ()
2717 "Reset any variables used by functions in the stealthy list as state.
2718 If new functions are added, their state needs to be updated here."
2719 (setq speedbar-vc-to-do-point t
2720 speedbar-obj-to-do-point t
2721 speedbar-ro-to-do-point t
)
2722 (run-hooks 'speedbar-scanner-reset-hook
)
2725 (defun speedbar-find-selected-file (file)
2726 "Go to the line where FILE is."
2728 (set-buffer speedbar-buffer
)
2730 (goto-char (point-min))
2732 (while (and (setq m
(re-search-forward
2733 (concat " \\(" (regexp-quote (file-name-nondirectory file
))
2734 "\\)\\(" speedbar-indicator-regex
"\\)?\n")
2738 (speedbar-line-directory
2740 (goto-char (match-beginning 0))
2743 (looking-at "[0-9]+:")
2744 (string-to-number (match-string 0)))))
2745 (match-string 1))))))
2748 (goto-char (match-beginning 1))
2749 (match-string 1)))))
2751 (defun speedbar-clear-current-file ()
2752 "Locate the file thought to be current, and remove its highlighting."
2754 ;;(set-buffer speedbar-buffer)
2755 (if speedbar-last-selected-file
2756 (speedbar-with-writable
2757 (if (speedbar-find-selected-file speedbar-last-selected-file
)
2758 (put-text-property (match-beginning 1)
2761 'speedbar-file-face
))))))
2763 (defun speedbar-update-current-file ()
2764 "Find the current file, and update our visuals to indicate its name.
2765 This is specific to file names. If the file name doesn't show up, but
2766 it should be in the list, then the directory cache needs to be updated."
2767 (let* ((lastf (selected-frame))
2768 (newcfd (save-excursion
2769 (dframe-select-attached-frame speedbar-frame
)
2770 (let ((rf (if (buffer-file-name)
2773 (select-frame lastf
)
2775 (newcf (if newcfd newcfd
))
2776 (lastb (current-buffer))
2777 (sucf-recursive (boundp 'sucf-recursive
))
2778 (case-fold-search t
))
2780 ;; check here, that way we won't refresh to newcf until
2781 ;; its been written, thus saving ourselves some time
2782 (file-exists-p newcf
)
2783 (not (string= newcf speedbar-last-selected-file
)))
2785 ;; It is important to select the frame, otherwise the window
2786 ;; we want the cursor to move in will not be updated by the
2787 ;; search-forward command.
2788 (select-frame (speedbar-current-frame))
2789 ;; Remove the old file...
2790 (speedbar-clear-current-file)
2791 ;; now highlight the new one.
2792 ;; (set-buffer speedbar-buffer)
2793 (speedbar-with-writable
2794 (if (speedbar-find-selected-file newcf
)
2795 ;; put the property on it
2796 (put-text-property (match-beginning 1)
2799 'speedbar-selected-face
)
2800 ;; Oops, it's not in the list. Should it be?
2801 (if (and (string-match speedbar-file-regexp newcf
)
2802 (string= (file-name-directory newcfd
)
2803 (expand-file-name default-directory
)))
2804 ;; yes, it is (we will ignore unknowns for now...)
2807 (if (speedbar-find-selected-file newcf
)
2808 ;; put the property on it
2809 (put-text-property (match-beginning 1)
2812 'speedbar-selected-face
)))
2813 ;; if it's not in there now, whatever...
2815 (setq speedbar-last-selected-file newcf
))
2816 (if (not sucf-recursive
)
2819 ;;Sat Dec 15 2001 12:40 AM (burton@openprivacy.org): this
2820 ;;doesn't need to be in. We don't want to recenter when we are
2823 ;;(speedbar-center-buffer-smartly)
2825 (speedbar-position-cursor-on-line)
2828 (select-frame lastf
)
2830 ;; return that we are done with this activity.
2833 (defun speedbar-add-indicator (indicator-string &optional replace-this
)
2834 "Add INDICATOR-STRING to the end of this speedbar line.
2835 If INDICATOR-STRING is space, and REPLACE-THIS is a character,
2836 then the existing indicator is removed. If there is already an
2837 indicator, then do not add a space."
2839 ;; The nature of the beast: Assume we are in "the right place"
2841 (skip-chars-backward (concat " " speedbar-vc-indicator
2842 speedbar-object-read-only-indicator
2843 (car speedbar-obj-indicator
)
2844 (cdr speedbar-obj-indicator
)))
2845 (if (and (not (looking-at speedbar-indicator-regex
))
2846 (not (string= indicator-string
" ")))
2847 (insert speedbar-indicator-separator
))
2848 (speedbar-with-writable
2850 (if (and replace-this
2851 (re-search-forward replace-this
(line-end-position) t
))
2852 (delete-region (match-beginning 0) (match-end 0))))
2854 (if (not (string= " " indicator-string
))
2855 (let ((start (point)))
2856 (insert indicator-string
)
2857 (speedbar-insert-image-button-maybe start
(length indicator-string
))
2860 (defun speedbar-check-read-only ()
2861 "Scan all the files in a directory, and for each see if it is read only."
2862 ;; Check for to-do to be reset. If reset but no RCS is available
2863 ;; then set to nil (do nothing) otherwise, start at the beginning
2865 (if speedbar-buffer
(set-buffer speedbar-buffer
))
2866 (if (eq speedbar-ro-to-do-point t
)
2867 (setq speedbar-ro-to-do-point
0))
2868 (if (numberp speedbar-ro-to-do-point
)
2870 (goto-char speedbar-ro-to-do-point
)
2871 (while (and (not (input-pending-p))
2872 (re-search-forward "^\\([0-9]+\\):\\s-*[[<][+-\?][]>] "
2874 (setq speedbar-ro-to-do-point
(point))
2875 (let ((f (speedbar-line-file)))
2877 (if (not (file-writable-p f
))
2878 (speedbar-add-indicator
2879 speedbar-object-read-only-indicator
2880 (regexp-quote speedbar-object-read-only-indicator
))
2881 (speedbar-add-indicator
2883 speedbar-object-read-only-indicator
))))))
2884 (if (input-pending-p)
2885 ;; return that we are incomplete
2887 ;; we are done, set to-do to nil
2888 (setq speedbar-ro-to-do-point nil
)
2893 (defun speedbar-check-vc ()
2894 "Scan all files in a directory, and for each see if it's checked out.
2895 See `speedbar-this-file-in-vc' and `speedbar-vc-check-dir-p' for how
2896 to add more types of version control systems."
2897 ;; Check for to-do to be reset. If reset but no RCS is available
2898 ;; then set to nil (do nothing) otherwise, start at the beginning
2900 (if speedbar-buffer
(set-buffer speedbar-buffer
))
2901 (if (and speedbar-vc-do-check
(eq speedbar-vc-to-do-point t
)
2902 (speedbar-vc-check-dir-p default-directory
)
2903 (not (or (and (featurep 'ange-ftp
)
2906 (if (featurep 'xemacs
)
2907 'ange-ftp-directory-format
2908 'ange-ftp-name-format
)))
2909 (expand-file-name default-directory
)))
2910 ;; efs support: Bob Weiner
2911 (and (featurep 'efs
)
2913 (let ((reg (symbol-value 'efs-directory-regexp
)))
2917 (expand-file-name default-directory
))))))
2918 (setq speedbar-vc-to-do-point
0))
2919 (if (numberp speedbar-vc-to-do-point
)
2921 (goto-char speedbar-vc-to-do-point
)
2922 (while (and (not (input-pending-p))
2923 (re-search-forward "^\\([0-9]+\\):\\s-*\\[[+-?]\\] "
2925 (setq speedbar-vc-to-do-point
(point))
2926 (if (speedbar-check-vc-this-line (match-string 1))
2927 (speedbar-add-indicator speedbar-vc-indicator
2928 (regexp-quote speedbar-vc-indicator
))
2929 (speedbar-add-indicator " "
2930 (regexp-quote speedbar-vc-indicator
))))
2931 (if (input-pending-p)
2932 ;; return that we are incomplete
2934 ;; we are done, set to-do to nil
2935 (setq speedbar-vc-to-do-point nil
)
2940 (defun speedbar-check-vc-this-line (depth)
2941 "Return t if the file on this line is checked out of a version control system.
2942 Parameter DEPTH is a string with the current depth of indentation of
2943 the file being checked."
2944 (let* ((d (string-to-number depth
))
2945 (f (speedbar-line-directory d
))
2946 (fn (buffer-substring-no-properties
2947 ;; Skip-chars: thanks ptype@dra.hmg.gb
2949 (skip-chars-forward "^ " (line-end-position))
2951 (fulln (concat f fn
)))
2952 (if (<= 2 speedbar-verbosity-level
)
2953 (dframe-message "Speedbar vc check...%s" fulln
))
2954 (and (file-writable-p fulln
)
2955 (speedbar-this-file-in-vc f fn
))))
2957 (defun speedbar-vc-check-dir-p (directory)
2958 "Return t if we should bother checking DIRECTORY for version control files.
2959 This can be overloaded to add new types of version control systems."
2961 (catch t
(dolist (vcd vc-directory-exclusion-list
)
2962 (if (file-exists-p (concat directory vcd
)) (throw t t
))) nil
)
2964 (run-hook-with-args-until-success 'speedbar-vc-directory-enable-hook
2968 (defun speedbar-this-file-in-vc (directory name
)
2969 "Check to see if the file in DIRECTORY with NAME is in a version control system.
2970 Automatically recognizes all VCs supported by VC mode. You can
2971 optimize this function by overriding it and only doing those checks
2972 that will occur on your system."
2974 (vc-backend (concat directory
"/" name
))
2976 (run-hook-with-args 'speedbar-vc-in-control-hook directory name
)
2979 ;; Object File scanning
2980 (defun speedbar-check-objects ()
2981 "Scan all files in a directory, and for each see if there is an object.
2982 See `speedbar-check-obj-this-line' and `speedbar-obj-alist' for how
2983 to add more object types."
2984 ;; Check for to-do to be reset. If reset but no RCS is available
2985 ;; then set to nil (do nothing) otherwise, start at the beginning
2987 (if speedbar-buffer
(set-buffer speedbar-buffer
))
2988 (if (and speedbar-obj-do-check
(eq speedbar-obj-to-do-point t
))
2989 (setq speedbar-obj-to-do-point
0))
2990 (if (numberp speedbar-obj-to-do-point
)
2992 (goto-char speedbar-obj-to-do-point
)
2993 (while (and (not (input-pending-p))
2994 (re-search-forward "^\\([0-9]+\\):\\s-*\\[[+-]\\] "
2996 (setq speedbar-obj-to-do-point
(point))
2997 (let ((ind (speedbar-check-obj-this-line (match-string 1))))
2998 (if (not ind
) (setq ind
" "))
2999 (speedbar-add-indicator ind
(concat
3000 (car speedbar-obj-indicator
)
3002 (cdr speedbar-obj-indicator
)))))
3003 (if (input-pending-p)
3004 ;; return that we are incomplete
3006 ;; we are done, set to-do to nil
3007 (setq speedbar-obj-to-do-point nil
)
3012 (defun speedbar-check-obj-this-line (depth)
3013 "Return t if the file on this line has an associated object.
3014 Parameter DEPTH is a string with the current depth of indentation of
3015 the file being checked."
3016 (let* ((d (string-to-number depth
))
3017 (f (speedbar-line-directory d
))
3018 (fn (buffer-substring-no-properties
3019 ;; Skip-chars: thanks ptype@dra.hmg.gb
3021 (skip-chars-forward "^ " (line-end-position))
3023 (fulln (concat f fn
)))
3024 (if (<= 2 speedbar-verbosity-level
)
3025 (dframe-message "Speedbar obj check...%s" fulln
))
3026 (let ((oa speedbar-obj-alist
))
3027 (while (and oa
(not (string-match (car (car oa
)) fulln
)))
3029 (if (not (and oa
(file-exists-p (concat (file-name-sans-extension fulln
)
3032 ;; Find out if the object is out of date or not.
3033 (let ((date1 (nth 5 (file-attributes fulln
)))
3034 (date2 (nth 5 (file-attributes (concat
3035 (file-name-sans-extension fulln
)
3037 (if (or (< (car date1
) (car date2
))
3038 (and (= (car date1
) (car date2
))
3039 (< (nth 1 date1
) (nth 1 date2
))))
3040 (car speedbar-obj-indicator
)
3041 (cdr speedbar-obj-indicator
)))))))
3043 ;;; Clicking Activity
3045 (defun speedbar-position-cursor-on-line ()
3046 "Position the cursor on a line."
3047 (let ((oldpos (point)))
3049 (if (looking-at "[0-9]+:\\s-*..?.? ")
3050 (goto-char (1- (match-end 0)))
3051 (goto-char oldpos
))))
3053 (defun speedbar-click (e)
3054 "Activate any speedbar buttons where the mouse is clicked.
3055 This must be bound to a mouse event. A button is any location of text
3056 with a mouse face that has a text property called `speedbar-function'.
3057 Argument E is the click event."
3058 ;; Backward compatibility let statement.
3059 (let ((speedbar-power-click dframe-power-click
))
3060 (speedbar-do-function-pointer))
3061 (dframe-quick-mouse e
))
3063 (defun speedbar-do-function-pointer ()
3064 "Look under the cursor and examine the text properties.
3065 From this extract the file/tag name, token, indentation level and call
3066 a function if appropriate."
3067 (let* ((speedbar-frame (speedbar-current-frame))
3068 (fn (get-text-property (point) 'speedbar-function
))
3069 (tok (get-text-property (point) 'speedbar-token
))
3070 ;; The 1-,+ is safe because scanning starts AFTER the point
3071 ;; specified. This lets the search include the character the
3073 (tp (previous-single-property-change
3074 (1+ (point)) 'speedbar-function
))
3075 (np (next-single-property-change
3076 (point) 'speedbar-function
))
3077 (txt (buffer-substring-no-properties (or tp
(point-min))
3078 (or np
(point-max))))
3079 (dent (save-excursion (beginning-of-line)
3081 (if (looking-at "[0-9]+")
3082 (buffer-substring-no-properties
3083 (match-beginning 0) (match-end 0))
3085 ;;(dframe-message "%S:%S:%S:%s" fn tok txt dent)
3086 (and fn
(funcall fn txt tok dent
)))
3087 (speedbar-position-cursor-on-line))
3089 ;;; Reading info from the speedbar buffer
3091 (defun speedbar-line-text (&optional p
)
3092 "Retrieve the text after prefix junk for the current line.
3093 Optional argument P is where to start the search from."
3095 (if p
(goto-char p
))
3097 (if (looking-at (concat
3098 "\\([0-9]+\\): *[[<{]?[-+?= ][]>}@()|] \\([^ \n]+\\)"))
3099 (get-text-property (match-beginning 2) 'speedbar-text
)
3102 (defun speedbar-line-token (&optional p
)
3103 "Retrieve the token information after the prefix junk for the current line.
3104 Optional argument P is where to start the search from."
3106 (if p
(goto-char p
))
3108 (if (looking-at (concat
3109 "\\([0-9]+\\): *[[<{]?[-+?= ][]>}@()|] \\([^ \n]+\\)\\("
3110 speedbar-indicator-regex
"\\)?"))
3112 (goto-char (match-beginning 2))
3113 (get-text-property (point) 'speedbar-token
))
3116 (defun speedbar-line-file (&optional p
)
3117 "Retrieve the file or whatever from the line at point P.
3118 The return value is a string representing the file. If it is a
3119 directory, then it is the directory name."
3123 (let ((f (speedbar-line-text p
)))
3125 (let* ((depth (string-to-number (match-string 1)))
3126 (directory (speedbar-line-directory depth
)))
3127 (if (file-exists-p (concat directory f
))
3128 (concat directory f
)
3132 (defun speedbar-goto-this-file (file)
3133 "If FILE is displayed, go to this line and return t.
3134 Otherwise do not move and return nil."
3135 (let ((directory (substring (file-name-directory (expand-file-name file
))
3136 (length (expand-file-name default-directory
))))
3139 (goto-char (point-min))
3140 ;; scan all the directories
3141 (while (and directory
(not (eq directory t
)))
3142 (if (string-match "^[/\\]?\\([^/\\]+\\)" directory
)
3143 (let ((pp (match-string 1 directory
)))
3144 (if (save-match-data
3145 (re-search-forward (concat "> " (regexp-quote pp
) "$")
3147 (setq directory
(substring directory
(match-end 1)))
3148 (setq directory nil
)))
3149 (setq directory t
)))
3150 ;; find the file part
3151 (if (or (not directory
) (string= (file-name-nondirectory file
) ""))
3152 ;; only had a dir part
3155 (speedbar-position-cursor-on-line)
3157 (goto-char dest
) nil
)
3158 ;; find the file part
3159 (let ((nd (file-name-nondirectory file
)))
3160 (if (re-search-forward
3161 (concat "] \\(" (regexp-quote nd
)
3162 "\\)\\(" speedbar-indicator-regex
"\\)$")
3165 (speedbar-position-cursor-on-line)
3170 (defun speedbar-line-directory (&optional depth
)
3171 "Retrieve the directory name associated with the current line.
3172 This may require traversing backwards from DEPTH and combining the default
3173 directory with these items. This function is replaceable in
3174 `speedbar-mode-functions-list' as `speedbar-line-directory'."
3177 (let ((rf (speedbar-fetch-replacement-function 'speedbar-line-directory
)))
3178 (if rf
(funcall rf depth
) default-directory
))))
3180 (defun speedbar-files-line-directory (&optional depth
)
3181 "Retrieve the directory associated with the current line.
3182 This may require traversing backwards from DEPTH and combining the default
3183 directory with these items."
3189 (looking-at "^\\([0-9]+\\):")
3190 (setq depth
(string-to-number (match-string 1)))))
3191 (let ((directory nil
))
3192 (setq depth
(1- depth
))
3193 (while (/= depth -
1)
3194 (if (not (re-search-backward (format "^%d:" depth
) nil t
))
3195 (error "Error building filename of tag")
3196 (cond ((looking-at "[0-9]+:\\s-*<->\\s-+\\([^\n]+\\)")
3197 (setq directory
(concat (speedbar-line-text)
3200 ((looking-at "[0-9]+:\\s-*[-]\\s-+\\([^\n]+\\)")
3201 ;; This is the start of our directory.
3202 (setq directory
(speedbar-line-text)))))
3203 (setq depth
(1- depth
)))
3205 (string-match (concat speedbar-indicator-regex
"$")
3207 (setq directory
(substring directory
0 (match-beginning 0))))
3208 (concat default-directory directory
)))))
3210 (defun speedbar-directory-line (directory)
3211 "Position the cursor on the line specified by DIRECTORY."
3213 (if (string-match "[/\\]$" directory
)
3214 (setq directory
(substring directory
0 (match-beginning 0))))
3215 (let ((nomatch t
) (depth 0)
3216 (fname (file-name-nondirectory directory
))
3217 (pname (file-name-directory directory
)))
3218 (if (not (member pname speedbar-shown-directories
))
3219 (error "Internal Error: File %s not shown in speedbar" directory
))
3220 (goto-char (point-min))
3223 (concat "[]>] \\(" (regexp-quote fname
)
3224 "\\)\\(" speedbar-indicator-regex
"\\)?$")
3227 (looking-at "\\([0-9]+\\):")
3228 (setq depth
(string-to-number (match-string 0))
3229 nomatch
(not (string= pname
(speedbar-line-directory depth
))))
3234 (defun speedbar-edit-line ()
3235 "Edit whatever tag or file is on the current speedbar line."
3239 ;; If this fails, then it is a non-standard click, and as such,
3240 ;; perfectly allowed.
3241 (if (re-search-forward "[]>?}] [^ ]"
3246 (speedbar-do-function-pointer))
3248 (speedbar-do-function-pointer)))
3250 (defun speedbar-expand-line (&optional arg
)
3251 "Expand the line under the cursor.
3252 With universal argument ARG, flush cached data."
3255 (let* ((dframe-power-click arg
)
3256 (speedbar-power-click arg
))
3259 (re-search-forward ":\\s-*.\\+. "
3260 (line-end-position))
3262 (speedbar-do-function-pointer))
3263 (error (speedbar-position-cursor-on-line)))))
3265 (defun speedbar-flush-expand-line ()
3266 "Expand the line under the cursor and flush any cached information."
3268 (speedbar-expand-line 1))
3270 (defun speedbar-contract-line ()
3271 "Contract the line under the cursor."
3276 (re-search-forward ":\\s-*.-. "
3277 (line-end-position))
3279 (speedbar-do-function-pointer))
3280 (error (speedbar-position-cursor-on-line))))
3282 (defun speedbar-toggle-line-expansion ()
3283 "Contract or expand the line under the cursor."
3288 (re-search-forward ":\\s-*.[-+]. "
3289 (line-end-position))
3291 (speedbar-do-function-pointer))
3292 (error (speedbar-position-cursor-on-line))))
3294 (defun speedbar-expand-line-descendants (&optional arg
)
3295 "Expand the line under the cursor and all descendants.
3296 Optional argument ARG indicates that any cache should be flushed."
3298 (speedbar-expand-line arg
)
3299 ;; Now, inside the area expanded here, expand all subnodes of
3300 ;; the same descendant type.
3302 (speedbar-next 1) ;; Move into the list.
3307 (speedbar-expand-line-descendants arg
)
3308 (speedbar-restricted-next 1))
3309 (error (setq err t
))))))
3312 (defun speedbar-contract-line-descendants ()
3313 "Expand the line under the cursor and all descendants."
3315 (speedbar-contract-line)
3316 ;; Don't need to do anything else since all descendants are
3317 ;; hidden by default anyway. Yay! It's easy.
3320 (defun speedbar-find-file (text _token indent
)
3321 "Speedbar click handler for filenames.
3322 TEXT, the file will be displayed in the attached frame.
3323 TOKEN is unused, but required by the click handler. INDENT is the
3324 current indentation level."
3325 (let ((cdd (speedbar-line-directory indent
)))
3326 ;; Run before visiting file hook here.
3327 (let ((f (selected-frame)))
3328 (dframe-select-attached-frame speedbar-frame
)
3329 (run-hooks 'speedbar-before-visiting-file-hook
)
3331 (speedbar-find-file-in-frame (concat cdd text
))
3332 (speedbar-stealthy-updates)
3333 (run-hooks 'speedbar-visiting-file-hook
)
3334 ;; Reset the timer with a new timeout when clicking a file
3335 ;; in case the user was navigating directories, we can cancel
3336 ;; that other timer.
3337 (speedbar-set-timer dframe-update-speed
))
3338 (dframe-maybee-jump-to-attached-frame))
3340 (defun speedbar-dir-follow (text _token indent
)
3341 "Speedbar click handler for directory names.
3342 Clicking a directory will cause the speedbar to list files in
3343 the subdirectory TEXT. TOKEN is an unused requirement. The
3344 subdirectory chosen will be at INDENT level."
3345 (setq default-directory
3346 (concat (expand-file-name (concat (speedbar-line-directory indent
) text
))
3348 ;; Because we leave speedbar as the current buffer,
3349 ;; update contents will change directory without
3350 ;; having to touch the attached frame. Turn off smart expand just
3352 (let ((speedbar-smart-directory-expand-flag nil
))
3353 (speedbar-update-contents))
3354 (speedbar-set-timer speedbar-navigating-speed
)
3355 (setq speedbar-last-selected-file nil
)
3356 (speedbar-stealthy-updates))
3358 (defun speedbar-delete-subblock (indent)
3359 "Delete text from point to indentation level INDENT or greater.
3360 Handles end-of-sublist smartly."
3361 (speedbar-with-writable
3363 (end-of-line) (forward-char 1)
3364 (let ((start (point)))
3365 (while (and (looking-at "^\\([0-9]+\\):")
3366 (> (string-to-number (match-string 1)) indent
)
3369 (beginning-of-line))
3370 (delete-region start
(point))))))
3372 (defun speedbar-dired (text token indent
)
3373 "Speedbar click handler for directory expand button.
3374 Clicking this button expands or contracts a directory. TEXT is the
3375 button clicked which has either a + or -. TOKEN is the directory to be
3376 expanded. INDENT is the current indentation level."
3377 (cond ((string-match "+" text
) ;we have to expand this dir
3378 (setq speedbar-shown-directories
3379 (cons (expand-file-name
3380 (concat (speedbar-line-directory indent
) token
"/"))
3381 speedbar-shown-directories
))
3382 (speedbar-change-expand-button-char ?-
)
3383 (speedbar-reset-scanners)
3385 (end-of-line) (forward-char 1)
3386 (speedbar-with-writable
3387 (speedbar-default-directory-list
3388 (concat (speedbar-line-directory indent
) token
"/")
3390 ((string-match "-" text
) ;we have to contract this node
3391 (speedbar-reset-scanners)
3392 (let ((oldl speedbar-shown-directories
)
3394 (td (expand-file-name
3395 (concat (speedbar-line-directory indent
) token
))))
3397 (if (not (string-match (concat "^" (regexp-quote td
)) (car oldl
)))
3398 (setq newl
(cons (car oldl
) newl
)))
3399 (setq oldl
(cdr oldl
)))
3400 (setq speedbar-shown-directories
(nreverse newl
)))
3401 (speedbar-change-expand-button-char ?
+)
3402 (speedbar-delete-subblock indent
)
3404 (t (error "Ooops... not sure what to do")))
3405 (speedbar-center-buffer-smartly)
3406 (save-excursion (speedbar-stealthy-updates)))
3408 (defun speedbar-directory-buttons-follow (_text token _indent
)
3409 "Speedbar click handler for default directory buttons.
3410 TEXT is the button clicked on. TOKEN is the directory to follow.
3411 INDENT is the current indentation level and is unused."
3412 (if (string-match "^[A-z]:$" token
)
3413 (setq default-directory
(concat token
"/"))
3414 (setq default-directory token
))
3415 ;; Because we leave speedbar as the current buffer,
3416 ;; update contents will change directory without
3417 ;; having to touch the attached frame.
3418 (speedbar-update-contents)
3419 (speedbar-set-timer speedbar-navigating-speed
))
3421 (defun speedbar-tag-file (text token indent
)
3422 "The cursor is on a selected line. Expand the tags in the specified file.
3423 The parameter TEXT and TOKEN are required, where TEXT is the button
3424 clicked, and TOKEN is the file to expand. INDENT is the current
3426 (cond ((string-match "+" text
) ;we have to expand this file
3427 (let* ((fn (expand-file-name (concat (speedbar-line-directory indent
)
3429 (lst (speedbar-fetch-dynamic-tags fn
)))
3430 ;; if no list, then remove expando button
3432 (speedbar-change-expand-button-char ??
)
3433 (speedbar-change-expand-button-char ?-
)
3434 (speedbar-with-writable
3436 (end-of-line) (forward-char 1)
3437 (funcall (car lst
) indent
(cdr lst
)))))))
3438 ((string-match "-" text
) ;we have to contract this node
3439 (speedbar-change-expand-button-char ?
+)
3440 (speedbar-delete-subblock indent
))
3441 (t (error "Ooops... not sure what to do")))
3442 (speedbar-center-buffer-smartly))
3444 (defun speedbar-tag-find (_text token indent
)
3445 "For the tag TEXT in a file TOKEN, go to that position.
3446 INDENT is the current indentation level."
3447 (let ((file (speedbar-line-directory indent
)))
3448 (let ((f (selected-frame)))
3449 (dframe-select-attached-frame speedbar-frame
)
3450 (run-hooks 'speedbar-before-visiting-tag-hook
)
3452 (speedbar-find-file-in-frame file
)
3453 (save-excursion (speedbar-stealthy-updates))
3454 ;; Reset the timer with a new timeout when clicking a file
3455 ;; in case the user was navigating directories, we can cancel
3456 ;; that other timer.
3457 (speedbar-set-timer dframe-update-speed
)
3459 (run-hooks 'speedbar-visiting-tag-hook
)
3460 (dframe-maybee-jump-to-attached-frame)
3463 (defun speedbar-tag-expand (text token indent
)
3464 "Expand a tag sublist. Imenu will return sub-lists of specialized tag types.
3465 Etags does not support this feature. TEXT will be the button string.
3466 TOKEN will be the list, and INDENT is the current indentation level."
3467 (cond ((string-match "+" text
) ;we have to expand this file
3468 (speedbar-change-expand-button-char ?-
)
3469 (speedbar-with-writable
3471 (end-of-line) (forward-char 1)
3472 (speedbar-insert-generic-list indent token
'speedbar-tag-expand
3473 'speedbar-tag-find
))))
3474 ((string-match "-" text
) ;we have to contract this node
3475 (speedbar-change-expand-button-char ?
+)
3476 (speedbar-delete-subblock indent
))
3477 (t (error "Ooops... not sure what to do")))
3478 (speedbar-center-buffer-smartly))
3480 ;;; Loading files into the attached frame.
3482 (defcustom speedbar-select-frame-method
'attached
3483 "Specify how to select a frame for displaying a file.
3484 A value of 'attached means to use the attached frame (the frame
3485 that speedbar was started from.) A number such as 1 or -1 means to
3486 pass that number to `other-frame' while selecting a frame from speedbar."
3490 (defun speedbar-find-file-in-frame (file)
3491 "This will load FILE into the speedbar attached frame.
3492 If the file is being displayed in a different frame already, then raise that
3494 (let* ((buff (find-file-noselect file
))
3495 (bwin (get-buffer-window buff
0)))
3498 (select-window bwin
)
3499 (raise-frame (window-frame bwin
)))
3500 (if dframe-power-click
3501 (let ((pop-up-frames t
)) (select-window (display-buffer buff
)))
3502 (if (numberp speedbar-select-frame-method
)
3503 (other-frame speedbar-select-frame-method
)
3504 (dframe-select-attached-frame speedbar-frame
))
3505 (switch-to-buffer buff
))))
3508 ;;; Centering Utility
3510 (defun speedbar-center-buffer-smartly ()
3511 "Recenter a speedbar buffer so the current indentation level is all visible.
3512 This assumes that the cursor is on a file, or tag of a file which the user is
3515 (save-selected-window
3517 (select-window (get-buffer-window speedbar-buffer t
))
3519 (set-buffer speedbar-buffer
)
3521 (if (<= (count-lines (point-min) (point-max))
3522 (1- (window-height)))
3523 ;; whole buffer fits
3526 (goto-char (point-min))
3530 (let (depth start end exp p
)
3533 (setq depth
(if (looking-at "[0-9]+")
3534 (string-to-number (buffer-substring-no-properties
3535 (match-beginning 0) (match-end 0)))
3537 (setq exp
(format "^%d:" depth
)))
3540 (if (re-search-backward exp nil t
)
3541 (setq start
(point))
3542 (setq start
(point-min)))
3543 (save-excursion ;Not sure about this part.
3546 (while (and (not (re-search-forward exp nil t
))
3548 (setq depth
(1- depth
))
3549 (setq exp
(format "^%d:" depth
)))
3552 (setq end
(point-max)))))
3553 ;; Now work out the details of centering
3554 (let ((nl (count-lines start end
))
3555 (wl (1- (window-height)))
3558 ;; We can't fit it all, so just center on cursor
3559 (progn (goto-char start
)
3561 ;; we can fit everything on the screen, but...
3562 (if (and (pos-visible-in-window-p start
(selected-window))
3563 (pos-visible-in-window-p end
(selected-window)))
3566 ;; we need to do something...
3568 (let ((newcent (/ (- (window-height) nl
) 2))
3569 (lte (count-lines start
(point-max))))
3570 (if (and (< (+ newcent lte
) (window-height))
3571 (> (- (window-height) lte
1)
3573 (setq newcent
(- (window-height)
3575 (recenter newcent
))))
3578 ;;; Tag Management -- List of expanders:
3580 (defun speedbar-fetch-dynamic-tags (file)
3581 "Return a list of tags generated dynamically from FILE.
3582 This uses the entries in `speedbar-dynamic-tags-function-list'
3583 to find the proper tags. It is up to each of those individual
3584 functions to do caching and flushing if appropriate."
3586 ;; If a file is in memory, switch to that buffer. This allows
3587 ;; us to use the local variable. If the file is on disk, we
3588 ;; can try a few of the defaults that can get tags without
3589 ;; opening the file.
3590 (if (get-file-buffer file
)
3591 (set-buffer (get-file-buffer file
)))
3592 ;; If there is a buffer-local value of
3593 ;; speedbar-dynamic-tags-function-list, it will now be available.
3594 (let ((dtf speedbar-dynamic-tags-function-list
)
3596 (while (and (eq ret t
) dtf
)
3598 (if (fboundp (car (car dtf
)))
3599 (funcall (car (car dtf
)) file
)
3602 (setq dtf
(cdr dtf
))))
3604 ;; No valid tag list, return nil
3606 ;; We have some tags. Return the list with the insert fn
3608 (cons (cdr (car dtf
)) ret
)))))
3610 ;;; Tag Management -- Imenu
3612 (if (not speedbar-use-imenu-flag
)
3616 (eval-when-compile (condition-case nil
(require 'imenu
) (error nil
)))
3617 (declare-function imenu--make-index-alist
"imenu" (&optional no-error
))
3619 (defun speedbar-fetch-dynamic-imenu (file)
3620 "Load FILE into a buffer, and generate tags using Imenu.
3621 Returns the tag list, or t for an error."
3622 ;; Load this AND compile it in
3624 (set-buffer (find-file-noselect file
))
3625 (if dframe-power-click
(setq imenu--index-alist nil
))
3627 (let ((index-alist (imenu--make-index-alist t
)))
3628 (if speedbar-sort-tags
3629 (sort (copy-alist index-alist
)
3630 (lambda (a b
) (string< (car a
) (car b
))))
3635 ;;; Tag Management -- etags (old XEmacs compatibility part)
3637 (defvar speedbar-fetch-etags-parse-list
3638 '(;; Note that java has the same parse-group as c
3639 ("\\.\\([cChH]\\|c\\+\\+\\|cpp\\|cc\\|hh\\|java\\|cxx\\|hxx\\)\\'" .
3640 speedbar-parse-c-or-c
++tag
)
3641 ("^\\.emacs$\\|.\\(el\\|l\\|lsp\\)\\'" .
3642 "def[^i]+\\s-+\\(\\(\\w\\|[-_]\\)+\\)\\s-*\C-?")
3643 ; ("\\.\\([fF]\\|for\\|FOR\\|77\\|90\\)\\'" .
3644 ; speedbar-parse-fortran77-tag)
3645 ("\\.tex\\'" . speedbar-parse-tex-string
)
3647 "\\(\\(FUNCTION\\|function\\|PROCEDURE\\|procedure\\)\\s-+\\([a-zA-Z0-9_.:]+\\)\\)\\s-*(?^?")
3649 "Associations of file extensions and expressions for extracting tags.
3650 To add a new file type, you would want to add a new association to the
3651 list, where the car is the file match, and the cdr is the way to
3652 extract an element from the tags output. If the output is complex,
3653 use a function symbol instead of regexp. The function should expect
3654 to be at the beginning of a line in the etags buffer.
3656 This variable is ignored if `speedbar-use-imenu-flag' is non-nil.")
3658 (defcustom speedbar-fetch-etags-command
"etags"
3659 "Command used to create an etags file.
3660 This variable is ignored if `speedbar-use-imenu-flag' is t."
3664 (defcustom speedbar-fetch-etags-arguments
'("-D" "-I" "-o" "-")
3665 "List of arguments to use with `speedbar-fetch-etags-command'.
3666 This creates an etags output buffer. Use `speedbar-toggle-etags' to
3667 modify this list conveniently.
3668 This variable is ignored if `speedbar-use-imenu-flag' is t."
3670 :type
'(choice (const nil
)
3671 (repeat :tag
"List of arguments" string
)))
3673 (defun speedbar-toggle-etags (flag)
3674 "Toggle FLAG in `speedbar-fetch-etags-arguments'.
3675 FLAG then becomes a member of etags command line arguments. If flag
3676 is \"sort\", then toggle the value of `speedbar-sort-tags'. If its
3677 value is \"show\" then toggle the value of
3678 `speedbar-show-unknown-files'.
3680 This function is a convenience function for XEmacs menu created by
3681 Farzin Guilak <farzin@protocol.com>."
3684 ((equal flag
"sort")
3685 (setq speedbar-sort-tags
(not speedbar-sort-tags
)))
3686 ((equal flag
"show")
3687 (setq speedbar-show-unknown-files
(not speedbar-show-unknown-files
)))
3688 ((or (equal flag
"-C")
3691 (if (member flag speedbar-fetch-etags-arguments
)
3692 (setq speedbar-fetch-etags-arguments
3693 (delete flag speedbar-fetch-etags-arguments
))
3694 (add-to-list 'speedbar-fetch-etags-arguments flag
)))
3697 (defun speedbar-fetch-dynamic-etags (file)
3698 "For FILE, run etags and create a list of symbols extracted.
3699 Each symbol will be associated with its line position in FILE."
3700 (let ((newlist nil
))
3703 (if (get-buffer "*etags tmp*")
3704 (kill-buffer "*etags tmp*")) ;kill to clean it up
3705 (if (<= 1 speedbar-verbosity-level
)
3706 (dframe-message "Fetching etags..."))
3707 (set-buffer (get-buffer-create "*etags tmp*"))
3708 (apply 'call-process speedbar-fetch-etags-command nil
3709 (current-buffer) nil
3710 (append speedbar-fetch-etags-arguments
(list file
)))
3711 (goto-char (point-min))
3712 (if (<= 1 speedbar-verbosity-level
)
3713 (dframe-message "Fetching etags..."))
3715 (let ((exprlst speedbar-fetch-etags-parse-list
)
3717 (while (and (not ans
) exprlst
)
3718 (if (string-match (car (car exprlst
)) file
)
3719 (setq ans
(car exprlst
)))
3720 (setq exprlst
(cdr exprlst
)))
3724 (set-buffer (get-buffer-create "*etags tmp*"))
3725 (while (not (save-excursion (end-of-line) (eobp)))
3727 (setq tnl
(speedbar-extract-one-symbol expr
)))
3728 (if tnl
(setq newlist
(cons tnl newlist
)))
3731 "Sorry, no support for a file of that extension"))))
3733 (if speedbar-sort-tags
3734 (sort newlist
(lambda (a b
) (string< (car a
) (car b
))))
3735 (reverse newlist
))))
3737 ;; This bit donated by Farzin Guilak <farzin@protocol.com> but I'm not
3738 ;; sure it's needed with the different sorting method.
3740 ;(defun speedbar-clean-etags()
3741 ; "Removes spaces before the ^? character, and removes `#define',
3742 ;return types, etc. preceding tags. This ensures that the sort operation
3743 ;works on the tags, not the return types."
3745 ; (goto-char (point-min))
3747 ; (re-search-forward "(?[ \t](?\C-?" nil t)
3748 ; (replace-match "\C-?" nil nil))
3749 ; (goto-char (point-min))
3751 ; (re-search-forward "\\(.*[ \t]+\\)\\([^ \t\n]+.*\C-?\\)" nil t)
3752 ; (delete-region (match-beginning 1) (match-end 1)))))
3754 (defun speedbar-extract-one-symbol (expr)
3755 "At point, return nil, or one alist in the form (SYMBOL . POSITION).
3756 The line should contain output from etags. Parse the output using the
3757 regular expression EXPR."
3758 (let* ((sym (if (stringp expr
)
3760 (re-search-forward expr
(line-end-position) t
))
3761 (buffer-substring-no-properties (match-beginning 1)
3764 (pos (let ((j (re-search-forward "[\C-?\C-a]\\([0-9]+\\),\\([0-9]+\\)"
3765 (line-end-position) t
)))
3767 (1+ (string-to-number (buffer-substring-no-properties
3775 (defun speedbar-parse-c-or-c++tag
()
3776 "Parse a C or C++ tag, which tends to be a little complex."
3778 (let ((bound (line-end-position)))
3779 (cond ((re-search-forward "\C-?\\([^\C-a]+\\)\C-a" bound t
)
3780 (buffer-substring-no-properties (match-beginning 1)
3782 ((re-search-forward "\\<\\([^ \t]+\\)\\s-+new(" bound t
)
3783 (buffer-substring-no-properties (match-beginning 1)
3785 ((re-search-forward "\\<\\([^ \t(]+\\)\\s-*(\C-?" bound t
)
3786 (buffer-substring-no-properties (match-beginning 1)
3791 (defun speedbar-parse-tex-string ()
3792 "Parse a Tex string. Only find data which is relevant."
3794 (let ((bound (line-end-position)))
3795 (cond ((re-search-forward "\\(\\(sub\\)*section\\|chapter\\|cite\\)\\s-*{[^\C-?}]*}?" bound t
)
3796 (buffer-substring-no-properties (match-beginning 0)
3801 ;;; BUFFER DISPLAY mode.
3803 (defvar speedbar-buffers-key-map nil
3804 "Keymap used when in the buffers display mode.")
3806 (if speedbar-buffers-key-map
3808 (setq speedbar-buffers-key-map
(speedbar-make-specialized-keymap))
3810 ;; Basic tree features
3811 (define-key speedbar-buffers-key-map
"e" 'speedbar-edit-line
)
3812 (define-key speedbar-buffers-key-map
"\C-m" 'speedbar-edit-line
)
3813 (define-key speedbar-buffers-key-map
"+" 'speedbar-expand-line
)
3814 (define-key speedbar-buffers-key-map
"=" 'speedbar-expand-line
)
3815 (define-key speedbar-buffers-key-map
"-" 'speedbar-contract-line
)
3816 (define-key speedbar-buffers-key-map
" " 'speedbar-toggle-line-expansion
)
3818 ;; Buffer specific keybindings
3819 (define-key speedbar-buffers-key-map
"k" 'speedbar-buffer-kill-buffer
)
3820 (define-key speedbar-buffers-key-map
"r" 'speedbar-buffer-revert-buffer
)
3824 (defvar speedbar-buffer-easymenu-definition
3825 '(["Jump to buffer" speedbar-edit-line t
]
3826 ["Expand File Tags" speedbar-expand-line
3827 (save-excursion (beginning-of-line)
3828 (looking-at "[0-9]+: *.\\+. "))]
3829 ["Flush Cache & Expand" speedbar-flush-expand-line
3830 (save-excursion (beginning-of-line)
3831 (looking-at "[0-9]+: *.\\+. "))]
3832 ["Contract File Tags" speedbar-contract-line
3833 (save-excursion (beginning-of-line)
3834 (looking-at "[0-9]+: *.-. "))]
3836 ["Kill Buffer" speedbar-buffer-kill-buffer
3837 (save-excursion (beginning-of-line)
3838 (looking-at "[0-9]+: *.[-+?]. "))]
3839 ["Revert Buffer" speedbar-buffer-revert-buffer
3840 (save-excursion (beginning-of-line)
3841 (looking-at "[0-9]+: *.[-+?]. "))]
3843 "Menu item elements shown when displaying a buffer list.")
3845 (defun speedbar-buffer-buttons (_directory _zero
)
3846 "Create speedbar buttons based on the buffers currently loaded.
3847 DIRECTORY is the directory of the currently active buffer, and ZERO is 0."
3848 (speedbar-buffer-buttons-engine nil
))
3850 (defun speedbar-buffer-buttons-temp (_directory _zero
)
3851 "Create speedbar buttons based on the buffers currently loaded.
3852 DIRECTORY is the directory of the currently active buffer, and ZERO is 0."
3853 (speedbar-buffer-buttons-engine t
))
3855 (defun speedbar-buffer-buttons-engine (temp)
3856 "Create speedbar buffer buttons.
3857 If TEMP is non-nil, then clicking on a buffer restores the previous display."
3858 (speedbar-insert-separator "Active Buffers:")
3859 (let ((bl (buffer-list))
3860 (case-fold-search t
))
3862 (if (string-match "^[ *]" (buffer-name (car bl
)))
3864 (let* ((known (string-match speedbar-file-regexp
3865 (buffer-name (car bl
))))
3866 (expchar (if known ?
+ ??
))
3867 (fn (if known
'speedbar-tag-file nil
))
3868 (fname (with-current-buffer (car bl
)
3869 (buffer-file-name))))
3870 (speedbar-make-tag-line 'bracket expchar fn
3871 (if fname
(file-name-nondirectory fname
))
3872 (buffer-name (car bl
))
3873 'speedbar-buffer-click temp
3874 'speedbar-file-face
0)
3875 (speedbar-buffers-tail-notes (car bl
))))
3877 (setq bl
(buffer-list))
3878 (speedbar-insert-separator "Scratch Buffers:")
3880 (if (not (string-match "^\\*" (buffer-name (car bl
))))
3882 (if (eq (car bl
) speedbar-buffer
)
3884 (speedbar-make-tag-line 'bracket ?? nil nil
3885 (buffer-name (car bl
))
3886 'speedbar-buffer-click temp
3887 'speedbar-file-face
0)
3888 (speedbar-buffers-tail-notes (car bl
))))
3890 (setq bl
(buffer-list))
3891 ;;(speedbar-insert-separator "Hidden Buffers:")
3893 ;; (if (not (string-match "^ " (buffer-name (car bl))))
3895 ;; (if (eq (car bl) speedbar-buffer)
3897 ;; (speedbar-make-tag-line 'bracket ?? nil nil
3898 ;; (buffer-name (car bl))
3899 ;; 'speedbar-buffer-click temp
3900 ;; 'speedbar-file-face 0)
3901 ;; (speedbar-buffers-tail-notes (car bl))))
3902 ;; (setq bl (cdr bl)))
3905 (defun speedbar-buffers-tail-notes (buffer)
3906 "Add a note to the end of the last tag line.
3907 Argument BUFFER is the buffer being tested."
3908 (when (with-current-buffer buffer buffer-read-only
)
3909 (speedbar-insert-button "%" nil nil nil nil t
)))
3911 (defun speedbar-buffers-item-info ()
3912 "Display information about the current buffer on the current line."
3913 (or (speedbar-item-info-tag-helper)
3914 (let* ((item (speedbar-line-text))
3915 (buffer (if item
(get-buffer item
) nil
)))
3917 (dframe-message "%s%s %S %d %s"
3918 (if (buffer-modified-p buffer
) "* " "")
3920 (with-current-buffer buffer major-mode
)
3921 (with-current-buffer buffer
(buffer-size))
3922 (or (buffer-file-name buffer
) "<No file>"))))))
3924 (defun speedbar-buffers-line-directory (&optional _depth
)
3925 "Fetch the directory of the file (buffer) specified on the current line.
3926 Optional argument DEPTH specifies the current depth of the back search."
3929 (let ((start (point)))
3930 ;; Buffers are always at level 0
3931 (if (not (re-search-backward "^0:" nil t
))
3933 (let* ((bn (speedbar-line-text))
3934 (buffer (if bn
(get-buffer bn
))))
3936 (if (eq start
(line-end-position))
3937 (or (with-current-buffer buffer default-directory
)
3939 (buffer-file-name buffer
))))))))
3941 (defun speedbar-buffer-click (text token _indent
)
3942 "When the users clicks on a buffer-button in speedbar.
3943 TEXT is the buffer's name, TOKEN and INDENT are unused."
3944 (if dframe-power-click
3945 (let ((pop-up-frames t
)) (select-window (display-buffer text
)))
3946 (dframe-select-attached-frame speedbar-frame
)
3947 (switch-to-buffer text
)
3948 (if token
(speedbar-change-initial-expansion-list
3949 speedbar-previously-used-expansion-list-name
))))
3951 (defun speedbar-buffer-kill-buffer ()
3952 "Kill the buffer the cursor is on in the speedbar buffer."
3955 (let ((text (speedbar-line-text)))
3956 (if (and (get-buffer text
)
3957 (speedbar-y-or-n-p (format "Kill buffer %s? " text
)))
3959 (speedbar-refresh)))))
3961 (defun speedbar-buffer-revert-buffer ()
3962 "Revert the buffer the cursor is on in the speedbar buffer."
3966 ;; If this fails, then it is a non-standard click, and as such,
3967 ;; perfectly allowed
3968 (if (re-search-forward "[]>?}] [^ ]" (line-end-position) t
)
3971 (buffer-substring (point) (line-end-position)))))
3972 (if (get-buffer text
)
3975 (revert-buffer t
)))))))
3978 ;;; Useful hook values and such.
3980 (defvar speedbar-highlight-one-tag-line nil
3981 "Overlay used for highlighting the most recently jumped to tag line.")
3983 (defun speedbar-highlight-one-tag-line ()
3984 "Highlight the current line, unhighlighting a previously jumped to line."
3985 (speedbar-unhighlight-one-tag-line)
3986 (setq speedbar-highlight-one-tag-line
3987 (speedbar-make-overlay (line-beginning-position)
3988 (1+ (line-end-position))))
3989 (speedbar-overlay-put speedbar-highlight-one-tag-line
'face
3990 'speedbar-highlight-face
)
3991 (add-hook 'pre-command-hook
'speedbar-unhighlight-one-tag-line
))
3993 (defun speedbar-unhighlight-one-tag-line ()
3994 "Unhighlight the currently highlighted line."
3995 (when (and speedbar-highlight-one-tag-line
3996 (not (eq this-command
'handle-switch-frame
)))
3997 (speedbar-delete-overlay speedbar-highlight-one-tag-line
)
3998 (setq speedbar-highlight-one-tag-line nil
)
3999 (remove-hook 'pre-command-hook
'speedbar-unhighlight-one-tag-line
)))
4001 (defun speedbar-recenter-to-top ()
4002 "Recenter the current buffer so point is on the top of the window."
4005 (defun speedbar-recenter ()
4006 "Recenter the current buffer so point is in the center of the window."
4007 (recenter (/ (window-height) 2)))
4010 ;;; Color loading section.
4012 (defface speedbar-button-face
'((((class color
) (background light
))
4013 :foreground
"green4")
4014 (((class color
) (background dark
))
4015 :foreground
"green3"))
4016 "Speedbar face for +/- buttons."
4017 :group
'speedbar-faces
)
4019 (defface speedbar-file-face
'((((class color
) (background light
))
4020 :foreground
"cyan4")
4021 (((class color
) (background dark
))
4024 "Speedbar face for file names."
4025 :group
'speedbar-faces
)
4027 (defface speedbar-directory-face
'((((class color
) (background light
))
4028 :foreground
"blue4")
4029 (((class color
) (background dark
))
4030 :foreground
"light blue"))
4031 "Speedbar face for directory names."
4032 :group
'speedbar-faces
)
4034 (defface speedbar-tag-face
'((((class color
) (background light
))
4035 :foreground
"brown")
4036 (((class color
) (background dark
))
4037 :foreground
"yellow"))
4038 "Speedbar face for tags."
4039 :group
'speedbar-faces
)
4041 (defface speedbar-selected-face
'((((class color
) (background light
))
4042 :foreground
"red" :underline t
)
4043 (((class color
) (background dark
))
4044 :foreground
"red" :underline t
)
4046 "Speedbar face for the file in the active window."
4047 :group
'speedbar-faces
)
4049 (defface speedbar-highlight-face
'((((class color
) (background light
))
4050 :background
"green")
4051 (((class color
) (background dark
))
4052 :background
"sea green"))
4053 "Speedbar face for highlighting buttons with the mouse."
4054 :group
'speedbar-faces
)
4056 (defface speedbar-separator-face
'((((class color
) (background light
))
4060 (((class color
) (background dark
))
4064 (((class grayscale monochrome
)
4069 (((class grayscale monochrome
)
4074 "Speedbar face for separator labels in a display."
4075 :group
'speedbar-faces
)
4077 ;; some edebug hooks
4078 (add-hook 'edebug-setup-hook
4080 (def-edebug-spec speedbar-with-writable def-body
)))
4082 ;; Fix a font lock problem for some versions of Emacs
4083 (and (boundp 'font-lock-global-modes
)
4084 font-lock-global-modes
4085 (if (eq font-lock-global-modes t
)
4086 (setq font-lock-global-modes
'(not speedbar-mode
))
4087 (if (eq (car font-lock-global-modes
) 'not
)
4088 (add-to-list 'font-lock-global-modes
'speedbar-mode t
)
4089 (setq font-lock-global-modes
(delq 'speedbar-mode
4090 font-lock-global-modes
)))))
4092 ;;; Obsolete variables and functions
4094 (define-obsolete-variable-alias
4095 'speedbar-ignored-path-regexp
'speedbar-ignored-directory-regexp
"22.1")
4097 (define-obsolete-function-alias 'speedbar-add-ignored-path-regexp
4098 'speedbar-add-ignored-directory-regexp
"22.1")
4100 (define-obsolete-function-alias 'speedbar-line-path
4101 'speedbar-line-directory
"22.1")
4103 (define-obsolete-function-alias 'speedbar-buffers-line-path
4104 'speedbar-buffers-line-directory
"22.1")
4106 (define-obsolete-function-alias 'speedbar-path-line
4107 'speedbar-directory-line
"22.1")
4109 (define-obsolete-function-alias 'speedbar-buffers-line-path
4110 'speedbar-buffers-line-directory
"22.1")
4114 ;; run load-time hooks
4115 (run-hooks 'speedbar-load-hook
)
4117 ;;; speedbar ends here