1 ;;; speedbar --- quick access to files and tags in a frame
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Author: Eric M. Ludlam <zappo@gnu.org>
7 ;; Keywords: file, tags, tools
9 (defvar speedbar-version
"1.0"
10 "The current version of speedbar.")
11 (defvar speedbar-incompatible-version
"0.14beta4"
12 "This version of speedbar is incompatible with this version.
13 Due to massive API changes (removing the use of the word PATH)
14 this version is not backward compatible to 0.14 or earlier.")
16 ;; This file is part of GNU Emacs.
18 ;; GNU Emacs is free software; you can redistribute it and/or modify
19 ;; it under the terms of the GNU General Public License as published by
20 ;; the Free Software Foundation; either version 3, or (at your option)
23 ;; GNU Emacs is distributed in the hope that it will be useful,
24 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 ;; GNU General Public License for more details.
28 ;; You should have received a copy of the GNU General Public License
29 ;; along with GNU Emacs; see the file COPYING. If not, write to the
30 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
31 ;; Boston, MA 02110-1301, USA.
35 ;; The speedbar provides a frame in which files, and locations in
36 ;; files are displayed. These items can be clicked on with mouse-2 in
37 ;; to display that file location.
39 ;;; Customizing and Developing for speedbar
41 ;; Please see the speedbar manual for informaion.
45 ;; Users of really old emacsen without the need timer functions
46 ;; will not have speedbar updating automatically. Use "g" to refresh
47 ;; the display after changing directories. Remember, do not interrupt
48 ;; the stealthy updates or your display may not be completely
51 ;; AUC-TEX users: The imenu tags for AUC-TEX mode don't work very
52 ;; well. Use the imenu keywords from tex-mode.el for better results.
54 ;; This file requires the library package assoc (association lists)
55 ;; assoc should be available in all modern versions of Emacs.
56 ;; The custom package is optional (for easy configuration of speedbar)
57 ;; http://www.dina.kvl.dk/~abraham/custom/
58 ;; custom is available in all versions of Emacs version 20 or better.
60 ;;; Developing for speedbar
62 ;; Adding a speedbar specialized display mode:
64 ;; Speedbar can be configured to create a special display for certain
65 ;; modes that do not display traditional file/tag data. Rmail, Info,
66 ;; and the debugger are examples. These modes can, however, benefit
67 ;; from a speedbar style display in their own way.
69 ;; If your `major-mode' is `foo-mode', the only requirement is to
70 ;; create a function called `foo-speedbar-buttons' which takes one
71 ;; argument, BUFFER. BUFFER will be the buffer speedbar wants filled.
72 ;; In `foo-speedbar-buttons' there are several functions that make
73 ;; building a speedbar display easy. See the documentation for
74 ;; `speedbar-with-writable' (needed because the buffer is usually
75 ;; read-only) `speedbar-make-tag-line', `speedbar-insert-button', and
76 ;; `speedbar-insert-generic-list'. If you use
77 ;; `speedbar-insert-generic-list', also read the doc for
78 ;; `speedbar-tag-hierarchy-method' in case you wish to override it.
79 ;; The macro `speedbar-with-attached-buffer' brings you back to the
80 ;; buffer speedbar is displaying for.
82 ;; For those functions that make buttons, the "function" should be a
83 ;; symbol that is the function to call when clicked on. The "token"
84 ;; is extra data you can pass along. The "function" must take three
85 ;; parameters. They are (TEXT TOKEN INDENT). TEXT is the text of the
86 ;; button clicked on. TOKEN is the data passed in when you create the
87 ;; button. INDENT is an indentation level, or 0. You can store
88 ;; indentation levels with `speedbar-make-tag-line' which creates a
89 ;; line with an expander (eg. [+]) and a text button.
91 ;; Some useful functions when writing expand functions, and click
92 ;; functions are `speedbar-change-expand-button-char',
93 ;; `speedbar-delete-subblock', and `speedbar-center-buffer-smartly'.
94 ;; The variable `speedbar-power-click' is set to t in your functions
95 ;; when the user shift-clicks. This is an indication of anything from
96 ;; refreshing cached data to making a buffer appear in a new frame.
98 ;; If you wish to add to the default speedbar menu for the case of
99 ;; `foo-mode', create a variable `foo-speedbar-menu-items'. This
100 ;; should be a list compatible with the `easymenu' package. It will
101 ;; be spliced into the main menu. (Available with click-mouse-3). If
102 ;; you wish to have extra key bindings in your special mode, create a
103 ;; variable `foo-speedbar-key-map'. Instead of using `make-keymap',
104 ;; or `make-sparse-keymap', use the function
105 ;; `speedbar-make-specialized-keymap'. This lets you inherit all of
106 ;; speedbar's default bindings with low overhead.
108 ;; Adding a speedbar top-level display mode:
110 ;; Unlike the specialized modes, there are no name requirements,
111 ;; however the methods for writing a button display, menu, and keymap
112 ;; are the same. Once you create these items, you can call the
113 ;; function `speedbar-add-expansion-list'. It takes one parameter
114 ;; which is a list element of the form (NAME MENU KEYMAP &rest
115 ;; BUTTON-FUNCTIONS). NAME is a string that will show up in the
116 ;; Displays menu item. MENU is a symbol containing the menu items to
117 ;; splice in. KEYMAP is a symbol holding the keymap to use, and
118 ;; BUTTON-FUNCTIONS are the function names to call, in order, to create
120 ;; Another tweakable variable is `speedbar-stealthy-function-list'
121 ;; which is of the form (NAME &rest FUNCTION ...). NAME is the string
122 ;; name matching `speedbar-add-expansion-list'. (It does not need to
123 ;; exist.). This provides additional display info which might be
124 ;; time-consuming to calculate.
125 ;; Lastly, `speedbar-mode-functions-list' allows you to set special
126 ;; function overrides.
129 ;; - Timeout directories we haven't visited in a while.
136 ;; customization stuff
137 (defgroup speedbar nil
138 "File and tag browser frame."
145 (defgroup speedbar-faces nil
146 "Faces used in speedbar."
151 (defgroup speedbar-vc nil
152 "Version control display in speedbar."
158 ;; Note: `inversion-test' requires parts of the CEDET package that are
159 ;; not included with Emacs.
161 ;; (defun speedbar-require-version (major minor &optional beta)
162 ;; "Non-nil if this version of SPEEDBAR does not satisfy a specific version.
165 ;; (MAJOR MINOR &optional BETA)
167 ;; Values MAJOR and MINOR must be integers. BETA can be an integer, or
168 ;; excluded if a released version is required.
170 ;; It is assumed that if the current version is newer than that specified,
171 ;; everything passes. Exceptions occur when known incompatibilities are
173 ;; (inversion-test 'speedbar
174 ;; (concat major "." minor
175 ;; (when beta (concat "beta" beta)))))
177 (defvar speedbar-initial-expansion-mode-alist
178 '(("buffers" speedbar-buffer-easymenu-definition speedbar-buffers-key-map
179 speedbar-buffer-buttons
)
180 ("quick buffers" speedbar-buffer-easymenu-definition speedbar-buffers-key-map
181 speedbar-buffer-buttons-temp
)
182 ;; Files last, means first in the Displays menu
183 ("files" speedbar-easymenu-definition-special speedbar-file-key-map
184 speedbar-directory-buttons speedbar-default-directory-list
)
186 "List of named expansion elements for filling the speedbar frame.
187 These expansion lists are only valid for regular files. Special modes
188 still get to override this list on a mode-by-mode basis. This list of
189 lists is of the form (NAME MENU KEYMAP FN1 FN2 ...). NAME is a string
190 representing the types of things to be displayed. MENU is an easymenu
191 structure used when in this mode. KEYMAP is a local keymap to install
192 over the regular speedbar keymap. FN1 ... are functions that will be
193 called in order. These functions will always get the default
194 directory to use passed in as the first parameter, and a 0 as the
195 second parameter. The 0 indicates the uppermost indentation level.
196 They must assume that the cursor is at the position where they start
199 (defvar speedbar-initial-expansion-list-name
"files"
200 "A symbol name representing the expansion list to use.
201 The expansion list `speedbar-initial-expansion-mode-alist' contains
202 the names and associated functions to use for buttons in speedbar.")
204 (defvar speedbar-previously-used-expansion-list-name
"files"
205 "Save the last expansion list method.
206 This is used for returning to a previous expansion list method when
207 the user is done with the current expansion list.")
209 (defvar speedbar-stealthy-function-list
211 speedbar-update-current-file
212 speedbar-check-read-only
214 speedbar-check-objects
)
216 "List of functions to periodically call stealthily.
217 This list is of the form:
218 '( (\"NAME\" FUNCTION ...)
220 where NAME is the name of the major display mode these functions are
221 for, and the remaining elements FUNCTION are functions to call in order.
222 Each function must return nil if interrupted, or t if completed.
223 Stealthy functions which have a single operation should always return t.
224 Functions which take a long time should maintain a state (where they
225 are in their speedbar related calculations) and permit interruption.
226 See `speedbar-check-vc' as a good example.")
228 (defvar speedbar-mode-functions-list
229 '(("files" (speedbar-item-info . speedbar-files-item-info
)
230 (speedbar-line-directory . speedbar-files-line-directory
))
231 ("buffers" (speedbar-item-info . speedbar-buffers-item-info
)
232 (speedbar-line-directory . speedbar-buffers-line-directory
))
233 ("quick buffers" (speedbar-item-info . speedbar-buffers-item-info
)
234 (speedbar-line-directory . speedbar-buffers-line-directory
))
236 "List of function tables to use for different major display modes.
237 It is not necessary to define any functions for a specialized mode.
238 This just provides a simple way of adding lots of customizations.
239 Each sublist is of the form:
240 (\"NAME\" (FUNCTIONSYMBOL . REPLACEMENTFUNCTION) ...)
241 Where NAME is the name of the specialized mode. The rest of the list
242 is a set of dotted pairs of the form FUNCTIONSYMBOL, which is the name
243 of a function you would like to replace, and REPLACEMENTFUNCTION,
244 which is a function you can call instead. Not all functions can be
245 replaced this way. Replaceable functions must provide that
246 functionality individually.")
248 (defcustom speedbar-mode-specific-contents-flag t
249 "*Non-nil means speedbar will show special mode contents.
250 This permits some modes to create customized contents for the speedbar
255 (defcustom speedbar-query-confirmation-method
'all
256 "*Query control for file operations.
257 The 'always flag means to always query before file operations.
258 The 'none-but-delete flag means to not query before any file
259 operations, except before a file deletion."
261 :type
'(radio (const :tag
"Always Query before some file operations."
263 (const :tag
"Never Query before file operations, except for deletions."
265 ;;;; (const :tag "Never Every Query."
269 (defvar speedbar-special-mode-expansion-list nil
270 "Default function list for creating specialized button lists.
271 This list is set by modes that wish to have special speedbar displays.
272 The list is of function names. Each function is called with one
273 parameter BUFFER, the originating buffer. The current buffer is the
276 (defvar speedbar-special-mode-key-map nil
277 "Default keymap used when identifying a specialized display mode.
278 This keymap is local to each buffer that wants to define special keybindings
279 effective when its display is shown.")
281 (defcustom speedbar-before-visiting-file-hook
'(push-mark)
282 "*Hooks run before speedbar visits a file in the selected frame.
283 The default buffer is the buffer in the selected window in the attached frame."
287 (defcustom speedbar-visiting-file-hook nil
288 "*Hooks run when speedbar visits a file in the selected frame."
292 (defcustom speedbar-before-visiting-tag-hook
'(push-mark)
293 "*Hooks run before speedbar visits a tag in the selected frame.
294 The default buffer is the buffer in the selected window in the attached frame."
298 (defcustom speedbar-visiting-tag-hook
'(speedbar-highlight-one-tag-line)
299 "*Hooks run when speedbar visits a tag in the selected frame."
302 :options
'(speedbar-highlight-one-tag-line
303 speedbar-recenter-to-top
307 (defcustom speedbar-load-hook nil
308 "*Hooks run when speedbar is loaded."
312 (defcustom speedbar-reconfigure-keymaps-hook nil
313 "*Hooks run when the keymaps are regenerated."
317 (defcustom speedbar-show-unknown-files nil
318 "*Non-nil show files we can't expand with a ? in the expand button.
319 A nil value means don't show the file in the list."
323 ;;; EVENTUALLY REMOVE THESE
325 ;; When I moved to a repeating timer, I had the horrible misfortune
326 ;; of losing the ability for adaptive speed choice. This update
327 ;; speed currently causes long delays when it should have been turned off.
328 (defvar speedbar-update-speed dframe-update-speed
)
329 (make-obsolete-variable 'speedbar-update-speed
333 (defvar speedbar-navigating-speed dframe-update-speed
)
334 (make-obsolete-variable 'speedbar-navigating-speed
339 (defcustom speedbar-frame-parameters
'((minibuffer . nil
)
347 "*Parameters to use when creating the speedbar frame in Emacs.
348 Any parameter supported by a frame may be added. The parameter `height'
349 will be initialized to the height of the frame speedbar is
350 attached to and added to this list before the new frame is initialized."
352 :type
'(repeat (cons :format
"%v"
353 (symbol :tag
"Parameter")
354 (sexp :tag
"Value"))))
356 ;; These values by Hrvoje Niksic <hniksic@srce.hr>
357 (defcustom speedbar-frame-plist
358 '(minibuffer nil width
20 border-width
0
359 internal-border-width
0 unsplittable t
360 default-toolbar-visible-p nil has-modeline-p nil
361 menubar-visible-p nil
362 default-gutter-visible-p nil
364 "*Parameters to use when creating the speedbar frame in XEmacs.
365 Parameters not listed here which will be added automatically are
366 `height' which will be initialized to the height of the frame speedbar
369 :type
'(repeat (group :inline t
370 (symbol :tag
"Property")
371 (sexp :tag
"Value"))))
373 (defcustom speedbar-use-imenu-flag
(fboundp 'imenu
)
374 "*Non-nil means use imenu for file parsing, nil to use etags.
375 XEmacs prior to 20.4 doesn't support imenu, therefore the default is to
376 use etags instead. Etags support is not as robust as imenu support."
377 :tag
"Use Imenu for tags"
381 (defvar speedbar-dynamic-tags-function-list
382 '((speedbar-fetch-dynamic-imenu . speedbar-insert-imenu-list
)
383 (speedbar-fetch-dynamic-etags . speedbar-insert-etags-list
))
384 "Set to a list of functions which will return and insert a list of tags.
385 Each element is of the form ( FETCH . INSERT ) where FETCH
386 is a function which takes one parameter (the file to tag) and returns a
387 list of tags. The tag list can be of any form as long as the
388 corresponding insert method can handle it. If it returns t, then an
389 error occurred, and the next fetch routine is tried.
390 INSERT is a function which takes an INDENTation level, and a LIST of
391 tags to insert. It will then create the speedbar buttons.")
393 (defcustom speedbar-use-tool-tips-flag
(fboundp 'tooltip-mode
)
394 "Non-nil means to use tool tips if they are available.
395 When tooltips are not available, mouse-tracking and minibuffer
396 display is used instead."
400 (defcustom speedbar-track-mouse-flag
(not speedbar-use-tool-tips-flag
)
401 "*Non-nil means to display info about the line under the mouse."
405 (defcustom speedbar-default-position
'left-right
406 "*Default position of the speedbar frame.
407 Possible values are 'left, 'right or 'left-right.
408 If value is 'left-right, the most suitable location is
409 determined automatically."
411 :type
'(radio (const :tag
"Automatic" left-right
)
412 (const :tag
"Left" left
)
413 (const :tag
"Right" right
)))
415 (defcustom speedbar-sort-tags nil
416 "*If non-nil, sort tags in the speedbar display. *Obsolete*.
417 Use `semantic-tag-hierarchy-method' instead."
421 (defcustom speedbar-tag-hierarchy-method
422 '(speedbar-prefix-group-tag-hierarchy
423 speedbar-trim-words-tag-hierarchy
)
424 "*List of hooks which speedbar will use to organize tags into groups.
425 Groups are defined as expandable meta-tags. Imenu supports
426 such things in some languages, such as separating variables from
427 functions. Each hook takes one argument LST, and may destructively
428 create a new list of the same form. LST is a list of elements of the
431 where each ELT is of the form
432 (TAG-NAME-STRING . NUMBER-OR-MARKER)
434 (GROUP-NAME-STRING ELT1 ELT2... ELTn)"
437 :options
'(speedbar-prefix-group-tag-hierarchy
438 speedbar-trim-words-tag-hierarchy
439 speedbar-simple-group-tag-hierarchy
440 speedbar-sort-tag-hierarchy
)
443 (defcustom speedbar-tag-group-name-minimum-length
4
444 "*The minimum length of a prefix group name before expanding.
445 Thus, if the `speedbar-tag-hierarchy-method' includes `prefix-group'
446 and one such groups common characters is less than this number of
447 characters, then the group name will be changed to the form of:
451 This way we won't get silly looking listings."
455 (defcustom speedbar-tag-split-minimum-length
20
456 "*Minimum length before we stop trying to create sub-lists in tags.
457 This is used by all tag-hierarchy methods that break large lists into
462 (defcustom speedbar-tag-regroup-maximum-length
10
463 "*Maximum length of submenus that are regrouped.
464 If the regrouping option is used, then if two or more short subgroups
465 are next to each other, then they are combined until this number of
470 (defcustom speedbar-directory-button-trim-method
'span
471 "*Indicates how the directory button will be displayed.
473 'span - span large directories over multiple lines.
474 'trim - trim large directories to only show the last few.
477 :type
'(radio (const :tag
"Span large directories over mutiple lines."
479 (const :tag
"Trim large directories to only show the last few."
481 (const :tag
"No trimming." nil
)))
483 (defcustom speedbar-smart-directory-expand-flag t
484 "*Non-nil means speedbar should use smart expansion.
485 Smart expansion only affects when speedbar wants to display a
486 directory for a file in the attached frame. When smart expansion is
487 enabled, new directories which are children of a displayed directory
488 are expanded in the current framework. If nil, then the current
489 hierarchy would be replaced with the new directory."
493 (defcustom speedbar-indentation-width
1
494 "*When sub-nodes are expanded, the number of spaces used for indentation."
498 (defcustom speedbar-hide-button-brackets-flag nil
499 "*Non-nil means speedbar will hide the brackets around the + or -."
503 (defcustom speedbar-before-popup-hook nil
504 "*Hooks called before popping up the speedbar frame."
508 (defcustom speedbar-after-create-hook
'(speedbar-frame-reposition-smartly)
509 "*Hooks called after popping up the speedbar frame."
513 (defcustom speedbar-before-delete-hook nil
514 "*Hooks called before deleting the speedbar frame."
518 (defcustom speedbar-mode-hook nil
519 "*Hooks called after creating a speedbar buffer."
523 (defcustom speedbar-timer-hook nil
524 "*Hooks called after running the speedbar timer function."
528 (defcustom speedbar-verbosity-level
1
529 "*Verbosity level of the speedbar.
531 1 means medium level verbosity.
532 2 and higher are higher levels of verbosity."
536 (defvar speedbar-indicator-separator
" "
537 "String separating file text from indicator characters.")
539 (defcustom speedbar-vc-do-check t
540 "*Non-nil check all files in speedbar to see if they have been checked out.
541 Any file checked out is marked with `speedbar-vc-indicator'."
545 (defvar speedbar-vc-indicator
"*"
546 "Text used to mark files which are currently checked out.
547 Other version control systems can be added by examining the function
548 `speedbar-vc-directory-enable-hook' and `speedbar-vc-in-control-hook'.")
550 (defcustom speedbar-vc-directory-enable-hook nil
551 "*Return non-nil if the current directory should be checked for Version Control.
552 Functions in this hook must accept one parameter which is the directory
557 (defcustom speedbar-vc-in-control-hook nil
558 "*Return non-nil if the specified file is under Version Control.
559 Functions in this hook must accept two parameters. The DIRECTORY of the
560 current file, and the FILENAME of the file being checked."
564 (defvar speedbar-vc-to-do-point nil
565 "Local variable maintaining the current version control check position.")
567 (defcustom speedbar-obj-do-check t
568 "*Non-nil check all files in speedbar to see if they have an object file.
569 Any file checked out is marked with `speedbar-obj-indicator', and the
570 marking is based on `speedbar-obj-alist'"
574 (defvar speedbar-obj-to-do-point nil
575 "Local variable maintaining the current version control check position.")
577 (defvar speedbar-obj-indicator
'("#" .
"!")
578 "Text used to mark files that have a corresponding hidden object file.
579 The car is for an up-to-date object. The cdr is for an out of date object.
580 The expression `speedbar-obj-alist' defines who gets tagged.")
582 (defvar speedbar-obj-alist
583 '(("\\.\\([cpC]\\|cpp\\|cc\\|cxx\\)$" .
".o")
585 ("\\.java$" .
".class")
586 ("\\.f\\(or\\|90\\|77\\)?$" .
".o")
588 ("\\.texi$" .
".info"))
589 "Alist of file extensions, and their corresponding object file type.")
591 (defvar speedbar-ro-to-do-point nil
592 "Local variable maintaining the current read only check position.")
594 (defvar speedbar-object-read-only-indicator
"%"
595 "Indicator to append onto a line if that item is Read Only.")
597 ;; Note: Look for addition place to add indicator lists that
598 ;; use skip-chars instead of a regular expression.
599 (defvar speedbar-indicator-regex
600 (concat (regexp-quote speedbar-indicator-separator
)
602 (regexp-quote speedbar-vc-indicator
)
604 (regexp-quote (car speedbar-obj-indicator
))
606 (regexp-quote (cdr speedbar-obj-indicator
))
608 (regexp-quote speedbar-object-read-only-indicator
)
610 "Regular expression used when identifying files.
611 Permits stripping of indicator characters from a line.")
613 (defcustom speedbar-scanner-reset-hook nil
614 "*Hook called whenever generic scanners are reset.
615 Set this to implement your own scanning / rescan safe functions with
620 (defvar speedbar-ignored-modes
'(fundamental-mode)
621 "*List of major modes which speedbar will not switch directories for.")
623 (defun speedbar-extension-list-to-regex (extlist)
624 "Takes EXTLIST, a list of extensions and transforms it into regexp.
625 All the preceding `.' are stripped for an optimized expression starting
626 with `.' followed by extensions, followed by full-filenames."
627 (let ((regex1 nil
) (regex2 nil
))
629 (if (= (string-to-char (car extlist
)) ?.
)
630 (setq regex1
(concat regex1
(if regex1
"\\|" "")
631 (substring (car extlist
) 1)))
632 (setq regex2
(concat regex2
(if regex2
"\\|" "") (car extlist
))))
633 (setq extlist
(cdr extlist
)))
634 ;; concat all the sub-exressions together, making sure all types
635 ;; of parts exist during concatination.
637 (if regex1
(concat "\\(\\.\\(" regex1
"\\)\\)") "")
638 (if (and regex1 regex2
) "\\|" "")
639 (if regex2
(concat "\\(" regex2
"\\)") "")
642 (defvar speedbar-ignored-directory-regexp nil
643 "Regular expression matching directories speedbar will not switch to.
644 Created from `speedbar-ignored-directory-expressions' with the function
645 `speedbar-extension-list-to-regex' (a misnamed function in this case.)
646 Use the function `speedbar-add-ignored-directory-regexp', or customize the
647 variable `speedbar-ignored-directory-expressions' to modify this variable.")
649 (define-obsolete-variable-alias 'speedbar-ignored-path-expressions
650 'speedbar-ignored-directory-expressions
)
652 (defcustom speedbar-ignored-directory-expressions
653 '("[/\\]logs?[/\\]\\'")
654 "*List of regular expressions matching directories speedbar will ignore.
655 They should included directories which are notoriously very large
656 and take a long time to load in. Use the function
657 `speedbar-add-ignored-directory-regexp' to add new items to this list after
658 speedbar is loaded. You may place anything you like in this list
659 before speedbar has been loaded."
661 :type
'(repeat (regexp :tag
"Directory Regexp"))
662 :set
(lambda (sym val
)
663 (setq speedbar-ignored-directory-expressions val
664 speedbar-ignored-directory-regexp
665 (speedbar-extension-list-to-regex val
))))
667 (defcustom speedbar-directory-unshown-regexp
"^\\(\\..*\\)\\'"
668 "*Regular expression matching directories not to show in speedbar.
669 They should include commonly existing directories which are not
670 useful. It is no longer necessary to include version-control
671 directories here; see `vc-directory-exclusion-list'."
675 (defvar speedbar-file-unshown-regexp
676 (let ((nstr "") (noext completion-ignored-extensions
))
678 (setq nstr
(concat nstr
(regexp-quote (car noext
)) "\\'"
679 (if (cdr noext
) "\\|" ""))
681 ;; backup refdir lockfile
682 (concat nstr
"\\|#[^#]+#$\\|\\.\\.?\\'\\|\\.#"))
683 "*Regexp matching files we don't want displayed in a speedbar buffer.
684 It is generated from the variable `completion-ignored-extensions'.")
686 (defvar speedbar-file-regexp nil
687 "Regular expression matching files we know how to expand.
688 Created from `speedbar-supported-extension-expressions' with the
689 function `speedbar-extension-list-to-regex'.")
691 ;; this is dangerous to customize, because the defaults will probably
692 ;; change in the future.
693 (defcustom speedbar-supported-extension-expressions
694 (append '(".[ch]\\(\\+\\+\\|pp\\|c\\|h\\|xx\\)?" ".tex\\(i\\(nfo\\)?\\)?"
695 ".el" ".emacs" ".l" ".lsp" ".p" ".java" ".f\\(90\\|77\\|or\\)?")
696 (if speedbar-use-imenu-flag
697 '(".ada" ".p[lm]" ".tcl" ".m" ".scm" ".pm" ".py" ".g"
698 ;; html is not supported by default, but an imenu tags package
699 ;; is available. Also, html files are nice to be able to see.
701 ".ma?k" "[Mm]akefile\\(\\.in\\)?")))
702 "*List of regular expressions which will match files supported by tagging.
703 Do not prefix the `.' char with a double \\ to quote it, as the period
704 will be stripped by a simplified optimizer when compiled into a
705 singular expression. This variable will be turned into
706 `speedbar-file-regexp' for use with speedbar. You should use the
707 function `speedbar-add-supported-extension' to add a new extension at
708 runtime, or use the configuration dialog to set it in your .emacs file.
709 If you add an extension to this list, and it does not appear, you may
710 need to also modify `completion-ignored-extension' which will also help
713 :type
'(repeat (regexp :tag
"Extension Regexp"))
714 :set
(lambda (sym val
)
715 (set 'speedbar-supported-extension-expressions val
)
716 (set 'speedbar-file-regexp
(speedbar-extension-list-to-regex val
))))
718 (setq speedbar-file-regexp
719 (speedbar-extension-list-to-regex speedbar-supported-extension-expressions
))
721 (defun speedbar-add-supported-extension (extension)
722 "Add EXTENSION as a new supported extension for speedbar tagging.
723 This should start with a `.' if it is not a complete file name, and
724 the dot should NOT be quoted in with \\. Other regular expression
725 matchers are allowed however. EXTENSION may be a single string or a
727 (interactive "sExtension: ")
728 (if (not (listp extension
)) (setq extension
(list extension
)))
730 (if (member (car extension
) speedbar-supported-extension-expressions
)
732 (setq speedbar-supported-extension-expressions
733 (cons (car extension
) speedbar-supported-extension-expressions
)))
734 (setq extension
(cdr extension
)))
735 (setq speedbar-file-regexp
(speedbar-extension-list-to-regex
736 speedbar-supported-extension-expressions
)))
738 (defun speedbar-add-ignored-directory-regexp (directory-expression)
739 "Add DIRECTORY-EXPRESSION as a new ignored directory for speedbar tracking.
740 This function will modify `speedbar-ignored-directory-regexp' and add
741 DIRECTORY-EXPRESSION to `speedbar-ignored-directory-expressions'."
742 (interactive "sDirectory regex: ")
743 (if (not (listp directory-expression
))
744 (setq directory-expression
(list directory-expression
)))
745 (while directory-expression
746 (if (member (car directory-expression
) speedbar-ignored-directory-expressions
)
748 (setq speedbar-ignored-directory-expressions
749 (cons (car directory-expression
) speedbar-ignored-directory-expressions
)))
750 (setq directory-expression
(cdr directory-expression
)))
751 (setq speedbar-ignored-directory-regexp
(speedbar-extension-list-to-regex
752 speedbar-ignored-directory-expressions
)))
754 ;; If we don't have custom, then we set it here by hand.
755 (if (not (fboundp 'custom-declare-variable
))
756 (setq speedbar-file-regexp
(speedbar-extension-list-to-regex
757 speedbar-supported-extension-expressions
)
758 speedbar-ignored-directory-regexp
(speedbar-extension-list-to-regex
759 speedbar-ignored-directory-expressions
)))
761 (defvar speedbar-update-flag dframe-have-timer-flag
762 "*Non-nil means to automatically update the display.
763 When this is nil then speedbar will not follow the attached frame's directory.
764 When speedbar is active, use:
766 \\<speedbar-key-map> `\\[speedbar-toggle-updates]'
768 to toggle this value.")
770 (defvar speedbar-update-flag-disable nil
771 "Permanently disable changing of the update flag.")
773 (defvar speedbar-syntax-table nil
774 "Syntax-table used on the speedbar.")
776 (if speedbar-syntax-table
778 (setq speedbar-syntax-table
(make-syntax-table))
779 ;; turn off paren matching around here.
780 (modify-syntax-entry ?
\' " " speedbar-syntax-table
)
781 (modify-syntax-entry ?
\" " " speedbar-syntax-table
)
782 (modify-syntax-entry ?
( " " speedbar-syntax-table
)
783 (modify-syntax-entry ?
) " " speedbar-syntax-table
)
784 (modify-syntax-entry ?
{ " " speedbar-syntax-table
)
785 (modify-syntax-entry ?
} " " speedbar-syntax-table
)
786 (modify-syntax-entry ?
[ " " speedbar-syntax-table
)
787 (modify-syntax-entry ?
] " " speedbar-syntax-table
))
789 (defvar speedbar-key-map nil
790 "Keymap used in speedbar buffer.")
794 (setq speedbar-key-map
(make-keymap))
795 (suppress-keymap speedbar-key-map t
)
798 (define-key speedbar-key-map
"t" 'speedbar-toggle-updates
)
799 (define-key speedbar-key-map
"g" 'speedbar-refresh
)
802 (define-key speedbar-key-map
"n" 'speedbar-next
)
803 (define-key speedbar-key-map
"p" 'speedbar-prev
)
804 (define-key speedbar-key-map
"\M-n" 'speedbar-restricted-next
)
805 (define-key speedbar-key-map
"\M-p" 'speedbar-restricted-prev
)
806 (define-key speedbar-key-map
"\C-\M-n" 'speedbar-forward-list
)
807 (define-key speedbar-key-map
"\C-\M-p" 'speedbar-backward-list
)
808 ;; These commands never seemed useful.
809 ;; (define-key speedbar-key-map " " 'speedbar-scroll-up)
810 ;; (define-key speedbar-key-map [delete] 'speedbar-scroll-down)
812 ;; Short cuts I happen to find useful
813 (define-key speedbar-key-map
"r"
814 (lambda () (interactive)
815 (speedbar-change-initial-expansion-list
816 speedbar-previously-used-expansion-list-name
)))
817 (define-key speedbar-key-map
"b"
818 (lambda () (interactive)
819 (speedbar-change-initial-expansion-list "quick buffers")))
820 (define-key speedbar-key-map
"f"
821 (lambda () (interactive)
822 (speedbar-change-initial-expansion-list "files")))
824 (dframe-update-keymap speedbar-key-map
)
827 (defun speedbar-make-specialized-keymap ()
828 "Create a keymap for use with a speedbar major or minor display mode.
829 This basically creates a sparse keymap, and makes its parent be
831 (let ((k (make-sparse-keymap)))
832 (set-keymap-parent k speedbar-key-map
)
835 (defvar speedbar-file-key-map nil
836 "Keymap used in speedbar buffer while files are displayed.")
838 (if speedbar-file-key-map
840 (setq speedbar-file-key-map
(speedbar-make-specialized-keymap))
842 ;; Basic tree features
843 (define-key speedbar-file-key-map
"e" 'speedbar-edit-line
)
844 (define-key speedbar-file-key-map
"\C-m" 'speedbar-edit-line
)
845 (define-key speedbar-file-key-map
"+" 'speedbar-expand-line
)
846 (define-key speedbar-file-key-map
"=" 'speedbar-expand-line
)
847 (define-key speedbar-file-key-map
"-" 'speedbar-contract-line
)
849 (define-key speedbar-file-key-map
"[" 'speedbar-expand-line-descendants
)
850 (define-key speedbar-file-key-map
"]" 'speedbar-contract-line-descendants
)
852 (define-key speedbar-file-key-map
" " 'speedbar-toggle-line-expansion
)
854 ;; file based commands
855 (define-key speedbar-file-key-map
"U" 'speedbar-up-directory
)
856 (define-key speedbar-file-key-map
"I" 'speedbar-item-info
)
857 (define-key speedbar-file-key-map
"B" 'speedbar-item-byte-compile
)
858 (define-key speedbar-file-key-map
"L" 'speedbar-item-load
)
859 (define-key speedbar-file-key-map
"C" 'speedbar-item-copy
)
860 (define-key speedbar-file-key-map
"D" 'speedbar-item-delete
)
861 (define-key speedbar-file-key-map
"O" 'speedbar-item-object-delete
)
862 (define-key speedbar-file-key-map
"R" 'speedbar-item-rename
)
863 (define-key speedbar-file-key-map
"M" 'speedbar-create-directory
)
866 (defvar speedbar-easymenu-definition-base
869 ["Update" speedbar-refresh t
]
870 ["Auto Update" speedbar-toggle-updates
871 :active
(not speedbar-update-flag-disable
)
872 :style toggle
:selected speedbar-update-flag
])
873 (if (and (or (fboundp 'defimage
)
874 (fboundp 'make-image-specifier
))
875 (if (fboundp 'display-graphic-p
)
879 ["Use Images" speedbar-toggle-images
880 :style toggle
:selected speedbar-use-images
]))
882 "Base part of the speedbar menu.")
884 (defvar speedbar-easymenu-definition-special
885 '(["Edit Item On Line" speedbar-edit-line t
]
886 ["Show All Files" speedbar-toggle-show-all-files
887 :style toggle
:selected speedbar-show-unknown-files
]
888 ["Expand File Tags" speedbar-expand-line
889 (save-excursion (beginning-of-line)
890 (looking-at "[0-9]+: *.\\+. "))]
891 ["Flush Cache & Expand" speedbar-flush-expand-line
892 (save-excursion (beginning-of-line)
893 (looking-at "[0-9]+: *.\\+. "))]
894 ["Expand All Descendants" speedbar-expand-line-descendants
895 (save-excursion (beginning-of-line)
896 (looking-at "[0-9]+: *.\\+. ")) ]
897 ["Contract File Tags" speedbar-contract-line
898 (save-excursion (beginning-of-line)
899 (looking-at "[0-9]+: *.-. "))]
900 ; ["Sort Tags" speedbar-toggle-sorting
901 ; :style toggle :selected speedbar-sort-tags]
903 ["File/Tag Information" speedbar-item-info t
]
904 ["Load Lisp File" speedbar-item-load
907 (looking-at "[0-9]+: *\\[[+-]\\] .+\\(\\.el\\)\\( \\|$\\)"))]
908 ["Byte Compile File" speedbar-item-byte-compile
911 (looking-at "[0-9]+: *\\[[+-]\\] .+\\(\\.el\\)\\( \\|$\\)"))]
912 ["Copy File" speedbar-item-copy
913 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *\\["))]
914 ["Rename File" speedbar-item-rename
915 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
916 ["Create Directory" speedbar-create-directory
917 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
918 ["Delete File" speedbar-item-delete
919 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
920 ["Delete Object" speedbar-item-object-delete
921 (save-excursion (beginning-of-line)
922 (looking-at "[0-9]+: *\\[[+-]\\] [^ \n]+ \\*?[!#]$"))]
924 "Additional menu items while in file-mode.")
926 (defvar speedbar-easymenu-definition-trailer
928 (if (and (featurep 'custom
) (fboundp 'custom-declare-variable
))
929 (list ["Customize..." speedbar-customize t
]))
931 ["Close" dframe-close-frame t
]
932 ["Quit" delete-frame t
] ))
933 "Menu items appearing at the end of the speedbar menu.")
935 (defvar speedbar-desired-buffer nil
936 "Non-nil when speedbar is showing buttons specific to a special mode.
937 In this case it is the originating buffer.")
938 (defvar speedbar-buffer nil
939 "The buffer displaying the speedbar.")
940 (defvar speedbar-frame nil
941 "The frame displaying speedbar.")
942 (defvar speedbar-cached-frame nil
943 "The frame that was last created, then removed from the display.")
944 (defvar speedbar-full-text-cache nil
945 "The last open directory is saved in its entirety for ultra-fast switching.")
947 (defvar speedbar-last-selected-file nil
948 "The last file which was selected in speedbar buffer.")
950 (defvar speedbar-shown-directories nil
951 "Maintain list of directories simultaneously open in the current speedbar.")
953 (defvar speedbar-directory-contents-alist nil
954 "An association list of directories and their contents.
955 Each sublist was returned by `speedbar-file-lists'. This list is
956 maintained to speed up the refresh rate when switching between
959 (defvar speedbar-power-click nil
960 "Never set this by hand. Value is t when S-mouse activity occurs.")
965 (defalias 'speedbar-make-overlay
966 (if (featurep 'xemacs
) 'make-extent
'make-overlay
))
968 (defalias 'speedbar-overlay-put
969 (if (featurep 'xemacs
) 'set-extent-property
'overlay-put
))
971 (defalias 'speedbar-delete-overlay
972 (if (featurep 'xemacs
) 'delete-extent
'delete-overlay
))
974 (defalias 'speedbar-mode-line-update
975 (if (featurep 'xemacs
) 'redraw-modeline
'force-mode-line-update
))
977 ;;; Mode definitions/ user commands
981 (defalias 'speedbar
'speedbar-frame-mode
)
983 (defun speedbar-frame-mode (&optional arg
)
984 "Enable or disable speedbar. Positive ARG means turn on, negative turn off.
985 A nil ARG means toggle. Once the speedbar frame is activated, a buffer in
986 `speedbar-mode' will be displayed. Currently, only one speedbar is
988 `speedbar-before-popup-hook' is called before popping up the speedbar frame.
989 `speedbar-before-delete-hook' is called before the frame is deleted."
991 ;; Get the buffer to play with
992 (if (not (buffer-live-p speedbar-buffer
))
994 (setq speedbar-buffer
(get-buffer-create " SPEEDBAR"))
995 (set-buffer speedbar-buffer
)
997 ;; Do the frame thing
998 (dframe-frame-mode arg
1000 'speedbar-cached-frame
1003 #'speedbar-frame-mode
1004 (if (featurep 'xemacs
)
1005 (append speedbar-frame-plist
1006 ;; This is a hack to get speedbar to iconfiy
1007 ;; with the selected frame.
1008 (list 'parent
(selected-frame)))
1009 speedbar-frame-parameters
)
1010 speedbar-before-delete-hook
1011 speedbar-before-popup-hook
1012 speedbar-after-create-hook
)
1013 ;; Start up the timer
1014 (if (not speedbar-frame
)
1015 (speedbar-set-timer nil
)
1016 (speedbar-reconfigure-keymaps)
1017 (speedbar-update-contents)
1018 (speedbar-set-timer dframe-update-speed
)
1020 ;; Frame modifications
1021 (set (make-local-variable 'dframe-delete-frame-function
)
1022 'speedbar-handle-delete-frame
)
1024 (set (make-local-variable 'automatic-hscrolling
) nil
) ; Emacs 21
1025 ;; reset the selection variable
1026 (setq speedbar-last-selected-file nil
))
1028 (defun speedbar-frame-reposition-smartly ()
1029 "Reposition the speedbar frame to be next to the attached frame."
1030 (cond ((and (featurep 'xemacs
)
1031 (or (member 'left speedbar-frame-plist
)
1032 (member 'top speedbar-frame-plist
)))
1033 (dframe-reposition-frame
1035 (dframe-attached-frame speedbar-frame
)
1036 (cons (car (cdr (member 'left speedbar-frame-plist
)))
1037 (car (cdr (member 'top speedbar-frame-plist
)))))
1039 ((and (not (featurep 'xemacs
))
1040 (or (assoc 'left speedbar-frame-parameters
)
1041 (assoc 'top speedbar-frame-parameters
)))
1042 ;; if left/top were specified in the parameters, pass them
1043 ;; down to the reposition function
1044 (dframe-reposition-frame
1046 (dframe-attached-frame speedbar-frame
)
1047 (cons (cdr (assoc 'left speedbar-frame-parameters
))
1048 (cdr (assoc 'top speedbar-frame-parameters
))))
1051 (dframe-reposition-frame speedbar-frame
1052 (dframe-attached-frame speedbar-frame
)
1053 speedbar-default-position
))))
1055 (defsubst speedbar-current-frame
()
1056 "Return the frame to use for speedbar based on current context."
1057 (dframe-current-frame 'speedbar-frame
'speedbar-mode
))
1059 (defun speedbar-handle-delete-frame (e)
1060 "Handle a delete frame event E.
1061 If the deleted frame is the frame speedbar is attached to,
1062 we need to delete speedbar also."
1063 (when (and speedbar-frame
1064 (eq (car (car (cdr e
))) ;; frame to be deleted
1065 dframe-attached-frame
))
1066 (delete-frame speedbar-frame
)))
1069 (defun speedbar-get-focus ()
1070 "Change frame focus to or from the speedbar frame.
1071 If the selected frame is not speedbar, then speedbar frame is
1072 selected. If the speedbar frame is active, then select the attached frame."
1074 (speedbar-reset-scanners)
1075 (dframe-get-focus 'speedbar-frame
'speedbar-frame-mode
1076 (lambda () (let ((speedbar-update-flag t
))
1077 (speedbar-timer-fn)))))
1079 (defsubst speedbar-frame-width
()
1080 "Return the width of the speedbar frame in characters.
1081 Return nil if it doesn't exist."
1082 (frame-width speedbar-frame
))
1084 (defun speedbar-mode ()
1085 "Major mode for managing a display of directories and tags.
1086 \\<speedbar-key-map>
1087 The first line represents the default directory of the speedbar frame.
1088 Each directory segment is a button which jumps speedbar's default
1089 directory to that directory. Buttons are activated by clicking `\\[speedbar-click]'.
1090 In some situations using `\\[dframe-power-click]' is a `power click' which will
1091 rescan cached items, or pop up new frames.
1093 Each line starting with <+> represents a directory. Click on the <+>
1094 to insert the directory listing into the current tree. Click on the
1095 <-> to retract that list. Click on the directory name to go to that
1096 directory as the default.
1098 Each line starting with [+] is a file. If the variable
1099 `speedbar-show-unknown-files' is t, the lines starting with [?] are
1100 files which don't have imenu support, but are not expressly ignored.
1101 Files are completely ignored if they match `speedbar-file-unshown-regexp'
1102 which is generated from `completion-ignored-extensions'.
1104 Files with a `*' character after their name are files checked out of a
1105 version control system. (Currently only RCS is supported.) New
1106 version control systems can be added by examining the documentation
1107 for `speedbar-this-file-in-vc' and `speedbar-vc-check-dir-p'.
1109 Files with a `#' or `!' character after them are source files that
1110 have an object file associated with them. The `!' indicates that the
1111 files is out of date. You can control what source/object associations
1112 exist through the variable `speedbar-obj-alist'.
1114 Click on the [+] to display a list of tags from that file. Click on
1115 the [-] to retract the list. Click on the file name to edit the file
1116 in the attached frame.
1118 If you open tags, you might find a node starting with {+}, which is a
1119 category of tags. Click the {+} to expand the category. Jump-able
1120 tags start with >. Click the name of the tag to go to that position
1121 in the selected file.
1123 \\{speedbar-key-map}"
1126 (kill-all-local-variables)
1127 (setq major-mode
'speedbar-mode
)
1128 (setq mode-name
"Speedbar")
1129 (set-syntax-table speedbar-syntax-table
)
1130 (setq font-lock-keywords nil
) ;; no font-locking please
1131 (setq truncate-lines t
)
1132 (make-local-variable 'frame-title-format
)
1133 (setq frame-title-format
(concat "Speedbar " speedbar-version
))
1134 (setq case-fold-search nil
)
1135 (toggle-read-only 1)
1136 (speedbar-set-mode-line-format)
1137 ;; Add in our dframe hooks.
1138 (if speedbar-track-mouse-flag
1139 (setq dframe-track-mouse-function
#'speedbar-track-mouse
))
1140 (setq dframe-help-echo-function
#'speedbar-item-info
1141 dframe-mouse-click-function
#'speedbar-click
1142 dframe-mouse-position-function
#'speedbar-position-cursor-on-line
)
1143 (run-hooks 'speedbar-mode-hook
))
1146 (defmacro speedbar-message
(fmt &rest args
)
1147 "Like `message', but for use in the speedbar frame.
1148 Argument FMT is the format string, and ARGS are the arguments for message."
1149 `(dframe-message ,fmt
,@args
))
1151 (defsubst speedbar-y-or-n-p
(prompt &optional deleting
)
1152 "Like `y-or-n-p', but for use in the speedbar frame.
1153 Argument PROMPT is the prompt to use.
1154 Optional argument DELETING means this is a query that will delete something.
1155 The variable `speedbar-query-confirmation-method' can cause this to
1156 return true without a query."
1157 (or (and (not deleting
)
1158 (eq speedbar-query-confirmation-method
'none-but-delete
))
1159 (dframe-y-or-n-p prompt
)))
1161 (defsubst speedbar-select-attached-frame
()
1162 "Select the frame attached to this speedbar."
1163 (dframe-select-attached-frame (speedbar-current-frame)))
1165 ;; Backwards compatibility
1166 (defalias 'speedbar-with-attached-buffer
'dframe-with-attached-buffer
)
1167 (defalias 'speedbar-maybee-jump-to-attached-frame
'dframe-maybee-jump-to-attached-frame
)
1169 (defun speedbar-set-mode-line-format ()
1170 "Set the format of the mode line based on the current speedbar environment.
1171 This gives visual indications of what is up. It EXPECTS the speedbar
1172 frame and window to be the currently active frame and window."
1173 (if (and (frame-live-p (speedbar-current-frame))
1174 (or (not (featurep 'xemacs
))
1176 (specifier-instance has-modeline-p
)))
1179 (set-buffer speedbar-buffer
)
1180 (let* ((w (or (speedbar-frame-width) 20))
1183 (p3 (if speedbar-update-flag
"#" "!"))
1184 (p35 (capitalize speedbar-initial-expansion-list-name
))
1185 (blank (- w
(length p1
) (length p3
) (length p5
) (length p35
)
1186 (if line-number-mode
5 1)))
1188 (make-string (/ blank
2) ?
)
1191 (make-string (+ (/ blank
2) (% blank
2)) ?
)
1194 (if line-number-mode
1195 (list (concat p1 p2 p3
" " p35
) '(line-number-mode " %3l")
1197 (list (concat p1 p2 p3 p4 p5
)))))
1198 (if (not (equal mode-line-format tf
))
1200 (setq mode-line-format tf
)
1201 (speedbar-mode-line-update)))))))
1203 (defvar speedbar-previous-menu nil
1204 "The menu before the last `speedbar-reconfigure-keymaps' was called.")
1206 (defun speedbar-reconfigure-keymaps ()
1207 "Reconfigure the menu-bar in a speedbar frame.
1208 Different menu items are displayed depending on the current display mode
1209 and the existence of packages."
1211 speedbar-easymenu-definition-base
1212 (if speedbar-shown-directories
1213 ;; file display mode version
1214 (speedbar-initial-menu)
1216 (dframe-select-attached-frame speedbar-frame
)
1217 (eval (nth 1 (assoc speedbar-initial-expansion-list-name
1218 speedbar-initial-expansion-mode-alist
)))))
1219 ;; Dynamic menu stuff
1221 (list (cons "Displays"
1222 (let ((displays nil
)
1223 (alist speedbar-initial-expansion-mode-alist
))
1228 (capitalize (car (car alist
)))
1230 'speedbar-change-initial-expansion-list
1234 `(string= ,(car (car alist
))
1235 speedbar-initial-expansion-list-name
)
1238 (setq alist
(cdr alist
)))
1241 speedbar-easymenu-definition-trailer
))
1242 (localmap (save-excursion
1243 (let ((cf (selected-frame)))
1245 (dframe-select-attached-frame speedbar-frame
)
1246 (if (local-variable-p
1247 'speedbar-special-mode-key-map
1249 speedbar-special-mode-key-map
)
1250 (select-frame cf
))))))
1252 (set-buffer speedbar-buffer
)
1253 (use-local-map (or localmap
1254 (speedbar-initial-keymap)
1255 ;; This creates a small keymap we can glom the
1256 ;; menu adjustments into.
1257 (speedbar-make-specialized-keymap)))
1258 ;; Delete the old menu if applicable.
1259 (if speedbar-previous-menu
(easy-menu-remove speedbar-previous-menu
))
1260 (setq speedbar-previous-menu md
)
1261 ;; Now add the new menu
1262 (if (not (featurep 'xemacs
))
1263 (easy-menu-define speedbar-menu-map
(current-local-map)
1265 (easy-menu-add md
(current-local-map))
1267 (if (fboundp 'set-buffer-menubar
)
1268 (set-buffer-menubar (list md
)))))
1270 (run-hooks 'speedbar-reconfigure-keymaps-hook
)))
1273 ;;; User Input stuff
1275 (defun speedbar-customize ()
1276 "Customize speedbar using the Custom package."
1278 (let ((sf (selected-frame)))
1279 (dframe-select-attached-frame speedbar-frame
)
1280 (customize-group 'speedbar
)
1282 (dframe-maybee-jump-to-attached-frame))
1284 (defun speedbar-track-mouse (event)
1285 "For motion EVENT, display info about the current line."
1286 (if (not speedbar-track-mouse-flag
)
1289 (save-window-excursion
1292 (mouse-set-point event
)
1293 (if (eq major-mode
'speedbar-mode
)
1294 ;; XEmacs may let us get in here in other mode buffers.
1295 (speedbar-item-info)))
1296 (t (speedbar-message nil
)))))))
1298 (defun speedbar-show-info-under-mouse ()
1299 "Call the info function for the line under the mouse."
1300 (let ((pos (mouse-position))) ; we ignore event until I use it later.
1301 (if (equal (car pos
) speedbar-frame
)
1303 (save-window-excursion
1304 (apply 'set-mouse-position pos
)
1305 (speedbar-item-info))))))
1307 (defun speedbar-next (arg)
1308 "Move to the next ARGth line in a speedbar buffer."
1310 (forward-line (or arg
1))
1311 (speedbar-item-info)
1312 (speedbar-position-cursor-on-line))
1314 (defun speedbar-prev (arg)
1315 "Move to the previous ARGth line in a speedbar buffer."
1317 (speedbar-next (if arg
(- arg
) -
1)))
1319 (defun speedbar-restricted-move (arg)
1320 "Move to the next ARGth line in a speedbar buffer at the same depth.
1321 This means that movement is restricted to a subnode, and that siblings
1322 of intermediate nodes are skipped."
1323 (if (not (numberp arg
)) (signal 'wrong-type-argument
(list arg
'numberp
)))
1324 ;; First find the extent for which we are allowed to move.
1325 (let ((depth (save-excursion (beginning-of-line)
1326 (if (looking-at "[0-9]+:")
1327 (string-to-number (match-string 0))
1329 (crement (if (< arg
0) 1 -
1)) ; decrement or increment
1330 (lastmatch (point)))
1332 (forward-line (- crement
))
1333 (let ((subdepth (save-excursion (beginning-of-line)
1334 (if (looking-at "[0-9]+:")
1335 (string-to-number (match-string 0))
1337 (cond ((or (< subdepth depth
)
1338 (progn (end-of-line) (eobp))
1339 (progn (beginning-of-line) (bobp)))
1340 ;; We have reached the end of this block.
1341 (goto-char lastmatch
)
1343 (error "End of sub-list"))
1345 (setq lastmatch
(point)
1346 arg
(+ arg crement
))))))
1347 (speedbar-position-cursor-on-line)))
1349 (defun speedbar-restricted-next (arg)
1350 "Move to the next ARGth line in a speedbar buffer at the same depth.
1351 This means that movement is restricted to a subnode, and that siblings
1352 of intermediate nodes are skipped."
1354 (speedbar-restricted-move (or arg
1))
1355 (speedbar-item-info))
1357 (defun speedbar-restricted-prev (arg)
1358 "Move to the previous ARGth line in a speedbar buffer at the same depth.
1359 This means that movement is restricted to a subnode, and that siblings
1360 of intermediate nodes are skipped."
1362 (speedbar-restricted-move (if arg
(- arg
) -
1))
1363 (speedbar-item-info))
1365 (defun speedbar-navigate-list (arg)
1366 "Move across ARG groups of similarly typed items in speedbar.
1367 Stop on the first line of the next type of item, or on the last or first item
1368 if we reach a buffer boundary."
1371 (if (looking-at "[0-9]+: *[[<{][-+?][]>}] ")
1372 (let ((str (regexp-quote (match-string 0))))
1373 (while (looking-at str
)
1374 (speedbar-restricted-move arg
)
1375 (beginning-of-line))))
1376 (speedbar-position-cursor-on-line))
1378 (defun speedbar-forward-list ()
1379 "Move forward over the current list.
1380 A LIST in speedbar is a group of similarly typed items, such as directories,
1381 files, or the directory button."
1383 (speedbar-navigate-list 1)
1384 (speedbar-item-info))
1386 (defun speedbar-backward-list ()
1387 "Move backward over the current list.
1388 A LIST in speedbar is a group of similarly typed items, such as directories,
1389 files, or the directory button."
1391 (speedbar-navigate-list -
1)
1392 (speedbar-item-info))
1394 (defun speedbar-scroll-up (&optional arg
)
1395 "Page down one screen-full of the speedbar, or ARG lines."
1398 (speedbar-position-cursor-on-line))
1400 (defun speedbar-scroll-down (&optional arg
)
1401 "Page up one screen-full of the speedbar, or ARG lines."
1404 (speedbar-position-cursor-on-line))
1406 (defun speedbar-up-directory ()
1407 "Keyboard accelerator for moving the default directory up one.
1408 Assumes that the current buffer is the speedbar buffer."
1410 (setq default-directory
(expand-file-name (concat default-directory
"../")))
1411 (speedbar-update-contents))
1413 ;;; Speedbar file activity (aka creeping featurism)
1415 (defun speedbar-refresh (&optional arg
)
1416 "Refresh the current speedbar display, disposing of any cached data.
1417 Argument ARG represents to force a refresh past any caches that may exist."
1419 (let ((dl speedbar-shown-directories
)
1420 (dframe-power-click arg
)
1422 ;; We need to hack something so this works in detached frames.
1424 (adelete 'speedbar-directory-contents-alist
(car dl
))
1426 (if (<= 1 speedbar-verbosity-level
)
1427 (speedbar-message "Refreshing speedbar..."))
1428 (speedbar-update-contents)
1429 (speedbar-stealthy-updates)
1430 ;; Reset the timer in case it got really hosed for some reason...
1431 (speedbar-set-timer dframe-update-speed
)
1432 (if (<= 1 speedbar-verbosity-level
)
1433 (speedbar-message "Refreshing speedbar...done"))))
1435 (defun speedbar-item-load ()
1436 "Load the item under the cursor or mouse if it is a Lisp file."
1438 (let ((f (speedbar-line-file)))
1439 (if (and (file-exists-p f
) (string-match "\\.el\\'" f
))
1440 (if (and (file-exists-p (concat f
"c"))
1441 (speedbar-y-or-n-p (format "Load %sc? " f
)))
1442 ;; If the compiled version exists, load that instead...
1443 (load-file (concat f
"c"))
1445 (error "Not a loadable file"))))
1447 (defun speedbar-item-byte-compile ()
1448 "Byte compile the item under the cursor or mouse if it is a Lisp file."
1450 (let ((f (speedbar-line-file))
1451 (sf (selected-frame)))
1452 (if (and (file-exists-p f
) (string-match "\\.el\\'" f
))
1454 (dframe-select-attached-frame speedbar-frame
)
1455 (byte-compile-file f nil
)
1457 (speedbar-reset-scanners)))
1460 (defun speedbar-mouse-item-info (event)
1461 "Provide information about what the user clicked on.
1462 This should be bound to a mouse EVENT."
1464 (mouse-set-point event
)
1465 (speedbar-item-info))
1467 (defun speedbar-generic-item-info ()
1468 "Attempt to derive, and then display information about this line item.
1469 File style information is displayed with `speedbar-item-info'."
1472 ;; Skip invisible number info.
1473 (if (looking-at "\\([0-9]+\\):") (goto-char (match-end 0)))
1474 ;; Skip items in "folder" type text characters.
1475 (if (looking-at "\\s-*[[<({].[]>)}] ") (goto-char (match-end 0)))
1477 (speedbar-message "Text: %s" (buffer-substring-no-properties
1478 (point) (progn (end-of-line) (point))))))
1480 (defun speedbar-item-info ()
1481 "Display info in the minibuffer about the button the mouse is over.
1482 This function can be replaced in `speedbar-mode-functions-list' as
1483 `speedbar-item-info'."
1485 (let (message-log-max)
1486 (funcall (or (speedbar-fetch-replacement-function 'speedbar-item-info
)
1487 'speedbar-generic-item-info
))))
1489 (defun speedbar-item-info-file-helper (&optional filename
)
1490 "Display info about a file that is on the current line.
1491 Return nil if not applicable. If FILENAME, then use that
1492 instead of reading it from the speedbar buffer."
1493 (let* ((item (or filename
(speedbar-line-file)))
1494 (attr (if item
(file-attributes item
) nil
)))
1495 (if (and item attr
) (speedbar-message "%s %-6d %s" (nth 8 attr
)
1499 (defun speedbar-item-info-tag-helper ()
1500 "Display info about a tag that is on the current line.
1501 Return nil if not applicable."
1504 (if (re-search-forward " [-+=]?> \\([^\n]+\\)"
1505 (save-excursion(end-of-line)(point)) t
)
1506 (let* ((tag (match-string 1))
1507 (attr (speedbar-line-token))
1509 (semantic-tagged (if (fboundp 'semantic-tag-p
)
1510 (semantic-tag-p attr
))))
1514 (when (and (semantic-tag-overlay attr
)
1515 (semantic-tag-buffer attr
))
1516 (set-buffer (semantic-tag-buffer attr
)))
1518 (funcall semantic-sb-info-format-tag-function attr
)
1520 (looking-at "\\([0-9]+\\):")
1521 (setq item
(file-name-nondirectory (speedbar-line-directory)))
1522 (speedbar-message "Tag: %s in %s" tag item
)))
1523 (if (re-search-forward "{[+-]} \\([^\n]+\\)$"
1524 (save-excursion(end-of-line)(point)) t
)
1525 (speedbar-message "Group of tags \"%s\"" (match-string 1))
1526 (if (re-search-forward " [+-]?[()|@] \\([^\n]+\\)$" nil t
)
1527 (let* ((detailtext (match-string 1))
1528 (detail (or (speedbar-line-token) detailtext
))
1529 (parent (save-excursion
1531 (let ((dep (if (looking-at "[0-9]+:")
1532 (1- (string-to-number (match-string 0)))
1534 (re-search-backward (concat "^"
1538 (if (looking-at "[0-9]+: +[-+=>]> \\([^\n]+\\)$")
1539 (speedbar-line-token)
1541 (if (featurep 'semantic
)
1543 (if (semantic-tag-p detail
)
1545 (funcall semantic-sb-info-format-tag-function detail parent
))
1547 (speedbar-message "Detail: %s of tag %s" detail
1548 (if (semantic-tag-p parent
)
1549 (semantic-format-tag-name parent nil t
)
1551 (speedbar-message "Detail: %s" detail
))))
1552 ;; Not using `semantic':
1554 (speedbar-message "Detail: %s of tag %s" detail parent
)
1555 (speedbar-message "Detail: %s" detail
))))
1558 (defun speedbar-files-item-info ()
1559 "Display info in the minibuffer about the button the mouse is over."
1560 (if (not speedbar-shown-directories
)
1561 (speedbar-generic-item-info)
1562 (or (speedbar-item-info-file-helper)
1563 (speedbar-item-info-tag-helper)
1564 (speedbar-generic-item-info))))
1566 (defun speedbar-item-copy ()
1567 "Copy the item under the cursor.
1568 Files can be copied to new names or places."
1570 (let ((f (speedbar-line-file)))
1571 (if (not f
) (error "Not a file"))
1572 (if (file-directory-p f
)
1573 (error "Cannot copy directory")
1574 (let* ((rt (read-file-name (format "Copy %s to: "
1575 (file-name-nondirectory f
))
1576 (file-name-directory f
)))
1577 (refresh (member (expand-file-name (file-name-directory rt
))
1578 speedbar-shown-directories
)))
1579 ;; Create the right file name part
1580 (if (file-directory-p rt
)
1582 (concat (expand-file-name rt
)
1583 (if (string-match "[/\\]$" rt
) "" "/")
1584 (file-name-nondirectory f
))))
1585 (if (or (not (file-exists-p rt
))
1586 (speedbar-y-or-n-p (format "Overwrite %s with %s? " rt f
)
1589 (copy-file f rt t t
)
1590 ;; refresh display if the new place is currently displayed.
1594 (if (not (speedbar-goto-this-file rt
))
1595 (speedbar-goto-this-file f
))))
1598 (defun speedbar-item-rename ()
1599 "Rename the item under the cursor or mouse.
1600 Files can be renamed to new names or moved to new directories."
1602 (let ((f (speedbar-line-file)))
1604 (let* ((rt (read-file-name (format "Rename %s to: "
1605 (file-name-nondirectory f
))
1606 (file-name-directory f
)))
1607 (refresh (member (expand-file-name (file-name-directory rt
))
1608 speedbar-shown-directories
)))
1609 ;; Create the right file name part
1610 (if (file-directory-p rt
)
1612 (concat (expand-file-name rt
)
1613 (if (string-match "[/\\]\\'" rt
) "" "/")
1614 (file-name-nondirectory f
))))
1615 (if (or (not (file-exists-p rt
))
1616 (speedbar-y-or-n-p (format "Overwrite %s with %s? " rt f
)
1619 (rename-file f rt t
)
1620 ;; refresh display if the new place is currently displayed.
1624 (speedbar-goto-this-file rt
)
1626 (error "Not a file"))))
1628 (defun speedbar-create-directory ()
1629 "Create a directory in speedbar."
1631 (let ((f (speedbar-line-file)))
1633 (let* ((basedir (file-name-directory f
))
1634 (nd (read-file-name "Create directory: "
1636 ;; Make the directory
1637 (make-directory nd t
)
1639 (speedbar-goto-this-file nd
)
1641 (error "Not a file"))))
1643 (defun speedbar-item-delete ()
1644 "Delete the item under the cursor. Files are removed from disk."
1646 (let ((f (speedbar-line-file)))
1647 (if (not f
) (error "Not a file"))
1648 (if (speedbar-y-or-n-p (format "Delete %s? " f
) t
)
1650 (if (file-directory-p f
)
1651 (delete-directory f
)
1653 (speedbar-message "Okie dokie..")
1660 (defun speedbar-item-object-delete ()
1661 "Delete the object associated from the item under the cursor.
1662 The file is removed from disk. The object is determined from the
1663 variable `speedbar-obj-alist'."
1665 (let* ((f (speedbar-line-file))
1667 (oa speedbar-obj-alist
))
1668 (if (not f
) (error "Not a file"))
1669 (while (and oa
(not (string-match (car (car oa
)) f
)))
1671 (setq obj
(concat (file-name-sans-extension f
) (cdr (car oa
))))
1672 (if (and oa
(file-exists-p obj
)
1673 (speedbar-y-or-n-p (format "Delete %s? " obj
) t
))
1676 (speedbar-reset-scanners)))))
1678 (defun speedbar-enable-update ()
1679 "Enable automatic updating in speedbar via timers."
1681 (setq speedbar-update-flag t
)
1682 (speedbar-set-mode-line-format)
1683 (speedbar-set-timer dframe-update-speed
))
1685 (defun speedbar-disable-update ()
1686 "Disable automatic updating and stop consuming resources."
1688 (setq speedbar-update-flag nil
)
1689 (speedbar-set-mode-line-format)
1690 (speedbar-set-timer nil
))
1692 (defun speedbar-toggle-updates ()
1693 "Toggle automatic update for the speedbar frame."
1695 (if speedbar-update-flag
1696 (speedbar-disable-update)
1697 (speedbar-enable-update)))
1699 (defun speedbar-toggle-images ()
1700 "Toggle use of images in the speedbar frame.
1701 Images are not available in Emacs 20 or earlier."
1703 (setq speedbar-use-images
(not speedbar-use-images
))
1706 (defun speedbar-toggle-sorting ()
1707 "Toggle tag sorting."
1709 (setq speedbar-sort-tags
(not speedbar-sort-tags
)))
1711 (defun speedbar-toggle-show-all-files ()
1712 "Toggle display of files speedbar can not tag."
1714 (setq speedbar-show-unknown-files
(not speedbar-show-unknown-files
))
1717 (defmacro speedbar-with-writable
(&rest forms
)
1718 "Allow the buffer to be writable and evaluate FORMS."
1719 (list 'let
'((inhibit-read-only t
))
1720 (cons 'progn forms
)))
1721 (put 'speedbar-with-writable
'lisp-indent-function
0)
1723 (defun speedbar-insert-button (text face mouse function
1724 &optional token prevline
)
1725 "Insert TEXT as the next logical speedbar button.
1726 FACE is the face to put on the button, MOUSE is the highlight face to use.
1727 When the user clicks on TEXT, FUNCTION is called with the TOKEN parameter.
1728 This function assumes that the current buffer is the speedbar buffer.
1729 If PREVLINE, then put this button on the previous line.
1731 This is a convenience function for special modes that create their own
1732 specialized speedbar displays."
1733 (goto-char (point-max))
1734 (let ((start (point)))
1735 (if (/= (current-column) 0) (insert "\n"))
1736 (put-text-property start
(point) 'invisible nil
))
1737 (if prevline
(progn (delete-char -
1)
1738 (insert " ") ;back up if desired...
1739 (put-text-property (1- (point)) (point) 'invisible nil
)))
1740 (let ((start (point)))
1742 (speedbar-make-button start
(point) face mouse function token
))
1743 (let ((start (point)))
1745 (add-text-properties
1746 start
(point) '(face nil invisible nil mouse-face nil
))))
1748 (defun speedbar-insert-separator (text)
1749 "Insert a separation label of TEXT.
1750 Separators are not active, have no labels, depth, or actions."
1751 (if speedbar-use-images
1752 (let ((start (point)))
1754 (speedbar-insert-image-button-maybe start
2)))
1755 (let ((start (point)))
1757 (speedbar-make-button start
(point)
1758 'speedbar-separator-face
1761 (defun speedbar-make-button (start end face mouse function
&optional token
)
1762 "Create a button from START to END, with FACE as the display face.
1763 MOUSE is the mouse face. When this button is clicked on FUNCTION
1764 will be run with the TOKEN parameter (any Lisp object). If FACE
1765 is t use the text properties of the string that is passed as an
1768 (put-text-property start end
'face face
))
1769 (add-text-properties
1770 start end
`(mouse-face ,mouse invisible nil
1771 speedbar-text
,(buffer-substring-no-properties start end
)))
1772 (if speedbar-use-tool-tips-flag
1773 (put-text-property start end
'help-echo
#'dframe-help-echo
))
1774 (if function
(put-text-property start end
'speedbar-function function
))
1775 (if token
(put-text-property start end
'speedbar-token token
))
1776 ;; So far the only text we have is less that 3 chars.
1777 (if (<= (- end start
) 3)
1778 (speedbar-insert-image-button-maybe start
(- end start
)))
1781 ;;; Initial Expansion list management
1783 (defun speedbar-initial-expansion-list ()
1784 "Return the current default expansion list.
1785 This is based on `speedbar-initial-expansion-list-name' referencing
1786 `speedbar-initial-expansion-mode-alist'."
1787 ;; cdr1 - name, cdr2 - menu
1788 (cdr (cdr (cdr (assoc speedbar-initial-expansion-list-name
1789 speedbar-initial-expansion-mode-alist
)))))
1791 (defun speedbar-initial-menu ()
1792 "Return the current default menu data.
1793 This is based on `speedbar-initial-expansion-list-name' referencing
1794 `speedbar-initial-expansion-mode-alist'."
1796 (car (cdr (assoc speedbar-initial-expansion-list-name
1797 speedbar-initial-expansion-mode-alist
)))))
1799 (defun speedbar-initial-keymap ()
1800 "Return the current default menu data.
1801 This is based on `speedbar-initial-expansion-list-name' referencing
1802 `speedbar-initial-expansion-mode-alist'."
1804 (car (cdr (cdr (assoc speedbar-initial-expansion-list-name
1805 speedbar-initial-expansion-mode-alist
))))))
1807 (defun speedbar-initial-stealthy-functions ()
1808 "Return a list of functions to call stealthily.
1809 This is based on `speedbar-initial-expansion-list-name' referencing
1810 `speedbar-stealthy-function-list'."
1811 (cdr (assoc speedbar-initial-expansion-list-name
1812 speedbar-stealthy-function-list
)))
1814 (defun speedbar-add-expansion-list (new-list)
1815 "Add NEW-LIST to the list of expansion lists."
1816 (add-to-list 'speedbar-initial-expansion-mode-alist new-list
))
1818 (defun speedbar-change-initial-expansion-list (new-default)
1819 "Change speedbar's default expansion list to NEW-DEFAULT."
1822 (completing-read (format "Speedbar Mode (default %s): "
1823 speedbar-previously-used-expansion-list-name
)
1824 speedbar-initial-expansion-mode-alist
1826 speedbar-previously-used-expansion-list-name
)))
1827 (setq speedbar-previously-used-expansion-list-name
1828 speedbar-initial-expansion-list-name
1829 speedbar-initial-expansion-list-name new-default
)
1830 (if (and (speedbar-current-frame) (frame-live-p (speedbar-current-frame)))
1833 (speedbar-reconfigure-keymaps))))
1835 (defun speedbar-fetch-replacement-function (function)
1836 "Return a current mode-specific replacement for function, or nil.
1837 Scans `speedbar-mode-functions-list' first for the current mode, then
1839 (cdr (assoc function
1840 (cdr (assoc speedbar-initial-expansion-list-name
1841 speedbar-mode-functions-list
)))))
1843 (defun speedbar-add-mode-functions-list (new-list)
1844 "Add NEW-LIST to the list of mode functions.
1845 See `speedbar-mode-functions-list' for details."
1846 (add-to-list 'speedbar-mode-functions-list new-list
))
1849 ;;; Special speedbar display management
1851 (defun speedbar-maybe-add-localized-support (buffer)
1852 "Quick check function called on BUFFERs by the speedbar timer function.
1853 Maintains the value of local variables which control speedbar's use
1854 of the special mode functions."
1855 (or speedbar-special-mode-expansion-list
1856 (speedbar-add-localized-speedbar-support buffer
)))
1858 (defun speedbar-add-localized-speedbar-support (buffer)
1859 "Add localized speedbar support to BUFFER's mode if it is available."
1860 (interactive "bBuffer: ")
1861 (if (stringp buffer
) (setq buffer
(get-buffer buffer
)))
1862 (if (not (buffer-live-p buffer
))
1867 (let ((ms (symbol-name major-mode
)) v
)
1868 (if (not (string-match "-mode$" ms
))
1869 nil
;; do nothing to broken mode
1870 (setq ms
(substring ms
0 (match-beginning 0)))
1871 (setq v
(intern-soft (concat ms
"-speedbar-buttons")))
1872 (make-local-variable 'speedbar-special-mode-expansion-list
)
1874 (setq speedbar-special-mode-expansion-list t
)
1875 ;; If it is autoloaded, we need to load it now so that
1876 ;; we have access to the varialbe -speedbar-menu-items.
1877 ;; Is this XEmacs safe?
1878 (let ((sf (symbol-function v
)))
1879 (if (and (listp sf
) (eq (car sf
) 'autoload
))
1880 (load-library (car (cdr sf
)))))
1881 (setq speedbar-special-mode-expansion-list
(list v
))
1882 (setq v
(intern-soft (concat ms
"-speedbar-key-map")))
1884 nil
;; don't add special keymap
1885 (make-local-variable 'speedbar-special-mode-key-map
)
1886 (setq speedbar-special-mode-key-map
1888 (setq v
(intern-soft (concat ms
"-speedbar-menu-items")))
1890 nil
;; don't add special menus
1891 (make-local-variable 'speedbar-easymenu-definition-special
)
1892 (setq speedbar-easymenu-definition-special
1896 (defun speedbar-remove-localized-speedbar-support (buffer)
1897 "Remove any traces that BUFFER supports speedbar in a specialized way."
1900 (kill-local-variable 'speedbar-special-mode-expansion-list
)
1901 (kill-local-variable 'speedbar-special-mode-key-map
)
1902 (kill-local-variable 'speedbar-easymenu-definition-special
)))
1904 ;;; File button management
1906 (defun speedbar-file-lists (directory)
1907 "Create file lists for DIRECTORY.
1908 The car is the list of directories, the cdr is list of files not
1909 matching ignored headers. Cache any directory files found in
1910 `speedbar-directory-contents-alist' and use that cache before scanning
1912 (setq directory
(expand-file-name directory
))
1913 ;; If in powerclick mode, then the directory we are getting
1914 ;; should be rescanned.
1915 (if dframe-power-click
1916 (adelete 'speedbar-directory-contents-alist directory
))
1917 ;; find the directory, either in the cache, or build it.
1918 (or (cdr-safe (assoc directory speedbar-directory-contents-alist
))
1919 (let ((default-directory directory
)
1920 (dir (directory-files directory nil
))
1925 (or (string-match speedbar-file-unshown-regexp
(car dir
))
1926 (member (car dir
) vc-directory-exclusion-list
)
1927 (string-match speedbar-directory-unshown-regexp
(car dir
))))
1928 (if (file-directory-p (car dir
))
1929 (setq dirs
(cons (car dir
) dirs
))
1930 (setq files
(cons (car dir
) files
))))
1931 (setq dir
(cdr dir
)))
1932 (let ((nl (cons (nreverse dirs
) (list (nreverse files
)))))
1933 (aput 'speedbar-directory-contents-alist directory nl
)
1937 (defun speedbar-directory-buttons (directory index
)
1938 "Insert a single button group at point for DIRECTORY.
1939 Each directory part is a different button. If part of the directory
1940 matches the user directory ~, then it is replaced with a ~.
1941 INDEX is not used, but is required by the caller."
1942 (let* ((tilde (expand-file-name "~/"))
1943 (dd (expand-file-name directory
))
1944 (junk (string-match (regexp-quote tilde
) dd
))
1946 (concat "~/" (substring dd
(match-end 0)))
1949 (if (string-match "^~[/\\]?\\'" displayme
) (setq displayme tilde
))
1953 (while (re-search-forward "\\([^/\\]+\\)[/\\]" nil t
)
1954 (speedbar-make-button (match-beginning 1) (match-end 1)
1955 'speedbar-directory-face
1956 'speedbar-highlight-face
1957 'speedbar-directory-buttons-follow
1958 (if (and (= (match-beginning 1) p
)
1959 (not (char-equal (char-after (+ p
1)) ?
:)))
1960 (expand-file-name "~/") ;the tilde
1961 (buffer-substring-no-properties
1963 ;; Nuke the beginning of the directory if it's too long...
1964 (cond ((eq speedbar-directory-button-trim-method
'span
)
1966 (let ((ww (or (speedbar-frame-width) 20)))
1967 (move-to-column ww nil
)
1968 (while (>= (current-column) ww
)
1969 (re-search-backward "[/\\]" nil t
)
1970 (if (<= (current-column) 2)
1972 (re-search-forward "[/\\]" nil t
)
1973 (if (< (current-column) 4)
1974 (re-search-forward "[/\\]" nil t
))
1976 (if (looking-at "[/\\]?$")
1979 (move-to-column ww nil
)))))
1980 ((eq speedbar-directory-button-trim-method
'trim
)
1982 (let ((ww (or (speedbar-frame-width) 20))
1983 (tl (current-column)))
1986 (move-to-column (- tl ww
))
1987 (if (re-search-backward "[/\\]" nil t
)
1989 (delete-region (point-min) (point))
1993 (if (string-match "\\`[/\\][^/\\]+[/\\]\\'" displayme
)
1998 (speedbar-make-button p
(point)
1999 'speedbar-directory-face
2000 'speedbar-highlight-face
2001 'speedbar-directory-buttons-follow
2004 (insert-char ?
\n 1 nil
)))
2006 (defun speedbar-make-tag-line (exp-button-type
2007 exp-button-char exp-button-function
2009 tag-button tag-button-function tag-button-data
2010 tag-button-face depth
)
2011 "Create a tag line with EXP-BUTTON-TYPE for the small expansion button.
2012 This is the button that expands or contracts a node (if applicable),
2013 and EXP-BUTTON-CHAR the character in it (+, -, ?, etc). EXP-BUTTON-FUNCTION
2014 is the function to call if it's clicked on. Button types are
2015 'bracket, 'angle, 'curly, 'expandtag, 'statictag, t, or nil.
2016 EXP-BUTTON-DATA is extra data attached to the text forming the expansion
2019 Next, TAG-BUTTON is the text of the tag. TAG-BUTTON-FUNCTION is the
2020 function to call if clicked on, and TAG-BUTTON-DATA is the data to
2021 attach to the text field (such a tag positioning, etc).
2022 TAG-BUTTON-FACE is a face used for this type of tag.
2024 Lastly, DEPTH shows the depth of expansion.
2026 This function assumes that the cursor is in the speedbar window at the
2027 position to insert a new item, and that the new item will end with a CR."
2028 (let ((start (point))
2030 (insert (int-to-string depth
) ":")
2032 (depthspacesize (* depth speedbar-indentation-width
)))
2033 (put-text-property start end
'invisible t
)
2034 (insert-char ? depthspacesize nil
)
2035 (put-text-property (- (point) depthspacesize
) (point) 'invisible nil
)
2036 (let* ((exp-button (cond ((eq exp-button-type
'bracket
) "[%c]")
2037 ((eq exp-button-type
'angle
) "<%c>")
2038 ((eq exp-button-type
'curly
) "{%c}")
2039 ((eq exp-button-type
'expandtag
) " %c>")
2040 ((eq exp-button-type
'statictag
) " =>")
2042 (buttxt (format exp-button exp-button-char
))
2044 (end (progn (insert buttxt
) (point)))
2045 (bf (if (and exp-button-type
(not (eq exp-button-type
'statictag
)))
2046 'speedbar-button-face nil
))
2047 (mf (if exp-button-function
'speedbar-highlight-face nil
))
2049 (speedbar-make-button start end bf mf exp-button-function exp-button-data
)
2050 (if speedbar-hide-button-brackets-flag
2052 (put-text-property start
(1+ start
) 'invisible t
)
2053 (put-text-property end
(1- end
) 'invisible t
)))
2055 (insert-char ?
1 nil
)
2056 (put-text-property (1- (point)) (point) 'invisible nil
)
2057 (let ((start (point))
2058 (end (progn (insert tag-button
) (point))))
2059 (insert-char ?
\n 1 nil
)
2060 (put-text-property (1- (point)) (point) 'invisible nil
)
2061 (speedbar-make-button start end tag-button-face
2062 (if tag-button-function
'speedbar-highlight-face nil
)
2063 tag-button-function tag-button-data
))
2066 (defun speedbar-change-expand-button-char (char)
2067 "Change the expansion button character to CHAR for the current line."
2070 (if (re-search-forward ":\\s-*.\\([-+?]\\)" (save-excursion (end-of-line)
2072 (speedbar-with-writable
2073 (goto-char (match-end 1))
2074 (insert-char char
1 t
)
2077 ;;(put-text-property (point) (1- (point)) 'invisible nil)
2078 ;; make sure we fix the image on the text here.
2079 (speedbar-insert-image-button-maybe (- (point) 1) 3)))))
2082 ;;; Build button lists
2084 (defun speedbar-insert-files-at-point (files level
)
2085 "Insert list of FILES starting at point, and indenting all files to LEVEL.
2086 Tag expandable items with a +, otherwise a ?. Don't highlight ? as we
2087 don't know how to manage them. The input parameter FILES is a cons
2088 cell of the form ( 'DIRLIST . 'FILELIST )."
2089 ;; Start inserting all the directories
2090 (let ((dirs (car files
)))
2092 (speedbar-make-tag-line 'angle ?
+ 'speedbar-dired
(car dirs
)
2093 (car dirs
) 'speedbar-dir-follow nil
2094 'speedbar-directory-face level
)
2095 (setq dirs
(cdr dirs
))))
2096 (let ((lst (car (cdr files
)))
2097 (case-fold-search t
))
2099 (let* ((known (string-match speedbar-file-regexp
(car lst
)))
2100 (expchar (if known ?
+ ??
))
2101 (fn (if known
'speedbar-tag-file nil
)))
2102 (if (or speedbar-show-unknown-files
(/= expchar ??
))
2103 (speedbar-make-tag-line 'bracket expchar fn
(car lst
)
2104 (car lst
) 'speedbar-find-file nil
2105 'speedbar-file-face level
)))
2106 (setq lst
(cdr lst
)))))
2108 (defun speedbar-default-directory-list (directory index
)
2109 "Insert files for DIRECTORY with level INDEX at point."
2110 (speedbar-insert-files-at-point
2111 (speedbar-file-lists directory
) index
)
2112 (speedbar-reset-scanners)
2114 ;; If the shown files variable has extra directories, then
2115 ;; it is our responsibility to redraw them all
2116 ;; Luckilly, the nature of inserting items into this list means
2117 ;; that by reversing it, we can easilly go in the right order
2118 (let ((sf (cdr (reverse speedbar-shown-directories
))))
2119 (setq speedbar-shown-directories
2120 (list (expand-file-name default-directory
)))
2121 ;; exand them all as we find them
2123 (if (speedbar-goto-this-file (car sf
))
2126 (if (looking-at "[0-9]+:[ ]*<")
2128 (goto-char (match-end 0))
2129 (speedbar-do-function-pointer)))))
2132 ;;; Generic List support
2134 ;; Generic lists are hierarchies of tags which we may need to permute
2135 ;; in order to make it look nice.
2137 ;; A generic list is of the form:
2138 ;; ( ("name" . marker-or-number) <-- one tag at this level
2139 ;; ("name" ("name" . mon) ("name" . mon) ) <-- one group of tags
2140 ;; ("name" mon ("name" . mon) ) <-- group w/ a position and tags
2141 (defun speedbar-generic-list-group-p (sublst)
2142 "Non-nil if SUBLST is a group.
2143 Groups may optionally contain a position."
2144 (and (stringp (car-safe sublst
))
2145 (or (and (listp (cdr-safe sublst
))
2146 (or (speedbar-generic-list-tag-p (car-safe (cdr-safe sublst
)))
2147 (speedbar-generic-list-group-p (car-safe (cdr-safe sublst
))
2149 (and (number-or-marker-p (car-safe (cdr-safe sublst
)))
2150 (listp (cdr-safe (cdr-safe sublst
)))
2151 (speedbar-generic-list-tag-p
2152 (car-safe (cdr-safe (cdr-safe sublst
)))))
2155 (defun speedbar-generic-list-positioned-group-p (sublst)
2156 "Non-nil if SUBLST is a group with a position."
2157 (and (stringp (car-safe sublst
))
2158 (number-or-marker-p (car-safe (cdr-safe sublst
)))
2159 (listp (cdr-safe (cdr-safe sublst
)))
2160 (let ((rest (car-safe (cdr-safe (cdr-safe sublst
)))))
2161 (or (speedbar-generic-list-tag-p rest
)
2162 (speedbar-generic-list-group-p rest
)
2163 (speedbar-generic-list-positioned-group-p rest
)
2166 (defun speedbar-generic-list-tag-p (sublst)
2167 "Non-nil if SUBLST is a tag."
2168 (and (stringp (car-safe sublst
))
2169 (or (and (number-or-marker-p (cdr-safe sublst
))
2170 (not (cdr-safe (cdr-safe sublst
))))
2171 ;; For semantic/bovine items, this is needed
2172 (symbolp (car-safe (cdr-safe sublst
))))
2175 (defun speedbar-sort-tag-hierarchy (lst)
2176 "Sort all elements of tag hierarchy LST."
2177 (sort (copy-alist lst
)
2178 (lambda (a b
) (string< (car a
) (car b
)))))
2180 (defun speedbar-try-completion (string alist
)
2181 "A wrapper for `try-completion'.
2182 Passes STRING and ALIST to `try-completion' if ALIST
2184 (if (and (consp alist
)
2185 (listp (car alist
)) (stringp (car (car alist
))))
2186 (try-completion string alist
)
2189 (defun speedbar-prefix-group-tag-hierarchy (lst)
2190 "Prefix group names for tag hierarchy LST."
2195 (short-group-list nil
)
2196 (short-start-name nil
)
2197 (short-end-name nil
)
2198 (num-shorts-grouped 0)
2199 (bins (make-vector 256 nil
))
2201 (if (<= (length lst
) speedbar-tag-regroup-maximum-length
)
2202 ;; Do nothing. Too short to bother with.
2204 ;; Break out sub-lists
2206 (if (speedbar-generic-list-group-p (car-safe lst
))
2207 (setq newlst
(cons (car lst
) newlst
))
2208 (setq sublst
(cons (car lst
) sublst
)))
2209 (setq lst
(cdr lst
)))
2210 ;; Reverse newlst because it was made backwards.
2211 ;; Sublist doesn't need reversing because the act
2212 ;; of binning things will reverse it for us.
2213 (setq newlst
(nreverse newlst
)
2215 ;; Now, first find out how long our list is. Never let a
2216 ;; list get-shorter than our minimum.
2217 (if (<= (length sublst
) speedbar-tag-split-minimum-length
)
2218 (setq work-list sublst
)
2219 (setq diff-idx
(length (speedbar-try-completion "" sublst
)))
2220 ;; Sort the whole list into bins.
2222 (let ((e (car sublst
))
2223 (s (car (car sublst
))))
2224 (cond ((<= (length s
) diff-idx
)
2225 ;; 0 storage bin for shorty.
2226 (aset bins
0 (cons e
(aref bins
0))))
2228 ;; stuff into a bin based on ascii value at diff
2229 (aset bins
(aref s diff-idx
)
2230 (cons e
(aref bins
(aref s diff-idx
)))))))
2231 (setq sublst
(cdr sublst
)))
2232 ;; Go through all our bins Stick singles into our
2233 ;; junk-list, everything else as sublsts in work-list.
2234 ;; If two neighboring lists are both small, make a grouped
2235 ;; group combinding those two sub-lists.
2237 (while (> 256 diff-idx
)
2238 ;; The bins contents are currently in forward order.
2239 (let ((l (aref bins diff-idx
)))
2241 (let ((tmp (cons (speedbar-try-completion "" l
) l
)))
2242 (if (or (> (length l
) speedbar-tag-regroup-maximum-length
)
2243 (> (+ (length l
) (length short-group-list
))
2244 speedbar-tag-split-minimum-length
))
2246 ;; We have reached a longer list, so we
2247 ;; must finish off a grouped group.
2249 ((and short-group-list
2250 (= (length short-group-list
)
2251 num-shorts-grouped
))
2252 ;; All singles? Junk list
2253 (setq junk-list
(append (nreverse short-group-list
)
2255 ((= num-shorts-grouped
1)
2256 ;; Only one short group? Just stick it in
2257 ;; there by itself. Make a group, and find
2259 (let ((subexpression (speedbar-try-completion
2260 "" short-group-list
)))
2261 (if (< (length subexpression
)
2262 speedbar-tag-group-name-minimum-length
)
2264 (concat short-start-name
2267 (car (car short-group-list
))
2268 (length short-start-name
))
2271 (cons (cons subexpression
2275 ;; Multiple groups to be named in a special
2276 ;; way by displaying the range over which we
2277 ;; have grouped them.
2279 (cons (cons (concat short-start-name
2284 ;; Reset short group list information every time.
2285 (setq short-group-list nil
2286 short-start-name nil
2288 num-shorts-grouped
0)))
2289 ;; Ok, now that we cleaned up the short-group-list,
2290 ;; we can deal with this new list, to decide if it
2291 ;; should go on one of these sub-lists or not.
2292 (if (< (length l
) speedbar-tag-regroup-maximum-length
)
2293 (setq short-group-list
(append l short-group-list
)
2294 num-shorts-grouped
(1+ num-shorts-grouped
)
2295 short-end-name
(car tmp
)
2296 short-start-name
(if short-start-name
2299 (setq work-list
(cons tmp work-list
))))))
2300 (setq diff-idx
(1+ diff-idx
))))
2301 ;; Did we run out of things? Drop our new list onto the end.
2303 ((and short-group-list
(= (length short-group-list
) num-shorts-grouped
))
2304 ;; All singles? Junk list
2305 (setq junk-list
(append short-group-list junk-list
)))
2306 ((= num-shorts-grouped
1)
2307 ;; Only one short group? Just stick it in
2310 (cons (cons (speedbar-try-completion "" short-group-list
)
2314 ;; Multiple groups to be named in a special
2315 ;; way by displaying the range over which we
2316 ;; have grouped them.
2318 (cons (cons (concat short-start-name
" to " short-end-name
)
2321 ;; Reverse the work list nreversed when consing.
2322 (setq work-list
(nreverse work-list
))
2323 ;; Now, stick our new list onto the end of
2326 (append newlst work-list junk-list
)
2327 (append newlst work-list
))
2328 (append newlst junk-list
)))))
2330 (defun speedbar-trim-words-tag-hierarchy (lst)
2331 "Trim all words in a tag hierarchy.
2332 Base trimming information on word separators, and group names.
2333 Argument LST is the list of tags to trim."
2340 (if (speedbar-generic-list-group-p (car-safe lst
))
2341 (setq newlst
(cons (car lst
) newlst
))
2342 (setq sublst
(cons (car lst
) sublst
)))
2343 (setq lst
(cdr lst
)))
2344 ;; Get the prefix to trim by. Make sure that we don't trim
2345 ;; off silly pieces, only complete understandable words.
2346 (setq trim-prefix
(speedbar-try-completion "" sublst
)
2347 newlst
(nreverse newlst
))
2348 (if (or (= (length sublst
) 1)
2350 (not (string-match "\\(\\w+\\W+\\)+" trim-prefix
)))
2351 (append newlst
(nreverse sublst
))
2352 (setq trim-prefix
(substring trim-prefix
(match-beginning 0)
2354 (setq trim-chars
(length trim-prefix
))
2357 (cons (substring (car (car sublst
)) trim-chars
)
2360 sublst
(cdr sublst
)))
2361 ;; Put the lists together
2362 (append newlst trimlst
))))
2364 (defun speedbar-simple-group-tag-hierarchy (lst)
2365 "Create a simple 'Tags' group with orphaned tags.
2366 Argument LST is the list of tags to sort into groups."
2370 (if (speedbar-generic-list-group-p (car-safe lst
))
2371 (setq newlst
(cons (car lst
) newlst
))
2372 (setq sublst
(cons (car lst
) sublst
)))
2373 (setq lst
(cdr lst
)))
2376 (setq newlst
(cons (cons "Tags" (nreverse sublst
)) newlst
))
2377 (nreverse newlst
))))
2379 (defun speedbar-create-tag-hierarchy (lst)
2380 "Adjust the tag hierarchy in LST, and return it.
2381 This uses `speedbar-tag-hierarchy-method' to determine how to adjust
2383 (let* ((f (save-excursion
2385 (or (speedbar-line-file)
2386 (speedbar-line-directory))))
2387 (methods (if (get-file-buffer f
)
2388 (save-excursion (set-buffer (get-file-buffer f
))
2389 speedbar-tag-hierarchy-method
)
2390 speedbar-tag-hierarchy-method
))
2391 (lst (if (fboundp 'copy-tree
)
2395 (setq lst
(funcall (car methods
) lst
)
2396 methods
(cdr methods
)))
2399 (defvar speedbar-generic-list-group-expand-button-type
'curly
2400 "The type of button created for groups of tags.
2401 Good values for this are `curly' and `expandtag'.
2402 Make buffer local for your mode.")
2404 (defvar speedbar-generic-list-tag-button-type nil
2405 "The type of button created for tags in generic lists.
2406 Good values for this are nil and `statictag'.
2407 Make buffer local for your mode.")
2409 (defun speedbar-insert-generic-list (level lst expand-fun find-fun
)
2410 "At LEVEL, insert a generic multi-level alist LST.
2411 Associations with lists get {+} tags (to expand into more nodes) and
2412 those with positions just get a > as the indicator. {+} buttons will
2413 have the function EXPAND-FUN and the token is the cdr list. The token
2414 name will have the function FIND-FUN and not token."
2415 ;; Remove imenu rescan button
2416 (if (string= (car (car lst
)) "*Rescan*")
2417 (setq lst
(cdr lst
)))
2418 ;; Get, and set up variables that define how we treat these tags.
2419 (let ((f (save-excursion (forward-line -
1)
2420 (or (speedbar-line-file)
2421 (speedbar-line-directory))))
2422 expand-button tag-button
)
2424 (if (get-file-buffer f
)
2425 (set-buffer (get-file-buffer f
)))
2426 (setq expand-button speedbar-generic-list-group-expand-button-type
2427 tag-button speedbar-generic-list-tag-button-type
))
2429 (setq lst
(speedbar-create-tag-hierarchy lst
))
2432 (cond ((null (car-safe lst
)) nil
) ;this would be a separator
2433 ((speedbar-generic-list-tag-p (car lst
))
2434 (speedbar-make-tag-line tag-button
2435 nil nil nil
;no expand button data
2436 (car (car lst
)) ;button name
2438 (cdr (car lst
)) ;token is position
2441 ((speedbar-generic-list-positioned-group-p (car lst
))
2442 (speedbar-make-tag-line expand-button
2443 ?
+ expand-fun
(cdr (cdr (car lst
)))
2444 (car (car lst
)) ;button name
2446 (car (cdr (car lst
))) ;token is posn
2449 ((speedbar-generic-list-group-p (car lst
))
2450 (speedbar-make-tag-line expand-button
2451 ?
+ expand-fun
(cdr (car lst
))
2452 (car (car lst
)) ;button name
2453 nil nil
'speedbar-tag-face
2455 (t (speedbar-message "speedbar-insert-generic-list: malformed list!")
2457 (setq lst
(cdr lst
)))))
2459 (defun speedbar-insert-imenu-list (indent lst
)
2460 "At level INDENT, insert the imenu generated LST."
2461 (speedbar-insert-generic-list indent lst
2462 'speedbar-tag-expand
2463 'speedbar-tag-find
))
2465 (defun speedbar-insert-etags-list (indent lst
)
2466 "At level INDENT, insert the etags generated LST."
2467 (speedbar-insert-generic-list indent lst
2468 'speedbar-tag-expand
2469 'speedbar-tag-find
))
2473 (defun speedbar-update-contents ()
2474 "Generically update the contents of the speedbar buffer."
2476 ;; Set the current special buffer
2477 (setq speedbar-desired-buffer nil
)
2479 ;; Check for special modes
2480 (speedbar-maybe-add-localized-support (current-buffer))
2482 ;; Choose the correct method of doodling.
2483 (if (and speedbar-mode-specific-contents-flag
2484 (consp speedbar-special-mode-expansion-list
)
2486 'speedbar-special-mode-expansion-list
2488 ;;(eq (get major-mode 'mode-class 'special)))
2489 (speedbar-update-special-contents)
2490 (speedbar-update-directory-contents)))
2492 (defun speedbar-update-localized-contents ()
2493 "Update the contents of the speedbar buffer for the current situation."
2494 ;; Due to the historical growth of speedbar, we need to do something
2495 ;; special for "files" mode. Too bad.
2496 (let ((name speedbar-initial-expansion-list-name
)
2497 (funclst (speedbar-initial-expansion-list))
2499 (if (string= name
"files")
2500 ;; Do all the files type work. It still goes through the
2501 ;; expansion list stuff. :(
2502 (if (or (member (expand-file-name default-directory
)
2503 speedbar-shown-directories
)
2504 (and speedbar-ignored-directory-regexp
2506 speedbar-ignored-directory-regexp
2507 (expand-file-name default-directory
))))
2509 (if (<= 1 speedbar-verbosity-level
)
2510 (speedbar-message "Updating speedbar to: %s..."
2512 (speedbar-update-directory-contents)
2513 (if (<= 1 speedbar-verbosity-level
)
2515 (speedbar-message "Updating speedbar to: %s...done"
2517 (speedbar-message nil
))))
2518 ;; Else, we can do a short cut. No text cache.
2519 (let ((cbd (expand-file-name default-directory
)))
2520 (set-buffer speedbar-buffer
)
2521 (speedbar-with-writable
2522 (let* ((window (get-buffer-window speedbar-buffer
0))
2523 (p (window-point window
))
2524 (start (window-start window
)))
2526 (dolist (func funclst
)
2527 (setq default-directory cbd
)
2528 (funcall func cbd
0))
2529 (speedbar-reconfigure-keymaps)
2530 (set-window-point window p
)
2531 (set-window-start window start
)))))))
2533 (defun speedbar-update-directory-contents ()
2534 "Update the contents of the speedbar buffer based on the current directory."
2535 (let ((cbd (expand-file-name default-directory
))
2537 (funclst (speedbar-initial-expansion-list))
2538 (cache speedbar-full-text-cache
)
2539 ;; disable stealth during update
2540 (speedbar-stealthy-function-list nil
)
2543 ;; Because there is a bug I can't find just yet
2545 (set-buffer speedbar-buffer
)
2546 ;; If we are updating contents to where we are, then this is
2547 ;; really a request to update existing contents, so we must be
2548 ;; careful with our text cache!
2549 (if (member cbd speedbar-shown-directories
)
2552 ;; If the current directory is not the last element in the dir
2553 ;; list, then we ALSO need to zap the list of expanded directories
2554 (if (/= (length (member cbd speedbar-shown-directories
)) 1)
2555 (setq speedbar-shown-directories
(list cbd
))))
2557 ;; Build cbd-parent, and see if THAT is in the current shown
2558 ;; directories. First, go through pains to get the parent directory
2559 (if (and speedbar-smart-directory-expand-flag
2561 (setq cbd-parent cbd
)
2562 (if (string-match "[/\\]$" cbd-parent
)
2563 (setq cbd-parent
(substring cbd-parent
0
2564 (match-beginning 0))))
2565 (setq cbd-parent
(file-name-directory cbd-parent
)))
2566 (member cbd-parent speedbar-shown-directories
))
2567 (setq expand-local t
)
2569 ;; If this directory is NOT in the current list of available
2570 ;; directories, then use the cache, and set the cache to our new
2571 ;; value. Make sure to unhighlight the current file, or if we
2572 ;; come back to this directory, it might be a different file
2573 ;; and then we get a mess!
2574 (if (> (point-max) 1)
2576 (speedbar-clear-current-file)
2577 (setq speedbar-full-text-cache
2578 (cons speedbar-shown-directories
(buffer-string)))))
2580 ;; Check if our new directory is in the list of directories
2581 ;; shown in the text-cache
2582 (if (member cbd
(car cache
))
2583 (setq speedbar-shown-directories
(car cache
)
2585 ;; default the shown directories to this list...
2586 (setq speedbar-shown-directories
(list cbd
)))
2588 (if (not expand-local
) (setq speedbar-last-selected-file nil
))
2589 (speedbar-with-writable
2590 (if (and expand-local
2591 ;; Find this directory as a speedbar node.
2592 (speedbar-directory-line cbd
))
2594 (speedbar-expand-line)
2595 (let* ((window (get-buffer-window speedbar-buffer
0))
2596 (p (window-point window
))
2597 (start (window-start window
)))
2600 (setq default-directory
2601 (nth (1- (length speedbar-shown-directories
))
2602 speedbar-shown-directories
))
2603 (insert (cdr cache
)))
2605 (dolist (func funclst
)
2606 (setq default-directory cbd
)
2607 (funcall func cbd
0))))
2608 (set-window-point window p
)
2609 (set-window-start window start
)))))
2610 (speedbar-reconfigure-keymaps))
2612 (defun speedbar-update-special-contents ()
2613 "Use the mode-specific variable to fill in the speedbar buffer.
2614 This should only be used by modes classified as special."
2615 (let ((funclst speedbar-special-mode-expansion-list
)
2616 (specialbuff (current-buffer)))
2618 (setq speedbar-desired-buffer specialbuff
)
2619 (set-buffer speedbar-buffer
)
2620 ;; If we are leaving a directory, cache it.
2621 (if (not speedbar-shown-directories
)
2624 ;; Clean up directory maintenance stuff
2625 (speedbar-clear-current-file)
2626 (setq speedbar-full-text-cache
2627 (cons speedbar-shown-directories
(buffer-string))
2628 speedbar-shown-directories nil
))
2629 ;; Now fill in the buffer with our newly found specialized list.
2630 (speedbar-with-writable
2631 (dolist (func funclst
)
2632 ;; We do not erase the buffer because these functions may
2633 ;; decide NOT to update themselves.
2634 (funcall func specialbuff
)))))
2635 (speedbar-reconfigure-keymaps))
2637 (defun speedbar-set-timer (timeout)
2638 "Set up the speedbar timer with TIMEOUT.
2639 Uses `dframe-set-timer'.
2640 Also resets scanner functions."
2641 (dframe-set-timer timeout
'speedbar-timer-fn
'speedbar-update-flag
)
2642 ;; Apply a revert hook that will reset the scanners. We attach to revert
2643 ;; because most reverts occur during VC state change, and this lets our
2644 ;; VC scanner fix itself.
2646 (add-hook 'after-revert-hook
'speedbar-reset-scanners
)
2647 (remove-hook 'after-revert-hook
'speedbar-reset-scanners
))
2648 ;; change this if it changed for some reason
2649 (speedbar-set-mode-line-format))
2651 (defun speedbar-timer-fn ()
2652 "Run whenever Emacs is idle to update the speedbar item."
2653 (if (or (not (speedbar-current-frame))
2654 (not (frame-live-p (speedbar-current-frame))))
2655 (speedbar-set-timer nil
)
2656 ;; Save all the match data so that we don't mess up executing fns
2658 ;; Only do stuff if the frame is visible, not an icon, and if
2659 ;; it is currently flagged to do something.
2660 (if (and speedbar-update-flag
2661 (speedbar-current-frame)
2662 (frame-visible-p (speedbar-current-frame))
2663 (not (eq (frame-visible-p (speedbar-current-frame)) 'icon
)))
2664 (let ((af (selected-frame)))
2665 (dframe-select-attached-frame speedbar-frame
)
2666 ;; make sure we at least choose a window to
2667 ;; get a good directory from
2668 (if (window-minibuffer-p (selected-window))
2670 ;; Check for special modes
2671 (speedbar-maybe-add-localized-support (current-buffer))
2672 ;; Update for special mode all the time!
2673 (if (and speedbar-mode-specific-contents-flag
2674 (consp speedbar-special-mode-expansion-list
)
2676 'speedbar-special-mode-expansion-list
2678 ;;(eq (get major-mode 'mode-class 'special)))
2680 (if (<= 2 speedbar-verbosity-level
)
2682 "Updating speedbar to special mode: %s..."
2684 (speedbar-update-special-contents)
2685 (if (<= 2 speedbar-verbosity-level
)
2688 "Updating speedbar to special mode: %s...done"
2690 (speedbar-message nil
))))
2692 ;; Update all the contents if directories change!
2693 (unless (and (or (member major-mode speedbar-ignored-modes
)
2694 (eq af
(speedbar-current-frame))
2695 (not (buffer-file-name)))
2696 ;; Always update for GUD.
2697 (not (string-equal "GUD"
2698 speedbar-initial-expansion-list-name
)))
2699 (speedbar-update-localized-contents)))
2701 ;; Now run stealthy updates of time-consuming items
2702 (speedbar-stealthy-updates)))))
2703 (run-hooks 'speedbar-timer-hook
))
2706 ;;; Stealthy activities
2708 (defvar speedbar-stealthy-update-recurse nil
2709 "Recursion avoidance variable for stealthy update.")
2711 (defun speedbar-stealthy-updates ()
2712 "For a given speedbar, run all items in the stealthy function list.
2713 Each item returns t if it completes successfully, or nil if
2714 interrupted by the user."
2715 (if (not speedbar-stealthy-update-recurse
)
2716 (let ((l (speedbar-initial-stealthy-functions))
2717 (speedbar-stealthy-update-recurse t
))
2719 (speedbar-with-writable
2720 (while (and l
(funcall (car l
)))
2723 ;;(speedbar-message "Exit with %S" (car l))
2726 (defun speedbar-reset-scanners ()
2727 "Reset any variables used by functions in the stealthy list as state.
2728 If new functions are added, their state needs to be updated here."
2729 (setq speedbar-vc-to-do-point t
2730 speedbar-obj-to-do-point t
2731 speedbar-ro-to-do-point t
)
2732 (run-hooks 'speedbar-scanner-reset-hook
)
2735 (defun speedbar-find-selected-file (file)
2736 "Go to the line where FILE is."
2738 (set-buffer speedbar-buffer
)
2740 (goto-char (point-min))
2742 (while (and (setq m
(re-search-forward
2743 (concat " \\(" (regexp-quote (file-name-nondirectory file
))
2744 "\\)\\(" speedbar-indicator-regex
"\\)?\n")
2748 (speedbar-line-directory
2750 (goto-char (match-beginning 0))
2753 (looking-at "[0-9]+:")
2754 (string-to-number (match-string 0)))))
2755 (match-string 1))))))
2758 (goto-char (match-beginning 1))
2759 (match-string 1)))))
2761 (defun speedbar-clear-current-file ()
2762 "Locate the file thought to be current, and remove its highlighting."
2764 ;;(set-buffer speedbar-buffer)
2765 (if speedbar-last-selected-file
2766 (speedbar-with-writable
2767 (if (speedbar-find-selected-file speedbar-last-selected-file
)
2768 (put-text-property (match-beginning 1)
2771 'speedbar-file-face
))))))
2773 (defun speedbar-update-current-file ()
2774 "Find the current file, and update our visuals to indicate its name.
2775 This is specific to file names. If the file name doesn't show up, but
2776 it should be in the list, then the directory cache needs to be updated."
2777 (let* ((lastf (selected-frame))
2778 (newcfd (save-excursion
2779 (dframe-select-attached-frame speedbar-frame
)
2780 (let ((rf (if (buffer-file-name)
2783 (select-frame lastf
)
2785 (newcf (if newcfd newcfd
))
2786 (lastb (current-buffer))
2787 (sucf-recursive (boundp 'sucf-recursive
))
2788 (case-fold-search t
))
2790 ;; check here, that way we won't refresh to newcf until
2791 ;; its been written, thus saving ourselves some time
2792 (file-exists-p newcf
)
2793 (not (string= newcf speedbar-last-selected-file
)))
2795 ;; It is important to select the frame, otherwise the window
2796 ;; we want the cursor to move in will not be updated by the
2797 ;; search-forward command.
2798 (select-frame (speedbar-current-frame))
2799 ;; Remove the old file...
2800 (speedbar-clear-current-file)
2801 ;; now highlight the new one.
2802 ;; (set-buffer speedbar-buffer)
2803 (speedbar-with-writable
2804 (if (speedbar-find-selected-file newcf
)
2805 ;; put the property on it
2806 (put-text-property (match-beginning 1)
2809 'speedbar-selected-face
)
2810 ;; Oops, it's not in the list. Should it be?
2811 (if (and (string-match speedbar-file-regexp newcf
)
2812 (string= (file-name-directory newcfd
)
2813 (expand-file-name default-directory
)))
2814 ;; yes, it is (we will ignore unknowns for now...)
2817 (if (speedbar-find-selected-file newcf
)
2818 ;; put the property on it
2819 (put-text-property (match-beginning 1)
2822 'speedbar-selected-face
)))
2823 ;; if it's not in there now, whatever...
2825 (setq speedbar-last-selected-file newcf
))
2826 (if (not sucf-recursive
)
2829 ;;Sat Dec 15 2001 12:40 AM (burton@openprivacy.org): this
2830 ;;doesn't need to be in. We don't want to recenter when we are
2833 ;;(speedbar-center-buffer-smartly)
2835 (speedbar-position-cursor-on-line)
2838 (select-frame lastf
)
2840 ;; return that we are done with this activity.
2843 (defun speedbar-add-indicator (indicator-string &optional replace-this
)
2844 "Add INDICATOR-STRING to the end of this speedbar line.
2845 If INDICATOR-STRING is space, and REPLACE-THIS is a character,
2846 then the existing indicator is removed. If there is already an
2847 indicator, then do not add a space."
2849 ;; The nature of the beast: Assume we are in "the right place"
2851 (skip-chars-backward (concat " " speedbar-vc-indicator
2852 speedbar-object-read-only-indicator
2853 (car speedbar-obj-indicator
)
2854 (cdr speedbar-obj-indicator
)))
2855 (if (and (not (looking-at speedbar-indicator-regex
))
2856 (not (string= indicator-string
" ")))
2857 (insert speedbar-indicator-separator
))
2858 (speedbar-with-writable
2860 (if (and replace-this
2861 (re-search-forward replace-this
(save-excursion (end-of-line)
2864 (delete-region (match-beginning 0) (match-end 0))))
2866 (if (not (string= " " indicator-string
))
2867 (let ((start (point)))
2868 (insert indicator-string
)
2869 (speedbar-insert-image-button-maybe start
(length indicator-string
))
2872 (defun speedbar-check-read-only ()
2873 "Scan all the files in a directory, and for each see if it is read only."
2874 ;; Check for to-do to be reset. If reset but no RCS is available
2875 ;; then set to nil (do nothing) otherwise, start at the beginning
2877 (if speedbar-buffer
(set-buffer speedbar-buffer
))
2878 (if (eq speedbar-ro-to-do-point t
)
2879 (setq speedbar-ro-to-do-point
0))
2880 (if (numberp speedbar-ro-to-do-point
)
2882 (goto-char speedbar-ro-to-do-point
)
2883 (while (and (not (input-pending-p))
2884 (re-search-forward "^\\([0-9]+\\):\\s-*[[<][+-\?][]>] "
2886 (setq speedbar-ro-to-do-point
(point))
2887 (let ((f (speedbar-line-file)))
2889 (if (not (file-writable-p f
))
2890 (speedbar-add-indicator
2891 speedbar-object-read-only-indicator
2892 (regexp-quote speedbar-object-read-only-indicator
))
2893 (speedbar-add-indicator
2895 speedbar-object-read-only-indicator
))))))
2896 (if (input-pending-p)
2897 ;; return that we are incomplete
2899 ;; we are done, set to-do to nil
2900 (setq speedbar-ro-to-do-point nil
)
2905 ;; Load efs/ange-ftp only if compiling to remove byte-compiler warnings.
2906 ;; Steven L Baur <steve@xemacs.org> said this was important:
2907 (eval-when-compile (or (featurep 'xemacs
)
2908 (condition-case () (require 'efs
)
2909 (error (require 'ange-ftp
)))))
2911 (defun speedbar-check-vc ()
2912 "Scan all files in a directory, and for each see if it's checked out.
2913 See `speedbar-this-file-in-vc' and `speedbar-vc-check-dir-p' for how
2914 to add more types of version control systems."
2915 ;; Check for to-do to be reset. If reset but no RCS is available
2916 ;; then set to nil (do nothing) otherwise, start at the beginning
2918 (if speedbar-buffer
(set-buffer speedbar-buffer
))
2919 (if (and speedbar-vc-do-check
(eq speedbar-vc-to-do-point t
)
2920 (speedbar-vc-check-dir-p default-directory
)
2921 (not (or (and (featurep 'ange-ftp
)
2924 (if (featurep 'xemacs
)
2925 'ange-ftp-directory-format
2926 'ange-ftp-name-format
)))
2927 (expand-file-name default-directory
)))
2928 ;; efs support: Bob Weiner
2929 (and (featurep 'efs
)
2931 (let ((reg (symbol-value 'efs-directory-regexp
)))
2935 (expand-file-name default-directory
))))))
2936 (setq speedbar-vc-to-do-point
0))
2937 (if (numberp speedbar-vc-to-do-point
)
2939 (goto-char speedbar-vc-to-do-point
)
2940 (while (and (not (input-pending-p))
2941 (re-search-forward "^\\([0-9]+\\):\\s-*\\[[+-?]\\] "
2943 (setq speedbar-vc-to-do-point
(point))
2944 (if (speedbar-check-vc-this-line (match-string 1))
2945 (speedbar-add-indicator speedbar-vc-indicator
2946 (regexp-quote speedbar-vc-indicator
))
2947 (speedbar-add-indicator " "
2948 (regexp-quote speedbar-vc-indicator
))))
2949 (if (input-pending-p)
2950 ;; return that we are incomplete
2952 ;; we are done, set to-do to nil
2953 (setq speedbar-vc-to-do-point nil
)
2958 (defun speedbar-check-vc-this-line (depth)
2959 "Return t if the file on this line is checked out of a version control system.
2960 Parameter DEPTH is a string with the current depth of indentation of
2961 the file being checked."
2962 (let* ((d (string-to-number depth
))
2963 (f (speedbar-line-directory d
))
2964 (fn (buffer-substring-no-properties
2965 ;; Skip-chars: thanks ptype@dra.hmg.gb
2967 (skip-chars-forward "^ "
2968 (save-excursion (end-of-line)
2971 (fulln (concat f fn
)))
2972 (if (<= 2 speedbar-verbosity-level
)
2973 (speedbar-message "Speedbar vc check...%s" fulln
))
2974 (and (file-writable-p fulln
)
2975 (speedbar-this-file-in-vc f fn
))))
2977 (defun speedbar-vc-check-dir-p (directory)
2978 "Return t if we should bother checking DIRECTORY for version control files.
2979 This can be overloaded to add new types of version control systems."
2981 (catch t
(dolist (vcd vc-directory-exclusion-list
)
2982 (if (file-exists-p (concat directory vcd
)) (throw t t
))) nil
)
2984 (run-hook-with-args-until-success 'speedbar-vc-directory-enable-hook
2988 (defun speedbar-this-file-in-vc (directory name
)
2989 "Check to see if the file in DIRECTORY with NAME is in a version control system.
2990 Automatically recognizes all VCs supported by VC mode. You can
2991 optimize this function by overriding it and only doing those checks
2992 that will occur on your system."
2994 (vc-backend (concat directory
"/" name
))
2996 (run-hook-with-args 'speedbar-vc-in-control-hook directory name
)
2999 ;; Objet File scanning
3000 (defun speedbar-check-objects ()
3001 "Scan all files in a directory, and for each see if there is an object.
3002 See `speedbar-check-obj-this-line' and `speedbar-obj-alist' for how
3003 to add more object types."
3004 ;; Check for to-do to be reset. If reset but no RCS is available
3005 ;; then set to nil (do nothing) otherwise, start at the beginning
3007 (if speedbar-buffer
(set-buffer speedbar-buffer
))
3008 (if (and speedbar-obj-do-check
(eq speedbar-obj-to-do-point t
))
3009 (setq speedbar-obj-to-do-point
0))
3010 (if (numberp speedbar-obj-to-do-point
)
3012 (goto-char speedbar-obj-to-do-point
)
3013 (while (and (not (input-pending-p))
3014 (re-search-forward "^\\([0-9]+\\):\\s-*\\[[+-]\\] "
3016 (setq speedbar-obj-to-do-point
(point))
3017 (let ((ind (speedbar-check-obj-this-line (match-string 1))))
3018 (if (not ind
) (setq ind
" "))
3019 (speedbar-add-indicator ind
(concat
3020 (car speedbar-obj-indicator
)
3022 (cdr speedbar-obj-indicator
)))))
3023 (if (input-pending-p)
3024 ;; return that we are incomplete
3026 ;; we are done, set to-do to nil
3027 (setq speedbar-obj-to-do-point nil
)
3032 (defun speedbar-check-obj-this-line (depth)
3033 "Return t if the file on this line has an associated object.
3034 Parameter DEPTH is a string with the current depth of indentation of
3035 the file being checked."
3036 (let* ((d (string-to-number depth
))
3037 (f (speedbar-line-directory d
))
3038 (fn (buffer-substring-no-properties
3039 ;; Skip-chars: thanks ptype@dra.hmg.gb
3041 (skip-chars-forward "^ "
3042 (save-excursion (end-of-line)
3045 (fulln (concat f fn
)))
3046 (if (<= 2 speedbar-verbosity-level
)
3047 (speedbar-message "Speedbar obj check...%s" fulln
))
3048 (let ((oa speedbar-obj-alist
))
3049 (while (and oa
(not (string-match (car (car oa
)) fulln
)))
3051 (if (not (and oa
(file-exists-p (concat (file-name-sans-extension fulln
)
3054 ;; Find out if the object is out of date or not.
3055 (let ((date1 (nth 5 (file-attributes fulln
)))
3056 (date2 (nth 5 (file-attributes (concat
3057 (file-name-sans-extension fulln
)
3059 (if (or (< (car date1
) (car date2
))
3060 (and (= (car date1
) (car date2
))
3061 (< (nth 1 date1
) (nth 1 date2
))))
3062 (car speedbar-obj-indicator
)
3063 (cdr speedbar-obj-indicator
)))))))
3065 ;;; Clicking Activity
3067 (defun speedbar-position-cursor-on-line ()
3068 "Position the cursor on a line."
3069 (let ((oldpos (point)))
3071 (if (looking-at "[0-9]+:\\s-*..?.? ")
3072 (goto-char (1- (match-end 0)))
3073 (goto-char oldpos
))))
3075 (defun speedbar-click (e)
3076 "Activate any speedbar buttons where the mouse is clicked.
3077 This must be bound to a mouse event. A button is any location of text
3078 with a mouse face that has a text property called `speedbar-function'.
3079 Argument E is the click event."
3080 ;; Backward compatibility let statement.
3081 (let ((speedbar-power-click dframe-power-click
))
3082 (speedbar-do-function-pointer))
3083 (dframe-quick-mouse e
))
3085 (defun speedbar-do-function-pointer ()
3086 "Look under the cursor and examine the text properties.
3087 From this extract the file/tag name, token, indentation level and call
3088 a function if appropriate."
3089 (let* ((speedbar-frame (speedbar-current-frame))
3090 (fn (get-text-property (point) 'speedbar-function
))
3091 (tok (get-text-property (point) 'speedbar-token
))
3092 ;; The 1-,+ is safe because scaning starts AFTER the point
3093 ;; specified. This lets the search include the character the
3095 (tp (previous-single-property-change
3096 (1+ (point)) 'speedbar-function
))
3097 (np (next-single-property-change
3098 (point) 'speedbar-function
))
3099 (txt (buffer-substring-no-properties (or tp
(point-min))
3100 (or np
(point-max))))
3101 (dent (save-excursion (beginning-of-line)
3103 (if (looking-at "[0-9]+")
3104 (buffer-substring-no-properties
3105 (match-beginning 0) (match-end 0))
3107 ;;(speedbar-message "%S:%S:%S:%s" fn tok txt dent)
3108 (and fn
(funcall fn txt tok dent
)))
3109 (speedbar-position-cursor-on-line))
3111 ;;; Reading info from the speedbar buffer
3113 (defun speedbar-line-text (&optional p
)
3114 "Retrieve the text after prefix junk for the current line.
3115 Optional argument P is where to start the search from."
3117 (if p
(goto-char p
))
3119 (if (looking-at (concat
3120 "\\([0-9]+\\): *[[<{]?[-+?= ][]>}@()|] \\([^ \n]+\\)"))
3121 (get-text-property (match-beginning 2) 'speedbar-text
)
3124 (defun speedbar-line-token (&optional p
)
3125 "Retrieve the token information after the prefix junk for the current line.
3126 Optional argument P is where to start the search from."
3128 (if p
(goto-char p
))
3130 (if (looking-at (concat
3131 "\\([0-9]+\\): *[[<{]?[-+?= ][]>}@()|] \\([^ \n]+\\)\\("
3132 speedbar-indicator-regex
"\\)?"))
3134 (goto-char (match-beginning 2))
3135 (get-text-property (point) 'speedbar-token
))
3138 (defun speedbar-line-file (&optional p
)
3139 "Retrieve the file or whatever from the line at point P.
3140 The return value is a string representing the file. If it is a
3141 directory, then it is the directory name."
3145 (let ((f (speedbar-line-text p
)))
3147 (let* ((depth (string-to-number (match-string 1)))
3148 (directory (speedbar-line-directory depth
)))
3149 (if (file-exists-p (concat directory f
))
3150 (concat directory f
)
3154 (defun speedbar-goto-this-file (file)
3155 "If FILE is displayed, go to this line and return t.
3156 Otherwise do not move and return nil."
3157 (let ((directory (substring (file-name-directory (expand-file-name file
))
3158 (length (expand-file-name default-directory
))))
3161 (goto-char (point-min))
3162 ;; scan all the directories
3163 (while (and directory
(not (eq directory t
)))
3164 (if (string-match "^[/\\]?\\([^/\\]+\\)" directory
)
3165 (let ((pp (match-string 1 directory
)))
3166 (if (save-match-data
3167 (re-search-forward (concat "> " (regexp-quote pp
) "$")
3169 (setq directory
(substring directory
(match-end 1)))
3170 (setq directory nil
)))
3171 (setq directory t
)))
3172 ;; find the file part
3173 (if (or (not directory
) (string= (file-name-nondirectory file
) ""))
3174 ;; only had a dir part
3177 (speedbar-position-cursor-on-line)
3179 (goto-char dest
) nil
)
3180 ;; find the file part
3181 (let ((nd (file-name-nondirectory file
)))
3182 (if (re-search-forward
3183 (concat "] \\(" (regexp-quote nd
)
3184 "\\)\\(" speedbar-indicator-regex
"\\)$")
3187 (speedbar-position-cursor-on-line)
3192 (defun speedbar-line-directory (&optional depth
)
3193 "Retrieve the directory name associated with the current line.
3194 This may require traversing backwards from DEPTH and combining the default
3195 directory with these items. This function is replaceable in
3196 `speedbar-mode-functions-list' as `speedbar-line-directory'."
3199 (let ((rf (speedbar-fetch-replacement-function 'speedbar-line-directory
)))
3200 (if rf
(funcall rf depth
) default-directory
))))
3202 (defun speedbar-files-line-directory (&optional depth
)
3203 "Retrieve the directory associated with the current line.
3204 This may require traversing backwards from DEPTH and combining the default
3205 directory with these items."
3211 (looking-at "^\\([0-9]+\\):")
3212 (setq depth
(string-to-number (match-string 1)))))
3213 (let ((directory nil
))
3214 (setq depth
(1- depth
))
3215 (while (/= depth -
1)
3216 (if (not (re-search-backward (format "^%d:" depth
) nil t
))
3217 (error "Error building filename of tag")
3218 (cond ((looking-at "[0-9]+:\\s-*<->\\s-+\\([^\n]+\\)")
3219 (setq directory
(concat (speedbar-line-text)
3222 ((looking-at "[0-9]+:\\s-*[-]\\s-+\\([^\n]+\\)")
3223 ;; This is the start of our directory.
3224 (setq directory
(speedbar-line-text)))))
3225 (setq depth
(1- depth
)))
3227 (string-match (concat speedbar-indicator-regex
"$")
3229 (setq directory
(substring directory
0 (match-beginning 0))))
3230 (concat default-directory directory
)))))
3232 (defun speedbar-directory-line (directory)
3233 "Position the cursor on the line specified by DIRECTORY."
3235 (if (string-match "[/\\]$" directory
)
3236 (setq directory
(substring directory
0 (match-beginning 0))))
3237 (let ((nomatch t
) (depth 0)
3238 (fname (file-name-nondirectory directory
))
3239 (pname (file-name-directory directory
)))
3240 (if (not (member pname speedbar-shown-directories
))
3241 (error "Internal Error: File %s not shown in speedbar" directory
))
3242 (goto-char (point-min))
3245 (concat "[]>] \\(" (regexp-quote fname
)
3246 "\\)\\(" speedbar-indicator-regex
"\\)?$")
3249 (looking-at "\\([0-9]+\\):")
3250 (setq depth
(string-to-number (match-string 0))
3251 nomatch
(not (string= pname
(speedbar-line-directory depth
))))
3256 (defun speedbar-edit-line ()
3257 "Edit whatever tag or file is on the current speedbar line."
3261 ;; If this fails, then it is a non-standard click, and as such,
3262 ;; perfectly allowed.
3263 (if (re-search-forward "[]>?}] [^ ]"
3264 (save-excursion (end-of-line) (point))
3268 (speedbar-do-function-pointer))
3270 (speedbar-do-function-pointer)))
3272 (defun speedbar-expand-line (&optional arg
)
3273 "Expand the line under the cursor.
3274 With universal argument ARG, flush cached data."
3277 (let* ((dframe-power-click arg
)
3278 (speedbar-power-click arg
))
3281 (re-search-forward ":\\s-*.\\+. "
3282 (save-excursion (end-of-line) (point)))
3284 (speedbar-do-function-pointer))
3285 (error (speedbar-position-cursor-on-line)))))
3287 (defun speedbar-flush-expand-line ()
3288 "Expand the line under the cursor and flush any cached information."
3290 (speedbar-expand-line 1))
3292 (defun speedbar-contract-line ()
3293 "Contract the line under the cursor."
3298 (re-search-forward ":\\s-*.-. "
3299 (save-excursion (end-of-line) (point)))
3301 (speedbar-do-function-pointer))
3302 (error (speedbar-position-cursor-on-line))))
3304 (defun speedbar-toggle-line-expansion ()
3305 "Contract or expand the line under the cursor."
3310 (re-search-forward ":\\s-*.[-+]. "
3311 (save-excursion (end-of-line) (point)))
3313 (speedbar-do-function-pointer))
3314 (error (speedbar-position-cursor-on-line))))
3316 (defun speedbar-expand-line-descendants (&optional arg
)
3317 "Expand the line under the cursor and all descendants.
3318 Optional argument ARG indicates that any cache should be flushed."
3320 (speedbar-expand-line arg
)
3321 ;; Now, inside the area expaded here, expand all subnodes of
3322 ;; the same descendant type.
3324 (speedbar-next 1) ;; Move into the list.
3329 (speedbar-expand-line-descendants arg
)
3330 (speedbar-restricted-next 1))
3331 (error (setq err t
))))))
3334 (defun speedbar-contract-line-descendants ()
3335 "Expand the line under the cursor and all descendants."
3337 (speedbar-contract-line)
3338 ;; Don't need to do anything else since all descendants are
3339 ;; hidden by default anyway. Yay! It's easy.
3342 (defun speedbar-find-file (text token indent
)
3343 "Speedbar click handler for filenames.
3344 TEXT, the file will be displayed in the attached frame.
3345 TOKEN is unused, but required by the click handler. INDENT is the
3346 current indentation level."
3347 (let ((cdd (speedbar-line-directory indent
)))
3348 ;; Run before visiting file hook here.
3349 (let ((f (selected-frame)))
3350 (dframe-select-attached-frame speedbar-frame
)
3351 (run-hooks 'speedbar-before-visiting-file-hook
)
3353 (speedbar-find-file-in-frame (concat cdd text
))
3354 (speedbar-stealthy-updates)
3355 (run-hooks 'speedbar-visiting-file-hook
)
3356 ;; Reset the timer with a new timeout when cliking a file
3357 ;; in case the user was navigating directories, we can cancel
3358 ;; that other timer.
3359 (speedbar-set-timer dframe-update-speed
))
3360 (dframe-maybee-jump-to-attached-frame))
3362 (defun speedbar-dir-follow (text token indent
)
3363 "Speedbar click handler for directory names.
3364 Clicking a directory will cause the speedbar to list files in
3365 the subdirectory TEXT. TOKEN is an unused requirement. The
3366 subdirectory chosen will be at INDENT level."
3367 (setq default-directory
3368 (concat (expand-file-name (concat (speedbar-line-directory indent
) text
))
3370 ;; Because we leave speedbar as the current buffer,
3371 ;; update contents will change directory without
3372 ;; having to touch the attached frame. Turn off smart expand just
3374 (let ((speedbar-smart-directory-expand-flag nil
))
3375 (speedbar-update-contents))
3376 (speedbar-set-timer speedbar-navigating-speed
)
3377 (setq speedbar-last-selected-file nil
)
3378 (speedbar-stealthy-updates))
3380 (defun speedbar-delete-subblock (indent)
3381 "Delete text from point to indentation level INDENT or greater.
3382 Handles end-of-sublist smartly."
3383 (speedbar-with-writable
3385 (end-of-line) (forward-char 1)
3386 (let ((start (point)))
3387 (while (and (looking-at "^\\([0-9]+\\):")
3388 (> (string-to-number (match-string 1)) indent
)
3391 (beginning-of-line))
3392 (delete-region start
(point))))))
3394 (defun speedbar-dired (text token indent
)
3395 "Speedbar click handler for directory expand button.
3396 Clicking this button expands or contracts a directory. TEXT is the
3397 button clicked which has either a + or -. TOKEN is the directory to be
3398 expanded. INDENT is the current indentation level."
3399 (cond ((string-match "+" text
) ;we have to expand this dir
3400 (setq speedbar-shown-directories
3401 (cons (expand-file-name
3402 (concat (speedbar-line-directory indent
) token
"/"))
3403 speedbar-shown-directories
))
3404 (speedbar-change-expand-button-char ?-
)
3405 (speedbar-reset-scanners)
3407 (end-of-line) (forward-char 1)
3408 (speedbar-with-writable
3409 (speedbar-default-directory-list
3410 (concat (speedbar-line-directory indent
) token
"/")
3412 ((string-match "-" text
) ;we have to contract this node
3413 (speedbar-reset-scanners)
3414 (let ((oldl speedbar-shown-directories
)
3416 (td (expand-file-name
3417 (concat (speedbar-line-directory indent
) token
))))
3419 (if (not (string-match (concat "^" (regexp-quote td
)) (car oldl
)))
3420 (setq newl
(cons (car oldl
) newl
)))
3421 (setq oldl
(cdr oldl
)))
3422 (setq speedbar-shown-directories
(nreverse newl
)))
3423 (speedbar-change-expand-button-char ?
+)
3424 (speedbar-delete-subblock indent
)
3426 (t (error "Ooops... not sure what to do")))
3427 (speedbar-center-buffer-smartly)
3428 (save-excursion (speedbar-stealthy-updates)))
3430 (defun speedbar-directory-buttons-follow (text token indent
)
3431 "Speedbar click handler for default directory buttons.
3432 TEXT is the button clicked on. TOKEN is the directory to follow.
3433 INDENT is the current indentation level and is unused."
3434 (if (string-match "^[A-z]:$" token
)
3435 (setq default-directory
(concat token
"/"))
3436 (setq default-directory token
))
3437 ;; Because we leave speedbar as the current buffer,
3438 ;; update contents will change directory without
3439 ;; having to touch the attached frame.
3440 (speedbar-update-contents)
3441 (speedbar-set-timer speedbar-navigating-speed
))
3443 (defun speedbar-tag-file (text token indent
)
3444 "The cursor is on a selected line. Expand the tags in the specified file.
3445 The parameter TEXT and TOKEN are required, where TEXT is the button
3446 clicked, and TOKEN is the file to expand. INDENT is the current
3448 (cond ((string-match "+" text
) ;we have to expand this file
3449 (let* ((fn (expand-file-name (concat (speedbar-line-directory indent
)
3452 (lst (speedbar-fetch-dynamic-tags fn
)))
3453 ;; if no list, then remove expando button
3455 (speedbar-change-expand-button-char ??
)
3456 (speedbar-change-expand-button-char ?-
)
3457 (speedbar-with-writable
3459 (end-of-line) (forward-char 1)
3460 (funcall (car lst
) indent
(cdr lst
)))))))
3461 ((string-match "-" text
) ;we have to contract this node
3462 (speedbar-change-expand-button-char ?
+)
3463 (speedbar-delete-subblock indent
))
3464 (t (error "Ooops... not sure what to do")))
3465 (speedbar-center-buffer-smartly))
3467 (defun speedbar-tag-find (text token indent
)
3468 "For the tag TEXT in a file TOKEN, go to that position.
3469 INDENT is the current indentation level."
3470 (let ((file (speedbar-line-directory indent
)))
3471 (let ((f (selected-frame)))
3472 (dframe-select-attached-frame speedbar-frame
)
3473 (run-hooks 'speedbar-before-visiting-tag-hook
)
3475 (speedbar-find-file-in-frame file
)
3476 (save-excursion (speedbar-stealthy-updates))
3477 ;; Reset the timer with a new timeout when cliking a file
3478 ;; in case the user was navigating directories, we can cancel
3479 ;; that other timer.
3480 (speedbar-set-timer dframe-update-speed
)
3482 (run-hooks 'speedbar-visiting-tag-hook
)
3483 (dframe-maybee-jump-to-attached-frame)
3486 (defun speedbar-tag-expand (text token indent
)
3487 "Expand a tag sublist. Imenu will return sub-lists of specialized tag types.
3488 Etags does not support this feature. TEXT will be the button string.
3489 TOKEN will be the list, and INDENT is the current indentation level."
3490 (cond ((string-match "+" text
) ;we have to expand this file
3491 (speedbar-change-expand-button-char ?-
)
3492 (speedbar-with-writable
3494 (end-of-line) (forward-char 1)
3495 (speedbar-insert-generic-list indent token
'speedbar-tag-expand
3496 'speedbar-tag-find
))))
3497 ((string-match "-" text
) ;we have to contract this node
3498 (speedbar-change-expand-button-char ?
+)
3499 (speedbar-delete-subblock indent
))
3500 (t (error "Ooops... not sure what to do")))
3501 (speedbar-center-buffer-smartly))
3503 ;;; Loading files into the attached frame.
3505 (defcustom speedbar-select-frame-method
'attached
3506 "*Specify how to select a frame for displaying a file.
3507 A value of 'attached means to use the attached frame (the frame
3508 that speedbar was started from.) A number such as 1 or -1 means to
3509 pass that number to `other-frame' while selecting a frame from speedbar."
3513 (defun speedbar-find-file-in-frame (file)
3514 "This will load FILE into the speedbar attached frame.
3515 If the file is being displayed in a different frame already, then raise that
3517 (let* ((buff (find-file-noselect file
))
3518 (bwin (get-buffer-window buff
0)))
3521 (select-window bwin
)
3522 (raise-frame (window-frame bwin
)))
3523 (if dframe-power-click
3524 (let ((pop-up-frames t
)) (select-window (display-buffer buff
)))
3525 (if (numberp speedbar-select-frame-method
)
3526 (other-frame speedbar-select-frame-method
)
3527 (dframe-select-attached-frame speedbar-frame
))
3528 (switch-to-buffer buff
))))
3531 ;;; Centering Utility
3533 (defun speedbar-center-buffer-smartly ()
3534 "Recenter a speedbar buffer so the current indentation level is all visible.
3535 This assumes that the cursor is on a file, or tag of a file which the user is
3538 (save-selected-window
3540 (select-window (get-buffer-window speedbar-buffer t
))
3542 (set-buffer speedbar-buffer
)
3544 (if (<= (count-lines (point-min) (point-max))
3545 (1- (window-height (selected-window))))
3546 ;; whole buffer fits
3549 (goto-char (point-min))
3553 (let (depth start end exp p
)
3556 (setq depth
(if (looking-at "[0-9]+")
3557 (string-to-number (buffer-substring-no-properties
3558 (match-beginning 0) (match-end 0)))
3560 (setq exp
(format "^%d:" depth
)))
3563 (if (re-search-backward exp nil t
)
3564 (setq start
(point))
3565 (setq start
(point-min)))
3566 (save-excursion ;Not sure about this part.
3569 (while (and (not (re-search-forward exp nil t
))
3571 (setq depth
(1- depth
))
3572 (setq exp
(format "^%d:" depth
)))
3575 (setq end
(point-max)))))
3576 ;; Now work out the details of centering
3577 (let ((nl (count-lines start end
))
3578 (wl (1- (window-height (selected-window))))
3581 ;; We can't fit it all, so just center on cursor
3582 (progn (goto-char start
)
3584 ;; we can fit everything on the screen, but...
3585 (if (and (pos-visible-in-window-p start
(selected-window))
3586 (pos-visible-in-window-p end
(selected-window)))
3589 ;; we need to do something...
3591 (let ((newcent (/ (- (window-height (selected-window)) nl
) 2))
3592 (lte (count-lines start
(point-max))))
3593 (if (and (< (+ newcent lte
) (window-height (selected-window)))
3594 (> (- (window-height (selected-window)) lte
1)
3596 (setq newcent
(- (window-height (selected-window))
3598 (recenter newcent
))))
3601 ;;; Tag Management -- List of expanders:
3603 (defun speedbar-fetch-dynamic-tags (file)
3604 "Return a list of tags generated dynamically from FILE.
3605 This uses the entries in `speedbar-dynamic-tags-function-list'
3606 to find the proper tags. It is up to each of those individual
3607 functions to do caching and flushing if appropriate."
3609 ;; If a file is in memory, switch to that buffer. This allows
3610 ;; us to use the local variable. If the file is on disk, we
3611 ;; can try a few of the defaults that can get tags without
3612 ;; opening the file.
3613 (if (get-file-buffer file
)
3614 (set-buffer (get-file-buffer file
)))
3615 ;; If there is a buffer-local value of
3616 ;; speedbar-dynamic-tags-function-list, it will now be available.
3617 (let ((dtf speedbar-dynamic-tags-function-list
)
3619 (while (and (eq ret t
) dtf
)
3621 (if (fboundp (car (car dtf
)))
3622 (funcall (car (car dtf
)) file
)
3625 (setq dtf
(cdr dtf
))))
3627 ;; No valid tag list, return nil
3629 ;; We have some tags. Return the list with the insert fn
3631 (cons (cdr (car dtf
)) ret
)))))
3633 ;;; Tag Management -- Imenu
3635 (if (not speedbar-use-imenu-flag
)
3639 (eval-when-compile (condition-case nil
(require 'imenu
) (error nil
)))
3641 (defun speedbar-fetch-dynamic-imenu (file)
3642 "Load FILE into a buffer, and generate tags using Imenu.
3643 Returns the tag list, or t for an error."
3644 ;; Load this AND compile it in
3646 (set-buffer (find-file-noselect file
))
3647 (if dframe-power-click
(setq imenu--index-alist nil
))
3649 (let ((index-alist (imenu--make-index-alist t
)))
3650 (if speedbar-sort-tags
3651 (sort (copy-alist index-alist
)
3652 (lambda (a b
) (string< (car a
) (car b
))))
3657 ;;; Tag Management -- etags (old XEmacs compatibility part)
3659 (defvar speedbar-fetch-etags-parse-list
3660 '(;; Note that java has the same parse-group as c
3661 ("\\.\\([cChH]\\|c\\+\\+\\|cpp\\|cc\\|hh\\|java\\|cxx\\|hxx\\)\\'" .
3662 speedbar-parse-c-or-c
++tag
)
3663 ("^\\.emacs$\\|.\\(el\\|l\\|lsp\\)\\'" .
3664 "def[^i]+\\s-+\\(\\(\\w\\|[-_]\\)+\\)\\s-*\C-?")
3665 ; ("\\.\\([fF]\\|for\\|FOR\\|77\\|90\\)\\'" .
3666 ; speedbar-parse-fortran77-tag)
3667 ("\\.tex\\'" . speedbar-parse-tex-string
)
3669 "\\(\\(FUNCTION\\|function\\|PROCEDURE\\|procedure\\)\\s-+\\([a-zA-Z0-9_.:]+\\)\\)\\s-*(?^?")
3671 "Associations of file extensions and expressions for extracting tags.
3672 To add a new file type, you would want to add a new association to the
3673 list, where the car is the file match, and the cdr is the way to
3674 extract an element from the tags output. If the output is complex,
3675 use a function symbol instead of regexp. The function should expect
3676 to be at the beginning of a line in the etags buffer.
3678 This variable is ignored if `speedbar-use-imenu-flag' is non-nil.")
3680 (defvar speedbar-fetch-etags-command
"etags"
3681 "*Command used to create an etags file.
3683 This variable is ignored if `speedbar-use-imenu-flag' is t.")
3685 (defvar speedbar-fetch-etags-arguments
'("-D" "-I" "-o" "-")
3686 "*List of arguments to use with `speedbar-fetch-etags-command'.
3687 This creates an etags output buffer. Use `speedbar-toggle-etags' to
3688 modify this list conveniently.
3690 This variable is ignored if `speedbar-use-imenu-flag' is t.")
3692 (defun speedbar-toggle-etags (flag)
3693 "Toggle FLAG in `speedbar-fetch-etags-arguments'.
3694 FLAG then becomes a member of etags command line arguments. If flag
3695 is \"sort\", then toggle the value of `speedbar-sort-tags'. If its
3696 value is \"show\" then toggle the value of
3697 `speedbar-show-unknown-files'.
3699 This function is a convenience function for XEmacs menu created by
3700 Farzin Guilak <farzin@protocol.com>."
3703 ((equal flag
"sort")
3704 (setq speedbar-sort-tags
(not speedbar-sort-tags
)))
3705 ((equal flag
"show")
3706 (setq speedbar-show-unknown-files
(not speedbar-show-unknown-files
)))
3707 ((or (equal flag
"-C")
3710 (if (member flag speedbar-fetch-etags-arguments
)
3711 (setq speedbar-fetch-etags-arguments
3712 (delete flag speedbar-fetch-etags-arguments
))
3713 (add-to-list 'speedbar-fetch-etags-arguments flag
)))
3716 (defun speedbar-fetch-dynamic-etags (file)
3717 "For FILE, run etags and create a list of symbols extracted.
3718 Each symbol will be associated with its line position in FILE."
3719 (let ((newlist nil
))
3722 (if (get-buffer "*etags tmp*")
3723 (kill-buffer "*etags tmp*")) ;kill to clean it up
3724 (if (<= 1 speedbar-verbosity-level
)
3725 (speedbar-message "Fetching etags..."))
3726 (set-buffer (get-buffer-create "*etags tmp*"))
3727 (apply 'call-process speedbar-fetch-etags-command nil
3728 (current-buffer) nil
3729 (append speedbar-fetch-etags-arguments
(list file
)))
3730 (goto-char (point-min))
3731 (if (<= 1 speedbar-verbosity-level
)
3732 (speedbar-message "Fetching etags..."))
3734 (let ((exprlst speedbar-fetch-etags-parse-list
)
3736 (while (and (not ans
) exprlst
)
3737 (if (string-match (car (car exprlst
)) file
)
3738 (setq ans
(car exprlst
)))
3739 (setq exprlst
(cdr exprlst
)))
3743 (set-buffer (get-buffer-create "*etags tmp*"))
3744 (while (not (save-excursion (end-of-line) (eobp)))
3746 (setq tnl
(speedbar-extract-one-symbol expr
)))
3747 (if tnl
(setq newlist
(cons tnl newlist
)))
3750 "Sorry, no support for a file of that extension"))))
3752 (if speedbar-sort-tags
3753 (sort newlist
(lambda (a b
) (string< (car a
) (car b
))))
3754 (reverse newlist
))))
3756 ;; This bit donated by Farzin Guilak <farzin@protocol.com> but I'm not
3757 ;; sure it's needed with the different sorting method.
3759 ;(defun speedbar-clean-etags()
3760 ; "Removes spaces before the ^? character, and removes `#define',
3761 ;return types, etc. preceding tags. This ensures that the sort operation
3762 ;works on the tags, not the return types."
3764 ; (goto-char (point-min))
3766 ; (re-search-forward "(?[ \t](?\C-?" nil t)
3767 ; (replace-match "\C-?" nil nil))
3768 ; (goto-char (point-min))
3770 ; (re-search-forward "\\(.*[ \t]+\\)\\([^ \t\n]+.*\C-?\\)" nil t)
3771 ; (delete-region (match-beginning 1) (match-end 1)))))
3773 (defun speedbar-extract-one-symbol (expr)
3774 "At point, return nil, or one alist in the form (SYMBOL . POSITION).
3775 The line should contain output from etags. Parse the output using the
3776 regular expression EXPR."
3777 (let* ((sym (if (stringp expr
)
3779 (re-search-forward expr
(save-excursion
3782 (buffer-substring-no-properties (match-beginning 1)
3785 (pos (let ((j (re-search-forward "[\C-?\C-a]\\([0-9]+\\),\\([0-9]+\\)"
3791 (1+ (string-to-number (buffer-substring-no-properties
3799 (defun speedbar-parse-c-or-c++tag
()
3800 "Parse a C or C++ tag, which tends to be a little complex."
3802 (let ((bound (save-excursion (end-of-line) (point))))
3803 (cond ((re-search-forward "\C-?\\([^\C-a]+\\)\C-a" bound t
)
3804 (buffer-substring-no-properties (match-beginning 1)
3806 ((re-search-forward "\\<\\([^ \t]+\\)\\s-+new(" bound t
)
3807 (buffer-substring-no-properties (match-beginning 1)
3809 ((re-search-forward "\\<\\([^ \t(]+\\)\\s-*(\C-?" bound t
)
3810 (buffer-substring-no-properties (match-beginning 1)
3815 (defun speedbar-parse-tex-string ()
3816 "Parse a Tex string. Only find data which is relevant."
3818 (let ((bound (save-excursion (end-of-line) (point))))
3819 (cond ((re-search-forward "\\(\\(sub\\)*section\\|chapter\\|cite\\)\\s-*{[^\C-?}]*}?" bound t
)
3820 (buffer-substring-no-properties (match-beginning 0)
3825 ;;; BUFFER DISPLAY mode.
3827 (defvar speedbar-buffers-key-map nil
3828 "Keymap used when in the buffers display mode.")
3830 (if speedbar-buffers-key-map
3832 (setq speedbar-buffers-key-map
(speedbar-make-specialized-keymap))
3834 ;; Basic tree features
3835 (define-key speedbar-buffers-key-map
"e" 'speedbar-edit-line
)
3836 (define-key speedbar-buffers-key-map
"\C-m" 'speedbar-edit-line
)
3837 (define-key speedbar-buffers-key-map
"+" 'speedbar-expand-line
)
3838 (define-key speedbar-buffers-key-map
"=" 'speedbar-expand-line
)
3839 (define-key speedbar-buffers-key-map
"-" 'speedbar-contract-line
)
3840 (define-key speedbar-buffers-key-map
" " 'speedbar-toggle-line-expansion
)
3842 ;; Buffer specific keybindings
3843 (define-key speedbar-buffers-key-map
"k" 'speedbar-buffer-kill-buffer
)
3844 (define-key speedbar-buffers-key-map
"r" 'speedbar-buffer-revert-buffer
)
3848 (defvar speedbar-buffer-easymenu-definition
3849 '(["Jump to buffer" speedbar-edit-line t
]
3850 ["Expand File Tags" speedbar-expand-line
3851 (save-excursion (beginning-of-line)
3852 (looking-at "[0-9]+: *.\\+. "))]
3853 ["Flush Cache & Expand" speedbar-flush-expand-line
3854 (save-excursion (beginning-of-line)
3855 (looking-at "[0-9]+: *.\\+. "))]
3856 ["Contract File Tags" speedbar-contract-line
3857 (save-excursion (beginning-of-line)
3858 (looking-at "[0-9]+: *.-. "))]
3860 ["Kill Buffer" speedbar-buffer-kill-buffer
3861 (save-excursion (beginning-of-line)
3862 (looking-at "[0-9]+: *.[-+?]. "))]
3863 ["Revert Buffer" speedbar-buffer-revert-buffer
3864 (save-excursion (beginning-of-line)
3865 (looking-at "[0-9]+: *.[-+?]. "))]
3867 "Menu item elements shown when displaying a buffer list.")
3869 (defun speedbar-buffer-buttons (directory zero
)
3870 "Create speedbar buttons based on the buffers currently loaded.
3871 DIRECTORY is the directory of the currently active buffer, and ZERO is 0."
3872 (speedbar-buffer-buttons-engine nil
))
3874 (defun speedbar-buffer-buttons-temp (directory zero
)
3875 "Create speedbar buttons based on the buffers currently loaded.
3876 DIRECTORY is the directory of the currently active buffer, and ZERO is 0."
3877 (speedbar-buffer-buttons-engine t
))
3879 (defun speedbar-buffer-buttons-engine (temp)
3880 "Create speedbar buffer buttons.
3881 If TEMP is non-nil, then clicking on a buffer restores the previous display."
3882 (speedbar-insert-separator "Active Buffers:")
3883 (let ((bl (buffer-list))
3884 (case-fold-search t
))
3886 (if (string-match "^[ *]" (buffer-name (car bl
)))
3888 (let* ((known (string-match speedbar-file-regexp
3889 (buffer-name (car bl
))))
3890 (expchar (if known ?
+ ??
))
3891 (fn (if known
'speedbar-tag-file nil
))
3892 (fname (save-excursion (set-buffer (car bl
))
3893 (buffer-file-name))))
3894 (speedbar-make-tag-line 'bracket expchar fn
3895 (if fname
(file-name-nondirectory fname
))
3896 (buffer-name (car bl
))
3897 'speedbar-buffer-click temp
3898 'speedbar-file-face
0)
3899 (speedbar-buffers-tail-notes (car bl
))))
3901 (setq bl
(buffer-list))
3902 (speedbar-insert-separator "Scratch Buffers:")
3904 (if (not (string-match "^\\*" (buffer-name (car bl
))))
3906 (if (eq (car bl
) speedbar-buffer
)
3908 (speedbar-make-tag-line 'bracket ?? nil nil
3909 (buffer-name (car bl
))
3910 'speedbar-buffer-click temp
3911 'speedbar-file-face
0)
3912 (speedbar-buffers-tail-notes (car bl
))))
3914 (setq bl
(buffer-list))
3915 ;;(speedbar-insert-separator "Hidden Buffers:")
3917 ;; (if (not (string-match "^ " (buffer-name (car bl))))
3919 ;; (if (eq (car bl) speedbar-buffer)
3921 ;; (speedbar-make-tag-line 'bracket ?? nil nil
3922 ;; (buffer-name (car bl))
3923 ;; 'speedbar-buffer-click temp
3924 ;; 'speedbar-file-face 0)
3925 ;; (speedbar-buffers-tail-notes (car bl))))
3926 ;; (setq bl (cdr bl)))
3929 (defun speedbar-buffers-tail-notes (buffer)
3930 "Add a note to the end of the last tag line.
3931 Argument BUFFER is the buffer being tested."
3935 (setq mod
(buffer-modified-p)
3936 ro buffer-read-only
))
3937 (if ro
(speedbar-insert-button "%" nil nil nil nil t
))))
3939 (defun speedbar-buffers-item-info ()
3940 "Display information about the current buffer on the current line."
3941 (or (speedbar-item-info-tag-helper)
3942 (let* ((item (speedbar-line-text))
3943 (buffer (if item
(get-buffer item
) nil
)))
3945 (speedbar-message "%s%s %S %d %s"
3946 (if (buffer-modified-p buffer
) "* " "")
3948 (save-excursion (set-buffer buffer
) major-mode
)
3949 (save-excursion (set-buffer buffer
)
3951 (or (buffer-file-name buffer
) "<No file>"))))))
3953 (defun speedbar-buffers-line-directory (&optional depth
)
3954 "Fetch the directory of the file (buffer) specified on the current line.
3955 Optional argument DEPTH specifies the current depth of the back search."
3958 (let ((start (point)))
3959 ;; Buffers are always at level 0
3960 (if (not (re-search-backward "^0:" nil t
))
3962 (let* ((bn (speedbar-line-text))
3963 (buffer (if bn
(get-buffer bn
))))
3968 (or (save-excursion (set-buffer buffer
)
3971 (buffer-file-name buffer
))))))))
3973 (defun speedbar-buffer-click (text token indent
)
3974 "When the users clicks on a buffer-button in speedbar.
3975 TEXT is the buffer's name, TOKEN and INDENT are unused."
3976 (if dframe-power-click
3977 (let ((pop-up-frames t
)) (select-window (display-buffer text
)))
3978 (dframe-select-attached-frame speedbar-frame
)
3979 (switch-to-buffer text
)
3980 (if token
(speedbar-change-initial-expansion-list
3981 speedbar-previously-used-expansion-list-name
))))
3983 (defun speedbar-buffer-kill-buffer ()
3984 "Kill the buffer the cursor is on in the speedbar buffer."
3987 (let ((text (speedbar-line-text)))
3988 (if (and (get-buffer text
)
3989 (speedbar-y-or-n-p (format "Kill buffer %s? " text
)))
3991 (speedbar-refresh)))))
3993 (defun speedbar-buffer-revert-buffer ()
3994 "Revert the buffer the cursor is on in the speedbar buffer."
3998 ;; If this fails, then it is a non-standard click, and as such,
3999 ;; perfectly allowed
4000 (if (re-search-forward "[]>?}] [^ ]"
4001 (save-excursion (end-of-line) (point))
4005 (buffer-substring (point) (save-excursion
4008 (if (get-buffer text
)
4011 (revert-buffer t
)))))))
4014 ;;; Useful hook values and such.
4016 (defvar speedbar-highlight-one-tag-line nil
4017 "Overlay used for highlighting the most recently jumped to tag line.")
4019 (defun speedbar-highlight-one-tag-line ()
4020 "Highlight the current line, unhighlighting a previously jumped to line."
4021 (speedbar-unhighlight-one-tag-line)
4022 (setq speedbar-highlight-one-tag-line
4023 (speedbar-make-overlay (save-excursion (beginning-of-line) (point))
4024 (save-excursion (end-of-line)
4027 (speedbar-overlay-put speedbar-highlight-one-tag-line
'face
4028 'speedbar-highlight-face
)
4029 (add-hook 'pre-command-hook
'speedbar-unhighlight-one-tag-line
)
4032 (defun speedbar-unhighlight-one-tag-line ()
4033 "Unhighlight the currently highlighted line."
4034 (if speedbar-highlight-one-tag-line
4036 (speedbar-delete-overlay speedbar-highlight-one-tag-line
)
4037 (setq speedbar-highlight-one-tag-line nil
)))
4038 (remove-hook 'pre-command-hook
'speedbar-unhighlight-one-tag-line
))
4040 (defun speedbar-recenter-to-top ()
4041 "Recenter the current buffer so point is on the top of the window."
4044 (defun speedbar-recenter ()
4045 "Recenter the current buffer so point is in the center of the window."
4046 (recenter (/ (window-height (selected-window)) 2)))
4049 ;;; Color loading section.
4051 (defface speedbar-button-face
'((((class color
) (background light
))
4052 (:foreground
"green4"))
4053 (((class color
) (background dark
))
4054 (:foreground
"green3")))
4055 "Face used for +/- buttons."
4056 :group
'speedbar-faces
)
4058 (defface speedbar-file-face
'((((class color
) (background light
))
4059 (:foreground
"cyan4"))
4060 (((class color
) (background dark
))
4061 (:foreground
"cyan"))
4063 "Face used for file names."
4064 :group
'speedbar-faces
)
4066 (defface speedbar-directory-face
'((((class color
) (background light
))
4067 (:foreground
"blue4"))
4068 (((class color
) (background dark
))
4069 (:foreground
"light blue")))
4070 "Face used for directory names."
4071 :group
'speedbar-faces
)
4072 (defface speedbar-tag-face
'((((class color
) (background light
))
4073 (:foreground
"brown"))
4074 (((class color
) (background dark
))
4075 (:foreground
"yellow")))
4076 "Face used for displaying tags."
4077 :group
'speedbar-faces
)
4079 (defface speedbar-selected-face
'((((class color
) (background light
))
4080 (:foreground
"red" :underline t
))
4081 (((class color
) (background dark
))
4082 (:foreground
"red" :underline t
))
4084 "Face used to underline the file in the active window."
4085 :group
'speedbar-faces
)
4087 (defface speedbar-highlight-face
'((((class color
) (background light
))
4088 (:background
"green"))
4089 (((class color
) (background dark
))
4090 (:background
"sea green"))
4091 (((class grayscale monochrome
)
4093 (:background
"black"))
4094 (((class grayscale monochrome
)
4096 (:background
"white")))
4097 "Face used for highlighting buttons with the mouse."
4098 :group
'speedbar-faces
)
4100 (defface speedbar-separator-face
'((((class color
) (background light
))
4104 (((class color
) (background dark
))
4108 (((class grayscale monochrome
)
4110 (:background
"black"
4113 (((class grayscale monochrome
)
4115 (:background
"white"
4117 :overline
"black")))
4118 "Face used for separator labels in a display."
4119 :group
'speedbar-faces
)
4121 ;; some edebug hooks
4122 (add-hook 'edebug-setup-hook
4124 (def-edebug-spec speedbar-with-writable def-body
)))
4126 ;; Fix a font lock problem for some versions of Emacs
4127 (if (boundp 'font-lock-global-modes
)
4128 (if (listp font-lock-global-modes
)
4129 (add-to-list 'font-lock-global-modes
'(not speedbar-mode
))
4134 ;;; Obsolete variables and functions
4136 (define-obsolete-variable-alias
4137 'speedbar-ignored-path-regexp
'speedbar-ignored-directory-regexp
)
4139 (define-obsolete-function-alias 'speedbar-add-ignored-path-regexp
4140 'speedbar-add-ignored-directory-regexp
)
4142 (define-obsolete-function-alias 'speedbar-line-path
4143 'speedbar-line-directory
)
4145 (define-obsolete-function-alias 'speedbar-buffers-line-path
4146 'speedbar-buffers-line-directory
)
4148 (define-obsolete-function-alias 'speedbar-path-line
4149 'speedbar-directory-line
)
4151 (define-obsolete-function-alias 'speedbar-buffers-line-path
4152 'speedbar-buffers-line-directory
)
4156 ;; run load-time hooks
4157 (run-hooks 'speedbar-load-hook
)
4159 ;; arch-tag: 4477e6d1-f78c-48b9-a503-387d3c9767d5
4160 ;;; speedbar ends here