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 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 2, 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.
62 ;; - Timeout directories we haven't visited in a while.
69 ;; customization stuff
70 (defgroup speedbar nil
71 "File and tag browser frame."
78 (defgroup speedbar-faces nil
79 "Faces used in speedbar."
84 (defgroup speedbar-vc nil
85 "Version control display in speedbar."
91 ;; Note: `inversion-test' requires parts of the CEDET package that are
92 ;; not included with Emacs.
94 ;; (defun speedbar-require-version (major minor &optional beta)
95 ;; "Non-nil if this version of SPEEDBAR does not satisfy a specific version.
98 ;; (MAJOR MINOR &optional BETA)
100 ;; Values MAJOR and MINOR must be integers. BETA can be an integer, or
101 ;; excluded if a released version is required.
103 ;; It is assumed that if the current version is newer than that specified,
104 ;; everything passes. Exceptions occur when known incompatibilities are
106 ;; (inversion-test 'speedbar
107 ;; (concat major "." minor
108 ;; (when beta (concat "beta" beta)))))
110 (defvar speedbar-initial-expansion-mode-alist
111 '(("buffers" speedbar-buffer-easymenu-definition speedbar-buffers-key-map
112 speedbar-buffer-buttons
)
113 ("quick buffers" speedbar-buffer-easymenu-definition speedbar-buffers-key-map
114 speedbar-buffer-buttons-temp
)
115 ;; Files last, means first in the Displays menu
116 ("files" speedbar-easymenu-definition-special speedbar-file-key-map
117 speedbar-directory-buttons speedbar-default-directory-list
)
119 "List of named expansion elements for filling the speedbar frame.
120 These expansion lists are only valid for regular files. Special modes
121 still get to override this list on a mode-by-mode basis. This list of
122 lists is of the form (NAME MENU KEYMAP FN1 FN2 ...). NAME is a string
123 representing the types of things to be displayed. MENU is an easymenu
124 structure used when in this mode. KEYMAP is a local keymap to install
125 over the regular speedbar keymap. FN1 ... are functions that will be
126 called in order. These functions will always get the default
127 directory to use passed in as the first parameter, and a 0 as the
128 second parameter. The 0 indicates the uppermost indentation level.
129 They must assume that the cursor is at the position where they start
132 (defvar speedbar-initial-expansion-list-name
"files"
133 "A symbol name representing the expansion list to use.
134 The expansion list `speedbar-initial-expansion-mode-alist' contains
135 the names and associated functions to use for buttons in speedbar.")
137 (defvar speedbar-previously-used-expansion-list-name
"files"
138 "Save the last expansion list method.
139 This is used for returning to a previous expansion list method when
140 the user is done with the current expansion list.")
142 (defvar speedbar-stealthy-function-list
144 speedbar-update-current-file
145 speedbar-check-read-only
147 speedbar-check-objects
)
149 "List of functions to periodically call stealthily.
150 This list is of the form:
151 '( (\"NAME\" FUNCTION ...)
153 where NAME is the name of the major display mode these functions are
154 for, and the remaining elements FUNCTION are functions to call in order.
155 Each function must return nil if interrupted, or t if completed.
156 Stealthy functions which have a single operation should always return
157 t. Functions which take a long time should maintain a state (where
158 they are in their speedbar related calculations) and permit
159 interruption. See `speedbar-check-vc' as a good example.")
161 (defvar speedbar-mode-functions-list
162 '(("files" (speedbar-item-info . speedbar-files-item-info
)
163 (speedbar-line-directory . speedbar-files-line-directory
))
164 ("buffers" (speedbar-item-info . speedbar-buffers-item-info
)
165 (speedbar-line-directory . speedbar-buffers-line-directory
))
166 ("quick buffers" (speedbar-item-info . speedbar-buffers-item-info
)
167 (speedbar-line-directory . speedbar-buffers-line-directory
))
169 "List of function tables to use for different major display modes.
170 It is not necessary to define any functions for a specialized mode.
171 This just provides a simple way of adding lots of customizations.
172 Each sublist is of the form:
173 (\"NAME\" (FUNCTIONSYMBOL . REPLACEMENTFUNCTION) ...)
174 Where NAME is the name of the specialized mode. The rest of the list
175 is a set of dotted pairs of the form FUNCTIONSYMBOL, which is the name
176 of a function you would like to replace, and REPLACEMENTFUNCTION,
177 which is a function you can call instead. Not all functions can be
178 replaced this way. Replaceable functions must provide that
179 functionality individually.")
181 (defcustom speedbar-mode-specific-contents-flag t
182 "*Non-nil means speedbar will show special mode contents.
183 This permits some modes to create customized contents for the speedbar
188 (defcustom speedbar-query-confirmation-method
'all
189 "*Query control for file operations.
190 The 'always flag means to always query before file operations.
191 The 'none-but-delete flag means to not query before any file
192 operations, except before a file deletion."
194 :type
'(radio (const :tag
"Always Query before some file operations."
196 (const :tag
"Never Query before file operations, except for deletions."
198 ;;;; (const :tag "Never Every Query."
202 (defvar speedbar-special-mode-expansion-list nil
203 "Default function list for creating specialized button lists.
204 This list is set by modes that wish to have special speedbar displays.
205 The list is of function names. Each function is called with one
206 parameter BUFFER, the originating buffer. The current buffer is the
209 (defvar speedbar-special-mode-key-map nil
210 "Default keymap used when identifying a specialized display mode.
211 This keymap is local to each buffer that wants to define special keybindings
212 effective when its display is shown.")
214 (defcustom speedbar-before-visiting-file-hook
'(push-mark)
215 "*Hooks run before speedbar visits a file in the selected frame.
216 The default buffer is the buffer in the selected window in the attached frame."
220 (defcustom speedbar-visiting-file-hook nil
221 "*Hooks run when speedbar visits a file in the selected frame."
225 (defcustom speedbar-before-visiting-tag-hook
'(push-mark)
226 "*Hooks run before speedbar visits a tag in the selected frame.
227 The default buffer is the buffer in the selected window in the attached frame."
231 (defcustom speedbar-visiting-tag-hook
'(speedbar-highlight-one-tag-line)
232 "*Hooks run when speedbar visits a tag in the selected frame."
235 :options
'(speedbar-highlight-one-tag-line
236 speedbar-recenter-to-top
240 (defcustom speedbar-load-hook nil
241 "*Hooks run when speedbar is loaded."
245 (defcustom speedbar-reconfigure-keymaps-hook nil
246 "*Hooks run when the keymaps are regenerated."
250 (defcustom speedbar-show-unknown-files nil
251 "*Non-nil show files we can't expand with a ? in the expand button.
252 nil means don't show the file in the list."
256 ;;; EVENTUALLY REMOVE THESE
258 ;; When I moved to a repeating timer, I had the horrible missfortune
259 ;; of loosing the ability for adaptive speed choice. This update
260 ;; speed currently causes long delays when it should have been turned off.
261 (defvar speedbar-update-speed dframe-update-speed
262 "*Obsoleted variable. Use `dframe-update-speed'.")
264 (defvar speedbar-navigating-speed dframe-update-speed
265 "*Obsoleted variable. Use `dframe-update-speed'.")
268 (defcustom speedbar-frame-parameters
'((minibuffer . nil
)
276 "*Parameters to use when creating the speedbar frame in Emacs.
277 Any parameter supported by a frame may be added. The parameter `height'
278 will be initialized to the height of the frame speedbar is
279 attached to and added to this list before the new frame is initialized."
281 :type
'(repeat (cons :format
"%v"
282 (symbol :tag
"Parameter")
283 (sexp :tag
"Value"))))
285 ;; These values by Hrvoje Niksic <hniksic@srce.hr>
286 (defcustom speedbar-frame-plist
287 '(minibuffer nil width
20 border-width
0
288 internal-border-width
0 unsplittable t
289 default-toolbar-visible-p nil has-modeline-p nil
290 menubar-visible-p nil
291 default-gutter-visible-p nil
293 "*Parameters to use when creating the speedbar frame in XEmacs.
294 Parameters not listed here which will be added automatically are
295 `height' which will be initialized to the height of the frame speedbar
298 :type
'(repeat (group :inline t
299 (symbol :tag
"Property")
300 (sexp :tag
"Value"))))
302 (defcustom speedbar-use-imenu-flag
(fboundp 'imenu
)
303 "*Non-nil means use imenu for file parsing. nil to use etags.
304 XEmacs prior to 20.4 doesn't support imenu, therefore the default is to
305 use etags instead. Etags support is not as robust as imenu support."
306 :tag
"Use Imenu for tags"
310 (defvar speedbar-dynamic-tags-function-list
311 '((speedbar-fetch-dynamic-imenu . speedbar-insert-imenu-list
)
312 (speedbar-fetch-dynamic-etags . speedbar-insert-etags-list
))
313 "Set to a list of functions which will return and insert a list of tags.
314 Each element is of the form ( FETCH . INSERT ) where FETCH
315 is a function which takes one parameter (the file to tag) and returns a
316 list of tags. The tag list can be of any form as long as the
317 corresponding insert method can handle it. If it returns t, then an
318 error occurred, and the next fetch routine is tried.
319 INSERT is a function which takes an INDENTation level, and a LIST of
320 tags to insert. It will then create the speedbar buttons.")
322 (defcustom speedbar-use-tool-tips-flag
(and (not (featurep 'xemacs
))
323 (>= emacs-major-version
21))
324 "*Non-nil means to use tool tips if they are avaialble.
325 When tooltips are not available, mouse-tracking and minibuffer
326 display is used instead."
330 (defcustom speedbar-track-mouse-flag
(not speedbar-use-tool-tips-flag
)
331 "*Non-nil means to display info about the line under the mouse."
335 (defcustom speedbar-default-position
'left-right
336 "*Default position of the speedbar frame.
337 Possible values are 'left, 'right or 'left-right.
338 If value is 'left-right, the most suitable location is
339 determined automatically."
341 :type
'(radio (const :tag
"Automatic" left-right
)
342 (const :tag
"Left" left
)
343 (const :tag
"Right" right
)))
345 (defcustom speedbar-sort-tags nil
346 "*If non-nil, sort tags in the speedbar display. *Obsolete*.
347 Use `semantic-tag-hierarchy-method' instead."
351 (defcustom speedbar-tag-hierarchy-method
352 '(speedbar-prefix-group-tag-hierarchy
353 speedbar-trim-words-tag-hierarchy
)
354 "*List of hooks which speedbar will use to organize tags into groups.
355 Groups are defined as expandable meta-tags. Imenu supports
356 such things in some languages, such as separating variables from
357 functions. Each hook takes one argument LST, and may destructively
358 create a new list of the same form. LST is a list of elements of the
361 where each ELT is of the form
362 (TAG-NAME-STRING . NUMBER-OR-MARKER)
364 (GROUP-NAME-STRING ELT1 ELT2... ELTn)"
367 :options
'(speedbar-prefix-group-tag-hierarchy
368 speedbar-trim-words-tag-hierarchy
369 speedbar-simple-group-tag-hierarchy
370 speedbar-sort-tag-hierarchy
)
373 (defcustom speedbar-tag-group-name-minimum-length
4
374 "*The minimum length of a prefix group name before expanding.
375 Thus, if the `speedbar-tag-hierarchy-method' includes `prefix-group'
376 and one such groups common characters is less than this number of
377 characters, then the group name will be changed to the form of:
381 This way we won't get silly looking listings."
385 (defcustom speedbar-tag-split-minimum-length
20
386 "*Minimum length before we stop trying to create sub-lists in tags.
387 This is used by all tag-hierarchy methods that break large lists into
392 (defcustom speedbar-tag-regroup-maximum-length
10
393 "*Maximum length of submenus that are regrouped.
394 If the regrouping option is used, then if two or more short subgroups
395 are next to each other, then they are combined until this number of
400 (defcustom speedbar-directory-button-trim-method
'span
401 "*Indicates how the directory button will be displayed.
403 'span - span large directories over multiple lines.
404 'trim - trim large directories to only show the last few.
407 :type
'(radio (const :tag
"Span large directories over mutiple lines."
409 (const :tag
"Trim large directories to only show the last few."
411 (const :tag
"No trimming." nil
)))
413 (defcustom speedbar-smart-directory-expand-flag t
414 "*Non-nil means speedbar should use smart expansion.
415 Smart expansion only affects when speedbar wants to display a
416 directory for a file in the attached frame. When smart expansion is
417 enabled, new directories which are children of a displayed directory
418 are expanded in the current framework. If nil, then the current
419 hierarchy would be replaced with the new directory."
423 (defcustom speedbar-indentation-width
1
424 "*When sub-nodes are expanded, the number of spaces used for indentation."
428 (defcustom speedbar-hide-button-brackets-flag nil
429 "*Non-nil means speedbar will hide the brackets around the + or -."
433 (defcustom speedbar-before-popup-hook nil
434 "*Hooks called before popping up the speedbar frame."
438 (defcustom speedbar-after-create-hook
'(speedbar-frame-reposition-smartly)
439 "*Hooks called before popping up the speedbar frame."
443 (defcustom speedbar-before-delete-hook nil
444 "*Hooks called before deleting the speedbar frame."
448 (defcustom speedbar-mode-hook nil
449 "*Hooks called after creating a speedbar buffer."
453 (defcustom speedbar-timer-hook nil
454 "*Hooks called after running the speedbar timer function."
458 (defcustom speedbar-verbosity-level
1
459 "*Verbosity level of the speedbar. 0 means say nothing.
460 1 means medium level verbosity. 2 and higher are higher levels of
465 (defvar speedbar-indicator-separator
" "
466 "String separating file text from indicator characters.")
468 (defcustom speedbar-vc-do-check t
469 "*Non-nil check all files in speedbar to see if they have been checked out.
470 Any file checked out is marked with `speedbar-vc-indicator'."
474 (defvar speedbar-vc-indicator
"*"
475 "Text used to mark files which are currently checked out.
476 Other version control systems can be added by examining the function
477 `speedbar-vc-directory-enable-hook' and `speedbar-vc-in-control-hook'.")
479 (defcustom speedbar-vc-directory-enable-hook nil
480 "*Return non-nil if the current directory should be checked for Version Control.
481 Functions in this hook must accept one parameter which is the directory
486 (defcustom speedbar-vc-in-control-hook nil
487 "*Return non-nil if the specified file is under Version Control.
488 Functions in this hook must accept two parameters. The DIRECTORY of the
489 current file, and the FILENAME of the file being checked."
493 (defvar speedbar-vc-to-do-point nil
494 "Local variable maintaining the current version control check position.")
496 (defcustom speedbar-obj-do-check t
497 "*Non-nil check all files in speedbar to see if they have an object file.
498 Any file checked out is marked with `speedbar-obj-indicator', and the
499 marking is based on `speedbar-obj-alist'"
503 (defvar speedbar-obj-to-do-point nil
504 "Local variable maintaining the current version control check position.")
506 (defvar speedbar-obj-indicator
'("#" .
"!")
507 "Text used to mark files that have a corresponding hidden object file.
508 The car is for an up-to-date object. The cdr is for an out of date object.
509 The expression `speedbar-obj-alist' defines who gets tagged.")
511 (defvar speedbar-obj-alist
512 '(("\\.\\([cpC]\\|cpp\\|cc\\|cxx\\)$" .
".o")
514 ("\\.java$" .
".class")
515 ("\\.f\\(or\\|90\\|77\\)?$" .
".o")
517 ("\\.texi$" .
".info"))
518 "Alist of file extensions, and their corresponding object file type.")
520 (defvar speedbar-ro-to-do-point nil
521 "Local variable maintaining the current read only check position.")
523 (defvar speedbar-object-read-only-indicator
"%"
524 "Indicator to append onto a line if that item is Read Only.")
526 ;; Note: Look for addition place to add indicator lists that
527 ;; use skip-chars instead of a regular expression.
528 (defvar speedbar-indicator-regex
529 (concat (regexp-quote speedbar-indicator-separator
)
531 (regexp-quote speedbar-vc-indicator
)
533 (regexp-quote (car speedbar-obj-indicator
))
535 (regexp-quote (cdr speedbar-obj-indicator
))
537 (regexp-quote speedbar-object-read-only-indicator
)
539 "Regular expression used when identifying files.
540 Permits stripping of indicator characters from a line.")
542 (defcustom speedbar-scanner-reset-hook nil
543 "*Hook called whenever generic scanners are reset.
544 Set this to implement your own scanning / rescan safe functions with
549 (defvar speedbar-ignored-modes
'(fundamental-mode)
550 "*List of major modes which speedbar will not switch directories for.")
552 (defun speedbar-extension-list-to-regex (extlist)
553 "Takes EXTLIST, a list of extensions and transforms it into regexp.
554 All the preceding `.' are stripped for an optimized expression starting
555 with `.' followed by extensions, followed by full-filenames."
556 (let ((regex1 nil
) (regex2 nil
))
558 (if (= (string-to-char (car extlist
)) ?.
)
559 (setq regex1
(concat regex1
(if regex1
"\\|" "")
560 (substring (car extlist
) 1)))
561 (setq regex2
(concat regex2
(if regex2
"\\|" "") (car extlist
))))
562 (setq extlist
(cdr extlist
)))
563 ;; concat all the sub-exressions together, making sure all types
564 ;; of parts exist during concatination.
566 (if regex1
(concat "\\(\\.\\(" regex1
"\\)\\)") "")
567 (if (and regex1 regex2
) "\\|" "")
568 (if regex2
(concat "\\(" regex2
"\\)") "")
571 (defvar speedbar-ignored-directory-regexp nil
572 "Regular expression matching directorys speedbar will not switch to.
573 Created from `speedbar-ignored-directory-expressions' with the function
574 `speedbar-extension-list-to-regex' (A misnamed function in this case.)
575 Use the function `speedbar-add-ignored-directory-regexp', or customize the
576 variable `speedbar-ignored-directory-expressions' to modify this variable.")
578 (defcustom speedbar-ignored-directory-expressions
579 '("[/\\]logs?[/\\]\\'")
580 "*List of regular expressions matching directories speedbar will ignore.
581 They should included directorys to directories which are notoriously very
582 large and take a long time to load in. Use the function
583 `speedbar-add-ignored-directory-regexp' to add new items to this list after
584 speedbar is loaded. You may place anything you like in this list
585 before speedbar has been loaded."
587 :type
'(repeat (regexp :tag
"Directory Regexp"))
588 :set
(lambda (sym val
)
589 (setq speedbar-ignored-directory-expressions val
590 speedbar-ignored-directory-regexp
591 (speedbar-extension-list-to-regex val
))))
593 (defcustom speedbar-directory-unshown-regexp
"^\\(CVS\\|RCS\\|SCCS\\|\\..*\\)\\'"
594 "*Regular expression matching directories not to show in speedbar.
595 They should include commonly existing directories which are not
596 useful, such as version control."
600 (defvar speedbar-file-unshown-regexp
601 (let ((nstr "") (noext completion-ignored-extensions
))
603 (setq nstr
(concat nstr
(regexp-quote (car noext
)) "\\'"
604 (if (cdr noext
) "\\|" ""))
606 ;; backup refdir lockfile
607 (concat nstr
"\\|#[^#]+#$\\|\\.\\.?\\'\\|\\.#"))
608 "*Regexp matching files we don't want displayed in a speedbar buffer.
609 It is generated from the variable `completion-ignored-extensions'")
611 (defvar speedbar-file-regexp nil
612 "Regular expression matching files we know how to expand.
613 Created from `speedbar-supported-extension-expressions' with the
614 function `speedbar-extension-list-to-regex'")
616 ;; this is dangerous to customize, because the defaults will probably
617 ;; change in the future.
618 (defcustom speedbar-supported-extension-expressions
619 (append '(".[ch]\\(\\+\\+\\|pp\\|c\\|h\\|xx\\)?" ".tex\\(i\\(nfo\\)?\\)?"
620 ".el" ".emacs" ".l" ".lsp" ".p" ".java" ".f\\(90\\|77\\|or\\)?")
621 (if speedbar-use-imenu-flag
622 '(".ada" ".p[lm]" ".tcl" ".m" ".scm" ".pm" ".py" ".g"
623 ;; html is not supported by default, but an imenu tags package
624 ;; is available. Also, html files are nice to be able to see.
626 ".ma?k" "[Mm]akefile\\(\\.in\\)?")))
627 "*List of regular expressions which will match files supported by tagging.
628 Do not prefix the `.' char with a double \\ to quote it, as the period
629 will be stripped by a simplified optimizer when compiled into a
630 singular expression. This variable will be turned into
631 `speedbar-file-regexp' for use with speedbar. You should use the
632 function `speedbar-add-supported-extension' to add a new extension at
633 runtime, or use the configuration dialog to set it in your .emacs
635 If you add an extension to this list, and it does not appear, you may
636 need to also modify `completion-ignored-extension' which will also help
639 :type
'(repeat (regexp :tag
"Extension Regexp"))
640 :set
(lambda (sym val
)
641 (set 'speedbar-supported-extension-expressions val
)
642 (set 'speedbar-file-regexp
(speedbar-extension-list-to-regex val
))))
644 (setq speedbar-file-regexp
645 (speedbar-extension-list-to-regex speedbar-supported-extension-expressions
))
647 (defun speedbar-add-supported-extension (extension)
648 "Add EXTENSION as a new supported extension for speedbar tagging.
649 This should start with a `.' if it is not a complete file name, and
650 the dot should NOT be quoted in with \\. Other regular expression
651 matchers are allowed however. EXTENSION may be a single string or a
653 (interactive "sExtension: ")
654 (if (not (listp extension
)) (setq extension
(list extension
)))
656 (if (member (car extension
) speedbar-supported-extension-expressions
)
658 (setq speedbar-supported-extension-expressions
659 (cons (car extension
) speedbar-supported-extension-expressions
)))
660 (setq extension
(cdr extension
)))
661 (setq speedbar-file-regexp
(speedbar-extension-list-to-regex
662 speedbar-supported-extension-expressions
)))
664 (defun speedbar-add-ignored-directory-regexp (directory-expression)
665 "Add DIRECTORY-EXPRESSION as a new ignored directory for speedbar tracking.
666 This function will modify `speedbar-ignored-directory-regexp' and add
667 DIRECTORY-EXPRESSION to `speedbar-ignored-directory-expressions'."
668 (interactive "sDirectory regex: ")
669 (if (not (listp directory-expression
))
670 (setq directory-expression
(list directory-expression
)))
671 (while directory-expression
672 (if (member (car directory-expression
) speedbar-ignored-directory-expressions
)
674 (setq speedbar-ignored-directory-expressions
675 (cons (car directory-expression
) speedbar-ignored-directory-expressions
)))
676 (setq directory-expression
(cdr directory-expression
)))
677 (setq speedbar-ignored-directory-regexp
(speedbar-extension-list-to-regex
678 speedbar-ignored-directory-expressions
)))
680 ;; If we don't have custom, then we set it here by hand.
681 (if (not (fboundp 'custom-declare-variable
))
682 (setq speedbar-file-regexp
(speedbar-extension-list-to-regex
683 speedbar-supported-extension-expressions
)
684 speedbar-ignored-directory-regexp
(speedbar-extension-list-to-regex
685 speedbar-ignored-directory-expressions
)))
687 (defvar speedbar-update-flag dframe-have-timer-flag
688 "*Non-nil means to automatically update the display.
689 When this is nil then speedbar will not follow the attached frame's directory.
690 When speedbar is active, use:
692 \\<speedbar-key-map> `\\[speedbar-toggle-updates]'
694 to toggle this value.")
696 (defvar speedbar-update-flag-disable nil
697 "Permanently disable changing of the update flag.")
699 (defvar speedbar-syntax-table nil
700 "Syntax-table used on the speedbar.")
702 (if speedbar-syntax-table
704 (setq speedbar-syntax-table
(make-syntax-table))
705 ;; turn off paren matching around here.
706 (modify-syntax-entry ?
\' " " speedbar-syntax-table
)
707 (modify-syntax-entry ?
\" " " speedbar-syntax-table
)
708 (modify-syntax-entry ?
( " " speedbar-syntax-table
)
709 (modify-syntax-entry ?
) " " speedbar-syntax-table
)
710 (modify-syntax-entry ?
{ " " speedbar-syntax-table
)
711 (modify-syntax-entry ?
} " " speedbar-syntax-table
)
712 (modify-syntax-entry ?
[ " " speedbar-syntax-table
)
713 (modify-syntax-entry ?
] " " speedbar-syntax-table
))
715 (defvar speedbar-key-map nil
716 "Keymap used in speedbar buffer.")
720 (setq speedbar-key-map
(make-keymap))
721 (suppress-keymap speedbar-key-map t
)
724 (define-key speedbar-key-map
"t" 'speedbar-toggle-updates
)
725 (define-key speedbar-key-map
"g" 'speedbar-refresh
)
728 (define-key speedbar-key-map
"n" 'speedbar-next
)
729 (define-key speedbar-key-map
"p" 'speedbar-prev
)
730 (define-key speedbar-key-map
"\M-n" 'speedbar-restricted-next
)
731 (define-key speedbar-key-map
"\M-p" 'speedbar-restricted-prev
)
732 (define-key speedbar-key-map
"\C-\M-n" 'speedbar-forward-list
)
733 (define-key speedbar-key-map
"\C-\M-p" 'speedbar-backward-list
)
734 ;; These commands never seemed useful.
735 ;; (define-key speedbar-key-map " " 'speedbar-scroll-up)
736 ;; (define-key speedbar-key-map [delete] 'speedbar-scroll-down)
738 ;; Short cuts I happen to find useful
739 (define-key speedbar-key-map
"r"
740 (lambda () (interactive)
741 (speedbar-change-initial-expansion-list
742 speedbar-previously-used-expansion-list-name
)))
743 (define-key speedbar-key-map
"b"
744 (lambda () (interactive)
745 (speedbar-change-initial-expansion-list "quick buffers")))
746 (define-key speedbar-key-map
"f"
747 (lambda () (interactive)
748 (speedbar-change-initial-expansion-list "files")))
750 (dframe-update-keymap speedbar-key-map
)
753 (defun speedbar-make-specialized-keymap ()
754 "Create a keymap for use with a speedbar major or minor display mode.
755 This basically creates a sparse keymap, and makes it's parent be
757 (let ((k (make-sparse-keymap)))
758 (set-keymap-parent k speedbar-key-map
)
761 (defvar speedbar-file-key-map nil
762 "Keymap used in speedbar buffer while files are displayed.")
764 (if speedbar-file-key-map
766 (setq speedbar-file-key-map
(speedbar-make-specialized-keymap))
768 ;; Basic tree features
769 (define-key speedbar-file-key-map
"e" 'speedbar-edit-line
)
770 (define-key speedbar-file-key-map
"\C-m" 'speedbar-edit-line
)
771 (define-key speedbar-file-key-map
"+" 'speedbar-expand-line
)
772 (define-key speedbar-file-key-map
"=" 'speedbar-expand-line
)
773 (define-key speedbar-file-key-map
"-" 'speedbar-contract-line
)
775 (define-key speedbar-file-key-map
"[" 'speedbar-expand-line-descendants
)
776 (define-key speedbar-file-key-map
"]" 'speedbar-contract-line-descendants
)
778 (define-key speedbar-file-key-map
" " 'speedbar-toggle-line-expansion
)
780 ;; file based commands
781 (define-key speedbar-file-key-map
"U" 'speedbar-up-directory
)
782 (define-key speedbar-file-key-map
"I" 'speedbar-item-info
)
783 (define-key speedbar-file-key-map
"B" 'speedbar-item-byte-compile
)
784 (define-key speedbar-file-key-map
"L" 'speedbar-item-load
)
785 (define-key speedbar-file-key-map
"C" 'speedbar-item-copy
)
786 (define-key speedbar-file-key-map
"D" 'speedbar-item-delete
)
787 (define-key speedbar-file-key-map
"O" 'speedbar-item-object-delete
)
788 (define-key speedbar-file-key-map
"R" 'speedbar-item-rename
)
789 (define-key speedbar-file-key-map
"M" 'speedbar-create-directory
)
792 (defvar speedbar-easymenu-definition-base
795 ["Update" speedbar-refresh t
]
796 ["Auto Update" speedbar-toggle-updates
797 :active
(not speedbar-update-flag-disable
)
798 :style toggle
:selected speedbar-update-flag
])
799 (if (and (or (fboundp 'defimage
)
800 (fboundp 'make-image-specifier
))
801 (if (fboundp 'display-graphic-p
)
805 ["Use Images" speedbar-toggle-images
806 :style toggle
:selected speedbar-use-images
]))
808 "Base part of the speedbar menu.")
810 (defvar speedbar-easymenu-definition-special
811 '(["Edit Item On Line" speedbar-edit-line t
]
812 ["Show All Files" speedbar-toggle-show-all-files
813 :style toggle
:selected speedbar-show-unknown-files
]
814 ["Expand File Tags" speedbar-expand-line
815 (save-excursion (beginning-of-line)
816 (looking-at "[0-9]+: *.\\+. "))]
817 ["Flush Cache & Expand" speedbar-flush-expand-line
818 (save-excursion (beginning-of-line)
819 (looking-at "[0-9]+: *.\\+. "))]
820 ["Expand All Descendants" speedbar-expand-line-descendants
821 (save-excursion (beginning-of-line)
822 (looking-at "[0-9]+: *.\\+. ")) ]
823 ["Contract File Tags" speedbar-contract-line
824 (save-excursion (beginning-of-line)
825 (looking-at "[0-9]+: *.-. "))]
826 ; ["Sort Tags" speedbar-toggle-sorting
827 ; :style toggle :selected speedbar-sort-tags]
829 ["File/Tag Information" speedbar-item-info t
]
830 ["Load Lisp File" speedbar-item-load
833 (looking-at "[0-9]+: *\\[[+-]\\] .+\\(\\.el\\)\\( \\|$\\)"))]
834 ["Byte Compile File" speedbar-item-byte-compile
837 (looking-at "[0-9]+: *\\[[+-]\\] .+\\(\\.el\\)\\( \\|$\\)"))]
838 ["Copy File" speedbar-item-copy
839 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *\\["))]
840 ["Rename File" speedbar-item-rename
841 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
842 ["Create Directory" speedbar-create-directory
843 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
844 ["Delete File" speedbar-item-delete
845 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
846 ["Delete Object" speedbar-item-object-delete
847 (save-excursion (beginning-of-line)
848 (looking-at "[0-9]+: *\\[[+-]\\] [^ \n]+ \\*?[!#]$"))]
850 "Additional menu items while in file-mode.")
852 (defvar speedbar-easymenu-definition-trailer
854 (if (and (featurep 'custom
) (fboundp 'custom-declare-variable
))
855 (list ["Customize..." speedbar-customize t
]))
857 ["Detach" speedbar-detach
(and speedbar-frame
858 (eq (selected-frame) speedbar-frame
)) ]
859 ["Close" dframe-close-frame t
]
860 ["Quit" delete-frame t
] ))
861 "Menu items appearing at the end of the speedbar menu.")
863 (defvar speedbar-desired-buffer nil
864 "Non-nil when speedbar is showing buttons specific to a special mode.
865 In this case it is the originating buffer.")
866 (defvar speedbar-buffer nil
867 "The buffer displaying the speedbar.")
868 (defvar speedbar-frame nil
869 "The frame displaying speedbar.")
870 (defvar speedbar-cached-frame nil
871 "The frame that was last created, then removed from the display.")
872 (defvar speedbar-full-text-cache nil
873 "The last open directory is saved in its entirety for ultra-fast switching.")
875 (defvar speedbar-last-selected-file nil
876 "The last file which was selected in speedbar buffer.")
878 (defvar speedbar-shown-directories nil
879 "Maintain list of directories simultaneously open in the current speedbar.")
881 (defvar speedbar-directory-contents-alist nil
882 "An association list of directories and their contents.
883 Each sublist was returned by `speedbar-file-lists'. This list is
884 maintained to speed up the refresh rate when switching between
887 (defvar speedbar-power-click nil
888 "Never set this by hand. Value is t when S-mouse activity occurs.")
893 (defalias 'speedbar-make-overlay
894 (if (featurep 'xemacs
) 'make-extent
'make-overlay
))
896 (defalias 'speedbar-overlay-put
897 (if (featurep 'xemacs
) 'set-extent-property
'overlay-put
))
899 (defalias 'speedbar-delete-overlay
900 (if (featurep 'xemacs
) 'delete-extent
'delete-overlay
))
902 (defalias 'speedbar-mode-line-update
903 (if (featurep 'xemacs
) 'redraw-modeline
'force-mode-line-update
))
905 ;;; Mode definitions/ user commands
909 (defalias 'speedbar
'speedbar-frame-mode
)
911 (defun speedbar-frame-mode (&optional arg
)
912 "Enable or disable speedbar. Positive ARG means turn on, negative turn off.
913 nil means toggle. Once the speedbar frame is activated, a buffer in
914 `speedbar-mode' will be displayed. Currently, only one speedbar is
916 `speedbar-before-popup-hook' is called before popping up the speedbar frame.
917 `speedbar-before-delete-hook' is called before the frame is deleted."
919 ;; Get the buffer to play with
920 (if (not (buffer-live-p speedbar-buffer
))
922 (setq speedbar-buffer
(get-buffer-create " SPEEDBAR"))
923 (set-buffer speedbar-buffer
)
925 ;; Do the frame thing
926 (dframe-frame-mode arg
928 'speedbar-cached-frame
931 #'speedbar-frame-mode
933 (append speedbar-frame-plist
934 ;; This is a hack to get speedbar to iconfiy
935 ;; with the selected frame.
936 (list 'parent
(selected-frame)))
937 speedbar-frame-parameters
)
938 speedbar-before-delete-hook
939 speedbar-before-popup-hook
940 speedbar-after-create-hook
)
941 ;; Start up the timer
942 (if (not speedbar-frame
)
943 (speedbar-set-timer nil
)
944 (speedbar-reconfigure-keymaps)
945 (speedbar-update-contents)
946 (speedbar-set-timer dframe-update-speed
)
948 ;; Frame modifications
949 (set (make-local-variable 'dframe-delete-frame-function
)
950 'speedbar-handle-delete-frame
)
952 (set (make-local-variable 'automatic-hscrolling
) nil
) ; Emacs 21
953 ;; reset the selection variable
954 (setq speedbar-last-selected-file nil
))
956 (defun speedbar-frame-reposition-smartly ()
957 "Reposition the speedbar frame to be next to the attached frame."
958 (cond ((and dframe-xemacsp
959 (or (member 'left speedbar-frame-plist
)
960 (member 'top speedbar-frame-plist
)))
961 (dframe-reposition-frame
963 (dframe-attached-frame speedbar-frame
)
964 (cons (car (cdr (member 'left speedbar-frame-plist
)))
965 (car (cdr (member 'top speedbar-frame-plist
)))))
967 ((and (not dframe-xemacsp
)
968 (or (assoc 'left speedbar-frame-parameters
)
969 (assoc 'top speedbar-frame-parameters
)))
970 ;; if left/top were specified in the parameters, pass them
971 ;; down to the reposition function
972 (dframe-reposition-frame
974 (dframe-attached-frame speedbar-frame
)
975 (cons (cdr (assoc 'left speedbar-frame-parameters
))
976 (cdr (assoc 'top speedbar-frame-parameters
))))
979 (dframe-reposition-frame speedbar-frame
980 (dframe-attached-frame speedbar-frame
)
981 speedbar-default-position
))))
983 (defun speedbar-detach ()
984 "Detach the current Speedbar from auto-updating.
985 Doing this allows the creation of a second speedbar."
987 (let ((buffer speedbar-buffer
))
988 (dframe-detach 'speedbar-frame
'speedbar-cached-frame
'speedbar-buffer
)
991 ;; Permanently disable auto-updating in this speedbar buffer.
992 (set (make-local-variable 'speedbar-update-flag
) nil
)
993 (set (make-local-variable 'speedbar-update-flag-disable
) t
)
994 ;; Make local copies of all the different variables to prevent
995 ;; funny stuff later...
998 (defsubst speedbar-current-frame
()
999 "Return the frame to use for speedbar based on current context."
1000 (dframe-current-frame 'speedbar-frame
'speedbar-mode
))
1002 (defun speedbar-handle-delete-frame (e)
1003 "Handle a delete frame event E.
1004 If the deleted frame is the frame SPEEDBAR is attached to,
1005 we need to delete speedbar also."
1006 (let ((frame-to-be-deleted (car (car (cdr e
)))))
1007 (if (eq frame-to-be-deleted dframe-attached-frame
)
1008 (delete-frame speedbar-frame
)))
1012 (defun speedbar-get-focus ()
1013 "Change frame focus to or from the speedbar frame.
1014 If the selected frame is not speedbar, then speedbar frame is
1015 selected. If the speedbar frame is active, then select the attached frame."
1017 (speedbar-reset-scanners)
1018 (dframe-get-focus 'speedbar-frame
'speedbar-frame-mode
1019 (lambda () (let ((speedbar-update-flag t
))
1020 (speedbar-timer-fn)))))
1022 (defsubst speedbar-frame-width
()
1023 "Return the width of the speedbar frame in characters.
1024 nil if it doesn't exist."
1025 (frame-width speedbar-frame
))
1027 (defun speedbar-mode ()
1028 "Major mode for managing a display of directories and tags.
1029 \\<speedbar-key-map>
1030 The first line represents the default directory of the speedbar frame.
1031 Each directory segment is a button which jumps speedbar's default
1032 directory to that directory. Buttons are activated by clicking `\\[speedbar-click]'.
1033 In some situations using `\\[dframe-power-click]' is a `power click' which will
1034 rescan cached items, or pop up new frames.
1036 Each line starting with <+> represents a directory. Click on the <+>
1037 to insert the directory listing into the current tree. Click on the
1038 <-> to retract that list. Click on the directory name to go to that
1039 directory as the default.
1041 Each line starting with [+] is a file. If the variable
1042 `speedbar-show-unknown-files' is t, the lines starting with [?] are
1043 files which don't have imenu support, but are not expressly ignored.
1044 Files are completely ignored if they match `speedbar-file-unshown-regexp'
1045 which is generated from `completion-ignored-extensions'.
1047 Files with a `*' character after their name are files checked out of a
1048 version control system. (Currently only RCS is supported.) New
1049 version control systems can be added by examining the documentation
1050 for `speedbar-this-file-in-vc' and `speedbar-vc-check-dir-p'.
1052 Files with a `#' or `!' character after them are source files that
1053 have an object file associated with them. The `!' indicates that the
1054 files is out of date. You can control what source/object associations
1055 exist through the variable `speedbar-obj-alist'.
1057 Click on the [+] to display a list of tags from that file. Click on
1058 the [-] to retract the list. Click on the file name to edit the file
1059 in the attached frame.
1061 If you open tags, you might find a node starting with {+}, which is a
1062 category of tags. Click the {+} to expand the category. Jump-able
1063 tags start with >. Click the name of the tag to go to that position
1064 in the selected file.
1066 \\{speedbar-key-map}"
1069 (kill-all-local-variables)
1070 (setq major-mode
'speedbar-mode
)
1071 (setq mode-name
"Speedbar")
1072 (set-syntax-table speedbar-syntax-table
)
1073 (setq font-lock-keywords nil
) ;; no font-locking please
1074 (setq truncate-lines t
)
1075 (make-local-variable 'frame-title-format
)
1076 (setq frame-title-format
(concat "Speedbar " speedbar-version
))
1077 (setq case-fold-search nil
)
1078 (toggle-read-only 1)
1079 (speedbar-set-mode-line-format)
1080 ;; Add in our dframe hooks.
1081 (if speedbar-track-mouse-flag
1082 (setq dframe-track-mouse-function
#'speedbar-track-mouse
))
1083 (setq dframe-help-echo-function
#'speedbar-item-info
1084 dframe-mouse-click-function
#'speedbar-click
1085 dframe-mouse-position-function
#'speedbar-position-cursor-on-line
)
1086 (run-hooks 'speedbar-mode-hook
))
1089 (defmacro speedbar-message
(fmt &rest args
)
1090 "Like message, but for use in the speedbar frame.
1091 Argument FMT is the format string, and ARGS are the arguments for message."
1092 `(dframe-message ,fmt
,@args
))
1094 (defsubst speedbar-y-or-n-p
(prompt &optional deleting
)
1095 "Like `y-or-n-p', but for use in the speedbar frame.
1096 Argument PROMPT is the prompt to use.
1097 Optional argument DELETING means this is a query that will delete something.
1098 The variable `speedbar-query-confirmation-method' can cause this to
1099 return true without a query."
1100 (or (and (not deleting
)
1101 (eq speedbar-query-confirmation-method
'none-but-delete
))
1102 (dframe-y-or-n-p prompt
)))
1104 (defsubst speedbar-select-attached-frame
()
1105 "Select the frame attached to this speedbar."
1106 (dframe-select-attached-frame (speedbar-current-frame)))
1108 ;; Backwards compatibility
1109 (defalias 'speedbar-with-attached-buffer
'dframe-with-attached-buffer
)
1110 (defalias 'speedbar-maybee-jump-to-attached-frame
'dframe-maybee-jump-to-attached-frame
)
1112 (defun speedbar-set-mode-line-format ()
1113 "Set the format of the mode line based on the current speedbar environment.
1114 This gives visual indications of what is up. It EXPECTS the speedbar
1115 frame and window to be the currently active frame and window."
1116 (if (and (frame-live-p (speedbar-current-frame))
1117 (or (not dframe-xemacsp
)
1119 (specifier-instance has-modeline-p
)))
1122 (set-buffer speedbar-buffer
)
1123 (let* ((w (or (speedbar-frame-width) 20))
1126 (p3 (if speedbar-update-flag
"#" "!"))
1127 (p35 (capitalize speedbar-initial-expansion-list-name
))
1128 (blank (- w
(length p1
) (length p3
) (length p5
) (length p35
)
1129 (if line-number-mode
5 1)))
1131 (make-string (/ blank
2) ?
)
1134 (make-string (+ (/ blank
2) (% blank
2)) ?
)
1137 (if line-number-mode
1138 (list (concat p1 p2 p3
" " p35
) '(line-number-mode " %3l")
1140 (list (concat p1 p2 p3 p4 p5
)))))
1141 (if (not (equal mode-line-format tf
))
1143 (setq mode-line-format tf
)
1144 (speedbar-mode-line-update)))))))
1146 (defvar speedbar-previous-menu nil
1147 "The menu before the last `speedbar-reconfigure-keymaps' was called.")
1149 (defun speedbar-reconfigure-keymaps ()
1150 "Reconfigure the menu-bar in a speedbar frame.
1151 Different menu items are displayed depending on the current display mode
1152 and the existence of packages."
1154 speedbar-easymenu-definition-base
1155 (if speedbar-shown-directories
1156 ;; file display mode version
1157 (speedbar-initial-menu)
1159 (dframe-select-attached-frame speedbar-frame
)
1160 (if (local-variable-p
1161 'speedbar-easymenu-definition-special
1163 ;; If bound locally, we can use it
1164 speedbar-easymenu-definition-special
)))
1165 ;; Dynamic menu stuff
1167 (list (cons "Displays"
1168 (let ((displays nil
)
1169 (alist speedbar-initial-expansion-mode-alist
))
1174 (capitalize (car (car alist
)))
1176 'speedbar-change-initial-expansion-list
1180 `(string= ,(car (car alist
))
1181 speedbar-initial-expansion-list-name
)
1184 (setq alist
(cdr alist
)))
1187 speedbar-easymenu-definition-trailer
))
1188 (localmap (save-excursion
1189 (let ((cf (selected-frame)))
1191 (dframe-select-attached-frame speedbar-frame
)
1192 (if (local-variable-p
1193 'speedbar-special-mode-key-map
1195 speedbar-special-mode-key-map
)
1196 (select-frame cf
))))))
1198 (set-buffer speedbar-buffer
)
1199 (use-local-map (or localmap
1200 (speedbar-initial-keymap)
1201 ;; This creates a small keymap we can glom the
1202 ;; menu adjustments into.
1203 (speedbar-make-specialized-keymap)))
1204 ;; Delete the old menu if applicable.
1205 (if speedbar-previous-menu
(easy-menu-remove speedbar-previous-menu
))
1206 (setq speedbar-previous-menu md
)
1207 ;; Now add the new menu
1208 (if (not dframe-xemacsp
)
1209 (easy-menu-define speedbar-menu-map
(current-local-map)
1211 (easy-menu-add md
(current-local-map))
1213 (if (fboundp 'set-buffer-menubar
)
1214 (set-buffer-menubar (list md
)))))
1216 (run-hooks 'speedbar-reconfigure-keymaps-hook
)))
1219 ;;; User Input stuff
1221 (defun speedbar-customize ()
1222 "Customize speedbar using the Custom package."
1224 (let ((sf (selected-frame)))
1225 (dframe-select-attached-frame speedbar-frame
)
1226 (customize-group 'speedbar
)
1228 (dframe-maybee-jump-to-attached-frame))
1230 (defun speedbar-track-mouse (event)
1231 "For motion EVENT, display info about the current line."
1232 (if (not speedbar-track-mouse-flag
)
1235 (save-window-excursion
1238 (mouse-set-point event
)
1239 (if (eq major-mode
'speedbar-mode
)
1240 ;; XEmacs may let us get in here in other mode buffers.
1241 (speedbar-item-info)))
1242 (t (speedbar-message nil
)))))))
1244 (defun speedbar-show-info-under-mouse ()
1245 "Call the info function for the line under the mouse.
1246 Optional EVENT is currently not used."
1247 (let ((pos (mouse-position))) ; we ignore event until I use it later.
1248 (if (equal (car pos
) speedbar-frame
)
1250 (save-window-excursion
1251 (apply 'set-mouse-position pos
)
1252 (speedbar-item-info))))))
1254 (defun speedbar-next (arg)
1255 "Move to the next ARGth line in a speedbar buffer."
1257 (forward-line (or arg
1))
1258 (speedbar-item-info)
1259 (speedbar-position-cursor-on-line))
1261 (defun speedbar-prev (arg)
1262 "Move to the previous ARGth line in a speedbar buffer."
1264 (speedbar-next (if arg
(- arg
) -
1)))
1266 (defun speedbar-restricted-move (arg)
1267 "Move to the next ARGth line in a speedbar buffer at the same depth.
1268 This means that movement is restricted to a subnode, and that siblings
1269 of intermediate nodes are skipped."
1270 (if (not (numberp arg
)) (signal 'wrong-type-argument
(list arg
'numberp
)))
1271 ;; First find the extent for which we are allowed to move.
1272 (let ((depth (save-excursion (beginning-of-line)
1273 (if (looking-at "[0-9]+:")
1274 (string-to-number (match-string 0))
1276 (crement (if (< arg
0) 1 -
1)) ; decrement or increment
1277 (lastmatch (point)))
1279 (forward-line (- crement
))
1280 (let ((subdepth (save-excursion (beginning-of-line)
1281 (if (looking-at "[0-9]+:")
1282 (string-to-number (match-string 0))
1284 (cond ((or (< subdepth depth
)
1285 (progn (end-of-line) (eobp))
1286 (progn (beginning-of-line) (bobp)))
1287 ;; We have reached the end of this block.
1288 (goto-char lastmatch
)
1290 (error "End of sub-list"))
1292 (setq lastmatch
(point)
1293 arg
(+ arg crement
))))))
1294 (speedbar-position-cursor-on-line)))
1296 (defun speedbar-restricted-next (arg)
1297 "Move to the next ARGth line in a speedbar buffer at the same depth.
1298 This means that movement is restricted to a subnode, and that siblings
1299 of intermediate nodes are skipped."
1301 (speedbar-restricted-move (or arg
1))
1302 (speedbar-item-info))
1304 (defun speedbar-restricted-prev (arg)
1305 "Move to the previous ARGth line in a speedbar buffer at the same depth.
1306 This means that movement is restricted to a subnode, and that siblings
1307 of intermediate nodes are skipped."
1309 (speedbar-restricted-move (if arg
(- arg
) -
1))
1310 (speedbar-item-info))
1312 (defun speedbar-navigate-list (arg)
1313 "Move across ARG groups of similarly typed items in speedbar.
1314 Stop on the first line of the next type of item, or on the last or first item
1315 if we reach a buffer boundary."
1318 (if (looking-at "[0-9]+: *[[<{][-+?][]>}] ")
1319 (let ((str (regexp-quote (match-string 0))))
1320 (while (looking-at str
)
1321 (speedbar-restricted-move arg
)
1322 (beginning-of-line))))
1323 (speedbar-position-cursor-on-line))
1325 (defun speedbar-forward-list ()
1326 "Move forward over the current list.
1327 A LIST in speedbar is a group of similarly typed items, such as directories,
1328 files, or the directory button."
1330 (speedbar-navigate-list 1)
1331 (speedbar-item-info))
1333 (defun speedbar-backward-list ()
1334 "Move backward over the current list.
1335 A LIST in speedbar is a group of similarly typed items, such as directories,
1336 files, or the directory button."
1338 (speedbar-navigate-list -
1)
1339 (speedbar-item-info))
1341 (defun speedbar-scroll-up (&optional arg
)
1342 "Page down one screen-full of the speedbar, or ARG lines."
1345 (speedbar-position-cursor-on-line))
1347 (defun speedbar-scroll-down (&optional arg
)
1348 "Page up one screen-full of the speedbar, or ARG lines."
1351 (speedbar-position-cursor-on-line))
1353 (defun speedbar-up-directory ()
1354 "Keyboard accelerator for moving the default directory up one.
1355 Assumes that the current buffer is the speedbar buffer."
1357 (setq default-directory
(expand-file-name (concat default-directory
"../")))
1358 (speedbar-update-contents))
1360 ;;; Speedbar file activity (aka creeping featurism)
1362 (defun speedbar-refresh (&optional arg
)
1363 "Refresh the current speedbar display, disposing of any cached data.
1364 Argument ARG represents to force a refresh past any caches that may exist."
1366 (let ((dl speedbar-shown-directories
)
1367 (dframe-power-click arg
)
1369 ;; We need to hack something so this works in detached frames.
1371 (adelete 'speedbar-directory-contents-alist
(car dl
))
1373 (if (<= 1 speedbar-verbosity-level
)
1374 (speedbar-message "Refreshing speedbar..."))
1375 (speedbar-update-contents)
1376 (speedbar-stealthy-updates)
1377 ;; Reset the timer in case it got really hosed for some reason...
1378 (speedbar-set-timer dframe-update-speed
)
1379 (if (<= 1 speedbar-verbosity-level
)
1380 (speedbar-message "Refreshing speedbar...done"))))
1382 (defun speedbar-item-load ()
1383 "Load the item under the cursor or mouse if it is a Lisp file."
1385 (let ((f (speedbar-line-file)))
1386 (if (and (file-exists-p f
) (string-match "\\.el\\'" f
))
1387 (if (and (file-exists-p (concat f
"c"))
1388 (speedbar-y-or-n-p (format "Load %sc? " f
)))
1389 ;; If the compiled version exists, load that instead...
1390 (load-file (concat f
"c"))
1392 (error "Not a loadable file"))))
1394 (defun speedbar-item-byte-compile ()
1395 "Byte compile the item under the cursor or mouse if it is a Lisp file."
1397 (let ((f (speedbar-line-file))
1398 (sf (selected-frame)))
1399 (if (and (file-exists-p f
) (string-match "\\.el\\'" f
))
1401 (dframe-select-attached-frame speedbar-frame
)
1402 (byte-compile-file f nil
)
1404 (speedbar-reset-scanners)))
1407 (defun speedbar-mouse-item-info (event)
1408 "Provide information about what the user clicked on.
1409 This should be bound to a mouse EVENT."
1411 (mouse-set-point event
)
1412 (speedbar-item-info))
1414 (defun speedbar-generic-item-info ()
1415 "Attempt to derive, and then display information about this line item.
1416 File style information is displayed with `speedbar-item-info'."
1419 ;; Skip invisible number info.
1420 (if (looking-at "\\([0-9]+\\):") (goto-char (match-end 0)))
1421 ;; Skip items in "folder" type text characters.
1422 (if (looking-at "\\s-*[[<({].[]>)}] ") (goto-char (match-end 0)))
1424 (speedbar-message "Text: %s" (buffer-substring-no-properties
1425 (point) (progn (end-of-line) (point))))))
1427 (defun speedbar-item-info ()
1428 "Display info in the mini-buffer about the button the mouse is over.
1429 This function can be replaced in `speedbar-mode-functions-list' as
1430 `speedbar-item-info'."
1432 (let (message-log-max)
1433 (funcall (or (speedbar-fetch-replacement-function 'speedbar-item-info
)
1434 'speedbar-generic-item-info
))))
1436 (defun speedbar-item-info-file-helper (&optional filename
)
1437 "Display info about a file that is on the current line.
1438 nil if not applicable. If FILENAME, then use that instead of reading
1439 it from the speedbar buffer."
1440 (let* ((item (or filename
(speedbar-line-file)))
1441 (attr (if item
(file-attributes item
) nil
)))
1442 (if (and item attr
) (speedbar-message "%s %-6d %s" (nth 8 attr
)
1446 (defun speedbar-item-info-tag-helper ()
1447 "Display info about a tag that is on the current line.
1448 nil if not applicable."
1451 (if (re-search-forward " [-+=]?> \\([^\n]+\\)"
1452 (save-excursion(end-of-line)(point)) t
)
1453 (let* ((tag (match-string 1))
1454 (attr (speedbar-line-token))
1456 (semantic-tagged (if (fboundp 'semantic-tag-p
)
1457 (semantic-tag-p attr
))))
1461 (when (and (semantic-tag-overlay attr
)
1462 (semantic-tag-buffer attr
))
1463 (set-buffer (semantic-tag-buffer attr
)))
1465 (funcall semantic-sb-info-format-tag-function attr
)
1467 (looking-at "\\([0-9]+\\):")
1468 (setq item
(file-name-nondirectory (speedbar-line-directory)))
1469 (speedbar-message "Tag: %s in %s" tag item
)))
1470 (if (re-search-forward "{[+-]} \\([^\n]+\\)$"
1471 (save-excursion(end-of-line)(point)) t
)
1472 (speedbar-message "Group of tags \"%s\"" (match-string 1))
1473 (if (re-search-forward " [+-]?[()|@] \\([^\n]+\\)$" nil t
)
1474 (let* ((detailtext (match-string 1))
1475 (detail (or (speedbar-line-token) detailtext
))
1476 (parent (save-excursion
1478 (let ((dep (if (looking-at "[0-9]+:")
1479 (1- (string-to-number (match-string 0)))
1481 (re-search-backward (concat "^"
1485 (if (looking-at "[0-9]+: +[-+=>]> \\([^\n]+\\)$")
1486 (speedbar-line-token)
1488 (if (featurep 'semantic
)
1490 (if (semantic-tag-p detail
)
1492 (funcall semantic-sb-info-format-tag-function detail parent
))
1494 (speedbar-message "Detail: %s of tag %s" detail
1495 (if (semantic-tag-p parent
)
1496 (semantic-format-tag-name parent nil t
)
1498 (speedbar-message "Detail: %s" detail
))))
1499 ;; Not using `semantic':
1501 (speedbar-message "Detail: %s of tag %s" detail parent
)
1502 (speedbar-message "Detail: %s" detail
))))
1505 (defun speedbar-files-item-info ()
1506 "Display info in the mini-buffer about the button the mouse is over."
1507 (if (not speedbar-shown-directories
)
1508 (speedbar-generic-item-info)
1509 (or (speedbar-item-info-file-helper)
1510 (speedbar-item-info-tag-helper)
1511 (speedbar-generic-item-info))))
1513 (defun speedbar-item-copy ()
1514 "Copy the item under the cursor.
1515 Files can be copied to new names or places."
1517 (let ((f (speedbar-line-file)))
1518 (if (not f
) (error "Not a file"))
1519 (if (file-directory-p f
)
1520 (error "Cannot copy directory")
1521 (let* ((rt (read-file-name (format "Copy %s to: "
1522 (file-name-nondirectory f
))
1523 (file-name-directory f
)))
1524 (refresh (member (expand-file-name (file-name-directory rt
))
1525 speedbar-shown-directories
)))
1526 ;; Create the right file name part
1527 (if (file-directory-p rt
)
1529 (concat (expand-file-name rt
)
1530 (if (string-match "[/\\]$" rt
) "" "/")
1531 (file-name-nondirectory f
))))
1532 (if (or (not (file-exists-p rt
))
1533 (speedbar-y-or-n-p (format "Overwrite %s with %s? " rt f
)
1536 (copy-file f rt t t
)
1537 ;; refresh display if the new place is currently displayed.
1541 (if (not (speedbar-goto-this-file rt
))
1542 (speedbar-goto-this-file f
))))
1545 (defun speedbar-item-rename ()
1546 "Rename the item under the cursor or mouse.
1547 Files can be renamed to new names or moved to new directories."
1549 (let ((f (speedbar-line-file)))
1551 (let* ((rt (read-file-name (format "Rename %s to: "
1552 (file-name-nondirectory f
))
1553 (file-name-directory f
)))
1554 (refresh (member (expand-file-name (file-name-directory rt
))
1555 speedbar-shown-directories
)))
1556 ;; Create the right file name part
1557 (if (file-directory-p rt
)
1559 (concat (expand-file-name rt
)
1560 (if (string-match "[/\\]\\'" rt
) "" "/")
1561 (file-name-nondirectory f
))))
1562 (if (or (not (file-exists-p rt
))
1563 (speedbar-y-or-n-p (format "Overwrite %s with %s? " rt f
)
1566 (rename-file f rt t
)
1567 ;; refresh display if the new place is currently displayed.
1571 (speedbar-goto-this-file rt
)
1573 (error "Not a file"))))
1575 (defun speedbar-create-directory ()
1576 "Create a directory in speedbar."
1578 (let ((f (speedbar-line-file)))
1580 (let* ((basedir (file-name-directory f
))
1581 (nd (read-file-name "Create directory: "
1583 ;; Make the directory
1584 (make-directory nd t
)
1586 (speedbar-goto-this-file nd
)
1588 (error "Not a file"))))
1590 (defun speedbar-item-delete ()
1591 "Delete the item under the cursor. Files are removed from disk."
1593 (let ((f (speedbar-line-file)))
1594 (if (not f
) (error "Not a file"))
1595 (if (speedbar-y-or-n-p (format "Delete %s? " f
) t
)
1597 (if (file-directory-p f
)
1598 (delete-directory f
)
1600 (speedbar-message "Okie dokie..")
1607 (defun speedbar-item-object-delete ()
1608 "Delete the object associated from the item under the cursor.
1609 The file is removed from disk. The object is determined from the
1610 variable `speedbar-obj-alist'."
1612 (let* ((f (speedbar-line-file))
1614 (oa speedbar-obj-alist
))
1615 (if (not f
) (error "Not a file"))
1616 (while (and oa
(not (string-match (car (car oa
)) f
)))
1618 (setq obj
(concat (file-name-sans-extension f
) (cdr (car oa
))))
1619 (if (and oa
(file-exists-p obj
)
1620 (speedbar-y-or-n-p (format "Delete %s? " obj
) t
))
1623 (speedbar-reset-scanners)))))
1625 (defun speedbar-enable-update ()
1626 "Enable automatic updating in speedbar via timers."
1628 (setq speedbar-update-flag t
)
1629 (speedbar-set-mode-line-format)
1630 (speedbar-set-timer dframe-update-speed
))
1632 (defun speedbar-disable-update ()
1633 "Disable automatic updating and stop consuming resources."
1635 (setq speedbar-update-flag nil
)
1636 (speedbar-set-mode-line-format)
1637 (speedbar-set-timer nil
))
1639 (defun speedbar-toggle-updates ()
1640 "Toggle automatic update for the speedbar frame."
1642 (if speedbar-update-flag
1643 (speedbar-disable-update)
1644 (speedbar-enable-update)))
1646 (defun speedbar-toggle-images ()
1647 "Toggle use of images in the speedbar frame.
1648 Images are not available in Emacs 20 or earlier."
1650 (setq speedbar-use-images
(not speedbar-use-images
))
1653 (defun speedbar-toggle-sorting ()
1654 "Toggle tag sorting."
1656 (setq speedbar-sort-tags
(not speedbar-sort-tags
)))
1658 (defun speedbar-toggle-show-all-files ()
1659 "Toggle display of files speedbar can not tag."
1661 (setq speedbar-show-unknown-files
(not speedbar-show-unknown-files
))
1664 (defmacro speedbar-with-writable
(&rest forms
)
1665 "Allow the buffer to be writable and evaluate FORMS."
1666 (list 'let
'((inhibit-read-only t
))
1667 (cons 'progn forms
)))
1668 (put 'speedbar-with-writable
'lisp-indent-function
0)
1670 (defun speedbar-insert-button (text face mouse function
1671 &optional token prevline
)
1672 "Insert TEXT as the next logical speedbar button.
1673 FACE is the face to put on the button, MOUSE is the highlight face to use.
1674 When the user clicks on TEXT, FUNCTION is called with the TOKEN parameter.
1675 This function assumes that the current buffer is the speedbar buffer.
1676 If PREVLINE, then put this button on the previous line.
1678 This is a convenience function for special modes that create their own
1679 specialized speedbar displays."
1680 (goto-char (point-max))
1681 (let ((start (point)))
1682 (if (/= (current-column) 0) (insert "\n"))
1683 (put-text-property start
(point) 'invisible nil
))
1684 (if prevline
(progn (delete-char -
1)
1685 (insert " ") ;back up if desired...
1686 (put-text-property (1- (point)) (point) 'invisible nil
)))
1687 (let ((start (point)))
1689 (speedbar-make-button start
(point) face mouse function token
))
1690 (let ((start (point)))
1692 (add-text-properties
1693 start
(point) '(face nil invisible nil mouse-face nil
))))
1695 (defun speedbar-insert-separator (text)
1696 "Insert a separation label of TEXT.
1697 Separators are not active, have no labels, depth, or actions."
1698 (if speedbar-use-images
1699 (let ((start (point)))
1701 (speedbar-insert-image-button-maybe start
2)))
1702 (let ((start (point)))
1704 (speedbar-make-button start
(point)
1705 'speedbar-separator-face
1708 (defun speedbar-make-button (start end face mouse function
&optional token
)
1709 "Create a button from START to END, with FACE as the display face.
1710 MOUSE is the mouse face. When this button is clicked on FUNCTION
1711 will be run with the TOKEN parameter (any Lisp object). If FACE
1712 is t use the text properties of the string that is passed as an
1715 (put-text-property start end
'face face
))
1716 (add-text-properties
1717 start end
`(mouse-face ,mouse invisible nil
1718 speedbar-text
,(buffer-substring-no-properties start end
)))
1719 (if speedbar-use-tool-tips-flag
1720 (put-text-property start end
'help-echo
#'dframe-help-echo
))
1721 (if function
(put-text-property start end
'speedbar-function function
))
1722 (if token
(put-text-property start end
'speedbar-token token
))
1723 ;; So far the only text we have is less that 3 chars.
1724 (if (<= (- end start
) 3)
1725 (speedbar-insert-image-button-maybe start
(- end start
)))
1728 ;;; Initial Expansion list management
1730 (defun speedbar-initial-expansion-list ()
1731 "Return the current default expansion list.
1732 This is based on `speedbar-initial-expansion-list-name' referencing
1733 `speedbar-initial-expansion-mode-alist'."
1734 ;; cdr1 - name, cdr2 - menu
1735 (cdr (cdr (cdr (assoc speedbar-initial-expansion-list-name
1736 speedbar-initial-expansion-mode-alist
)))))
1738 (defun speedbar-initial-menu ()
1739 "Return the current default menu data.
1740 This is based on `speedbar-initial-expansion-list-name' referencing
1741 `speedbar-initial-expansion-mode-alist'."
1743 (car (cdr (assoc speedbar-initial-expansion-list-name
1744 speedbar-initial-expansion-mode-alist
)))))
1746 (defun speedbar-initial-keymap ()
1747 "Return the current default menu data.
1748 This is based on `speedbar-initial-expansion-list-name' referencing
1749 `speedbar-initial-expansion-mode-alist'."
1751 (car (cdr (cdr (assoc speedbar-initial-expansion-list-name
1752 speedbar-initial-expansion-mode-alist
))))))
1754 (defun speedbar-initial-stealthy-functions ()
1755 "Return a list of functions to call stealthily.
1756 This is based on `speedbar-initial-expansion-list-name' referencing
1757 `speedbar-stealthy-function-list'."
1758 (cdr (assoc speedbar-initial-expansion-list-name
1759 speedbar-stealthy-function-list
)))
1761 (defun speedbar-add-expansion-list (new-list)
1762 "Add NEW-LIST to the list of expansion lists."
1763 (add-to-list 'speedbar-initial-expansion-mode-alist new-list
))
1765 (defun speedbar-change-initial-expansion-list (new-default)
1766 "Change speedbar's default expansion list to NEW-DEFAULT."
1769 (completing-read (format "Speedbar Mode (default %s): "
1770 speedbar-previously-used-expansion-list-name
)
1771 speedbar-initial-expansion-mode-alist
1773 speedbar-previously-used-expansion-list-name
)))
1774 (setq speedbar-previously-used-expansion-list-name
1775 speedbar-initial-expansion-list-name
1776 speedbar-initial-expansion-list-name new-default
)
1777 (if (and (speedbar-current-frame) (frame-live-p (speedbar-current-frame)))
1780 (speedbar-reconfigure-keymaps))))
1782 (defun speedbar-fetch-replacement-function (function)
1783 "Return a current mode specific replacement for function, or nil.
1784 Scans `speedbar-mode-functions-list' first for the current mode, then
1786 (cdr (assoc function
1787 (cdr (assoc speedbar-initial-expansion-list-name
1788 speedbar-mode-functions-list
)))))
1790 (defun speedbar-add-mode-functions-list (new-list)
1791 "Add NEW-LIST to the list of mode functions.
1792 See `speedbar-mode-functions-list' for details."
1793 (add-to-list 'speedbar-mode-functions-list new-list
))
1796 ;;; Special speedbar display management
1798 (defun speedbar-maybe-add-localized-support (buffer)
1799 "Quick check function called on BUFFERs by the speedbar timer function.
1800 Maintains the value of local variables which control speedbars use
1801 of the special mode functions."
1802 (or speedbar-special-mode-expansion-list
1803 (speedbar-add-localized-speedbar-support buffer
)))
1805 (defun speedbar-add-localized-speedbar-support (buffer)
1806 "Add localized speedbar support to BUFFER's mode if it is available."
1807 (interactive "bBuffer: ")
1808 (if (stringp buffer
) (setq buffer
(get-buffer buffer
)))
1809 (if (not (buffer-live-p buffer
))
1814 (let ((ms (symbol-name major-mode
)) v
)
1815 (if (not (string-match "-mode$" ms
))
1816 nil
;; do nothing to broken mode
1817 (setq ms
(substring ms
0 (match-beginning 0)))
1818 (setq v
(intern-soft (concat ms
"-speedbar-buttons")))
1819 (make-local-variable 'speedbar-special-mode-expansion-list
)
1821 (setq speedbar-special-mode-expansion-list t
)
1822 ;; If it is autoloaded, we need to load it now so that
1823 ;; we have access to the varialbe -speedbar-menu-items.
1824 ;; Is this XEmacs safe?
1825 (let ((sf (symbol-function v
)))
1826 (if (and (listp sf
) (eq (car sf
) 'autoload
))
1827 (load-library (car (cdr sf
)))))
1828 (setq speedbar-special-mode-expansion-list
(list v
))
1829 (setq v
(intern-soft (concat ms
"-speedbar-key-map")))
1831 nil
;; don't add special keymap
1832 (make-local-variable 'speedbar-special-mode-key-map
)
1833 (setq speedbar-special-mode-key-map
1835 (setq v
(intern-soft (concat ms
"-speedbar-menu-items")))
1837 nil
;; don't add special menus
1838 (make-local-variable 'speedbar-easymenu-definition-special
)
1839 (setq speedbar-easymenu-definition-special
1843 (defun speedbar-remove-localized-speedbar-support (buffer)
1844 "Remove any traces that BUFFER supports speedbar in a specialized way."
1847 (kill-local-variable 'speedbar-special-mode-expansion-list
)
1848 (kill-local-variable 'speedbar-special-mode-key-map
)
1849 (kill-local-variable 'speedbar-easymenu-definition-special
)))
1851 ;;; File button management
1853 (defun speedbar-file-lists (directory)
1854 "Create file lists for DIRECTORY.
1855 The car is the list of directories, the cdr is list of files not
1856 matching ignored headers. Cache any directory files found in
1857 `speedbar-directory-contents-alist' and use that cache before scanning
1859 (setq directory
(expand-file-name directory
))
1860 ;; If in powerclick mode, then the directory we are getting
1861 ;; should be rescanned.
1862 (if dframe-power-click
1863 (adelete 'speedbar-directory-contents-alist directory
))
1864 ;; find the directory, either in the cache, or build it.
1865 (or (cdr-safe (assoc directory speedbar-directory-contents-alist
))
1866 (let ((default-directory directory
)
1867 (dir (directory-files directory nil
))
1872 (or (string-match speedbar-file-unshown-regexp
(car dir
))
1873 (string-match speedbar-directory-unshown-regexp
(car dir
))))
1874 (if (file-directory-p (car dir
))
1875 (setq dirs
(cons (car dir
) dirs
))
1876 (setq files
(cons (car dir
) files
))))
1877 (setq dir
(cdr dir
)))
1878 (let ((nl (cons (nreverse dirs
) (list (nreverse files
)))))
1879 (aput 'speedbar-directory-contents-alist directory nl
)
1883 (defun speedbar-directory-buttons (directory index
)
1884 "Insert a single button group at point for DIRECTORY.
1885 Each directory directory part is a different button. If part of the directory
1886 matches the user directory ~, then it is replaced with a ~.
1887 INDEX is not used, but is required by the caller."
1888 (let* ((tilde (expand-file-name "~/"))
1889 (dd (expand-file-name directory
))
1890 (junk (string-match (regexp-quote tilde
) dd
))
1892 (concat "~/" (substring dd
(match-end 0)))
1895 (if (string-match "^~[/\\]?\\'" displayme
) (setq displayme tilde
))
1899 (while (re-search-forward "\\([^/\\]+\\)[/\\]" nil t
)
1900 (speedbar-make-button (match-beginning 1) (match-end 1)
1901 'speedbar-directory-face
1902 'speedbar-highlight-face
1903 'speedbar-directory-buttons-follow
1904 (if (and (= (match-beginning 1) p
)
1905 (not (char-equal (char-after (+ p
1)) ?
:)))
1906 (expand-file-name "~/") ;the tilde
1907 (buffer-substring-no-properties
1909 ;; Nuke the beginning of the directory if it's too long...
1910 (cond ((eq speedbar-directory-button-trim-method
'span
)
1912 (let ((ww (or (speedbar-frame-width) 20)))
1913 (move-to-column ww nil
)
1914 (while (>= (current-column) ww
)
1915 (re-search-backward "[/\\]" nil t
)
1916 (if (<= (current-column) 2)
1918 (re-search-forward "[/\\]" nil t
)
1919 (if (< (current-column) 4)
1920 (re-search-forward "[/\\]" nil t
))
1922 (if (looking-at "[/\\]?$")
1925 (move-to-column ww nil
)))))
1926 ((eq speedbar-directory-button-trim-method
'trim
)
1928 (let ((ww (or (speedbar-frame-width) 20))
1929 (tl (current-column)))
1932 (move-to-column (- tl ww
))
1933 (if (re-search-backward "[/\\]" nil t
)
1935 (delete-region (point-min) (point))
1939 (if (string-match "\\`[/\\][^/\\]+[/\\]\\'" displayme
)
1944 (speedbar-make-button p
(point)
1945 'speedbar-directory-face
1946 'speedbar-highlight-face
1947 'speedbar-directory-buttons-follow
1950 (insert-char ?
\n 1 nil
)))
1952 (defun speedbar-make-tag-line (exp-button-type
1953 exp-button-char exp-button-function
1955 tag-button tag-button-function tag-button-data
1956 tag-button-face depth
)
1957 "Create a tag line with EXP-BUTTON-TYPE for the small expansion button.
1958 This is the button that expands or contracts a node (if applicable),
1959 and EXP-BUTTON-CHAR the character in it (+, -, ?, etc). EXP-BUTTON-FUNCTION
1960 is the function to call if it's clicked on. Button types are
1961 'bracket, 'angle, 'curly, 'expandtag, 'statictag, t, or nil.
1962 EXP-BUTTON-DATA is extra data attached to the text forming the expansion
1965 Next, TAG-BUTTON is the text of the tag. TAG-BUTTON-FUNCTION is the
1966 function to call if clicked on, and TAG-BUTTON-DATA is the data to
1967 attach to the text field (such a tag positioning, etc).
1968 TAG-BUTTON-FACE is a face used for this type of tag.
1970 Lastly, DEPTH shows the depth of expansion.
1972 This function assumes that the cursor is in the speedbar window at the
1973 position to insert a new item, and that the new item will end with a CR."
1974 (let ((start (point))
1976 (insert (int-to-string depth
) ":")
1978 (depthspacesize (* depth speedbar-indentation-width
)))
1979 (put-text-property start end
'invisible t
)
1980 (insert-char ? depthspacesize nil
)
1981 (put-text-property (- (point) depthspacesize
) (point) 'invisible nil
)
1982 (let* ((exp-button (cond ((eq exp-button-type
'bracket
) "[%c]")
1983 ((eq exp-button-type
'angle
) "<%c>")
1984 ((eq exp-button-type
'curly
) "{%c}")
1985 ((eq exp-button-type
'expandtag
) " %c>")
1986 ((eq exp-button-type
'statictag
) " =>")
1988 (buttxt (format exp-button exp-button-char
))
1990 (end (progn (insert buttxt
) (point)))
1991 (bf (if (and exp-button-type
(not (eq exp-button-type
'statictag
)))
1992 'speedbar-button-face nil
))
1993 (mf (if exp-button-function
'speedbar-highlight-face nil
))
1995 (speedbar-make-button start end bf mf exp-button-function exp-button-data
)
1996 (if speedbar-hide-button-brackets-flag
1998 (put-text-property start
(1+ start
) 'invisible t
)
1999 (put-text-property end
(1- end
) 'invisible t
)))
2001 (insert-char ?
1 nil
)
2002 (put-text-property (1- (point)) (point) 'invisible nil
)
2003 (let ((start (point))
2004 (end (progn (insert tag-button
) (point))))
2005 (insert-char ?
\n 1 nil
)
2006 (put-text-property (1- (point)) (point) 'invisible nil
)
2007 (speedbar-make-button start end tag-button-face
2008 (if tag-button-function
'speedbar-highlight-face nil
)
2009 tag-button-function tag-button-data
))
2012 (defun speedbar-change-expand-button-char (char)
2013 "Change the expansion button character to CHAR for the current line."
2016 (if (re-search-forward ":\\s-*.\\([-+?]\\)" (save-excursion (end-of-line)
2018 (speedbar-with-writable
2019 (goto-char (match-end 1))
2020 (insert-char char
1 t
)
2023 ;;(put-text-property (point) (1- (point)) 'invisible nil)
2024 ;; make sure we fix the image on the text here.
2025 (speedbar-insert-image-button-maybe (- (point) 1) 3)))))
2028 ;;; Build button lists
2030 (defun speedbar-insert-files-at-point (files level
)
2031 "Insert list of FILES starting at point, and indenting all files to LEVEL.
2032 Tag expandable items with a +, otherwise a ?. Don't highlight ? as we
2033 don't know how to manage them. The input parameter FILES is a cons
2034 cell of the form ( 'DIRLIST . 'FILELIST )."
2035 ;; Start inserting all the directories
2036 (let ((dirs (car files
)))
2038 (speedbar-make-tag-line 'angle ?
+ 'speedbar-dired
(car dirs
)
2039 (car dirs
) 'speedbar-dir-follow nil
2040 'speedbar-directory-face level
)
2041 (setq dirs
(cdr dirs
))))
2042 (let ((lst (car (cdr files
)))
2043 (case-fold-search t
))
2045 (let* ((known (string-match speedbar-file-regexp
(car lst
)))
2046 (expchar (if known ?
+ ??
))
2047 (fn (if known
'speedbar-tag-file nil
)))
2048 (if (or speedbar-show-unknown-files
(/= expchar ??
))
2049 (speedbar-make-tag-line 'bracket expchar fn
(car lst
)
2050 (car lst
) 'speedbar-find-file nil
2051 'speedbar-file-face level
)))
2052 (setq lst
(cdr lst
)))))
2054 (defun speedbar-default-directory-list (directory index
)
2055 "Insert files for DIRECTORY with level INDEX at point."
2056 (speedbar-insert-files-at-point
2057 (speedbar-file-lists directory
) index
)
2058 (speedbar-reset-scanners)
2060 ;; If the shown files variable has extra directories, then
2061 ;; it is our responsibility to redraw them all
2062 ;; Luckilly, the nature of inserting items into this list means
2063 ;; that by reversing it, we can easilly go in the right order
2064 (let ((sf (cdr (reverse speedbar-shown-directories
))))
2065 (setq speedbar-shown-directories
2066 (list (expand-file-name default-directory
)))
2067 ;; exand them all as we find them
2069 (if (speedbar-goto-this-file (car sf
))
2072 (if (looking-at "[0-9]+:[ ]*<")
2074 (goto-char (match-end 0))
2075 (speedbar-do-function-pointer)))))
2078 ;;; Generic List support
2080 ;; Generic lists are hierarchies of tags which we may need to permute
2081 ;; in order to make it look nice.
2083 ;; A generic list is of the form:
2084 ;; ( ("name" . marker-or-number) <-- one tag at this level
2085 ;; ("name" ("name" . mon) ("name" . mon) ) <-- one group of tags
2086 ;; ("name" mon ("name" . mon) ) <-- group w/ a position and tags
2087 (defun speedbar-generic-list-group-p (sublst)
2088 "Non-nil if SUBLST is a group.
2089 Groups may optionally contain a position."
2090 (and (stringp (car-safe sublst
))
2091 (or (and (listp (cdr-safe sublst
))
2092 (or (speedbar-generic-list-tag-p (car-safe (cdr-safe sublst
)))
2093 (speedbar-generic-list-group-p (car-safe (cdr-safe sublst
))
2095 (and (number-or-marker-p (car-safe (cdr-safe sublst
)))
2096 (listp (cdr-safe (cdr-safe sublst
)))
2097 (speedbar-generic-list-tag-p
2098 (car-safe (cdr-safe (cdr-safe sublst
)))))
2101 (defun speedbar-generic-list-positioned-group-p (sublst)
2102 "Non-nil of SUBLST is a group with a position."
2103 (and (stringp (car-safe sublst
))
2104 (number-or-marker-p (car-safe (cdr-safe sublst
)))
2105 (listp (cdr-safe (cdr-safe sublst
)))
2106 (let ((rest (car-safe (cdr-safe (cdr-safe sublst
)))))
2107 (or (speedbar-generic-list-tag-p rest
)
2108 (speedbar-generic-list-group-p rest
)
2109 (speedbar-generic-list-positioned-group-p rest
)
2112 (defun speedbar-generic-list-tag-p (sublst)
2113 "Non nil if SUBLST is a tag."
2114 (and (stringp (car-safe sublst
))
2115 (or (and (number-or-marker-p (cdr-safe sublst
))
2116 (not (cdr-safe (cdr-safe sublst
))))
2117 ;; For semantic/bovine items, this is needed
2118 (symbolp (car-safe (cdr-safe sublst
))))
2121 (defun speedbar-sort-tag-hierarchy (lst)
2122 "Sort all elements of tag hierarchy LST."
2123 (sort (copy-alist lst
)
2124 (lambda (a b
) (string< (car a
) (car b
)))))
2126 (defun speedbar-try-completion (string alist
)
2127 "A wrapper for `try-completion'.
2128 Passes STRING and ALIST to `try-completion' if ALIST
2130 (if (and (consp alist
)
2131 (listp (car alist
)) (stringp (car (car alist
))))
2132 (try-completion string alist
)
2135 (defun speedbar-prefix-group-tag-hierarchy (lst)
2136 "Prefix group names for tag hierarchy LST."
2141 (short-group-list nil
)
2142 (short-start-name nil
)
2143 (short-end-name nil
)
2144 (num-shorts-grouped 0)
2145 (bins (make-vector 256 nil
))
2147 (if (<= (length lst
) speedbar-tag-regroup-maximum-length
)
2148 ;; Do nothing. Too short to bother with.
2150 ;; Break out sub-lists
2152 (if (speedbar-generic-list-group-p (car-safe lst
))
2153 (setq newlst
(cons (car lst
) newlst
))
2154 (setq sublst
(cons (car lst
) sublst
)))
2155 (setq lst
(cdr lst
)))
2156 ;; Reverse newlst because it was made backwards.
2157 ;; Sublist doesn't need reversing because the act
2158 ;; of binning things will reverse it for us.
2159 (setq newlst
(nreverse newlst
)
2161 ;; Now, first find out how long our list is. Never let a
2162 ;; list get-shorter than our minimum.
2163 (if (<= (length sublst
) speedbar-tag-split-minimum-length
)
2164 (setq work-list sublst
)
2165 (setq diff-idx
(length (speedbar-try-completion "" sublst
)))
2166 ;; Sort the whole list into bins.
2168 (let ((e (car sublst
))
2169 (s (car (car sublst
))))
2170 (cond ((<= (length s
) diff-idx
)
2171 ;; 0 storage bin for shorty.
2172 (aset bins
0 (cons e
(aref bins
0))))
2174 ;; stuff into a bin based on ascii value at diff
2175 (aset bins
(aref s diff-idx
)
2176 (cons e
(aref bins
(aref s diff-idx
)))))))
2177 (setq sublst
(cdr sublst
)))
2178 ;; Go through all our bins Stick singles into our
2179 ;; junk-list, everything else as sublsts in work-list.
2180 ;; If two neighboring lists are both small, make a grouped
2181 ;; group combinding those two sub-lists.
2183 (while (> 256 diff-idx
)
2184 ;; The bins contents are currently in forward order.
2185 (let ((l (aref bins diff-idx
)))
2187 (let ((tmp (cons (speedbar-try-completion "" l
) l
)))
2188 (if (or (> (length l
) speedbar-tag-regroup-maximum-length
)
2189 (> (+ (length l
) (length short-group-list
))
2190 speedbar-tag-split-minimum-length
))
2192 ;; We have reached a longer list, so we
2193 ;; must finish off a grouped group.
2195 ((and short-group-list
2196 (= (length short-group-list
)
2197 num-shorts-grouped
))
2198 ;; All singles? Junk list
2199 (setq junk-list
(append (nreverse short-group-list
)
2201 ((= num-shorts-grouped
1)
2202 ;; Only one short group? Just stick it in
2203 ;; there by itself. Make a group, and find
2205 (let ((subexpression (speedbar-try-completion
2206 "" short-group-list
)))
2207 (if (< (length subexpression
)
2208 speedbar-tag-group-name-minimum-length
)
2210 (concat short-start-name
2213 (car (car short-group-list
))
2214 (length short-start-name
))
2217 (cons (cons subexpression
2221 ;; Multiple groups to be named in a special
2222 ;; way by displaying the range over which we
2223 ;; have grouped them.
2225 (cons (cons (concat short-start-name
2230 ;; Reset short group list information every time.
2231 (setq short-group-list nil
2232 short-start-name nil
2234 num-shorts-grouped
0)))
2235 ;; Ok, now that we cleaned up the short-group-list,
2236 ;; we can deal with this new list, to decide if it
2237 ;; should go on one of these sub-lists or not.
2238 (if (< (length l
) speedbar-tag-regroup-maximum-length
)
2239 (setq short-group-list
(append l short-group-list
)
2240 num-shorts-grouped
(1+ num-shorts-grouped
)
2241 short-end-name
(car tmp
)
2242 short-start-name
(if short-start-name
2245 (setq work-list
(cons tmp work-list
))))))
2246 (setq diff-idx
(1+ diff-idx
))))
2247 ;; Did we run out of things? Drop our new list onto the end.
2249 ((and short-group-list
(= (length short-group-list
) num-shorts-grouped
))
2250 ;; All singles? Junk list
2251 (setq junk-list
(append short-group-list junk-list
)))
2252 ((= num-shorts-grouped
1)
2253 ;; Only one short group? Just stick it in
2256 (cons (cons (speedbar-try-completion "" short-group-list
)
2260 ;; Multiple groups to be named in a special
2261 ;; way by displaying the range over which we
2262 ;; have grouped them.
2264 (cons (cons (concat short-start-name
" to " short-end-name
)
2267 ;; Reverse the work list nreversed when consing.
2268 (setq work-list
(nreverse work-list
))
2269 ;; Now, stick our new list onto the end of
2272 (append newlst work-list junk-list
)
2273 (append newlst work-list
))
2274 (append newlst junk-list
)))))
2276 (defun speedbar-trim-words-tag-hierarchy (lst)
2277 "Trim all words in a tag hierarchy.
2278 Base trimming information on word separators, and group names.
2279 Argument LST is the list of tags to trim."
2286 (if (speedbar-generic-list-group-p (car-safe lst
))
2287 (setq newlst
(cons (car lst
) newlst
))
2288 (setq sublst
(cons (car lst
) sublst
)))
2289 (setq lst
(cdr lst
)))
2290 ;; Get the prefix to trim by. Make sure that we don't trim
2291 ;; off silly pieces, only complete understandable words.
2292 (setq trim-prefix
(speedbar-try-completion "" sublst
)
2293 newlst
(nreverse newlst
))
2294 (if (or (= (length sublst
) 1)
2296 (not (string-match "\\(\\w+\\W+\\)+" trim-prefix
)))
2297 (append newlst
(nreverse sublst
))
2298 (setq trim-prefix
(substring trim-prefix
(match-beginning 0)
2300 (setq trim-chars
(length trim-prefix
))
2303 (cons (substring (car (car sublst
)) trim-chars
)
2306 sublst
(cdr sublst
)))
2307 ;; Put the lists together
2308 (append newlst trimlst
))))
2310 (defun speedbar-simple-group-tag-hierarchy (lst)
2311 "Create a simple 'Tags' group with orphaned tags.
2312 Argument LST is the list of tags to sort into groups."
2316 (if (speedbar-generic-list-group-p (car-safe lst
))
2317 (setq newlst
(cons (car lst
) newlst
))
2318 (setq sublst
(cons (car lst
) sublst
)))
2319 (setq lst
(cdr lst
)))
2322 (setq newlst
(cons (cons "Tags" (nreverse sublst
)) newlst
))
2323 (nreverse newlst
))))
2325 (defun speedbar-create-tag-hierarchy (lst)
2326 "Adjust the tag hierarchy in LST, and return it.
2327 This uses `speedbar-tag-hierarchy-method' to determine how to adjust
2329 (let* ((f (save-excursion
2331 (or (speedbar-line-file)
2332 (speedbar-line-directory))))
2333 (methods (if (get-file-buffer f
)
2334 (save-excursion (set-buffer (get-file-buffer f
))
2335 speedbar-tag-hierarchy-method
)
2336 speedbar-tag-hierarchy-method
))
2337 (lst (if (fboundp 'copy-tree
)
2341 (setq lst
(funcall (car methods
) lst
)
2342 methods
(cdr methods
)))
2345 (defvar speedbar-generic-list-group-expand-button-type
'curly
2346 "The type of button created for groups of tags.
2347 Good values for this are `curly' and `expandtag'.
2348 Make buffer local for your mode.")
2350 (defvar speedbar-generic-list-tag-button-type nil
2351 "The type of button created for tags in generic lists.
2352 Good values for this are nil and `statictag'.
2353 Make buffer local for your mode.")
2355 (defun speedbar-insert-generic-list (level lst expand-fun find-fun
)
2356 "At LEVEL, insert a generic multi-level alist LST.
2357 Associations with lists get {+} tags (to expand into more nodes) and
2358 those with positions just get a > as the indicator. {+} buttons will
2359 have the function EXPAND-FUN and the token is the CDR list. The token
2360 name will have the function FIND-FUN and not token."
2361 ;; Remove imenu rescan button
2362 (if (string= (car (car lst
)) "*Rescan*")
2363 (setq lst
(cdr lst
)))
2364 ;; Get, and set up variables that define how we treat these tags.
2365 (let ((f (save-excursion (forward-line -
1)
2366 (or (speedbar-line-file)
2367 (speedbar-line-directory))))
2368 expand-button tag-button
)
2370 (if (get-file-buffer f
)
2371 (set-buffer (get-file-buffer f
)))
2372 (setq expand-button speedbar-generic-list-group-expand-button-type
2373 tag-button speedbar-generic-list-tag-button-type
))
2375 (setq lst
(speedbar-create-tag-hierarchy lst
))
2378 (cond ((null (car-safe lst
)) nil
) ;this would be a separator
2379 ((speedbar-generic-list-tag-p (car lst
))
2380 (speedbar-make-tag-line tag-button
2381 nil nil nil
;no expand button data
2382 (car (car lst
)) ;button name
2384 (cdr (car lst
)) ;token is position
2387 ((speedbar-generic-list-positioned-group-p (car lst
))
2388 (speedbar-make-tag-line expand-button
2389 ?
+ expand-fun
(cdr (cdr (car lst
)))
2390 (car (car lst
)) ;button name
2392 (car (cdr (car lst
))) ;token is posn
2395 ((speedbar-generic-list-group-p (car lst
))
2396 (speedbar-make-tag-line expand-button
2397 ?
+ expand-fun
(cdr (car lst
))
2398 (car (car lst
)) ;button name
2399 nil nil
'speedbar-tag-face
2401 (t (speedbar-message "speedbar-insert-generic-list: malformed list!")
2403 (setq lst
(cdr lst
)))))
2405 (defun speedbar-insert-imenu-list (indent lst
)
2406 "At level INDENT, insert the imenu generated LST."
2407 (speedbar-insert-generic-list indent lst
2408 'speedbar-tag-expand
2409 'speedbar-tag-find
))
2411 (defun speedbar-insert-etags-list (indent lst
)
2412 "At level INDENT, insert the etags generated LST."
2413 (speedbar-insert-generic-list indent lst
2414 'speedbar-tag-expand
2415 'speedbar-tag-find
))
2419 (defun speedbar-update-contents ()
2420 "Generically update the contents of the speedbar buffer."
2422 ;; Set the current special buffer
2423 (setq speedbar-desired-buffer nil
)
2425 ;; Check for special modes
2426 (speedbar-maybe-add-localized-support (current-buffer))
2428 ;; Choose the correct method of doodling.
2429 (if (and speedbar-mode-specific-contents-flag
2430 (consp speedbar-special-mode-expansion-list
)
2432 'speedbar-special-mode-expansion-list
2434 ;;(eq (get major-mode 'mode-class 'special)))
2435 (speedbar-update-special-contents)
2436 (speedbar-update-directory-contents)))
2438 (defun speedbar-update-localized-contents ()
2439 "Update the contents of the speedbar buffer for the current situation."
2440 ;; Due to the historical growth of speedbar, we need to do something
2441 ;; special for "files" mode. Too bad.
2442 (let ((name speedbar-initial-expansion-list-name
)
2443 (funclst (speedbar-initial-expansion-list))
2445 (if (string= name
"files")
2446 ;; Do all the files type work. It still goes through the
2447 ;; expansion list stuff. :(
2448 (if (or (member (expand-file-name default-directory
)
2449 speedbar-shown-directories
)
2450 (and speedbar-ignored-directory-regexp
2452 speedbar-ignored-directory-regexp
2453 (expand-file-name default-directory
))))
2455 (if (<= 1 speedbar-verbosity-level
)
2456 (speedbar-message "Updating speedbar to: %s..."
2458 (speedbar-update-directory-contents)
2459 (if (<= 1 speedbar-verbosity-level
)
2461 (speedbar-message "Updating speedbar to: %s...done"
2463 (speedbar-message nil
))))
2464 ;; Else, we can do a short cut. No text cache.
2465 (let ((cbd (expand-file-name default-directory
))
2467 (set-buffer speedbar-buffer
)
2468 (speedbar-with-writable
2469 (let* ((window (get-buffer-window speedbar-buffer
0))
2470 (p (window-point window
)))
2472 (dolist (func funclst
)
2473 (setq default-directory cbd
)
2474 (funcall func cbd
0))
2475 (speedbar-reconfigure-keymaps)
2476 (set-window-point window p
)))
2479 (defun speedbar-update-directory-contents ()
2480 "Update the contents of the speedbar buffer based on the current directory."
2484 (let ((cbd (expand-file-name default-directory
))
2486 (funclst (speedbar-initial-expansion-list))
2487 (cache speedbar-full-text-cache
)
2488 ;; disable stealth during update
2489 (speedbar-stealthy-function-list nil
)
2492 ;; Because there is a bug I can't find just yet
2494 (set-buffer speedbar-buffer
)
2495 ;; If we are updating contents to where we are, then this is
2496 ;; really a request to update existing contents, so we must be
2497 ;; careful with our text cache!
2498 (if (member cbd speedbar-shown-directories
)
2501 ;; If the current directory is not the last element in the dir
2502 ;; list, then we ALSO need to zap the list of expanded directories
2503 (if (/= (length (member cbd speedbar-shown-directories
)) 1)
2504 (setq speedbar-shown-directories
(list cbd
))))
2506 ;; Build cbd-parent, and see if THAT is in the current shown
2507 ;; directories. First, go through pains to get the parent directory
2508 (if (and speedbar-smart-directory-expand-flag
2510 (setq cbd-parent cbd
)
2511 (if (string-match "[/\\]$" cbd-parent
)
2512 (setq cbd-parent
(substring cbd-parent
0
2513 (match-beginning 0))))
2514 (setq cbd-parent
(file-name-directory cbd-parent
)))
2515 (member cbd-parent speedbar-shown-directories
))
2516 (setq expand-local t
)
2518 ;; If this directory is NOT in the current list of available
2519 ;; directorys, then use the cache, and set the cache to our new
2520 ;; value. Make sure to unhighlight the current file, or if we
2521 ;; come back to this directory, it might be a different file
2522 ;; and then we get a mess!
2523 (if (> (point-max) 1)
2525 (speedbar-clear-current-file)
2526 (setq speedbar-full-text-cache
2527 (cons speedbar-shown-directories
(buffer-string)))))
2529 ;; Check if our new directory is in the list of directories
2530 ;; shown in the text-cache
2531 (if (member cbd
(car cache
))
2532 (setq speedbar-shown-directories
(car cache
)
2534 ;; default the shown directories to this list...
2535 (setq speedbar-shown-directories
(list cbd
)))
2537 (if (not expand-local
) (setq speedbar-last-selected-file nil
))
2538 (speedbar-with-writable
2539 (if (and expand-local
2540 ;; Find this directory as a speedbar node.
2541 (speedbar-directory-line cbd
))
2543 (speedbar-expand-line)
2546 (setq default-directory
2547 (nth (1- (length speedbar-shown-directories
))
2548 speedbar-shown-directories
))
2549 (insert (cdr cache
)))
2551 (dolist (func funclst
)
2552 (setq default-directory cbd
)
2553 (funcall func cbd
0)))))
2554 (goto-char (point-min)))))
2555 (speedbar-reconfigure-keymaps))
2557 (defun speedbar-update-special-contents ()
2558 "Use the mode-specific variable to fill in the speedbar buffer.
2559 This should only be used by modes classified as special."
2560 (let ((funclst speedbar-special-mode-expansion-list
)
2561 (specialbuff (current-buffer)))
2563 (setq speedbar-desired-buffer specialbuff
)
2564 (set-buffer speedbar-buffer
)
2565 ;; If we are leaving a directory, cache it.
2566 (if (not speedbar-shown-directories
)
2569 ;; Clean up directory maintenance stuff
2570 (speedbar-clear-current-file)
2571 (setq speedbar-full-text-cache
2572 (cons speedbar-shown-directories
(buffer-string))
2573 speedbar-shown-directories nil
))
2574 ;; Now fill in the buffer with our newly found specialized list.
2575 (speedbar-with-writable
2576 (dolist (func funclst
)
2577 ;; We do not erase the buffer because these functions may
2578 ;; decide NOT to update themselves.
2579 (funcall func specialbuff
)))
2580 (goto-char (point-min))))
2581 (speedbar-reconfigure-keymaps))
2583 (defun speedbar-set-timer (timeout)
2584 "Set up the speedbar timer with TIMEOUT.
2585 Uses `dframe-set-timer'.
2586 Also resets scanner functions."
2587 (dframe-set-timer timeout
'speedbar-timer-fn
'speedbar-update-flag
)
2588 ;; Apply a revert hook that will reset the scanners. We attach to revert
2589 ;; because most reverts occur during VC state change, and this lets our
2590 ;; VC scanner fix itself.
2592 (add-hook 'after-revert-hook
'speedbar-reset-scanners
)
2593 (remove-hook 'after-revert-hook
'speedbar-reset-scanners
))
2594 ;; change this if it changed for some reason
2595 (speedbar-set-mode-line-format))
2597 (defun speedbar-timer-fn ()
2598 "Run whenever Emacs is idle to update the speedbar item."
2599 (if (or (not (speedbar-current-frame))
2600 (not (frame-live-p (speedbar-current-frame))))
2601 (speedbar-set-timer nil
)
2602 ;; Save all the match data so that we don't mess up executing fns
2604 ;; Only do stuff if the frame is visible, not an icon, and if
2605 ;; it is currently flagged to do something.
2606 (if (and speedbar-update-flag
2607 (speedbar-current-frame)
2608 (frame-visible-p (speedbar-current-frame))
2609 (not (eq (frame-visible-p (speedbar-current-frame)) 'icon
)))
2610 (let ((af (selected-frame)))
2611 (save-window-excursion
2612 (dframe-select-attached-frame speedbar-frame
)
2613 ;; make sure we at least choose a window to
2614 ;; get a good directory from
2615 (if (window-minibuffer-p (selected-window))
2617 ;; Check for special modes
2618 (speedbar-maybe-add-localized-support (current-buffer))
2619 ;; Update for special mode all the time!
2620 (if (and speedbar-mode-specific-contents-flag
2621 (consp speedbar-special-mode-expansion-list
)
2623 'speedbar-special-mode-expansion-list
2625 ;;(eq (get major-mode 'mode-class 'special)))
2627 (if (<= 2 speedbar-verbosity-level
)
2629 "Updating speedbar to special mode: %s..."
2631 (speedbar-update-special-contents)
2632 (if (<= 2 speedbar-verbosity-level
)
2635 "Updating speedbar to special mode: %s...done"
2637 (speedbar-message nil
))))
2638 ;; Update all the contents if directories change!
2639 (if (or (member major-mode speedbar-ignored-modes
)
2640 (eq af
(speedbar-current-frame))
2641 (not (buffer-file-name)))
2643 (speedbar-update-localized-contents)
2646 ;; Now run stealthy updates of time-consuming items
2647 (speedbar-stealthy-updates)))))
2648 (run-hooks 'speedbar-timer-hook
))
2651 ;;; Stealthy activities
2653 (defvar speedbar-stealthy-update-recurse nil
2654 "Recursion avoidance variable for stealthy update.")
2656 (defun speedbar-stealthy-updates ()
2657 "For a given speedbar, run all items in the stealthy function list.
2658 Each item returns t if it completes successfully, or nil if
2659 interrupted by the user."
2660 (if (not speedbar-stealthy-update-recurse
)
2661 (let ((l (speedbar-initial-stealthy-functions))
2662 (speedbar-stealthy-update-recurse t
))
2664 (speedbar-with-writable
2665 (while (and l
(funcall (car l
)))
2668 ;;(speedbar-message "Exit with %S" (car l))
2671 (defun speedbar-reset-scanners ()
2672 "Reset any variables used by functions in the stealthy list as state.
2673 If new functions are added, their state needs to be updated here."
2674 (setq speedbar-vc-to-do-point t
2675 speedbar-obj-to-do-point t
2676 speedbar-ro-to-do-point t
)
2677 (run-hooks 'speedbar-scanner-reset-hook
)
2680 (defun speedbar-find-selected-file (file)
2681 "Go to the line where FILE is."
2683 (set-buffer speedbar-buffer
)
2685 (goto-char (point-min))
2687 (while (and (setq m
(re-search-forward
2688 (concat " \\(" (regexp-quote (file-name-nondirectory file
))
2689 "\\)\\(" speedbar-indicator-regex
"\\)?\n")
2693 (speedbar-line-directory
2695 (goto-char (match-beginning 0))
2698 (looking-at "[0-9]+:")
2699 (string-to-number (match-string 0)))))
2700 (match-string 1))))))
2703 (goto-char (match-beginning 1))
2704 (match-string 1)))))
2706 (defun speedbar-clear-current-file ()
2707 "Locate the file thought to be current, and remove its highlighting."
2709 ;;(set-buffer speedbar-buffer)
2710 (if speedbar-last-selected-file
2711 (speedbar-with-writable
2712 (if (speedbar-find-selected-file speedbar-last-selected-file
)
2713 (put-text-property (match-beginning 1)
2716 'speedbar-file-face
))))))
2718 (defun speedbar-update-current-file ()
2719 "Find the current file, and update our visuals to indicate its name.
2720 This is specific to file names. If the file name doesn't show up, but
2721 it should be in the list, then the directory cache needs to be
2723 (let* ((lastf (selected-frame))
2724 (newcfd (save-excursion
2725 (dframe-select-attached-frame speedbar-frame
)
2726 (let ((rf (if (buffer-file-name)
2729 (select-frame lastf
)
2731 (newcf (if newcfd newcfd
))
2732 (lastb (current-buffer))
2733 (sucf-recursive (boundp 'sucf-recursive
))
2734 (case-fold-search t
))
2736 ;; check here, that way we won't refresh to newcf until
2737 ;; its been written, thus saving ourselves some time
2738 (file-exists-p newcf
)
2739 (not (string= newcf speedbar-last-selected-file
)))
2741 ;; It is important to select the frame, otherwise the window
2742 ;; we want the cursor to move in will not be updated by the
2743 ;; search-forward command.
2744 (select-frame (speedbar-current-frame))
2745 ;; Remove the old file...
2746 (speedbar-clear-current-file)
2747 ;; now highlight the new one.
2748 ;; (set-buffer speedbar-buffer)
2749 (speedbar-with-writable
2750 (if (speedbar-find-selected-file newcf
)
2751 ;; put the property on it
2752 (put-text-property (match-beginning 1)
2755 'speedbar-selected-face
)
2756 ;; Oops, it's not in the list. Should it be?
2757 (if (and (string-match speedbar-file-regexp newcf
)
2758 (string= (file-name-directory newcfd
)
2759 (expand-file-name default-directory
)))
2760 ;; yes, it is (we will ignore unknowns for now...)
2763 (if (speedbar-find-selected-file newcf
)
2764 ;; put the property on it
2765 (put-text-property (match-beginning 1)
2768 'speedbar-selected-face
)))
2769 ;; if it's not in there now, whatever...
2771 (setq speedbar-last-selected-file newcf
))
2772 (if (not sucf-recursive
)
2775 ;;Sat Dec 15 2001 12:40 AM (burton@openprivacy.org): this
2776 ;;doesn't need to be in. We don't want to recenter when we are
2779 ;;(speedbar-center-buffer-smartly)
2781 (speedbar-position-cursor-on-line)
2784 (select-frame lastf
)
2786 ;; return that we are done with this activity.
2789 (defun speedbar-add-indicator (indicator-string &optional replace-this
)
2790 "Add INDICATOR-STRING to the end of this speedbar line.
2791 If INDICATOR-STRING is space, and REPLACE-THIS is a character, then
2792 the existing indicator is removed. If there is already an
2793 indicator, then do not add a space."
2795 ;; The nature of the beast: Assume we are in "the right place"
2797 (skip-chars-backward (concat " " speedbar-vc-indicator
2798 speedbar-object-read-only-indicator
2799 (car speedbar-obj-indicator
)
2800 (cdr speedbar-obj-indicator
)))
2801 (if (and (not (looking-at speedbar-indicator-regex
))
2802 (not (string= indicator-string
" ")))
2803 (insert speedbar-indicator-separator
))
2804 (speedbar-with-writable
2806 (if (and replace-this
2807 (re-search-forward replace-this
(save-excursion (end-of-line)
2810 (delete-region (match-beginning 0) (match-end 0))))
2812 (if (not (string= " " indicator-string
))
2813 (let ((start (point)))
2814 (insert indicator-string
)
2815 (speedbar-insert-image-button-maybe start
(length indicator-string
))
2818 (defun speedbar-check-read-only ()
2819 "Scan all the files in a directory, and for each see if it is read only."
2820 ;; Check for to-do to be reset. If reset but no RCS is available
2821 ;; then set to nil (do nothing) otherwise, start at the beginning
2823 (if speedbar-buffer
(set-buffer speedbar-buffer
))
2824 (if (eq speedbar-ro-to-do-point t
)
2825 (setq speedbar-ro-to-do-point
0))
2826 (if (numberp speedbar-ro-to-do-point
)
2828 (goto-char speedbar-ro-to-do-point
)
2829 (while (and (not (input-pending-p))
2830 (re-search-forward "^\\([0-9]+\\):\\s-*[[<][+-\?][]>] "
2832 (setq speedbar-ro-to-do-point
(point))
2833 (let ((f (speedbar-line-file)))
2835 (if (not (file-writable-p f
))
2836 (speedbar-add-indicator
2837 speedbar-object-read-only-indicator
2838 (regexp-quote speedbar-object-read-only-indicator
))
2839 (speedbar-add-indicator
2841 speedbar-object-read-only-indicator
))))))
2842 (if (input-pending-p)
2843 ;; return that we are incomplete
2845 ;; we are done, set to-do to nil
2846 (setq speedbar-ro-to-do-point nil
)
2851 ;; Load efs/ange-ftp only if compiling to remove byte-compiler warnings.
2852 ;; Steven L Baur <steve@xemacs.org> said this was important:
2853 (eval-when-compile (or (featurep 'xemacs
)
2854 (condition-case () (require 'efs
)
2855 (error (require 'ange-ftp
)))))
2857 (defun speedbar-check-vc ()
2858 "Scan all files in a directory, and for each see if it's checked out.
2859 See `speedbar-this-file-in-vc' and `speedbar-vc-check-dir-p' for how
2860 to add more types of version control systems."
2861 ;; Check for to-do to be reset. If reset but no RCS is available
2862 ;; then set to nil (do nothing) otherwise, start at the beginning
2864 (if speedbar-buffer
(set-buffer speedbar-buffer
))
2865 (if (and speedbar-vc-do-check
(eq speedbar-vc-to-do-point t
)
2866 (speedbar-vc-check-dir-p default-directory
)
2867 (not (or (and (featurep 'ange-ftp
)
2871 'ange-ftp-directory-format
2872 'ange-ftp-name-format
)))
2873 (expand-file-name default-directory
)))
2874 ;; efs support: Bob Weiner
2875 (and (featurep 'efs
)
2877 (let ((reg (symbol-value 'efs-directory-regexp
)))
2881 (expand-file-name default-directory
))))))
2882 (setq speedbar-vc-to-do-point
0))
2883 (if (numberp speedbar-vc-to-do-point
)
2885 (goto-char speedbar-vc-to-do-point
)
2886 (while (and (not (input-pending-p))
2887 (re-search-forward "^\\([0-9]+\\):\\s-*\\[[+-?]\\] "
2889 (setq speedbar-vc-to-do-point
(point))
2890 (if (speedbar-check-vc-this-line (match-string 1))
2891 (speedbar-add-indicator speedbar-vc-indicator
2892 (regexp-quote speedbar-vc-indicator
))
2893 (speedbar-add-indicator " "
2894 (regexp-quote speedbar-vc-indicator
))))
2895 (if (input-pending-p)
2896 ;; return that we are incomplete
2898 ;; we are done, set to-do to nil
2899 (setq speedbar-vc-to-do-point nil
)
2904 (defun speedbar-check-vc-this-line (depth)
2905 "Return t if the file on this line is check of of a version control system.
2906 Parameter DEPTH is a string with the current depth of indentation of
2907 the file being checked."
2908 (let* ((d (string-to-number depth
))
2909 (f (speedbar-line-directory d
))
2910 (fn (buffer-substring-no-properties
2911 ;; Skip-chars: thanks ptype@dra.hmg.gb
2913 (skip-chars-forward "^ "
2914 (save-excursion (end-of-line)
2917 (fulln (concat f fn
)))
2918 (if (<= 2 speedbar-verbosity-level
)
2919 (speedbar-message "Speedbar vc check...%s" fulln
))
2920 (and (file-writable-p fulln
)
2921 (speedbar-this-file-in-vc f fn
))))
2923 (defun speedbar-vc-check-dir-p (directory)
2924 "Return t if we should bother checking DIRECTORY for version control files.
2925 This can be overloaded to add new types of version control systems."
2927 ;; Local CVS available in Emacs 21
2928 (and (fboundp 'vc-state
)
2929 (file-exists-p (concat directory
"CVS/")))
2931 (file-exists-p (concat directory
"RCS/"))
2933 (file-exists-p (concat directory
"SCCS/"))
2934 ;; Remote SCCS project
2935 (let ((proj-dir (getenv "PROJECTDIR")))
2937 (file-exists-p (concat proj-dir
"/SCCS"))
2940 (run-hook-with-args-until-success 'speedbar-vc-directory-enable-hook
2944 (defun speedbar-this-file-in-vc (directory name
)
2945 "Check to see if the file in DIRECTORY with NAME is in a version control system.
2946 You can add new VC systems by overriding this function. You can
2947 optimize this function by overriding it and only doing those checks
2948 that will occur on your system."
2950 (if (fboundp 'vc-state
)
2951 ;; Emacs 21 handles VC state in a nice way.
2953 (let ((state (vc-state (concat directory name
))))
2954 (not (or (eq 'up-to-date state
)
2956 ;; An error means not in a VC system
2960 (file-exists-p (concat directory
"RCS/" name
",v"))
2961 (file-exists-p (concat directory
"RCS/" name
))
2962 ;; Local SCCS file name
2963 (file-exists-p (concat directory
"SCCS/s." name
))
2964 ;; Remote SCCS file name
2965 (let ((proj-dir (getenv "PROJECTDIR")))
2967 (file-exists-p (concat proj-dir
"/SCCS/s." name
))
2970 (run-hook-with-args 'speedbar-vc-in-control-hook directory name
)
2973 ;; Objet File scanning
2974 (defun speedbar-check-objects ()
2975 "Scan all files in a directory, and for each see if there is an object.
2976 See `speedbar-check-obj-this-line' and `speedbar-obj-alist' for how
2977 to add more object types."
2978 ;; Check for to-do to be reset. If reset but no RCS is available
2979 ;; then set to nil (do nothing) otherwise, start at the beginning
2981 (if speedbar-buffer
(set-buffer speedbar-buffer
))
2982 (if (and speedbar-obj-do-check
(eq speedbar-obj-to-do-point t
))
2983 (setq speedbar-obj-to-do-point
0))
2984 (if (numberp speedbar-obj-to-do-point
)
2986 (goto-char speedbar-obj-to-do-point
)
2987 (while (and (not (input-pending-p))
2988 (re-search-forward "^\\([0-9]+\\):\\s-*\\[[+-]\\] "
2990 (setq speedbar-obj-to-do-point
(point))
2991 (let ((ind (speedbar-check-obj-this-line (match-string 1))))
2992 (if (not ind
) (setq ind
" "))
2993 (speedbar-add-indicator ind
(concat
2994 (car speedbar-obj-indicator
)
2996 (cdr speedbar-obj-indicator
)))))
2997 (if (input-pending-p)
2998 ;; return that we are incomplete
3000 ;; we are done, set to-do to nil
3001 (setq speedbar-obj-to-do-point nil
)
3006 (defun speedbar-check-obj-this-line (depth)
3007 "Return t if the file on this line has an associated object.
3008 Parameter DEPTH is a string with the current depth of indentation of
3009 the file being checked."
3010 (let* ((d (string-to-number depth
))
3011 (f (speedbar-line-directory d
))
3012 (fn (buffer-substring-no-properties
3013 ;; Skip-chars: thanks ptype@dra.hmg.gb
3015 (skip-chars-forward "^ "
3016 (save-excursion (end-of-line)
3019 (fulln (concat f fn
)))
3020 (if (<= 2 speedbar-verbosity-level
)
3021 (speedbar-message "Speedbar obj check...%s" fulln
))
3022 (let ((oa speedbar-obj-alist
))
3023 (while (and oa
(not (string-match (car (car oa
)) fulln
)))
3025 (if (not (and oa
(file-exists-p (concat (file-name-sans-extension fulln
)
3028 ;; Find out if the object is out of date or not.
3029 (let ((date1 (nth 5 (file-attributes fulln
)))
3030 (date2 (nth 5 (file-attributes (concat
3031 (file-name-sans-extension fulln
)
3033 (if (or (< (car date1
) (car date2
))
3034 (and (= (car date1
) (car date2
))
3035 (< (nth 1 date1
) (nth 1 date2
))))
3036 (car speedbar-obj-indicator
)
3037 (cdr speedbar-obj-indicator
)))))))
3039 ;;; Clicking Activity
3041 (defun speedbar-position-cursor-on-line ()
3042 "Position the cursor on a line."
3043 (let ((oldpos (point)))
3045 (if (looking-at "[0-9]+:\\s-*..?.? ")
3046 (goto-char (1- (match-end 0)))
3047 (goto-char oldpos
))))
3049 (defun speedbar-click (e)
3050 "Activate any speedbar buttons where the mouse is clicked.
3051 This must be bound to a mouse event. A button is any location of text
3052 with a mouse face that has a text property called `speedbar-function'.
3053 Argument E is the click event."
3054 ;; Backward compatibility let statement.
3055 (let ((speedbar-power-click dframe-power-click
))
3056 (speedbar-do-function-pointer))
3057 (dframe-quick-mouse e
))
3059 (defun speedbar-do-function-pointer ()
3060 "Look under the cursor and examine the text properties.
3061 From this extract the file/tag name, token, indentation level and call
3062 a function if appropriate."
3063 (let* ((speedbar-frame (speedbar-current-frame))
3064 (fn (get-text-property (point) 'speedbar-function
))
3065 (tok (get-text-property (point) 'speedbar-token
))
3066 ;; The 1-,+ is safe because scaning starts AFTER the point
3067 ;; specified. This lets the search include the character the
3069 (tp (previous-single-property-change
3070 (1+ (point)) 'speedbar-function
))
3071 (np (next-single-property-change
3072 (point) 'speedbar-function
))
3073 (txt (buffer-substring-no-properties (or tp
(point-min))
3074 (or np
(point-max))))
3075 (dent (save-excursion (beginning-of-line)
3077 (if (looking-at "[0-9]+")
3078 (buffer-substring-no-properties
3079 (match-beginning 0) (match-end 0))
3081 ;;(speedbar-message "%S:%S:%S:%s" fn tok txt dent)
3082 (and fn
(funcall fn txt tok dent
)))
3083 (speedbar-position-cursor-on-line))
3085 ;;; Reading info from the speedbar buffer
3087 (defun speedbar-line-text (&optional p
)
3088 "Retrieve the text after prefix junk for the current line.
3089 Optional argument P is where to start the search from."
3091 (if p
(goto-char p
))
3093 (if (looking-at (concat
3094 "\\([0-9]+\\): *[[<{]?[-+?= ][]>}@()|] \\([^ \n]+\\)"))
3095 (get-text-property (match-beginning 2) 'speedbar-text
)
3098 (defun speedbar-line-token (&optional p
)
3099 "Retrieve the token information after the prefix junk for the current line.
3100 Optional argument P is where to start the search from."
3102 (if p
(goto-char p
))
3104 (if (looking-at (concat
3105 "\\([0-9]+\\): *[[<{]?[-+?= ][]>}@()|] \\([^ \n]+\\)\\("
3106 speedbar-indicator-regex
"\\)?"))
3108 (goto-char (match-beginning 2))
3109 (get-text-property (point) 'speedbar-token
))
3112 (defun speedbar-line-file (&optional p
)
3113 "Retrieve the file or whatever from the line at point P.
3114 The return value is a string representing the file. If it is a
3115 directory, then it is the directory name."
3119 (let ((f (speedbar-line-text p
)))
3121 (let* ((depth (string-to-number (match-string 1)))
3122 (directory (speedbar-line-directory depth
)))
3123 (if (file-exists-p (concat directory f
))
3124 (concat directory f
)
3128 (defun speedbar-goto-this-file (file)
3129 "If FILE is displayed, go to this line and return t.
3130 Otherwise do not move and return nil."
3131 (let ((directory (substring (file-name-directory (expand-file-name file
))
3132 (length (expand-file-name default-directory
))))
3135 (goto-char (point-min))
3136 ;; scan all the directories
3137 (while (and directory
(not (eq directory t
)))
3138 (if (string-match "^[/\\]?\\([^/\\]+\\)" directory
)
3139 (let ((pp (match-string 1 directory
)))
3140 (if (save-match-data
3141 (re-search-forward (concat "> " (regexp-quote pp
) "$")
3143 (setq directory
(substring directory
(match-end 1)))
3144 (setq directory nil
)))
3145 (setq directory t
)))
3146 ;; find the file part
3147 (if (or (not directory
) (string= (file-name-nondirectory file
) ""))
3148 ;; only had a dir part
3151 (speedbar-position-cursor-on-line)
3153 (goto-char dest
) nil
)
3154 ;; find the file part
3155 (let ((nd (file-name-nondirectory file
)))
3156 (if (re-search-forward
3157 (concat "] \\(" (regexp-quote nd
)
3158 "\\)\\(" speedbar-indicator-regex
"\\)$")
3161 (speedbar-position-cursor-on-line)
3166 (defun speedbar-line-directory (&optional depth
)
3167 "Retrieve the directory name associated with the current line.
3168 This may require traversing backwards from DEPTH and combining the default
3169 directory with these items. This function is replaceable in
3170 `speedbar-mode-functions-list' as `speedbar-line-directory'."
3173 (let ((rf (speedbar-fetch-replacement-function 'speedbar-line-directory
)))
3174 (if rf
(funcall rf depth
) default-directory
))))
3176 (defun speedbar-files-line-directory (&optional depth
)
3177 "Retrieve the directoryname associated with the current line.
3178 This may require traversing backwards from DEPTH and combining the default
3179 directory with these items."
3185 (looking-at "^\\([0-9]+\\):")
3186 (setq depth
(string-to-number (match-string 1)))))
3187 (let ((directory nil
))
3188 (setq depth
(1- depth
))
3189 (while (/= depth -
1)
3190 (if (not (re-search-backward (format "^%d:" depth
) nil t
))
3191 (error "Error building filename of tag")
3192 (cond ((looking-at "[0-9]+:\\s-*<->\\s-+\\([^\n]+\\)")
3193 (setq directory
(concat (speedbar-line-text)
3196 ((looking-at "[0-9]+:\\s-*[-]\\s-+\\([^\n]+\\)")
3197 ;; This is the start of our directory.
3198 (setq directory
(speedbar-line-text)))))
3199 (setq depth
(1- depth
)))
3201 (string-match (concat speedbar-indicator-regex
"$")
3203 (setq directory
(substring directory
0 (match-beginning 0))))
3204 (concat default-directory directory
)))))
3206 (defun speedbar-directory-line (directory)
3207 "Position the cursor on the line specified by DIRECTORY."
3209 (if (string-match "[/\\]$" directory
)
3210 (setq directory
(substring directory
0 (match-beginning 0))))
3211 (let ((nomatch t
) (depth 0)
3212 (fname (file-name-nondirectory directory
))
3213 (pname (file-name-directory directory
)))
3214 (if (not (member pname speedbar-shown-directories
))
3215 (error "Internal Error: File %s not shown in speedbar" directory
))
3216 (goto-char (point-min))
3219 (concat "[]>] \\(" (regexp-quote fname
)
3220 "\\)\\(" speedbar-indicator-regex
"\\)?$")
3223 (looking-at "\\([0-9]+\\):")
3224 (setq depth
(string-to-number (match-string 0))
3225 nomatch
(not (string= pname
(speedbar-line-directory depth
))))
3230 (defun speedbar-edit-line ()
3231 "Edit whatever tag or file is on the current speedbar line."
3235 ;; If this fails, then it is a non-standard click, and as such,
3236 ;; perfectly allowed.
3237 (if (re-search-forward "[]>?}] [^ ]"
3238 (save-excursion (end-of-line) (point))
3242 (speedbar-do-function-pointer))
3244 (speedbar-do-function-pointer)))
3246 (defun speedbar-expand-line (&optional arg
)
3247 "Expand the line under the cursor.
3248 With universal argument ARG, flush cached data."
3251 (let* ((dframe-power-click arg
)
3252 (speedbar-power-click arg
))
3255 (re-search-forward ":\\s-*.\\+. "
3256 (save-excursion (end-of-line) (point)))
3258 (speedbar-do-function-pointer))
3259 (error (speedbar-position-cursor-on-line)))))
3261 (defun speedbar-flush-expand-line ()
3262 "Expand the line under the cursor and flush any cached information."
3264 (speedbar-expand-line 1))
3266 (defun speedbar-contract-line ()
3267 "Contract the line under the cursor."
3272 (re-search-forward ":\\s-*.-. "
3273 (save-excursion (end-of-line) (point)))
3275 (speedbar-do-function-pointer))
3276 (error (speedbar-position-cursor-on-line))))
3278 (defun speedbar-toggle-line-expansion ()
3279 "Contract or expand the line under the cursor."
3284 (re-search-forward ":\\s-*.[-+]. "
3285 (save-excursion (end-of-line) (point)))
3287 (speedbar-do-function-pointer))
3288 (error (speedbar-position-cursor-on-line))))
3290 (defun speedbar-expand-line-descendants (&optional arg
)
3291 "Expand the line under the cursor and all descendants.
3292 Optional argument ARG indicates that any cache should be flushed."
3294 (speedbar-expand-line arg
)
3295 ;; Now, inside the area expaded here, expand all subnodes of
3296 ;; the same descendant type.
3298 (speedbar-next 1) ;; Move into the list.
3303 (speedbar-expand-line-descendants arg
)
3304 (speedbar-restricted-next 1))
3305 (error (setq err t
))))))
3308 (defun speedbar-contract-line-descendants ()
3309 "Expand the line under the cursor and all descendants."
3311 (speedbar-contract-line)
3312 ;; Don't need to do anything else since all descendants are
3313 ;; hidden by default anyway. Yay! It's easy.
3316 (defun speedbar-find-file (text token indent
)
3317 "Speedbar click handler for filenames.
3318 TEXT, the file will be displayed in the attached frame.
3319 TOKEN is unused, but required by the click handler. INDENT is the
3320 current indentation level."
3321 (let ((cdd (speedbar-line-directory indent
)))
3322 ;; Run before visiting file hook here.
3323 (let ((f (selected-frame)))
3324 (dframe-select-attached-frame speedbar-frame
)
3325 (run-hooks 'speedbar-before-visiting-file-hook
)
3327 (speedbar-find-file-in-frame (concat cdd text
))
3328 (speedbar-stealthy-updates)
3329 (run-hooks 'speedbar-visiting-file-hook
)
3330 ;; Reset the timer with a new timeout when cliking a file
3331 ;; in case the user was navigating directories, we can cancel
3332 ;; that other timer.
3333 (speedbar-set-timer dframe-update-speed
))
3334 (dframe-maybee-jump-to-attached-frame))
3336 (defun speedbar-dir-follow (text token indent
)
3337 "Speedbar click handler for directory names.
3338 Clicking a directory will cause the speedbar to list files in
3339 the subdirectory TEXT. TOKEN is an unused requirement. The
3340 subdirectory chosen will be at INDENT level."
3341 (setq default-directory
3342 (concat (expand-file-name (concat (speedbar-line-directory indent
) text
))
3344 ;; Because we leave speedbar as the current buffer,
3345 ;; update contents will change directory without
3346 ;; having to touch the attached frame. Turn off smart expand just
3348 (let ((speedbar-smart-directory-expand-flag nil
))
3349 (speedbar-update-contents))
3350 (speedbar-set-timer speedbar-navigating-speed
)
3351 (setq speedbar-last-selected-file nil
)
3352 (speedbar-stealthy-updates))
3354 (defun speedbar-delete-subblock (indent)
3355 "Delete text from point to indentation level INDENT or greater.
3356 Handles end-of-sublist smartly."
3357 (speedbar-with-writable
3359 (end-of-line) (forward-char 1)
3360 (let ((start (point)))
3361 (while (and (looking-at "^\\([0-9]+\\):")
3362 (> (string-to-number (match-string 1)) indent
)
3365 (beginning-of-line))
3366 (delete-region start
(point))))))
3368 (defun speedbar-dired (text token indent
)
3369 "Speedbar click handler for directory expand button.
3370 Clicking this button expands or contracts a directory. TEXT is the
3371 button clicked which has either a + or -. TOKEN is the directory to be
3372 expanded. INDENT is the current indentation level."
3373 (cond ((string-match "+" text
) ;we have to expand this dir
3374 (setq speedbar-shown-directories
3375 (cons (expand-file-name
3376 (concat (speedbar-line-directory indent
) token
"/"))
3377 speedbar-shown-directories
))
3378 (speedbar-change-expand-button-char ?-
)
3379 (speedbar-reset-scanners)
3381 (end-of-line) (forward-char 1)
3382 (speedbar-with-writable
3383 (speedbar-default-directory-list
3384 (concat (speedbar-line-directory indent
) token
"/")
3386 ((string-match "-" text
) ;we have to contract this node
3387 (speedbar-reset-scanners)
3388 (let ((oldl speedbar-shown-directories
)
3390 (td (expand-file-name
3391 (concat (speedbar-line-directory indent
) token
))))
3393 (if (not (string-match (concat "^" (regexp-quote td
)) (car oldl
)))
3394 (setq newl
(cons (car oldl
) newl
)))
3395 (setq oldl
(cdr oldl
)))
3396 (setq speedbar-shown-directories
(nreverse newl
)))
3397 (speedbar-change-expand-button-char ?
+)
3398 (speedbar-delete-subblock indent
)
3400 (t (error "Ooops... not sure what to do")))
3401 (speedbar-center-buffer-smartly)
3402 (save-excursion (speedbar-stealthy-updates)))
3404 (defun speedbar-directory-buttons-follow (text token indent
)
3405 "Speedbar click handler for default directory buttons.
3406 TEXT is the button clicked on. TOKEN is the directory to follow.
3407 INDENT is the current indentation level and is unused."
3408 (if (string-match "^[A-z]:$" token
)
3409 (setq default-directory
(concat token
"/"))
3410 (setq default-directory token
))
3411 ;; Because we leave speedbar as the current buffer,
3412 ;; update contents will change directory without
3413 ;; having to touch the attached frame.
3414 (speedbar-update-contents)
3415 (speedbar-set-timer speedbar-navigating-speed
))
3417 (defun speedbar-tag-file (text token indent
)
3418 "The cursor is on a selected line. Expand the tags in the specified file.
3419 The parameter TEXT and TOKEN are required, where TEXT is the button
3420 clicked, and TOKEN is the file to expand. INDENT is the current
3422 (cond ((string-match "+" text
) ;we have to expand this file
3423 (let* ((fn (expand-file-name (concat (speedbar-line-directory indent
)
3426 (lst (speedbar-fetch-dynamic-tags fn
)))
3427 ;; if no list, then remove expando button
3429 (speedbar-change-expand-button-char ??
)
3430 (speedbar-change-expand-button-char ?-
)
3431 (speedbar-with-writable
3433 (end-of-line) (forward-char 1)
3434 (funcall (car lst
) indent
(cdr lst
)))))))
3435 ((string-match "-" text
) ;we have to contract this node
3436 (speedbar-change-expand-button-char ?
+)
3437 (speedbar-delete-subblock indent
))
3438 (t (error "Ooops... not sure what to do")))
3439 (speedbar-center-buffer-smartly))
3441 (defun speedbar-tag-find (text token indent
)
3442 "For the tag TEXT in a file TOKEN, go to that position.
3443 INDENT is the current indentation level."
3444 (let ((file (speedbar-line-directory indent
)))
3445 (let ((f (selected-frame)))
3446 (dframe-select-attached-frame speedbar-frame
)
3447 (run-hooks 'speedbar-before-visiting-tag-hook
)
3449 (speedbar-find-file-in-frame file
)
3450 (save-excursion (speedbar-stealthy-updates))
3451 ;; Reset the timer with a new timeout when cliking a file
3452 ;; in case the user was navigating directories, we can cancel
3453 ;; that other timer.
3454 (speedbar-set-timer dframe-update-speed
)
3456 (run-hooks 'speedbar-visiting-tag-hook
)
3457 (dframe-maybee-jump-to-attached-frame)
3460 (defun speedbar-tag-expand (text token indent
)
3461 "Expand a tag sublist. Imenu will return sub-lists of specialized tag types.
3462 Etags does not support this feature. TEXT will be the button
3463 string. TOKEN will be the list, and INDENT is the current indentation
3465 (cond ((string-match "+" text
) ;we have to expand this file
3466 (speedbar-change-expand-button-char ?-
)
3467 (speedbar-with-writable
3469 (end-of-line) (forward-char 1)
3470 (speedbar-insert-generic-list indent token
'speedbar-tag-expand
3471 'speedbar-tag-find
))))
3472 ((string-match "-" text
) ;we have to contract this node
3473 (speedbar-change-expand-button-char ?
+)
3474 (speedbar-delete-subblock indent
))
3475 (t (error "Ooops... not sure what to do")))
3476 (speedbar-center-buffer-smartly))
3478 ;;; Loading files into the attached frame.
3480 (defcustom speedbar-select-frame-method
'attached
3481 "*Specify how to select a frame for displaying a file.
3482 A value of 'attached means to use the attached frame (the frame
3483 that speedbar was started from.) A number such as 1 or -1 means to
3484 pass that number to `other-frame' while selecting a frame from speedbar."
3488 (defun speedbar-find-file-in-frame (file)
3489 "This will load FILE into the speedbar attached frame.
3490 If the file is being displayed in a different frame already, then raise that
3492 (let* ((buff (find-file-noselect file
))
3493 (bwin (get-buffer-window buff
0)))
3496 (select-window bwin
)
3497 (raise-frame (window-frame bwin
)))
3498 (if dframe-power-click
3499 (let ((pop-up-frames t
)) (select-window (display-buffer buff
)))
3500 (if (numberp speedbar-select-frame-method
)
3501 (other-frame speedbar-select-frame-method
)
3502 (dframe-select-attached-frame speedbar-frame
))
3503 (switch-to-buffer buff
))))
3506 ;;; Centering Utility
3508 (defun speedbar-center-buffer-smartly ()
3509 "Recenter a speedbar buffer so the current indentation level is all visible.
3510 This assumes that the cursor is on a file, or tag of a file which the user is
3513 (save-selected-window
3515 (select-window (get-buffer-window speedbar-buffer t
))
3517 (set-buffer speedbar-buffer
)
3519 (if (<= (count-lines (point-min) (point-max))
3520 (1- (window-height (selected-window))))
3521 ;; whole buffer fits
3524 (goto-char (point-min))
3528 (let (depth start end exp p
)
3531 (setq depth
(if (looking-at "[0-9]+")
3532 (string-to-number (buffer-substring-no-properties
3533 (match-beginning 0) (match-end 0)))
3535 (setq exp
(format "^%d:" depth
)))
3538 (if (re-search-backward exp nil t
)
3539 (setq start
(point))
3540 (setq start
(point-min)))
3541 (save-excursion ;Not sure about this part.
3544 (while (and (not (re-search-forward exp nil t
))
3546 (setq depth
(1- depth
))
3547 (setq exp
(format "^%d:" depth
)))
3550 (setq end
(point-max)))))
3551 ;; Now work out the details of centering
3552 (let ((nl (count-lines start end
))
3553 (wl (1- (window-height (selected-window))))
3556 ;; We can't fit it all, so just center on cursor
3557 (progn (goto-char start
)
3559 ;; we can fit everything on the screen, but...
3560 (if (and (pos-visible-in-window-p start
(selected-window))
3561 (pos-visible-in-window-p end
(selected-window)))
3564 ;; we need to do something...
3566 (let ((newcent (/ (- (window-height (selected-window)) nl
) 2))
3567 (lte (count-lines start
(point-max))))
3568 (if (and (< (+ newcent lte
) (window-height (selected-window)))
3569 (> (- (window-height (selected-window)) lte
1)
3571 (setq newcent
(- (window-height (selected-window))
3573 (recenter newcent
))))
3576 ;;; Tag Management -- List of expanders:
3578 (defun speedbar-fetch-dynamic-tags (file)
3579 "Return a list of tags generated dynamically from FILE.
3580 This uses the entries in `speedbar-dynamic-tags-function-list'
3581 to find the proper tags. It is up to each of those individual
3582 functions to do caching and flushing if appropriate."
3584 ;; If a file is in memory, switch to that buffer. This allows
3585 ;; us to use the local variable. If the file is on disk, we
3586 ;; can try a few of the defaults that can get tags without
3587 ;; opening the file.
3588 (if (get-file-buffer file
)
3589 (set-buffer (get-file-buffer file
)))
3590 ;; If there is a buffer-local value of
3591 ;; speedbar-dynamic-tags-function-list, it will now be available.
3592 (let ((dtf speedbar-dynamic-tags-function-list
)
3594 (while (and (eq ret t
) dtf
)
3596 (if (fboundp (car (car dtf
)))
3597 (funcall (car (car dtf
)) file
)
3600 (setq dtf
(cdr dtf
))))
3602 ;; No valid tag list, return nil
3604 ;; We have some tags. Return the list with the insert fn
3606 (cons (cdr (car dtf
)) ret
)))))
3608 ;;; Tag Management -- Imenu
3610 (if (not speedbar-use-imenu-flag
)
3614 (eval-when-compile (condition-case nil
(require 'imenu
) (error nil
)))
3616 (defun speedbar-fetch-dynamic-imenu (file)
3617 "Load FILE into a buffer, and generate tags using Imenu.
3618 Returns the tag list, or t for an error."
3619 ;; Load this AND compile it in
3621 (set-buffer (find-file-noselect file
))
3622 (if dframe-power-click
(setq imenu--index-alist nil
))
3624 (let ((index-alist (imenu--make-index-alist t
)))
3625 (if speedbar-sort-tags
3626 (sort (copy-alist index-alist
)
3627 (lambda (a b
) (string< (car a
) (car b
))))
3632 ;;; Tag Management -- etags (old XEmacs compatibility part)
3634 (defvar speedbar-fetch-etags-parse-list
3635 '(;; Note that java has the same parse-group as c
3636 ("\\.\\([cChH]\\|c\\+\\+\\|cpp\\|cc\\|hh\\|java\\|cxx\\|hxx\\)\\'" .
3637 speedbar-parse-c-or-c
++tag
)
3638 ("^\\.emacs$\\|.\\(el\\|l\\|lsp\\)\\'" .
3639 "def[^i]+\\s-+\\(\\(\\w\\|[-_]\\)+\\)\\s-*\C-?")
3640 ; ("\\.\\([fF]\\|for\\|FOR\\|77\\|90\\)\\'" .
3641 ; speedbar-parse-fortran77-tag)
3642 ("\\.tex\\'" . speedbar-parse-tex-string
)
3644 "\\(\\(FUNCTION\\|function\\|PROCEDURE\\|procedure\\)\\s-+\\([a-zA-Z0-9_.:]+\\)\\)\\s-*(?^?")
3646 "Associations of file extensions and expressions for extracting tags.
3647 To add a new file type, you would want to add a new association to the
3648 list, where the car is the file match, and the cdr is the way to
3649 extract an element from the tags output. If the output is complex,
3650 use a function symbol instead of regexp. The function should expect
3651 to be at the beginning of a line in the etags buffer.
3653 This variable is ignored if `speedbar-use-imenu-flag' is non-nil.")
3655 (defvar speedbar-fetch-etags-command
"etags"
3656 "*Command used to create an etags file.
3658 This variable is ignored if `speedbar-use-imenu-flag' is t.")
3660 (defvar speedbar-fetch-etags-arguments
'("-D" "-I" "-o" "-")
3661 "*List of arguments to use with `speedbar-fetch-etags-command'.
3662 This creates an etags output buffer. Use `speedbar-toggle-etags' to
3663 modify this list conveniently.
3665 This variable is ignored if `speedbar-use-imenu-flag' is t.")
3667 (defun speedbar-toggle-etags (flag)
3668 "Toggle FLAG in `speedbar-fetch-etags-arguments'.
3669 FLAG then becomes a member of etags command line arguments. If flag
3670 is \"sort\", then toggle the value of `speedbar-sort-tags'. If its
3671 value is \"show\" then toggle the value of
3672 `speedbar-show-unknown-files'.
3674 This function is a convenience function for XEmacs menu created by
3675 Farzin Guilak <farzin@protocol.com>."
3678 ((equal flag
"sort")
3679 (setq speedbar-sort-tags
(not speedbar-sort-tags
)))
3680 ((equal flag
"show")
3681 (setq speedbar-show-unknown-files
(not speedbar-show-unknown-files
)))
3682 ((or (equal flag
"-C")
3685 (if (member flag speedbar-fetch-etags-arguments
)
3686 (setq speedbar-fetch-etags-arguments
3687 (delete flag speedbar-fetch-etags-arguments
))
3688 (add-to-list 'speedbar-fetch-etags-arguments flag
)))
3691 (defun speedbar-fetch-dynamic-etags (file)
3692 "For FILE, run etags and create a list of symbols extracted.
3693 Each symbol will be associated with its line position in FILE."
3694 (let ((newlist nil
))
3697 (if (get-buffer "*etags tmp*")
3698 (kill-buffer "*etags tmp*")) ;kill to clean it up
3699 (if (<= 1 speedbar-verbosity-level
)
3700 (speedbar-message "Fetching etags..."))
3701 (set-buffer (get-buffer-create "*etags tmp*"))
3702 (apply 'call-process speedbar-fetch-etags-command nil
3703 (current-buffer) nil
3704 (append speedbar-fetch-etags-arguments
(list file
)))
3705 (goto-char (point-min))
3706 (if (<= 1 speedbar-verbosity-level
)
3707 (speedbar-message "Fetching etags..."))
3709 (let ((exprlst speedbar-fetch-etags-parse-list
)
3711 (while (and (not ans
) exprlst
)
3712 (if (string-match (car (car exprlst
)) file
)
3713 (setq ans
(car exprlst
)))
3714 (setq exprlst
(cdr exprlst
)))
3718 (set-buffer (get-buffer-create "*etags tmp*"))
3719 (while (not (save-excursion (end-of-line) (eobp)))
3721 (setq tnl
(speedbar-extract-one-symbol expr
)))
3722 (if tnl
(setq newlist
(cons tnl newlist
)))
3725 "Sorry, no support for a file of that extension"))))
3727 (if speedbar-sort-tags
3728 (sort newlist
(lambda (a b
) (string< (car a
) (car b
))))
3729 (reverse newlist
))))
3731 ;; This bit donated by Farzin Guilak <farzin@protocol.com> but I'm not
3732 ;; sure it's needed with the different sorting method.
3734 ;(defun speedbar-clean-etags()
3735 ; "Removes spaces before the ^? character, and removes `#define',
3736 ;return types, etc. preceding tags. This ensures that the sort operation
3737 ;works on the tags, not the return types."
3739 ; (goto-char (point-min))
3741 ; (re-search-forward "(?[ \t](?\C-?" nil t)
3742 ; (replace-match "\C-?" nil nil))
3743 ; (goto-char (point-min))
3745 ; (re-search-forward "\\(.*[ \t]+\\)\\([^ \t\n]+.*\C-?\\)" nil t)
3746 ; (delete-region (match-beginning 1) (match-end 1)))))
3748 (defun speedbar-extract-one-symbol (expr)
3749 "At point, return nil, or one alist in the form: (SYMBOL . POSITION)
3750 The line should contain output from etags. Parse the output using the
3751 regular expression EXPR."
3752 (let* ((sym (if (stringp expr
)
3754 (re-search-forward expr
(save-excursion
3757 (buffer-substring-no-properties (match-beginning 1)
3760 (pos (let ((j (re-search-forward "[\C-?\C-a]\\([0-9]+\\),\\([0-9]+\\)"
3766 (1+ (string-to-number (buffer-substring-no-properties
3774 (defun speedbar-parse-c-or-c++tag
()
3775 "Parse a C or C++ tag, which tends to be a little complex."
3777 (let ((bound (save-excursion (end-of-line) (point))))
3778 (cond ((re-search-forward "\C-?\\([^\C-a]+\\)\C-a" bound t
)
3779 (buffer-substring-no-properties (match-beginning 1)
3781 ((re-search-forward "\\<\\([^ \t]+\\)\\s-+new(" bound t
)
3782 (buffer-substring-no-properties (match-beginning 1)
3784 ((re-search-forward "\\<\\([^ \t(]+\\)\\s-*(\C-?" bound t
)
3785 (buffer-substring-no-properties (match-beginning 1)
3790 (defun speedbar-parse-tex-string ()
3791 "Parse a Tex string. Only find data which is relevant."
3793 (let ((bound (save-excursion (end-of-line) (point))))
3794 (cond ((re-search-forward "\\(\\(sub\\)*section\\|chapter\\|cite\\)\\s-*{[^\C-?}]*}?" bound t
)
3795 (buffer-substring-no-properties (match-beginning 0)
3800 ;;; BUFFER DISPLAY mode.
3802 (defvar speedbar-buffers-key-map nil
3803 "Keymap used when in the buffers display mode.")
3805 (if speedbar-buffers-key-map
3807 (setq speedbar-buffers-key-map
(speedbar-make-specialized-keymap))
3809 ;; Basic tree features
3810 (define-key speedbar-buffers-key-map
"e" 'speedbar-edit-line
)
3811 (define-key speedbar-buffers-key-map
"\C-m" 'speedbar-edit-line
)
3812 (define-key speedbar-buffers-key-map
"+" 'speedbar-expand-line
)
3813 (define-key speedbar-buffers-key-map
"=" 'speedbar-expand-line
)
3814 (define-key speedbar-buffers-key-map
"-" 'speedbar-contract-line
)
3815 (define-key speedbar-buffers-key-map
" " 'speedbar-toggle-line-expansion
)
3817 ;; Buffer specific keybindings
3818 (define-key speedbar-buffers-key-map
"k" 'speedbar-buffer-kill-buffer
)
3819 (define-key speedbar-buffers-key-map
"r" 'speedbar-buffer-revert-buffer
)
3823 (defvar speedbar-buffer-easymenu-definition
3824 '(["Jump to buffer" speedbar-edit-line t
]
3825 ["Expand File Tags" speedbar-expand-line
3826 (save-excursion (beginning-of-line)
3827 (looking-at "[0-9]+: *.\\+. "))]
3828 ["Flush Cache & Expand" speedbar-flush-expand-line
3829 (save-excursion (beginning-of-line)
3830 (looking-at "[0-9]+: *.\\+. "))]
3831 ["Contract File Tags" speedbar-contract-line
3832 (save-excursion (beginning-of-line)
3833 (looking-at "[0-9]+: *.-. "))]
3835 ["Kill Buffer" speedbar-buffer-kill-buffer
3836 (save-excursion (beginning-of-line)
3837 (looking-at "[0-9]+: *.[-+?]. "))]
3838 ["Revert Buffer" speedbar-buffer-revert-buffer
3839 (save-excursion (beginning-of-line)
3840 (looking-at "[0-9]+: *.[-+?]. "))]
3842 "Menu item elements shown when displaying a buffer list.")
3844 (defun speedbar-buffer-buttons (directory zero
)
3845 "Create speedbar buttons based on the buffers currently loaded.
3846 DIRECTORY is the directory to the currently active buffer, and ZERO is 0."
3847 (speedbar-buffer-buttons-engine nil
))
3849 (defun speedbar-buffer-buttons-temp (directory zero
)
3850 "Create speedbar buttons based on the buffers currently loaded.
3851 DIRECTORY is the directory to the currently active buffer, and ZERO is 0."
3852 (speedbar-buffer-buttons-engine t
))
3854 (defun speedbar-buffer-buttons-engine (temp)
3855 "Create speedbar buffer buttons.
3856 If TEMP is non-nil, then clicking on a buffer restores the previous display."
3857 (speedbar-insert-separator "Active Buffers:")
3858 (let ((bl (buffer-list))
3859 (case-fold-search t
))
3861 (if (string-match "^[ *]" (buffer-name (car bl
)))
3863 (let* ((known (string-match speedbar-file-regexp
3864 (buffer-name (car bl
))))
3865 (expchar (if known ?
+ ??
))
3866 (fn (if known
'speedbar-tag-file nil
))
3867 (fname (save-excursion (set-buffer (car bl
))
3868 (buffer-file-name))))
3869 (speedbar-make-tag-line 'bracket expchar fn
3870 (if fname
(file-name-nondirectory fname
))
3871 (buffer-name (car bl
))
3872 'speedbar-buffer-click temp
3873 'speedbar-file-face
0)
3874 (speedbar-buffers-tail-notes (car bl
))))
3876 (setq bl
(buffer-list))
3877 (speedbar-insert-separator "Scratch Buffers:")
3879 (if (not (string-match "^\\*" (buffer-name (car bl
))))
3881 (if (eq (car bl
) speedbar-buffer
)
3883 (speedbar-make-tag-line 'bracket ?? nil nil
3884 (buffer-name (car bl
))
3885 'speedbar-buffer-click temp
3886 'speedbar-file-face
0)
3887 (speedbar-buffers-tail-notes (car bl
))))
3889 (setq bl
(buffer-list))
3890 ;;(speedbar-insert-separator "Hidden Buffers:")
3892 ;; (if (not (string-match "^ " (buffer-name (car bl))))
3894 ;; (if (eq (car bl) speedbar-buffer)
3896 ;; (speedbar-make-tag-line 'bracket ?? nil nil
3897 ;; (buffer-name (car bl))
3898 ;; 'speedbar-buffer-click temp
3899 ;; 'speedbar-file-face 0)
3900 ;; (speedbar-buffers-tail-notes (car bl))))
3901 ;; (setq bl (cdr bl)))
3904 (defun speedbar-buffers-tail-notes (buffer)
3905 "Add a note to the end of the last tag line.
3906 Argument BUFFER is the buffer being tested."
3910 (setq mod
(buffer-modified-p)
3911 ro buffer-read-only
))
3912 (if ro
(speedbar-insert-button "%" nil nil nil nil t
))))
3914 (defun speedbar-buffers-item-info ()
3915 "Display information about the current buffer on the current line."
3916 (or (speedbar-item-info-tag-helper)
3917 (let* ((item (speedbar-line-text))
3918 (buffer (if item
(get-buffer item
) nil
)))
3920 (speedbar-message "%s%s %S %d %s"
3921 (if (buffer-modified-p buffer
) "* " "")
3923 (save-excursion (set-buffer buffer
) major-mode
)
3924 (save-excursion (set-buffer buffer
)
3926 (or (buffer-file-name buffer
) "<No file>"))))))
3928 (defun speedbar-buffers-line-directory (&optional depth
)
3929 "Fetch the full directory to the file (buffer) specified on the current line.
3930 Optional argument DEPTH specifies the current depth of the back search."
3933 (let ((start (point)))
3934 ;; Buffers are always at level 0
3935 (if (not (re-search-backward "^0:" nil t
))
3937 (let* ((bn (speedbar-line-text))
3938 (buffer (if bn
(get-buffer bn
))))
3943 (or (save-excursion (set-buffer buffer
)
3946 (buffer-file-name buffer
))))))))
3948 (defun speedbar-buffer-click (text token indent
)
3949 "When the users clicks on a buffer-button in speedbar.
3950 TEXT is the buffer's name, TOKEN and INDENT are unused."
3951 (if dframe-power-click
3952 (let ((pop-up-frames t
)) (select-window (display-buffer text
)))
3953 (dframe-select-attached-frame speedbar-frame
)
3954 (switch-to-buffer text
)
3955 (if token
(speedbar-change-initial-expansion-list
3956 speedbar-previously-used-expansion-list-name
))))
3958 (defun speedbar-buffer-kill-buffer ()
3959 "Kill the buffer the cursor is on in the speedbar buffer."
3962 (let ((text (speedbar-line-text)))
3963 (if (and (get-buffer text
)
3964 (speedbar-y-or-n-p (format "Kill buffer %s? " text
)))
3966 (speedbar-refresh)))))
3968 (defun speedbar-buffer-revert-buffer ()
3969 "Revert the buffer the cursor is on in the speedbar buffer."
3973 ;; If this fails, then it is a non-standard click, and as such,
3974 ;; perfectly allowed
3975 (if (re-search-forward "[]>?}] [^ ]"
3976 (save-excursion (end-of-line) (point))
3980 (buffer-substring (point) (save-excursion
3983 (if (get-buffer text
)
3986 (revert-buffer t
)))))))
3989 ;;; Useful hook values and such.
3991 (defvar speedbar-highlight-one-tag-line nil
3992 "Overlay used for highlighting the most recently jumped to tag line.")
3994 (defun speedbar-highlight-one-tag-line ()
3995 "Highlight the current line, unhighlighting a previously jumped to line."
3996 (speedbar-unhighlight-one-tag-line)
3997 (setq speedbar-highlight-one-tag-line
3998 (speedbar-make-overlay (save-excursion (beginning-of-line) (point))
3999 (save-excursion (end-of-line)
4002 (speedbar-overlay-put speedbar-highlight-one-tag-line
'face
4003 'speedbar-highlight-face
)
4004 (add-hook 'pre-command-hook
'speedbar-unhighlight-one-tag-line
)
4007 (defun speedbar-unhighlight-one-tag-line ()
4008 "Unhighlight the currently highlighted line."
4009 (if speedbar-highlight-one-tag-line
4011 (speedbar-delete-overlay speedbar-highlight-one-tag-line
)
4012 (setq speedbar-highlight-one-tag-line nil
)))
4013 (remove-hook 'pre-command-hook
'speedbar-unhighlight-one-tag-line
))
4015 (defun speedbar-recenter-to-top ()
4016 "Recenter the current buffer so POINT is on the top of the window."
4019 (defun speedbar-recenter ()
4020 "Recenter the current buffer so POINT is in the center of the window."
4021 (recenter (/ (window-height (selected-window)) 2)))
4024 ;;; Color loading section.
4026 (defface speedbar-button-face
'((((class color
) (background light
))
4027 (:foreground
"green4"))
4028 (((class color
) (background dark
))
4029 (:foreground
"green3")))
4030 "Face used for +/- buttons."
4031 :group
'speedbar-faces
)
4033 (defface speedbar-file-face
'((((class color
) (background light
))
4034 (:foreground
"cyan4"))
4035 (((class color
) (background dark
))
4036 (:foreground
"cyan"))
4038 "Face used for file names."
4039 :group
'speedbar-faces
)
4041 (defface speedbar-directory-face
'((((class color
) (background light
))
4042 (:foreground
"blue4"))
4043 (((class color
) (background dark
))
4044 (:foreground
"light blue")))
4045 "Face used for directory names."
4046 :group
'speedbar-faces
)
4047 (defface speedbar-tag-face
'((((class color
) (background light
))
4048 (:foreground
"brown"))
4049 (((class color
) (background dark
))
4050 (:foreground
"yellow")))
4051 "Face used for displaying tags."
4052 :group
'speedbar-faces
)
4054 (defface speedbar-selected-face
'((((class color
) (background light
))
4055 (:foreground
"red" :underline t
))
4056 (((class color
) (background dark
))
4057 (:foreground
"red" :underline t
))
4059 "Face used to underline the file in the active window."
4060 :group
'speedbar-faces
)
4062 (defface speedbar-highlight-face
'((((class color
) (background light
))
4063 (:background
"green"))
4064 (((class color
) (background dark
))
4065 (:background
"sea green"))
4066 (((class grayscale monochrome
)
4068 (:background
"black"))
4069 (((class grayscale monochrome
)
4071 (:background
"white")))
4072 "Face used for highlighting buttons with the mouse."
4073 :group
'speedbar-faces
)
4075 (defface speedbar-separator-face
'((((class color
) (background light
))
4079 (((class color
) (background dark
))
4083 (((class grayscale monochrome
)
4085 (:background
"black"
4088 (((class grayscale monochrome
)
4090 (:background
"white"
4092 :overline
"black")))
4093 "Face used for separator labes in a display."
4094 :group
'speedbar-faces
)
4096 ;; some edebug hooks
4097 (add-hook 'edebug-setup-hook
4099 (def-edebug-spec speedbar-with-writable def-body
)))
4101 ;; Fix a font lock problem for some versions of Emacs
4102 (if (boundp 'font-lock-global-modes
)
4103 (if (listp font-lock-global-modes
)
4104 (add-to-list 'font-lock-global-modes
'(not speedbar-mode
))
4109 ;;; Obsolete variables and functions
4111 (define-obsolete-variable-alias
4112 'speedbar-ignored-path-regexp
'speedbar-ignored-directory-regexp
)
4114 (define-obsolete-variable-alias 'speedbar-ignored-path-expressions
4115 'speedbar-ignored-directory-expressions
)
4117 (define-obsolete-function-alias 'speedbar-add-ignored-path-regexp
4118 'speedbar-add-ignored-directory-regexp
)
4120 (define-obsolete-function-alias 'speedbar-line-path
4121 'speedbar-line-directory
)
4123 (define-obsolete-function-alias 'speedbar-buffers-line-path
4124 'speedbar-buffers-line-directory
)
4126 (define-obsolete-function-alias 'speedbar-path-line
4127 'speedbar-directory-line
)
4129 (define-obsolete-function-alias 'speedbar-buffers-line-path
4130 'speedbar-buffers-line-directory
)
4134 ;; run load-time hooks
4135 (run-hooks 'speedbar-load-hook
)
4137 ;; arch-tag: 4477e6d1-f78c-48b9-a503-387d3c9767d5
4138 ;;; speedbar ends here