Mercurial > emacs
annotate lisp/speedbar.el @ 22143:468e3489f1c0
(temporary-file-directory): Renamed from system-tmp-directory.
Value is now a directory name, not a file name.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 19 May 1998 05:21:42 +0000 |
parents | d8a81542dbf9 |
children | a77d473867b8 |
rev | line source |
---|---|
21650 | 1 ;;; speedbar --- quick access to files and tags |
2 | |
3 ;;; Copyright (C) 1996, 97, 98 Free Software Foundation | |
4 ;; | |
5 ;; Author: Eric M. Ludlam <zappo@gnu.ai.mit.edu> | |
6 ;; Version: 0.6.2 | |
7 ;; Keywords: file, tags, tools | |
8 ;; | |
9 ;; This file is part of GNU Emacs. | |
10 ;; | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 ;; | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 ;; | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
25 | |
26 ;;; Commentary: | |
27 ;; | |
28 ;; The speedbar provides a frame in which files, and locations in | |
29 ;; files are displayed. These items can be clicked on with mouse-2 | |
30 ;; in order to make the last active frame display that file location. | |
31 ;; | |
32 ;; Starting Speedbar: | |
33 ;; | |
34 ;; If speedbar came to you as a part of Emacs, simply type | |
35 ;; `M-x speedbar', and it will be autoloaded for you. A "Speedbar" | |
36 ;; submenu will be added under "Tools". | |
37 ;; | |
38 ;; If speedbar is not a part of your distribution, then add | |
39 ;; this to your .emacs file: | |
40 ;; | |
41 ;; (autoload 'speedbar-frame-mode "speedbar" "Popup a speedbar frame" t) | |
42 ;; (autoload 'speedbar-get-focus "speedbar" "Jump to speedbar frame" t) | |
43 ;; | |
44 ;; If you want to choose it from a menu, you can do this: | |
45 ;; | |
46 ;; Emacs: | |
47 ;; (define-key-after (lookup-key global-map [menu-bar tools]) | |
48 ;; [speedbar] '("Speedbar" . speedbar-frame-mode) [calendar]) | |
49 ;; | |
50 ;; XEmacs: | |
51 ;; (add-menu-button '("Tools") | |
52 ;; ["Speedbar" speedbar-frame-mode | |
53 ;; :style toggle | |
54 ;; :selected (and (boundp 'speedbar-frame) | |
55 ;; (frame-live-p speedbar-frame) | |
56 ;; (frame-visible-p speedbar-frame))] | |
57 ;; "--") | |
58 ;; | |
59 ;; If you want to access speedbar using only the keyboard, do this: | |
60 ;; | |
61 ;; (global-set-key [(f4)] 'speedbar-get-focus) | |
62 ;; | |
63 ;; This will let you hit f4 (or whatever key you choose) to jump | |
64 ;; focus to the speedbar frame. Pressing it again will bring you back | |
65 ;; to the attached frame. Pressing RET or e to jump to a file | |
66 ;; or tag will move you back to the attached frame. The command | |
67 ;; `speedbar-get-focus' will also create a speedbar frame if it does | |
68 ;; not exist. | |
69 ;; | |
70 ;; Customizing Speedbar: | |
71 ;; | |
72 ;; Once a speedbar frame is active, it takes advantage of idle time | |
73 ;; to keep its contents updated. The contents is usually a list of | |
74 ;; files in the directory of the currently active buffer. When | |
75 ;; applicable, tags in the active file can be expanded. | |
76 ;; | |
77 ;; To add new supported files types into speedbar, use the function | |
78 ;; `speedbar-add-supported-extension' If speedbar complains that the | |
79 ;; file type is not supported, that means there is no built in | |
80 ;; support from imenu, and the etags part wasn't set up correctly. You | |
81 ;; may add elements to `speedbar-supported-extension-expressions' as long | |
82 ;; as it is done before speedbar is loaded. | |
83 ;; | |
84 ;; To prevent speedbar from following you into certain directories | |
85 ;; use the function `speedbar-add-ignored-path-regexp' too add a new | |
86 ;; regular expression matching a type of path. You may add list | |
87 ;; elements to `speedbar-ignored-path-expressions' as long as it is | |
88 ;; done before speedbar is loaded. | |
89 ;; | |
90 ;; To add new file types to imenu, see the documentation in the | |
91 ;; file imenu.el that comes with emacs. To add new file types which | |
92 ;; etags supports, you need to modify the variable | |
93 ;; `speedbar-fetch-etags-parse-list'. | |
94 ;; | |
95 ;; If the updates are going too slow for you, modify the variable | |
96 ;; `speedbar-update-speed' to a longer idle time before updates. | |
97 ;; | |
98 ;; If you navigate directories, you will probably notice that you | |
99 ;; will navigate to a directory which is eventually replaced after | |
100 ;; you go back to editing a file (unless you pull up a new file.) | |
101 ;; The delay time before this happens is in | |
102 ;; `speedbar-navigating-speed', and defaults to 10 seconds. | |
103 ;; | |
104 ;; Users XEmacs previous to 20 may want to change the default | |
105 ;; timeouts for `speedbar-update-speed' to something longer as XEmacs | |
106 ;; doesn't have idle timers, the speedbar timer keeps going off | |
107 ;; arbitrarily while you're typing. It's quite pesky. | |
108 ;; | |
109 ;; Users of really old emacsen without the needed timers will not | |
110 ;; have speedbar updating automatically. Use "r" to refresh the | |
111 ;; display after changing directories. Remember, do not interrupt the | |
112 ;; stealthy updates or your display may not be completely refreshed. | |
113 ;; | |
114 ;; See optional file `speedbspec.el' for additional configurations | |
115 ;; which allow speedbar to create specialized lists for special modes | |
116 ;; that are not file-related. | |
117 ;; | |
118 ;; AUC-TEX users: The imenu tags for AUC-TEX mode don't work very | |
119 ;; well. Use the imenu keywords from tex-mode.el for better results. | |
120 ;; | |
121 ;; This file requires the library package assoc (association lists) | |
122 ;; and the package custom (for easy configuration of speedbar) | |
123 ;; http://www.dina.kvl.dk/~abraham/custom/ | |
124 ;; | |
125 ;; If you do not have custom installed, you can still get face colors | |
126 ;; by modifying the faces directly in your .emacs file, or setting | |
127 ;; them in your .Xdefaults file. | |
128 ;; Here is an example .Xdefaults for a dark background: | |
129 ;; | |
130 ;; emacs*speedbar-button-face.attributeForeground: Aquamarine | |
131 ;; emacs*speedbar-selected-face.attributeForeground: red | |
132 ;; emacs*speedbar-selected-face.attributeUnderline: true | |
133 ;; emacs*speedbar-directory-face.attributeForeground: magenta | |
134 ;; emacs*speedbar-file-face.attributeForeground: green3 | |
135 ;; emacs*speedbar-highlight-face.attributeBackground: sea green | |
136 ;; emacs*speedbar-tag-face.attributeForeground: yellow | |
137 | |
138 ;;; Speedbar updates can be found at: | |
139 ;; ftp://ftp.ultranet.com/pub/zappo/speedbar*.tar.gz | |
140 ;; | |
141 | |
142 ;;; Change log: | |
143 ;; 0.1 Initial Revision | |
144 ;; 0.2 Fixed problem with x-pointer-shape causing future frames not | |
145 ;; to be created. | |
146 ;; Fixed annoying habit of `speedbar-update-contents' to make | |
147 ;; it possible to accidentally kill the speedbar buffer. | |
148 ;; Clicking directory names now only changes the contents of | |
149 ;; the speedbar, and does not cause a dired mode to appear. | |
150 ;; Clicking the <+> next to the directory does cause dired to | |
151 ;; be run. | |
152 ;; Added XEmacs support, which means timer support moved to a | |
153 ;; platform independant call. | |
154 ;; Added imenu support. Now modes are supported by imenu | |
155 ;; first, and etags only if the imenu call doesn't work. | |
156 ;; Imenu is a little faster than etags, and is more emacs | |
157 ;; friendly. | |
158 ;; Added more user control variables described in the commentary. | |
159 ;; Added smart recentering when nodes are opened and closed. | |
160 ;; 0.3 x-pointer-shape fixed for emacs 19.35, so I put that check in. | |
161 ;; Added invisible codes to the beginning of each line. | |
162 ;; Added list aproach to node expansion for easier addition of new | |
163 ;; types of things to expand by | |
164 ;; Added multi-level path name support | |
165 ;; Added multi-level tag name support. | |
166 ;; Only mouse-2 is now used for node expansion | |
167 ;; Added keys e + - to edit expand, and contract node lines | |
168 ;; Added longer legal file regexp for all those modes which support | |
169 ;; imenu. (pascal, fortran90, ada, pearl) | |
170 ;; Added pascal support to etags from Dave Penkler <dave_penkler@grenoble.hp.com> | |
171 ;; Fixed centering algorithm | |
172 ;; Tried to choose background independent colors. Made more robust. | |
173 ;; Rearranged code into a more logical order | |
174 ;; 0.3.1 Fixed doc & broken keybindings | |
175 ;; Added mode hooks. | |
176 ;; Improved color selection to be background mode smart | |
177 ;; `nil' passed to `speedbar-frame-mode' now toggles the frame as | |
178 ;; advertised in the doc string | |
179 ;; 0.4a Added modified patch from Dan Schmidt <dfan@lglass.com> allowing a | |
180 ;; directory cache to be maintained speeding up revisiting of files. | |
181 ;; Default raise-lower behavior is now off by default. | |
182 ;; Added some menu items for edit expand and contract. | |
183 ;; Pre 19.31 emacsen can run without idle timers. | |
184 ;; Added some patch information from Farzin Guilak <farzin@protocol.com> | |
185 ;; adding xemacs specifics, and some etags upgrades. | |
186 ;; Added ability to set a faces symbol-value to a string | |
187 ;; representing the desired foreground color. (idea from | |
188 ;; Farzin Guilak, but implemented differently) | |
189 ;; Fixed problem with 1 character buttons. | |
190 ;; Added support for new Imenu marker technique. | |
191 ;; Added `speedbar-load-hooks' for things to run only once on | |
192 ;; load such as updating one of the many lists. | |
193 ;; Added `speedbar-supported-extension-expressions' which is a | |
194 ;; list of extensions that speedbar will tag. This variable | |
195 ;; should only be updated with `speedbar-add-supported-extension' | |
196 ;; Moved configure dialog support to a separate file so | |
197 ;; speedbar is not dependant on eieio to run | |
198 ;; Fixed list-contraction problem when the item was at the end | |
199 ;; of a sublist. | |
200 ;; Fixed XEmacs multi-frame timer selecting bug problem. | |
201 ;; Added `speedbar-ignored-modes' which is a list of major modes | |
202 ;; speedbar will not follow when it is displayed in the selected frame | |
203 ;; 0.4 When the file being edited is not in the list, and is a file | |
204 ;; that should be in the list, the speedbar cache is replaced. | |
205 ;; Temp buffers are now shown in the attached frame not the | |
206 ;; speedbar frame | |
207 ;; New variables `speedbar-vc-*' and `speedbar-stealthy-function-list' | |
208 ;; added. `speedbar-update-current-file' is now a member of | |
209 ;; the stealthy list. New function `speedbar-check-vc' will | |
210 ;; examine each file and mark it if it is checked out. To | |
211 ;; add new version control types, override the function | |
212 ;; `speedbar-this-file-in-vc' and `speedbar-vc-check-dir-p'. | |
213 ;; The stealth list is interruptible so that long operations | |
214 ;; do not interrupt someones editing flow. Other long | |
215 ;; speedbar updates will be added to the stealthy list in the | |
216 ;; future should interesting ones be needed. | |
217 ;; Added many new functions including: | |
218 ;; `speedbar-item-byte-compile' `speedbar-item-load' | |
219 ;; `speedbar-item-copy' `speedbar-item-rename' `speedbar-item-delete' | |
220 ;; and `speedbar-item-info' | |
221 ;; If the user kills the speedbar buffer in some way, the frame will | |
222 ;; be removed. | |
223 ;; 0.4.1 Bug fixes | |
224 ;; <mark.jeffries@nomura.co.uk> added `speedbar-update-flag', | |
225 ;; XEmacs fixes for menus, and tag sorting, and quit key. | |
226 ;; Modeline now updates itself based on window-width. | |
227 ;; Frame is cached when closed to make pulling it up again faster. | |
228 ;; Speedbars window is now marked as dedicated. | |
229 ;; Added bindings: <grossjoh@charly.informatik.uni-dortmund.de> | |
230 ;; Long directories are now span multiple lines autmoatically | |
231 ;; Added `speedbar-directory-button-trim-method' to specify how to | |
232 ;; sorten the directory button to fit on the screen. | |
233 ;; 0.4.2 Add one level of full-text cache. | |
234 ;; Add `speedbar-get-focus' to switchto/raise the speedbar frame. | |
235 ;; Editing thing-on-line will auto-raise the attached frame. | |
236 ;; Bound `U' to `speedbar-up-directory' command. | |
237 ;; Refresh will now maintain all subdirectories that were open | |
238 ;; when the refresh was requested. (This does not include the | |
239 ;; tags, only the directories) | |
240 ;; 0.4.3 Bug fixes | |
241 ;; 0.4.4 Added `speedbar-ignored-path-expressions' and friends. | |
242 ;; Configuration menu items not displayed if dialog-mode not present | |
243 ;; Speedbar buffer now starts with a space, and is not deleted | |
244 ;; ewhen the speedbar frame is closed. This prevents the invisible | |
245 ;; frame from preventing buffer switches with other buffers. | |
246 ;; Fixed very bad bug in the -add-[extension|path] functions. | |
247 ;; Added `speedbar-find-file-in-frame' which will always pop up a frame | |
248 ;; that is already display a buffer selected in the speedbar buffer. | |
249 ;; Added S-mouse2 as "power click" for always poping up a new frame. | |
250 ;; and always rescanning with imenu (ditching the imenu cache), and | |
251 ;; always rescanning directories. | |
252 ;; 0.4.5 XEmacs bugfixes and enhancements. | |
253 ;; Window Title simplified. | |
254 ;; 0.4.6 Fixed problems w/ dedicated minibuffer frame. | |
255 ;; Fixed errors reported by checkdoc. | |
256 ;; 0.5 Mode-specific contents added. Controlled w/ the variable | |
257 ;; `speedbar-mode-specific-contents-flag'. See speedbspec | |
258 ;; for info on enabling this feature. | |
259 ;; `speedbar-load-hook' name change and pointer check against | |
260 ;; major-mode. Suggested by Sam Steingold <sds@ptc.com> | |
261 ;; Quit auto-selects the attached frame. | |
262 ;; Ranamed `speedbar-do-updates' to `speedbar-update-flag' | |
263 ;; Passes checkdoc. | |
264 ;; 0.5.1 Advice from ptype@dra.hmg.gb: | |
265 ;; Use `post-command-idle-hook' in older emacsen | |
266 ;; `speedbar-sort-tags' now works with imenu. | |
267 ;; Unknown files (marked w/ ?) can now be operated on w/ | |
268 ;; file commands. | |
269 ;; `speedbar-vc-*-hook's for easilly adding new version control systems. | |
270 ;; Checkin/out w/ vc will reset the scanners and update the * marker. | |
271 ;; Fixed ange-ftp require compile time problem. | |
272 ;; Fixed XEmacs menu bar bug. | |
273 ;; Added `speedbar-activity-change-focus-flag' to control if the | |
274 ;; focus changes w/ mouse events. | |
275 ;; Added `speedbar-sort-tags' toggle to the menubar. | |
276 ;; Added `speedbar-smart-directory-expand-flag' to toggle how | |
277 ;; new directories might be inserted into the speedbar hierarchy. | |
278 ;; Added `speedbar-visiting-[tag|file]hook' which is called whenever | |
279 ;; speedbar pulls up a file or tag in the attached frame. Setting | |
280 ;; this to `reposition-window' will do nice things to function tags. | |
281 ;; Fixed text-cache default-directory bug. | |
282 ;; Emacs 20 char= support. | |
283 ;; 0.5.2 Customization | |
284 ;; For older emacsen, you will need to download the new defcustom | |
285 ;; package to get nice faces for speedbar | |
286 ;; mouse1 Double-click is now the same as middle click. | |
287 ;; No mouse pointer shape stuff for XEmacs (is there any?) | |
288 ;; 0.5.3 Regressive support for non-custom enabled emacsen. | |
289 ;; Fixed serious problem w/ 0.5.2 and ignored paths. | |
290 ;; `condition-case' no longer used in timer fcn. | |
291 ;; `speedbar-edit-line' is now smarter w/ special modes. | |
292 ;; 0.5.4 Fixed more problems for Emacs 20 so speedbar loads correctly. | |
293 ;; Updated some documentation strings. | |
294 ;; Added customization menu item, and customized some more variables. | |
295 ;; 0.5.5 Fixed so that there can be no ignored paths | |
296 ;; Added .l & .lsp as lisp, suggested by: sshteingold@cctrading.com | |
297 ;; You can now adjust height in `speedbar-frame-parameters' | |
298 ;; XEmacs fix for use of `local-variable-p' | |
299 ;; 0.5.6 Folded in XEmacs suggestions from Hrvoje Niksic <hniksic@srce.hr> | |
300 ;; Several custom changes (group definitions, trim-method & others) | |
301 ;; Keymap changes, and ways to add menu items. | |
302 ;; Timer use changes for XEmacs 20.4 | |
303 ;; Regular expression enhancements. | |
304 ;; 0.6 Fixed up some frame definition stuff, use more convenience fns. | |
305 ;; Rehashed frame creation code for better compatibility. | |
306 ;; Fixed setting of kill-buffer hook. | |
307 ;; Default speedbar has no menubar, mouse-3 is popup menu, | |
308 ;; XEmacs double-click capability (Hrvoje Niksic <hniksic@srce.hr>) | |
309 ;; General documentation fixup. | |
310 ;; 0.6.1 Fixed button-3 menu for Emacs 20. | |
311 ;; 0.6.2 Added autoload tag to `speedbar-get-focus' | |
312 | |
313 ;;; TODO: | |
314 ;; - More functions to create buttons and options | |
315 ;; - filtering algorithms to reduce the number of tags/files displayed. | |
316 ;; - Timeout directories we haven't visited in a while. | |
317 ;; - Remeber tags when refreshing the display. (Refresh tags too?) | |
318 ;; - More 'special mode support. | |
319 ;; - C- Mouse 3 menu too much indirection | |
320 | |
321 (require 'assoc) | |
322 (require 'easymenu) | |
323 | |
324 ;; From custom web page for compatibility between versions of custom: | |
325 (eval-and-compile | |
326 (condition-case () | |
327 (require 'custom) | |
328 (error nil)) | |
329 (if (and (featurep 'custom) (fboundp 'custom-declare-variable)) | |
330 nil ;; We've got what we needed | |
331 ;; We have the old custom-library, hack around it! | |
332 (defmacro defgroup (&rest args) | |
333 nil) | |
334 (defmacro defface (var values doc &rest args) | |
335 (` (progn | |
336 (defvar (, var) (quote (, var))) | |
337 ;; To make colors for your faces you need to set your .Xdefaults | |
338 ;; or set them up ahead of time in your .emacs file. | |
339 (make-face (, var)) | |
340 ))) | |
341 (defmacro defcustom (var value doc &rest args) | |
342 (` (defvar (, var) (, value) (, doc)))))) | |
343 | |
344 ;; customization stuff | |
345 (defgroup speedbar nil | |
346 "File and tag browser frame." | |
347 :group 'tags | |
21658
d8a81542dbf9
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
21650
diff
changeset
|
348 :group 'tools |
d8a81542dbf9
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
21650
diff
changeset
|
349 :version "20.3") |
21650 | 350 |
351 (defgroup speedbar-faces nil | |
352 "Faces used in speedbar." | |
353 :prefix "speedbar-" | |
354 :group 'speedbar | |
355 :group 'faces) | |
356 | |
357 (defgroup speedbar-vc nil | |
358 "Version control display in speedbar." | |
359 :prefix "speedbar-" | |
360 :group 'speedbar) | |
361 | |
362 ;;; Code: | |
363 (defvar speedbar-xemacsp (string-match "XEmacs" emacs-version) | |
364 "Non-nil if we are running in the XEmacs environment.") | |
365 (defvar speedbar-xemacs20p (and speedbar-xemacsp (= emacs-major-version 20))) | |
366 | |
367 (defvar speedbar-initial-expansion-list | |
368 '(speedbar-directory-buttons speedbar-default-directory-list) | |
369 "List of functions to call to fill in the speedbar buffer. | |
370 Whenever a top level update is issued all functions in this list are | |
371 run. These functions will always get the default directory to use | |
372 passed in as the first parameter, and a 0 as the second parameter. | |
373 The 0 indicates the uppermost indentation level. They must assume | |
374 that the cursor is at the position where they start inserting | |
375 buttons.") | |
376 | |
377 (defvar speedbar-stealthy-function-list | |
378 '(speedbar-update-current-file speedbar-check-vc) | |
379 "List of functions to periodically call stealthily. | |
380 Each function must return nil if interrupted, or t if completed. | |
381 Stealthy functions which have a single operation should always return | |
382 t. Functions which take a long time should maintain a state (where | |
383 they are in their speedbar related calculations) and permit | |
384 interruption. See `speedbar-check-vc' as a good example.") | |
385 | |
386 (defcustom speedbar-mode-specific-contents-flag t | |
387 "*Non-nil means speedbar will show special mode contents. | |
388 This permits some modes to create customized contents for the speedbar | |
389 frame." | |
390 :group 'speedbar | |
391 :type 'boolean) | |
392 | |
393 (defvar speedbar-special-mode-expansion-list nil | |
394 "Mode specific list of functions to call to fill in speedbar. | |
395 Some modes, such as Info or RMAIL, do not relate quite as easily into | |
396 a simple list of files. When this variable is non-nil and buffer-local, | |
397 then these functions are used, creating specialized contents. These | |
398 functions are called each time the speedbar timer is called. This | |
399 allows a mode to update its contents regularly. | |
400 | |
401 Each function is called with the default and frame belonging to | |
402 speedbar, and with one parameter; the buffer requesting | |
403 the speedbar display.") | |
404 | |
405 (defcustom speedbar-visiting-file-hook nil | |
406 "Hooks run when speedbar visits a file in the selected frame." | |
407 :group 'speedbar | |
408 :type 'hook) | |
409 | |
410 (defcustom speedbar-visiting-tag-hook nil | |
411 "Hooks run when speedbar visits a tag in the selected frame." | |
412 :group 'speedbar | |
413 :type 'hook) | |
414 | |
415 (defcustom speedbar-load-hook nil | |
416 "Hooks run when speedbar is loaded." | |
417 :group 'speedbar | |
418 :type 'hook) | |
419 | |
420 (defcustom speedbar-show-unknown-files nil | |
421 "*Non-nil show files we can't expand with a ? in the expand button. | |
422 nil means don't show the file in the list." | |
423 :group 'speedbar | |
424 :type 'boolean) | |
425 | |
426 (defcustom speedbar-update-speed | |
427 (if speedbar-xemacsp | |
428 (if speedbar-xemacs20p | |
429 2 ; 1 is too obrusive in XEmacs | |
430 5) ; when no idleness, need long delay | |
431 1) | |
432 "*Idle time in seconds needed before speedbar will update itself. | |
433 Updates occur to allow speedbar to display directory information | |
434 relevant to the buffer you are currently editing." | |
435 :group 'speedbar | |
436 :type 'integer) | |
437 | |
438 (defcustom speedbar-navigating-speed 10 | |
439 "*Idle time to wait after navigation commands in speedbar are executed. | |
440 Navigation commands included expanding/contracting nodes, and moving | |
441 between different directories." | |
442 :group 'speedbar | |
443 :type 'integer) | |
444 | |
445 (defcustom speedbar-frame-parameters '((minibuffer . nil) | |
446 (width . 20) | |
447 (scroll-bar-width . 10) | |
448 (border-width . 0) | |
449 (menu-bar-lines . 0) | |
450 (unsplittable . t)) | |
451 "*Parameters to use when creating the speedbar frame in Emacs. | |
452 Parameters not listed here which will be added automatically are | |
453 `height' which will be initialized to the height of the frame speedbar | |
454 is attached to." | |
455 :group 'speedbar | |
456 :type '(repeat (sexp :tag "Parameter:"))) | |
457 | |
458 ;; These values by Hrvoje Niksic <hniksic@srce.hr> | |
459 (defcustom speedbar-frame-plist | |
460 '(minibuffer nil width 20 border-width 0 | |
461 internal-border-width 0 unsplittable t | |
462 default-toolbar-visible-p nil has-modeline-p nil | |
463 menubar-visible-p nil | |
464 ;; I don't see the particular value of these three, but... | |
465 text-pointer-glyph [cursor-font :data "top_left_arrow"] | |
466 nontext-pointer-glyph [cursor-font :data "top_left_arrow"] | |
467 selection-pointer-glyph [cursor-font :data "hand2"]) | |
468 "*Parameters to use when creating the speedbar frame in XEmacs. | |
469 Parameters not listed here which will be added automatically are | |
470 `height' which will be initialized to the height of the frame speedbar | |
471 is attached to." | |
472 :group 'speedbar | |
473 :type '(repeat (group :inline t | |
474 (symbol :tag "Property") | |
475 (sexp :tag "Value")))) | |
476 | |
477 (defcustom speedbar-use-imenu-flag (stringp (locate-library "imenu")) | |
478 "*Non-nil means use imenu for file parsing. nil to use etags. | |
479 XEmacs prior to 20.4 doesn't support imenu, therefore the default is to | |
480 use etags instead. Etags support is not as robust as imenu support." | |
481 :tag "User Imenu" | |
482 :group 'speedbar | |
483 :type 'boolean) | |
484 | |
485 (defcustom speedbar-sort-tags nil | |
486 "*If Non-nil, sort tags in the speedbar display." | |
487 :group 'speedbar | |
488 :type 'boolean) | |
489 | |
490 (defcustom speedbar-activity-change-focus-flag nil | |
491 "*Non-nil means the selected frame will change based on activity. | |
492 Thus, if a file is selected for edit, the buffer will appear in the | |
493 selected frame and the focus will change to that frame." | |
494 :group 'speedbar | |
495 :type 'boolean) | |
496 | |
497 (defcustom speedbar-directory-button-trim-method 'span | |
498 "*Indicates how the directory button will be displayed. | |
499 Possible values are: | |
500 'span - span large directories over multiple lines. | |
501 'trim - trim large directories to only show the last few. | |
502 nil - no trimming." | |
503 :group 'speedbar | |
504 :type '(radio (const :tag "Span large directories over mutiple lines." | |
505 span) | |
506 (const :tag "Trim large directories to only show the last few." | |
507 trim) | |
508 (const :tag "No trimming." nil))) | |
509 | |
510 (defcustom speedbar-smart-directory-expand-flag t | |
511 "*Non-nil means speedbar should use smart expansion. | |
512 Smart expansion only affects when speedbar wants to display a | |
513 directory for a file in the attached frame. When smart expansion is | |
514 enabled, new directories which are children of a displayed directory | |
515 are expanded in the current framework. If nil, then the current | |
516 hierarchy would be replaced with the new directory." | |
517 :group 'speedbar | |
518 :type 'boolean) | |
519 | |
520 (defcustom speedbar-before-popup-hook nil | |
521 "*Hooks called before popping up the speedbar frame." | |
522 :group 'speedbar | |
523 :type 'hook) | |
524 | |
525 (defcustom speedbar-before-delete-hook nil | |
526 "*Hooks called before deleting the speedbar frame." | |
527 :group 'speedbar | |
528 :type 'hook) | |
529 | |
530 (defcustom speedbar-mode-hook nil | |
531 "*Hooks called after creating a speedbar buffer." | |
532 :group 'speedbar | |
533 :type 'hook) | |
534 | |
535 (defcustom speedbar-timer-hook nil | |
536 "*Hooks called after running the speedbar timer function." | |
537 :group 'speedbar | |
538 :type 'hook) | |
539 | |
540 (defcustom speedbar-verbosity-level 1 | |
541 "*Verbosity level of the speedbar. 0 means say nothing. | |
542 1 means medium level verbosity. 2 and higher are higher levels of | |
543 verbosity." | |
544 :group 'speedbar | |
545 :type 'integer) | |
546 | |
547 (defcustom speedbar-vc-do-check t | |
548 "*Non-nil check all files in speedbar to see if they have been checked out. | |
549 Any file checked out is marked with `speedbar-vc-indicator'" | |
550 :group 'speedbar-vc | |
551 :type 'boolean) | |
552 | |
553 (defvar speedbar-vc-indicator " *" | |
554 "Text used to mark files which are currently checked out. | |
555 Currently only RCS is supported. Other version control systems can be | |
556 added by examining the function `speedbar-this-file-in-vc' and | |
557 `speedbar-vc-check-dir-p'") | |
558 | |
559 (defcustom speedbar-scanner-reset-hook nil | |
560 "*Hook called whenever generic scanners are reset. | |
561 Set this to implement your own scanning / rescan safe functions with | |
562 state data." | |
563 :group 'speedbar | |
564 :type 'hook) | |
565 | |
566 (defcustom speedbar-vc-path-enable-hook nil | |
567 "*Return non-nil if the current path should be checked for Version Control. | |
568 Functions in this hook must accept one parameter which is the path | |
569 being checked." | |
570 :group 'speedbar-vc | |
571 :type 'hook) | |
572 | |
573 (defcustom speedbar-vc-in-control-hook nil | |
574 "*Return non-nil if the specified file is under Version Control. | |
575 Functions in this hook must accept two parameters. The PATH of the | |
576 current file, and the FILENAME of the file being checked." | |
577 :group 'speedbar-vc | |
578 :type 'hook) | |
579 | |
580 (defvar speedbar-vc-to-do-point nil | |
581 "Local variable maintaining the current version control check position.") | |
582 | |
583 (defvar speedbar-ignored-modes nil | |
584 "*List of major modes which speedbar will not switch directories for.") | |
585 | |
586 (defun speedbar-extension-list-to-regex (extlist) | |
587 "Takes EXTLIST, a list of extensions and transforms it into regexp. | |
588 All the preceding . are stripped for an optimized expression starting | |
589 with . followed by extensions, followed by full-filenames." | |
590 (let ((regex1 nil) (regex2 nil)) | |
591 (while extlist | |
592 (if (= (string-to-char (car extlist)) ?.) | |
593 (setq regex1 (concat regex1 (if regex1 "\\|" "") | |
594 (substring (car extlist) 1))) | |
595 (setq regex2 (concat regex2 (if regex2 "\\|" "") (car extlist)))) | |
596 (setq extlist (cdr extlist))) | |
597 ;; concat all the sub-exressions together, making sure all types | |
598 ;; of parts exist during concatination. | |
599 (concat "\\(" | |
600 (if regex1 (concat "\\(\\.\\(" regex1 "\\)\\)") "") | |
601 (if (and regex1 regex2) "\\|" "") | |
602 (if regex2 (concat "\\(" regex2 "\\)") "") | |
603 "\\)$"))) | |
604 | |
605 (defvar speedbar-ignored-path-regexp nil | |
606 "Regular expression matching paths speedbar will not switch to. | |
607 Created from `speedbar-ignored-path-expressions' with the function | |
608 `speedbar-extension-list-to-regex' (A misnamed function in this case.) | |
609 Use the function `speedbar-add-ignored-path-regexp', or customize the | |
610 variable `speedbar-ignored-path-expressions' to modify this variable.") | |
611 | |
612 (defcustom speedbar-ignored-path-expressions | |
613 '("/logs?/\\'") | |
614 "*List of regular expressions matching directories speedbar will ignore. | |
615 They should included paths to directories which are notoriously very | |
616 large and take a long time to load in. Use the function | |
617 `speedbar-add-ignored-path-regexp' to add new items to this list after | |
618 speedbar is loaded. You may place anything you like in this list | |
619 before speedbar has been loaded." | |
620 :group 'speedbar | |
621 :type '(repeat (regexp :tag "Path Regexp")) | |
622 :set (lambda (sym val) | |
623 (setq speedbar-ignored-path-expressions val | |
624 speedbar-ignored-path-regexp | |
625 (speedbar-extension-list-to-regex val)))) | |
626 | |
627 (defvar speedbar-file-unshown-regexp | |
628 (let ((nstr "") (noext completion-ignored-extensions)) | |
629 (while noext | |
630 (setq nstr (concat nstr (regexp-quote (car noext)) "\\'" | |
631 (if (cdr noext) "\\|" "")) | |
632 noext (cdr noext))) | |
633 (concat nstr "\\|#[^#]+#$\\|\\.\\.?\\'")) | |
634 "*Regexp matching files we don't want displayed in a speedbar buffer. | |
635 It is generated from the variable `completion-ignored-extensions'") | |
636 | |
637 ;; this is dangerous to customize, because the defaults will probably | |
638 ;; change in the future. | |
639 (defcustom speedbar-supported-extension-expressions | |
640 (append '(".[CcHh]\\(\\+\\+\\|pp\\|c\\|h\\)?" ".tex\\(i\\(nfo\\)?\\)?" | |
641 ".el" ".emacs" ".l" ".lsp" ".p" ".java") | |
642 (if speedbar-use-imenu-flag | |
643 '(".f90" ".ada" ".pl" ".tcl" ".m" | |
644 "Makefile\\(\\.in\\)?"))) | |
645 "*List of regular expressions which will match files supported by tagging. | |
646 Do not prefix the `.' char with a double \\ to quote it, as the period | |
647 will be stripped by a simplified optimizer when compiled into a | |
648 singular expression. This variable will be turned into | |
649 `speedbar-file-regexp' for use with speedbar. You should use the | |
650 function `speedbar-add-supported-extension' to add a new extension at | |
651 runtime, or use the configuration dialog to set it in your .emacs | |
652 file." | |
653 :group 'speedbar | |
654 :type '(repeat (regexp :tag "Extension Regexp")) | |
655 :set (lambda (sym val) | |
656 (setq speedbar-supported-extension-expressions val | |
657 speedbar-file-regexp (speedbar-extension-list-to-regex val))) | |
658 ) | |
659 | |
660 (defvar speedbar-file-regexp | |
661 (speedbar-extension-list-to-regex speedbar-supported-extension-expressions) | |
662 "Regular expression matching files we know how to expand. | |
663 Created from `speedbar-supported-extension-expression' with the | |
664 function `speedbar-extension-list-to-regex'") | |
665 | |
666 (defun speedbar-add-supported-extension (extension) | |
667 "Add EXTENSION as a new supported extension for speedbar tagging. | |
668 This should start with a `.' if it is not a complete file name, and | |
669 the dot should NOT be quoted in with \\. Other regular expression | |
670 matchers are allowed however. EXTENSION may be a single string or a | |
671 list of strings." | |
672 (if (not (listp extension)) (setq extension (list extension))) | |
673 (while extension | |
674 (if (member (car extension) speedbar-supported-extension-expressions) | |
675 nil | |
676 (setq speedbar-supported-extension-expressions | |
677 (cons (car extension) speedbar-supported-extension-expressions))) | |
678 (setq extension (cdr extension))) | |
679 (setq speedbar-file-regexp (speedbar-extension-list-to-regex | |
680 speedbar-supported-extension-expressions))) | |
681 | |
682 (defun speedbar-add-ignored-path-regexp (path-expression) | |
683 "Add PATH-EXPRESSION as a new ignored path for speedbar tracking. | |
684 This function will modify `speedbar-ignored-path-regexp' and add | |
685 PATH-EXPRESSION to `speedbar-ignored-path-expressions'." | |
686 (if (not (listp path-expression)) | |
687 (setq path-expression (list path-expression))) | |
688 (while path-expression | |
689 (if (member (car path-expression) speedbar-ignored-path-expressions) | |
690 nil | |
691 (setq speedbar-ignored-path-expressions | |
692 (cons (car path-expression) speedbar-ignored-path-expressions))) | |
693 (setq path-expression (cdr path-expression))) | |
694 (setq speedbar-ignored-path-regexp (speedbar-extension-list-to-regex | |
695 speedbar-ignored-path-expressions))) | |
696 | |
697 ;; If we don't have custom, then we set it here by hand. | |
698 (if (not (fboundp 'custom-declare-variable)) | |
699 (setq speedbar-file-regexp (speedbar-extension-list-to-regex | |
700 speedbar-supported-extension-expressions) | |
701 speedbar-ignored-path-regexp (speedbar-extension-list-to-regex | |
702 speedbar-ignored-path-expressions))) | |
703 | |
704 (defvar speedbar-update-flag (or (fboundp 'run-with-idle-timer) | |
705 (fboundp 'start-itimer) | |
706 (boundp 'post-command-idle-hook)) | |
707 "*Non-nil means to automatically update the display. | |
708 When this is nil then speedbar will not follow the attached frame's path. | |
709 When speedbar is active, use: | |
710 | |
711 \\<speedbar-key-map> `\\[speedbar-toggle-updates]' | |
712 | |
713 to toggle this value.") | |
714 | |
715 (defvar speedbar-syntax-table nil | |
716 "Syntax-table used on the speedbar.") | |
717 | |
718 (if speedbar-syntax-table | |
719 nil | |
720 (setq speedbar-syntax-table (make-syntax-table)) | |
721 ;; turn off paren matching around here. | |
722 (modify-syntax-entry ?\' " " speedbar-syntax-table) | |
723 (modify-syntax-entry ?\" " " speedbar-syntax-table) | |
724 (modify-syntax-entry ?( " " speedbar-syntax-table) | |
725 (modify-syntax-entry ?) " " speedbar-syntax-table) | |
726 (modify-syntax-entry ?[ " " speedbar-syntax-table) | |
727 (modify-syntax-entry ?] " " speedbar-syntax-table)) | |
728 | |
729 | |
730 (defvar speedbar-key-map nil | |
731 "Keymap used in speedbar buffer.") | |
732 | |
733 (if speedbar-key-map | |
734 nil | |
735 (setq speedbar-key-map (make-keymap)) | |
736 (suppress-keymap speedbar-key-map t) | |
737 | |
738 ;; control | |
739 (define-key speedbar-key-map "e" 'speedbar-edit-line) | |
740 (define-key speedbar-key-map "\C-m" 'speedbar-edit-line) | |
741 (define-key speedbar-key-map "+" 'speedbar-expand-line) | |
742 (define-key speedbar-key-map "-" 'speedbar-contract-line) | |
743 (define-key speedbar-key-map "g" 'speedbar-refresh) | |
744 (define-key speedbar-key-map "t" 'speedbar-toggle-updates) | |
745 (define-key speedbar-key-map "q" 'speedbar-close-frame) | |
746 (define-key speedbar-key-map "U" 'speedbar-up-directory) | |
747 | |
748 ;; navigation | |
749 (define-key speedbar-key-map "n" 'speedbar-next) | |
750 (define-key speedbar-key-map "p" 'speedbar-prev) | |
751 (define-key speedbar-key-map " " 'speedbar-scroll-up) | |
752 (define-key speedbar-key-map [delete] 'speedbar-scroll-down) | |
753 | |
754 ;; After much use, I suddenly desired in my heart to perform dired | |
755 ;; style operations since the directory was RIGHT THERE! | |
756 (define-key speedbar-key-map "I" 'speedbar-item-info) | |
757 (define-key speedbar-key-map "B" 'speedbar-item-byte-compile) | |
758 (define-key speedbar-key-map "L" 'speedbar-item-load) | |
759 (define-key speedbar-key-map "C" 'speedbar-item-copy) | |
760 (define-key speedbar-key-map "D" 'speedbar-item-delete) | |
761 (define-key speedbar-key-map "R" 'speedbar-item-rename) | |
762 | |
763 (if speedbar-xemacsp | |
764 (progn | |
765 ;; mouse bindings so we can manipulate the items on each line | |
766 (define-key speedbar-key-map 'button2 'speedbar-click) | |
767 (define-key speedbar-key-map '(shift button2) 'speedbar-power-click) | |
768 (define-key speedbar-key-map 'button3 'speedbar-xemacs-popup-kludge) | |
769 (define-key speedbar-key-map '(meta button3) 'speedbar-mouse-item-info)) | |
770 ;; mouse bindings so we can manipulate the items on each line | |
771 (define-key speedbar-key-map [down-mouse-1] 'speedbar-double-click) | |
772 (define-key speedbar-key-map [mouse-2] 'speedbar-click) | |
773 ;; This is the power click for new frames, or refreshing a cache | |
774 (define-key speedbar-key-map [S-mouse-2] 'speedbar-power-click) | |
775 ;; This adds a small unecessary visual effect | |
776 ;;(define-key speedbar-key-map [down-mouse-2] 'speedbar-quick-mouse) | |
777 (define-key speedbar-key-map [M-mouse-2] 'speedbar-mouse-item-info) | |
778 | |
779 (define-key speedbar-key-map [down-mouse-3] 'speedbar-emacs-popup-kludge) | |
780 | |
781 ;;***** Disable disabling: Remove menubar completely. | |
782 ;; disable all menus - we don't have a lot of space to play with | |
783 ;; in such a skinny frame. This will cleverly find and nuke some | |
784 ;; user-defined menus as well if they are there. Too bad it | |
785 ;; rely's on the structure of a keymap to work. | |
786 ; (let ((k (lookup-key global-map [menu-bar]))) | |
787 ; (while k | |
788 ; (if (and (listp (car k)) (listp (cdr (car k)))) | |
789 ; (define-key speedbar-key-map (vector 'menu-bar (car (car k))) | |
790 ; 'undefined)) | |
791 ; (setq k (cdr k)))) | |
792 | |
793 ;; This lets the user scroll as if we had a scrollbar... well maybe not | |
794 (define-key speedbar-key-map [mode-line mouse-2] 'speedbar-mouse-hscroll) | |
795 )) | |
796 | |
797 (defvar speedbar-easymenu-definition-base | |
798 '("Speedbar" | |
799 ["Update" speedbar-refresh t] | |
800 ["Auto Update" speedbar-toggle-updates | |
801 :style toggle :selected speedbar-update-flag] | |
802 ) | |
803 "Base part of the speedbar menu.") | |
804 | |
805 (defvar speedbar-easymenu-definition-special | |
806 '(["Edit Item On Line" speedbar-edit-line t] | |
807 ["Show All Files" speedbar-toggle-show-all-files | |
808 :style toggle :selected speedbar-show-unknown-files] | |
809 ["Expand Item" speedbar-expand-line | |
810 (save-excursion (beginning-of-line) | |
811 (looking-at "[0-9]+: *.\\+. "))] | |
812 ["Contract Item" speedbar-contract-line | |
813 (save-excursion (beginning-of-line) | |
814 (looking-at "[0-9]+: *.-. "))] | |
815 ["Sort Tags" speedbar-toggle-sorting | |
816 :style toggle :selected speedbar-sort-tags] | |
817 "----" | |
818 ["Item Information" speedbar-item-info t] | |
819 ["Load Lisp File" speedbar-item-load | |
820 (save-excursion | |
821 (beginning-of-line) | |
822 (looking-at "[0-9]+: *\\[[+-]\\] .+\\(\\.el\\)\\( \\*\\)?$"))] | |
823 ["Byte Compile File" speedbar-item-byte-compile | |
824 (save-excursion | |
825 (beginning-of-line) | |
826 (looking-at "[0-9]+: *\\[[+-]\\] .+\\(\\.el\\)\\( \\*\\)?$"))] | |
827 ["Copy Item" speedbar-item-copy | |
828 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *\\["))] | |
829 ["Rename Item" speedbar-item-rename | |
830 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))] | |
831 ["Delete Item" speedbar-item-delete | |
832 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]) | |
833 "Additional menu items while in file-mode.") | |
834 | |
835 (defvar speedbar-easymenu-definition-trailer | |
836 (if (and (featurep 'custom) (fboundp 'custom-declare-variable)) | |
837 '("----" | |
838 ["Customize..." speedbar-customize t] | |
839 ["Close" speedbar-close-frame t]) | |
840 '("----" | |
841 ["Close" speedbar-close-frame t])) | |
842 "Menu items appearing at the end of the speedbar menu.") | |
843 | |
844 (defvar speedbar-desired-buffer nil | |
845 "Non-nil when speedbar is showing buttons specific a special mode. | |
846 In this case it is the originating buffer.") | |
847 (defvar speedbar-buffer nil | |
848 "The buffer displaying the speedbar.") | |
849 (defvar speedbar-frame nil | |
850 "The frame displaying speedbar.") | |
851 (defvar speedbar-cached-frame nil | |
852 "The frame that was last created, then removed from the display.") | |
853 (defvar speedbar-full-text-cache nil | |
854 "The last open directory is saved in its entirety for ultra-fast switching.") | |
855 (defvar speedbar-timer nil | |
856 "The speedbar timer used for updating the buffer.") | |
857 (defvar speedbar-attached-frame nil | |
858 "The frame which started speedbar mode. | |
859 This is the frame from which all data displayed in the speedbar is | |
860 gathered, and in which files and such are displayed.") | |
861 | |
862 (defvar speedbar-last-selected-file nil | |
863 "The last file which was selected in speedbar buffer.") | |
864 | |
865 (defvar speedbar-shown-directories nil | |
866 "Maintain list of directories simultaneously open in the current speedbar.") | |
867 | |
868 (defvar speedbar-directory-contents-alist nil | |
869 "An association list of directories and their contents. | |
870 Each sublist was returned by `speedbar-file-lists'. This list is | |
871 maintained to speed up the refresh rate when switching between | |
872 directories.") | |
873 | |
874 (defvar speedbar-power-click nil | |
875 "Never set this by hand. Value is t when S-mouse activity occurs.") | |
876 | |
877 | |
878 ;;; Mode definitions/ user commands | |
879 ;; | |
880 | |
881 ;;;###autoload | |
882 (defalias 'speedbar 'speedbar-frame-mode) | |
883 ;;;###autoload | |
884 (defun speedbar-frame-mode (&optional arg) | |
885 "Enable or disable speedbar. Positive ARG means turn on, negative turn off. | |
886 nil means toggle. Once the speedbar frame is activated, a buffer in | |
887 `speedbar-mode' will be displayed. Currently, only one speedbar is | |
888 supported at a time. | |
889 `speedbar-before-popup-hook' is called before popping up the speedbar frame. | |
890 `speedbar-before-delete-hook' is called before the frame is deleted." | |
891 (interactive "P") | |
892 (if (if (and speedbar-xemacsp (fboundp 'console-on-window-system-p)) | |
893 (not (console-on-window-system-p)) | |
894 (not (symbol-value 'window-system))) | |
895 (error "Speedbar is not useful outside of a windowing environment")) | |
896 ;;; RMS says this should not modify the menu. | |
897 ; (if speedbar-xemacsp | |
898 ; (add-menu-button '("Tools") | |
899 ; ["Speedbar" speedbar-frame-mode | |
900 ; :style toggle | |
901 ; :selected (and (boundp 'speedbar-frame) | |
902 ; (frame-live-p speedbar-frame) | |
903 ; (frame-visible-p speedbar-frame))] | |
904 ; "--") | |
905 ; (define-key-after (lookup-key global-map [menu-bar tools]) | |
906 ; [speedbar] '("Speedbar" . speedbar-frame-mode) [calendar])) | |
907 ;; toggle frame on and off. | |
908 (if (not arg) (if (and (frame-live-p speedbar-frame) | |
909 (frame-visible-p speedbar-frame)) | |
910 (setq arg -1) (setq arg 1))) | |
911 ;; turn the frame off on neg number | |
912 (if (and (numberp arg) (< arg 0)) | |
913 (progn | |
914 (run-hooks 'speedbar-before-delete-hook) | |
915 (if (and speedbar-frame (frame-live-p speedbar-frame)) | |
916 (progn | |
917 (setq speedbar-cached-frame speedbar-frame) | |
918 (make-frame-invisible speedbar-frame))) | |
919 (setq speedbar-frame nil) | |
920 (speedbar-set-timer nil) | |
921 ;; Used to delete the buffer. This has the annoying affect of | |
922 ;; preventing whatever took its place from ever appearing | |
923 ;; as the default after a C-x b was typed | |
924 ;;(if (bufferp speedbar-buffer) | |
925 ;; (kill-buffer speedbar-buffer)) | |
926 ) | |
927 ;; Set this as our currently attached frame | |
928 (setq speedbar-attached-frame (selected-frame)) | |
929 (run-hooks 'speedbar-before-popup-hook) | |
930 ;; Get the frame to work in | |
931 (if (frame-live-p speedbar-cached-frame) | |
932 (progn | |
933 (setq speedbar-frame speedbar-cached-frame) | |
934 (make-frame-visible speedbar-frame) | |
935 ;; Get the buffer to play with | |
936 (speedbar-mode) | |
937 (select-frame speedbar-frame) | |
938 (if (not (eq (current-buffer) speedbar-buffer)) | |
939 (switch-to-buffer speedbar-buffer)) | |
940 (set-window-dedicated-p (selected-window) t) | |
941 (raise-frame speedbar-frame) | |
942 (speedbar-set-timer speedbar-update-speed) | |
943 ) | |
944 (if (frame-live-p speedbar-frame) | |
945 (raise-frame speedbar-frame) | |
946 (setq speedbar-frame | |
947 (if speedbar-xemacsp | |
948 (make-frame (nconc (list 'height | |
949 (speedbar-needed-height)) | |
950 speedbar-frame-plist)) | |
951 (let* ((mh (cdr (assoc 'menu-bar-lines (frame-parameters)))) | |
952 (params (append speedbar-frame-parameters | |
953 (list (cons | |
954 'height | |
955 (if speedbar-xemacsp | |
956 (speedbar-needed-height) | |
957 (+ mh (frame-height)))))))) | |
958 (if (< emacs-major-version 20);;a bug is fixed in v20 & later | |
959 (make-frame params) | |
960 (let ((x-pointer-shape x-pointer-top-left-arrow) | |
961 (x-sensitive-text-pointer-shape x-pointer-hand2)) | |
962 (make-frame params)))))) | |
963 ;; reset the selection variable | |
964 (setq speedbar-last-selected-file nil) | |
965 ;; Put the buffer into the frame | |
966 (save-window-excursion | |
967 ;; Get the buffer to play with | |
968 (speedbar-mode) | |
969 (select-frame speedbar-frame) | |
970 (switch-to-buffer speedbar-buffer) | |
971 (set-window-dedicated-p (selected-window) t)) | |
972 (speedbar-set-timer speedbar-update-speed))))) | |
973 | |
974 ;;;###autoload | |
975 (defun speedbar-get-focus () | |
976 "Change frame focus to or from the speedbar frame. | |
977 If the selected frame is not speedbar, then speedbar frame is | |
978 selected. If the speedbar frame is active, then select the attached frame." | |
979 (interactive) | |
980 (if (eq (selected-frame) speedbar-frame) | |
981 (if (frame-live-p speedbar-attached-frame) | |
982 (select-frame speedbar-attached-frame)) | |
983 ;; make sure we have a frame | |
984 (if (not (frame-live-p speedbar-frame)) (speedbar-frame-mode 1)) | |
985 ;; go there | |
986 (select-frame speedbar-frame)) | |
987 (other-frame 0)) | |
988 | |
989 (defun speedbar-close-frame () | |
990 "Turn off a currently active speedbar." | |
991 (interactive) | |
992 (speedbar-frame-mode -1) | |
993 (select-frame speedbar-attached-frame) | |
994 (other-frame 0)) | |
995 | |
996 (defmacro speedbar-frame-width () | |
997 "Return the width of the speedbar frame in characters. | |
998 nil if it doesn't exist." | |
999 '(frame-width speedbar-frame)) | |
1000 | |
1001 ;; XEmacs function only. | |
1002 (defun speedbar-needed-height (&optional frame) | |
1003 "The needed height for the tool bar FRAME (in characters)." | |
1004 (or frame (setq frame (selected-frame))) | |
1005 ;; The 1 is the missing modeline/minibuffer | |
1006 (+ 1 (/ (frame-pixel-height frame) | |
1007 (face-height 'default frame)))) | |
1008 | |
1009 (defun speedbar-mode () | |
1010 "Major mode for managing a display of directories and tags. | |
1011 \\<speedbar-key-map> | |
1012 The first line represents the default path of the speedbar frame. | |
1013 Each directory segment is a button which jumps speedbar's default | |
1014 directory to that path. Buttons are activated by clicking `\\[speedbar-click]'. | |
1015 In some situations using `\\[speedbar-power-click]' is a `power click' which will | |
1016 rescan cached items, or pop up new frames. | |
1017 | |
1018 Each line starting with <+> represents a directory. Click on the <+> | |
1019 to insert the directory listing into the current tree. Click on the | |
1020 <-> to retract that list. Click on the directory name to go to that | |
1021 directory as the default. | |
1022 | |
1023 Each line starting with [+] is a file. If the variable | |
1024 `speedbar-show-unknown-files' is t, the lines starting with [?] are | |
1025 files which don't have imenu support, but are not expressly ignored. | |
1026 Files are completely ignored if they match `speedbar-file-unshown-regexp' | |
1027 which is generated from `completion-ignored-extensions'. | |
1028 | |
1029 Files with a `*' character after their name are files checked out of a | |
1030 version control system. (currently only RCS is supported.) New | |
1031 version control systems can be added by examining the documentation | |
1032 for `speedbar-this-file-in-vc' and `speedbar-vc-check-dir-p' | |
1033 | |
1034 Click on the [+] to display a list of tags from that file. Click on | |
1035 the [-] to retract the list. Click on the file name to edit the file | |
1036 in the attached frame. | |
1037 | |
1038 If you open tags, you might find a node starting with {+}, which is a | |
1039 category of tags. Click the {+} to expand the category. Jump-able | |
1040 tags start with >. Click the name of the tag to go to that position | |
1041 in the selected file. | |
1042 | |
1043 \\{speedbar-key-map}" | |
1044 ;; NOT interactive | |
1045 (save-excursion | |
1046 (setq speedbar-buffer (set-buffer (get-buffer-create " SPEEDBAR"))) | |
1047 (kill-all-local-variables) | |
1048 (setq major-mode 'speedbar-mode) | |
1049 (setq mode-name "Speedbar") | |
1050 (use-local-map speedbar-key-map) | |
1051 (set-syntax-table speedbar-syntax-table) | |
1052 (setq font-lock-keywords nil) ;; no font-locking please | |
1053 (setq truncate-lines t) | |
1054 (make-local-variable 'frame-title-format) | |
1055 (setq frame-title-format "Speedbar") | |
1056 ;; Set this up special just for the speedbar buffer | |
1057 (if (null default-minibuffer-frame) | |
1058 (progn | |
1059 (make-local-variable 'default-minibuffer-frame) | |
1060 (setq default-minibuffer-frame speedbar-attached-frame))) | |
1061 (make-local-variable 'temp-buffer-show-function) | |
1062 (setq temp-buffer-show-function 'speedbar-temp-buffer-show-function) | |
1063 (if speedbar-xemacsp | |
1064 (progn | |
1065 ;; Argh! mouse-track-click-hook doesn't understand the | |
1066 ;; make-local-hook conventions. | |
1067 (make-local-variable 'mouse-track-click-hook) | |
1068 (add-hook 'mouse-track-click-hook | |
1069 (lambda (event count) | |
1070 (if (/= (event-button event) 1) | |
1071 nil ; Do normal operations. | |
1072 (cond ((eq count 1) | |
1073 (speedbar-quick-mouse event)) | |
1074 ((or (eq count 2) | |
1075 (eq count 3)) | |
1076 (mouse-set-point event) | |
1077 (speedbar-do-function-pointer) | |
1078 (speedbar-quick-mouse event))) | |
1079 ;; Don't do normal operations. | |
1080 t))))) | |
1081 (make-local-hook 'kill-buffer-hook) | |
1082 (add-hook 'kill-buffer-hook (lambda () (let ((skilling (boundp 'skilling))) | |
1083 (if skilling | |
1084 nil | |
1085 (if (eq (current-buffer) | |
1086 speedbar-buffer) | |
1087 (speedbar-frame-mode -1))))) | |
1088 t t) | |
1089 (speedbar-set-mode-line-format) | |
1090 (if (not speedbar-xemacsp) | |
1091 (setq auto-show-mode nil)) ;no auto-show for Emacs | |
1092 (run-hooks 'speedbar-mode-hook)) | |
1093 (speedbar-update-contents) | |
1094 speedbar-buffer) | |
1095 | |
1096 (defun speedbar-set-mode-line-format () | |
1097 "Set the format of the mode line based on the current speedbar environment. | |
1098 This gives visual indications of what is up. It EXPECTS the speedbar | |
1099 frame and window to be the currently active frame and window." | |
1100 (if (and (frame-live-p speedbar-frame) | |
1101 (or (not speedbar-xemacsp) | |
1102 (specifier-instance has-modeline-p))) | |
1103 (save-excursion | |
1104 (set-buffer speedbar-buffer) | |
1105 (let* ((w (or (speedbar-frame-width) 20)) | |
1106 (p1 "<<") | |
1107 (p5 ">>") | |
1108 (p3 (if speedbar-update-flag "SPEEDBAR" "SLOWBAR")) | |
1109 (blank (- w (length p1) (length p3) (length p5) | |
1110 (if line-number-mode 4 0))) | |
1111 (p2 (if (> blank 0) | |
1112 (make-string (/ blank 2) ? ) | |
1113 "")) | |
1114 (p4 (if (> blank 0) | |
1115 (make-string (+ (/ blank 2) (% blank 2)) ? ) | |
1116 "")) | |
1117 (tf | |
1118 (if line-number-mode | |
1119 (list (concat p1 p2 p3) '(line-number-mode " %3l") | |
1120 (concat p4 p5)) | |
1121 (list (concat p1 p2 p3 p4 p5))))) | |
1122 (if (not (equal mode-line-format tf)) | |
1123 (progn | |
1124 (setq mode-line-format tf) | |
1125 (force-mode-line-update))))))) | |
1126 | |
1127 (defun speedbar-temp-buffer-show-function (buffer) | |
1128 "Placed in the variable `temp-buffer-show-function' in `speedbar-mode'. | |
1129 If a user requests help using \\[help-command] <Key> the temp BUFFER will be | |
1130 redirected into a window on the attached frame." | |
1131 (if speedbar-attached-frame (select-frame speedbar-attached-frame)) | |
1132 (pop-to-buffer buffer nil) | |
1133 (other-window -1) | |
1134 (run-hooks 'temp-buffer-show-hook)) | |
1135 | |
1136 (defun speedbar-reconfigure-menubar () | |
1137 "Reconfigure the menu-bar in a speedbar frame. | |
1138 Different menu items are displayed depending on the current display mode | |
1139 and the existence of packages." | |
1140 (let ((md (append speedbar-easymenu-definition-base | |
1141 (if speedbar-shown-directories | |
1142 ;; file display mode version | |
1143 speedbar-easymenu-definition-special | |
1144 (save-excursion | |
1145 (select-frame speedbar-attached-frame) | |
1146 (if (local-variable-p | |
1147 'speedbar-easymenu-definition-special | |
1148 (current-buffer)) | |
1149 ;; If bound locally, we can use it | |
1150 speedbar-easymenu-definition-special))) | |
1151 ;; The trailer | |
1152 speedbar-easymenu-definition-trailer))) | |
1153 (easy-menu-define speedbar-menu-map speedbar-key-map "Speedbar menu" md) | |
1154 (if speedbar-xemacsp | |
1155 (save-excursion | |
1156 (set-buffer speedbar-buffer) | |
1157 ;; For the benefit of button3 | |
1158 (if (and (not (assoc "Speedbar" mode-popup-menu))) | |
1159 (easy-menu-add md)) | |
1160 (set-buffer-menubar (list md))) | |
1161 (easy-menu-add md)))) | |
1162 | |
1163 | |
1164 ;;; User Input stuff | |
1165 ;; | |
1166 | |
1167 ;; XEmacs: this can be implemented using modeline keymaps, but there | |
1168 ;; is no use, as we have horizontal scrollbar (as the docstring | |
1169 ;; hints.) | |
1170 (defun speedbar-mouse-hscroll (e) | |
1171 "Read a mouse event E from the mode line, and horizontally scroll. | |
1172 If the mouse is being clicked on the far left, or far right of the | |
1173 mode-line. This is only useful for non-XEmacs" | |
1174 (interactive "e") | |
1175 (let* ((xp (car (nth 2 (car (cdr e))))) | |
1176 (cpw (/ (frame-pixel-width) | |
1177 (frame-width))) | |
1178 (oc (1+ (/ xp cpw))) | |
1179 ) | |
1180 (cond ((< oc 3) | |
1181 (scroll-left 2)) | |
1182 ((> oc (- (window-width) 3)) | |
1183 (scroll-right 2)) | |
1184 (t (message "Click on the edge of the modeline to scroll left/right"))) | |
1185 ;;(message "X: Pixel %d Char Pixels %d On char %d" xp cpw oc) | |
1186 )) | |
1187 | |
1188 (defun speedbar-customize () | |
1189 "Customize speedbar using the Custom package." | |
1190 (interactive) | |
1191 (let ((sf (selected-frame))) | |
1192 (select-frame speedbar-attached-frame) | |
1193 (customize-group 'speedbar) | |
1194 (select-frame sf)) | |
1195 (speedbar-maybee-jump-to-attached-frame)) | |
1196 | |
1197 ;; In XEmacs, we make popup menus work on the item over mouse (as | |
1198 ;; opposed to where the point happens to be.) We attain this by | |
1199 ;; temporarily moving the point to that place. | |
1200 ;; Hrvoje Niksic <hniksic@srce.hr> | |
1201 (defun speedbar-xemacs-popup-kludge (event) | |
1202 "Pop up a menu related to the clicked on item. | |
1203 Must be bound to EVENT." | |
1204 (interactive "e") | |
1205 (save-excursion | |
1206 (goto-char (event-closest-point event)) | |
1207 (beginning-of-line) | |
1208 (forward-char (min 5 (- (save-excursion (end-of-line) (point)) | |
1209 (save-excursion (beginning-of-line) (point))))) | |
1210 (popup-mode-menu) | |
1211 ;; Wait for menu to bail out. `popup-mode-menu' (and other popup | |
1212 ;; menu functions) return immediately. | |
1213 (let (new) | |
1214 (while (not (misc-user-event-p (setq new (next-event)))) | |
1215 (dispatch-event new)) | |
1216 (dispatch-event new)))) | |
1217 | |
1218 (defun speedbar-emacs-popup-kludge (e) | |
1219 "Pop up a menu related to the clicked on item. | |
1220 Must be bound to event E." | |
1221 (interactive "e") | |
1222 (save-excursion | |
1223 (mouse-set-point e) | |
1224 ;; This gets the cursor where the user can see it. | |
1225 (if (not (bolp)) (forward-char -1)) | |
1226 (sit-for 0) | |
1227 (if (< emacs-major-version 20) | |
1228 (mouse-major-mode-menu e) | |
1229 (mouse-major-mode-menu e nil)))) | |
1230 | |
1231 (defun speedbar-next (arg) | |
1232 "Move to the next ARGth line in a speedbar buffer." | |
1233 (interactive "p") | |
1234 (forward-line (or arg 1)) | |
1235 (speedbar-item-info) | |
1236 (speedbar-position-cursor-on-line)) | |
1237 | |
1238 (defun speedbar-prev (arg) | |
1239 "Move to the previous ARGth line in a speedbar buffer." | |
1240 (interactive "p") | |
1241 (speedbar-next (if arg (- arg) -1))) | |
1242 | |
1243 (defun speedbar-scroll-up (&optional arg) | |
1244 "Page down one screen-full of the speedbar, or ARG lines." | |
1245 (interactive "P") | |
1246 (scroll-up arg) | |
1247 (speedbar-position-cursor-on-line)) | |
1248 | |
1249 (defun speedbar-scroll-down (&optional arg) | |
1250 "Page up one screen-full of the speedbar, or ARG lines." | |
1251 (interactive "P") | |
1252 (scroll-down arg) | |
1253 (speedbar-position-cursor-on-line)) | |
1254 | |
1255 (defun speedbar-up-directory () | |
1256 "Keyboard accelerator for moving the default directory up one. | |
1257 Assumes that the current buffer is the speedbar buffer" | |
1258 (interactive) | |
1259 (setq default-directory (expand-file-name (concat default-directory "../"))) | |
1260 (speedbar-update-contents)) | |
1261 | |
1262 ;;; Speedbar file activity (aka creeping featurism) | |
1263 ;; | |
1264 (defun speedbar-refresh () | |
1265 "Refresh the current speedbar display, disposing of any cached data." | |
1266 (interactive) | |
1267 (let ((dl speedbar-shown-directories)) | |
1268 (while dl | |
1269 (adelete 'speedbar-directory-contents-alist (car dl)) | |
1270 (setq dl (cdr dl)))) | |
1271 (if (<= 1 speedbar-verbosity-level) (message "Refreshing speedbar...")) | |
1272 (speedbar-update-contents) | |
1273 (speedbar-stealthy-updates) | |
1274 ;; Reset the timer in case it got really hosed for some reason... | |
1275 (speedbar-set-timer speedbar-update-speed) | |
1276 (if (<= 1 speedbar-verbosity-level) (message "Refreshing speedbar...done"))) | |
1277 | |
1278 (defun speedbar-item-load () | |
1279 "Load the item under the cursor or mouse if it is a lisp file." | |
1280 (interactive) | |
1281 (let ((f (speedbar-line-file))) | |
1282 (if (and (file-exists-p f) (string-match "\\.el\\'" f)) | |
1283 (if (and (file-exists-p (concat f "c")) | |
1284 (y-or-n-p (format "Load %sc? " f))) | |
1285 ;; If the compiled version exists, load that instead... | |
1286 (load-file (concat f "c")) | |
1287 (load-file f)) | |
1288 (error "Not a loadable file...")))) | |
1289 | |
1290 (defun speedbar-item-byte-compile () | |
1291 "Byte compile the item under the cursor or mouse if it is a lisp file." | |
1292 (interactive) | |
1293 (let ((f (speedbar-line-file)) | |
1294 (sf (selected-frame))) | |
1295 (if (and (file-exists-p f) (string-match "\\.el\\'" f)) | |
1296 (progn | |
1297 (select-frame speedbar-attached-frame) | |
1298 (byte-compile-file f nil) | |
1299 (select-frame sf))) | |
1300 )) | |
1301 | |
1302 (defun speedbar-mouse-item-info (event) | |
1303 "Provide information about what the user clicked on. | |
1304 This should be bound to a mouse EVENT." | |
1305 (interactive "e") | |
1306 (mouse-set-point event) | |
1307 (speedbar-item-info)) | |
1308 | |
1309 (defun speedbar-item-info () | |
1310 "Display info in the mini-buffer about the button the mouse is over." | |
1311 (interactive) | |
1312 (if (not speedbar-shown-directories) | |
1313 nil | |
1314 (let* ((item (speedbar-line-file)) | |
1315 (attr (if item (file-attributes item) nil))) | |
1316 (if item (message "%s %d %s" (nth 8 attr) (nth 7 attr) item) | |
1317 (save-excursion | |
1318 (beginning-of-line) | |
1319 (looking-at "\\([0-9]+\\):") | |
1320 (setq item (speedbar-line-path (string-to-int (match-string 1)))) | |
1321 (if (re-search-forward "> \\([^ ]+\\)$" | |
1322 (save-excursion(end-of-line)(point)) t) | |
1323 (progn | |
1324 (setq attr (get-text-property (match-beginning 1) | |
1325 'speedbar-token)) | |
1326 (message "Tag %s in %s at position %s" | |
1327 (match-string 1) item (if attr attr 0))) | |
1328 (message "No special info for this line."))) | |
1329 )))) | |
1330 | |
1331 (defun speedbar-item-copy () | |
1332 "Copy the item under the cursor. | |
1333 Files can be copied to new names or places." | |
1334 (interactive) | |
1335 (let ((f (speedbar-line-file))) | |
1336 (if (not f) (error "Not a file.")) | |
1337 (if (file-directory-p f) | |
1338 (error "Cannot copy directory.") | |
1339 (let* ((rt (read-file-name (format "Copy %s to: " | |
1340 (file-name-nondirectory f)) | |
1341 (file-name-directory f))) | |
1342 (refresh (member (expand-file-name (file-name-directory rt)) | |
1343 speedbar-shown-directories))) | |
1344 ;; Create the right file name part | |
1345 (if (file-directory-p rt) | |
1346 (setq rt | |
1347 (concat (expand-file-name rt) | |
1348 (if (string-match "/$" rt) "" "/") | |
1349 (file-name-nondirectory f)))) | |
1350 (if (or (not (file-exists-p rt)) | |
1351 (y-or-n-p (format "Overwrite %s with %s? " rt f))) | |
1352 (progn | |
1353 (copy-file f rt t t) | |
1354 ;; refresh display if the new place is currently displayed. | |
1355 (if refresh | |
1356 (progn | |
1357 (speedbar-refresh) | |
1358 (if (not (speedbar-goto-this-file rt)) | |
1359 (speedbar-goto-this-file f)))) | |
1360 )))))) | |
1361 | |
1362 (defun speedbar-item-rename () | |
1363 "Rename the item under the cursor or mouse. | |
1364 Files can be renamed to new names or moved to new directories." | |
1365 (interactive) | |
1366 (let ((f (speedbar-line-file))) | |
1367 (if f | |
1368 (let* ((rt (read-file-name (format "Rename %s to: " | |
1369 (file-name-nondirectory f)) | |
1370 (file-name-directory f))) | |
1371 (refresh (member (expand-file-name (file-name-directory rt)) | |
1372 speedbar-shown-directories))) | |
1373 ;; Create the right file name part | |
1374 (if (file-directory-p rt) | |
1375 (setq rt | |
1376 (concat (expand-file-name rt) | |
1377 (if (string-match "/\\'" rt) "" "/") | |
1378 (file-name-nondirectory f)))) | |
1379 (if (or (not (file-exists-p rt)) | |
1380 (y-or-n-p (format "Overwrite %s with %s? " rt f))) | |
1381 (progn | |
1382 (rename-file f rt t) | |
1383 ;; refresh display if the new place is currently displayed. | |
1384 (if refresh | |
1385 (progn | |
1386 (speedbar-refresh) | |
1387 (speedbar-goto-this-file rt) | |
1388 ))))) | |
1389 (error "Not a file.")))) | |
1390 | |
1391 (defun speedbar-item-delete () | |
1392 "Delete the item under the cursor. Files are removed from disk." | |
1393 (interactive) | |
1394 (let ((f (speedbar-line-file))) | |
1395 (if (not f) (error "Not a file.")) | |
1396 (if (y-or-n-p (format "Delete %s? " f)) | |
1397 (progn | |
1398 (if (file-directory-p f) | |
1399 (delete-directory f) | |
1400 (delete-file f)) | |
1401 (message "Okie dokie..") | |
1402 (let ((p (point))) | |
1403 (speedbar-refresh) | |
1404 (goto-char p)) | |
1405 )) | |
1406 )) | |
1407 | |
1408 (defun speedbar-enable-update () | |
1409 "Enable automatic updating in speedbar via timers." | |
1410 (interactive) | |
1411 (setq speedbar-update-flag t) | |
1412 (speedbar-set-mode-line-format) | |
1413 (speedbar-set-timer speedbar-update-speed)) | |
1414 | |
1415 (defun speedbar-disable-update () | |
1416 "Disable automatic updating and stop consuming resources." | |
1417 (interactive) | |
1418 (setq speedbar-update-flag nil) | |
1419 (speedbar-set-mode-line-format) | |
1420 (speedbar-set-timer nil)) | |
1421 | |
1422 (defun speedbar-toggle-updates () | |
1423 "Toggle automatic update for the speedbar frame." | |
1424 (interactive) | |
1425 (if speedbar-update-flag | |
1426 (speedbar-disable-update) | |
1427 (speedbar-enable-update))) | |
1428 | |
1429 (defun speedbar-toggle-sorting () | |
1430 "Toggle automatic update for the speedbar frame." | |
1431 (interactive) | |
1432 (setq speedbar-sort-tags (not speedbar-sort-tags))) | |
1433 | |
1434 (defun speedbar-toggle-show-all-files () | |
1435 "Toggle display of files speedbar can not tag." | |
1436 (interactive) | |
1437 (setq speedbar-show-unknown-files (not speedbar-show-unknown-files)) | |
1438 (speedbar-refresh)) | |
1439 | |
1440 ;;; Utility functions | |
1441 ;; | |
1442 (defun speedbar-set-timer (timeout) | |
1443 "Apply a timer with TIMEOUT, or remove a timer if TIMOUT is nil. | |
1444 TIMEOUT is the number of seconds until the speedbar timer is called | |
1445 again. When TIMEOUT is nil, turn off all timeouts. | |
1446 This function will also enable or disable the `vc-checkin-hook' used | |
1447 to track file check ins, and will change the mode line to match | |
1448 `speedbar-update-flag'." | |
1449 (cond | |
1450 ;; XEmacs | |
1451 (speedbar-xemacsp | |
1452 (if speedbar-timer | |
1453 (progn (delete-itimer speedbar-timer) | |
1454 (setq speedbar-timer nil))) | |
1455 (if timeout | |
1456 (if (and speedbar-xemacsp | |
1457 (or (>= emacs-major-version 20) | |
1458 (>= emacs-minor-version 15))) | |
1459 (setq speedbar-timer (start-itimer "speedbar" | |
1460 'speedbar-timer-fn | |
1461 timeout | |
1462 timeout | |
1463 t)) | |
1464 (setq speedbar-timer (start-itimer "speedbar" | |
1465 'speedbar-timer-fn | |
1466 timeout | |
1467 nil))))) | |
1468 ;; Post 19.31 Emacs | |
1469 ((fboundp 'run-with-idle-timer) | |
1470 (if speedbar-timer | |
1471 (progn (cancel-timer speedbar-timer) | |
1472 (setq speedbar-timer nil))) | |
1473 (if timeout | |
1474 (setq speedbar-timer | |
1475 (run-with-idle-timer timeout t 'speedbar-timer-fn)))) | |
1476 ;; Emacs 19.30 (Thanks twice: ptype@dra.hmg.gb) | |
1477 ((fboundp 'post-command-idle-hook) | |
1478 (if timeout | |
1479 (add-hook 'post-command-idle-hook 'speedbar-timer-fn) | |
1480 (remove-hook 'post-command-idle-hook 'speedbar-timer-fn))) | |
1481 ;; Older or other Emacsen with no timers. Set up so that its | |
1482 ;; obvious this emacs can't handle the updates | |
1483 (t | |
1484 (setq speedbar-update-flag nil))) | |
1485 ;; Apply a revert hook that will reset the scanners. We attach to revert | |
1486 ;; because most reverts occur during VC state change, and this lets our | |
1487 ;; VC scanner fix itself. | |
1488 (if timeout | |
1489 (add-hook 'after-revert-hook 'speedbar-reset-scanners) | |
1490 (remove-hook 'after-revert-hook 'speedbar-reset-scanners) | |
1491 ) | |
1492 ;; change this if it changed for some reason | |
1493 (speedbar-set-mode-line-format)) | |
1494 | |
1495 (defmacro speedbar-with-writable (&rest forms) | |
1496 "Allow the buffer to be writable and evaluate FORMS." | |
1497 (list 'let '((inhibit-read-only t)) | |
1498 '(toggle-read-only -1) | |
1499 (cons 'progn forms))) | |
1500 (put 'speedbar-with-writable 'lisp-indent-function 0) | |
1501 | |
1502 (defun speedbar-select-window (buffer) | |
1503 "Select a window in which BUFFER is show. | |
1504 If it is not shown, force it to appear in the default window." | |
1505 (let ((win (get-buffer-window buffer speedbar-attached-frame))) | |
1506 (if win | |
1507 (select-window win) | |
1508 (show-buffer (selected-window) buffer)))) | |
1509 | |
1510 (defmacro speedbar-with-attached-buffer (&rest forms) | |
1511 "Execute FORMS in the attached frame's special buffer. | |
1512 Optionally select that frame if necessary." | |
1513 ;; Reset the timer with a new timeout when cliking a file | |
1514 ;; in case the user was navigating directories, we can cancel | |
1515 ;; that other timer. | |
1516 (list | |
1517 'progn | |
1518 '(speedbar-set-timer speedbar-update-speed) | |
1519 (list | |
1520 'let '((cf (selected-frame))) | |
1521 '(select-frame speedbar-attached-frame) | |
1522 '(speedbar-select-window speedbar-desired-buffer) | |
1523 (cons 'progn forms) | |
1524 '(select-frame cf) | |
1525 '(speedbar-maybee-jump-to-attached-frame) | |
1526 ))) | |
1527 | |
1528 (defun speedbar-insert-button (text face mouse function | |
1529 &optional token prevline) | |
1530 "Insert TEXT as the next logical speedbar button. | |
1531 FACE is the face to put on the button, MOUSE is the highlight face to use. | |
1532 When the user clicks on TEXT, FUNCTION is called with the TOKEN parameter. | |
1533 This function assumes that the current buffer is the speedbar buffer. | |
1534 If PREVLINE, then put this button on the previous line. | |
1535 | |
1536 This is a convenience function for special mode that create their own | |
1537 specialized speedbar displays." | |
1538 (goto-char (point-max)) | |
1539 (if (/= (current-column) 0) (insert "\n")) | |
1540 (if prevline (progn (delete-char -1) (insert " "))) ;back up if desired... | |
1541 (let ((start (point))) | |
1542 (insert text) | |
1543 (speedbar-make-button start (point) face mouse function token)) | |
1544 (let ((start (point))) | |
1545 (insert "\n") | |
1546 (put-text-property start (point) 'face nil) | |
1547 (put-text-property start (point) 'mouse-face nil))) | |
1548 | |
1549 (defun speedbar-make-button (start end face mouse function &optional token) | |
1550 "Create a button from START to END, with FACE as the display face. | |
1551 MOUSE is the mouse face. When this button is clicked on FUNCTION | |
1552 will be run with the TOKEN parameter (any lisp object)" | |
1553 (put-text-property start end 'face face) | |
1554 (put-text-property start end 'mouse-face mouse) | |
1555 (put-text-property start end 'invisible nil) | |
1556 (if function (put-text-property start end 'speedbar-function function)) | |
1557 (if token (put-text-property start end 'speedbar-token token)) | |
1558 ) | |
1559 | |
1560 ;;; File button management | |
1561 ;; | |
1562 (defun speedbar-file-lists (directory) | |
1563 "Create file lists for DIRECTORY. | |
1564 The car is the list of directories, the cdr is list of files not | |
1565 matching ignored headers. Cache any directory files found in | |
1566 `speedbar-directory-contents-alist' and use that cache before scanning | |
1567 the file-system" | |
1568 (setq directory (expand-file-name directory)) | |
1569 ;; If in powerclick mode, then the directory we are getting | |
1570 ;; should be rescanned. | |
1571 (if speedbar-power-click | |
1572 (adelete 'speedbar-directory-contents-alist directory)) | |
1573 ;; find the directory, either in the cache, or build it. | |
1574 (or (cdr-safe (assoc directory speedbar-directory-contents-alist)) | |
1575 (let ((default-directory directory) | |
1576 (dir (directory-files directory nil)) | |
1577 (dirs nil) | |
1578 (files nil)) | |
1579 (while dir | |
1580 (if (not (string-match speedbar-file-unshown-regexp (car dir))) | |
1581 (if (file-directory-p (car dir)) | |
1582 (setq dirs (cons (car dir) dirs)) | |
1583 (setq files (cons (car dir) files)))) | |
1584 (setq dir (cdr dir))) | |
1585 (let ((nl (cons (nreverse dirs) (list (nreverse files))))) | |
1586 (aput 'speedbar-directory-contents-alist directory nl) | |
1587 nl)) | |
1588 )) | |
1589 | |
1590 (defun speedbar-directory-buttons (directory index) | |
1591 "Insert a single button group at point for DIRECTORY. | |
1592 Each directory path part is a different button. If part of the path | |
1593 matches the user directory ~, then it is replaced with a ~. | |
1594 INDEX is not used, but is required by the caller." | |
1595 (let* ((tilde (expand-file-name "~")) | |
1596 (dd (expand-file-name directory)) | |
1597 (junk (string-match (regexp-quote tilde) dd)) | |
1598 (displayme (if junk | |
1599 (concat "~" (substring dd (match-end 0))) | |
1600 dd)) | |
1601 (p (point))) | |
1602 (if (string-match "^~/?\\'" displayme) (setq displayme (concat tilde "/"))) | |
1603 (insert displayme) | |
1604 (save-excursion | |
1605 (goto-char p) | |
1606 (while (re-search-forward "\\([^/]+\\)/" nil t) | |
1607 (speedbar-make-button (match-beginning 1) (match-end 1) | |
1608 'speedbar-directory-face | |
1609 'speedbar-highlight-face | |
1610 'speedbar-directory-buttons-follow | |
1611 (if (= (match-beginning 1) p) | |
1612 (expand-file-name "~/") ;the tilde | |
1613 (buffer-substring-no-properties | |
1614 p (match-end 0))))) | |
1615 ;; Nuke the beginning of the directory if it's too long... | |
1616 (cond ((eq speedbar-directory-button-trim-method 'span) | |
1617 (beginning-of-line) | |
1618 (let ((ww (or (speedbar-frame-width) 20))) | |
1619 (move-to-column ww nil) | |
1620 (while (>= (current-column) ww) | |
1621 (re-search-backward "/" nil t) | |
1622 (if (<= (current-column) 2) | |
1623 (progn | |
1624 (re-search-forward "/" nil t) | |
1625 (if (< (current-column) 4) | |
1626 (re-search-forward "/" nil t)) | |
1627 (forward-char -1))) | |
1628 (if (looking-at "/?$") | |
1629 (beginning-of-line) | |
1630 (insert "/...\n ") | |
1631 (move-to-column ww nil))))) | |
1632 ((eq speedbar-directory-button-trim-method 'trim) | |
1633 (end-of-line) | |
1634 (let ((ww (or (speedbar-frame-width) 20)) | |
1635 (tl (current-column))) | |
1636 (if (< ww tl) | |
1637 (progn | |
1638 (move-to-column (- tl ww)) | |
1639 (if (re-search-backward "/" nil t) | |
1640 (progn | |
1641 (delete-region (point-min) (point)) | |
1642 (insert "$") | |
1643 ))))))) | |
1644 ) | |
1645 (if (string-match "\\`/[^/]+/\\'" displayme) | |
1646 (progn | |
1647 (insert " ") | |
1648 (let ((p (point))) | |
1649 (insert "<root>") | |
1650 (speedbar-make-button p (point) | |
1651 'speedbar-directory-face | |
1652 'speedbar-highlight-face | |
1653 'speedbar-directory-buttons-follow | |
1654 "/")))) | |
1655 (end-of-line) | |
1656 (insert-char ?\n 1 nil))) | |
1657 | |
1658 (defun speedbar-make-tag-line (exp-button-type | |
1659 exp-button-char exp-button-function | |
1660 exp-button-data | |
1661 tag-button tag-button-function tag-button-data | |
1662 tag-button-face depth) | |
1663 "Create a tag line with EXP-BUTTON-TYPE for the small expansion button. | |
1664 This is the button that expands or contracts a node (if applicable), | |
1665 and EXP-BUTTON-CHAR the character in it (+, -, ?, etc). EXP-BUTTON-FUNCTION | |
1666 is the function to call if it's clicked on. Button types are | |
1667 'bracket, 'angle, 'curly, or nil. EXP-BUTTON-DATA is extra data | |
1668 attached to the text forming the expansion button. | |
1669 | |
1670 Next, TAG-BUTTON is the text of the tag. TAG-BUTTON-FUNCTION is the | |
1671 function to call if clicked on, and TAG-BUTTON-DATA is the data to | |
1672 attach to the text field (such a tag positioning, etc). | |
1673 TAG-BUTTON-FACE is a face used for this type of tag. | |
1674 | |
1675 Lastly, DEPTH shows the depth of expansion. | |
1676 | |
1677 This function assumes that the cursor is in the speedbar window at the | |
1678 position to insert a new item, and that the new item will end with a CR" | |
1679 (let ((start (point)) | |
1680 (end (progn | |
1681 (insert (int-to-string depth) ":") | |
1682 (point)))) | |
1683 (put-text-property start end 'invisible t) | |
1684 ) | |
1685 (insert-char ? depth nil) | |
1686 (put-text-property (- (point) depth) (point) 'invisible nil) | |
1687 (let* ((exp-button (cond ((eq exp-button-type 'bracket) "[%c]") | |
1688 ((eq exp-button-type 'angle) "<%c>") | |
1689 ((eq exp-button-type 'curly) "{%c}") | |
1690 (t ">"))) | |
1691 (buttxt (format exp-button exp-button-char)) | |
1692 (start (point)) | |
1693 (end (progn (insert buttxt) (point))) | |
1694 (bf (if exp-button-type 'speedbar-button-face nil)) | |
1695 (mf (if exp-button-function 'speedbar-highlight-face nil)) | |
1696 ) | |
1697 (speedbar-make-button start end bf mf exp-button-function exp-button-data) | |
1698 ) | |
1699 (insert-char ? 1 nil) | |
1700 (put-text-property (1- (point)) (point) 'invisible nil) | |
1701 (let ((start (point)) | |
1702 (end (progn (insert tag-button) (point)))) | |
1703 (insert-char ?\n 1 nil) | |
1704 (put-text-property (1- (point)) (point) 'invisible nil) | |
1705 (speedbar-make-button start end tag-button-face | |
1706 (if tag-button-function 'speedbar-highlight-face nil) | |
1707 tag-button-function tag-button-data)) | |
1708 ) | |
1709 | |
1710 (defun speedbar-change-expand-button-char (char) | |
1711 "Change the expansion button character to CHAR for the current line." | |
1712 (save-excursion | |
1713 (beginning-of-line) | |
1714 (if (re-search-forward ":\\s-*.\\([-+?]\\)" (save-excursion (end-of-line) | |
1715 (point)) t) | |
1716 (speedbar-with-writable | |
1717 (goto-char (match-beginning 1)) | |
1718 (delete-char 1) | |
1719 (insert-char char 1 t))))) | |
1720 | |
1721 | |
1722 ;;; Build button lists | |
1723 ;; | |
1724 (defun speedbar-insert-files-at-point (files level) | |
1725 "Insert list of FILES starting at point, and indenting all files to LEVEL. | |
1726 Tag expandable items with a +, otherwise a ?. Don't highlight ? as we | |
1727 don't know how to manage them. The input parameter FILES is a cons | |
1728 cell of the form ( 'DIRLIST . 'FILELIST )" | |
1729 ;; Start inserting all the directories | |
1730 (let ((dirs (car files))) | |
1731 (while dirs | |
1732 (speedbar-make-tag-line 'angle ?+ 'speedbar-dired (car dirs) | |
1733 (car dirs) 'speedbar-dir-follow nil | |
1734 'speedbar-directory-face level) | |
1735 (setq dirs (cdr dirs)))) | |
1736 (let ((lst (car (cdr files)))) | |
1737 (while lst | |
1738 (let* ((known (string-match speedbar-file-regexp (car lst))) | |
1739 (expchar (if known ?+ ??)) | |
1740 (fn (if known 'speedbar-tag-file nil))) | |
1741 (if (or speedbar-show-unknown-files (/= expchar ??)) | |
1742 (speedbar-make-tag-line 'bracket expchar fn (car lst) | |
1743 (car lst) 'speedbar-find-file nil | |
1744 'speedbar-file-face level))) | |
1745 (setq lst (cdr lst))))) | |
1746 | |
1747 (defun speedbar-default-directory-list (directory index) | |
1748 "Insert files for DIRECTORY with level INDEX at point." | |
1749 (speedbar-insert-files-at-point | |
1750 (speedbar-file-lists directory) index) | |
1751 (speedbar-reset-scanners) | |
1752 (if (= index 0) | |
1753 ;; If the shown files variable has extra directories, then | |
1754 ;; it is our responsibility to redraw them all | |
1755 ;; Luckilly, the nature of inserting items into this list means | |
1756 ;; that by reversing it, we can easilly go in the right order | |
1757 (let ((sf (cdr (reverse speedbar-shown-directories)))) | |
1758 (setq speedbar-shown-directories | |
1759 (list (expand-file-name default-directory))) | |
1760 ;; exand them all as we find them | |
1761 (while sf | |
1762 (if (speedbar-goto-this-file (car sf)) | |
1763 (progn | |
1764 (beginning-of-line) | |
1765 (if (looking-at "[0-9]+:[ ]*<") | |
1766 (progn | |
1767 (goto-char (match-end 0)) | |
1768 (speedbar-do-function-pointer))) | |
1769 (setq sf (cdr sf))))) | |
1770 ))) | |
1771 | |
1772 (defun speedbar-insert-generic-list (level lst expand-fun find-fun) | |
1773 "At LEVEL, insert a generic multi-level alist LST. | |
1774 Associations with lists get {+} tags (to expand into more nodes) and | |
1775 those with positions just get a > as the indicator. {+} buttons will | |
1776 have the function EXPAND-FUN and the token is the CDR list. The token | |
1777 name will have the function FIND-FUN and not token." | |
1778 ;; Remove imenu rescan button | |
1779 (if (string= (car (car lst)) "*Rescan*") | |
1780 (setq lst (cdr lst))) | |
1781 ;; insert the parts | |
1782 (while lst | |
1783 (cond ((null (car-safe lst)) nil) ;this would be a separator | |
1784 ((or (numberp (cdr-safe (car-safe lst))) | |
1785 (markerp (cdr-safe (car-safe lst)))) | |
1786 (speedbar-make-tag-line nil nil nil nil ;no expand button data | |
1787 (car (car lst)) ;button name | |
1788 find-fun ;function | |
1789 (cdr (car lst)) ;token is position | |
1790 'speedbar-tag-face | |
1791 (1+ level))) | |
1792 ((listp (cdr-safe (car-safe lst))) | |
1793 (speedbar-make-tag-line 'curly ?+ expand-fun (cdr (car lst)) | |
1794 (car (car lst)) ;button name | |
1795 nil nil 'speedbar-tag-face | |
1796 (1+ level))) | |
1797 (t (message "Ooops!"))) | |
1798 (setq lst (cdr lst)))) | |
1799 | |
1800 ;;; Timed functions | |
1801 ;; | |
1802 (defun speedbar-update-contents () | |
1803 "Generically update the contents of the speedbar buffer." | |
1804 (interactive) | |
1805 ;; Set the current special buffer | |
1806 (setq speedbar-desired-buffer nil) | |
1807 (if (and speedbar-mode-specific-contents-flag | |
1808 speedbar-special-mode-expansion-list | |
1809 (local-variable-p | |
1810 'speedbar-special-mode-expansion-list | |
1811 (current-buffer))) | |
1812 ;;(eq (get major-mode 'mode-class 'special))) | |
1813 (speedbar-update-special-contents) | |
1814 (speedbar-update-directory-contents))) | |
1815 | |
1816 (defun speedbar-update-directory-contents () | |
1817 "Update the contents of the speedbar buffer based on the current directory." | |
1818 (let ((cbd (expand-file-name default-directory)) | |
1819 cbd-parent | |
1820 (funclst speedbar-initial-expansion-list) | |
1821 (cache speedbar-full-text-cache) | |
1822 ;; disable stealth during update | |
1823 (speedbar-stealthy-function-list nil) | |
1824 (use-cache nil) | |
1825 (expand-local nil) | |
1826 ;; Because there is a bug I can't find just yet | |
1827 (inhibit-quit nil)) | |
1828 (save-excursion | |
1829 (set-buffer speedbar-buffer) | |
1830 ;; If we are updating contents to where we are, then this is | |
1831 ;; really a request to update existing contents, so we must be | |
1832 ;; careful with our text cache! | |
1833 (if (member cbd speedbar-shown-directories) | |
1834 (setq cache nil) | |
1835 | |
1836 ;; Build cbd-parent, and see if THAT is in the current shown | |
1837 ;; directories. First, go through pains to get the parent directory | |
1838 (if (and speedbar-smart-directory-expand-flag | |
1839 (save-match-data | |
1840 (setq cbd-parent cbd) | |
1841 (if (string-match "/$" cbd-parent) | |
1842 (setq cbd-parent (substring cbd-parent 0 (match-beginning 0)))) | |
1843 (setq cbd-parent (file-name-directory cbd-parent))) | |
1844 (member cbd-parent speedbar-shown-directories)) | |
1845 (setq expand-local t) | |
1846 | |
1847 ;; If this directory is NOT in the current list of available | |
1848 ;; paths, then use the cache, and set the cache to our new | |
1849 ;; value. Make sure to unhighlight the current file, or if we | |
1850 ;; come back to this directory, it might be a different file | |
1851 ;; and then we get a mess! | |
1852 (if (> (point-max) 1) | |
1853 (progn | |
1854 (speedbar-clear-current-file) | |
1855 (setq speedbar-full-text-cache | |
1856 (cons speedbar-shown-directories (buffer-string))))) | |
1857 | |
1858 ;; Check if our new directory is in the list of directories | |
1859 ;; shown in the text-cache | |
1860 (if (member cbd (car cache)) | |
1861 (setq speedbar-shown-directories (car cache) | |
1862 use-cache t) | |
1863 ;; default the shown directories to this list... | |
1864 (setq speedbar-shown-directories (list cbd))) | |
1865 )) | |
1866 (setq speedbar-last-selected-file nil) | |
1867 (speedbar-with-writable | |
1868 (if (and expand-local | |
1869 ;; Find this directory as a speedbar node. | |
1870 (speedbar-path-line cbd)) | |
1871 ;; Open it. | |
1872 (speedbar-expand-line) | |
1873 (erase-buffer) | |
1874 (cond (use-cache | |
1875 (setq default-directory | |
1876 (nth (1- (length speedbar-shown-directories)) | |
1877 speedbar-shown-directories)) | |
1878 (insert (cdr cache))) | |
1879 (t | |
1880 (while funclst | |
1881 (setq default-directory cbd) | |
1882 (funcall (car funclst) cbd 0) | |
1883 (setq funclst (cdr funclst)))))) | |
1884 (goto-char (point-min))))) | |
1885 (speedbar-reconfigure-menubar)) | |
1886 | |
1887 (defun speedbar-update-special-contents () | |
1888 "Used the mode-specific variable to fill in the speedbar buffer. | |
1889 This should only be used by modes classified as special." | |
1890 (let ((funclst speedbar-special-mode-expansion-list) | |
1891 (specialbuff (current-buffer))) | |
1892 (save-excursion | |
1893 (setq speedbar-desired-buffer specialbuff) | |
1894 (set-buffer speedbar-buffer) | |
1895 ;; If we are leaving a directory, cache it. | |
1896 (if (not speedbar-shown-directories) | |
1897 ;; Do nothing | |
1898 nil | |
1899 ;; Clean up directory maintenance stuff | |
1900 (speedbar-clear-current-file) | |
1901 (setq speedbar-full-text-cache | |
1902 (cons speedbar-shown-directories (buffer-string)) | |
1903 speedbar-shown-directories nil)) | |
1904 ;; Now fill in the buffer with our newly found specialized list. | |
1905 (speedbar-with-writable | |
1906 (while funclst | |
1907 ;; We do not erase the buffer because these functions may | |
1908 ;; decide NOT to update themselves. | |
1909 (funcall (car funclst) specialbuff) | |
1910 (setq funclst (cdr funclst)))) | |
1911 (goto-char (point-min)))) | |
1912 (speedbar-reconfigure-menubar)) | |
1913 | |
1914 (defun speedbar-timer-fn () | |
1915 "Run whenever emacs is idle to update the speedbar item." | |
1916 (if (not (and (frame-live-p speedbar-frame) | |
1917 (frame-live-p speedbar-attached-frame))) | |
1918 (speedbar-set-timer nil) | |
1919 ;; Save all the match data so that we don't mess up executing fns | |
1920 (save-match-data | |
1921 (if (and (frame-visible-p speedbar-frame) speedbar-update-flag) | |
1922 (let ((af (selected-frame))) | |
1923 (save-window-excursion | |
1924 (select-frame speedbar-attached-frame) | |
1925 ;; make sure we at least choose a window to | |
1926 ;; get a good directory from | |
1927 (if (string-match "\\*Minibuf-[0-9]+\\*" (buffer-name)) | |
1928 (other-window 1)) | |
1929 ;; Update for special mode all the time! | |
1930 (if (and speedbar-mode-specific-contents-flag | |
1931 speedbar-special-mode-expansion-list | |
1932 (local-variable-p | |
1933 'speedbar-special-mode-expansion-list | |
1934 (current-buffer))) | |
1935 ;;(eq (get major-mode 'mode-class 'special))) | |
1936 (progn | |
1937 (if (<= 2 speedbar-verbosity-level) | |
1938 (message "Updating speedbar to special mode: %s..." | |
1939 major-mode)) | |
1940 (speedbar-update-special-contents) | |
1941 (if (<= 2 speedbar-verbosity-level) | |
1942 (message "Updating speedbar to special mode: %s...done" | |
1943 major-mode))) | |
1944 ;; Update all the contents if directories change! | |
1945 (if (or (member (expand-file-name default-directory) | |
1946 speedbar-shown-directories) | |
1947 (and speedbar-ignored-path-regexp | |
1948 (string-match | |
1949 speedbar-ignored-path-regexp | |
1950 (expand-file-name default-directory))) | |
1951 (member major-mode speedbar-ignored-modes) | |
1952 (eq af speedbar-frame) | |
1953 (not (buffer-file-name))) | |
1954 nil | |
1955 (if (<= 1 speedbar-verbosity-level) | |
1956 (message "Updating speedbar to: %s..." | |
1957 default-directory)) | |
1958 (speedbar-update-directory-contents) | |
1959 (if (<= 1 speedbar-verbosity-level) | |
1960 (message "Updating speedbar to: %s...done" | |
1961 default-directory)))) | |
1962 (select-frame af)) | |
1963 ;; Now run stealthy updates of time-consuming items | |
1964 (speedbar-stealthy-updates))))) | |
1965 (run-hooks 'speedbar-timer-hook)) | |
1966 | |
1967 | |
1968 ;;; Stealthy activities | |
1969 ;; | |
1970 (defun speedbar-stealthy-updates () | |
1971 "For a given speedbar, run all items in the stealthy function list. | |
1972 Each item returns t if it completes successfully, or nil if | |
1973 interrupted by the user." | |
1974 (let ((l speedbar-stealthy-function-list)) | |
1975 (unwind-protect | |
1976 (while (and l (funcall (car l))) | |
1977 (sit-for 0) | |
1978 (setq l (cdr l))) | |
1979 ;(message "Exit with %S" (car l)) | |
1980 ))) | |
1981 | |
1982 (defun speedbar-reset-scanners () | |
1983 "Reset any variables used by functions in the stealthy list as state. | |
1984 If new functions are added, their state needs to be updated here." | |
1985 (setq speedbar-vc-to-do-point t) | |
1986 (run-hooks 'speedbar-scanner-reset-hook) | |
1987 ) | |
1988 | |
1989 (defun speedbar-clear-current-file () | |
1990 "Locate the file thought to be current, and remove its highlighting." | |
1991 (save-excursion | |
1992 (set-buffer speedbar-buffer) | |
1993 (if speedbar-last-selected-file | |
1994 (speedbar-with-writable | |
1995 (goto-char (point-min)) | |
1996 (if (and | |
1997 speedbar-last-selected-file | |
1998 (re-search-forward | |
1999 (concat " \\(" (regexp-quote speedbar-last-selected-file) | |
2000 "\\)\\(" (regexp-quote speedbar-vc-indicator) | |
2001 "\\)?\n") | |
2002 nil t)) | |
2003 (put-text-property (match-beginning 1) | |
2004 (match-end 1) | |
2005 'face | |
2006 'speedbar-file-face)))))) | |
2007 | |
2008 (defun speedbar-update-current-file () | |
2009 "Find the current file, and update our visuals to indicate its name. | |
2010 This is specific to file names. If the file name doesn't show up, but | |
2011 it should be in the list, then the directory cache needs to be | |
2012 updated." | |
2013 (let* ((lastf (selected-frame)) | |
2014 (newcfd (save-excursion | |
2015 (select-frame speedbar-attached-frame) | |
2016 (let ((rf (if (buffer-file-name) | |
2017 (buffer-file-name) | |
2018 nil))) | |
2019 (select-frame lastf) | |
2020 rf))) | |
2021 (newcf (if newcfd (file-name-nondirectory newcfd))) | |
2022 (lastb (current-buffer)) | |
2023 (sucf-recursive (boundp 'sucf-recursive))) | |
2024 (if (and newcf | |
2025 ;; check here, that way we won't refresh to newcf until | |
2026 ;; its been written, thus saving ourselves some time | |
2027 (file-exists-p newcf) | |
2028 (not (string= newcf speedbar-last-selected-file))) | |
2029 (progn | |
2030 ;; It is important to select the frame, otherwise the window | |
2031 ;; we want the cursor to move in will not be updated by the | |
2032 ;; search-forward command. | |
2033 (select-frame speedbar-frame) | |
2034 ;; Remove the old file... | |
2035 (speedbar-clear-current-file) | |
2036 ;; now highlight the new one. | |
2037 (set-buffer speedbar-buffer) | |
2038 (speedbar-with-writable | |
2039 (goto-char (point-min)) | |
2040 (if (re-search-forward | |
2041 (concat " \\(" (regexp-quote newcf) "\\)\\(" | |
2042 (regexp-quote speedbar-vc-indicator) | |
2043 "\\)?\n") nil t) | |
2044 ;; put the property on it | |
2045 (put-text-property (match-beginning 1) | |
2046 (match-end 1) | |
2047 'face | |
2048 'speedbar-selected-face) | |
2049 ;; Oops, it's not in the list. Should it be? | |
2050 (if (and (string-match speedbar-file-regexp newcf) | |
2051 (string= (file-name-directory newcfd) | |
2052 (expand-file-name default-directory))) | |
2053 ;; yes, it is (we will ignore unknowns for now...) | |
2054 (progn | |
2055 (speedbar-refresh) | |
2056 (if (re-search-forward | |
2057 (concat " \\(" (regexp-quote newcf) "\\)\n") nil t) | |
2058 ;; put the property on it | |
2059 (put-text-property (match-beginning 1) | |
2060 (match-end 1) | |
2061 'face | |
2062 'speedbar-selected-face))) | |
2063 ;; if it's not in there now, whatever... | |
2064 )) | |
2065 (setq speedbar-last-selected-file newcf)) | |
2066 (if (not sucf-recursive) | |
2067 (progn | |
2068 (forward-line -1) | |
2069 (speedbar-position-cursor-on-line))) | |
2070 (set-buffer lastb) | |
2071 (select-frame lastf) | |
2072 ))) | |
2073 ;; return that we are done with this activity. | |
2074 t) | |
2075 | |
2076 ;; Load ange-ftp only if compiling to remove errors. | |
2077 ;; Steven L Baur <steve@xemacs.org> said this was important: | |
2078 (eval-when-compile (or (featurep 'xemacs) (require 'ange-ftp))) | |
2079 | |
2080 (defun speedbar-check-vc () | |
2081 "Scan all files in a directory, and for each see if it's checked out. | |
2082 See `speedbar-this-file-in-vc' and `speedbar-vc-check-dir-p' for how | |
2083 to add more types of version control systems." | |
2084 ;; Check for to-do to be reset. If reset but no RCS is available | |
2085 ;; then set to nil (do nothing) otherwise, start at the beginning | |
2086 (save-excursion | |
2087 (set-buffer speedbar-buffer) | |
2088 (if (and speedbar-vc-do-check (eq speedbar-vc-to-do-point t) | |
2089 (speedbar-vc-check-dir-p default-directory) | |
2090 (not (and (featurep 'ange-ftp) | |
2091 (string-match (car | |
2092 (if speedbar-xemacsp | |
2093 ange-ftp-path-format | |
2094 ange-ftp-name-format)) | |
2095 (expand-file-name default-directory))))) | |
2096 (setq speedbar-vc-to-do-point 0)) | |
2097 (if (numberp speedbar-vc-to-do-point) | |
2098 (progn | |
2099 (goto-char speedbar-vc-to-do-point) | |
2100 (while (and (not (input-pending-p)) | |
2101 (re-search-forward "^\\([0-9]+\\):\\s-*\\[[+-]\\] " | |
2102 nil t)) | |
2103 (setq speedbar-vc-to-do-point (point)) | |
2104 (if (speedbar-check-vc-this-line (match-string 1)) | |
2105 (if (not (looking-at (regexp-quote speedbar-vc-indicator))) | |
2106 (speedbar-with-writable (insert speedbar-vc-indicator))) | |
2107 (if (looking-at (regexp-quote speedbar-vc-indicator)) | |
2108 (speedbar-with-writable | |
2109 (delete-region (match-beginning 0) (match-end 0)))))) | |
2110 (if (input-pending-p) | |
2111 ;; return that we are incomplete | |
2112 nil | |
2113 ;; we are done, set to-do to nil | |
2114 (setq speedbar-vc-to-do-point nil) | |
2115 ;; and return t | |
2116 t)) | |
2117 t))) | |
2118 | |
2119 (defun speedbar-check-vc-this-line (depth) | |
2120 "Return t if the file on this line is check of of a version control system. | |
2121 Parameter DEPTH is a string with the current depth of indentation of | |
2122 the file being checked." | |
2123 (let* ((d (string-to-int depth)) | |
2124 (f (speedbar-line-path d)) | |
2125 (fn (buffer-substring-no-properties | |
2126 ;; Skip-chars: thanks ptype@dra.hmg.gb | |
2127 (point) (progn | |
2128 (skip-chars-forward "^ " | |
2129 (save-excursion (end-of-line) | |
2130 (point))) | |
2131 (point)))) | |
2132 (fulln (concat f fn))) | |
2133 (if (<= 2 speedbar-verbosity-level) | |
2134 (message "Speedbar vc check...%s" fulln)) | |
2135 (and (file-writable-p fulln) | |
2136 (speedbar-this-file-in-vc f fn)))) | |
2137 | |
2138 (defun speedbar-vc-check-dir-p (path) | |
2139 "Return t if we should bother checking PATH for version control files. | |
2140 This can be overloaded to add new types of version control systems." | |
2141 (or | |
2142 ;; Local RCS | |
2143 (file-exists-p (concat path "RCS/")) | |
2144 ;; Local SCCS | |
2145 (file-exists-p (concat path "SCCS/")) | |
2146 ;; Remote SCCS project | |
2147 (let ((proj-dir (getenv "PROJECTDIR"))) | |
2148 (if proj-dir | |
2149 (file-exists-p (concat proj-dir "/SCCS")) | |
2150 nil)) | |
2151 ;; User extension | |
2152 (run-hook-with-args 'speedbar-vc-path-enable-hook path) | |
2153 )) | |
2154 | |
2155 (defun speedbar-this-file-in-vc (path name) | |
2156 "Check to see if the file in PATH with NAME is in a version control system. | |
2157 You can add new VC systems by overriding this function. You can | |
2158 optimize this function by overriding it and only doing those checks | |
2159 that will occur on your system." | |
2160 (or | |
2161 ;; RCS file name | |
2162 (file-exists-p (concat path "RCS/" name ",v")) | |
2163 ;; Local SCCS file name | |
2164 (file-exists-p (concat path "SCCS/p." name)) | |
2165 ;; Remote SCCS file name | |
2166 (let ((proj-dir (getenv "PROJECTDIR"))) | |
2167 (if proj-dir | |
2168 (file-exists-p (concat proj-dir "/SCCS/p." name)) | |
2169 nil)) | |
2170 ;; User extension | |
2171 (run-hook-with-args 'speedbar-vc-in-control-hook path name) | |
2172 )) | |
2173 | |
2174 ;;; Clicking Activity | |
2175 ;; | |
2176 (defun speedbar-quick-mouse (e) | |
2177 "Since mouse events are strange, this will keep the mouse nicely positioned. | |
2178 This should be bound to mouse event E." | |
2179 (interactive "e") | |
2180 (mouse-set-point e) | |
2181 (speedbar-position-cursor-on-line) | |
2182 ) | |
2183 | |
2184 (defun speedbar-position-cursor-on-line () | |
2185 "Position the cursor on a line." | |
2186 (let ((oldpos (point))) | |
2187 (beginning-of-line) | |
2188 (if (looking-at "[0-9]+:\\s-*..?.? ") | |
2189 (goto-char (1- (match-end 0))) | |
2190 (goto-char oldpos)))) | |
2191 | |
2192 (defun speedbar-power-click (e) | |
2193 "Activate any speedbar button as a power click. | |
2194 This should be bound to mouse event E." | |
2195 (interactive "e") | |
2196 (let ((speedbar-power-click t)) | |
2197 (speedbar-click e))) | |
2198 | |
2199 (defun speedbar-click (e) | |
2200 "Activate any speedbar buttons where the mouse is clicked. | |
2201 This must be bound to a mouse event. A button is any location of text | |
2202 with a mouse face that has a text property called `speedbar-function'. | |
2203 This should be bound to mouse event E." | |
2204 (interactive "e") | |
2205 (mouse-set-point e) | |
2206 (speedbar-do-function-pointer) | |
2207 (speedbar-quick-mouse e)) | |
2208 | |
2209 (defun speedbar-double-click (e) | |
2210 "Activate any speedbar buttons where the mouse is clicked. | |
2211 This must be bound to a mouse event. A button is any location of text | |
2212 with a mouse face that has a text property called `speedbar-function'. | |
2213 This should be bound to mouse event E." | |
2214 (interactive "e") | |
2215 ;; Emacs only. XEmacs handles this via `mouse-track-click-hook'. | |
2216 (cond ((eq (car e) 'down-mouse-1) | |
2217 (mouse-set-point e)) | |
2218 ((eq (car e) 'mouse-1) | |
2219 (speedbar-quick-mouse e)) | |
2220 ((or (eq (car e) 'double-down-mouse-1) | |
2221 (eq (car e) 'tripple-down-mouse-1)) | |
2222 (mouse-set-point e) | |
2223 (speedbar-do-function-pointer) | |
2224 (speedbar-quick-mouse e)))) | |
2225 | |
2226 (defun speedbar-do-function-pointer () | |
2227 "Look under the cursor and examine the text properties. | |
2228 From this extract the file/tag name, token, indentation level and call | |
2229 a function if appropriate" | |
2230 (let* ((fn (get-text-property (point) 'speedbar-function)) | |
2231 (tok (get-text-property (point) 'speedbar-token)) | |
2232 ;; The 1-,+ is safe because scaning starts AFTER the point | |
2233 ;; specified. This lets the search include the character the | |
2234 ;; cursor is on. | |
2235 (tp (previous-single-property-change | |
2236 (1+ (point)) 'speedbar-function)) | |
2237 (np (next-single-property-change | |
2238 (point) 'speedbar-function)) | |
2239 (txt (buffer-substring-no-properties (or tp (point-min)) | |
2240 (or np (point-max)))) | |
2241 (dent (save-excursion (beginning-of-line) | |
2242 (string-to-number | |
2243 (if (looking-at "[0-9]+") | |
2244 (buffer-substring-no-properties | |
2245 (match-beginning 0) (match-end 0)) | |
2246 "0"))))) | |
2247 ;;(message "%S:%S:%S:%s" fn tok txt dent) | |
2248 (and fn (funcall fn txt tok dent))) | |
2249 (speedbar-position-cursor-on-line)) | |
2250 | |
2251 ;;; Reading info from the speedbar buffer | |
2252 ;; | |
2253 (defun speedbar-line-file (&optional p) | |
2254 "Retrieve the file or whatever from the line at P point. | |
2255 The return value is a string representing the file. If it is a | |
2256 directory, then it is the directory name." | |
2257 (save-excursion | |
2258 (save-match-data | |
2259 (beginning-of-line) | |
2260 (if (looking-at (concat | |
2261 "\\([0-9]+\\): *[[<][-+?][]>] \\([^ \n]+\\)\\(" | |
2262 (regexp-quote speedbar-vc-indicator) | |
2263 "\\)?")) | |
2264 (let* ((depth (string-to-int (match-string 1))) | |
2265 (path (speedbar-line-path depth)) | |
2266 (f (match-string 2))) | |
2267 (concat path f)) | |
2268 nil)))) | |
2269 | |
2270 (defun speedbar-goto-this-file (file) | |
2271 "If FILE is displayed, goto this line and return t. | |
2272 Otherwise do not move and return nil." | |
2273 (let ((path (substring (file-name-directory (expand-file-name file)) | |
2274 (length (expand-file-name default-directory)))) | |
2275 (dest (point))) | |
2276 (save-match-data | |
2277 (goto-char (point-min)) | |
2278 ;; scan all the directories | |
2279 (while (and path (not (eq path t))) | |
2280 (if (string-match "^/?\\([^/]+\\)" path) | |
2281 (let ((pp (match-string 1 path))) | |
2282 (if (save-match-data | |
2283 (re-search-forward (concat "> " (regexp-quote pp) "$") | |
2284 nil t)) | |
2285 (setq path (substring path (match-end 1))) | |
2286 (setq path nil))) | |
2287 (setq path t))) | |
2288 ;; find the file part | |
2289 (if (or (not path) (string= (file-name-nondirectory file) "")) | |
2290 ;; only had a dir part | |
2291 (if path | |
2292 (progn | |
2293 (speedbar-position-cursor-on-line) | |
2294 t) | |
2295 (goto-char dest) nil) | |
2296 ;; find the file part | |
2297 (let ((nd (file-name-nondirectory file))) | |
2298 (if (re-search-forward | |
2299 (concat "] \\(" (regexp-quote nd) | |
2300 "\\)\\(" (regexp-quote speedbar-vc-indicator) "\\)?$") | |
2301 nil t) | |
2302 (progn | |
2303 (speedbar-position-cursor-on-line) | |
2304 t) | |
2305 (goto-char dest) | |
2306 nil)))))) | |
2307 | |
2308 (defun speedbar-line-path (depth) | |
2309 "Retrieve the pathname associated with the current line. | |
2310 This may require traversing backwards from DEPTH and combining the default | |
2311 directory with these items." | |
2312 (save-excursion | |
2313 (save-match-data | |
2314 (let ((path nil)) | |
2315 (setq depth (1- depth)) | |
2316 (while (/= depth -1) | |
2317 (if (not (re-search-backward (format "^%d:" depth) nil t)) | |
2318 (error "Error building path of tag") | |
2319 (cond ((looking-at "[0-9]+:\\s-*<->\\s-+\\([^\n]+\\)$") | |
2320 (setq path (concat (buffer-substring-no-properties | |
2321 (match-beginning 1) (match-end 1)) | |
2322 "/" | |
2323 path))) | |
2324 ((looking-at "[0-9]+:\\s-*[-]\\s-+\\([^\n]+\\)$") | |
2325 ;; This is the start of our path. | |
2326 (setq path (buffer-substring-no-properties | |
2327 (match-beginning 1) (match-end 1)))))) | |
2328 (setq depth (1- depth))) | |
2329 (if (and path | |
2330 (string-match (concat (regexp-quote speedbar-vc-indicator) "$") | |
2331 path)) | |
2332 (setq path (substring path 0 (match-beginning 0)))) | |
2333 (concat default-directory path))))) | |
2334 | |
2335 (defun speedbar-path-line (path) | |
2336 "Position the cursor on the line specified by PATH." | |
2337 (save-match-data | |
2338 (if (string-match "/$" path) | |
2339 (setq path (substring path 0 (match-beginning 0)))) | |
2340 (let ((nomatch t) (depth 0) | |
2341 (fname (file-name-nondirectory path)) | |
2342 (pname (file-name-directory path))) | |
2343 (if (not (member pname speedbar-shown-directories)) | |
2344 (error "Internal Error: File %s not shown in speedbar." path)) | |
2345 (goto-char (point-min)) | |
2346 (while (and nomatch | |
2347 (re-search-forward | |
2348 (concat "[]>] \\(" (regexp-quote fname) | |
2349 "\\)\\(" (regexp-quote speedbar-vc-indicator) "\\)?$") | |
2350 nil t)) | |
2351 (beginning-of-line) | |
2352 (looking-at "\\([0-9]+\\):") | |
2353 (setq depth (string-to-int (match-string 0)) | |
2354 nomatch (not (string= pname (speedbar-line-path depth)))) | |
2355 (end-of-line)) | |
2356 (beginning-of-line) | |
2357 (not nomatch)))) | |
2358 | |
2359 (defun speedbar-edit-line () | |
2360 "Edit whatever tag or file is on the current speedbar line." | |
2361 (interactive) | |
2362 (or (save-excursion | |
2363 (beginning-of-line) | |
2364 ;; If this fails, then it is a non-standard click, and as such, | |
2365 ;; perfectly allowed. | |
2366 (if (re-search-forward "[]>}] [a-zA-Z0-9]" | |
2367 (save-excursion (end-of-line) (point)) | |
2368 t) | |
2369 (speedbar-do-function-pointer) | |
2370 nil)) | |
2371 (speedbar-do-function-pointer))) | |
2372 | |
2373 (defun speedbar-expand-line () | |
2374 "Expand the line under the cursor." | |
2375 (interactive) | |
2376 (beginning-of-line) | |
2377 (re-search-forward ":\\s-*.\\+. " (save-excursion (end-of-line) (point))) | |
2378 (forward-char -2) | |
2379 (speedbar-do-function-pointer)) | |
2380 | |
2381 (defun speedbar-contract-line () | |
2382 "Contract the line under the cursor." | |
2383 (interactive) | |
2384 (beginning-of-line) | |
2385 (re-search-forward ":\\s-*.-. " (save-excursion (end-of-line) (point))) | |
2386 (forward-char -2) | |
2387 (speedbar-do-function-pointer)) | |
2388 | |
2389 (if speedbar-xemacsp | |
2390 (defalias 'speedbar-mouse-event-p 'button-press-event-p) | |
2391 (defun speedbar-mouse-event-p (event) | |
2392 "Return t if the event is a mouse related event" | |
2393 ;; And Emacs does it this way | |
2394 (if (and (listp event) | |
2395 (member (event-basic-type event) | |
2396 '(mouse-1 mouse-2 mouse-3))) | |
2397 t | |
2398 nil))) | |
2399 | |
2400 (defun speedbar-maybee-jump-to-attached-frame () | |
2401 "Jump to the attached frame ONLY if this was not a mouse event." | |
2402 (if (or (not (speedbar-mouse-event-p last-input-event)) | |
2403 speedbar-activity-change-focus-flag) | |
2404 (progn | |
2405 (select-frame speedbar-attached-frame) | |
2406 (other-frame 0)))) | |
2407 | |
2408 (defun speedbar-find-file (text token indent) | |
2409 "Speedbar click handler for filenames. | |
2410 TEXT, the file will be displayed in the attached frame. | |
2411 TOKEN is unused, but required by the click handler. INDENT is the | |
2412 current indentation level." | |
2413 (let ((cdd (speedbar-line-path indent))) | |
2414 (speedbar-find-file-in-frame (concat cdd text)) | |
2415 (speedbar-stealthy-updates) | |
2416 (run-hooks 'speedbar-visiting-file-hook) | |
2417 ;; Reset the timer with a new timeout when cliking a file | |
2418 ;; in case the user was navigating directories, we can cancel | |
2419 ;; that other timer. | |
2420 (speedbar-set-timer speedbar-update-speed)) | |
2421 (speedbar-maybee-jump-to-attached-frame)) | |
2422 | |
2423 (defun speedbar-dir-follow (text token indent) | |
2424 "Speedbar click handler for directory names. | |
2425 Clicking a directory will cause the speedbar to list files in the | |
2426 the subdirectory TEXT. TOKEN is an unused requirement. The | |
2427 subdirectory chosen will be at INDENT level." | |
2428 (setq default-directory | |
2429 (concat (expand-file-name (concat (speedbar-line-path indent) text)) | |
2430 "/")) | |
2431 ;; Because we leave speedbar as the current buffer, | |
2432 ;; update contents will change directory without | |
2433 ;; having to touch the attached frame. | |
2434 (speedbar-update-contents) | |
2435 (speedbar-set-timer speedbar-navigating-speed) | |
2436 (setq speedbar-last-selected-file nil) | |
2437 (speedbar-stealthy-updates)) | |
2438 | |
2439 (defun speedbar-delete-subblock (indent) | |
2440 "Delete text from point to indentation level INDENT or greater. | |
2441 Handles end-of-sublist smartly." | |
2442 (speedbar-with-writable | |
2443 (save-excursion | |
2444 (end-of-line) (forward-char 1) | |
2445 (while (and (not (save-excursion | |
2446 (re-search-forward (format "^%d:" indent) | |
2447 nil t))) | |
2448 (>= indent 0)) | |
2449 (setq indent (1- indent))) | |
2450 (delete-region (point) (if (>= indent 0) | |
2451 (match-beginning 0) | |
2452 (point-max)))))) | |
2453 | |
2454 (defun speedbar-dired (text token indent) | |
2455 "Speedbar click handler for directory expand button. | |
2456 Clicking this button expands or contracts a directory. TEXT is the | |
2457 button clicked which has either a + or -. TOKEN is the directory to be | |
2458 expanded. INDENT is the current indentation level." | |
2459 (cond ((string-match "+" text) ;we have to expand this dir | |
2460 (setq speedbar-shown-directories | |
2461 (cons (expand-file-name | |
2462 (concat (speedbar-line-path indent) token "/")) | |
2463 speedbar-shown-directories)) | |
2464 (speedbar-change-expand-button-char ?-) | |
2465 (speedbar-reset-scanners) | |
2466 (save-excursion | |
2467 (end-of-line) (forward-char 1) | |
2468 (speedbar-with-writable | |
2469 (speedbar-default-directory-list | |
2470 (concat (speedbar-line-path indent) token "/") | |
2471 (1+ indent))))) | |
2472 ((string-match "-" text) ;we have to contract this node | |
2473 (speedbar-reset-scanners) | |
2474 (let ((oldl speedbar-shown-directories) | |
2475 (newl nil) | |
2476 (td (expand-file-name | |
2477 (concat (speedbar-line-path indent) token)))) | |
2478 (while oldl | |
2479 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl))) | |
2480 (setq newl (cons (car oldl) newl))) | |
2481 (setq oldl (cdr oldl))) | |
2482 (setq speedbar-shown-directories newl)) | |
2483 (speedbar-change-expand-button-char ?+) | |
2484 (speedbar-delete-subblock indent) | |
2485 ) | |
2486 (t (error "Ooops... not sure what to do."))) | |
2487 (speedbar-center-buffer-smartly) | |
2488 (setq speedbar-last-selected-file nil) | |
2489 (save-excursion (speedbar-stealthy-updates))) | |
2490 | |
2491 (defun speedbar-directory-buttons-follow (text token indent) | |
2492 "Speedbar click handler for default directory buttons. | |
2493 TEXT is the button clicked on. TOKEN is the directory to follow. | |
2494 INDENT is the current indentation level and is unused." | |
2495 (setq default-directory token) | |
2496 ;; Because we leave speedbar as the current buffer, | |
2497 ;; update contents will change directory without | |
2498 ;; having to touch the attached frame. | |
2499 (speedbar-update-contents) | |
2500 (speedbar-set-timer speedbar-navigating-speed)) | |
2501 | |
2502 (defun speedbar-tag-file (text token indent) | |
2503 "The cursor is on a selected line. Expand the tags in the specified file. | |
2504 The parameter TEXT and TOKEN are required, where TEXT is the button | |
2505 clicked, and TOKEN is the file to expand. INDENT is the current | |
2506 indentation level." | |
2507 (cond ((string-match "+" text) ;we have to expand this file | |
2508 (let* ((fn (expand-file-name (concat (speedbar-line-path indent) | |
2509 token))) | |
2510 (lst (if speedbar-use-imenu-flag | |
2511 (let ((tim (speedbar-fetch-dynamic-imenu fn))) | |
2512 (if (eq tim t) | |
2513 (speedbar-fetch-dynamic-etags fn) | |
2514 tim)) | |
2515 (speedbar-fetch-dynamic-etags fn)))) | |
2516 ;; if no list, then remove expando button | |
2517 (if (not lst) | |
2518 (speedbar-change-expand-button-char ??) | |
2519 (speedbar-change-expand-button-char ?-) | |
2520 (speedbar-with-writable | |
2521 (save-excursion | |
2522 (end-of-line) (forward-char 1) | |
2523 (speedbar-insert-generic-list indent | |
2524 lst 'speedbar-tag-expand | |
2525 'speedbar-tag-find)))))) | |
2526 ((string-match "-" text) ;we have to contract this node | |
2527 (speedbar-change-expand-button-char ?+) | |
2528 (speedbar-delete-subblock indent)) | |
2529 (t (error "Ooops... not sure what to do."))) | |
2530 (speedbar-center-buffer-smartly)) | |
2531 | |
2532 (defun speedbar-tag-find (text token indent) | |
2533 "For the tag TEXT in a file TOKEN, goto that position. | |
2534 INDENT is the current indentation level." | |
2535 (let ((file (speedbar-line-path indent))) | |
2536 (speedbar-find-file-in-frame file) | |
2537 (save-excursion (speedbar-stealthy-updates)) | |
2538 ;; Reset the timer with a new timeout when cliking a file | |
2539 ;; in case the user was navigating directories, we can cancel | |
2540 ;; that other timer. | |
2541 (speedbar-set-timer speedbar-update-speed) | |
2542 (goto-char token) | |
2543 (run-hooks 'speedbar-visiting-tag-hook) | |
2544 ;;(recenter) | |
2545 (speedbar-maybee-jump-to-attached-frame) | |
2546 )) | |
2547 | |
2548 (defun speedbar-tag-expand (text token indent) | |
2549 "Expand a tag sublist. Imenu will return sub-lists of specialized tag types. | |
2550 Etags does not support this feature. TEXT will be the button | |
2551 string. TOKEN will be the list, and INDENT is the current indentation | |
2552 level." | |
2553 (cond ((string-match "+" text) ;we have to expand this file | |
2554 (speedbar-change-expand-button-char ?-) | |
2555 (speedbar-with-writable | |
2556 (save-excursion | |
2557 (end-of-line) (forward-char 1) | |
2558 (speedbar-insert-generic-list indent | |
2559 token 'speedbar-tag-expand | |
2560 'speedbar-tag-find)))) | |
2561 ((string-match "-" text) ;we have to contract this node | |
2562 (speedbar-change-expand-button-char ?+) | |
2563 (speedbar-delete-subblock indent)) | |
2564 (t (error "Ooops... not sure what to do."))) | |
2565 (speedbar-center-buffer-smartly)) | |
2566 | |
2567 ;;; Loading files into the attached frame. | |
2568 ;; | |
2569 (defun speedbar-find-file-in-frame (file) | |
2570 "This will load FILE into the speedbar attached frame. | |
2571 If the file is being displayed in a different frame already, then raise that | |
2572 frame instead." | |
2573 (let* ((buff (find-file-noselect file)) | |
2574 (bwin (get-buffer-window buff 0))) | |
2575 (if bwin | |
2576 (progn | |
2577 (select-window bwin) | |
2578 (raise-frame (window-frame bwin))) | |
2579 (if speedbar-power-click | |
2580 (let ((pop-up-frames t)) (select-window (display-buffer buff))) | |
2581 (select-frame speedbar-attached-frame) | |
2582 (switch-to-buffer buff)))) | |
2583 ) | |
2584 | |
2585 ;;; Centering Utility | |
2586 ;; | |
2587 (defun speedbar-center-buffer-smartly () | |
2588 "Recenter a speedbar buffer so the current indentation level is all visible. | |
2589 This assumes that the cursor is on a file, or tag of a file which the user is | |
2590 interested in." | |
2591 (if (<= (count-lines (point-min) (point-max)) | |
2592 (window-height (selected-window))) | |
2593 ;; whole buffer fits | |
2594 (let ((cp (point))) | |
2595 (goto-char (point-min)) | |
2596 (recenter 0) | |
2597 (goto-char cp)) | |
2598 ;; too big | |
2599 (let (depth start end exp p) | |
2600 (save-excursion | |
2601 (beginning-of-line) | |
2602 (setq depth (if (looking-at "[0-9]+") | |
2603 (string-to-int (buffer-substring-no-properties | |
2604 (match-beginning 0) (match-end 0))) | |
2605 0)) | |
2606 (setq exp (format "^%d:\\s-*[[{<]\\([?+-]\\)[]>}]" depth))) | |
2607 (save-excursion | |
2608 (end-of-line) | |
2609 (if (re-search-backward exp nil t) | |
2610 (setq start (point)) | |
2611 (error "Center error")) | |
2612 (save-excursion ;Not sure about this part. | |
2613 (end-of-line) | |
2614 (setq p (point)) | |
2615 (while (and (not (re-search-forward exp nil t)) | |
2616 (>= depth 0)) | |
2617 (setq depth (1- depth)) | |
2618 (setq exp (format "^%d:\\s-*[[{<]\\([?+-]\\)[]>}]" depth))) | |
2619 (if (/= (point) p) | |
2620 (setq end (point)) | |
2621 (setq end (point-max))))) | |
2622 ;; Now work out the details of centering | |
2623 (let ((nl (count-lines start end)) | |
2624 (cp (point))) | |
2625 (if (> nl (window-height (selected-window))) | |
2626 ;; We can't fit it all, so just center on cursor | |
2627 (progn (goto-char start) | |
2628 (recenter 1)) | |
2629 ;; we can fit everything on the screen, but... | |
2630 (if (and (pos-visible-in-window-p start (selected-window)) | |
2631 (pos-visible-in-window-p end (selected-window))) | |
2632 ;; we are all set! | |
2633 nil | |
2634 ;; we need to do something... | |
2635 (goto-char start) | |
2636 (let ((newcent (/ (- (window-height (selected-window)) nl) 2)) | |
2637 (lte (count-lines start (point-max)))) | |
2638 (if (and (< (+ newcent lte) (window-height (selected-window))) | |
2639 (> (- (window-height (selected-window)) lte 1) | |
2640 newcent)) | |
2641 (setq newcent (- (window-height (selected-window)) | |
2642 lte 1))) | |
2643 (recenter newcent)))) | |
2644 (goto-char cp))))) | |
2645 | |
2646 | |
2647 ;;; Tag Management -- Imenu | |
2648 ;; | |
2649 (if (not speedbar-use-imenu-flag) | |
2650 | |
2651 nil | |
2652 | |
2653 (eval-when-compile (if (locate-library "imenu") (require 'imenu))) | |
2654 | |
2655 (defun speedbar-fetch-dynamic-imenu (file) | |
2656 "Load FILE into a buffer, and generate tags using Imenu. | |
2657 Returns the tag list, or t for an error." | |
2658 ;; Load this AND compile it in | |
2659 (require 'imenu) | |
2660 (save-excursion | |
2661 (set-buffer (find-file-noselect file)) | |
2662 (if speedbar-power-click (setq imenu--index-alist nil)) | |
2663 (condition-case nil | |
2664 (let ((index-alist (imenu--make-index-alist t))) | |
2665 (if speedbar-sort-tags | |
2666 (sort (copy-alist index-alist) | |
2667 (lambda (a b) (string< (car a) (car b)))) | |
2668 index-alist)) | |
2669 (error t)))) | |
2670 ) | |
2671 | |
2672 ;;; Tag Management -- etags (old XEmacs compatibility part) | |
2673 ;; | |
2674 (defvar speedbar-fetch-etags-parse-list | |
2675 '(;; Note that java has the same parse-group as c | |
2676 ("\\.\\([cChH]\\|c\\+\\+\\|cpp\\|cc\\|hh\\|java\\)\\'" . | |
2677 speedbar-parse-c-or-c++tag) | |
2678 ("^\\.emacs$\\|.\\(el\\|l\\|lsp\\)\\'" . | |
2679 "def[^i]+\\s-+\\(\\(\\w\\|[-_]\\)+\\)\\s-*\C-?") | |
2680 ("\\.tex\\'" . speedbar-parse-tex-string) | |
2681 ("\\.p\\'" . | |
2682 "\\(\\(FUNCTION\\|function\\|PROCEDURE\\|procedure\\)\\s-+\\([a-zA-Z0-9_.:]+\\)\\)\\s-*(?^?") | |
2683 ) | |
2684 "Associations of file extensions and expressions for extracting tags. | |
2685 To add a new file type, you would want to add a new association to the | |
2686 list, where the car is the file match, and the cdr is the way to | |
2687 extract an element from the tags output. If the output is complex, | |
2688 use a function symbol instead of regexp. The function should expect | |
2689 to be at the beginning of a line in the etags buffer. | |
2690 | |
2691 This variable is ignored if `speedbar-use-imenu-flag' is non-nil.") | |
2692 | |
2693 (defvar speedbar-fetch-etags-command "etags" | |
2694 "*Command used to create an etags file. | |
2695 | |
2696 This variable is ignored if `speedbar-use-imenu-flag' is t") | |
2697 | |
2698 (defvar speedbar-fetch-etags-arguments '("-D" "-I" "-o" "-") | |
2699 "*List of arguments to use with `speedbar-fetch-etags-command'. | |
2700 This creates an etags output buffer. Use `speedbar-toggle-etags' to | |
2701 modify this list conveniently. | |
2702 | |
2703 This variable is ignored if `speedbar-use-imenu-flag' is t") | |
2704 | |
2705 (defun speedbar-toggle-etags (flag) | |
2706 "Toggle FLAG in `speedbar-fetch-etags-arguments'. | |
2707 FLAG then becomes a member of etags command line arguments. If flag | |
2708 is \"sort\", then toggle the value of `speedbar-sort-tags'. If its | |
2709 value is \"show\" then toggle the value of | |
2710 `speedbar-show-unknown-files'. | |
2711 | |
2712 This function is a convenience function for XEmacs menu created by | |
2713 Farzin Guilak <farzin@protocol.com>" | |
2714 (interactive) | |
2715 (cond | |
2716 ((equal flag "sort") | |
2717 (setq speedbar-sort-tags (not speedbar-sort-tags))) | |
2718 ((equal flag "show") | |
2719 (setq speedbar-show-unknown-files (not speedbar-show-unknown-files))) | |
2720 ((or (equal flag "-C") | |
2721 (equal flag "-S") | |
2722 (equal flag "-D")) | |
2723 (if (member flag speedbar-fetch-etags-arguments) | |
2724 (setq speedbar-fetch-etags-arguments | |
2725 (delete flag speedbar-fetch-etags-arguments)) | |
2726 (add-to-list 'speedbar-fetch-etags-arguments flag))) | |
2727 (t nil))) | |
2728 | |
2729 (defun speedbar-fetch-dynamic-etags (file) | |
2730 "For FILE, run etags and create a list of symbols extracted. | |
2731 Each symbol will be associated with its line position in FILE." | |
2732 (let ((newlist nil)) | |
2733 (unwind-protect | |
2734 (save-excursion | |
2735 (if (get-buffer "*etags tmp*") | |
2736 (kill-buffer "*etags tmp*")) ;kill to clean it up | |
2737 (if (<= 1 speedbar-verbosity-level) (message "Fetching etags...")) | |
2738 (set-buffer (get-buffer-create "*etags tmp*")) | |
2739 (apply 'call-process speedbar-fetch-etags-command nil | |
2740 (current-buffer) nil | |
2741 (append speedbar-fetch-etags-arguments (list file))) | |
2742 (goto-char (point-min)) | |
2743 (if (<= 1 speedbar-verbosity-level) (message "Fetching etags...")) | |
2744 (let ((expr | |
2745 (let ((exprlst speedbar-fetch-etags-parse-list) | |
2746 (ans nil)) | |
2747 (while (and (not ans) exprlst) | |
2748 (if (string-match (car (car exprlst)) file) | |
2749 (setq ans (car exprlst))) | |
2750 (setq exprlst (cdr exprlst))) | |
2751 (cdr ans)))) | |
2752 (if expr | |
2753 (let (tnl) | |
2754 (while (not (save-excursion (end-of-line) (eobp))) | |
2755 (save-excursion | |
2756 (setq tnl (speedbar-extract-one-symbol expr))) | |
2757 (if tnl (setq newlist (cons tnl newlist))) | |
2758 (forward-line 1))) | |
2759 (message "Sorry, no support for a file of that extension")))) | |
2760 ) | |
2761 (if speedbar-sort-tags | |
2762 (sort newlist (lambda (a b) (string< (car a) (car b)))) | |
2763 (reverse newlist)))) | |
2764 | |
2765 ;; This bit donated by Farzin Guilak <farzin@protocol.com> but I'm not | |
2766 ;; sure it's needed with the different sorting method. | |
2767 ;; | |
2768 ;(defun speedbar-clean-etags() | |
2769 ; "Removes spaces before the ^? character, and removes `#define', | |
2770 ;return types, etc. preceding tags. This ensures that the sort operation | |
2771 ;works on the tags, not the return types." | |
2772 ; (save-excursion | |
2773 ; (goto-char (point-min)) | |
2774 ; (while | |
2775 ; (re-search-forward "(?[ \t](?\C-?" nil t) | |
2776 ; (replace-match "\C-?" nil nil)) | |
2777 ; (goto-char (point-min)) | |
2778 ; (while | |
2779 ; (re-search-forward "\\(.*[ \t]+\\)\\([^ \t\n]+.*\C-?\\)" nil t) | |
2780 ; (delete-region (match-beginning 1) (match-end 1))))) | |
2781 | |
2782 (defun speedbar-extract-one-symbol (expr) | |
2783 "At point, return nil, or one alist in the form: ( symbol . position ) | |
2784 The line should contain output from etags. Parse the output using the | |
2785 regular expression EXPR" | |
2786 (let* ((sym (if (stringp expr) | |
2787 (if (save-excursion | |
2788 (re-search-forward expr (save-excursion | |
2789 (end-of-line) | |
2790 (point)) t)) | |
2791 (buffer-substring-no-properties (match-beginning 1) | |
2792 (match-end 1))) | |
2793 (funcall expr))) | |
2794 (pos (let ((j (re-search-forward "[\C-?\C-a]\\([0-9]+\\),\\([0-9]+\\)" | |
2795 (save-excursion | |
2796 (end-of-line) | |
2797 (point)) | |
2798 t))) | |
2799 (if (and j sym) | |
2800 (1+ (string-to-int (buffer-substring-no-properties | |
2801 (match-beginning 2) | |
2802 (match-end 2)))) | |
2803 0)))) | |
2804 (if (/= pos 0) | |
2805 (cons sym pos) | |
2806 nil))) | |
2807 | |
2808 (defun speedbar-parse-c-or-c++tag () | |
2809 "Parse a c or c++ tag, which tends to be a little complex." | |
2810 (save-excursion | |
2811 (let ((bound (save-excursion (end-of-line) (point)))) | |
2812 (cond ((re-search-forward "\C-?\\([^\C-a]+\\)\C-a" bound t) | |
2813 (buffer-substring-no-properties (match-beginning 1) | |
2814 (match-end 1))) | |
2815 ((re-search-forward "\\<\\([^ \t]+\\)\\s-+new(" bound t) | |
2816 (buffer-substring-no-properties (match-beginning 1) | |
2817 (match-end 1))) | |
2818 ((re-search-forward "\\<\\([^ \t(]+\\)\\s-*(\C-?" bound t) | |
2819 (buffer-substring-no-properties (match-beginning 1) | |
2820 (match-end 1))) | |
2821 (t nil)) | |
2822 ))) | |
2823 | |
2824 (defun speedbar-parse-tex-string () | |
2825 "Parse a Tex string. Only find data which is relevant." | |
2826 (save-excursion | |
2827 (let ((bound (save-excursion (end-of-line) (point)))) | |
2828 (cond ((re-search-forward "\\(\\(sub\\)*section\\|chapter\\|cite\\)\\s-*{[^\C-?}]*}?" bound t) | |
2829 (buffer-substring-no-properties (match-beginning 0) | |
2830 (match-end 0))) | |
2831 (t nil))))) | |
2832 | |
2833 | |
2834 ;;; Color loading section This is messy *Blech!* | |
2835 ;; | |
2836 (defface speedbar-button-face '((((class color) (background light)) | |
2837 (:foreground "green4")) | |
2838 (((class color) (background dark)) | |
2839 (:foreground "green3"))) | |
2840 "Face used for +/- buttons." | |
2841 :group 'speedbar-faces) | |
2842 | |
2843 (defface speedbar-file-face '((((class color) (background light)) | |
2844 (:foreground "cyan4")) | |
2845 (((class color) (background dark)) | |
2846 (:foreground "cyan")) | |
2847 (t (:bold t))) | |
2848 "Face used for file names." | |
2849 :group 'speedbar-faces) | |
2850 | |
2851 (defface speedbar-directory-face '((((class color) (background light)) | |
2852 (:foreground "blue4")) | |
2853 (((class color) (background dark)) | |
2854 (:foreground "light blue"))) | |
2855 "Faced used for directory names." | |
2856 :group 'speedbar-faces) | |
2857 (defface speedbar-tag-face '((((class color) (background light)) | |
2858 (:foreground "brown")) | |
2859 (((class color) (background dark)) | |
2860 (:foreground "yellow"))) | |
2861 "Face used for displaying tags." | |
2862 :group 'speedbar-faces) | |
2863 | |
2864 (defface speedbar-selected-face '((((class color) (background light)) | |
2865 (:foreground "red" :underline t)) | |
2866 (((class color) (background dark)) | |
2867 (:foreground "red" :underline t)) | |
2868 (t (:underline t))) | |
2869 "Face used to underline the file in the active window." | |
2870 :group 'speedbar-faces) | |
2871 | |
2872 (defface speedbar-highlight-face '((((class color) (background light)) | |
2873 (:background "green")) | |
2874 (((class color) (background dark)) | |
2875 (:background "sea green")) | |
2876 (((class grayscale monochrome) | |
2877 (background light)) | |
2878 (:background "black")) | |
2879 (((class grayscale monochrome) | |
2880 (background dark)) | |
2881 (:background "white"))) | |
2882 "Face used for highlighting buttons with the mouse." | |
2883 :group 'speedbar-faces) | |
2884 | |
2885 ;; some edebug hooks | |
2886 (add-hook 'edebug-setup-hook | |
2887 (lambda () | |
2888 (def-edebug-spec speedbar-with-writable def-body))) | |
2889 | |
2890 (provide 'speedbar) | |
2891 ;;; speedbar ends here | |
2892 | |
2893 ;; run load-time hooks | |
2894 (run-hooks 'speedbar-load-hook) |