1 ;;; speedbar --- quick access to files and tags in a frame
3 ;; Copyright (C) 1996-2018 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 <https://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 ;; AUC-TEX users: The imenu tags for AUC-TEX mode don't work very
43 ;; well. Use the imenu keywords from tex-mode.el for better results.
45 ;;; Developing for speedbar
47 ;; Adding a speedbar specialized display mode:
49 ;; Speedbar can be configured to create a special display for certain
50 ;; modes that do not display traditional file/tag data. Rmail, Info,
51 ;; and the debugger are examples. These modes can, however, benefit
52 ;; from a speedbar style display in their own way.
54 ;; If your `major-mode' is `foo-mode', the only requirement is to
55 ;; create a function called `foo-speedbar-buttons' which takes one
56 ;; argument, BUFFER. BUFFER will be the buffer speedbar wants filled.
57 ;; In `foo-speedbar-buttons' there are several functions that make
58 ;; building a speedbar display easy. See the documentation for
59 ;; `speedbar-with-writable' (needed because the buffer is usually
60 ;; read-only) `speedbar-make-tag-line', `speedbar-insert-button', and
61 ;; `speedbar-insert-generic-list'. If you use
62 ;; `speedbar-insert-generic-list', also read the doc for
63 ;; `speedbar-tag-hierarchy-method' in case you wish to override it.
64 ;; The macro `dframe-with-attached-buffer' brings you back to the
65 ;; buffer speedbar is displaying for.
67 ;; For those functions that make buttons, the "function" should be a
68 ;; symbol that is the function to call when clicked on. The "token"
69 ;; is extra data you can pass along. The "function" must take three
70 ;; parameters. They are (TEXT TOKEN INDENT). TEXT is the text of the
71 ;; button clicked on. TOKEN is the data passed in when you create the
72 ;; button. INDENT is an indentation level, or 0. You can store
73 ;; indentation levels with `speedbar-make-tag-line' which creates a
74 ;; line with an expander (eg. [+]) and a text button.
76 ;; Some useful functions when writing expand functions, and click
77 ;; functions are `speedbar-change-expand-button-char',
78 ;; `speedbar-delete-subblock', and `speedbar-center-buffer-smartly'.
79 ;; The variable `speedbar-power-click' is set to t in your functions
80 ;; when the user shift-clicks. This is an indication of anything from
81 ;; refreshing cached data to making a buffer appear in a new frame.
83 ;; If you wish to add to the default speedbar menu for the case of
84 ;; `foo-mode', create a variable `foo-speedbar-menu-items'. This
85 ;; should be a list compatible with the `easymenu' package. It will
86 ;; be spliced into the main menu. (Available with click-mouse-3). If
87 ;; you wish to have extra key bindings in your special mode, create a
88 ;; variable `foo-speedbar-key-map'. Instead of using `make-keymap',
89 ;; or `make-sparse-keymap', use the function
90 ;; `speedbar-make-specialized-keymap'. This lets you inherit all of
91 ;; speedbar's default bindings with low overhead.
93 ;; Adding a speedbar top-level display mode:
95 ;; Unlike the specialized modes, there are no name requirements,
96 ;; however the methods for writing a button display, menu, and keymap
97 ;; are the same. Once you create these items, you can call the
98 ;; function `speedbar-add-expansion-list'. It takes one parameter
99 ;; which is a list element of the form (NAME MENU KEYMAP &rest
100 ;; BUTTON-FUNCTIONS). NAME is a string that will show up in the
101 ;; Displays menu item. MENU is a symbol containing the menu items to
102 ;; splice in. KEYMAP is a symbol holding the keymap to use, and
103 ;; BUTTON-FUNCTIONS are the function names to call, in order, to create
105 ;; Another tweakable variable is `speedbar-stealthy-function-list'
106 ;; which is of the form (NAME &rest FUNCTION ...). NAME is the string
107 ;; name matching `speedbar-add-expansion-list'. (It does not need to
108 ;; exist.). This provides additional display info which might be
109 ;; time-consuming to calculate.
110 ;; Lastly, `speedbar-mode-functions-list' allows you to set special
111 ;; function overrides.
114 ;; - Timeout directories we haven't visited in a while.
120 ;; customization stuff
121 (defgroup speedbar nil
122 "File and tag browser frame."
126 :link
'(custom-manual "(speedbar) Top")
127 :link
'(info-link "(speedbar) Customizing")
131 (defgroup speedbar-faces nil
132 "Faces used in speedbar."
134 :link
'(info-link "(speedbar) Frames and Faces")
138 (defgroup speedbar-vc nil
139 "Version control display in speedbar."
140 :link
'(info-link "(speedbar) Version Control")
146 ;; Note: `inversion-test' requires parts of the CEDET package that are
147 ;; not included with Emacs.
149 ;; (defun speedbar-require-version (major minor &optional beta)
150 ;; "Non-nil if this version of SPEEDBAR does not satisfy a specific version.
153 ;; (MAJOR MINOR &optional BETA)
155 ;; Values MAJOR and MINOR must be integers. BETA can be an integer, or
156 ;; excluded if a released version is required.
158 ;; It is assumed that if the current version is newer than that specified,
159 ;; everything passes. Exceptions occur when known incompatibilities are
161 ;; (inversion-test 'speedbar
162 ;; (concat major "." minor
163 ;; (when beta (concat "beta" beta)))))
165 (defvar speedbar-initial-expansion-mode-alist
166 '(("buffers" speedbar-buffer-easymenu-definition speedbar-buffers-key-map
167 speedbar-buffer-buttons
)
168 ("quick buffers" speedbar-buffer-easymenu-definition speedbar-buffers-key-map
169 speedbar-buffer-buttons-temp
)
170 ;; Files last, means first in the Displays menu
171 ("files" speedbar-easymenu-definition-special speedbar-file-key-map
172 speedbar-directory-buttons speedbar-default-directory-list
)
174 "List of named expansion elements for filling the speedbar frame.
175 These expansion lists are only valid for regular files. Special modes
176 still get to override this list on a mode-by-mode basis. This list of
177 lists is of the form (NAME MENU KEYMAP FN1 FN2 ...). NAME is a string
178 representing the types of things to be displayed. MENU is an easymenu
179 structure used when in this mode. KEYMAP is a local keymap to install
180 over the regular speedbar keymap. FN1 ... are functions that will be
181 called in order. These functions will always get the default
182 directory to use passed in as the first parameter, and a 0 as the
183 second parameter. The 0 indicates the uppermost indentation level.
184 They must assume that the cursor is at the position where they start
187 (defvar speedbar-initial-expansion-list-name
"files"
188 "A symbol name representing the expansion list to use.
189 The expansion list `speedbar-initial-expansion-mode-alist' contains
190 the names and associated functions to use for buttons in speedbar.")
192 (defvar speedbar-previously-used-expansion-list-name
"files"
193 "Save the last expansion list method.
194 This is used for returning to a previous expansion list method when
195 the user is done with the current expansion list.")
197 (defvar speedbar-stealthy-function-list
199 speedbar-update-current-file
200 speedbar-check-read-only
202 speedbar-check-objects
)
204 "List of functions to periodically call stealthily.
205 This list is of the form:
206 ( (\"NAME\" FUNCTION ...)
208 where NAME is the name of the major display mode these functions are
209 for, and the remaining elements FUNCTION are functions to call in order.
210 Each function must return nil if interrupted, or t if completed.
211 Stealthy functions which have a single operation should always return t.
212 Functions which take a long time should maintain a state (where they
213 are in their speedbar related calculations) and permit interruption.
214 See `speedbar-check-vc' as a good example.")
216 (defvar speedbar-mode-functions-list
217 '(("files" (speedbar-item-info . speedbar-files-item-info
)
218 (speedbar-line-directory . speedbar-files-line-directory
))
219 ("buffers" (speedbar-item-info . speedbar-buffers-item-info
)
220 (speedbar-line-directory . speedbar-buffers-line-directory
))
221 ("quick buffers" (speedbar-item-info . speedbar-buffers-item-info
)
222 (speedbar-line-directory . speedbar-buffers-line-directory
))
224 "List of function tables to use for different major display modes.
225 It is not necessary to define any functions for a specialized mode.
226 This just provides a simple way of adding lots of customizations.
227 Each sublist is of the form:
228 (\"NAME\" (FUNCTIONSYMBOL . REPLACEMENTFUNCTION) ...)
229 Where NAME is the name of the specialized mode. The rest of the list
230 is a set of dotted pairs of the form FUNCTIONSYMBOL, which is the name
231 of a function you would like to replace, and REPLACEMENTFUNCTION,
232 which is a function you can call instead. Not all functions can be
233 replaced this way. Replaceable functions must provide that
234 functionality individually.")
236 (defcustom speedbar-mode-specific-contents-flag t
237 "Non-nil means speedbar will show special mode contents.
238 This permits some modes to create customized contents for the speedbar
243 (defcustom speedbar-query-confirmation-method
'all
244 "Query control for file operations.
245 The `all' flag means to always query before file operations.
246 The `none-but-delete' flag means to not query before any file
247 operations, except before a file deletion."
249 :type
'(radio (const :tag
"Always Query before some file operations."
251 (const :tag
"Never Query before file operations, except for deletions."
253 ;;;; (const :tag "Never Every Query."
257 (defvar speedbar-special-mode-expansion-list nil
258 "Default function list for creating specialized button lists.
259 This list is set by modes that wish to have special speedbar displays.
260 The list is of function names. Each function is called with one
261 parameter BUFFER, the originating buffer. The current buffer is the
264 (defvar speedbar-special-mode-key-map nil
265 "Default keymap used when identifying a specialized display mode.
266 This keymap is local to each buffer that wants to define special keybindings
267 effective when its display is shown.")
269 (defcustom speedbar-before-visiting-file-hook
'(push-mark)
270 "Hooks run before speedbar visits a file in the selected frame.
271 The default buffer is the buffer in the selected window in the attached frame."
275 (defcustom speedbar-visiting-file-hook nil
276 "Hooks run when speedbar visits a file in the selected frame."
280 (defcustom speedbar-before-visiting-tag-hook
'(push-mark)
281 "Hooks run before speedbar visits a tag in the selected frame.
282 The default buffer is the buffer in the selected window in the attached frame."
286 (defcustom speedbar-visiting-tag-hook
'(speedbar-highlight-one-tag-line)
287 "Hooks run when speedbar visits a tag in the selected frame."
290 :options
'(speedbar-highlight-one-tag-line
291 speedbar-recenter-to-top
295 (defcustom speedbar-load-hook nil
296 "Hooks run when speedbar is loaded."
300 (defcustom speedbar-reconfigure-keymaps-hook nil
301 "Hooks run when the keymaps are regenerated."
305 (defcustom speedbar-show-unknown-files nil
306 "Non-nil show files we can't expand with a ? in the expand button.
307 A nil value means don't show the file in the list."
311 ;;; EVENTUALLY REMOVE THESE
313 ;; When I moved to a repeating timer, I had the horrible misfortune
314 ;; of losing the ability for adaptive speed choice. This update
315 ;; speed currently causes long delays when it should have been turned off.
316 (defvar speedbar-update-speed dframe-update-speed
)
317 (make-obsolete-variable 'speedbar-update-speed
319 "speedbar 1.0pre3 (Emacs 23.1)")
321 (defvar speedbar-navigating-speed dframe-update-speed
)
322 (make-obsolete-variable 'speedbar-navigating-speed
324 "speedbar 1.0pre3 (Emacs 23.1)")
327 (defcustom speedbar-frame-parameters
'((minibuffer . nil
)
335 "Parameters to use when creating the speedbar frame in Emacs.
336 Any parameter supported by a frame may be added. The parameter `height'
337 will be initialized to the height of the frame speedbar is
338 attached to and added to this list before the new frame is initialized."
340 :type
'(repeat (cons :format
"%v"
341 (symbol :tag
"Parameter")
342 (sexp :tag
"Value"))))
344 ;; These values by Hrvoje Niksic <hniksic@srce.hr>
345 (defcustom speedbar-frame-plist
346 '(minibuffer nil width
20 border-width
0
347 internal-border-width
0 unsplittable t
348 default-toolbar-visible-p nil has-modeline-p nil
349 menubar-visible-p nil
350 default-gutter-visible-p nil
352 "Parameters to use when creating the speedbar frame in XEmacs.
353 Parameters not listed here which will be added automatically are
354 `height' which will be initialized to the height of the frame speedbar
357 :type
'(repeat (group :inline t
358 (symbol :tag
"Property")
359 (sexp :tag
"Value"))))
361 (defcustom speedbar-use-imenu-flag
(fboundp 'imenu
)
362 "Non-nil means use imenu for file parsing, nil to use etags.
363 XEmacs prior to 20.4 doesn't support imenu, therefore the default is to
364 use etags instead. Etags support is not as robust as imenu support."
365 :tag
"Use Imenu for tags"
369 (defvar speedbar-dynamic-tags-function-list
370 '((speedbar-fetch-dynamic-imenu . speedbar-insert-imenu-list
)
371 (speedbar-fetch-dynamic-etags . speedbar-insert-etags-list
))
372 "Set to a list of functions which will return and insert a list of tags.
373 Each element is of the form ( FETCH . INSERT ) where FETCH
374 is a function which takes one parameter (the file to tag) and returns a
375 list of tags. The tag list can be of any form as long as the
376 corresponding insert method can handle it. If it returns t, then an
377 error occurred, and the next fetch routine is tried.
378 INSERT is a function which takes an INDENTation level, and a LIST of
379 tags to insert. It will then create the speedbar buttons.")
381 (defcustom speedbar-use-tool-tips-flag
(fboundp 'tooltip-mode
)
382 "Non-nil means to use tool tips if they are available.
383 When tooltips are not available, mouse-tracking and minibuffer
384 display is used instead."
388 (defcustom speedbar-track-mouse-flag
(not speedbar-use-tool-tips-flag
)
389 "Non-nil means to display info about the line under the mouse."
393 (defcustom speedbar-default-position
'left-right
394 "Default position of the speedbar frame.
395 Possible values are `left', `right' or `left-right'.
396 If value is `left-right', the most suitable location is
397 determined automatically."
399 :type
'(radio (const :tag
"Automatic" left-right
)
400 (const :tag
"Left" left
)
401 (const :tag
"Right" right
)))
403 (defcustom speedbar-sort-tags nil
404 "If non-nil, sort tags in the speedbar display. *Obsolete*.
405 Use `semantic-tag-hierarchy-method' instead."
409 (defcustom speedbar-tag-hierarchy-method
410 '(speedbar-prefix-group-tag-hierarchy
411 speedbar-trim-words-tag-hierarchy
)
412 "List of hooks which speedbar will use to organize tags into groups.
413 Groups are defined as expandable meta-tags. Imenu supports
414 such things in some languages, such as separating variables from
415 functions. Each hook takes one argument LST, and may destructively
416 create a new list of the same form. LST is a list of elements of the
419 where each ELT is of the form
420 (TAG-NAME-STRING . NUMBER-OR-MARKER)
422 (GROUP-NAME-STRING ELT1 ELT2... ELTn)"
425 :options
'(speedbar-prefix-group-tag-hierarchy
426 speedbar-trim-words-tag-hierarchy
427 speedbar-simple-group-tag-hierarchy
428 speedbar-sort-tag-hierarchy
)
431 (defcustom speedbar-tag-group-name-minimum-length
4
432 "The minimum length of a prefix group name before expanding.
433 Thus, if the `speedbar-tag-hierarchy-method' includes `prefix-group'
434 and one such groups common characters is less than this number of
435 characters, then the group name will be changed to the form of:
439 This way we won't get silly looking listings."
443 (defcustom speedbar-tag-split-minimum-length
20
444 "Minimum length before we stop trying to create sub-lists in tags.
445 This is used by all tag-hierarchy methods that break large lists into
450 (defcustom speedbar-tag-regroup-maximum-length
10
451 "Maximum length of submenus that are regrouped.
452 If the regrouping option is used, then if two or more short subgroups
453 are next to each other, then they are combined until this number of
458 (defcustom speedbar-directory-button-trim-method
'span
459 "Indicates how the directory button will be displayed.
461 `span' - span large directories over multiple lines.
462 `trim' - trim large directories to only show the last few.
465 :type
'(radio (const :tag
"Span large directories over multiple lines."
467 (const :tag
"Trim large directories to only show the last few."
469 (const :tag
"No trimming." nil
)))
471 (defcustom speedbar-smart-directory-expand-flag t
472 "Non-nil means speedbar should use smart expansion.
473 Smart expansion only affects when speedbar wants to display a
474 directory for a file in the attached frame. When smart expansion is
475 enabled, new directories which are children of a displayed directory
476 are expanded in the current framework. If nil, then the current
477 hierarchy would be replaced with the new directory."
481 (defcustom speedbar-indentation-width
1
482 "When sub-nodes are expanded, the number of spaces used for indentation."
486 (defcustom speedbar-hide-button-brackets-flag nil
487 "Non-nil means speedbar will hide the brackets around the + or -."
491 (defcustom speedbar-before-popup-hook nil
492 "Hooks called before popping up the speedbar frame."
496 (defcustom speedbar-after-create-hook
'(speedbar-frame-reposition-smartly)
497 "Hooks called after popping up the speedbar frame."
501 (defcustom speedbar-before-delete-hook nil
502 "Hooks called before deleting the speedbar frame."
506 (defcustom speedbar-mode-hook nil
507 "Hook run after creating a speedbar buffer."
511 (defcustom speedbar-timer-hook nil
512 "Hooks called after running the speedbar timer function."
516 (defcustom speedbar-verbosity-level
1
517 "Verbosity level of the speedbar.
519 1 means medium level verbosity.
520 2 and higher are higher levels of verbosity."
524 (defvar speedbar-indicator-separator
" "
525 "String separating file text from indicator characters.")
527 (defcustom speedbar-vc-do-check t
528 "Non-nil check all files in speedbar to see if they have been checked out.
529 Any file checked out is marked with `speedbar-vc-indicator'."
533 (defvar speedbar-vc-indicator
"*"
534 "Text used to mark files which are currently checked out.
535 Other version control systems can be added by examining the function
536 `speedbar-vc-directory-enable-hook' and `speedbar-vc-in-control-hook'.")
538 (defcustom speedbar-vc-directory-enable-hook nil
539 "Return non-nil if the current directory should be checked for Version Control.
540 Functions in this hook must accept one parameter which is the directory
545 (defcustom speedbar-vc-in-control-hook nil
546 "Return non-nil if the specified file is under Version Control.
547 Functions in this hook must accept two parameters. The DIRECTORY of the
548 current file, and the FILENAME of the file being checked."
552 (defvar speedbar-vc-to-do-point nil
553 "Local variable maintaining the current version control check position.")
555 (defcustom speedbar-obj-do-check t
556 "Non-nil check all files in speedbar to see if they have an object file.
557 Any file checked out is marked with `speedbar-obj-indicator', and the
558 marking is based on `speedbar-obj-alist'"
562 (defvar speedbar-obj-to-do-point nil
563 "Local variable maintaining the current version control check position.")
565 (defvar speedbar-obj-indicator
'("#" .
"!")
566 "Text used to mark files that have a corresponding hidden object file.
567 The car is for an up-to-date object. The cdr is for an out of date object.
568 The expression `speedbar-obj-alist' defines who gets tagged.")
570 (defvar speedbar-obj-alist
571 '(("\\.\\([cpC]\\|cpp\\|cc\\|cxx\\)$" .
".o")
573 ("\\.java$" .
".class")
574 ("\\.f\\(or\\|90\\|77\\)?$" .
".o")
576 ("\\.texi$" .
".info"))
577 "Alist of file extensions, and their corresponding object file type.")
579 (defvar speedbar-ro-to-do-point nil
580 "Local variable maintaining the current read only check position.")
582 (defvar speedbar-object-read-only-indicator
"%"
583 "Indicator to append onto a line if that item is Read Only.")
585 ;; Note: Look for addition place to add indicator lists that
586 ;; use skip-chars instead of a regular expression.
587 (defvar speedbar-indicator-regex
588 (concat (regexp-quote speedbar-indicator-separator
)
590 (regexp-quote speedbar-vc-indicator
)
592 (regexp-quote (car speedbar-obj-indicator
))
594 (regexp-quote (cdr speedbar-obj-indicator
))
596 (regexp-quote speedbar-object-read-only-indicator
)
598 "Regular expression used when identifying files.
599 Permits stripping of indicator characters from a line.")
601 (defcustom speedbar-scanner-reset-hook nil
602 "Hook called whenever generic scanners are reset.
603 Set this to implement your own scanning / rescan safe functions with
608 (defcustom speedbar-ignored-modes
'(fundamental-mode)
609 "List of major modes which speedbar will not switch directories for."
611 :type
'(choice (const nil
)
612 (repeat :tag
"List of modes" (symbol :tag
"Major mode"))))
614 (defun speedbar-extension-list-to-regex (extlist)
615 "Takes EXTLIST, a list of extensions and transforms it into regexp.
616 All the preceding `.' are stripped for an optimized expression starting
617 with `.' followed by extensions, followed by full-filenames."
618 (let ((regex1 nil
) (regex2 nil
))
620 (if (= (string-to-char (car extlist
)) ?.
)
621 (setq regex1
(concat regex1
(if regex1
"\\|" "")
622 (substring (car extlist
) 1)))
623 (setq regex2
(concat regex2
(if regex2
"\\|" "") (car extlist
))))
624 (setq extlist
(cdr extlist
)))
625 ;; Concatenate all the subexpressions together, making sure all types
626 ;; of parts exist during concatenation.
628 (if regex1
(concat "\\(\\.\\(" regex1
"\\)\\)") "")
629 (if (and regex1 regex2
) "\\|" "")
630 (if regex2
(concat "\\(" regex2
"\\)") "")
633 (defvar speedbar-ignored-directory-regexp nil
634 "Regular expression matching directories speedbar will not switch to.
635 Created from `speedbar-ignored-directory-expressions' with the function
636 `speedbar-extension-list-to-regex' (a misnamed function in this case.)
637 Use the function `speedbar-add-ignored-directory-regexp', or customize the
638 variable `speedbar-ignored-directory-expressions' to modify this variable.")
640 (defcustom speedbar-ignored-directory-expressions
641 '("[/\\]logs?[/\\]\\'")
642 "List of regular expressions matching directories speedbar will ignore.
643 They should included directories which are notoriously very large
644 and take a long time to load in. Use the function
645 `speedbar-add-ignored-directory-regexp' to add new items to this list after
646 speedbar is loaded. You may place anything you like in this list
647 before speedbar has been loaded."
649 :type
'(repeat (regexp :tag
"Directory Regexp"))
650 :set
(lambda (_sym val
)
651 (setq speedbar-ignored-directory-expressions val
652 speedbar-ignored-directory-regexp
653 (speedbar-extension-list-to-regex val
))))
655 (defcustom speedbar-directory-unshown-regexp
"^\\(\\..*\\)\\'"
656 "Regular expression matching directories not to show in speedbar.
657 They should include commonly existing directories which are not
658 useful. It is no longer necessary to include version-control
659 directories here; see `vc-directory-exclusion-list'."
663 (defcustom speedbar-file-unshown-regexp
664 (let ((nstr "") (noext completion-ignored-extensions
))
666 (setq nstr
(concat nstr
(regexp-quote (car noext
)) "\\'"
667 (if (cdr noext
) "\\|" ""))
669 ;; backup refdir lockfile
670 (concat nstr
"\\|#[^#]+#$\\|\\.\\.?\\'\\|\\.#"))
671 "Regexp matching files we don't want displayed in a speedbar buffer.
672 It is generated from the variable `completion-ignored-extensions'."
676 (defvar speedbar-file-regexp nil
677 "Regular expression matching files we know how to expand.
678 Created from `speedbar-supported-extension-expressions' with the
679 function `speedbar-extension-list-to-regex'.")
681 ;; this is dangerous to customize, because the defaults will probably
682 ;; change in the future.
683 (defcustom speedbar-supported-extension-expressions
684 (append '(".[ch]\\(\\+\\+\\|pp\\|c\\|h\\|xx\\)?" ".tex\\(i\\(nfo\\)?\\)?"
685 ".el" ".emacs" ".l" ".lsp" ".p" ".java" ".js" ".f\\(90\\|77\\|or\\)?")
686 (if speedbar-use-imenu-flag
687 '(".ad[abs]" ".p[lm]" ".tcl" ".m" ".scm" ".pm" ".py" ".g"
688 ;; html is not supported by default, but an imenu tags package
689 ;; is available. Also, html files are nice to be able to see.
691 ".ma?k" "[Mm]akefile\\(\\.in\\)?")))
692 "List of regular expressions which will match files supported by tagging.
693 Do not prefix the `.' char with a double \\ to quote it, as the period
694 will be stripped by a simplified optimizer when compiled into a
695 singular expression. This variable will be turned into
696 `speedbar-file-regexp' for use with speedbar. You should use the
697 function `speedbar-add-supported-extension' to add a new extension at
698 runtime, or use the configuration dialog to set it in your init file.
699 If you add an extension to this list, and it does not appear, you may
700 need to also modify `completion-ignored-extension' which will also help
703 :type
'(repeat (regexp :tag
"Extension Regexp"))
704 :set
(lambda (_sym val
)
705 (set 'speedbar-supported-extension-expressions val
)
706 (set 'speedbar-file-regexp
(speedbar-extension-list-to-regex val
))))
708 (setq speedbar-file-regexp
709 (speedbar-extension-list-to-regex speedbar-supported-extension-expressions
))
711 (defun speedbar-add-supported-extension (extension)
712 "Add EXTENSION as a new supported extension for speedbar tagging.
713 This should start with a `.' if it is not a complete file name, and
714 the dot should NOT be quoted in with \\. Other regular expression
715 matchers are allowed however. EXTENSION may be a single string or a
717 (interactive "sExtension: ")
718 (if (not (listp extension
)) (setq extension
(list extension
)))
720 (if (member (car extension
) speedbar-supported-extension-expressions
)
722 (setq speedbar-supported-extension-expressions
723 (cons (car extension
) speedbar-supported-extension-expressions
)))
724 (setq extension
(cdr extension
)))
725 (setq speedbar-file-regexp
(speedbar-extension-list-to-regex
726 speedbar-supported-extension-expressions
)))
728 (defun speedbar-add-ignored-directory-regexp (directory-expression)
729 "Add DIRECTORY-EXPRESSION as a new ignored directory for speedbar tracking.
730 This function will modify `speedbar-ignored-directory-regexp' and add
731 DIRECTORY-EXPRESSION to `speedbar-ignored-directory-expressions'."
732 (interactive "sDirectory regex: ")
733 (if (not (listp directory-expression
))
734 (setq directory-expression
(list directory-expression
)))
735 (while directory-expression
736 (if (member (car directory-expression
) speedbar-ignored-directory-expressions
)
738 (setq speedbar-ignored-directory-expressions
739 (cons (car directory-expression
) speedbar-ignored-directory-expressions
)))
740 (setq directory-expression
(cdr directory-expression
)))
741 (setq speedbar-ignored-directory-regexp
(speedbar-extension-list-to-regex
742 speedbar-ignored-directory-expressions
)))
744 ;; If we don't have custom, then we set it here by hand.
745 (if (not (fboundp 'custom-declare-variable
))
746 (setq speedbar-file-regexp
(speedbar-extension-list-to-regex
747 speedbar-supported-extension-expressions
)
748 speedbar-ignored-directory-regexp
(speedbar-extension-list-to-regex
749 speedbar-ignored-directory-expressions
)))
751 (defcustom speedbar-update-flag dframe-have-timer-flag
752 "Non-nil means to automatically update the display.
753 When this is nil then speedbar will not follow the attached frame's directory.
754 If you want to change this while speedbar is active, either use
755 \\[customize] or call \\<speedbar-mode-map> `\\[speedbar-toggle-updates]'."
757 :initialize
'custom-initialize-default
758 :set
(lambda (sym val
)
760 (speedbar-toggle-updates))
763 (defvar speedbar-update-flag-disable nil
764 "Permanently disable changing of the update flag.")
766 (define-obsolete-variable-alias
767 'speedbar-syntax-table
'speedbar-mode-syntax-table
"24.1")
768 (defvar speedbar-mode-syntax-table
769 (let ((st (make-syntax-table)))
770 ;; Turn off paren matching around here.
771 (modify-syntax-entry ?
\' " " st
)
772 (modify-syntax-entry ?
\" " " st
)
773 (modify-syntax-entry ?\
( " " st
)
774 (modify-syntax-entry ?\
) " " st
)
775 (modify-syntax-entry ?\
{ " " st
)
776 (modify-syntax-entry ?\
} " " st
)
777 (modify-syntax-entry ?\
[ " " st
)
778 (modify-syntax-entry ?\
] " " st
)
780 "Syntax-table used on the speedbar.")
783 (define-obsolete-variable-alias 'speedbar-key-map
'speedbar-mode-map
"24.1")
784 (defvar speedbar-mode-map
785 (let ((map (make-keymap)))
786 (suppress-keymap map t
)
789 (define-key map
"t" 'speedbar-toggle-updates
)
790 (define-key map
"g" 'speedbar-refresh
)
793 (define-key map
"n" 'speedbar-next
)
794 (define-key map
"p" 'speedbar-prev
)
795 (define-key map
"\M-n" 'speedbar-restricted-next
)
796 (define-key map
"\M-p" 'speedbar-restricted-prev
)
797 (define-key map
"\C-\M-n" 'speedbar-forward-list
)
798 (define-key map
"\C-\M-p" 'speedbar-backward-list
)
799 ;; These commands never seemed useful.
800 ;; (define-key map " " 'speedbar-scroll-up)
801 ;; (define-key map [delete] 'speedbar-scroll-down)
803 ;; Short cuts I happen to find useful.
805 (lambda () (interactive)
806 (speedbar-change-initial-expansion-list
807 speedbar-previously-used-expansion-list-name
)))
809 (lambda () (interactive)
810 (speedbar-change-initial-expansion-list "quick buffers")))
812 (lambda () (interactive)
813 (speedbar-change-initial-expansion-list "files")))
815 (dframe-update-keymap map
)
817 "Keymap used in speedbar buffer.")
819 (defun speedbar-make-specialized-keymap ()
820 "Create a keymap for use with a speedbar major or minor display mode.
821 This basically creates a sparse keymap, and makes its parent be
822 `speedbar-mode-map'."
823 (let ((k (make-sparse-keymap)))
824 (set-keymap-parent k speedbar-mode-map
)
827 (defvar speedbar-file-key-map
828 (let ((map (speedbar-make-specialized-keymap)))
830 ;; Basic tree features.
831 (define-key map
"e" 'speedbar-edit-line
)
832 (define-key map
"\C-m" 'speedbar-edit-line
)
833 (define-key map
"+" 'speedbar-expand-line
)
834 (define-key map
"=" 'speedbar-expand-line
)
835 (define-key map
"-" 'speedbar-contract-line
)
837 (define-key map
"[" 'speedbar-expand-line-descendants
)
838 (define-key map
"]" 'speedbar-contract-line-descendants
)
840 (define-key map
" " 'speedbar-toggle-line-expansion
)
842 ;; File based commands.
843 (define-key map
"U" 'speedbar-up-directory
)
844 (define-key map
"I" 'speedbar-item-info
)
845 (define-key map
"B" 'speedbar-item-byte-compile
)
846 (define-key map
"L" 'speedbar-item-load
)
847 (define-key map
"C" 'speedbar-item-copy
)
848 (define-key map
"D" 'speedbar-item-delete
)
849 (define-key map
"O" 'speedbar-item-object-delete
)
850 (define-key map
"R" 'speedbar-item-rename
)
851 (define-key map
"M" 'speedbar-create-directory
)
853 "Keymap used in speedbar buffer while files are displayed.")
855 (defvar speedbar-easymenu-definition-base
858 ["Update" speedbar-refresh t
]
859 ["Auto Update" speedbar-toggle-updates
860 :active
(not speedbar-update-flag-disable
)
861 :style toggle
:selected speedbar-update-flag
])
862 (if (and (or (fboundp 'defimage
)
863 (fboundp 'make-image-specifier
))
864 (if (fboundp 'display-graphic-p
)
868 ["Use Images" speedbar-toggle-images
869 :style toggle
:selected speedbar-use-images
]))
871 "Base part of the speedbar menu.")
873 (defvar speedbar-easymenu-definition-special
874 '(["Edit Item On Line" speedbar-edit-line t
]
875 ["Show All Files" speedbar-toggle-show-all-files
876 :style toggle
:selected speedbar-show-unknown-files
]
877 ["Expand File Tags" speedbar-expand-line
878 (save-excursion (beginning-of-line)
879 (looking-at "[0-9]+: *.\\+. "))]
880 ["Flush Cache & Expand" speedbar-flush-expand-line
881 (save-excursion (beginning-of-line)
882 (looking-at "[0-9]+: *.\\+. "))]
883 ["Expand All Descendants" speedbar-expand-line-descendants
884 (save-excursion (beginning-of-line)
885 (looking-at "[0-9]+: *.\\+. ")) ]
886 ["Contract File Tags" speedbar-contract-line
887 (save-excursion (beginning-of-line)
888 (looking-at "[0-9]+: *.-. "))]
889 ; ["Sort Tags" speedbar-toggle-sorting
890 ; :style toggle :selected speedbar-sort-tags]
892 ["File/Tag Information" speedbar-item-info t
]
893 ["Load Lisp File" speedbar-item-load
896 (looking-at "[0-9]+: *\\[[+-]\\] .+\\(\\.el\\)\\( \\|$\\)"))]
897 ["Byte Compile File" speedbar-item-byte-compile
900 (looking-at "[0-9]+: *\\[[+-]\\] .+\\(\\.el\\)\\( \\|$\\)"))]
901 ["Copy File" speedbar-item-copy
902 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *\\["))]
903 ["Rename File" speedbar-item-rename
904 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
905 ["Create Directory" speedbar-create-directory
906 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
907 ["Delete File" speedbar-item-delete
908 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
909 ["Delete Object" speedbar-item-object-delete
910 (save-excursion (beginning-of-line)
911 (looking-at "[0-9]+: *\\[[+-]\\] [^ \n]+ \\*?[!#]$"))]
913 "Additional menu items while in file-mode.")
915 (defvar speedbar-easymenu-definition-trailer
917 (if (and (featurep 'custom
) (fboundp 'custom-declare-variable
))
918 (list ["Customize..." speedbar-customize t
]))
920 ["Close" dframe-close-frame t
]
921 ["Quit" delete-frame t
] ))
922 "Menu items appearing at the end of the speedbar menu.")
924 (defvar speedbar-desired-buffer nil
925 "Non-nil when speedbar is showing buttons specific to a special mode.
926 In this case it is the originating buffer.")
927 (defvar speedbar-buffer nil
928 "The buffer displaying the speedbar.")
929 (defvar speedbar-frame nil
930 "The frame displaying speedbar.")
931 (defvar speedbar-cached-frame nil
932 "The frame that was last created, then removed from the display.")
933 (defvar speedbar-full-text-cache nil
934 "The last open directory is saved in its entirety for ultra-fast switching.")
936 (defvar speedbar-last-selected-file nil
937 "The last file which was selected in speedbar buffer.")
939 (defvar speedbar-shown-directories nil
940 "Maintain list of directories simultaneously open in the current speedbar.")
942 (defvar speedbar-directory-contents-alist nil
943 "An association list of directories and their contents.
944 Each sublist was returned by `speedbar-file-lists'. This list is
945 maintained to speed up the refresh rate when switching between
948 (defvar speedbar-power-click nil
949 "Never set this by hand. Value is t when S-mouse activity occurs.")
954 (defalias 'speedbar-make-overlay
955 (if (featurep 'xemacs
) 'make-extent
'make-overlay
))
957 (defalias 'speedbar-overlay-put
958 (if (featurep 'xemacs
) 'set-extent-property
'overlay-put
))
960 (defalias 'speedbar-delete-overlay
961 (if (featurep 'xemacs
) 'delete-extent
'delete-overlay
))
963 (defalias 'speedbar-mode-line-update
964 (if (featurep 'xemacs
) 'redraw-modeline
'force-mode-line-update
))
966 ;;; Mode definitions/ user commands
970 (defalias 'speedbar
'speedbar-frame-mode
)
972 (defun speedbar-frame-mode (&optional arg
)
973 "Enable or disable speedbar. Positive ARG means turn on, negative turn off.
974 A nil ARG means toggle. Once the speedbar frame is activated, a buffer in
975 `speedbar-mode' will be displayed. Currently, only one speedbar is
977 `speedbar-before-popup-hook' is called before popping up the speedbar frame.
978 `speedbar-before-delete-hook' is called before the frame is deleted."
980 ;; Get the buffer to play with
981 (if (not (buffer-live-p speedbar-buffer
))
983 (setq speedbar-buffer
(get-buffer-create " SPEEDBAR"))
984 (set-buffer speedbar-buffer
)
986 ;; Do the frame thing
987 (dframe-frame-mode arg
989 'speedbar-cached-frame
992 #'speedbar-frame-mode
993 (if (featurep 'xemacs
)
994 (append speedbar-frame-plist
995 ;; This is a hack to get speedbar to iconify
996 ;; with the selected frame.
997 (list 'parent
(selected-frame)))
998 speedbar-frame-parameters
)
999 'speedbar-before-delete-hook
1000 'speedbar-before-popup-hook
1001 'speedbar-after-create-hook
)
1002 ;; Start up the timer
1003 (if (not speedbar-frame
)
1004 (speedbar-set-timer nil
)
1005 (speedbar-reconfigure-keymaps)
1006 (speedbar-update-contents)
1007 (speedbar-set-timer dframe-update-speed
)
1009 ;; Frame modifications
1010 (set (make-local-variable 'dframe-delete-frame-function
)
1011 'speedbar-handle-delete-frame
)
1013 (set (make-local-variable 'auto-hscroll-mode
) nil
)
1014 ;; reset the selection variable
1015 (setq speedbar-last-selected-file nil
))
1017 (defun speedbar-frame-reposition-smartly ()
1018 "Reposition the speedbar frame to be next to the attached frame."
1019 (cond ((and (featurep 'xemacs
)
1020 (or (member 'left speedbar-frame-plist
)
1021 (member 'top speedbar-frame-plist
)))
1022 (dframe-reposition-frame
1024 (dframe-attached-frame speedbar-frame
)
1025 (cons (car (cdr (member 'left speedbar-frame-plist
)))
1026 (car (cdr (member 'top speedbar-frame-plist
)))))
1028 ((and (not (featurep 'xemacs
))
1029 (or (assoc 'left speedbar-frame-parameters
)
1030 (assoc 'top speedbar-frame-parameters
)))
1031 ;; if left/top were specified in the parameters, pass them
1032 ;; down to the reposition function
1033 (dframe-reposition-frame
1035 (dframe-attached-frame speedbar-frame
)
1036 (cons (cdr (assoc 'left speedbar-frame-parameters
))
1037 (cdr (assoc 'top speedbar-frame-parameters
))))
1040 (dframe-reposition-frame speedbar-frame
1041 (dframe-attached-frame speedbar-frame
)
1042 speedbar-default-position
))))
1044 (defsubst speedbar-current-frame
()
1045 "Return the frame to use for speedbar based on current context."
1046 (dframe-current-frame 'speedbar-frame
'speedbar-mode
))
1048 (defun speedbar-handle-delete-frame (e)
1049 "Handle a delete frame event E.
1050 If the deleted frame is the frame speedbar is attached to,
1051 we need to delete speedbar also."
1052 (when (and speedbar-frame
1053 (eq (car (car (cdr e
))) ;; frame to be deleted
1054 dframe-attached-frame
))
1055 (delete-frame speedbar-frame
)))
1058 (defun speedbar-get-focus ()
1059 "Change frame focus to or from the speedbar frame.
1060 If the selected frame is not speedbar, then speedbar frame is
1061 selected. If the speedbar frame is active, then select the attached frame."
1063 (speedbar-reset-scanners)
1064 (dframe-get-focus 'speedbar-frame
'speedbar-frame-mode
)
1065 (let ((speedbar-update-flag t
))
1066 (speedbar-timer-fn)))
1068 (defsubst speedbar-frame-width
()
1069 "Return the width of the speedbar frame in characters.
1070 Return nil if it doesn't exist."
1071 (frame-width speedbar-frame
))
1073 (define-derived-mode speedbar-mode fundamental-mode
"Speedbar"
1074 "Major mode for managing a display of directories and tags.
1075 \\<speedbar-mode-map>
1076 The first line represents the default directory of the speedbar frame.
1077 Each directory segment is a button which jumps speedbar's default
1078 directory to that directory. Buttons are activated by clicking `\\[speedbar-click]'.
1079 In some situations using `\\[dframe-power-click]' is a `power click' which will
1080 rescan cached items, or pop up new frames.
1082 Each line starting with <+> represents a directory. Click on the <+>
1083 to insert the directory listing into the current tree. Click on the
1084 <-> to retract that list. Click on the directory name to go to that
1085 directory as the default.
1087 Each line starting with [+] is a file. If the variable
1088 `speedbar-show-unknown-files' is t, the lines starting with [?] are
1089 files which don't have imenu support, but are not expressly ignored.
1090 Files are completely ignored if they match `speedbar-file-unshown-regexp'
1091 which is generated from `completion-ignored-extensions'.
1093 Files with a `*' character after their name are files checked out of a
1094 version control system. (Currently only RCS is supported.) New
1095 version control systems can be added by examining the documentation
1096 for `speedbar-this-file-in-vc' and `speedbar-vc-check-dir-p'.
1098 Files with a `#' or `!' character after them are source files that
1099 have an object file associated with them. The `!' indicates that the
1100 files is out of date. You can control what source/object associations
1101 exist through the variable `speedbar-obj-alist'.
1103 Click on the [+] to display a list of tags from that file. Click on
1104 the [-] to retract the list. Click on the file name to edit the file
1105 in the attached frame.
1107 If you open tags, you might find a node starting with {+}, which is a
1108 category of tags. Click the {+} to expand the category. Jump-able
1109 tags start with >. Click the name of the tag to go to that position
1110 in the selected file.
1112 \\{speedbar-mode-map}"
1114 (setq font-lock-keywords nil
) ;; no font-locking please
1115 (setq truncate-lines t
)
1116 (make-local-variable 'frame-title-format
)
1117 (setq frame-title-format
(concat "Speedbar " speedbar-version
)
1118 case-fold-search nil
1120 (speedbar-set-mode-line-format)
1121 ;; Add in our dframe hooks.
1122 (if speedbar-track-mouse-flag
1123 (setq dframe-track-mouse-function
#'speedbar-track-mouse
))
1124 (setq dframe-help-echo-function
#'speedbar-item-info
1125 dframe-mouse-click-function
#'speedbar-click
1126 dframe-mouse-position-function
#'speedbar-position-cursor-on-line
))
1129 (define-obsolete-function-alias 'speedbar-message
'dframe-message
"24.4")
1131 (defsubst speedbar-y-or-n-p
(prompt &optional deleting
)
1132 "Like `y-or-n-p', but for use in the speedbar frame.
1133 Argument PROMPT is the prompt to use.
1134 Optional argument DELETING means this is a query that will delete something.
1135 The variable `speedbar-query-confirmation-method' can cause this to
1136 return true without a query."
1137 (or (and (not deleting
)
1138 (eq speedbar-query-confirmation-method
'none-but-delete
))
1139 (dframe-y-or-n-p prompt
)))
1141 (defsubst speedbar-select-attached-frame
()
1142 "Select the frame attached to this speedbar."
1143 (dframe-select-attached-frame (speedbar-current-frame)))
1145 ;; Backwards compatibility
1146 (define-obsolete-function-alias 'speedbar-with-attached-buffer
1147 'dframe-with-attached-buffer
"24.4") ; macro
1148 (define-obsolete-function-alias 'speedbar-maybee-jump-to-attached-frame
1149 'dframe-maybee-jump-to-attached-frame
"24.4")
1151 (defun speedbar-set-mode-line-format ()
1152 "Set the format of the mode line based on the current speedbar environment.
1153 This gives visual indications of what is up. It EXPECTS the speedbar
1154 frame and window to be the currently active frame and window."
1155 (if (and (frame-live-p (speedbar-current-frame))
1156 (or (not (featurep 'xemacs
))
1158 (specifier-instance has-modeline-p
)))
1160 (with-current-buffer speedbar-buffer
1161 (let* ((w (or (speedbar-frame-width) 20))
1164 (p3 (if speedbar-update-flag
"#" "!"))
1165 (p35 (capitalize speedbar-initial-expansion-list-name
))
1166 (blank (- w
(length p1
) (length p3
) (length p5
) (length p35
)
1167 (if line-number-mode
5 1)))
1169 (make-string (/ blank
2) ?
)
1172 (make-string (+ (/ blank
2) (% blank
2)) ?
)
1175 (if line-number-mode
1176 (list (concat p1 p2 p3
" " p35
) '(line-number-mode " %3l")
1178 (list (concat p1 p2 p3 p4 p5
)))))
1179 (if (not (equal mode-line-format tf
))
1181 (setq mode-line-format tf
)
1182 (speedbar-mode-line-update)))))))
1184 (defvar speedbar-previous-menu nil
1185 "The menu before the last `speedbar-reconfigure-keymaps' was called.")
1187 (defun speedbar-reconfigure-keymaps ()
1188 "Reconfigure the menu-bar in a speedbar frame.
1189 Different menu items are displayed depending on the current display mode
1190 and the existence of packages."
1192 speedbar-easymenu-definition-base
1193 (if speedbar-shown-directories
1194 ;; file display mode version
1195 (speedbar-initial-menu)
1197 (dframe-select-attached-frame speedbar-frame
)
1198 (eval (nth 1 (assoc speedbar-initial-expansion-list-name
1199 speedbar-initial-expansion-mode-alist
)))))
1200 ;; Dynamic menu stuff
1202 (list (cons "Displays"
1203 (let ((displays nil
)
1204 (alist speedbar-initial-expansion-mode-alist
))
1209 (capitalize (car (car alist
)))
1211 'speedbar-change-initial-expansion-list
1215 `(string= ,(car (car alist
))
1216 speedbar-initial-expansion-list-name
)
1219 (setq alist
(cdr alist
)))
1222 speedbar-easymenu-definition-trailer
))
1223 (localmap (save-excursion
1224 (let ((cf (selected-frame)))
1226 (dframe-select-attached-frame speedbar-frame
)
1227 (if (local-variable-p
1228 'speedbar-special-mode-key-map
1230 speedbar-special-mode-key-map
)
1231 (select-frame cf
))))))
1232 (with-current-buffer speedbar-buffer
1233 (use-local-map (or localmap
1234 (speedbar-initial-keymap)
1235 ;; This creates a small keymap we can glom the
1236 ;; menu adjustments into.
1237 (speedbar-make-specialized-keymap)))
1238 ;; Delete the old menu if applicable.
1239 (if speedbar-previous-menu
(easy-menu-remove speedbar-previous-menu
))
1240 (setq speedbar-previous-menu md
)
1241 ;; Now add the new menu
1242 (if (not (featurep 'xemacs
))
1243 (easy-menu-define speedbar-menu-map
(current-local-map)
1245 (easy-menu-add md
(current-local-map))
1247 (if (fboundp 'set-buffer-menubar
)
1248 (set-buffer-menubar (list md
)))))
1250 (run-hooks 'speedbar-reconfigure-keymaps-hook
)))
1253 ;;; User Input stuff
1255 (defun speedbar-customize ()
1256 "Customize speedbar using the Custom package."
1258 (let ((sf (selected-frame)))
1259 (dframe-select-attached-frame speedbar-frame
)
1260 (customize-group 'speedbar
)
1262 (dframe-maybee-jump-to-attached-frame))
1264 (defun speedbar-track-mouse (event)
1265 "For motion EVENT, display info about the current line."
1266 (if (not speedbar-track-mouse-flag
)
1269 (save-window-excursion
1272 (mouse-set-point event
)
1273 (if (eq major-mode
'speedbar-mode
)
1274 ;; XEmacs may let us get in here in other mode buffers.
1275 (speedbar-item-info)))
1276 (error (dframe-message nil
)))))))
1278 (defun speedbar-show-info-under-mouse ()
1279 "Call the info function for the line under the mouse."
1280 (let ((pos (mouse-position))) ; we ignore event until I use it later.
1281 (if (equal (car pos
) speedbar-frame
)
1283 (save-window-excursion
1284 (apply 'set-mouse-position pos
)
1285 (speedbar-item-info))))))
1287 (defun speedbar-next (arg)
1288 "Move to the next ARGth line in a speedbar buffer."
1290 (forward-line (or arg
1))
1291 (speedbar-item-info)
1292 (speedbar-position-cursor-on-line))
1294 (defun speedbar-prev (arg)
1295 "Move to the previous ARGth line in a speedbar buffer."
1297 (speedbar-next (if arg
(- arg
) -
1)))
1299 (defun speedbar-restricted-move (arg)
1300 "Move to the next ARGth line in a speedbar buffer at the same depth.
1301 This means that movement is restricted to a subnode, and that siblings
1302 of intermediate nodes are skipped."
1303 (if (not (numberp arg
)) (signal 'wrong-type-argument
(list 'numberp arg
)))
1304 ;; First find the extent for which we are allowed to move.
1305 (let ((depth (save-excursion (beginning-of-line)
1306 (if (looking-at "[0-9]+:")
1307 (string-to-number (match-string 0))
1309 (crement (if (< arg
0) 1 -
1)) ; decrement or increment
1310 (lastmatch (point)))
1312 (forward-line (- crement
))
1313 (let ((subdepth (save-excursion (beginning-of-line)
1314 (if (looking-at "[0-9]+:")
1315 (string-to-number (match-string 0))
1317 (cond ((or (< subdepth depth
)
1318 (progn (end-of-line) (eobp))
1319 (progn (beginning-of-line) (bobp)))
1320 ;; We have reached the end of this block.
1321 (goto-char lastmatch
)
1323 (error "End of sub-list"))
1325 (setq lastmatch
(point)
1326 arg
(+ arg crement
))))))
1327 (speedbar-position-cursor-on-line)))
1329 (defun speedbar-restricted-next (arg)
1330 "Move to the next ARGth line in a speedbar buffer at the same depth.
1331 This means that movement is restricted to a subnode, and that siblings
1332 of intermediate nodes are skipped."
1334 (speedbar-restricted-move (or arg
1))
1335 (speedbar-item-info))
1337 (defun speedbar-restricted-prev (arg)
1338 "Move to the previous ARGth line in a speedbar buffer at the same depth.
1339 This means that movement is restricted to a subnode, and that siblings
1340 of intermediate nodes are skipped."
1342 (speedbar-restricted-move (if arg
(- arg
) -
1))
1343 (speedbar-item-info))
1345 (defun speedbar-navigate-list (arg)
1346 "Move across ARG groups of similarly typed items in speedbar.
1347 Stop on the first line of the next type of item, or on the last or first item
1348 if we reach a buffer boundary."
1351 (if (looking-at "[0-9]+: *[[<{][-+?][]>}] ")
1352 (let ((str (regexp-quote (match-string 0))))
1353 (while (looking-at str
)
1354 (speedbar-restricted-move arg
)
1355 (beginning-of-line))))
1356 (speedbar-position-cursor-on-line))
1358 (defun speedbar-forward-list ()
1359 "Move forward over the current list.
1360 A LIST in speedbar is a group of similarly typed items, such as directories,
1361 files, or the directory button."
1363 (speedbar-navigate-list 1)
1364 (speedbar-item-info))
1366 (defun speedbar-backward-list ()
1367 "Move backward over the current list.
1368 A LIST in speedbar is a group of similarly typed items, such as directories,
1369 files, or the directory button."
1371 (speedbar-navigate-list -
1)
1372 (speedbar-item-info))
1374 (defun speedbar-scroll-up (&optional arg
)
1375 "Page down one screen-full of the speedbar, or ARG lines."
1378 (speedbar-position-cursor-on-line))
1380 (defun speedbar-scroll-down (&optional arg
)
1381 "Page up one screen-full of the speedbar, or ARG lines."
1384 (speedbar-position-cursor-on-line))
1386 (defun speedbar-up-directory ()
1387 "Keyboard accelerator for moving the default directory up one.
1388 Assumes that the current buffer is the speedbar buffer."
1390 (setq default-directory
(expand-file-name (concat default-directory
"../")))
1391 (speedbar-update-contents))
1393 ;;; Speedbar file activity (aka creeping featurism)
1395 (defun speedbar-refresh (&optional arg
)
1396 "Refresh the current speedbar display, disposing of any cached data.
1397 Argument ARG represents to force a refresh past any caches that may exist."
1399 (let ((dl speedbar-shown-directories
)
1400 (dframe-power-click arg
)
1402 ;; We need to hack something so this works in detached frames.
1404 (setq speedbar-directory-contents-alist
1405 (delq (assoc d speedbar-directory-contents-alist
)
1406 speedbar-directory-contents-alist
)))
1407 (if (<= 1 speedbar-verbosity-level
)
1408 (dframe-message "Refreshing speedbar..."))
1409 (speedbar-update-contents)
1410 (speedbar-stealthy-updates)
1411 ;; Reset the timer in case it got really hosed for some reason...
1412 (speedbar-set-timer dframe-update-speed
)
1413 (if (<= 1 speedbar-verbosity-level
)
1414 (dframe-message "Refreshing speedbar...done"))))
1416 (defun speedbar-item-load ()
1417 "Load the item under the cursor or mouse if it is a Lisp file."
1419 (let ((f (speedbar-line-file)))
1420 (if (and (file-exists-p f
) (string-match "\\.el\\'" f
))
1421 (if (and (file-exists-p (concat f
"c"))
1422 (speedbar-y-or-n-p (format "Load %sc? " f
)))
1423 ;; If the compiled version exists, load that instead...
1424 (load-file (concat f
"c"))
1426 (error "Not a loadable file"))))
1428 (defun speedbar-item-byte-compile ()
1429 "Byte compile the item under the cursor or mouse if it is a Lisp file."
1431 (let ((f (speedbar-line-file))
1432 (sf (selected-frame)))
1433 (if (and (file-exists-p f
) (string-match "\\.el\\'" f
))
1435 (dframe-select-attached-frame speedbar-frame
)
1436 (byte-compile-file f nil
)
1438 (speedbar-reset-scanners)))
1441 (defun speedbar-mouse-item-info (event)
1442 "Provide information about what the user clicked on.
1443 This should be bound to a mouse EVENT."
1445 (mouse-set-point event
)
1446 (speedbar-item-info))
1448 (defun speedbar-generic-item-info ()
1449 "Attempt to derive, and then display information about this line item.
1450 File style information is displayed with `speedbar-item-info'."
1453 ;; Skip invisible number info.
1454 (if (looking-at "\\([0-9]+\\):") (goto-char (match-end 0)))
1455 ;; Skip items in "folder" type text characters.
1456 (if (looking-at "\\s-*[[<({].[]>)}] ") (goto-char (match-end 0)))
1458 (dframe-message "Text: %s" (buffer-substring-no-properties
1459 (point) (line-end-position)))))
1461 (defun speedbar-item-info ()
1462 "Display info in the minibuffer about the button the mouse is over.
1463 This function can be replaced in `speedbar-mode-functions-list' as
1464 `speedbar-item-info'."
1466 (let (message-log-max)
1467 (funcall (or (speedbar-fetch-replacement-function 'speedbar-item-info
)
1468 'speedbar-generic-item-info
))))
1470 (defun speedbar-item-info-file-helper (&optional filename
)
1471 "Display info about a file that is on the current line.
1472 Return nil if not applicable. If FILENAME, then use that
1473 instead of reading it from the speedbar buffer."
1474 (let* ((item (or filename
(speedbar-line-file)))
1475 (attr (if item
(file-attributes item
) nil
)))
1476 (if (and item attr
) (dframe-message "%s %-6d %s" (nth 8 attr
)
1480 (defun speedbar-item-info-tag-helper ()
1481 "Display info about a tag that is on the current line.
1482 Return nil if not applicable."
1485 (if (re-search-forward " [-+=]?> \\([^\n]+\\)" (line-end-position) t
)
1486 (let* ((tag (match-string 1))
1487 (attr (speedbar-line-token))
1489 (semantic-tagged (if (fboundp 'semantic-tag-p
)
1490 (semantic-tag-p attr
))))
1494 (when (and (semantic-tag-overlay attr
)
1495 (semantic-tag-buffer attr
))
1496 (set-buffer (semantic-tag-buffer attr
)))
1498 (funcall semantic-sb-info-format-tag-function attr
)
1500 (looking-at "\\([0-9]+\\):")
1501 (setq item
(file-name-nondirectory (speedbar-line-directory)))
1502 (dframe-message "Tag: %s in %s" tag item
)))
1503 (if (re-search-forward "{[+-]} \\([^\n]+\\)$" (line-end-position) t
)
1504 (dframe-message "Group of tags \"%s\"" (match-string 1))
1505 (if (re-search-forward " [+-]?[()|@] \\([^\n]+\\)$" nil t
)
1506 (let* ((detailtext (match-string 1))
1507 (detail (or (speedbar-line-token) detailtext
))
1508 (parent (save-excursion
1510 (let ((dep (if (looking-at "[0-9]+:")
1511 (1- (string-to-number (match-string 0)))
1513 (re-search-backward (concat "^"
1517 (if (looking-at "[0-9]+: +[-+=>]> \\([^\n]+\\)$")
1518 (speedbar-line-token)
1520 (if (featurep 'semantic
)
1522 (if (semantic-tag-p detail
)
1524 (funcall semantic-sb-info-format-tag-function detail parent
))
1526 (dframe-message "Detail: %s of tag %s" detail
1527 (if (semantic-tag-p parent
)
1528 (semantic-format-tag-name parent nil t
)
1530 (dframe-message "Detail: %s" detail
))))
1531 ;; Not using `semantic':
1533 (dframe-message "Detail: %s of tag %s" detail parent
)
1534 (dframe-message "Detail: %s" detail
))))
1537 (defun speedbar-files-item-info ()
1538 "Display info in the minibuffer about the button the mouse is over."
1539 (if (not speedbar-shown-directories
)
1540 (speedbar-generic-item-info)
1541 (or (speedbar-item-info-file-helper)
1542 (speedbar-item-info-tag-helper)
1543 (speedbar-generic-item-info))))
1545 (defun speedbar-item-copy ()
1546 "Copy the item under the cursor.
1547 Files can be copied to new names or places."
1549 (let ((f (speedbar-line-file)))
1550 (if (not f
) (error "Not a file"))
1551 (if (file-directory-p f
)
1552 (error "Cannot copy directory")
1553 (let* ((rt (read-file-name (format "Copy %s to: "
1554 (file-name-nondirectory f
))
1555 (file-name-directory f
)))
1556 (refresh (member (expand-file-name (file-name-directory rt
))
1557 speedbar-shown-directories
)))
1558 ;; Create the right file name part
1559 (if (file-directory-p rt
)
1561 (concat (expand-file-name rt
)
1562 (if (string-match "[/\\]$" rt
) "" "/")
1563 (file-name-nondirectory f
))))
1564 (if (or (not (file-exists-p rt
))
1565 (speedbar-y-or-n-p (format "Overwrite %s with %s? " rt f
)
1568 (copy-file f rt t t
)
1569 ;; refresh display if the new place is currently displayed.
1573 (if (not (speedbar-goto-this-file rt
))
1574 (speedbar-goto-this-file f
))))
1577 (defun speedbar-item-rename ()
1578 "Rename the item under the cursor or mouse.
1579 Files can be renamed to new names or moved to new directories."
1581 (let ((f (speedbar-line-file)))
1583 (let* ((rt (read-file-name (format "Rename %s to: "
1584 (file-name-nondirectory f
))
1585 (file-name-directory f
)))
1586 (refresh (member (expand-file-name (file-name-directory rt
))
1587 speedbar-shown-directories
)))
1588 ;; Create the right file name part
1589 (if (file-directory-p rt
)
1591 (concat (expand-file-name rt
)
1592 (if (string-match "[/\\]\\'" rt
) "" "/")
1593 (file-name-nondirectory f
))))
1594 (if (or (not (file-exists-p rt
))
1595 (speedbar-y-or-n-p (format "Overwrite %s with %s? " rt f
)
1598 (rename-file f rt t
)
1599 ;; refresh display if the new place is currently displayed.
1603 (speedbar-goto-this-file rt
)
1605 (error "Not a file"))))
1607 (defun speedbar-create-directory ()
1608 "Create a directory in speedbar."
1610 (let ((f (speedbar-line-file)))
1612 (let* ((basedir (file-name-directory f
))
1613 (nd (read-directory-name "Create directory: "
1615 ;; Make the directory
1616 (make-directory nd t
)
1618 (speedbar-goto-this-file nd
)
1620 (error "Not a file"))))
1622 (defun speedbar-item-delete ()
1623 "Delete the item under the cursor. Files are removed from disk."
1625 (let ((f (speedbar-line-file)))
1626 (if (not f
) (error "Not a file"))
1627 (if (speedbar-y-or-n-p (format "Delete %s? " f
) t
)
1629 (if (file-directory-p f
)
1630 (delete-directory f t t
)
1632 (dframe-message "Okie dokie.")
1639 (defun speedbar-item-object-delete ()
1640 "Delete the object associated from the item under the cursor.
1641 The file is removed from disk. The object is determined from the
1642 variable `speedbar-obj-alist'."
1644 (let* ((f (speedbar-line-file))
1646 (oa speedbar-obj-alist
))
1647 (if (not f
) (error "Not a file"))
1648 (while (and oa
(not (string-match (car (car oa
)) f
)))
1650 (setq obj
(concat (file-name-sans-extension f
) (cdr (car oa
))))
1651 (if (and oa
(file-exists-p obj
)
1652 (speedbar-y-or-n-p (format "Delete %s? " obj
) t
))
1655 (speedbar-reset-scanners)))))
1657 (defun speedbar-enable-update ()
1658 "Enable automatic updating in speedbar via timers."
1660 (setq speedbar-update-flag t
)
1661 (speedbar-set-mode-line-format)
1662 (speedbar-set-timer dframe-update-speed
))
1664 (defun speedbar-disable-update ()
1665 "Disable automatic updating and stop consuming resources."
1667 (setq speedbar-update-flag nil
)
1668 (speedbar-set-mode-line-format)
1669 (speedbar-set-timer nil
))
1671 (defun speedbar-toggle-updates ()
1672 "Toggle automatic update for the speedbar frame."
1674 (if speedbar-update-flag
1675 (speedbar-disable-update)
1676 (speedbar-enable-update)))
1678 (defun speedbar-toggle-images ()
1679 "Toggle use of images in the speedbar frame."
1681 (setq speedbar-use-images
(not speedbar-use-images
))
1684 (defun speedbar-toggle-sorting ()
1685 "Toggle tag sorting."
1687 (setq speedbar-sort-tags
(not speedbar-sort-tags
)))
1689 (defun speedbar-toggle-show-all-files ()
1690 "Toggle display of files speedbar can not tag."
1692 (setq speedbar-show-unknown-files
(not speedbar-show-unknown-files
))
1695 (defmacro speedbar-with-writable
(&rest forms
)
1696 "Allow the buffer to be writable and evaluate FORMS."
1697 (declare (indent 0))
1698 `(let ((inhibit-read-only t
))
1701 (defun speedbar-insert-button (text face mouse function
1702 &optional token prevline
)
1703 "Insert TEXT as the next logical speedbar button.
1704 FACE is the face to put on the button, MOUSE is the highlight face to use.
1705 When the user clicks on TEXT, FUNCTION is called with the TOKEN parameter.
1706 This function assumes that the current buffer is the speedbar buffer.
1707 If PREVLINE, then put this button on the previous line.
1709 This is a convenience function for special modes that create their own
1710 specialized speedbar displays."
1711 (goto-char (point-max))
1712 (let ((start (point)))
1713 (if (/= (current-column) 0) (insert "\n"))
1714 (put-text-property start
(point) 'invisible nil
))
1715 (if prevline
(progn (delete-char -
1)
1716 (insert " ") ;back up if desired...
1717 (put-text-property (1- (point)) (point) 'invisible nil
)))
1718 (let ((start (point)))
1720 (speedbar-make-button start
(point) face mouse function token
))
1721 (let ((start (point)))
1723 (add-text-properties
1724 start
(point) '(face nil invisible nil mouse-face nil
))))
1726 (defun speedbar-insert-separator (text)
1727 "Insert a separation label of TEXT.
1728 Separators are not active, have no labels, depth, or actions."
1729 (if speedbar-use-images
1730 (let ((start (point)))
1732 (speedbar-insert-image-button-maybe start
2)))
1733 (let ((start (point)))
1735 (speedbar-make-button start
(point)
1736 'speedbar-separator-face
1739 (defun speedbar-make-button (start end face mouse function
&optional token
)
1740 "Create a button from START to END, with FACE as the display face.
1741 MOUSE is the mouse face. When this button is clicked on FUNCTION
1742 will be run with the TOKEN parameter (any Lisp object). If FACE
1743 is t use the text properties of the string that is passed as an
1746 (put-text-property start end
'face face
))
1747 (add-text-properties
1748 start end
`(mouse-face ,mouse invisible nil
1749 speedbar-text
,(buffer-substring-no-properties start end
)))
1750 (if speedbar-use-tool-tips-flag
1751 (put-text-property start end
'help-echo
#'dframe-help-echo
))
1752 (if function
(put-text-property start end
'speedbar-function function
))
1753 (if token
(put-text-property start end
'speedbar-token token
))
1754 ;; So far the only text we have is less that 3 chars.
1755 (if (<= (- end start
) 3)
1756 (speedbar-insert-image-button-maybe start
(- end start
)))
1759 ;;; Initial Expansion list management
1761 (defun speedbar-initial-expansion-list ()
1762 "Return the current default expansion list.
1763 This is based on `speedbar-initial-expansion-list-name' referencing
1764 `speedbar-initial-expansion-mode-alist'."
1765 ;; cdr1 - name, cdr2 - menu
1766 (cdr (cdr (cdr (assoc speedbar-initial-expansion-list-name
1767 speedbar-initial-expansion-mode-alist
)))))
1769 (defun speedbar-initial-menu ()
1770 "Return the current default menu data.
1771 This is based on `speedbar-initial-expansion-list-name' referencing
1772 `speedbar-initial-expansion-mode-alist'."
1774 (car (cdr (assoc speedbar-initial-expansion-list-name
1775 speedbar-initial-expansion-mode-alist
)))))
1777 (defun speedbar-initial-keymap ()
1778 "Return the current default menu data.
1779 This is based on `speedbar-initial-expansion-list-name' referencing
1780 `speedbar-initial-expansion-mode-alist'."
1782 (car (cdr (cdr (assoc speedbar-initial-expansion-list-name
1783 speedbar-initial-expansion-mode-alist
))))))
1785 (defun speedbar-initial-stealthy-functions ()
1786 "Return a list of functions to call stealthily.
1787 This is based on `speedbar-initial-expansion-list-name' referencing
1788 `speedbar-stealthy-function-list'."
1789 (cdr (assoc speedbar-initial-expansion-list-name
1790 speedbar-stealthy-function-list
)))
1792 (defun speedbar-add-expansion-list (new-list)
1793 "Add NEW-LIST to the list of expansion lists."
1794 (add-to-list 'speedbar-initial-expansion-mode-alist new-list
))
1796 (defun speedbar-change-initial-expansion-list (new-default)
1797 "Change speedbar's default expansion list to NEW-DEFAULT."
1800 (completing-read (format "Speedbar Mode (default %s): "
1801 speedbar-previously-used-expansion-list-name
)
1802 speedbar-initial-expansion-mode-alist
1804 speedbar-previously-used-expansion-list-name
)))
1805 (setq speedbar-previously-used-expansion-list-name
1806 speedbar-initial-expansion-list-name
1807 speedbar-initial-expansion-list-name new-default
)
1808 (if (and (speedbar-current-frame) (frame-live-p (speedbar-current-frame)))
1811 (speedbar-reconfigure-keymaps))))
1813 (defun speedbar-fetch-replacement-function (function)
1814 "Return a current mode-specific replacement for function, or nil.
1815 Scans `speedbar-mode-functions-list' first for the current mode, then
1817 (cdr (assoc function
1818 (cdr (assoc speedbar-initial-expansion-list-name
1819 speedbar-mode-functions-list
)))))
1821 (defun speedbar-add-mode-functions-list (new-list)
1822 "Add NEW-LIST to the list of mode functions.
1823 See `speedbar-mode-functions-list' for details."
1824 (add-to-list 'speedbar-mode-functions-list new-list
))
1827 ;;; Special speedbar display management
1829 (defun speedbar-maybe-add-localized-support (buffer)
1830 "Quick check function called on BUFFERs by the speedbar timer function.
1831 Maintains the value of local variables which control speedbar's use
1832 of the special mode functions."
1833 (or speedbar-special-mode-expansion-list
1834 (speedbar-add-localized-speedbar-support buffer
)))
1836 (defun speedbar-add-localized-speedbar-support (buffer)
1837 "Add localized speedbar support to BUFFER's mode if it is available."
1838 (interactive "bBuffer: ")
1839 (if (stringp buffer
) (setq buffer
(get-buffer buffer
)))
1840 (if (not (buffer-live-p buffer
))
1842 (with-current-buffer buffer
1844 (let ((ms (symbol-name major-mode
)) v
)
1845 (if (not (string-match "-mode$" ms
))
1846 nil
;; do nothing to broken mode
1847 (setq ms
(substring ms
0 (match-beginning 0)))
1848 (setq v
(intern-soft (concat ms
"-speedbar-buttons")))
1849 (make-local-variable 'speedbar-special-mode-expansion-list
)
1851 (setq speedbar-special-mode-expansion-list t
)
1852 ;; If it is autoloaded, we need to load it now so that
1853 ;; we have access to the variable -speedbar-menu-items.
1854 ;; Is this XEmacs safe?
1855 (autoload-do-load (symbol-function v
) v
)
1856 (setq speedbar-special-mode-expansion-list
(list v
))
1857 (setq v
(intern-soft (concat ms
"-speedbar-key-map")))
1859 nil
;; don't add special keymap
1860 (make-local-variable 'speedbar-special-mode-key-map
)
1861 (setq speedbar-special-mode-key-map
1863 (setq v
(intern-soft (concat ms
"-speedbar-menu-items")))
1865 nil
;; don't add special menus
1866 (make-local-variable 'speedbar-easymenu-definition-special
)
1867 (setq speedbar-easymenu-definition-special
1871 (defun speedbar-remove-localized-speedbar-support (buffer)
1872 "Remove any traces that BUFFER supports speedbar in a specialized way."
1873 (with-current-buffer buffer
1874 (kill-local-variable 'speedbar-special-mode-expansion-list
)
1875 (kill-local-variable 'speedbar-special-mode-key-map
)
1876 (kill-local-variable 'speedbar-easymenu-definition-special
)))
1878 ;;; File button management
1880 (defun speedbar-file-lists (directory)
1881 "Create file lists for DIRECTORY.
1882 The car is the list of directories, the cdr is list of files not
1883 matching ignored headers. Cache any directory files found in
1884 `speedbar-directory-contents-alist' and use that cache before scanning
1886 (setq directory
(expand-file-name directory
))
1887 ;; find the directory, either in the cache, or build it.
1888 (or (and (not dframe-power-click
) ;; In powerclick mode, always rescan.
1889 (cdr-safe (assoc directory speedbar-directory-contents-alist
)))
1890 (let ((default-directory directory
)
1891 (dir (directory-files directory nil
))
1896 (or (string-match speedbar-file-unshown-regexp
(car dir
))
1897 (member (car dir
) vc-directory-exclusion-list
)
1898 (string-match speedbar-directory-unshown-regexp
(car dir
))))
1899 (if (file-directory-p (car dir
))
1900 (setq dirs
(cons (car dir
) dirs
))
1901 (setq files
(cons (car dir
) files
))))
1902 (setq dir
(cdr dir
)))
1903 (let ((nl (cons (nreverse dirs
) (list (nreverse files
))))
1904 (ae (assoc directory speedbar-directory-contents-alist
)))
1905 (if ae
(setcdr ae nl
)
1906 (push (cons directory nl
)
1907 speedbar-directory-contents-alist
))
1911 (defun speedbar-directory-buttons (directory _index
)
1912 "Insert a single button group at point for DIRECTORY.
1913 Each directory part is a different button. If part of the directory
1914 matches the user directory ~, then it is replaced with a ~.
1915 INDEX is not used, but is required by the caller."
1916 (let* ((tilde (expand-file-name "~/"))
1917 (dd (expand-file-name directory
))
1918 (junk (string-match (regexp-quote tilde
) dd
))
1920 (concat "~/" (substring dd
(match-end 0)))
1923 (if (string-match "^~[/\\]?\\'" displayme
) (setq displayme tilde
))
1927 (while (re-search-forward "\\([^/\\]+\\)[/\\]" nil t
)
1928 (speedbar-make-button (match-beginning 1) (match-end 1)
1929 'speedbar-directory-face
1930 'speedbar-highlight-face
1931 'speedbar-directory-buttons-follow
1932 (if (and (= (match-beginning 1) p
)
1933 (not (char-equal (char-after (+ p
1)) ?
:)))
1934 (expand-file-name "~/") ;the tilde
1935 (buffer-substring-no-properties
1937 ;; Nuke the beginning of the directory if it's too long...
1938 (cond ((eq speedbar-directory-button-trim-method
'span
)
1940 (let ((ww (or (speedbar-frame-width) 20)))
1941 (move-to-column ww nil
)
1942 (while (>= (current-column) ww
)
1943 (re-search-backward "[/\\]" nil t
)
1944 (if (<= (current-column) 2)
1946 (re-search-forward "[/\\]" nil t
)
1947 (if (< (current-column) 4)
1948 (re-search-forward "[/\\]" nil t
))
1950 (if (looking-at "[/\\]?$")
1953 (move-to-column ww nil
)))))
1954 ((eq speedbar-directory-button-trim-method
'trim
)
1956 (let ((ww (or (speedbar-frame-width) 20))
1957 (tl (current-column)))
1960 (move-to-column (- tl ww
))
1961 (if (re-search-backward "[/\\]" nil t
)
1963 (delete-region (point-min) (point))
1967 (if (string-match "\\`[/\\][^/\\]+[/\\]\\'" displayme
)
1972 (speedbar-make-button p
(point)
1973 'speedbar-directory-face
1974 'speedbar-highlight-face
1975 'speedbar-directory-buttons-follow
1978 (insert-char ?
\n 1 nil
)))
1980 (defun speedbar-make-tag-line (exp-button-type
1981 exp-button-char exp-button-function
1983 tag-button tag-button-function tag-button-data
1984 tag-button-face depth
)
1985 "Create a tag line with EXP-BUTTON-TYPE for the small expansion button.
1986 This is the button that expands or contracts a node (if applicable),
1987 and EXP-BUTTON-CHAR the character in it (+, -, ?, etc). EXP-BUTTON-FUNCTION
1988 is the function to call if it's clicked on. Button types are
1989 `bracket', `angle', `curly', `expandtag', `statictag', t, or nil.
1990 EXP-BUTTON-DATA is extra data attached to the text forming the expansion
1993 Next, TAG-BUTTON is the text of the tag. TAG-BUTTON-FUNCTION is the
1994 function to call if clicked on, and TAG-BUTTON-DATA is the data to
1995 attach to the text field (such a tag positioning, etc).
1996 TAG-BUTTON-FACE is a face used for this type of tag.
1998 Lastly, DEPTH shows the depth of expansion.
2000 This function assumes that the cursor is in the speedbar window at the
2001 position to insert a new item, and that the new item will end with a CR."
2002 (let ((start (point))
2004 (insert (int-to-string depth
) ":")
2006 (depthspacesize (* depth speedbar-indentation-width
)))
2007 (put-text-property start end
'invisible t
)
2008 (insert-char ? depthspacesize nil
)
2009 (put-text-property (- (point) depthspacesize
) (point) 'invisible nil
)
2010 (let* ((exp-button (cond ((eq exp-button-type
'bracket
) "[%c]")
2011 ((eq exp-button-type
'angle
) "<%c>")
2012 ((eq exp-button-type
'curly
) "{%c}")
2013 ((eq exp-button-type
'expandtag
) " %c>")
2014 ((eq exp-button-type
'statictag
) " =>")
2016 (buttxt (format exp-button exp-button-char
))
2018 (end (progn (insert buttxt
) (point)))
2019 (bf (if (and exp-button-type
(not (eq exp-button-type
'statictag
)))
2020 'speedbar-button-face nil
))
2021 (mf (if exp-button-function
'speedbar-highlight-face nil
))
2023 (speedbar-make-button start end bf mf exp-button-function exp-button-data
)
2024 (if speedbar-hide-button-brackets-flag
2026 (put-text-property start
(1+ start
) 'invisible t
)
2027 (put-text-property end
(1- end
) 'invisible t
)))
2029 (insert-char ?
1 nil
)
2030 (put-text-property (1- (point)) (point) 'invisible nil
)
2031 (let ((start (point))
2032 (end (progn (insert tag-button
) (point))))
2033 (insert-char ?
\n 1 nil
)
2034 (put-text-property (1- (point)) (point) 'invisible nil
)
2035 (speedbar-make-button start end tag-button-face
2036 (if tag-button-function
'speedbar-highlight-face nil
)
2037 tag-button-function tag-button-data
))
2040 (defun speedbar-change-expand-button-char (char)
2041 "Change the expansion button character to CHAR for the current line."
2044 (if (re-search-forward ":\\s-*.\\([-+?]\\)" (line-end-position) t
)
2045 (speedbar-with-writable
2046 (goto-char (match-end 1))
2047 (insert-char char
1 t
)
2050 ;;(put-text-property (point) (1- (point)) 'invisible nil)
2051 ;; make sure we fix the image on the text here.
2052 (speedbar-insert-image-button-maybe (- (point) 1) 3)))))
2055 ;;; Build button lists
2057 (defun speedbar-insert-files-at-point (files level
)
2058 "Insert list of FILES starting at point, and indenting all files to LEVEL.
2059 Tag expandable items with a +, otherwise a ?. Don't highlight ? as we
2060 don't know how to manage them. The input parameter FILES is a cons
2061 cell of the form (DIRLIST . FILELIST)."
2062 ;; Start inserting all the directories
2063 (let ((dirs (car files
)))
2065 (speedbar-make-tag-line 'angle ?
+ 'speedbar-dired
(car dirs
)
2066 (car dirs
) 'speedbar-dir-follow nil
2067 'speedbar-directory-face level
)
2068 (setq dirs
(cdr dirs
))))
2069 (let ((lst (car (cdr files
)))
2070 (case-fold-search t
))
2072 (let* ((known (string-match speedbar-file-regexp
(car lst
)))
2073 (expchar (if known ?
+ ??
))
2074 (fn (if known
'speedbar-tag-file nil
)))
2075 (if (or speedbar-show-unknown-files
(/= expchar ??
))
2076 (speedbar-make-tag-line 'bracket expchar fn
(car lst
)
2077 (car lst
) 'speedbar-find-file nil
2078 'speedbar-file-face level
)))
2079 (setq lst
(cdr lst
)))))
2081 (defun speedbar-default-directory-list (directory index
)
2082 "Insert files for DIRECTORY with level INDEX at point."
2083 (speedbar-insert-files-at-point
2084 (speedbar-file-lists directory
) index
)
2085 (speedbar-reset-scanners)
2087 ;; If the shown files variable has extra directories, then
2088 ;; it is our responsibility to redraw them all
2089 ;; Luckily, the nature of inserting items into this list means
2090 ;; that by reversing it, we can easily go in the right order
2091 (let ((sf (cdr (reverse speedbar-shown-directories
))))
2092 (setq speedbar-shown-directories
2093 (list (expand-file-name default-directory
)))
2094 ;; Expand them all as we find them.
2096 (if (speedbar-goto-this-file (car sf
))
2099 (if (looking-at "[0-9]+:[ ]*<")
2101 (goto-char (match-end 0))
2102 (speedbar-do-function-pointer)))))
2105 ;;; Generic List support
2107 ;; Generic lists are hierarchies of tags which we may need to permute
2108 ;; in order to make it look nice.
2110 ;; A generic list is of the form:
2111 ;; ( ("name" . marker-or-number) <-- one tag at this level
2112 ;; ("name" marker-or-number goto-fun . args) <-- one tag at this level
2113 ;; ("name" ("name" . mon) ("name" . mon) ) <-- one group of tags
2114 ;; ("name" mon ("name" . mon) ) <-- group w/ a position and tags
2115 (defun speedbar-generic-list-group-p (sublst)
2116 "Non-nil if SUBLST is a group.
2117 Groups may optionally contain a position."
2118 (and (stringp (car-safe sublst
))
2119 (or (and (listp (cdr-safe sublst
))
2120 (or (speedbar-generic-list-tag-p (car-safe (cdr-safe sublst
)))
2121 (speedbar-generic-list-group-p (car-safe (cdr-safe sublst
))
2123 (and (number-or-marker-p (car-safe (cdr-safe sublst
)))
2124 (listp (cdr-safe (cdr-safe sublst
)))
2125 (speedbar-generic-list-tag-p
2126 (car-safe (cdr-safe (cdr-safe sublst
)))))
2129 (defun speedbar-generic-list-positioned-group-p (sublst)
2130 "Non-nil if SUBLST is a group with a position."
2131 (and (stringp (car-safe sublst
))
2132 (number-or-marker-p (car-safe (cdr-safe sublst
)))
2133 (listp (cdr-safe (cdr-safe sublst
)))
2134 (let ((rest (car-safe (cdr-safe (cdr-safe sublst
)))))
2135 (or (speedbar-generic-list-tag-p rest
)
2136 (speedbar-generic-list-group-p rest
)
2137 (speedbar-generic-list-positioned-group-p rest
)
2140 (defun speedbar-generic-list-tag-p (sublst)
2141 "Non-nil if SUBLST is a tag."
2142 (and (stringp (car-safe sublst
))
2143 (or (and (number-or-marker-p (cdr-safe sublst
))
2144 (not (cdr-safe (cdr-safe sublst
))))
2145 (ignore-errors (and (number-or-marker-p (nth 1 sublst
))
2146 (functionp (nth 2 sublst
))))
2147 ;; For semantic/bovine items, this is needed
2148 (symbolp (car-safe (cdr-safe sublst
))))
2151 (defun speedbar-sort-tag-hierarchy (lst)
2152 "Sort all elements of tag hierarchy LST."
2153 (sort (copy-alist lst
)
2154 (lambda (a b
) (string< (car a
) (car b
)))))
2156 (defun speedbar-try-completion (string alist
)
2157 "A wrapper for `try-completion'.
2158 Passes STRING and ALIST to `try-completion' if ALIST
2160 (if (and (consp alist
)
2161 (listp (car alist
)) (stringp (car (car alist
))))
2162 (try-completion string alist
)
2165 (defun speedbar-prefix-group-tag-hierarchy (lst)
2166 "Prefix group names for tag hierarchy LST."
2171 (short-group-list nil
)
2172 (short-start-name nil
)
2173 (short-end-name nil
)
2174 (num-shorts-grouped 0)
2175 (bins (make-vector 256 nil
))
2177 (if (<= (length lst
) speedbar-tag-regroup-maximum-length
)
2178 ;; Do nothing. Too short to bother with.
2180 ;; Break out sub-lists
2182 (if (speedbar-generic-list-group-p (car-safe lst
))
2183 (setq newlst
(cons (car lst
) newlst
))
2184 (setq sublst
(cons (car lst
) sublst
)))
2185 (setq lst
(cdr lst
)))
2186 ;; Reverse newlst because it was made backwards.
2187 ;; Sublist doesn't need reversing because the act
2188 ;; of binning things will reverse it for us.
2189 (setq newlst
(nreverse newlst
)
2191 ;; Now, first find out how long our list is. Never let a
2192 ;; list get-shorter than our minimum.
2193 (if (<= (length sublst
) speedbar-tag-split-minimum-length
)
2194 (setq work-list sublst
)
2195 (setq diff-idx
(length (speedbar-try-completion "" sublst
)))
2196 ;; Sort the whole list into bins.
2198 (let ((e (car sublst
))
2199 (s (car (car sublst
))))
2200 (cond ((<= (length s
) diff-idx
)
2201 ;; 0 storage bin for shorty.
2202 (aset bins
0 (cons e
(aref bins
0))))
2204 ;; stuff into a bin based on ascii value at diff
2205 (aset bins
(aref s diff-idx
)
2206 (cons e
(aref bins
(aref s diff-idx
)))))))
2207 (setq sublst
(cdr sublst
)))
2208 ;; Go through all our bins Stick singles into our
2209 ;; junk-list, everything else as sublsts in work-list.
2210 ;; If two neighboring lists are both small, make a grouped
2211 ;; group combining those two sub-lists.
2213 (while (> 256 diff-idx
)
2214 ;; The bins contents are currently in forward order.
2215 (let ((l (aref bins diff-idx
)))
2217 (let ((tmp (cons (speedbar-try-completion "" l
) l
)))
2218 (if (or (> (length l
) speedbar-tag-regroup-maximum-length
)
2219 (> (+ (length l
) (length short-group-list
))
2220 speedbar-tag-split-minimum-length
))
2222 ;; We have reached a longer list, so we
2223 ;; must finish off a grouped group.
2225 ((and short-group-list
2226 (= (length short-group-list
)
2227 num-shorts-grouped
))
2228 ;; All singles? Junk list
2229 (setq junk-list
(append (nreverse short-group-list
)
2231 ((= num-shorts-grouped
1)
2232 ;; Only one short group? Just stick it in
2233 ;; there by itself. Make a group, and find
2235 (let ((subexpression (speedbar-try-completion
2236 "" short-group-list
)))
2237 (if (< (length subexpression
)
2238 speedbar-tag-group-name-minimum-length
)
2240 (concat short-start-name
2243 (car (car short-group-list
))
2244 (length short-start-name
))
2247 (cons (cons subexpression
2251 ;; Multiple groups to be named in a special
2252 ;; way by displaying the range over which we
2253 ;; have grouped them.
2255 (cons (cons (concat short-start-name
2260 ;; Reset short group list information every time.
2261 (setq short-group-list nil
2262 short-start-name nil
2264 num-shorts-grouped
0)))
2265 ;; Ok, now that we cleaned up the short-group-list,
2266 ;; we can deal with this new list, to decide if it
2267 ;; should go on one of these sub-lists or not.
2268 (if (< (length l
) speedbar-tag-regroup-maximum-length
)
2269 (setq short-group-list
(append l short-group-list
)
2270 num-shorts-grouped
(1+ num-shorts-grouped
)
2271 short-end-name
(car tmp
)
2272 short-start-name
(if short-start-name
2275 (setq work-list
(cons tmp work-list
))))))
2276 (setq diff-idx
(1+ diff-idx
))))
2277 ;; Did we run out of things? Drop our new list onto the end.
2279 ((and short-group-list
(= (length short-group-list
) num-shorts-grouped
))
2280 ;; All singles? Junk list
2281 (setq junk-list
(append short-group-list junk-list
)))
2282 ((= num-shorts-grouped
1)
2283 ;; Only one short group? Just stick it in
2286 (cons (cons (speedbar-try-completion "" short-group-list
)
2290 ;; Multiple groups to be named in a special
2291 ;; way by displaying the range over which we
2292 ;; have grouped them.
2294 (cons (cons (concat short-start-name
" to " short-end-name
)
2297 ;; Reverse the work list nreversed when consing.
2298 (setq work-list
(nreverse work-list
))
2299 ;; Now, stick our new list onto the end of
2302 (append newlst work-list junk-list
)
2303 (append newlst work-list
))
2304 (append newlst junk-list
)))))
2306 (defun speedbar-trim-words-tag-hierarchy (lst)
2307 "Trim all words in a tag hierarchy.
2308 Base trimming information on word separators, and group names.
2309 Argument LST is the list of tags to trim."
2316 (if (speedbar-generic-list-group-p (car-safe lst
))
2317 (setq newlst
(cons (car lst
) newlst
))
2318 (setq sublst
(cons (car lst
) sublst
)))
2319 (setq lst
(cdr lst
)))
2320 ;; Get the prefix to trim by. Make sure that we don't trim
2321 ;; off silly pieces, only complete understandable words.
2322 (setq trim-prefix
(speedbar-try-completion "" sublst
)
2323 newlst
(nreverse newlst
))
2324 (if (or (= (length sublst
) 1)
2326 (not (string-match "\\(\\w+\\W+\\)+" trim-prefix
)))
2327 (append newlst
(nreverse sublst
))
2328 (setq trim-prefix
(substring trim-prefix
(match-beginning 0)
2330 (setq trim-chars
(length trim-prefix
))
2333 (cons (substring (car (car sublst
)) trim-chars
)
2336 sublst
(cdr sublst
)))
2337 ;; Put the lists together
2338 (append newlst trimlst
))))
2340 (defun speedbar-simple-group-tag-hierarchy (lst)
2341 "Create a simple `Tags' group with orphaned tags.
2342 Argument LST is the list of tags to sort into groups."
2346 (if (speedbar-generic-list-group-p (car-safe lst
))
2347 (setq newlst
(cons (car lst
) newlst
))
2348 (setq sublst
(cons (car lst
) sublst
)))
2349 (setq lst
(cdr lst
)))
2352 (setq newlst
(cons (cons "Tags" (nreverse sublst
)) newlst
))
2353 (nreverse newlst
))))
2355 (defun speedbar-create-tag-hierarchy (lst)
2356 "Adjust the tag hierarchy in LST, and return it.
2357 This uses `speedbar-tag-hierarchy-method' to determine how to adjust
2359 (let* ((f (save-excursion
2361 (or (speedbar-line-file)
2362 (speedbar-line-directory))))
2363 (methods (if (get-file-buffer f
)
2364 (with-current-buffer (get-file-buffer f
)
2365 speedbar-tag-hierarchy-method
)
2366 speedbar-tag-hierarchy-method
))
2367 (lst (if (fboundp 'copy-tree
)
2371 (setq lst
(funcall (car methods
) lst
)
2372 methods
(cdr methods
)))
2375 (defvar speedbar-generic-list-group-expand-button-type
'curly
2376 "The type of button created for groups of tags.
2377 Good values for this are `curly' and `expandtag'.
2378 Make buffer local for your mode.")
2380 (defvar speedbar-generic-list-tag-button-type nil
2381 "The type of button created for tags in generic lists.
2382 Good values for this are nil and `statictag'.
2383 Make buffer local for your mode.")
2385 (defun speedbar-insert-generic-list (level lst expand-fun find-fun
)
2386 "At LEVEL, insert a generic multi-level alist LST.
2387 Associations with lists get {+} tags (to expand into more nodes) and
2388 those with positions just get a > as the indicator. {+} buttons will
2389 have the function EXPAND-FUN and the token is the cdr list. The token
2390 name will have the function FIND-FUN and not token."
2391 ;; Remove imenu rescan button
2392 (if (string= (car (car lst
)) "*Rescan*")
2393 (setq lst
(cdr lst
)))
2394 ;; Get, and set up variables that define how we treat these tags.
2395 (let ((f (save-excursion (forward-line -
1)
2396 (or (speedbar-line-file)
2397 (speedbar-line-directory))))
2398 expand-button tag-button
)
2400 (if (get-file-buffer f
)
2401 (set-buffer (get-file-buffer f
)))
2402 (setq expand-button speedbar-generic-list-group-expand-button-type
2403 tag-button speedbar-generic-list-tag-button-type
))
2405 (setq lst
(speedbar-create-tag-hierarchy lst
))
2408 (cond ((null (car-safe lst
)) nil
) ;this would be a separator
2409 ((speedbar-generic-list-tag-p (car lst
))
2410 (speedbar-make-tag-line tag-button
2411 nil nil nil
;no expand button data
2412 (car (car lst
)) ;button name
2414 (cdr (car lst
)) ;token is position
2417 ((speedbar-generic-list-positioned-group-p (car lst
))
2418 (speedbar-make-tag-line expand-button
2419 ?
+ expand-fun
(cdr (cdr (car lst
)))
2420 (car (car lst
)) ;button name
2422 (car (cdr (car lst
))) ;token is posn
2425 ((speedbar-generic-list-group-p (car lst
))
2426 (speedbar-make-tag-line expand-button
2427 ?
+ expand-fun
(cdr (car lst
))
2428 (car (car lst
)) ;button name
2429 nil nil
'speedbar-tag-face
2431 (t (dframe-message "speedbar-insert-generic-list: malformed list!")
2433 (setq lst
(cdr lst
)))))
2435 (defun speedbar-insert-imenu-list (indent lst
)
2436 "At level INDENT, insert the imenu generated LST."
2437 (speedbar-insert-generic-list indent lst
2438 'speedbar-tag-expand
2439 'speedbar-tag-find
))
2441 (defun speedbar-insert-etags-list (indent lst
)
2442 "At level INDENT, insert the etags generated LST."
2443 (speedbar-insert-generic-list indent lst
2444 'speedbar-tag-expand
2445 'speedbar-tag-find
))
2449 (defun speedbar-update-contents ()
2450 "Generically update the contents of the speedbar buffer."
2452 ;; Set the current special buffer
2453 (setq speedbar-desired-buffer nil
)
2455 ;; Check for special modes
2456 (speedbar-maybe-add-localized-support (current-buffer))
2458 ;; Choose the correct method of doodling.
2459 (if (and speedbar-mode-specific-contents-flag
2460 (consp speedbar-special-mode-expansion-list
)
2462 'speedbar-special-mode-expansion-list
2464 ;;(eq (get major-mode 'mode-class 'special)))
2465 (speedbar-update-special-contents)
2466 (speedbar-update-directory-contents)))
2468 (defun speedbar-update-localized-contents ()
2469 "Update the contents of the speedbar buffer for the current situation."
2470 ;; Due to the historical growth of speedbar, we need to do something
2471 ;; special for "files" mode. Too bad.
2472 (let ((name speedbar-initial-expansion-list-name
)
2473 (funclst (speedbar-initial-expansion-list))
2475 (if (string= name
"files")
2476 ;; Do all the files type work. It still goes through the
2477 ;; expansion list stuff. :(
2478 (if (or (member (expand-file-name default-directory
)
2479 speedbar-shown-directories
)
2480 (and speedbar-ignored-directory-regexp
2482 speedbar-ignored-directory-regexp
2483 (expand-file-name default-directory
))))
2485 (if (<= 1 speedbar-verbosity-level
)
2486 (dframe-message "Updating speedbar to: %s..."
2488 (speedbar-update-directory-contents)
2489 (if (<= 1 speedbar-verbosity-level
)
2491 (dframe-message "Updating speedbar to: %s...done"
2493 (dframe-message nil
))))
2494 ;; Else, we can do a short cut. No text cache.
2495 (let ((cbd (expand-file-name default-directory
)))
2496 (set-buffer speedbar-buffer
)
2497 (speedbar-with-writable
2498 (let* ((window (get-buffer-window speedbar-buffer
0))
2499 (p (window-point window
))
2500 (start (window-start window
)))
2502 (dolist (func funclst
)
2503 (setq default-directory cbd
)
2504 (funcall func cbd
0))
2505 (speedbar-reconfigure-keymaps)
2506 (set-window-point window p
)
2507 (set-window-start window start
)))))))
2509 (defun speedbar-update-directory-contents ()
2510 "Update the contents of the speedbar buffer based on the current directory."
2511 (let ((cbd (expand-file-name default-directory
))
2513 (funclst (speedbar-initial-expansion-list))
2514 (cache speedbar-full-text-cache
)
2515 ;; disable stealth during update
2516 (speedbar-stealthy-function-list nil
)
2519 ;; Because there is a bug I can't find just yet
2521 (set-buffer speedbar-buffer
)
2522 ;; If we are updating contents to where we are, then this is
2523 ;; really a request to update existing contents, so we must be
2524 ;; careful with our text cache!
2525 (if (member cbd speedbar-shown-directories
)
2528 ;; If the current directory is not the last element in the dir
2529 ;; list, then we ALSO need to zap the list of expanded directories
2530 (if (/= (length (member cbd speedbar-shown-directories
)) 1)
2531 (setq speedbar-shown-directories
(list cbd
))))
2533 ;; Build cbd-parent, and see if THAT is in the current shown
2534 ;; directories. First, go through pains to get the parent directory
2535 (if (and speedbar-smart-directory-expand-flag
2537 (setq cbd-parent cbd
)
2538 (if (string-match "[/\\]$" cbd-parent
)
2539 (setq cbd-parent
(substring cbd-parent
0
2540 (match-beginning 0))))
2541 (setq cbd-parent
(file-name-directory cbd-parent
)))
2542 (member cbd-parent speedbar-shown-directories
))
2543 (setq expand-local t
)
2545 ;; If this directory is NOT in the current list of available
2546 ;; directories, then use the cache, and set the cache to our new
2547 ;; value. Make sure to unhighlight the current file, or if we
2548 ;; come back to this directory, it might be a different file
2549 ;; and then we get a mess!
2550 (if (> (point-max) 1)
2552 (speedbar-clear-current-file)
2553 (setq speedbar-full-text-cache
2554 (cons speedbar-shown-directories
(buffer-string)))))
2556 ;; Check if our new directory is in the list of directories
2557 ;; shown in the text-cache
2558 (if (member cbd
(car cache
))
2559 (setq speedbar-shown-directories
(car cache
)
2561 ;; default the shown directories to this list...
2562 (setq speedbar-shown-directories
(list cbd
)))
2564 (if (not expand-local
) (setq speedbar-last-selected-file nil
))
2565 (speedbar-with-writable
2566 (if (and expand-local
2567 ;; Find this directory as a speedbar node.
2568 (speedbar-directory-line cbd
))
2570 (speedbar-expand-line)
2571 (let* ((window (get-buffer-window speedbar-buffer
0))
2572 (p (window-point window
))
2573 (start (window-start window
)))
2576 (setq default-directory
2577 (nth (1- (length speedbar-shown-directories
))
2578 speedbar-shown-directories
))
2579 (insert (cdr cache
)))
2581 (dolist (func funclst
)
2582 (setq default-directory cbd
)
2583 (funcall func cbd
0))))
2584 (set-window-point window p
)
2585 (set-window-start window start
)))))
2586 (speedbar-reconfigure-keymaps))
2588 (defun speedbar-update-special-contents ()
2589 "Use the mode-specific variable to fill in the speedbar buffer.
2590 This should only be used by modes classified as special."
2591 (let ((funclst speedbar-special-mode-expansion-list
)
2592 (specialbuff (current-buffer)))
2593 (setq speedbar-desired-buffer specialbuff
)
2594 (with-current-buffer speedbar-buffer
2595 ;; If we are leaving a directory, cache it.
2596 (if (not speedbar-shown-directories
)
2599 ;; Clean up directory maintenance stuff
2600 (speedbar-clear-current-file)
2601 (setq speedbar-full-text-cache
2602 (cons speedbar-shown-directories
(buffer-string))
2603 speedbar-shown-directories nil
))
2604 ;; Now fill in the buffer with our newly found specialized list.
2605 (speedbar-with-writable
2606 (dolist (func funclst
)
2607 ;; We do not erase the buffer because these functions may
2608 ;; decide NOT to update themselves.
2609 (funcall func specialbuff
)))))
2610 (speedbar-reconfigure-keymaps))
2612 (defun speedbar-set-timer (timeout)
2613 "Set up the speedbar timer with TIMEOUT.
2614 Uses `dframe-set-timer'.
2615 Also resets scanner functions."
2616 (dframe-set-timer timeout
'speedbar-timer-fn
'speedbar-update-flag
)
2617 ;; Apply a revert hook that will reset the scanners. We attach to revert
2618 ;; because most reverts occur during VC state change, and this lets our
2619 ;; VC scanner fix itself.
2621 (add-hook 'after-revert-hook
'speedbar-reset-scanners
)
2622 (remove-hook 'after-revert-hook
'speedbar-reset-scanners
))
2623 ;; change this if it changed for some reason
2624 (speedbar-set-mode-line-format))
2626 (defun speedbar-timer-fn ()
2627 "Run whenever Emacs is idle to update the speedbar item."
2628 (if (or (not (speedbar-current-frame))
2629 (not (frame-live-p (speedbar-current-frame))))
2630 (speedbar-set-timer nil
)
2631 ;; Save all the match data so that we don't mess up executing fns
2633 ;; Only do stuff if the frame is visible, not an icon, and if
2634 ;; it is currently flagged to do something.
2635 (if (and speedbar-update-flag
2636 (speedbar-current-frame)
2637 (frame-visible-p (speedbar-current-frame))
2638 (not (eq (frame-visible-p (speedbar-current-frame)) 'icon
)))
2639 (let ((af (selected-frame)))
2640 (dframe-select-attached-frame speedbar-frame
)
2641 ;; make sure we at least choose a window to
2642 ;; get a good directory from
2643 (if (window-minibuffer-p)
2645 ;; Check for special modes
2646 (speedbar-maybe-add-localized-support (current-buffer))
2647 ;; Update for special mode all the time!
2648 (if (and speedbar-mode-specific-contents-flag
2649 (consp speedbar-special-mode-expansion-list
)
2651 'speedbar-special-mode-expansion-list
2653 ;;(eq (get major-mode 'mode-class 'special)))
2655 (if (<= 2 speedbar-verbosity-level
)
2657 "Updating speedbar to special mode: %s..."
2659 (speedbar-update-special-contents)
2660 (if (<= 2 speedbar-verbosity-level
)
2663 "Updating speedbar to special mode: %s...done"
2665 (dframe-message nil
))))
2667 ;; Update all the contents if directories change!
2668 (unless (and (or (member major-mode speedbar-ignored-modes
)
2669 (eq af
(speedbar-current-frame))
2670 (not (buffer-file-name)))
2671 ;; Always update for GUD.
2672 (not (string-equal "GUD"
2673 speedbar-initial-expansion-list-name
)))
2674 (speedbar-update-localized-contents)))
2676 ;; Now run stealthy updates of time-consuming items
2677 (speedbar-stealthy-updates)))))
2678 (run-hooks 'speedbar-timer-hook
))
2681 ;;; Stealthy activities
2683 (defvar speedbar-stealthy-update-recurse nil
2684 "Recursion avoidance variable for stealthy update.")
2686 (defun speedbar-stealthy-updates ()
2687 "For a given speedbar, run all items in the stealthy function list.
2688 Each item returns t if it completes successfully, or nil if
2689 interrupted by the user."
2690 (if (not speedbar-stealthy-update-recurse
)
2691 (let ((l (speedbar-initial-stealthy-functions))
2692 (speedbar-stealthy-update-recurse t
))
2694 (speedbar-with-writable
2695 (while (and l
(funcall (car l
)))
2698 ;;(dframe-message "Exit with %S" (car l))
2701 (defun speedbar-reset-scanners ()
2702 "Reset any variables used by functions in the stealthy list as state.
2703 If new functions are added, their state needs to be updated here."
2704 (setq speedbar-vc-to-do-point t
2705 speedbar-obj-to-do-point t
2706 speedbar-ro-to-do-point t
)
2707 (run-hooks 'speedbar-scanner-reset-hook
)
2710 (defun speedbar-find-selected-file (file)
2711 "Go to the line where FILE is."
2713 (set-buffer speedbar-buffer
)
2715 (goto-char (point-min))
2717 (while (and (setq m
(re-search-forward
2718 (concat " \\(" (regexp-quote (file-name-nondirectory file
))
2719 "\\)\\(" speedbar-indicator-regex
"\\)?\n")
2723 (speedbar-line-directory
2725 (goto-char (match-beginning 0))
2728 (looking-at "[0-9]+:")
2729 (string-to-number (match-string 0)))))
2730 (match-string 1))))))
2733 (goto-char (match-beginning 1))
2734 (match-string 1)))))
2736 (defun speedbar-clear-current-file ()
2737 "Locate the file thought to be current, and remove its highlighting."
2739 ;;(set-buffer speedbar-buffer)
2740 (if speedbar-last-selected-file
2741 (speedbar-with-writable
2742 (if (speedbar-find-selected-file speedbar-last-selected-file
)
2743 (put-text-property (match-beginning 1)
2746 'speedbar-file-face
))))))
2748 (defun speedbar-update-current-file ()
2749 "Find the current file, and update our visuals to indicate its name.
2750 This is specific to file names. If the file name doesn't show up, but
2751 it should be in the list, then the directory cache needs to be updated."
2752 (let* ((lastf (selected-frame))
2753 (newcfd (save-excursion
2754 (dframe-select-attached-frame speedbar-frame
)
2755 (let ((rf (if (buffer-file-name)
2758 (select-frame lastf
)
2760 (newcf (if newcfd newcfd
))
2761 (lastb (current-buffer))
2762 (sucf-recursive (boundp 'sucf-recursive
))
2763 (case-fold-search t
))
2765 ;; check here, that way we won't refresh to newcf until
2766 ;; its been written, thus saving ourselves some time
2767 (file-exists-p newcf
)
2768 (not (string= newcf speedbar-last-selected-file
)))
2770 ;; It is important to select the frame, otherwise the window
2771 ;; we want the cursor to move in will not be updated by the
2772 ;; search-forward command.
2773 (select-frame (speedbar-current-frame))
2774 ;; Remove the old file...
2775 (speedbar-clear-current-file)
2776 ;; now highlight the new one.
2777 ;; (set-buffer speedbar-buffer)
2778 (speedbar-with-writable
2779 (if (speedbar-find-selected-file newcf
)
2780 ;; put the property on it
2781 (put-text-property (match-beginning 1)
2784 'speedbar-selected-face
)
2785 ;; Oops, it's not in the list. Should it be?
2786 (if (and (string-match speedbar-file-regexp newcf
)
2787 (string= (file-name-directory newcfd
)
2788 (expand-file-name default-directory
)))
2789 ;; yes, it is (we will ignore unknowns for now...)
2792 (if (speedbar-find-selected-file newcf
)
2793 ;; put the property on it
2794 (put-text-property (match-beginning 1)
2797 'speedbar-selected-face
)))
2798 ;; if it's not in there now, whatever...
2800 (setq speedbar-last-selected-file newcf
))
2801 (if (not sucf-recursive
)
2804 ;;Sat Dec 15 2001 12:40 AM (burton@openprivacy.org): this
2805 ;;doesn't need to be in. We don't want to recenter when we are
2808 ;;(speedbar-center-buffer-smartly)
2810 (speedbar-position-cursor-on-line)
2813 (select-frame lastf
)
2815 ;; return that we are done with this activity.
2818 (defun speedbar-add-indicator (indicator-string &optional replace-this
)
2819 "Add INDICATOR-STRING to the end of this speedbar line.
2820 If INDICATOR-STRING is space, and REPLACE-THIS is a character,
2821 then the existing indicator is removed. If there is already an
2822 indicator, then do not add a space."
2824 ;; The nature of the beast: Assume we are in "the right place"
2826 (skip-chars-backward (concat " " speedbar-vc-indicator
2827 speedbar-object-read-only-indicator
2828 (car speedbar-obj-indicator
)
2829 (cdr speedbar-obj-indicator
)))
2830 (if (and (not (looking-at speedbar-indicator-regex
))
2831 (not (string= indicator-string
" ")))
2832 (insert speedbar-indicator-separator
))
2833 (speedbar-with-writable
2835 (if (and replace-this
2836 (re-search-forward replace-this
(line-end-position) t
))
2837 (delete-region (match-beginning 0) (match-end 0))))
2839 (if (not (string= " " indicator-string
))
2840 (let ((start (point)))
2841 (insert indicator-string
)
2842 (speedbar-insert-image-button-maybe start
(length indicator-string
))
2845 (defun speedbar-check-read-only ()
2846 "Scan all the files in a directory, and for each see if it is read only."
2847 ;; Check for to-do to be reset. If reset but no RCS is available
2848 ;; then set to nil (do nothing) otherwise, start at the beginning
2850 (if speedbar-buffer
(set-buffer speedbar-buffer
))
2851 (if (eq speedbar-ro-to-do-point t
)
2852 (setq speedbar-ro-to-do-point
0))
2853 (if (numberp speedbar-ro-to-do-point
)
2855 (goto-char speedbar-ro-to-do-point
)
2856 (while (and (not (input-pending-p))
2857 (re-search-forward "^\\([0-9]+\\):\\s-*[[<][+-?][]>] "
2859 (setq speedbar-ro-to-do-point
(point))
2860 (let ((f (speedbar-line-file)))
2862 (if (not (file-writable-p f
))
2863 (speedbar-add-indicator
2864 speedbar-object-read-only-indicator
2865 (regexp-quote speedbar-object-read-only-indicator
))
2866 (speedbar-add-indicator
2868 speedbar-object-read-only-indicator
))))))
2869 (if (input-pending-p)
2870 ;; return that we are incomplete
2872 ;; we are done, set to-do to nil
2873 (setq speedbar-ro-to-do-point nil
)
2878 (defun speedbar-check-vc ()
2879 "Scan all files in a directory, and for each see if it's checked out.
2880 See `speedbar-this-file-in-vc' and `speedbar-vc-check-dir-p' for how
2881 to add more types of version control systems."
2882 ;; Check for to-do to be reset. If reset but no RCS is available
2883 ;; then set to nil (do nothing) otherwise, start at the beginning
2885 (if speedbar-buffer
(set-buffer speedbar-buffer
))
2886 (if (and speedbar-vc-do-check
(eq speedbar-vc-to-do-point t
)
2887 (speedbar-vc-check-dir-p default-directory
)
2888 (not (or (and (featurep 'ange-ftp
)
2891 (if (featurep 'xemacs
)
2892 'ange-ftp-directory-format
2893 'ange-ftp-name-format
)))
2894 (expand-file-name default-directory
)))
2895 ;; efs support: Bob Weiner
2896 (and (featurep 'efs
)
2898 (let ((reg (symbol-value 'efs-directory-regexp
)))
2902 (expand-file-name default-directory
))))))
2903 (setq speedbar-vc-to-do-point
0))
2904 (if (numberp speedbar-vc-to-do-point
)
2906 (goto-char speedbar-vc-to-do-point
)
2907 (while (and (not (input-pending-p))
2908 (re-search-forward "^\\([0-9]+\\):\\s-*\\[[+-?]\\] "
2910 (setq speedbar-vc-to-do-point
(point))
2911 (if (speedbar-check-vc-this-line (match-string 1))
2912 (speedbar-add-indicator speedbar-vc-indicator
2913 (regexp-quote speedbar-vc-indicator
))
2914 (speedbar-add-indicator " "
2915 (regexp-quote speedbar-vc-indicator
))))
2916 (if (input-pending-p)
2917 ;; return that we are incomplete
2919 ;; we are done, set to-do to nil
2920 (setq speedbar-vc-to-do-point nil
)
2925 (defun speedbar-check-vc-this-line (depth)
2926 "Return t if the file on this line is checked out of a version control system.
2927 Parameter DEPTH is a string with the current depth of indentation of
2928 the file being checked."
2929 (let* ((d (string-to-number depth
))
2930 (f (speedbar-line-directory d
))
2931 (fn (buffer-substring-no-properties
2932 ;; Skip-chars: thanks ptype@dra.hmg.gb
2934 (skip-chars-forward "^ " (line-end-position))
2936 (fulln (concat f fn
)))
2937 (if (<= 2 speedbar-verbosity-level
)
2938 (dframe-message "Speedbar vc check...%s" fulln
))
2939 (and (file-writable-p fulln
)
2940 (speedbar-this-file-in-vc f fn
))))
2942 (defun speedbar-vc-check-dir-p (directory)
2943 "Return t if we should bother checking DIRECTORY for version control files.
2944 This can be overloaded to add new types of version control systems."
2946 (catch t
(dolist (vcd vc-directory-exclusion-list
)
2947 (if (file-exists-p (concat directory vcd
)) (throw t t
))) nil
)
2949 (run-hook-with-args-until-success 'speedbar-vc-directory-enable-hook
2953 (defun speedbar-this-file-in-vc (directory name
)
2954 "Check to see if the file in DIRECTORY with NAME is in a version control system.
2955 Automatically recognizes all VCs supported by VC mode. You can
2956 optimize this function by overriding it and only doing those checks
2957 that will occur on your system."
2959 (vc-backend (concat directory
"/" name
))
2961 (run-hook-with-args 'speedbar-vc-in-control-hook directory name
)
2964 ;; Object File scanning
2965 (defun speedbar-check-objects ()
2966 "Scan all files in a directory, and for each see if there is an object.
2967 See `speedbar-check-obj-this-line' and `speedbar-obj-alist' for how
2968 to add more object types."
2969 ;; Check for to-do to be reset. If reset but no RCS is available
2970 ;; then set to nil (do nothing) otherwise, start at the beginning
2972 (if speedbar-buffer
(set-buffer speedbar-buffer
))
2973 (if (and speedbar-obj-do-check
(eq speedbar-obj-to-do-point t
))
2974 (setq speedbar-obj-to-do-point
0))
2975 (if (numberp speedbar-obj-to-do-point
)
2977 (goto-char speedbar-obj-to-do-point
)
2978 (while (and (not (input-pending-p))
2979 (re-search-forward "^\\([0-9]+\\):\\s-*\\[[+-]\\] "
2981 (setq speedbar-obj-to-do-point
(point))
2982 (let ((ind (speedbar-check-obj-this-line (match-string 1))))
2983 (if (not ind
) (setq ind
" "))
2984 (speedbar-add-indicator ind
(concat
2985 (car speedbar-obj-indicator
)
2987 (cdr speedbar-obj-indicator
)))))
2988 (if (input-pending-p)
2989 ;; return that we are incomplete
2991 ;; we are done, set to-do to nil
2992 (setq speedbar-obj-to-do-point nil
)
2997 (defun speedbar-check-obj-this-line (depth)
2998 "Return t if the file on this line has an associated object.
2999 Parameter DEPTH is a string with the current depth of indentation of
3000 the file being checked."
3001 (let* ((d (string-to-number depth
))
3002 (f (speedbar-line-directory d
))
3003 (fn (buffer-substring-no-properties
3004 ;; Skip-chars: thanks ptype@dra.hmg.gb
3006 (skip-chars-forward "^ " (line-end-position))
3008 (fulln (concat f fn
)))
3009 (if (<= 2 speedbar-verbosity-level
)
3010 (dframe-message "Speedbar obj check...%s" fulln
))
3011 (let ((oa speedbar-obj-alist
))
3012 (while (and oa
(not (string-match (car (car oa
)) fulln
)))
3014 (if (not (and oa
(file-exists-p (concat (file-name-sans-extension fulln
)
3017 ;; Find out if the object is out of date or not.
3018 (let ((date1 (nth 5 (file-attributes fulln
)))
3019 (date2 (nth 5 (file-attributes (concat
3020 (file-name-sans-extension fulln
)
3022 (if (or (< (car date1
) (car date2
))
3023 (and (= (car date1
) (car date2
))
3024 (< (nth 1 date1
) (nth 1 date2
))))
3025 (car speedbar-obj-indicator
)
3026 (cdr speedbar-obj-indicator
)))))))
3028 ;;; Clicking Activity
3030 (defun speedbar-position-cursor-on-line ()
3031 "Position the cursor on a line."
3032 (let ((oldpos (point)))
3034 (if (looking-at "[0-9]+:\\s-*..?.? ")
3035 (goto-char (1- (match-end 0)))
3036 (goto-char oldpos
))))
3038 (defun speedbar-click (e)
3039 "Activate any speedbar buttons where the mouse is clicked.
3040 This must be bound to a mouse event. A button is any location of text
3041 with a mouse face that has a text property called `speedbar-function'.
3042 Argument E is the click event."
3043 ;; Backward compatibility let statement.
3044 (let ((speedbar-power-click dframe-power-click
))
3045 (speedbar-do-function-pointer))
3046 (dframe-quick-mouse e
))
3048 (defun speedbar-do-function-pointer ()
3049 "Look under the cursor and examine the text properties.
3050 From this extract the file/tag name, token, indentation level and call
3051 a function if appropriate."
3052 (let* ((speedbar-frame (speedbar-current-frame))
3053 (fn (get-text-property (point) 'speedbar-function
))
3054 (tok (get-text-property (point) 'speedbar-token
))
3055 ;; The 1-,+ is safe because scanning starts AFTER the point
3056 ;; specified. This lets the search include the character the
3058 (tp (previous-single-property-change
3059 (1+ (point)) 'speedbar-function
))
3060 (np (next-single-property-change
3061 (point) 'speedbar-function
))
3062 (txt (buffer-substring-no-properties (or tp
(point-min))
3063 (or np
(point-max))))
3064 (dent (save-excursion (beginning-of-line)
3066 (if (looking-at "[0-9]+")
3067 (buffer-substring-no-properties
3068 (match-beginning 0) (match-end 0))
3070 ;;(dframe-message "%S:%S:%S:%s" fn tok txt dent)
3071 (and fn
(funcall fn txt tok dent
)))
3072 (speedbar-position-cursor-on-line))
3074 ;;; Reading info from the speedbar buffer
3076 (defun speedbar-line-text (&optional p
)
3077 "Retrieve the text after prefix junk for the current line.
3078 Optional argument P is where to start the search from."
3080 (if p
(goto-char p
))
3082 (if (looking-at (concat
3083 "\\([0-9]+\\): *[[<{]?[-+?= ][]>}@()|] \\([^ \n]+\\)"))
3084 (get-text-property (match-beginning 2) 'speedbar-text
)
3087 (defun speedbar-line-token (&optional p
)
3088 "Retrieve the token information after the prefix junk for the current line.
3089 Optional argument P is where to start the search from."
3091 (if p
(goto-char p
))
3093 (if (looking-at (concat
3094 "\\([0-9]+\\): *[[<{]?[-+?= ][]>}@()|] \\([^ \n]+\\)\\("
3095 speedbar-indicator-regex
"\\)?"))
3097 (goto-char (match-beginning 2))
3098 (get-text-property (point) 'speedbar-token
))
3101 (defun speedbar-line-file (&optional p
)
3102 "Retrieve the file or whatever from the line at point P.
3103 The return value is a string representing the file. If it is a
3104 directory, then it is the directory name."
3108 (let ((f (speedbar-line-text p
)))
3110 (let* ((depth (string-to-number (match-string 1)))
3111 (directory (speedbar-line-directory depth
)))
3112 (if (file-exists-p (concat directory f
))
3113 (concat directory f
)
3117 (defun speedbar-goto-this-file (file)
3118 "If FILE is displayed, go to this line and return t.
3119 Otherwise do not move and return nil."
3120 (let ((directory (substring (file-name-directory (expand-file-name file
))
3121 (length (expand-file-name default-directory
))))
3124 (goto-char (point-min))
3125 ;; scan all the directories
3126 (while (and directory
(not (eq directory t
)))
3127 (if (string-match "^[/\\]?\\([^/\\]+\\)" directory
)
3128 (let ((pp (match-string 1 directory
)))
3129 (if (save-match-data
3130 (re-search-forward (concat "> " (regexp-quote pp
) "$")
3132 (setq directory
(substring directory
(match-end 1)))
3133 (setq directory nil
)))
3134 (setq directory t
)))
3135 ;; find the file part
3136 (if (or (not directory
) (string= (file-name-nondirectory file
) ""))
3137 ;; only had a dir part
3140 (speedbar-position-cursor-on-line)
3142 (goto-char dest
) nil
)
3143 ;; find the file part
3144 (let ((nd (file-name-nondirectory file
)))
3145 (if (re-search-forward
3146 (concat "] \\(" (regexp-quote nd
)
3147 "\\)\\(" speedbar-indicator-regex
"\\)$")
3150 (speedbar-position-cursor-on-line)
3155 (defun speedbar-line-directory (&optional depth
)
3156 "Retrieve the directory name associated with the current line.
3157 This may require traversing backwards from DEPTH and combining the default
3158 directory with these items. This function is replaceable in
3159 `speedbar-mode-functions-list' as `speedbar-line-directory'."
3162 (let ((rf (speedbar-fetch-replacement-function 'speedbar-line-directory
)))
3163 (if rf
(funcall rf depth
) default-directory
))))
3165 (defun speedbar-files-line-directory (&optional depth
)
3166 "Retrieve the directory associated with the current line.
3167 This may require traversing backwards from DEPTH and combining the default
3168 directory with these items."
3174 (looking-at "^\\([0-9]+\\):")
3175 (setq depth
(string-to-number (match-string 1)))))
3176 (let ((directory nil
))
3177 (setq depth
(1- depth
))
3178 (while (/= depth -
1)
3179 (if (not (re-search-backward (format "^%d:" depth
) nil t
))
3180 (error "Error building filename of tag")
3181 (cond ((looking-at "[0-9]+:\\s-*<->\\s-+\\([^\n]+\\)")
3182 (setq directory
(concat (speedbar-line-text)
3185 ((looking-at "[0-9]+:\\s-*[-]\\s-+\\([^\n]+\\)")
3186 ;; This is the start of our directory.
3187 (setq directory
(speedbar-line-text)))))
3188 (setq depth
(1- depth
)))
3190 (string-match (concat speedbar-indicator-regex
"$")
3192 (setq directory
(substring directory
0 (match-beginning 0))))
3193 (concat default-directory directory
)))))
3195 (defun speedbar-directory-line (directory)
3196 "Position the cursor on the line specified by DIRECTORY."
3198 (if (string-match "[/\\]$" directory
)
3199 (setq directory
(substring directory
0 (match-beginning 0))))
3200 (let ((nomatch t
) (depth 0)
3201 (fname (file-name-nondirectory directory
))
3202 (pname (file-name-directory directory
)))
3203 (if (not (member pname speedbar-shown-directories
))
3204 (error "Internal Error: File %s not shown in speedbar" directory
))
3205 (goto-char (point-min))
3208 (concat "[]>] \\(" (regexp-quote fname
)
3209 "\\)\\(" speedbar-indicator-regex
"\\)?$")
3212 (looking-at "\\([0-9]+\\):")
3213 (setq depth
(string-to-number (match-string 0))
3214 nomatch
(not (string= pname
(speedbar-line-directory depth
))))
3219 (defun speedbar-edit-line ()
3220 "Edit whatever tag or file is on the current speedbar line."
3224 ;; If this fails, then it is a non-standard click, and as such,
3225 ;; perfectly allowed.
3226 (if (re-search-forward "[]>?}] [^ ]"
3231 (speedbar-do-function-pointer))
3233 (speedbar-do-function-pointer)))
3235 (defun speedbar-expand-line (&optional arg
)
3236 "Expand the line under the cursor.
3237 With universal argument ARG, flush cached data."
3240 (let* ((dframe-power-click arg
)
3241 (speedbar-power-click arg
))
3244 (re-search-forward ":\\s-*.\\+. "
3245 (line-end-position))
3247 (speedbar-do-function-pointer))
3248 (error (speedbar-position-cursor-on-line)))))
3250 (defun speedbar-flush-expand-line ()
3251 "Expand the line under the cursor and flush any cached information."
3253 (speedbar-expand-line 1))
3255 (defun speedbar-contract-line ()
3256 "Contract the line under the cursor."
3261 (re-search-forward ":\\s-*.-. "
3262 (line-end-position))
3264 (speedbar-do-function-pointer))
3265 (error (speedbar-position-cursor-on-line))))
3267 (defun speedbar-toggle-line-expansion ()
3268 "Contract or expand the line under the cursor."
3273 (re-search-forward ":\\s-*.[-+]. "
3274 (line-end-position))
3276 (speedbar-do-function-pointer))
3277 (error (speedbar-position-cursor-on-line))))
3279 (defun speedbar-expand-line-descendants (&optional arg
)
3280 "Expand the line under the cursor and all descendants.
3281 Optional argument ARG indicates that any cache should be flushed."
3283 (speedbar-expand-line arg
)
3284 ;; Now, inside the area expanded here, expand all subnodes of
3285 ;; the same descendant type.
3287 (speedbar-next 1) ;; Move into the list.
3292 (speedbar-expand-line-descendants arg
)
3293 (speedbar-restricted-next 1))
3294 (error (setq err t
))))))
3297 (defun speedbar-contract-line-descendants ()
3298 "Expand the line under the cursor and all descendants."
3300 (speedbar-contract-line)
3301 ;; Don't need to do anything else since all descendants are
3302 ;; hidden by default anyway. Yay! It's easy.
3305 (defun speedbar-find-file (text _token indent
)
3306 "Speedbar click handler for filenames.
3307 TEXT, the file will be displayed in the attached frame.
3308 TOKEN is unused, but required by the click handler. INDENT is the
3309 current indentation level."
3310 (let ((cdd (speedbar-line-directory indent
)))
3311 ;; Run before visiting file hook here.
3312 (let ((f (selected-frame)))
3313 (dframe-select-attached-frame speedbar-frame
)
3314 (run-hooks 'speedbar-before-visiting-file-hook
)
3316 (speedbar-find-file-in-frame (concat cdd text
))
3317 (speedbar-stealthy-updates)
3318 (run-hooks 'speedbar-visiting-file-hook
)
3319 ;; Reset the timer with a new timeout when clicking a file
3320 ;; in case the user was navigating directories, we can cancel
3321 ;; that other timer.
3322 (speedbar-set-timer dframe-update-speed
))
3323 (dframe-maybee-jump-to-attached-frame))
3325 (defun speedbar-dir-follow (text _token indent
)
3326 "Speedbar click handler for directory names.
3327 Clicking a directory will cause the speedbar to list files in
3328 the subdirectory TEXT. TOKEN is an unused requirement. The
3329 subdirectory chosen will be at INDENT level."
3330 (setq default-directory
3331 (concat (expand-file-name (concat (speedbar-line-directory indent
) text
))
3333 ;; Because we leave speedbar as the current buffer,
3334 ;; update contents will change directory without
3335 ;; having to touch the attached frame. Turn off smart expand just
3337 (let ((speedbar-smart-directory-expand-flag nil
))
3338 (speedbar-update-contents))
3339 (speedbar-set-timer speedbar-navigating-speed
)
3340 (setq speedbar-last-selected-file nil
)
3341 (speedbar-stealthy-updates))
3343 (defun speedbar-delete-subblock (indent)
3344 "Delete text from point to indentation level INDENT or greater.
3345 Handles end-of-sublist smartly."
3346 (speedbar-with-writable
3348 (end-of-line) (forward-char 1)
3349 (let ((start (point)))
3350 (while (and (looking-at "^\\([0-9]+\\):")
3351 (> (string-to-number (match-string 1)) indent
)
3354 (beginning-of-line))
3355 (delete-region start
(point))))))
3357 (defun speedbar-dired (text token indent
)
3358 "Speedbar click handler for directory expand button.
3359 Clicking this button expands or contracts a directory. TEXT is the
3360 button clicked which has either a + or -. TOKEN is the directory to be
3361 expanded. INDENT is the current indentation level."
3362 (cond ((string-match "+" text
) ;we have to expand this dir
3363 (setq speedbar-shown-directories
3364 (cons (expand-file-name
3365 (concat (speedbar-line-directory indent
) token
"/"))
3366 speedbar-shown-directories
))
3367 (speedbar-change-expand-button-char ?-
)
3368 (speedbar-reset-scanners)
3370 (end-of-line) (forward-char 1)
3371 (speedbar-with-writable
3372 (speedbar-default-directory-list
3373 (concat (speedbar-line-directory indent
) token
"/")
3375 ((string-match "-" text
) ;we have to contract this node
3376 (speedbar-reset-scanners)
3377 (let ((oldl speedbar-shown-directories
)
3379 (td (expand-file-name
3380 (concat (speedbar-line-directory indent
) token
))))
3382 (if (not (string-match (concat "^" (regexp-quote td
)) (car oldl
)))
3383 (setq newl
(cons (car oldl
) newl
)))
3384 (setq oldl
(cdr oldl
)))
3385 (setq speedbar-shown-directories
(nreverse newl
)))
3386 (speedbar-change-expand-button-char ?
+)
3387 (speedbar-delete-subblock indent
)
3389 (t (error "Ooops... not sure what to do")))
3390 (speedbar-center-buffer-smartly)
3391 (save-excursion (speedbar-stealthy-updates)))
3393 (defun speedbar-directory-buttons-follow (_text token _indent
)
3394 "Speedbar click handler for default directory buttons.
3395 TEXT is the button clicked on. TOKEN is the directory to follow.
3396 INDENT is the current indentation level and is unused."
3397 (if (string-match "^[A-z]:$" token
)
3398 (setq default-directory
(concat token
"/"))
3399 (setq default-directory token
))
3400 ;; Because we leave speedbar as the current buffer,
3401 ;; update contents will change directory without
3402 ;; having to touch the attached frame.
3403 (speedbar-update-contents)
3404 (speedbar-set-timer speedbar-navigating-speed
))
3406 (defun speedbar-tag-file (text token indent
)
3407 "The cursor is on a selected line. Expand the tags in the specified file.
3408 The parameter TEXT and TOKEN are required, where TEXT is the button
3409 clicked, and TOKEN is the file to expand. INDENT is the current
3411 (cond ((string-match "+" text
) ;we have to expand this file
3412 (let* ((fn (expand-file-name (concat (speedbar-line-directory indent
)
3414 (lst (speedbar-fetch-dynamic-tags fn
)))
3415 ;; if no list, then remove expando button
3417 (speedbar-change-expand-button-char ??
)
3418 (speedbar-change-expand-button-char ?-
)
3419 (speedbar-with-writable
3421 (end-of-line) (forward-char 1)
3422 (funcall (car lst
) indent
(cdr lst
)))))))
3423 ((string-match "-" text
) ;we have to contract this node
3424 (speedbar-change-expand-button-char ?
+)
3425 (speedbar-delete-subblock indent
))
3426 (t (error "Ooops... not sure what to do")))
3427 (speedbar-center-buffer-smartly))
3429 (defun speedbar-tag-find (_text token indent
)
3430 "For the tag TEXT in a file TOKEN, go to that position.
3431 INDENT is the current indentation level."
3432 (let ((file (speedbar-line-directory indent
)))
3433 (let ((f (selected-frame)))
3434 (dframe-select-attached-frame speedbar-frame
)
3435 (run-hooks 'speedbar-before-visiting-tag-hook
)
3437 (speedbar-find-file-in-frame file
)
3438 (save-excursion (speedbar-stealthy-updates))
3439 ;; Reset the timer with a new timeout when clicking a file
3440 ;; in case the user was navigating directories, we can cancel
3441 ;; that other timer.
3442 (speedbar-set-timer dframe-update-speed
)
3444 (run-hooks 'speedbar-visiting-tag-hook
)
3445 (dframe-maybee-jump-to-attached-frame)
3448 (defun speedbar-tag-expand (text token indent
)
3449 "Expand a tag sublist. Imenu will return sub-lists of specialized tag types.
3450 Etags does not support this feature. TEXT will be the button string.
3451 TOKEN will be the list, and INDENT is the current indentation level."
3452 (cond ((string-match "+" text
) ;we have to expand this file
3453 (speedbar-change-expand-button-char ?-
)
3454 (speedbar-with-writable
3456 (end-of-line) (forward-char 1)
3457 (speedbar-insert-generic-list indent token
'speedbar-tag-expand
3458 'speedbar-tag-find
))))
3459 ((string-match "-" text
) ;we have to contract this node
3460 (speedbar-change-expand-button-char ?
+)
3461 (speedbar-delete-subblock indent
))
3462 (t (error "Ooops... not sure what to do")))
3463 (speedbar-center-buffer-smartly))
3465 ;;; Loading files into the attached frame.
3467 (defcustom speedbar-select-frame-method
'attached
3468 "Specify how to select a frame for displaying a file.
3469 A number such as 1 or -1 means to pass that number to `other-frame'
3470 while selecting a frame from speedbar. Any other value means to use
3471 the attached frame (the frame that speedbar was started from)."
3473 :type
'(choice integer
(other :tag
"attached" attached
)))
3475 (defun speedbar-find-file-in-frame (file)
3476 "This will load FILE into the speedbar attached frame.
3477 If the file is being displayed in a different frame already, then raise that
3479 (let* ((buff (find-file-noselect file
))
3480 (bwin (get-buffer-window buff
0)))
3483 (select-window bwin
)
3484 (raise-frame (window-frame bwin
)))
3485 (if dframe-power-click
3486 (let ((pop-up-frames t
)) (select-window (display-buffer buff
)))
3487 (if (numberp speedbar-select-frame-method
)
3488 (other-frame speedbar-select-frame-method
)
3489 (dframe-select-attached-frame speedbar-frame
))
3490 (switch-to-buffer buff
))))
3493 ;;; Centering Utility
3495 (defun speedbar-center-buffer-smartly ()
3496 "Recenter a speedbar buffer so the current indentation level is all visible.
3497 This assumes that the cursor is on a file, or tag of a file which the user is
3500 (save-selected-window
3502 (select-window (get-buffer-window speedbar-buffer t
))
3504 (set-buffer speedbar-buffer
)
3506 (if (<= (count-lines (point-min) (point-max))
3507 (1- (window-height)))
3508 ;; whole buffer fits
3511 (goto-char (point-min))
3515 (let (depth start end exp p
)
3518 (setq depth
(if (looking-at "[0-9]+")
3519 (string-to-number (buffer-substring-no-properties
3520 (match-beginning 0) (match-end 0)))
3522 (setq exp
(format "^%d:" depth
)))
3525 (if (re-search-backward exp nil t
)
3526 (setq start
(point))
3527 (setq start
(point-min)))
3528 (save-excursion ;Not sure about this part.
3531 (while (and (not (re-search-forward exp nil t
))
3533 (setq depth
(1- depth
))
3534 (setq exp
(format "^%d:" depth
)))
3537 (setq end
(point-max)))))
3538 ;; Now work out the details of centering
3539 (let ((nl (count-lines start end
))
3540 (wl (1- (window-height)))
3543 ;; We can't fit it all, so just center on cursor
3544 (progn (goto-char start
)
3546 ;; we can fit everything on the screen, but...
3547 (if (and (pos-visible-in-window-p start
(selected-window))
3548 (pos-visible-in-window-p end
(selected-window)))
3551 ;; we need to do something...
3553 (let ((newcent (/ (- (window-height) nl
) 2))
3554 (lte (count-lines start
(point-max))))
3555 (if (and (< (+ newcent lte
) (window-height))
3556 (> (- (window-height) lte
1)
3558 (setq newcent
(- (window-height)
3560 (recenter newcent
))))
3563 ;;; Tag Management -- List of expanders:
3565 (defun speedbar-fetch-dynamic-tags (file)
3566 "Return a list of tags generated dynamically from FILE.
3567 This uses the entries in `speedbar-dynamic-tags-function-list'
3568 to find the proper tags. It is up to each of those individual
3569 functions to do caching and flushing if appropriate."
3571 ;; If a file is in memory, switch to that buffer. This allows
3572 ;; us to use the local variable. If the file is on disk, we
3573 ;; can try a few of the defaults that can get tags without
3574 ;; opening the file.
3575 (if (get-file-buffer file
)
3576 (set-buffer (get-file-buffer file
)))
3577 ;; If there is a buffer-local value of
3578 ;; speedbar-dynamic-tags-function-list, it will now be available.
3579 (let ((dtf speedbar-dynamic-tags-function-list
)
3581 (while (and (eq ret t
) dtf
)
3583 (if (fboundp (car (car dtf
)))
3584 (funcall (car (car dtf
)) file
)
3587 (setq dtf
(cdr dtf
))))
3589 ;; No valid tag list, return nil
3591 ;; We have some tags. Return the list with the insert fn
3593 (cons (cdr (car dtf
)) ret
)))))
3595 ;;; Tag Management -- Imenu
3597 (if (not speedbar-use-imenu-flag
)
3601 (eval-when-compile (condition-case nil
(require 'imenu
) (error nil
)))
3602 (declare-function imenu--make-index-alist
"imenu" (&optional no-error
))
3604 (defun speedbar-fetch-dynamic-imenu (file)
3605 "Load FILE into a buffer, and generate tags using Imenu.
3606 Returns the tag list, or t for an error."
3607 ;; Load this AND compile it in
3609 (set-buffer (find-file-noselect file
))
3610 (if dframe-power-click
(setq imenu--index-alist nil
))
3612 (let ((index-alist (imenu--make-index-alist t
)))
3613 (if speedbar-sort-tags
3614 (sort (copy-alist index-alist
)
3615 (lambda (a b
) (string< (car a
) (car b
))))
3620 ;;; Tag Management -- etags (old XEmacs compatibility part)
3622 (defvar speedbar-fetch-etags-parse-list
3623 '(;; Note that java has the same parse-group as c
3624 ("\\.\\([cChH]\\|c\\+\\+\\|cpp\\|cc\\|hh\\|java\\|cxx\\|hxx\\)\\'" .
3625 speedbar-parse-c-or-c
++tag
)
3626 ("^\\.emacs$\\|.\\(el\\|l\\|lsp\\)\\'" .
3627 "def[^i]+\\s-+\\(\\(\\w\\|[-_]\\)+\\)\\s-*\C-?")
3628 ; ("\\.\\([fF]\\|for\\|FOR\\|77\\|90\\)\\'" .
3629 ; speedbar-parse-fortran77-tag)
3630 ("\\.tex\\'" . speedbar-parse-tex-string
)
3632 "\\(\\(FUNCTION\\|function\\|PROCEDURE\\|procedure\\)\\s-+\\([a-zA-Z0-9_.:]+\\)\\)\\s-*(?^?")
3634 "Associations of file extensions and expressions for extracting tags.
3635 To add a new file type, you would want to add a new association to the
3636 list, where the car is the file match, and the cdr is the way to
3637 extract an element from the tags output. If the output is complex,
3638 use a function symbol instead of regexp. The function should expect
3639 to be at the beginning of a line in the etags buffer.
3641 This variable is ignored if `speedbar-use-imenu-flag' is non-nil.")
3643 (defcustom speedbar-fetch-etags-command
"etags"
3644 "Command used to create an etags file.
3645 This variable is ignored if `speedbar-use-imenu-flag' is t."
3649 (defcustom speedbar-fetch-etags-arguments
'("-D" "-I" "-o" "-")
3650 "List of arguments to use with `speedbar-fetch-etags-command'.
3651 This creates an etags output buffer. Use `speedbar-toggle-etags' to
3652 modify this list conveniently.
3653 This variable is ignored if `speedbar-use-imenu-flag' is t."
3655 :type
'(choice (const nil
)
3656 (repeat :tag
"List of arguments" string
)))
3658 (defun speedbar-toggle-etags (flag)
3659 "Toggle FLAG in `speedbar-fetch-etags-arguments'.
3660 FLAG then becomes a member of etags command line arguments. If flag
3661 is \"sort\", then toggle the value of `speedbar-sort-tags'. If its
3662 value is \"show\" then toggle the value of
3663 `speedbar-show-unknown-files'.
3665 This function is a convenience function for XEmacs menu created by
3666 Farzin Guilak <farzin@protocol.com>."
3669 ((equal flag
"sort")
3670 (setq speedbar-sort-tags
(not speedbar-sort-tags
)))
3671 ((equal flag
"show")
3672 (setq speedbar-show-unknown-files
(not speedbar-show-unknown-files
)))
3673 ((or (equal flag
"-C")
3676 (if (member flag speedbar-fetch-etags-arguments
)
3677 (setq speedbar-fetch-etags-arguments
3678 (delete flag speedbar-fetch-etags-arguments
))
3679 (add-to-list 'speedbar-fetch-etags-arguments flag
)))
3682 (defun speedbar-fetch-dynamic-etags (file)
3683 "For FILE, run etags and create a list of symbols extracted.
3684 Each symbol will be associated with its line position in FILE."
3685 (let ((newlist nil
))
3688 (if (get-buffer "*etags tmp*")
3689 (kill-buffer "*etags tmp*")) ;kill to clean it up
3690 (if (<= 1 speedbar-verbosity-level
)
3691 (dframe-message "Fetching etags..."))
3692 (set-buffer (get-buffer-create "*etags tmp*"))
3693 (apply 'call-process speedbar-fetch-etags-command nil
3694 (current-buffer) nil
3695 (append speedbar-fetch-etags-arguments
(list file
)))
3696 (goto-char (point-min))
3697 (if (<= 1 speedbar-verbosity-level
)
3698 (dframe-message "Fetching etags..."))
3700 (let ((exprlst speedbar-fetch-etags-parse-list
)
3702 (while (and (not ans
) exprlst
)
3703 (if (string-match (car (car exprlst
)) file
)
3704 (setq ans
(car exprlst
)))
3705 (setq exprlst
(cdr exprlst
)))
3709 (set-buffer (get-buffer-create "*etags tmp*"))
3710 (while (not (save-excursion (end-of-line) (eobp)))
3712 (setq tnl
(speedbar-extract-one-symbol expr
)))
3713 (if tnl
(setq newlist
(cons tnl newlist
)))
3716 "Sorry, no support for a file of that extension"))))
3718 (if speedbar-sort-tags
3719 (sort newlist
(lambda (a b
) (string< (car a
) (car b
))))
3720 (reverse newlist
))))
3722 ;; This bit donated by Farzin Guilak <farzin@protocol.com> but I'm not
3723 ;; sure it's needed with the different sorting method.
3725 ;(defun speedbar-clean-etags()
3726 ; "Removes spaces before the ^? character, and removes `#define',
3727 ;return types, etc. preceding tags. This ensures that the sort operation
3728 ;works on the tags, not the return types."
3730 ; (goto-char (point-min))
3732 ; (re-search-forward "(?[ \t](?\C-?" nil t)
3733 ; (replace-match "\C-?" nil nil))
3734 ; (goto-char (point-min))
3736 ; (re-search-forward "\\(.*[ \t]+\\)\\([^ \t\n]+.*\C-?\\)" nil t)
3737 ; (delete-region (match-beginning 1) (match-end 1)))))
3739 (defun speedbar-extract-one-symbol (expr)
3740 "At point, return nil, or one alist in the form (SYMBOL . POSITION).
3741 The line should contain output from etags. Parse the output using the
3742 regular expression EXPR."
3743 (let* ((sym (if (stringp expr
)
3745 (re-search-forward expr
(line-end-position) t
))
3746 (buffer-substring-no-properties (match-beginning 1)
3749 (pos (let ((j (re-search-forward "[\C-?\C-a]\\([0-9]+\\),\\([0-9]+\\)"
3750 (line-end-position) t
)))
3752 (1+ (string-to-number (buffer-substring-no-properties
3760 (defun speedbar-parse-c-or-c++tag
()
3761 "Parse a C or C++ tag, which tends to be a little complex."
3763 (let ((bound (line-end-position)))
3764 (cond ((re-search-forward "\C-?\\([^\C-a]+\\)\C-a" bound t
)
3765 (buffer-substring-no-properties (match-beginning 1)
3767 ((re-search-forward "\\<\\([^ \t]+\\)\\s-+new(" bound t
)
3768 (buffer-substring-no-properties (match-beginning 1)
3770 ((re-search-forward "\\<\\([^ \t(]+\\)\\s-*(\C-?" bound t
)
3771 (buffer-substring-no-properties (match-beginning 1)
3776 (defun speedbar-parse-tex-string ()
3777 "Parse a Tex string. Only find data which is relevant."
3779 (let ((bound (line-end-position)))
3780 (cond ((re-search-forward "\\(\\(sub\\)*section\\|chapter\\|cite\\)\\s-*{[^\C-?}]*}?" bound t
)
3781 (buffer-substring-no-properties (match-beginning 0)
3786 ;;; BUFFER DISPLAY mode.
3788 (defvar speedbar-buffers-key-map nil
3789 "Keymap used when in the buffers display mode.")
3791 (if speedbar-buffers-key-map
3793 (setq speedbar-buffers-key-map
(speedbar-make-specialized-keymap))
3795 ;; Basic tree features
3796 (define-key speedbar-buffers-key-map
"e" 'speedbar-edit-line
)
3797 (define-key speedbar-buffers-key-map
"\C-m" 'speedbar-edit-line
)
3798 (define-key speedbar-buffers-key-map
"+" 'speedbar-expand-line
)
3799 (define-key speedbar-buffers-key-map
"=" 'speedbar-expand-line
)
3800 (define-key speedbar-buffers-key-map
"-" 'speedbar-contract-line
)
3801 (define-key speedbar-buffers-key-map
" " 'speedbar-toggle-line-expansion
)
3803 ;; Buffer specific keybindings
3804 (define-key speedbar-buffers-key-map
"k" 'speedbar-buffer-kill-buffer
)
3805 (define-key speedbar-buffers-key-map
"r" 'speedbar-buffer-revert-buffer
)
3809 (defvar speedbar-buffer-easymenu-definition
3810 '(["Jump to buffer" speedbar-edit-line t
]
3811 ["Expand File Tags" speedbar-expand-line
3812 (save-excursion (beginning-of-line)
3813 (looking-at "[0-9]+: *.\\+. "))]
3814 ["Flush Cache & Expand" speedbar-flush-expand-line
3815 (save-excursion (beginning-of-line)
3816 (looking-at "[0-9]+: *.\\+. "))]
3817 ["Contract File Tags" speedbar-contract-line
3818 (save-excursion (beginning-of-line)
3819 (looking-at "[0-9]+: *.-. "))]
3821 ["Kill Buffer" speedbar-buffer-kill-buffer
3822 (save-excursion (beginning-of-line)
3823 (looking-at "[0-9]+: *.[-+?]. "))]
3824 ["Revert Buffer" speedbar-buffer-revert-buffer
3825 (save-excursion (beginning-of-line)
3826 (looking-at "[0-9]+: *.[-+?]. "))]
3828 "Menu item elements shown when displaying a buffer list.")
3830 (defun speedbar-buffer-buttons (_directory _zero
)
3831 "Create speedbar buttons based on the buffers currently loaded.
3832 DIRECTORY is the directory of the currently active buffer, and ZERO is 0."
3833 (speedbar-buffer-buttons-engine nil
))
3835 (defun speedbar-buffer-buttons-temp (_directory _zero
)
3836 "Create speedbar buttons based on the buffers currently loaded.
3837 DIRECTORY is the directory of the currently active buffer, and ZERO is 0."
3838 (speedbar-buffer-buttons-engine t
))
3840 (defun speedbar-buffer-buttons-engine (temp)
3841 "Create speedbar buffer buttons.
3842 If TEMP is non-nil, then clicking on a buffer restores the previous display."
3843 (speedbar-insert-separator "Active Buffers:")
3844 (let ((bl (buffer-list))
3845 (case-fold-search t
))
3847 (if (string-match "^[ *]" (buffer-name (car bl
)))
3849 (let* ((known (string-match speedbar-file-regexp
3850 (buffer-name (car bl
))))
3851 (expchar (if known ?
+ ??
))
3852 (fn (if known
'speedbar-tag-file nil
))
3853 (fname (with-current-buffer (car bl
)
3854 (buffer-file-name))))
3855 (speedbar-make-tag-line 'bracket expchar fn
3856 (if fname
(file-name-nondirectory fname
))
3857 (buffer-name (car bl
))
3858 'speedbar-buffer-click temp
3859 'speedbar-file-face
0)
3860 (speedbar-buffers-tail-notes (car bl
))))
3862 (setq bl
(buffer-list))
3863 (speedbar-insert-separator "Scratch Buffers:")
3865 (if (not (string-match "^\\*" (buffer-name (car bl
))))
3867 (if (eq (car bl
) speedbar-buffer
)
3869 (speedbar-make-tag-line 'bracket ?? nil nil
3870 (buffer-name (car bl
))
3871 'speedbar-buffer-click temp
3872 'speedbar-file-face
0)
3873 (speedbar-buffers-tail-notes (car bl
))))
3875 (setq bl
(buffer-list))
3876 ;;(speedbar-insert-separator "Hidden Buffers:")
3878 ;; (if (not (string-match "^ " (buffer-name (car bl))))
3880 ;; (if (eq (car bl) speedbar-buffer)
3882 ;; (speedbar-make-tag-line 'bracket ?? nil nil
3883 ;; (buffer-name (car bl))
3884 ;; 'speedbar-buffer-click temp
3885 ;; 'speedbar-file-face 0)
3886 ;; (speedbar-buffers-tail-notes (car bl))))
3887 ;; (setq bl (cdr bl)))
3890 (defun speedbar-buffers-tail-notes (buffer)
3891 "Add a note to the end of the last tag line.
3892 Argument BUFFER is the buffer being tested."
3893 (when (with-current-buffer buffer buffer-read-only
)
3894 (speedbar-insert-button "%" nil nil nil nil t
)))
3896 (defun speedbar-buffers-item-info ()
3897 "Display information about the current buffer on the current line."
3898 (or (speedbar-item-info-tag-helper)
3899 (let* ((item (speedbar-line-text))
3900 (buffer (if item
(get-buffer item
) nil
)))
3902 (dframe-message "%s%s %S %d %s"
3903 (if (buffer-modified-p buffer
) "* " "")
3905 (with-current-buffer buffer major-mode
)
3906 (with-current-buffer buffer
(buffer-size))
3907 (or (buffer-file-name buffer
) "<No file>"))))))
3909 (defun speedbar-buffers-line-directory (&optional _depth
)
3910 "Fetch the directory of the file (buffer) specified on the current line.
3911 Optional argument DEPTH specifies the current depth of the back search."
3914 (let ((start (point)))
3915 ;; Buffers are always at level 0
3916 (if (not (re-search-backward "^0:" nil t
))
3918 (let* ((bn (speedbar-line-text))
3919 (buffer (if bn
(get-buffer bn
))))
3921 (if (eq start
(line-end-position))
3922 (or (with-current-buffer buffer default-directory
)
3924 (buffer-file-name buffer
))))))))
3926 (defun speedbar-buffer-click (text token _indent
)
3927 "When the users clicks on a buffer-button in speedbar.
3928 TEXT is the buffer's name, TOKEN and INDENT are unused."
3929 (if dframe-power-click
3930 (let ((pop-up-frames t
)) (select-window (display-buffer text
)))
3931 (dframe-select-attached-frame speedbar-frame
)
3932 (switch-to-buffer text
)
3933 (if token
(speedbar-change-initial-expansion-list
3934 speedbar-previously-used-expansion-list-name
))))
3936 (defun speedbar-buffer-kill-buffer ()
3937 "Kill the buffer the cursor is on in the speedbar buffer."
3940 (let ((text (speedbar-line-text)))
3941 (if (and (get-buffer text
)
3942 (speedbar-y-or-n-p (format "Kill buffer %s? " text
)))
3944 (speedbar-refresh)))))
3946 (defun speedbar-buffer-revert-buffer ()
3947 "Revert the buffer the cursor is on in the speedbar buffer."
3951 ;; If this fails, then it is a non-standard click, and as such,
3952 ;; perfectly allowed
3953 (if (re-search-forward "[]>?}] [^ ]" (line-end-position) t
)
3956 (buffer-substring (point) (line-end-position)))))
3957 (if (get-buffer text
)
3960 (revert-buffer t
)))))))
3963 ;;; Useful hook values and such.
3965 (defvar speedbar-highlight-one-tag-line nil
3966 "Overlay used for highlighting the most recently jumped to tag line.")
3968 (defun speedbar-highlight-one-tag-line ()
3969 "Highlight the current line, unhighlighting a previously jumped to line."
3970 (speedbar-unhighlight-one-tag-line)
3971 (setq speedbar-highlight-one-tag-line
3972 (speedbar-make-overlay (line-beginning-position)
3973 (1+ (line-end-position))))
3974 (speedbar-overlay-put speedbar-highlight-one-tag-line
'face
3975 'speedbar-highlight-face
)
3976 (add-hook 'pre-command-hook
'speedbar-unhighlight-one-tag-line
))
3978 (defun speedbar-unhighlight-one-tag-line ()
3979 "Unhighlight the currently highlighted line."
3980 (when (and speedbar-highlight-one-tag-line
3981 (not (eq this-command
'handle-switch-frame
)))
3982 (speedbar-delete-overlay speedbar-highlight-one-tag-line
)
3983 (setq speedbar-highlight-one-tag-line nil
)
3984 (remove-hook 'pre-command-hook
'speedbar-unhighlight-one-tag-line
)))
3986 (defun speedbar-recenter-to-top ()
3987 "Recenter the current buffer so point is on the top of the window."
3990 (defun speedbar-recenter ()
3991 "Recenter the current buffer so point is in the center of the window."
3992 (recenter (/ (window-height) 2)))
3995 ;;; Color loading section.
3997 (defface speedbar-button-face
'((((class color
) (background light
))
3998 :foreground
"green4")
3999 (((class color
) (background dark
))
4000 :foreground
"green3"))
4001 "Speedbar face for +/- buttons."
4002 :group
'speedbar-faces
)
4004 (defface speedbar-file-face
'((((class color
) (background light
))
4005 :foreground
"cyan4")
4006 (((class color
) (background dark
))
4009 "Speedbar face for file names."
4010 :group
'speedbar-faces
)
4012 (defface speedbar-directory-face
'((((class color
) (background light
))
4013 :foreground
"blue4")
4014 (((class color
) (background dark
))
4015 :foreground
"light blue"))
4016 "Speedbar face for directory names."
4017 :group
'speedbar-faces
)
4019 (defface speedbar-tag-face
'((((class color
) (background light
))
4020 :foreground
"brown")
4021 (((class color
) (background dark
))
4022 :foreground
"yellow"))
4023 "Speedbar face for tags."
4024 :group
'speedbar-faces
)
4026 (defface speedbar-selected-face
'((((class color
) (background light
))
4027 :foreground
"red" :underline t
)
4028 (((class color
) (background dark
))
4029 :foreground
"red" :underline t
)
4031 "Speedbar face for the file in the active window."
4032 :group
'speedbar-faces
)
4034 (defface speedbar-highlight-face
'((((class color
) (background light
))
4035 :background
"green")
4036 (((class color
) (background dark
))
4037 :background
"sea green"))
4038 "Speedbar face for highlighting buttons with the mouse."
4039 :group
'speedbar-faces
)
4041 (defface speedbar-separator-face
'((((class color
) (background light
))
4045 (((class color
) (background dark
))
4049 (((class grayscale monochrome
)
4054 (((class grayscale monochrome
)
4059 "Speedbar face for separator labels in a display."
4060 :group
'speedbar-faces
)
4062 ;; some edebug hooks
4063 (add-hook 'edebug-setup-hook
4065 (def-edebug-spec speedbar-with-writable def-body
)))
4067 ;; Fix a font lock problem for some versions of Emacs
4068 (and (boundp 'font-lock-global-modes
)
4069 font-lock-global-modes
4070 (if (eq font-lock-global-modes t
)
4071 (setq font-lock-global-modes
'(not speedbar-mode
))
4072 (if (eq (car font-lock-global-modes
) 'not
)
4073 (add-to-list 'font-lock-global-modes
'speedbar-mode t
)
4074 (setq font-lock-global-modes
(delq 'speedbar-mode
4075 font-lock-global-modes
)))))
4079 ;; run load-time hooks
4080 (run-hooks 'speedbar-load-hook
)
4082 ;;; speedbar ends here