Mercurial > emacs
annotate lisp/speedbar.el @ 23353:2a5d306408cb
*** empty log message ***
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Wed, 30 Sep 1998 19:07:17 +0000 |
parents | a1bd0f4f73e1 |
children | 64e80b07376b |
rev | line source |
---|---|
22735 | 1 ;;; speedbar --- quick access to files and tags in a frame |
21650 | 2 |
3 ;;; Copyright (C) 1996, 97, 98 Free Software Foundation | |
22735 | 4 |
5 ;; Author: Eric M. Ludlam <zappo@gnu.org> | |
23242 | 6 ;; Version: 0.7.2c |
22735 | 7 ;; Keywords: file, tags, tools |
23275
a1bd0f4f73e1
(speedbar-initial-expansion-list-name): Fix
Andreas Schwab <schwab@suse.de>
parents:
23242
diff
changeset
|
8 ;; X-RCS: $Id: speedbar.el,v 1.15 1998/09/12 13:58:46 zappo Exp $ |
22735 | 9 |
21650 | 10 ;; This file is part of GNU Emacs. |
22735 | 11 |
21650 | 12 ;; GNU Emacs is free software; you can redistribute it and/or modify |
13 ;; it under the terms of the GNU General Public License as published by | |
14 ;; the Free Software Foundation; either version 2, or (at your option) | |
15 ;; any later version. | |
22735 | 16 |
21650 | 17 ;; GNU Emacs is distributed in the hope that it will be useful, |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
22735 | 21 |
21650 | 22 ;; You should have received a copy of the GNU General Public License |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
25 ;; Boston, MA 02111-1307, USA. | |
26 | |
27 ;;; Commentary: | |
28 ;; | |
29 ;; The speedbar provides a frame in which files, and locations in | |
30 ;; files are displayed. These items can be clicked on with mouse-2 | |
31 ;; in order to make the last active frame display that file location. | |
32 ;; | |
33 ;; Starting Speedbar: | |
34 ;; | |
35 ;; If speedbar came to you as a part of Emacs, simply type | |
22735 | 36 ;; `M-x speedbar', and it will be autoloaded for you. |
21650 | 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 ;; | |
22735 | 44 ;; If you want to choose it from a menu, such as "Tools", you can do this: |
21650 | 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 | |
22735 | 91 ;; file imenu.el that comes with Emacs. To add new file types which |
21650 | 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 ;; | |
22735 | 104 ;; To enable mouse tracking with information in the minibuffer of |
105 ;; the attached frame, use the variable `speedbar-track-mouse-flag'. | |
106 ;; | |
107 ;; Tag layout can be modified through `speedbar-tag-hierarchy-method', | |
108 ;; which controls how tags are layed out. It is actually a list of | |
109 ;; functions that filter the data. The default groups large tag lists | |
110 ;; into sub-lists. A long flat list can be used instead if needed. | |
111 ;; Other filters could be easily added. | |
112 ;; | |
113 ;; Users of XEmacs previous to 20 may want to change the default | |
21650 | 114 ;; timeouts for `speedbar-update-speed' to something longer as XEmacs |
115 ;; doesn't have idle timers, the speedbar timer keeps going off | |
116 ;; arbitrarily while you're typing. It's quite pesky. | |
117 ;; | |
118 ;; Users of really old emacsen without the needed timers will not | |
119 ;; have speedbar updating automatically. Use "r" to refresh the | |
120 ;; display after changing directories. Remember, do not interrupt the | |
121 ;; stealthy updates or your display may not be completely refreshed. | |
122 ;; | |
123 ;; AUC-TEX users: The imenu tags for AUC-TEX mode don't work very | |
124 ;; well. Use the imenu keywords from tex-mode.el for better results. | |
125 ;; | |
126 ;; This file requires the library package assoc (association lists) | |
127 ;; and the package custom (for easy configuration of speedbar) | |
128 ;; http://www.dina.kvl.dk/~abraham/custom/ | |
129 ;; | |
22735 | 130 ;;; Developing for speedbar |
131 ;; | |
132 ;; Adding a speedbar specialized display mode: | |
133 ;; | |
134 ;; Speedbar can be configured to create a special display for certain | |
135 ;; modes that do not display tradition file/tag data. Rmail, Info, | |
136 ;; and the debugger are examples. These modes can, however, benefit | |
137 ;; from a speedbar style display in their own way. | |
21650 | 138 ;; |
22735 | 139 ;; If your `major-mode' is `foo-mode', the only requirement is to |
140 ;; create a function called `foo-speedbar-buttons' which takes one | |
141 ;; argument, BUFFER. BUFFER will be the buffer speedbar wants filled. | |
142 ;; In `foo-speedbar-buttons' there are several functions that make | |
143 ;; building a speedbar display easy. See the documentation for | |
144 ;; `speedbar-with-writable' (needed because the buffer is usually | |
145 ;; read-only) `speedbar-make-tag-line', `speedbar-insert-button', and | |
146 ;; `speedbar-insert-generic-list'. If you use | |
147 ;; `speedbar-insert-generic-list', also read the doc for | |
148 ;; `speedbar-tag-hierarchy-method' in case you wish to override it. | |
149 ;; The function `speedbar-with-attached-buffer' brings you back to the | |
150 ;; buffer speedbar is displaying for. | |
21650 | 151 ;; |
22735 | 152 ;; For those functions that make buttons, the "function" should be a |
153 ;; symbol that is the function to call when clicked on. The "token" | |
154 ;; is extra data you can pass along. The "function" must take three | |
155 ;; parameters. They are (TEXT TOKEN INDENT). TEXT is the text of the | |
156 ;; button clicked on. TOKEN is the data passed in when you create the | |
157 ;; button. INDENT is an indentation level, or 0. You can store | |
158 ;; indentation levels with `speedbar-make-tag-line' which creates a | |
159 ;; line with an expander (eg. [+]) and a text button. | |
160 ;; | |
161 ;; Some useful functions when writing expand functions, and click | |
162 ;; functions are `speedbar-change-expand-button-char', | |
163 ;; `speedbar-delete-subblock', and `speedbar-center-buffer-smartly'. | |
164 ;; The variable `speedbar-power-click' is set to t in your functions | |
165 ;; when the user shift-clicks. This indications anything from | |
166 ;; refreshing cached data to making a buffer appear in a new frame. | |
167 ;; | |
168 ;; If you wish to add to the default speedbar menu for the case of | |
169 ;; `foo-mode', create a variable `foo-speedbar-menu-items'. This | |
170 ;; should be a list compatible with the `easymenu' package. It will | |
171 ;; be spliced into the main menu. (Available with click-mouse-3). If | |
172 ;; you wish to have extra key bindings in your special mode, create a | |
173 ;; variable `foo-speedbar-key-map'. Instead of using `make-keymap', | |
174 ;; or `make-sparse-keymap', use the function | |
175 ;; `speedbar-make-specialized-keymap'. This lets you inherit all of | |
176 ;; speedbar's default bindings with low overhead. | |
177 ;; | |
178 ;; Adding a speedbar top-level display mode: | |
179 ;; | |
180 ;; Unlike the specialized modes, there are no name requirements, | |
181 ;; however the methods for writing a button display, menu, and keymap | |
182 ;; are the same. Once you create these items, you can call the | |
183 ;; function `speedbar-add-expansion-list'. It takes one parameter | |
184 ;; which is a list element of the form (NAME MENU KEYMAP &rest | |
185 ;; BUTTON-FUNCTIONS). NAME is a string that will show up in the | |
186 ;; Displays menu item. MENU is a symbol containing the menu items to | |
187 ;; splice in. KEYMAP is a symbol holding the keymap to use, and | |
188 ;; BUTTON-FUNCTIONS are the function names to call, in order, to create | |
189 ;; the display. | |
21650 | 190 |
191 ;;; TODO: | |
192 ;; - More functions to create buttons and options | |
193 ;; - Timeout directories we haven't visited in a while. | |
194 ;; - Remeber tags when refreshing the display. (Refresh tags too?) | |
195 ;; - More 'special mode support. | |
196 | |
197 (require 'assoc) | |
198 (require 'easymenu) | |
199 | |
22735 | 200 (defvar speedbar-xemacsp (string-match "XEmacs" emacs-version) |
201 "Non-nil if we are running in the XEmacs environment.") | |
202 (defvar speedbar-xemacs20p (and speedbar-xemacsp | |
203 (= emacs-major-version 20))) | |
204 | |
21650 | 205 ;; From custom web page for compatibility between versions of custom: |
206 (eval-and-compile | |
207 (condition-case () | |
208 (require 'custom) | |
209 (error nil)) | |
22735 | 210 (if (and (featurep 'custom) (fboundp 'custom-declare-variable) |
211 ;; Some XEmacsen w/ custom don't have :set keyword. | |
212 ;; This protects them against custom. | |
213 (fboundp 'custom-initialize-set)) | |
21650 | 214 nil ;; We've got what we needed |
215 ;; We have the old custom-library, hack around it! | |
216 (defmacro defgroup (&rest args) | |
217 nil) | |
218 (defmacro defface (var values doc &rest args) | |
219 (` (progn | |
220 (defvar (, var) (quote (, var))) | |
221 ;; To make colors for your faces you need to set your .Xdefaults | |
222 ;; or set them up ahead of time in your .emacs file. | |
223 (make-face (, var)) | |
224 ))) | |
225 (defmacro defcustom (var value doc &rest args) | |
226 (` (defvar (, var) (, value) (, doc)))))) | |
227 | |
228 ;; customization stuff | |
229 (defgroup speedbar nil | |
230 "File and tag browser frame." | |
231 :group 'tags | |
21658
d8a81542dbf9
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
21650
diff
changeset
|
232 :group 'tools |
22250
a77d473867b8
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
21658
diff
changeset
|
233 :group 'convenience |
21658
d8a81542dbf9
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
21650
diff
changeset
|
234 :version "20.3") |
21650 | 235 |
236 (defgroup speedbar-faces nil | |
237 "Faces used in speedbar." | |
238 :prefix "speedbar-" | |
239 :group 'speedbar | |
240 :group 'faces) | |
241 | |
242 (defgroup speedbar-vc nil | |
243 "Version control display in speedbar." | |
244 :prefix "speedbar-" | |
245 :group 'speedbar) | |
246 | |
247 ;;; Code: | |
22735 | 248 (defvar speedbar-initial-expansion-mode-alist |
249 '(("buffers" speedbar-buffer-easymenu-definition speedbar-buffers-key-map | |
250 speedbar-buffer-buttons) | |
251 ("quick buffers" speedbar-buffer-easymenu-definition speedbar-buffers-key-map | |
252 speedbar-buffer-buttons-temp) | |
253 ;; Files last, means first in the Displays menu | |
254 ("files" speedbar-easymenu-definition-special speedbar-file-key-map | |
255 speedbar-directory-buttons speedbar-default-directory-list) | |
256 ) | |
257 "List of named expansion elements for filling the speedbar frame. | |
258 These expansion lists are only valid for regular files. Special modes | |
259 still get to override this list on a mode-by-mode basis. This list of | |
260 lists is of the form (NAME MENU KEYMAP FN1 FN2 ...). NAME is a string | |
261 representing the types of things to be displayed. MENU is an easymenu | |
262 structure used when in this mode. KEYMAP is a local keymap to install | |
263 over the regular speedbar keymap. FN1 ... are functions that will be | |
264 called in order. These functions will always get the default | |
265 directory to use passed in as the first parameter, and a 0 as the | |
266 second parameter. The 0 indicates the uppermost indentation level. | |
267 They must assume that the cursor is at the position where they start | |
268 inserting buttons.") | |
21650 | 269 |
22735 | 270 (defcustom speedbar-initial-expansion-list-name "files" |
271 "A symbol name representing the expansion list to use. | |
272 The expansion list `speedbar-initial-expansion-mode-alist' contains | |
273 the names and associated functions to use for buttons in speedbar." | |
274 :group 'speedbar | |
23275
a1bd0f4f73e1
(speedbar-initial-expansion-list-name): Fix
Andreas Schwab <schwab@suse.de>
parents:
23242
diff
changeset
|
275 :type '(radio (const :tag "File Directories" "files") |
a1bd0f4f73e1
(speedbar-initial-expansion-list-name): Fix
Andreas Schwab <schwab@suse.de>
parents:
23242
diff
changeset
|
276 (const "buffers") |
a1bd0f4f73e1
(speedbar-initial-expansion-list-name): Fix
Andreas Schwab <schwab@suse.de>
parents:
23242
diff
changeset
|
277 (const "quick buffers") |
22735 | 278 )) |
279 | |
280 (defvar speedbar-previously-used-expansion-list-name "files" | |
281 "Save the last expansion list method. | |
282 This is used for returning to a previous expansion list method when | |
283 the user is done with the current expansion list.") | |
21650 | 284 |
285 (defvar speedbar-stealthy-function-list | |
22735 | 286 '(("files" |
287 speedbar-update-current-file speedbar-check-vc speedbar-check-objects) | |
288 ) | |
21650 | 289 "List of functions to periodically call stealthily. |
22735 | 290 This list is of the form: |
291 '( (\"NAME\" FUNCTION ...) | |
292 ...) | |
293 where NAME is the name of the major display mode these functions are | |
294 for, and the remaining elements FUNCTION are functions to call in order. | |
21650 | 295 Each function must return nil if interrupted, or t if completed. |
296 Stealthy functions which have a single operation should always return | |
297 t. Functions which take a long time should maintain a state (where | |
298 they are in their speedbar related calculations) and permit | |
299 interruption. See `speedbar-check-vc' as a good example.") | |
300 | |
301 (defcustom speedbar-mode-specific-contents-flag t | |
302 "*Non-nil means speedbar will show special mode contents. | |
303 This permits some modes to create customized contents for the speedbar | |
304 frame." | |
305 :group 'speedbar | |
306 :type 'boolean) | |
307 | |
308 (defvar speedbar-special-mode-expansion-list nil | |
22735 | 309 "Default function list for creating specialized button lists. |
310 This list is set by modes that wish to have special speedbar displays. | |
311 The list is of function names. Each function is called with one | |
312 parameter BUFFER, the originating buffer. The current buffer is the | |
313 speedbar buffer.") | |
21650 | 314 |
22735 | 315 (defvar speedbar-special-mode-key-map nil |
316 "Default keymap used when identifying a specialized display mode. | |
317 This keymap is local to each buffer that wants to define special keybindings | |
318 effective when it's display is shown.") | |
21650 | 319 |
320 (defcustom speedbar-visiting-file-hook nil | |
321 "Hooks run when speedbar visits a file in the selected frame." | |
322 :group 'speedbar | |
323 :type 'hook) | |
324 | |
325 (defcustom speedbar-visiting-tag-hook nil | |
326 "Hooks run when speedbar visits a tag in the selected frame." | |
327 :group 'speedbar | |
328 :type 'hook) | |
329 | |
330 (defcustom speedbar-load-hook nil | |
331 "Hooks run when speedbar is loaded." | |
332 :group 'speedbar | |
333 :type 'hook) | |
334 | |
335 (defcustom speedbar-show-unknown-files nil | |
336 "*Non-nil show files we can't expand with a ? in the expand button. | |
337 nil means don't show the file in the list." | |
338 :group 'speedbar | |
339 :type 'boolean) | |
340 | |
341 (defcustom speedbar-update-speed | |
342 (if speedbar-xemacsp | |
343 (if speedbar-xemacs20p | |
344 2 ; 1 is too obrusive in XEmacs | |
345 5) ; when no idleness, need long delay | |
346 1) | |
347 "*Idle time in seconds needed before speedbar will update itself. | |
348 Updates occur to allow speedbar to display directory information | |
349 relevant to the buffer you are currently editing." | |
350 :group 'speedbar | |
351 :type 'integer) | |
352 | |
22735 | 353 ;; When I moved to a repeating timer, I had the horrible missfortune |
354 ;; of loosing the ability for adaptive speed choice. This update | |
355 ;; speed currently causes long delays when it should have been turned off. | |
356 (defcustom speedbar-navigating-speed speedbar-update-speed | |
21650 | 357 "*Idle time to wait after navigation commands in speedbar are executed. |
358 Navigation commands included expanding/contracting nodes, and moving | |
359 between different directories." | |
360 :group 'speedbar | |
361 :type 'integer) | |
362 | |
363 (defcustom speedbar-frame-parameters '((minibuffer . nil) | |
364 (width . 20) | |
365 (border-width . 0) | |
366 (menu-bar-lines . 0) | |
367 (unsplittable . t)) | |
368 "*Parameters to use when creating the speedbar frame in Emacs. | |
369 Parameters not listed here which will be added automatically are | |
370 `height' which will be initialized to the height of the frame speedbar | |
371 is attached to." | |
372 :group 'speedbar | |
373 :type '(repeat (sexp :tag "Parameter:"))) | |
374 | |
375 ;; These values by Hrvoje Niksic <hniksic@srce.hr> | |
376 (defcustom speedbar-frame-plist | |
377 '(minibuffer nil width 20 border-width 0 | |
378 internal-border-width 0 unsplittable t | |
379 default-toolbar-visible-p nil has-modeline-p nil | |
380 menubar-visible-p nil | |
381 ;; I don't see the particular value of these three, but... | |
382 text-pointer-glyph [cursor-font :data "top_left_arrow"] | |
383 nontext-pointer-glyph [cursor-font :data "top_left_arrow"] | |
384 selection-pointer-glyph [cursor-font :data "hand2"]) | |
385 "*Parameters to use when creating the speedbar frame in XEmacs. | |
386 Parameters not listed here which will be added automatically are | |
387 `height' which will be initialized to the height of the frame speedbar | |
388 is attached to." | |
389 :group 'speedbar | |
390 :type '(repeat (group :inline t | |
391 (symbol :tag "Property") | |
392 (sexp :tag "Value")))) | |
393 | |
394 (defcustom speedbar-use-imenu-flag (stringp (locate-library "imenu")) | |
395 "*Non-nil means use imenu for file parsing. nil to use etags. | |
396 XEmacs prior to 20.4 doesn't support imenu, therefore the default is to | |
397 use etags instead. Etags support is not as robust as imenu support." | |
398 :tag "User Imenu" | |
399 :group 'speedbar | |
400 :type 'boolean) | |
401 | |
22735 | 402 (defcustom speedbar-track-mouse-flag t |
403 "*Non-nil means to display info about the line under the mouse." | |
404 :group 'speedbar | |
405 :type 'boolean) | |
406 | |
21650 | 407 (defcustom speedbar-sort-tags nil |
22735 | 408 "*If Non-nil, sort tags in the speedbar display. *Obsolete*." |
21650 | 409 :group 'speedbar |
410 :type 'boolean) | |
411 | |
22735 | 412 (defcustom speedbar-tag-hierarchy-method |
413 '(prefix-group trim-words) | |
414 "*List of methods which speedbar will use to organize tags into groups. | |
415 Groups are defined as expandable meta-tags. Imenu supports such | |
416 things in some languages, such as separating variables from functions. | |
417 Available methods are: | |
418 sort - Sort tags. (sometimes unnecessary) | |
419 trim-words - Trim all tags by a common prefix, broken @ word sections. | |
420 prefix-group - Try to guess groups by prefix. | |
421 simple-group - If imenu already returned some meta groups, stick all | |
422 tags that are not in a group into a sub-group." | |
423 :group 'speedbar | |
424 :type '(repeat | |
425 (radio | |
426 (const :tag "Sort the tags." sort) | |
427 (const :tag "Trim words to common prefix." trim-words) | |
428 (const :tag "Create groups from common prefixes." prefix-group) | |
429 (const :tag "Group loose tags into their own group." simple-group)) | |
430 )) | |
431 | |
432 (defcustom speedbar-tag-split-minimum-length 20 | |
433 "*Minimum length before we stop trying to create sub-lists in tags. | |
434 This is used by all tag-hierarchy methods that break large lists into | |
435 sub-lists." | |
436 :group 'speedbar | |
437 :type 'integer) | |
438 | |
439 (defcustom speedbar-tag-regroup-maximum-length 10 | |
440 "*Maximum length of submenus that are regrouped. | |
441 If the regrouping option is used, then if two or more short subgroups | |
442 are next to each other, then they are combined until this number of | |
443 items is reached." | |
444 :group 'speedbar | |
445 :type 'integer) | |
446 | |
21650 | 447 (defcustom speedbar-activity-change-focus-flag nil |
448 "*Non-nil means the selected frame will change based on activity. | |
449 Thus, if a file is selected for edit, the buffer will appear in the | |
450 selected frame and the focus will change to that frame." | |
451 :group 'speedbar | |
452 :type 'boolean) | |
453 | |
454 (defcustom speedbar-directory-button-trim-method 'span | |
455 "*Indicates how the directory button will be displayed. | |
456 Possible values are: | |
457 'span - span large directories over multiple lines. | |
458 'trim - trim large directories to only show the last few. | |
459 nil - no trimming." | |
460 :group 'speedbar | |
461 :type '(radio (const :tag "Span large directories over mutiple lines." | |
462 span) | |
463 (const :tag "Trim large directories to only show the last few." | |
464 trim) | |
465 (const :tag "No trimming." nil))) | |
466 | |
467 (defcustom speedbar-smart-directory-expand-flag t | |
468 "*Non-nil means speedbar should use smart expansion. | |
469 Smart expansion only affects when speedbar wants to display a | |
470 directory for a file in the attached frame. When smart expansion is | |
471 enabled, new directories which are children of a displayed directory | |
472 are expanded in the current framework. If nil, then the current | |
473 hierarchy would be replaced with the new directory." | |
474 :group 'speedbar | |
475 :type 'boolean) | |
476 | |
22735 | 477 (defvar speedbar-hide-button-brackets-flag nil |
478 "*Non-nil means speedbar will hide the brackets around the + or -.") | |
479 | |
21650 | 480 (defcustom speedbar-before-popup-hook nil |
481 "*Hooks called before popping up the speedbar frame." | |
482 :group 'speedbar | |
483 :type 'hook) | |
484 | |
485 (defcustom speedbar-before-delete-hook nil | |
486 "*Hooks called before deleting the speedbar frame." | |
487 :group 'speedbar | |
488 :type 'hook) | |
489 | |
490 (defcustom speedbar-mode-hook nil | |
491 "*Hooks called after creating a speedbar buffer." | |
492 :group 'speedbar | |
493 :type 'hook) | |
494 | |
495 (defcustom speedbar-timer-hook nil | |
496 "*Hooks called after running the speedbar timer function." | |
497 :group 'speedbar | |
498 :type 'hook) | |
499 | |
500 (defcustom speedbar-verbosity-level 1 | |
501 "*Verbosity level of the speedbar. 0 means say nothing. | |
502 1 means medium level verbosity. 2 and higher are higher levels of | |
503 verbosity." | |
504 :group 'speedbar | |
505 :type 'integer) | |
506 | |
22735 | 507 (defvar speedbar-indicator-separator " " |
508 "String separating file text from indicator characters.") | |
509 | |
21650 | 510 (defcustom speedbar-vc-do-check t |
511 "*Non-nil check all files in speedbar to see if they have been checked out. | |
512 Any file checked out is marked with `speedbar-vc-indicator'" | |
513 :group 'speedbar-vc | |
514 :type 'boolean) | |
515 | |
22735 | 516 (defvar speedbar-vc-indicator "*" |
21650 | 517 "Text used to mark files which are currently checked out. |
518 Currently only RCS is supported. Other version control systems can be | |
519 added by examining the function `speedbar-this-file-in-vc' and | |
520 `speedbar-vc-check-dir-p'") | |
521 | |
522 (defcustom speedbar-vc-path-enable-hook nil | |
523 "*Return non-nil if the current path should be checked for Version Control. | |
524 Functions in this hook must accept one parameter which is the path | |
525 being checked." | |
526 :group 'speedbar-vc | |
527 :type 'hook) | |
528 | |
529 (defcustom speedbar-vc-in-control-hook nil | |
530 "*Return non-nil if the specified file is under Version Control. | |
531 Functions in this hook must accept two parameters. The PATH of the | |
532 current file, and the FILENAME of the file being checked." | |
533 :group 'speedbar-vc | |
534 :type 'hook) | |
535 | |
536 (defvar speedbar-vc-to-do-point nil | |
537 "Local variable maintaining the current version control check position.") | |
538 | |
22735 | 539 (defcustom speedbar-obj-do-check t |
540 "*Non-nil check all files in speedbar to see if they have an object file. | |
541 Any file checked out is marked with `speedbar-obj-indicator', and the | |
542 marking is based on `speedbar-obj-alist'" | |
543 :group 'speedbar-vc | |
544 :type 'boolean) | |
545 | |
546 (defvar speedbar-obj-to-do-point nil | |
547 "Local variable maintaining the current version control check position.") | |
548 | |
549 (defvar speedbar-obj-indicator '("#" . "!") | |
550 "Text used to mark files that have a corresponding hidden object file. | |
551 The car is for an up-to-date object. The cdr is for an out of date object. | |
552 The expression `speedbar-obj-alist' defines who gets tagged.") | |
553 | |
554 (defvar speedbar-obj-alist | |
555 '(("\\.\\([cpC]\\|cpp\\|cc\\)$" . ".o") | |
556 ("\\.el$" . ".elc") | |
557 ("\\.java$" . ".class") | |
558 ("\\.f\\(or\\|90\\|77\\)?$" . ".o") | |
559 ("\\.tex$" . ".dvi") | |
560 ("\\.texi$" . ".info")) | |
561 "Alist of file extensions, and their corresponding object file type.") | |
562 | |
563 (defvar speedbar-indicator-regex | |
564 (concat (regexp-quote speedbar-indicator-separator) | |
565 "\\(" | |
566 (regexp-quote speedbar-vc-indicator) | |
567 "\\|" | |
568 (regexp-quote (car speedbar-obj-indicator)) | |
569 "\\|" | |
570 (regexp-quote (cdr speedbar-obj-indicator)) | |
571 "\\)*") | |
572 "Regular expression used when identifying files. | |
573 Permits stripping of indicator characters from a line.") | |
574 | |
575 (defcustom speedbar-scanner-reset-hook nil | |
576 "*Hook called whenever generic scanners are reset. | |
577 Set this to implement your own scanning / rescan safe functions with | |
578 state data." | |
579 :group 'speedbar | |
580 :type 'hook) | |
581 | |
21650 | 582 (defvar speedbar-ignored-modes nil |
583 "*List of major modes which speedbar will not switch directories for.") | |
584 | |
585 (defun speedbar-extension-list-to-regex (extlist) | |
586 "Takes EXTLIST, a list of extensions and transforms it into regexp. | |
22735 | 587 All the preceding `.' are stripped for an optimized expression starting |
588 with `.' followed by extensions, followed by full-filenames." | |
21650 | 589 (let ((regex1 nil) (regex2 nil)) |
590 (while extlist | |
591 (if (= (string-to-char (car extlist)) ?.) | |
592 (setq regex1 (concat regex1 (if regex1 "\\|" "") | |
593 (substring (car extlist) 1))) | |
594 (setq regex2 (concat regex2 (if regex2 "\\|" "") (car extlist)))) | |
595 (setq extlist (cdr extlist))) | |
596 ;; concat all the sub-exressions together, making sure all types | |
597 ;; of parts exist during concatination. | |
598 (concat "\\(" | |
599 (if regex1 (concat "\\(\\.\\(" regex1 "\\)\\)") "") | |
600 (if (and regex1 regex2) "\\|" "") | |
601 (if regex2 (concat "\\(" regex2 "\\)") "") | |
602 "\\)$"))) | |
603 | |
604 (defvar speedbar-ignored-path-regexp nil | |
605 "Regular expression matching paths speedbar will not switch to. | |
606 Created from `speedbar-ignored-path-expressions' with the function | |
607 `speedbar-extension-list-to-regex' (A misnamed function in this case.) | |
608 Use the function `speedbar-add-ignored-path-regexp', or customize the | |
609 variable `speedbar-ignored-path-expressions' to modify this variable.") | |
610 | |
611 (defcustom speedbar-ignored-path-expressions | |
612 '("/logs?/\\'") | |
613 "*List of regular expressions matching directories speedbar will ignore. | |
614 They should included paths to directories which are notoriously very | |
615 large and take a long time to load in. Use the function | |
616 `speedbar-add-ignored-path-regexp' to add new items to this list after | |
617 speedbar is loaded. You may place anything you like in this list | |
618 before speedbar has been loaded." | |
619 :group 'speedbar | |
620 :type '(repeat (regexp :tag "Path Regexp")) | |
621 :set (lambda (sym val) | |
622 (setq speedbar-ignored-path-expressions val | |
623 speedbar-ignored-path-regexp | |
624 (speedbar-extension-list-to-regex val)))) | |
625 | |
22735 | 626 (defcustom speedbar-directory-unshown-regexp "^\\(CVS\\|RCS\\|SCCS\\)\\'" |
627 "*Regular expression matching directories not to show in speedbar. | |
628 They should include commonly existing directories which are not | |
629 useful, such as version control." | |
630 :group 'speedbar | |
631 :type 'string) | |
632 | |
21650 | 633 (defvar speedbar-file-unshown-regexp |
634 (let ((nstr "") (noext completion-ignored-extensions)) | |
635 (while noext | |
636 (setq nstr (concat nstr (regexp-quote (car noext)) "\\'" | |
637 (if (cdr noext) "\\|" "")) | |
638 noext (cdr noext))) | |
23073
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
639 ;; backup refdir lockfile |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
640 (concat nstr "\\|#[^#]+#$\\|\\.\\.?\\'\\|\\.#")) |
21650 | 641 "*Regexp matching files we don't want displayed in a speedbar buffer. |
642 It is generated from the variable `completion-ignored-extensions'") | |
643 | |
644 ;; this is dangerous to customize, because the defaults will probably | |
645 ;; change in the future. | |
646 (defcustom speedbar-supported-extension-expressions | |
22735 | 647 (append '(".[ch]\\(\\+\\+\\|pp\\|c\\|h\\|xx\\)?" ".tex\\(i\\(nfo\\)?\\)?" |
648 ".el" ".emacs" ".l" ".lsp" ".p" ".java" ".f\\(90\\|77\\|or\\)?") | |
21650 | 649 (if speedbar-use-imenu-flag |
22735 | 650 '(".ada" ".pl" ".tcl" ".m" ".scm" ".pm" ".py" |
651 ;; html is not supported by default, but an imenu tags package | |
652 ;; is available. Also, html files are nice to be able to see. | |
653 ".s?html" | |
21650 | 654 "Makefile\\(\\.in\\)?"))) |
655 "*List of regular expressions which will match files supported by tagging. | |
656 Do not prefix the `.' char with a double \\ to quote it, as the period | |
657 will be stripped by a simplified optimizer when compiled into a | |
658 singular expression. This variable will be turned into | |
659 `speedbar-file-regexp' for use with speedbar. You should use the | |
660 function `speedbar-add-supported-extension' to add a new extension at | |
661 runtime, or use the configuration dialog to set it in your .emacs | |
662 file." | |
663 :group 'speedbar | |
664 :type '(repeat (regexp :tag "Extension Regexp")) | |
665 :set (lambda (sym val) | |
666 (setq speedbar-supported-extension-expressions val | |
667 speedbar-file-regexp (speedbar-extension-list-to-regex val))) | |
668 ) | |
669 | |
670 (defvar speedbar-file-regexp | |
671 (speedbar-extension-list-to-regex speedbar-supported-extension-expressions) | |
672 "Regular expression matching files we know how to expand. | |
673 Created from `speedbar-supported-extension-expression' with the | |
674 function `speedbar-extension-list-to-regex'") | |
675 | |
676 (defun speedbar-add-supported-extension (extension) | |
677 "Add EXTENSION as a new supported extension for speedbar tagging. | |
678 This should start with a `.' if it is not a complete file name, and | |
679 the dot should NOT be quoted in with \\. Other regular expression | |
680 matchers are allowed however. EXTENSION may be a single string or a | |
681 list of strings." | |
22735 | 682 (interactive "sExtionsion: ") |
21650 | 683 (if (not (listp extension)) (setq extension (list extension))) |
684 (while extension | |
685 (if (member (car extension) speedbar-supported-extension-expressions) | |
686 nil | |
687 (setq speedbar-supported-extension-expressions | |
688 (cons (car extension) speedbar-supported-extension-expressions))) | |
689 (setq extension (cdr extension))) | |
690 (setq speedbar-file-regexp (speedbar-extension-list-to-regex | |
691 speedbar-supported-extension-expressions))) | |
692 | |
693 (defun speedbar-add-ignored-path-regexp (path-expression) | |
694 "Add PATH-EXPRESSION as a new ignored path for speedbar tracking. | |
695 This function will modify `speedbar-ignored-path-regexp' and add | |
696 PATH-EXPRESSION to `speedbar-ignored-path-expressions'." | |
22735 | 697 (interactive "sPath regex: ") |
21650 | 698 (if (not (listp path-expression)) |
699 (setq path-expression (list path-expression))) | |
700 (while path-expression | |
701 (if (member (car path-expression) speedbar-ignored-path-expressions) | |
702 nil | |
703 (setq speedbar-ignored-path-expressions | |
704 (cons (car path-expression) speedbar-ignored-path-expressions))) | |
705 (setq path-expression (cdr path-expression))) | |
706 (setq speedbar-ignored-path-regexp (speedbar-extension-list-to-regex | |
707 speedbar-ignored-path-expressions))) | |
708 | |
709 ;; If we don't have custom, then we set it here by hand. | |
710 (if (not (fboundp 'custom-declare-variable)) | |
711 (setq speedbar-file-regexp (speedbar-extension-list-to-regex | |
712 speedbar-supported-extension-expressions) | |
713 speedbar-ignored-path-regexp (speedbar-extension-list-to-regex | |
714 speedbar-ignored-path-expressions))) | |
715 | |
22735 | 716 (defvar speedbar-update-flag (and |
717 (or (fboundp 'run-with-idle-timer) | |
718 (fboundp 'start-itimer) | |
719 (boundp 'post-command-idle-hook)) | |
720 window-system) | |
21650 | 721 "*Non-nil means to automatically update the display. |
722 When this is nil then speedbar will not follow the attached frame's path. | |
723 When speedbar is active, use: | |
724 | |
725 \\<speedbar-key-map> `\\[speedbar-toggle-updates]' | |
726 | |
727 to toggle this value.") | |
728 | |
729 (defvar speedbar-syntax-table nil | |
730 "Syntax-table used on the speedbar.") | |
731 | |
732 (if speedbar-syntax-table | |
733 nil | |
734 (setq speedbar-syntax-table (make-syntax-table)) | |
735 ;; turn off paren matching around here. | |
736 (modify-syntax-entry ?\' " " speedbar-syntax-table) | |
737 (modify-syntax-entry ?\" " " speedbar-syntax-table) | |
738 (modify-syntax-entry ?( " " speedbar-syntax-table) | |
739 (modify-syntax-entry ?) " " speedbar-syntax-table) | |
740 (modify-syntax-entry ?[ " " speedbar-syntax-table) | |
741 (modify-syntax-entry ?] " " speedbar-syntax-table)) | |
742 | |
743 (defvar speedbar-key-map nil | |
744 "Keymap used in speedbar buffer.") | |
745 | |
746 (if speedbar-key-map | |
747 nil | |
748 (setq speedbar-key-map (make-keymap)) | |
749 (suppress-keymap speedbar-key-map t) | |
750 | |
751 ;; control | |
752 (define-key speedbar-key-map "g" 'speedbar-refresh) | |
753 (define-key speedbar-key-map "t" 'speedbar-toggle-updates) | |
754 (define-key speedbar-key-map "q" 'speedbar-close-frame) | |
23080
8b7bb810f362
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
23073
diff
changeset
|
755 (define-key speedbar-key-map "Q" 'delete-frame) |
21650 | 756 |
757 ;; navigation | |
758 (define-key speedbar-key-map "n" 'speedbar-next) | |
759 (define-key speedbar-key-map "p" 'speedbar-prev) | |
22735 | 760 (define-key speedbar-key-map "\M-n" 'speedbar-restricted-next) |
761 (define-key speedbar-key-map "\M-p" 'speedbar-restricted-prev) | |
762 (define-key speedbar-key-map "\C-\M-n" 'speedbar-forward-list) | |
763 (define-key speedbar-key-map "\C-\M-p" 'speedbar-backward-list) | |
21650 | 764 (define-key speedbar-key-map " " 'speedbar-scroll-up) |
765 (define-key speedbar-key-map [delete] 'speedbar-scroll-down) | |
766 | |
22735 | 767 ;; Short cuts I happen to find useful |
768 (define-key speedbar-key-map "r" | |
769 (lambda () (interactive) | |
770 (speedbar-change-initial-expansion-list | |
771 speedbar-previously-used-expansion-list-name))) | |
772 (define-key speedbar-key-map "b" | |
773 (lambda () (interactive) | |
774 (speedbar-change-initial-expansion-list "quick buffers"))) | |
775 (define-key speedbar-key-map "f" | |
776 (lambda () (interactive) | |
777 (speedbar-change-initial-expansion-list "files"))) | |
778 | |
779 ;; Overrides | |
780 (substitute-key-definition 'switch-to-buffer | |
781 'speedbar-switch-buffer-attached-frame | |
782 speedbar-key-map global-map) | |
21650 | 783 |
784 (if speedbar-xemacsp | |
785 (progn | |
786 ;; mouse bindings so we can manipulate the items on each line | |
787 (define-key speedbar-key-map 'button2 'speedbar-click) | |
788 (define-key speedbar-key-map '(shift button2) 'speedbar-power-click) | |
22735 | 789 ;; Info doc fix from Bob Weiner |
790 (if (featurep 'infodoc) | |
791 nil | |
792 (define-key speedbar-key-map 'button3 'speedbar-xemacs-popup-kludge)) | |
793 (define-key speedbar-key-map '(meta button3) 'speedbar-mouse-item-info) | |
794 ) | |
795 | |
21650 | 796 ;; mouse bindings so we can manipulate the items on each line |
797 (define-key speedbar-key-map [down-mouse-1] 'speedbar-double-click) | |
798 (define-key speedbar-key-map [mouse-2] 'speedbar-click) | |
799 ;; This is the power click for new frames, or refreshing a cache | |
800 (define-key speedbar-key-map [S-mouse-2] 'speedbar-power-click) | |
801 ;; This adds a small unecessary visual effect | |
802 ;;(define-key speedbar-key-map [down-mouse-2] 'speedbar-quick-mouse) | |
803 (define-key speedbar-key-map [M-mouse-2] 'speedbar-mouse-item-info) | |
804 | |
805 (define-key speedbar-key-map [down-mouse-3] 'speedbar-emacs-popup-kludge) | |
806 | |
807 ;; This lets the user scroll as if we had a scrollbar... well maybe not | |
808 (define-key speedbar-key-map [mode-line mouse-2] 'speedbar-mouse-hscroll) | |
22735 | 809 ;; another handy place users might click to get our menu. |
810 (define-key speedbar-key-map [mode-line down-mouse-1] | |
811 'speedbar-emacs-popup-kludge) | |
812 | |
22893
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
813 ;; We can't switch buffers with the buffer mouse menu. Lets hack it. |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
814 (define-key speedbar-key-map [C-down-mouse-1] 'speedbar-hack-buffer-menu) |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
815 |
22735 | 816 ;; Lastly, we want to track the mouse. Play here |
817 (define-key speedbar-key-map [mouse-movement] 'speedbar-track-mouse) | |
818 )) | |
819 | |
820 (defun speedbar-make-specialized-keymap () | |
821 "Create a keymap for use w/ a speedbar major or minor display mode. | |
822 This basically creates a sparse keymap, and makes it's parent be | |
823 `speedbar-key-map'." | |
824 (let ((k (make-sparse-keymap))) | |
825 (set-keymap-parent k speedbar-key-map) | |
826 k)) | |
827 | |
828 (defvar speedbar-file-key-map nil | |
829 "Keymap used in speedbar buffer while files are displayed.") | |
830 | |
831 (if speedbar-file-key-map | |
832 nil | |
833 (setq speedbar-file-key-map (speedbar-make-specialized-keymap)) | |
834 | |
835 ;; Basic tree features | |
836 (define-key speedbar-file-key-map "e" 'speedbar-edit-line) | |
837 (define-key speedbar-file-key-map "\C-m" 'speedbar-edit-line) | |
838 (define-key speedbar-file-key-map "+" 'speedbar-expand-line) | |
839 (define-key speedbar-file-key-map "-" 'speedbar-contract-line) | |
840 | |
841 ;; file based commands | |
842 (define-key speedbar-file-key-map "U" 'speedbar-up-directory) | |
843 (define-key speedbar-file-key-map "I" 'speedbar-item-info) | |
844 (define-key speedbar-file-key-map "B" 'speedbar-item-byte-compile) | |
845 (define-key speedbar-file-key-map "L" 'speedbar-item-load) | |
846 (define-key speedbar-file-key-map "C" 'speedbar-item-copy) | |
847 (define-key speedbar-file-key-map "D" 'speedbar-item-delete) | |
848 (define-key speedbar-file-key-map "O" 'speedbar-item-object-delete) | |
849 (define-key speedbar-file-key-map "R" 'speedbar-item-rename) | |
850 ) | |
21650 | 851 |
852 (defvar speedbar-easymenu-definition-base | |
853 '("Speedbar" | |
854 ["Update" speedbar-refresh t] | |
855 ["Auto Update" speedbar-toggle-updates | |
856 :style toggle :selected speedbar-update-flag] | |
857 ) | |
858 "Base part of the speedbar menu.") | |
859 | |
860 (defvar speedbar-easymenu-definition-special | |
861 '(["Edit Item On Line" speedbar-edit-line t] | |
862 ["Show All Files" speedbar-toggle-show-all-files | |
863 :style toggle :selected speedbar-show-unknown-files] | |
22735 | 864 ["Expand File Tags" speedbar-expand-line |
21650 | 865 (save-excursion (beginning-of-line) |
866 (looking-at "[0-9]+: *.\\+. "))] | |
22735 | 867 ["Contract File Tags" speedbar-contract-line |
21650 | 868 (save-excursion (beginning-of-line) |
869 (looking-at "[0-9]+: *.-. "))] | |
22735 | 870 ; ["Sort Tags" speedbar-toggle-sorting |
871 ; :style toggle :selected speedbar-sort-tags] | |
21650 | 872 "----" |
22735 | 873 ["File/Tag Information" speedbar-item-info t] |
21650 | 874 ["Load Lisp File" speedbar-item-load |
875 (save-excursion | |
876 (beginning-of-line) | |
22735 | 877 (looking-at "[0-9]+: *\\[[+-]\\] .+\\(\\.el\\)\\( \\|$\\)"))] |
21650 | 878 ["Byte Compile File" speedbar-item-byte-compile |
879 (save-excursion | |
880 (beginning-of-line) | |
22735 | 881 (looking-at "[0-9]+: *\\[[+-]\\] .+\\(\\.el\\)\\( \\|$\\)"))] |
882 ["Copy File" speedbar-item-copy | |
21650 | 883 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *\\["))] |
22735 | 884 ["Rename File" speedbar-item-rename |
885 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))] | |
886 ["Delete File" speedbar-item-delete | |
21650 | 887 (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))] |
22735 | 888 ["Delete Object" speedbar-item-object-delete |
889 (save-excursion (beginning-of-line) | |
890 (looking-at "[0-9]+: *\\[[+-]\\] [^ \n]+ \\*?[!#]$"))] | |
891 ) | |
21650 | 892 "Additional menu items while in file-mode.") |
893 | |
894 (defvar speedbar-easymenu-definition-trailer | |
22735 | 895 (list |
896 (if (and (featurep 'custom) (fboundp 'custom-declare-variable)) | |
897 ["Customize..." speedbar-customize t]) | |
23073
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
898 ["Close" speedbar-close-frame t] |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
899 ["Quit" delete-frame t] ) |
21650 | 900 "Menu items appearing at the end of the speedbar menu.") |
901 | |
902 (defvar speedbar-desired-buffer nil | |
903 "Non-nil when speedbar is showing buttons specific a special mode. | |
904 In this case it is the originating buffer.") | |
905 (defvar speedbar-buffer nil | |
906 "The buffer displaying the speedbar.") | |
907 (defvar speedbar-frame nil | |
908 "The frame displaying speedbar.") | |
909 (defvar speedbar-cached-frame nil | |
910 "The frame that was last created, then removed from the display.") | |
911 (defvar speedbar-full-text-cache nil | |
912 "The last open directory is saved in its entirety for ultra-fast switching.") | |
913 (defvar speedbar-timer nil | |
914 "The speedbar timer used for updating the buffer.") | |
915 (defvar speedbar-attached-frame nil | |
916 "The frame which started speedbar mode. | |
917 This is the frame from which all data displayed in the speedbar is | |
918 gathered, and in which files and such are displayed.") | |
919 | |
920 (defvar speedbar-last-selected-file nil | |
921 "The last file which was selected in speedbar buffer.") | |
922 | |
923 (defvar speedbar-shown-directories nil | |
924 "Maintain list of directories simultaneously open in the current speedbar.") | |
925 | |
926 (defvar speedbar-directory-contents-alist nil | |
927 "An association list of directories and their contents. | |
928 Each sublist was returned by `speedbar-file-lists'. This list is | |
929 maintained to speed up the refresh rate when switching between | |
930 directories.") | |
931 | |
932 (defvar speedbar-power-click nil | |
933 "Never set this by hand. Value is t when S-mouse activity occurs.") | |
934 | |
935 | |
936 ;;; Mode definitions/ user commands | |
937 ;; | |
938 | |
939 ;;;###autoload | |
940 (defalias 'speedbar 'speedbar-frame-mode) | |
941 ;;;###autoload | |
942 (defun speedbar-frame-mode (&optional arg) | |
943 "Enable or disable speedbar. Positive ARG means turn on, negative turn off. | |
944 nil means toggle. Once the speedbar frame is activated, a buffer in | |
945 `speedbar-mode' will be displayed. Currently, only one speedbar is | |
946 supported at a time. | |
947 `speedbar-before-popup-hook' is called before popping up the speedbar frame. | |
948 `speedbar-before-delete-hook' is called before the frame is deleted." | |
949 (interactive "P") | |
950 ;; toggle frame on and off. | |
951 (if (not arg) (if (and (frame-live-p speedbar-frame) | |
952 (frame-visible-p speedbar-frame)) | |
953 (setq arg -1) (setq arg 1))) | |
954 ;; turn the frame off on neg number | |
955 (if (and (numberp arg) (< arg 0)) | |
956 (progn | |
957 (run-hooks 'speedbar-before-delete-hook) | |
958 (if (and speedbar-frame (frame-live-p speedbar-frame)) | |
959 (progn | |
960 (setq speedbar-cached-frame speedbar-frame) | |
961 (make-frame-invisible speedbar-frame))) | |
962 (setq speedbar-frame nil) | |
963 (speedbar-set-timer nil) | |
964 ;; Used to delete the buffer. This has the annoying affect of | |
965 ;; preventing whatever took its place from ever appearing | |
966 ;; as the default after a C-x b was typed | |
967 ;;(if (bufferp speedbar-buffer) | |
968 ;; (kill-buffer speedbar-buffer)) | |
969 ) | |
970 ;; Set this as our currently attached frame | |
971 (setq speedbar-attached-frame (selected-frame)) | |
972 (run-hooks 'speedbar-before-popup-hook) | |
973 ;; Get the frame to work in | |
974 (if (frame-live-p speedbar-cached-frame) | |
975 (progn | |
976 (setq speedbar-frame speedbar-cached-frame) | |
977 (make-frame-visible speedbar-frame) | |
978 ;; Get the buffer to play with | |
979 (speedbar-mode) | |
980 (select-frame speedbar-frame) | |
981 (if (not (eq (current-buffer) speedbar-buffer)) | |
982 (switch-to-buffer speedbar-buffer)) | |
983 (set-window-dedicated-p (selected-window) t) | |
984 (raise-frame speedbar-frame) | |
985 (speedbar-set-timer speedbar-update-speed) | |
986 ) | |
987 (if (frame-live-p speedbar-frame) | |
988 (raise-frame speedbar-frame) | |
989 (setq speedbar-frame | |
990 (if speedbar-xemacsp | |
991 (make-frame (nconc (list 'height | |
992 (speedbar-needed-height)) | |
993 speedbar-frame-plist)) | |
23073
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
994 (let* ((mh (frame-parameter nil 'menu-bar-lines)) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
995 (cfx (frame-parameter nil 'left)) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
996 (cfy (frame-parameter nil 'top)) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
997 (cfw (frame-pixel-width)) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
998 (params |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
999 (append |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
1000 speedbar-frame-parameters |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
1001 (list (cons 'height (+ mh (frame-height)))))) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
1002 (frame |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
1003 (if (or (< emacs-major-version 20) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
1004 (not (eq window-system 'x))) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
1005 (make-frame params) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
1006 (let ((x-pointer-shape x-pointer-top-left-arrow) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
1007 (x-sensitive-text-pointer-shape |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
1008 x-pointer-hand2)) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
1009 (make-frame params))))) |
23241
87bf8eb5c639
(speedbar-frame-mode): Only set the position on window systems.
Eric M. Ludlam <zappo@gnu.org>
parents:
23085
diff
changeset
|
1010 (if (and window-system (not (eq window-system 'pc))) |
87bf8eb5c639
(speedbar-frame-mode): Only set the position on window systems.
Eric M. Ludlam <zappo@gnu.org>
parents:
23085
diff
changeset
|
1011 (set-frame-position frame |
87bf8eb5c639
(speedbar-frame-mode): Only set the position on window systems.
Eric M. Ludlam <zappo@gnu.org>
parents:
23085
diff
changeset
|
1012 ;; Decide which side to put it |
87bf8eb5c639
(speedbar-frame-mode): Only set the position on window systems.
Eric M. Ludlam <zappo@gnu.org>
parents:
23085
diff
changeset
|
1013 ;; on. 200 is just a buffer |
87bf8eb5c639
(speedbar-frame-mode): Only set the position on window systems.
Eric M. Ludlam <zappo@gnu.org>
parents:
23085
diff
changeset
|
1014 ;; for the left edge of the |
87bf8eb5c639
(speedbar-frame-mode): Only set the position on window systems.
Eric M. Ludlam <zappo@gnu.org>
parents:
23085
diff
changeset
|
1015 ;; screen. The extra 10 is just |
87bf8eb5c639
(speedbar-frame-mode): Only set the position on window systems.
Eric M. Ludlam <zappo@gnu.org>
parents:
23085
diff
changeset
|
1016 ;; dressings for window decorations. |
87bf8eb5c639
(speedbar-frame-mode): Only set the position on window systems.
Eric M. Ludlam <zappo@gnu.org>
parents:
23085
diff
changeset
|
1017 (if (< cfx 200) |
87bf8eb5c639
(speedbar-frame-mode): Only set the position on window systems.
Eric M. Ludlam <zappo@gnu.org>
parents:
23085
diff
changeset
|
1018 (+ cfx cfw 10) |
87bf8eb5c639
(speedbar-frame-mode): Only set the position on window systems.
Eric M. Ludlam <zappo@gnu.org>
parents:
23085
diff
changeset
|
1019 (- cfx (frame-pixel-width frame) |
87bf8eb5c639
(speedbar-frame-mode): Only set the position on window systems.
Eric M. Ludlam <zappo@gnu.org>
parents:
23085
diff
changeset
|
1020 10)) |
87bf8eb5c639
(speedbar-frame-mode): Only set the position on window systems.
Eric M. Ludlam <zappo@gnu.org>
parents:
23085
diff
changeset
|
1021 cfy)) |
23073
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
1022 frame))) |
21650 | 1023 ;; reset the selection variable |
1024 (setq speedbar-last-selected-file nil) | |
1025 ;; Put the buffer into the frame | |
1026 (save-window-excursion | |
1027 ;; Get the buffer to play with | |
1028 (speedbar-mode) | |
1029 (select-frame speedbar-frame) | |
1030 (switch-to-buffer speedbar-buffer) | |
1031 (set-window-dedicated-p (selected-window) t)) | |
22893
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1032 (if (or (null window-system) (eq window-system 'pc)) |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1033 (progn |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1034 (select-frame speedbar-frame) |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1035 (set-frame-name "Speedbar"))) |
21650 | 1036 (speedbar-set-timer speedbar-update-speed))))) |
1037 | |
1038 ;;;###autoload | |
1039 (defun speedbar-get-focus () | |
1040 "Change frame focus to or from the speedbar frame. | |
1041 If the selected frame is not speedbar, then speedbar frame is | |
1042 selected. If the speedbar frame is active, then select the attached frame." | |
1043 (interactive) | |
1044 (if (eq (selected-frame) speedbar-frame) | |
1045 (if (frame-live-p speedbar-attached-frame) | |
1046 (select-frame speedbar-attached-frame)) | |
22735 | 1047 ;; If updates are off, then refresh the frame (they want it now...) |
1048 (if (not speedbar-update-flag) | |
1049 (let ((speedbar-update-flag t)) | |
1050 (speedbar-timer-fn))) | |
21650 | 1051 ;; make sure we have a frame |
1052 (if (not (frame-live-p speedbar-frame)) (speedbar-frame-mode 1)) | |
1053 ;; go there | |
22735 | 1054 (select-frame speedbar-frame) |
1055 ) | |
21650 | 1056 (other-frame 0)) |
1057 | |
1058 (defun speedbar-close-frame () | |
1059 "Turn off a currently active speedbar." | |
1060 (interactive) | |
1061 (speedbar-frame-mode -1) | |
1062 (select-frame speedbar-attached-frame) | |
1063 (other-frame 0)) | |
1064 | |
22735 | 1065 (defun speedbar-switch-buffer-attached-frame (&optional buffer) |
1066 "Switch to BUFFER in speedbar's attached frame, and raise that frame. | |
1067 This overrides the default behavior of `switch-to-buffer' which is | |
1068 broken because of the dedicated speedbar frame." | |
1069 (interactive) | |
1070 ;; Assume we are in the speedbar frame. | |
1071 (speedbar-get-focus) | |
1072 ;; Now switch buffers | |
1073 (if buffer | |
1074 (switch-to-buffer buffer) | |
1075 (call-interactively 'switch-to-buffer nil nil))) | |
1076 | |
21650 | 1077 (defmacro speedbar-frame-width () |
1078 "Return the width of the speedbar frame in characters. | |
1079 nil if it doesn't exist." | |
1080 '(frame-width speedbar-frame)) | |
1081 | |
1082 ;; XEmacs function only. | |
1083 (defun speedbar-needed-height (&optional frame) | |
1084 "The needed height for the tool bar FRAME (in characters)." | |
1085 (or frame (setq frame (selected-frame))) | |
1086 ;; The 1 is the missing modeline/minibuffer | |
1087 (+ 1 (/ (frame-pixel-height frame) | |
1088 (face-height 'default frame)))) | |
1089 | |
1090 (defun speedbar-mode () | |
1091 "Major mode for managing a display of directories and tags. | |
1092 \\<speedbar-key-map> | |
1093 The first line represents the default path of the speedbar frame. | |
1094 Each directory segment is a button which jumps speedbar's default | |
1095 directory to that path. Buttons are activated by clicking `\\[speedbar-click]'. | |
1096 In some situations using `\\[speedbar-power-click]' is a `power click' which will | |
1097 rescan cached items, or pop up new frames. | |
1098 | |
1099 Each line starting with <+> represents a directory. Click on the <+> | |
1100 to insert the directory listing into the current tree. Click on the | |
1101 <-> to retract that list. Click on the directory name to go to that | |
1102 directory as the default. | |
1103 | |
1104 Each line starting with [+] is a file. If the variable | |
1105 `speedbar-show-unknown-files' is t, the lines starting with [?] are | |
1106 files which don't have imenu support, but are not expressly ignored. | |
1107 Files are completely ignored if they match `speedbar-file-unshown-regexp' | |
1108 which is generated from `completion-ignored-extensions'. | |
1109 | |
1110 Files with a `*' character after their name are files checked out of a | |
1111 version control system. (currently only RCS is supported.) New | |
1112 version control systems can be added by examining the documentation | |
1113 for `speedbar-this-file-in-vc' and `speedbar-vc-check-dir-p' | |
1114 | |
22735 | 1115 Files with a `#' or `!' character after them are source files that |
1116 have an object file associated with them. The `!' indicates that the | |
1117 files is out of date. You can control what source/object associations | |
1118 exist through the variable `speedbar-obj-alist'. | |
1119 | |
21650 | 1120 Click on the [+] to display a list of tags from that file. Click on |
1121 the [-] to retract the list. Click on the file name to edit the file | |
1122 in the attached frame. | |
1123 | |
1124 If you open tags, you might find a node starting with {+}, which is a | |
1125 category of tags. Click the {+} to expand the category. Jump-able | |
1126 tags start with >. Click the name of the tag to go to that position | |
1127 in the selected file. | |
1128 | |
1129 \\{speedbar-key-map}" | |
1130 ;; NOT interactive | |
1131 (save-excursion | |
1132 (setq speedbar-buffer (set-buffer (get-buffer-create " SPEEDBAR"))) | |
1133 (kill-all-local-variables) | |
1134 (setq major-mode 'speedbar-mode) | |
1135 (setq mode-name "Speedbar") | |
1136 (set-syntax-table speedbar-syntax-table) | |
1137 (setq font-lock-keywords nil) ;; no font-locking please | |
1138 (setq truncate-lines t) | |
1139 (make-local-variable 'frame-title-format) | |
1140 (setq frame-title-format "Speedbar") | |
1141 ;; Set this up special just for the speedbar buffer | |
22735 | 1142 ;; Terminal minibuffer stuff does not require this. |
22893
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1143 (if (and window-system (not (eq window-system 'pc)) |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1144 (null default-minibuffer-frame)) |
21650 | 1145 (progn |
1146 (make-local-variable 'default-minibuffer-frame) | |
1147 (setq default-minibuffer-frame speedbar-attached-frame))) | |
22735 | 1148 ;; Correct use of `temp-buffer-show-function': Bob Weiner |
1149 (if (and (boundp 'temp-buffer-show-hook) | |
1150 (boundp 'temp-buffer-show-function)) | |
1151 (progn (make-local-variable 'temp-buffer-show-hook) | |
1152 (setq temp-buffer-show-hook temp-buffer-show-function))) | |
21650 | 1153 (make-local-variable 'temp-buffer-show-function) |
1154 (setq temp-buffer-show-function 'speedbar-temp-buffer-show-function) | |
1155 (if speedbar-xemacsp | |
1156 (progn | |
1157 ;; Argh! mouse-track-click-hook doesn't understand the | |
1158 ;; make-local-hook conventions. | |
1159 (make-local-variable 'mouse-track-click-hook) | |
1160 (add-hook 'mouse-track-click-hook | |
1161 (lambda (event count) | |
1162 (if (/= (event-button event) 1) | |
1163 nil ; Do normal operations. | |
1164 (cond ((eq count 1) | |
1165 (speedbar-quick-mouse event)) | |
1166 ((or (eq count 2) | |
1167 (eq count 3)) | |
1168 (mouse-set-point event) | |
1169 (speedbar-do-function-pointer) | |
1170 (speedbar-quick-mouse event))) | |
1171 ;; Don't do normal operations. | |
1172 t))))) | |
1173 (make-local-hook 'kill-buffer-hook) | |
1174 (add-hook 'kill-buffer-hook (lambda () (let ((skilling (boundp 'skilling))) | |
1175 (if skilling | |
1176 nil | |
1177 (if (eq (current-buffer) | |
1178 speedbar-buffer) | |
1179 (speedbar-frame-mode -1))))) | |
1180 t t) | |
23083
2dea437fe88a
(speedbar-with-writable): remove `toggle-read-only'.
Eric M. Ludlam <zappo@gnu.org>
parents:
23080
diff
changeset
|
1181 (toggle-read-only 1) |
21650 | 1182 (speedbar-set-mode-line-format) |
22735 | 1183 (if speedbar-xemacsp |
1184 (progn | |
1185 (make-local-variable 'mouse-motion-handler) | |
1186 (setq mouse-motion-handler 'speedbar-track-mouse-xemacs)) | |
1187 (if speedbar-track-mouse-flag | |
1188 (progn | |
1189 (make-local-variable 'track-mouse) | |
1190 (setq track-mouse t))) ;this could be messy. | |
1191 (setq auto-show-mode nil)) ;no auto-show for Emacs | |
21650 | 1192 (run-hooks 'speedbar-mode-hook)) |
1193 (speedbar-update-contents) | |
1194 speedbar-buffer) | |
1195 | |
22735 | 1196 (defun speedbar-show-info-under-mouse (&optional event) |
1197 "Call the info function for the line under the mouse. | |
1198 Optional EVENT is currently not used." | |
1199 (let ((pos (mouse-position))) ; we ignore event until I use it later. | |
1200 (if (equal (car pos) speedbar-frame) | |
1201 (save-excursion | |
1202 (save-window-excursion | |
1203 (apply 'set-mouse-position pos) | |
1204 (speedbar-item-info)))))) | |
1205 | |
21650 | 1206 (defun speedbar-set-mode-line-format () |
1207 "Set the format of the mode line based on the current speedbar environment. | |
1208 This gives visual indications of what is up. It EXPECTS the speedbar | |
1209 frame and window to be the currently active frame and window." | |
1210 (if (and (frame-live-p speedbar-frame) | |
1211 (or (not speedbar-xemacsp) | |
1212 (specifier-instance has-modeline-p))) | |
1213 (save-excursion | |
1214 (set-buffer speedbar-buffer) | |
1215 (let* ((w (or (speedbar-frame-width) 20)) | |
1216 (p1 "<<") | |
1217 (p5 ">>") | |
1218 (p3 (if speedbar-update-flag "SPEEDBAR" "SLOWBAR")) | |
1219 (blank (- w (length p1) (length p3) (length p5) | |
1220 (if line-number-mode 4 0))) | |
1221 (p2 (if (> blank 0) | |
1222 (make-string (/ blank 2) ? ) | |
1223 "")) | |
1224 (p4 (if (> blank 0) | |
1225 (make-string (+ (/ blank 2) (% blank 2)) ? ) | |
1226 "")) | |
1227 (tf | |
1228 (if line-number-mode | |
1229 (list (concat p1 p2 p3) '(line-number-mode " %3l") | |
1230 (concat p4 p5)) | |
1231 (list (concat p1 p2 p3 p4 p5))))) | |
1232 (if (not (equal mode-line-format tf)) | |
1233 (progn | |
1234 (setq mode-line-format tf) | |
1235 (force-mode-line-update))))))) | |
1236 | |
1237 (defun speedbar-temp-buffer-show-function (buffer) | |
1238 "Placed in the variable `temp-buffer-show-function' in `speedbar-mode'. | |
1239 If a user requests help using \\[help-command] <Key> the temp BUFFER will be | |
1240 redirected into a window on the attached frame." | |
1241 (if speedbar-attached-frame (select-frame speedbar-attached-frame)) | |
1242 (pop-to-buffer buffer nil) | |
1243 (other-window -1) | |
23084
e1613f1c52f8
(speedbar-temp-buffer-show-function): For emacs don't call hook
Eric M. Ludlam <zappo@gnu.org>
parents:
23083
diff
changeset
|
1244 ;; Fix for using this hook on some platforms: Bob Weiner |
e1613f1c52f8
(speedbar-temp-buffer-show-function): For emacs don't call hook
Eric M. Ludlam <zappo@gnu.org>
parents:
23083
diff
changeset
|
1245 (cond ((not speedbar-xemacsp) |
e1613f1c52f8
(speedbar-temp-buffer-show-function): For emacs don't call hook
Eric M. Ludlam <zappo@gnu.org>
parents:
23083
diff
changeset
|
1246 (run-hooks 'temp-buffer-show-hook)) |
e1613f1c52f8
(speedbar-temp-buffer-show-function): For emacs don't call hook
Eric M. Ludlam <zappo@gnu.org>
parents:
23083
diff
changeset
|
1247 ((fboundp 'run-hook-with-args) |
22735 | 1248 (run-hook-with-args 'temp-buffer-show-hook buffer)) |
1249 ((and (boundp 'temp-buffer-show-hook) | |
1250 (listp temp-buffer-show-hook)) | |
1251 (mapcar (function (lambda (hook) (funcall hook buffer))) | |
1252 temp-buffer-show-hook)))) | |
21650 | 1253 |
22893
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1254 (defvar speedbar-previous-menu nil |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1255 "The menu before the last `speedbar-reconfigure-keymaps' was called.") |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1256 |
22735 | 1257 (defun speedbar-reconfigure-keymaps () |
21650 | 1258 "Reconfigure the menu-bar in a speedbar frame. |
1259 Different menu items are displayed depending on the current display mode | |
1260 and the existence of packages." | |
22735 | 1261 (let ((md (append |
1262 speedbar-easymenu-definition-base | |
1263 (if speedbar-shown-directories | |
1264 ;; file display mode version | |
1265 (speedbar-initial-menu) | |
1266 (save-excursion | |
1267 (select-frame speedbar-attached-frame) | |
1268 (if (local-variable-p | |
1269 'speedbar-easymenu-definition-special | |
1270 (current-buffer)) | |
1271 ;; If bound locally, we can use it | |
1272 speedbar-easymenu-definition-special))) | |
1273 ;; Dynamic menu stuff | |
1274 '("-") | |
1275 (list (cons "Displays" | |
1276 (let ((displays nil) | |
1277 (alist speedbar-initial-expansion-mode-alist)) | |
1278 (while alist | |
1279 (setq displays | |
1280 (cons | |
1281 (vector | |
1282 (capitalize (car (car alist))) | |
1283 (list | |
1284 'speedbar-change-initial-expansion-list | |
1285 (car (car alist))) | |
1286 t) | |
1287 displays)) | |
1288 (setq alist (cdr alist))) | |
1289 displays))) | |
1290 ;; The trailer | |
1291 speedbar-easymenu-definition-trailer)) | |
1292 (localmap (save-excursion | |
1293 (let ((cf (selected-frame))) | |
1294 (prog2 | |
1295 (select-frame speedbar-attached-frame) | |
1296 (if (local-variable-p | |
1297 'speedbar-special-mode-key-map | |
1298 (current-buffer)) | |
1299 speedbar-special-mode-key-map) | |
1300 (select-frame cf)))))) | |
1301 (save-excursion | |
1302 (set-buffer speedbar-buffer) | |
1303 (use-local-map (or localmap | |
1304 (speedbar-initial-keymap) | |
1305 ;; This creates a small keymap we can glom the | |
1306 ;; menu adjustments into. | |
1307 (speedbar-make-specialized-keymap))) | |
22893
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1308 ;; Delete the old menu if applicable. |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1309 (if speedbar-previous-menu (easy-menu-remove speedbar-previous-menu)) |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1310 (setq speedbar-previous-menu md) |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1311 ;; Now add the new menu |
22735 | 1312 (if (not speedbar-xemacsp) |
1313 (easy-menu-define speedbar-menu-map (current-local-map) | |
1314 "Speedbar menu" md) | |
22893
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1315 (easy-menu-add md (current-local-map)) |
22735 | 1316 (set-buffer-menubar (list md)))))) |
21650 | 1317 |
1318 | |
1319 ;;; User Input stuff | |
1320 ;; | |
1321 | |
1322 ;; XEmacs: this can be implemented using modeline keymaps, but there | |
1323 ;; is no use, as we have horizontal scrollbar (as the docstring | |
1324 ;; hints.) | |
1325 (defun speedbar-mouse-hscroll (e) | |
1326 "Read a mouse event E from the mode line, and horizontally scroll. | |
1327 If the mouse is being clicked on the far left, or far right of the | |
1328 mode-line. This is only useful for non-XEmacs" | |
1329 (interactive "e") | |
1330 (let* ((xp (car (nth 2 (car (cdr e))))) | |
1331 (cpw (/ (frame-pixel-width) | |
1332 (frame-width))) | |
1333 (oc (1+ (/ xp cpw))) | |
1334 ) | |
1335 (cond ((< oc 3) | |
1336 (scroll-left 2)) | |
1337 ((> oc (- (window-width) 3)) | |
1338 (scroll-right 2)) | |
1339 (t (message "Click on the edge of the modeline to scroll left/right"))) | |
1340 ;;(message "X: Pixel %d Char Pixels %d On char %d" xp cpw oc) | |
1341 )) | |
1342 | |
1343 (defun speedbar-customize () | |
1344 "Customize speedbar using the Custom package." | |
1345 (interactive) | |
1346 (let ((sf (selected-frame))) | |
1347 (select-frame speedbar-attached-frame) | |
1348 (customize-group 'speedbar) | |
1349 (select-frame sf)) | |
1350 (speedbar-maybee-jump-to-attached-frame)) | |
1351 | |
22735 | 1352 (defun speedbar-track-mouse (event) |
1353 "For motion EVENT, display info about the current line." | |
1354 (interactive "e") | |
1355 (if (not speedbar-track-mouse-flag) | |
1356 nil | |
1357 (save-excursion | |
1358 (let ((char (nth 1 (car (cdr event))))) | |
1359 (if (not (numberp char)) | |
1360 (message nil) | |
1361 (goto-char char) | |
1362 ;; (message "%S" event) | |
1363 (speedbar-item-info) | |
1364 ))))) | |
1365 | |
1366 (defun speedbar-track-mouse-xemacs (event) | |
1367 "For motion EVENT, display info about the current line." | |
1368 (if (functionp (default-value 'mouse-motion-handler)) | |
1369 (funcall (default-value 'mouse-motion-handler) event)) | |
1370 (if speedbar-track-mouse-flag | |
1371 (save-excursion | |
1372 (save-window-excursion | |
1373 (condition-case () | |
1374 (progn (mouse-set-point event) | |
1375 ;; Prevent focus-related bugs. | |
1376 (if (eq major-mode 'speedbar-mode) | |
1377 (speedbar-item-info))) | |
1378 (error nil)))))) | |
1379 | |
21650 | 1380 ;; In XEmacs, we make popup menus work on the item over mouse (as |
1381 ;; opposed to where the point happens to be.) We attain this by | |
1382 ;; temporarily moving the point to that place. | |
1383 ;; Hrvoje Niksic <hniksic@srce.hr> | |
1384 (defun speedbar-xemacs-popup-kludge (event) | |
1385 "Pop up a menu related to the clicked on item. | |
1386 Must be bound to EVENT." | |
1387 (interactive "e") | |
22735 | 1388 (select-frame speedbar-frame) |
21650 | 1389 (save-excursion |
1390 (goto-char (event-closest-point event)) | |
1391 (beginning-of-line) | |
1392 (forward-char (min 5 (- (save-excursion (end-of-line) (point)) | |
1393 (save-excursion (beginning-of-line) (point))))) | |
1394 (popup-mode-menu) | |
1395 ;; Wait for menu to bail out. `popup-mode-menu' (and other popup | |
1396 ;; menu functions) return immediately. | |
1397 (let (new) | |
1398 (while (not (misc-user-event-p (setq new (next-event)))) | |
1399 (dispatch-event new)) | |
1400 (dispatch-event new)))) | |
1401 | |
1402 (defun speedbar-emacs-popup-kludge (e) | |
1403 "Pop up a menu related to the clicked on item. | |
1404 Must be bound to event E." | |
1405 (interactive "e") | |
1406 (save-excursion | |
1407 (mouse-set-point e) | |
1408 ;; This gets the cursor where the user can see it. | |
1409 (if (not (bolp)) (forward-char -1)) | |
1410 (sit-for 0) | |
1411 (if (< emacs-major-version 20) | |
1412 (mouse-major-mode-menu e) | |
1413 (mouse-major-mode-menu e nil)))) | |
1414 | |
22893
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1415 (defun speedbar-hack-buffer-menu (e) |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1416 "Control mouse 1 is buffer menu. |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1417 This hack overrides it so that the right thing happens in the main |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1418 Emacs frame, not in the speedbar frame. |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1419 Argument E is the event causing this activity." |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1420 (interactive "e") |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1421 (let ((fn (lookup-key global-map (if speedbar-xemacsp |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1422 '(control button1) |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1423 [C-down-mouse-1]))) |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1424 (newbuff nil)) |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1425 (unwind-protect |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1426 (save-excursion |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1427 (set-window-dedicated-p (selected-window) nil) |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1428 (call-interactively fn) |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1429 (setq newbuff (current-buffer))) |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1430 (switch-to-buffer " SPEEDBAR") |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1431 (set-window-dedicated-p (selected-window) t)) |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1432 (speedbar-with-attached-buffer |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1433 (switch-to-buffer newbuff)))) |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1434 |
21650 | 1435 (defun speedbar-next (arg) |
1436 "Move to the next ARGth line in a speedbar buffer." | |
1437 (interactive "p") | |
1438 (forward-line (or arg 1)) | |
1439 (speedbar-item-info) | |
1440 (speedbar-position-cursor-on-line)) | |
1441 | |
1442 (defun speedbar-prev (arg) | |
1443 "Move to the previous ARGth line in a speedbar buffer." | |
1444 (interactive "p") | |
1445 (speedbar-next (if arg (- arg) -1))) | |
1446 | |
22735 | 1447 (defun speedbar-restricted-move (arg) |
1448 "Move to the next ARGth line in a speedbar buffer at the same depth. | |
1449 This means that movement is restricted to a subnode, and that siblings | |
1450 of intermediate nodes are skipped." | |
1451 (if (not (numberp arg)) (signal 'wrong-type-argument (list arg 'numberp))) | |
1452 ;; First find the extent for which we are allowed to move. | |
1453 (let ((depth (save-excursion (beginning-of-line) | |
1454 (if (looking-at "[0-9]+:") | |
1455 (string-to-int (match-string 0)) | |
1456 0))) | |
1457 (crement (if (< arg 0) 1 -1)) ; decrement or increment | |
1458 (lastmatch (point))) | |
1459 (while (/= arg 0) | |
1460 (forward-line (- crement)) | |
1461 (let ((subdepth (save-excursion (beginning-of-line) | |
1462 (if (looking-at "[0-9]+:") | |
1463 (string-to-int (match-string 0)) | |
1464 0)))) | |
1465 (cond ((or (< subdepth depth) | |
1466 (progn (end-of-line) (eobp)) | |
1467 (progn (beginning-of-line) (bobp))) | |
1468 ;; We have reached the end of this block. | |
1469 (goto-char lastmatch) | |
1470 (setq arg 0) | |
1471 (error "End of sub-list")) | |
1472 ((= subdepth depth) | |
1473 (setq lastmatch (point) | |
1474 arg (+ arg crement)))))) | |
1475 (speedbar-position-cursor-on-line))) | |
1476 | |
1477 (defun speedbar-restricted-next (arg) | |
1478 "Move to the next ARGth line in a speedbar buffer at the same depth. | |
1479 This means that movement is restricted to a subnode, and that siblings | |
1480 of intermediate nodes are skipped." | |
1481 (interactive "p") | |
1482 (speedbar-restricted-move (or arg 1)) | |
1483 (speedbar-item-info)) | |
1484 | |
1485 | |
1486 (defun speedbar-restricted-prev (arg) | |
1487 "Move to the previous ARGth line in a speedbar buffer at the same depth. | |
1488 This means that movement is restricted to a subnode, and that siblings | |
1489 of intermediate nodes are skipped." | |
1490 (interactive "p") | |
1491 (speedbar-restricted-move (if arg (- arg) -1)) | |
1492 (speedbar-item-info)) | |
1493 | |
1494 (defun speedbar-navigate-list (arg) | |
1495 "Move across ARG groups of similarly typed items in speedbar. | |
1496 Stop on the first line of the next type of item, or on the last or first item | |
1497 if we reach a buffer boundary." | |
1498 (interactive "p") | |
1499 (beginning-of-line) | |
1500 (if (looking-at "[0-9]+: *[[<{][-+?][]>}] ") | |
1501 (let ((str (regexp-quote (match-string 0)))) | |
1502 (while (looking-at str) | |
1503 (speedbar-restricted-move arg) | |
1504 (beginning-of-line)))) | |
1505 (speedbar-position-cursor-on-line)) | |
1506 | |
1507 (defun speedbar-forward-list () | |
1508 "Move forward over the current list. | |
1509 A LIST in speedbar is a group of similarly typed items, such as directories, | |
1510 files, or the directory button." | |
1511 (interactive) | |
1512 (speedbar-navigate-list 1) | |
1513 (speedbar-item-info)) | |
1514 | |
1515 (defun speedbar-backward-list () | |
1516 "Move backward over the current list. | |
1517 A LIST in speedbar is a group of similarly typed items, such as directories, | |
1518 files, or the directory button." | |
1519 (interactive) | |
1520 (speedbar-navigate-list -1) | |
1521 (speedbar-item-info)) | |
1522 | |
21650 | 1523 (defun speedbar-scroll-up (&optional arg) |
1524 "Page down one screen-full of the speedbar, or ARG lines." | |
1525 (interactive "P") | |
1526 (scroll-up arg) | |
1527 (speedbar-position-cursor-on-line)) | |
1528 | |
1529 (defun speedbar-scroll-down (&optional arg) | |
1530 "Page up one screen-full of the speedbar, or ARG lines." | |
1531 (interactive "P") | |
1532 (scroll-down arg) | |
1533 (speedbar-position-cursor-on-line)) | |
1534 | |
1535 (defun speedbar-up-directory () | |
1536 "Keyboard accelerator for moving the default directory up one. | |
1537 Assumes that the current buffer is the speedbar buffer" | |
1538 (interactive) | |
1539 (setq default-directory (expand-file-name (concat default-directory "../"))) | |
1540 (speedbar-update-contents)) | |
1541 | |
1542 ;;; Speedbar file activity (aka creeping featurism) | |
1543 ;; | |
1544 (defun speedbar-refresh () | |
1545 "Refresh the current speedbar display, disposing of any cached data." | |
1546 (interactive) | |
22893
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1547 (let ((dl speedbar-shown-directories) |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1548 (dm (and (boundp 'deactivate-mark) deactivate-mark))) |
21650 | 1549 (while dl |
1550 (adelete 'speedbar-directory-contents-alist (car dl)) | |
22893
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1551 (setq dl (cdr dl))) |
22906
adfc04c48002
Updated refresh messages to clear themselves.
Eric M. Ludlam <zappo@gnu.org>
parents:
22893
diff
changeset
|
1552 (if (<= 1 speedbar-verbosity-level) |
adfc04c48002
Updated refresh messages to clear themselves.
Eric M. Ludlam <zappo@gnu.org>
parents:
22893
diff
changeset
|
1553 (message "Refreshing speedbar...")) |
22893
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1554 (speedbar-update-contents) |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1555 (speedbar-stealthy-updates) |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1556 ;; Reset the timer in case it got really hosed for some reason... |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1557 (speedbar-set-timer speedbar-update-speed) |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1558 (if (<= 1 speedbar-verbosity-level) |
22906
adfc04c48002
Updated refresh messages to clear themselves.
Eric M. Ludlam <zappo@gnu.org>
parents:
22893
diff
changeset
|
1559 (message "Refreshing speedbar...done")) |
22893
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
1560 (if (boundp 'deactivate-mark) (setq deactivate-mark dm)))) |
21650 | 1561 |
1562 (defun speedbar-item-load () | |
22735 | 1563 "Load the item under the cursor or mouse if it is a Lisp file." |
21650 | 1564 (interactive) |
1565 (let ((f (speedbar-line-file))) | |
1566 (if (and (file-exists-p f) (string-match "\\.el\\'" f)) | |
1567 (if (and (file-exists-p (concat f "c")) | |
1568 (y-or-n-p (format "Load %sc? " f))) | |
1569 ;; If the compiled version exists, load that instead... | |
1570 (load-file (concat f "c")) | |
1571 (load-file f)) | |
22735 | 1572 (error "Not a loadable file")))) |
21650 | 1573 |
1574 (defun speedbar-item-byte-compile () | |
22735 | 1575 "Byte compile the item under the cursor or mouse if it is a Lisp file." |
21650 | 1576 (interactive) |
1577 (let ((f (speedbar-line-file)) | |
1578 (sf (selected-frame))) | |
1579 (if (and (file-exists-p f) (string-match "\\.el\\'" f)) | |
1580 (progn | |
1581 (select-frame speedbar-attached-frame) | |
1582 (byte-compile-file f nil) | |
22735 | 1583 (select-frame sf) |
1584 (speedbar-reset-scanners))) | |
21650 | 1585 )) |
1586 | |
1587 (defun speedbar-mouse-item-info (event) | |
1588 "Provide information about what the user clicked on. | |
1589 This should be bound to a mouse EVENT." | |
1590 (interactive "e") | |
1591 (mouse-set-point event) | |
1592 (speedbar-item-info)) | |
1593 | |
22735 | 1594 (defun speedbar-generic-item-info () |
1595 "Attempt to derive, and then display information about thils line item. | |
1596 File style information is displayed with `speedbar-item-info'." | |
1597 (save-excursion | |
1598 (beginning-of-line) | |
1599 ;; Skip invisible number info. | |
1600 (if (looking-at "\\([0-9]+\\):") (goto-char (match-end 0))) | |
1601 ;; Skip items in "folder" type text characters. | |
1602 (if (looking-at "\\s-*[[<({].[]>)}] ") (goto-char (match-end 0))) | |
1603 ;; Get the text | |
1604 (message "Text: %s" (buffer-substring-no-properties | |
1605 (point) (progn (end-of-line) (point)))))) | |
1606 | |
21650 | 1607 (defun speedbar-item-info () |
1608 "Display info in the mini-buffer about the button the mouse is over." | |
1609 (interactive) | |
1610 (if (not speedbar-shown-directories) | |
22735 | 1611 (speedbar-generic-item-info) |
21650 | 1612 (let* ((item (speedbar-line-file)) |
1613 (attr (if item (file-attributes item) nil))) | |
22735 | 1614 (if (and item attr) (message "%s %-6d %s" (nth 8 attr) (nth 7 attr) item) |
21650 | 1615 (save-excursion |
1616 (beginning-of-line) | |
22735 | 1617 (if (not (looking-at "\\([0-9]+\\):")) |
1618 (speedbar-generic-item-info) | |
1619 (setq item (speedbar-line-path (string-to-int (match-string 1)))) | |
1620 (if (re-search-forward "> \\([^ ]+\\)$" | |
1621 (save-excursion(end-of-line)(point)) t) | |
1622 (progn | |
1623 (setq attr (get-text-property (match-beginning 1) | |
1624 'speedbar-token)) | |
1625 (message "Tag: %s in %s @ %s" | |
1626 (match-string 1) item | |
1627 (if attr | |
1628 (if (markerp attr) (marker-position attr) attr) | |
1629 0))) | |
1630 (if (re-search-forward "{[+-]} \\([^\n]+\\)$" | |
1631 (save-excursion(end-of-line)(point)) t) | |
1632 (message "Group of tags \"%s\"" (match-string 1)) | |
1633 (speedbar-generic-item-info))))))))) | |
21650 | 1634 |
1635 (defun speedbar-item-copy () | |
1636 "Copy the item under the cursor. | |
1637 Files can be copied to new names or places." | |
1638 (interactive) | |
1639 (let ((f (speedbar-line-file))) | |
22735 | 1640 (if (not f) (error "Not a file")) |
21650 | 1641 (if (file-directory-p f) |
22735 | 1642 (error "Cannot copy directory") |
21650 | 1643 (let* ((rt (read-file-name (format "Copy %s to: " |
1644 (file-name-nondirectory f)) | |
1645 (file-name-directory f))) | |
1646 (refresh (member (expand-file-name (file-name-directory rt)) | |
1647 speedbar-shown-directories))) | |
1648 ;; Create the right file name part | |
1649 (if (file-directory-p rt) | |
1650 (setq rt | |
1651 (concat (expand-file-name rt) | |
1652 (if (string-match "/$" rt) "" "/") | |
1653 (file-name-nondirectory f)))) | |
1654 (if (or (not (file-exists-p rt)) | |
1655 (y-or-n-p (format "Overwrite %s with %s? " rt f))) | |
1656 (progn | |
1657 (copy-file f rt t t) | |
1658 ;; refresh display if the new place is currently displayed. | |
1659 (if refresh | |
1660 (progn | |
1661 (speedbar-refresh) | |
1662 (if (not (speedbar-goto-this-file rt)) | |
1663 (speedbar-goto-this-file f)))) | |
1664 )))))) | |
1665 | |
1666 (defun speedbar-item-rename () | |
1667 "Rename the item under the cursor or mouse. | |
1668 Files can be renamed to new names or moved to new directories." | |
1669 (interactive) | |
1670 (let ((f (speedbar-line-file))) | |
1671 (if f | |
1672 (let* ((rt (read-file-name (format "Rename %s to: " | |
1673 (file-name-nondirectory f)) | |
1674 (file-name-directory f))) | |
1675 (refresh (member (expand-file-name (file-name-directory rt)) | |
1676 speedbar-shown-directories))) | |
1677 ;; Create the right file name part | |
1678 (if (file-directory-p rt) | |
1679 (setq rt | |
1680 (concat (expand-file-name rt) | |
1681 (if (string-match "/\\'" rt) "" "/") | |
1682 (file-name-nondirectory f)))) | |
1683 (if (or (not (file-exists-p rt)) | |
1684 (y-or-n-p (format "Overwrite %s with %s? " rt f))) | |
1685 (progn | |
1686 (rename-file f rt t) | |
1687 ;; refresh display if the new place is currently displayed. | |
1688 (if refresh | |
1689 (progn | |
1690 (speedbar-refresh) | |
1691 (speedbar-goto-this-file rt) | |
1692 ))))) | |
22735 | 1693 (error "Not a file")))) |
21650 | 1694 |
1695 (defun speedbar-item-delete () | |
1696 "Delete the item under the cursor. Files are removed from disk." | |
1697 (interactive) | |
1698 (let ((f (speedbar-line-file))) | |
22735 | 1699 (if (not f) (error "Not a file")) |
21650 | 1700 (if (y-or-n-p (format "Delete %s? " f)) |
1701 (progn | |
1702 (if (file-directory-p f) | |
1703 (delete-directory f) | |
1704 (delete-file f)) | |
1705 (message "Okie dokie..") | |
1706 (let ((p (point))) | |
1707 (speedbar-refresh) | |
1708 (goto-char p)) | |
1709 )) | |
1710 )) | |
1711 | |
22735 | 1712 (defun speedbar-item-object-delete () |
1713 "Delete the object associated from the item under the cursor. | |
1714 The file is removed from disk. The object is determined from the | |
1715 variable `speedbar-obj-alist'." | |
1716 (interactive) | |
1717 (let* ((f (speedbar-line-file)) | |
1718 (obj nil) | |
1719 (oa speedbar-obj-alist)) | |
1720 (if (not f) (error "Not a file")) | |
1721 (while (and oa (not (string-match (car (car oa)) f))) | |
1722 (setq oa (cdr oa))) | |
1723 (setq obj (concat (file-name-sans-extension f) (cdr (car oa)))) | |
1724 (if (and oa (file-exists-p obj) | |
1725 (y-or-n-p (format "Delete %s? " obj))) | |
1726 (progn | |
1727 (delete-file obj) | |
1728 (speedbar-reset-scanners))))) | |
1729 | |
21650 | 1730 (defun speedbar-enable-update () |
1731 "Enable automatic updating in speedbar via timers." | |
1732 (interactive) | |
1733 (setq speedbar-update-flag t) | |
1734 (speedbar-set-mode-line-format) | |
1735 (speedbar-set-timer speedbar-update-speed)) | |
1736 | |
1737 (defun speedbar-disable-update () | |
1738 "Disable automatic updating and stop consuming resources." | |
1739 (interactive) | |
1740 (setq speedbar-update-flag nil) | |
1741 (speedbar-set-mode-line-format) | |
1742 (speedbar-set-timer nil)) | |
1743 | |
1744 (defun speedbar-toggle-updates () | |
1745 "Toggle automatic update for the speedbar frame." | |
1746 (interactive) | |
1747 (if speedbar-update-flag | |
1748 (speedbar-disable-update) | |
1749 (speedbar-enable-update))) | |
1750 | |
1751 (defun speedbar-toggle-sorting () | |
1752 "Toggle automatic update for the speedbar frame." | |
1753 (interactive) | |
1754 (setq speedbar-sort-tags (not speedbar-sort-tags))) | |
1755 | |
1756 (defun speedbar-toggle-show-all-files () | |
1757 "Toggle display of files speedbar can not tag." | |
1758 (interactive) | |
1759 (setq speedbar-show-unknown-files (not speedbar-show-unknown-files)) | |
1760 (speedbar-refresh)) | |
1761 | |
1762 ;;; Utility functions | |
1763 ;; | |
1764 (defun speedbar-set-timer (timeout) | |
1765 "Apply a timer with TIMEOUT, or remove a timer if TIMOUT is nil. | |
1766 TIMEOUT is the number of seconds until the speedbar timer is called | |
1767 again. When TIMEOUT is nil, turn off all timeouts. | |
1768 This function will also enable or disable the `vc-checkin-hook' used | |
1769 to track file check ins, and will change the mode line to match | |
1770 `speedbar-update-flag'." | |
1771 (cond | |
1772 ;; XEmacs | |
1773 (speedbar-xemacsp | |
1774 (if speedbar-timer | |
1775 (progn (delete-itimer speedbar-timer) | |
1776 (setq speedbar-timer nil))) | |
1777 (if timeout | |
1778 (if (and speedbar-xemacsp | |
1779 (or (>= emacs-major-version 20) | |
1780 (>= emacs-minor-version 15))) | |
1781 (setq speedbar-timer (start-itimer "speedbar" | |
1782 'speedbar-timer-fn | |
1783 timeout | |
1784 timeout | |
1785 t)) | |
1786 (setq speedbar-timer (start-itimer "speedbar" | |
1787 'speedbar-timer-fn | |
1788 timeout | |
1789 nil))))) | |
1790 ;; Post 19.31 Emacs | |
1791 ((fboundp 'run-with-idle-timer) | |
1792 (if speedbar-timer | |
1793 (progn (cancel-timer speedbar-timer) | |
1794 (setq speedbar-timer nil))) | |
1795 (if timeout | |
1796 (setq speedbar-timer | |
1797 (run-with-idle-timer timeout t 'speedbar-timer-fn)))) | |
1798 ;; Emacs 19.30 (Thanks twice: ptype@dra.hmg.gb) | |
1799 ((fboundp 'post-command-idle-hook) | |
1800 (if timeout | |
1801 (add-hook 'post-command-idle-hook 'speedbar-timer-fn) | |
1802 (remove-hook 'post-command-idle-hook 'speedbar-timer-fn))) | |
1803 ;; Older or other Emacsen with no timers. Set up so that its | |
1804 ;; obvious this emacs can't handle the updates | |
1805 (t | |
1806 (setq speedbar-update-flag nil))) | |
1807 ;; Apply a revert hook that will reset the scanners. We attach to revert | |
1808 ;; because most reverts occur during VC state change, and this lets our | |
1809 ;; VC scanner fix itself. | |
1810 (if timeout | |
1811 (add-hook 'after-revert-hook 'speedbar-reset-scanners) | |
1812 (remove-hook 'after-revert-hook 'speedbar-reset-scanners) | |
1813 ) | |
1814 ;; change this if it changed for some reason | |
1815 (speedbar-set-mode-line-format)) | |
1816 | |
1817 (defmacro speedbar-with-writable (&rest forms) | |
1818 "Allow the buffer to be writable and evaluate FORMS." | |
1819 (list 'let '((inhibit-read-only t)) | |
1820 (cons 'progn forms))) | |
1821 (put 'speedbar-with-writable 'lisp-indent-function 0) | |
1822 | |
1823 (defun speedbar-select-window (buffer) | |
22735 | 1824 "Select a window in which BUFFER is shown. |
21650 | 1825 If it is not shown, force it to appear in the default window." |
1826 (let ((win (get-buffer-window buffer speedbar-attached-frame))) | |
1827 (if win | |
1828 (select-window win) | |
22735 | 1829 (set-window-buffer (selected-window) buffer)))) |
21650 | 1830 |
1831 (defmacro speedbar-with-attached-buffer (&rest forms) | |
1832 "Execute FORMS in the attached frame's special buffer. | |
1833 Optionally select that frame if necessary." | |
1834 ;; Reset the timer with a new timeout when cliking a file | |
1835 ;; in case the user was navigating directories, we can cancel | |
1836 ;; that other timer. | |
1837 (list | |
1838 'progn | |
1839 '(speedbar-set-timer speedbar-update-speed) | |
1840 (list | |
1841 'let '((cf (selected-frame))) | |
1842 '(select-frame speedbar-attached-frame) | |
1843 '(speedbar-select-window speedbar-desired-buffer) | |
1844 (cons 'progn forms) | |
1845 '(select-frame cf) | |
1846 '(speedbar-maybee-jump-to-attached-frame) | |
1847 ))) | |
1848 | |
1849 (defun speedbar-insert-button (text face mouse function | |
1850 &optional token prevline) | |
1851 "Insert TEXT as the next logical speedbar button. | |
1852 FACE is the face to put on the button, MOUSE is the highlight face to use. | |
1853 When the user clicks on TEXT, FUNCTION is called with the TOKEN parameter. | |
1854 This function assumes that the current buffer is the speedbar buffer. | |
1855 If PREVLINE, then put this button on the previous line. | |
1856 | |
1857 This is a convenience function for special mode that create their own | |
1858 specialized speedbar displays." | |
1859 (goto-char (point-max)) | |
1860 (if (/= (current-column) 0) (insert "\n")) | |
1861 (if prevline (progn (delete-char -1) (insert " "))) ;back up if desired... | |
1862 (let ((start (point))) | |
1863 (insert text) | |
1864 (speedbar-make-button start (point) face mouse function token)) | |
1865 (let ((start (point))) | |
1866 (insert "\n") | |
1867 (put-text-property start (point) 'face nil) | |
1868 (put-text-property start (point) 'mouse-face nil))) | |
1869 | |
1870 (defun speedbar-make-button (start end face mouse function &optional token) | |
1871 "Create a button from START to END, with FACE as the display face. | |
1872 MOUSE is the mouse face. When this button is clicked on FUNCTION | |
22735 | 1873 will be run with the TOKEN parameter (any Lisp object)" |
21650 | 1874 (put-text-property start end 'face face) |
1875 (put-text-property start end 'mouse-face mouse) | |
1876 (put-text-property start end 'invisible nil) | |
1877 (if function (put-text-property start end 'speedbar-function function)) | |
1878 (if token (put-text-property start end 'speedbar-token token)) | |
1879 ) | |
1880 | |
22735 | 1881 ;;; Initial Expansion list management |
1882 ;; | |
1883 (defun speedbar-initial-expansion-list () | |
1884 "Return the current default expansion list. | |
1885 This is based on `speedbar-initial-expansion-list-name' referencing | |
1886 `speedbar-initial-expansion-mode-alist'." | |
1887 ;; cdr1 - name, cdr2 - menu | |
1888 (cdr (cdr (cdr (assoc speedbar-initial-expansion-list-name | |
1889 speedbar-initial-expansion-mode-alist))))) | |
1890 | |
1891 (defun speedbar-initial-menu () | |
1892 "Return the current default menu data. | |
1893 This is based on `speedbar-initial-expansion-list-name' referencing | |
1894 `speedbar-initial-expansion-mode-alist'." | |
1895 (symbol-value | |
1896 (car (cdr (assoc speedbar-initial-expansion-list-name | |
1897 speedbar-initial-expansion-mode-alist))))) | |
1898 | |
1899 (defun speedbar-initial-keymap () | |
1900 "Return the current default menu data. | |
1901 This is based on `speedbar-initial-expansion-list-name' referencing | |
1902 `speedbar-initial-expansion-mode-alist'." | |
1903 (symbol-value | |
1904 (car (cdr (cdr (assoc speedbar-initial-expansion-list-name | |
1905 speedbar-initial-expansion-mode-alist)))))) | |
1906 | |
1907 (defun speedbar-initial-stealthy-functions () | |
1908 "Return a list of functions to call stealthily. | |
1909 This is based on `speedbar-initial-expansion-list-name' referencing | |
1910 `speedbar-stealthy-function-list'." | |
1911 (cdr (assoc speedbar-initial-expansion-list-name | |
1912 speedbar-stealthy-function-list))) | |
1913 | |
1914 (defun speedbar-add-expansion-list (new-list) | |
1915 "Add NEW-LIST to the list of expansion lists." | |
1916 (add-to-list 'speedbar-initial-expansion-mode-alist new-list)) | |
1917 | |
1918 (defun speedbar-change-initial-expansion-list (new-default) | |
1919 "Change speedbar's default expansion list to NEW-DEFAULT." | |
1920 (interactive | |
1921 (list | |
1922 (completing-read (format "Speedbar Mode (default %s): " | |
1923 speedbar-previously-used-expansion-list-name) | |
1924 speedbar-initial-expansion-mode-alist | |
1925 nil t "" nil | |
1926 speedbar-previously-used-expansion-list-name))) | |
1927 (setq speedbar-previously-used-expansion-list-name | |
1928 speedbar-initial-expansion-list-name | |
1929 speedbar-initial-expansion-list-name new-default) | |
1930 (speedbar-refresh) | |
1931 (speedbar-reconfigure-keymaps)) | |
1932 | |
1933 | |
1934 ;;; Special speedbar display management | |
1935 ;; | |
1936 (defun speedbar-maybe-add-localized-support (buffer) | |
1937 "Quick check function called on BUFFERs by the speedbar timer function. | |
1938 Maintains the value of local variables which control speedbars use | |
1939 of the special mode functions." | |
1940 (or speedbar-special-mode-expansion-list | |
1941 (speedbar-add-localized-speedbar-support buffer))) | |
1942 | |
1943 (defun speedbar-add-localized-speedbar-support (buffer) | |
1944 "Add localized speedbar support to BUFFER's mode if it is available." | |
1945 (interactive "bBuffer: ") | |
1946 (if (stringp buffer) (setq buffer (get-buffer buffer))) | |
1947 (if (not (buffer-live-p buffer)) | |
1948 nil | |
1949 (save-excursion | |
1950 (set-buffer buffer) | |
1951 (save-match-data | |
1952 (let ((ms (symbol-name major-mode)) v) | |
1953 (if (not (string-match "-mode$" ms)) | |
1954 nil ;; do nothing to broken mode | |
1955 (setq ms (substring ms 0 (match-beginning 0))) | |
1956 (setq v (intern-soft (concat ms "-speedbar-buttons"))) | |
1957 (make-local-variable 'speedbar-special-mode-expansion-list) | |
1958 (if (not v) | |
1959 (setq speedbar-special-mode-expansion-list t) | |
1960 ;; If it is autoloaded, we need to load it now so that | |
1961 ;; we have access to the varialbe -speedbar-menu-items. | |
1962 ;; Is this XEmacs safe? | |
1963 (let ((sf (symbol-function v))) | |
1964 (if (and (listp sf) (eq (car sf) 'autoload)) | |
1965 (load-library (car (cdr sf))))) | |
1966 (setq speedbar-special-mode-expansion-list (list v)) | |
1967 (setq v (intern-soft (concat ms "-speedbar-key-map"))) | |
1968 (if (not v) | |
1969 nil ;; don't add special keymap | |
1970 (make-local-variable 'speedbar-special-mode-key-map) | |
1971 (setq speedbar-special-mode-key-map | |
1972 (symbol-value v))) | |
1973 (setq v (intern-soft (concat ms "-speedbar-menu-items"))) | |
1974 (if (not v) | |
1975 nil ;; don't add special menus | |
1976 (make-local-variable 'speedbar-easymenu-definition-special) | |
1977 (setq speedbar-easymenu-definition-special | |
1978 (symbol-value v))) | |
1979 ))))))) | |
1980 | |
1981 (defun speedbar-remove-localized-speedbar-support (buffer) | |
1982 "Remove any traces that BUFFER supports speedbar in a specialized way." | |
1983 (save-excursion | |
1984 (set-buffer buffer) | |
1985 (kill-local-variable 'speedbar-special-mode-expansion-list) | |
1986 (kill-local-variable 'speedbar-special-mode-key-map) | |
1987 (kill-local-variable 'speedbar-easymenu-definition-special))) | |
1988 | |
21650 | 1989 ;;; File button management |
1990 ;; | |
1991 (defun speedbar-file-lists (directory) | |
1992 "Create file lists for DIRECTORY. | |
1993 The car is the list of directories, the cdr is list of files not | |
1994 matching ignored headers. Cache any directory files found in | |
1995 `speedbar-directory-contents-alist' and use that cache before scanning | |
1996 the file-system" | |
1997 (setq directory (expand-file-name directory)) | |
1998 ;; If in powerclick mode, then the directory we are getting | |
1999 ;; should be rescanned. | |
2000 (if speedbar-power-click | |
2001 (adelete 'speedbar-directory-contents-alist directory)) | |
2002 ;; find the directory, either in the cache, or build it. | |
2003 (or (cdr-safe (assoc directory speedbar-directory-contents-alist)) | |
2004 (let ((default-directory directory) | |
2005 (dir (directory-files directory nil)) | |
2006 (dirs nil) | |
2007 (files nil)) | |
2008 (while dir | |
22735 | 2009 (if (not |
2010 (or (string-match speedbar-file-unshown-regexp (car dir)) | |
2011 (string-match speedbar-directory-unshown-regexp (car dir)))) | |
21650 | 2012 (if (file-directory-p (car dir)) |
2013 (setq dirs (cons (car dir) dirs)) | |
2014 (setq files (cons (car dir) files)))) | |
2015 (setq dir (cdr dir))) | |
2016 (let ((nl (cons (nreverse dirs) (list (nreverse files))))) | |
2017 (aput 'speedbar-directory-contents-alist directory nl) | |
2018 nl)) | |
2019 )) | |
2020 | |
2021 (defun speedbar-directory-buttons (directory index) | |
2022 "Insert a single button group at point for DIRECTORY. | |
2023 Each directory path part is a different button. If part of the path | |
2024 matches the user directory ~, then it is replaced with a ~. | |
2025 INDEX is not used, but is required by the caller." | |
2026 (let* ((tilde (expand-file-name "~")) | |
2027 (dd (expand-file-name directory)) | |
2028 (junk (string-match (regexp-quote tilde) dd)) | |
2029 (displayme (if junk | |
2030 (concat "~" (substring dd (match-end 0))) | |
2031 dd)) | |
2032 (p (point))) | |
2033 (if (string-match "^~/?\\'" displayme) (setq displayme (concat tilde "/"))) | |
2034 (insert displayme) | |
2035 (save-excursion | |
2036 (goto-char p) | |
2037 (while (re-search-forward "\\([^/]+\\)/" nil t) | |
2038 (speedbar-make-button (match-beginning 1) (match-end 1) | |
2039 'speedbar-directory-face | |
2040 'speedbar-highlight-face | |
2041 'speedbar-directory-buttons-follow | |
2042 (if (= (match-beginning 1) p) | |
2043 (expand-file-name "~/") ;the tilde | |
2044 (buffer-substring-no-properties | |
2045 p (match-end 0))))) | |
2046 ;; Nuke the beginning of the directory if it's too long... | |
2047 (cond ((eq speedbar-directory-button-trim-method 'span) | |
2048 (beginning-of-line) | |
2049 (let ((ww (or (speedbar-frame-width) 20))) | |
2050 (move-to-column ww nil) | |
2051 (while (>= (current-column) ww) | |
2052 (re-search-backward "/" nil t) | |
2053 (if (<= (current-column) 2) | |
2054 (progn | |
2055 (re-search-forward "/" nil t) | |
2056 (if (< (current-column) 4) | |
2057 (re-search-forward "/" nil t)) | |
2058 (forward-char -1))) | |
2059 (if (looking-at "/?$") | |
2060 (beginning-of-line) | |
2061 (insert "/...\n ") | |
2062 (move-to-column ww nil))))) | |
2063 ((eq speedbar-directory-button-trim-method 'trim) | |
2064 (end-of-line) | |
2065 (let ((ww (or (speedbar-frame-width) 20)) | |
2066 (tl (current-column))) | |
2067 (if (< ww tl) | |
2068 (progn | |
2069 (move-to-column (- tl ww)) | |
2070 (if (re-search-backward "/" nil t) | |
2071 (progn | |
2072 (delete-region (point-min) (point)) | |
2073 (insert "$") | |
2074 ))))))) | |
2075 ) | |
2076 (if (string-match "\\`/[^/]+/\\'" displayme) | |
2077 (progn | |
2078 (insert " ") | |
2079 (let ((p (point))) | |
2080 (insert "<root>") | |
2081 (speedbar-make-button p (point) | |
2082 'speedbar-directory-face | |
2083 'speedbar-highlight-face | |
2084 'speedbar-directory-buttons-follow | |
2085 "/")))) | |
2086 (end-of-line) | |
2087 (insert-char ?\n 1 nil))) | |
2088 | |
2089 (defun speedbar-make-tag-line (exp-button-type | |
2090 exp-button-char exp-button-function | |
2091 exp-button-data | |
2092 tag-button tag-button-function tag-button-data | |
2093 tag-button-face depth) | |
2094 "Create a tag line with EXP-BUTTON-TYPE for the small expansion button. | |
2095 This is the button that expands or contracts a node (if applicable), | |
2096 and EXP-BUTTON-CHAR the character in it (+, -, ?, etc). EXP-BUTTON-FUNCTION | |
2097 is the function to call if it's clicked on. Button types are | |
2098 'bracket, 'angle, 'curly, or nil. EXP-BUTTON-DATA is extra data | |
2099 attached to the text forming the expansion button. | |
2100 | |
2101 Next, TAG-BUTTON is the text of the tag. TAG-BUTTON-FUNCTION is the | |
2102 function to call if clicked on, and TAG-BUTTON-DATA is the data to | |
2103 attach to the text field (such a tag positioning, etc). | |
2104 TAG-BUTTON-FACE is a face used for this type of tag. | |
2105 | |
2106 Lastly, DEPTH shows the depth of expansion. | |
2107 | |
2108 This function assumes that the cursor is in the speedbar window at the | |
2109 position to insert a new item, and that the new item will end with a CR" | |
2110 (let ((start (point)) | |
2111 (end (progn | |
2112 (insert (int-to-string depth) ":") | |
2113 (point)))) | |
2114 (put-text-property start end 'invisible t) | |
2115 ) | |
2116 (insert-char ? depth nil) | |
2117 (put-text-property (- (point) depth) (point) 'invisible nil) | |
2118 (let* ((exp-button (cond ((eq exp-button-type 'bracket) "[%c]") | |
2119 ((eq exp-button-type 'angle) "<%c>") | |
2120 ((eq exp-button-type 'curly) "{%c}") | |
2121 (t ">"))) | |
2122 (buttxt (format exp-button exp-button-char)) | |
2123 (start (point)) | |
2124 (end (progn (insert buttxt) (point))) | |
2125 (bf (if exp-button-type 'speedbar-button-face nil)) | |
2126 (mf (if exp-button-function 'speedbar-highlight-face nil)) | |
2127 ) | |
2128 (speedbar-make-button start end bf mf exp-button-function exp-button-data) | |
22735 | 2129 (if speedbar-hide-button-brackets-flag |
2130 (progn | |
2131 (put-text-property start (1+ start) 'invisible t) | |
2132 (put-text-property end (1- end) 'invisible t))) | |
21650 | 2133 ) |
2134 (insert-char ? 1 nil) | |
2135 (put-text-property (1- (point)) (point) 'invisible nil) | |
2136 (let ((start (point)) | |
2137 (end (progn (insert tag-button) (point)))) | |
2138 (insert-char ?\n 1 nil) | |
2139 (put-text-property (1- (point)) (point) 'invisible nil) | |
2140 (speedbar-make-button start end tag-button-face | |
2141 (if tag-button-function 'speedbar-highlight-face nil) | |
2142 tag-button-function tag-button-data)) | |
2143 ) | |
2144 | |
2145 (defun speedbar-change-expand-button-char (char) | |
2146 "Change the expansion button character to CHAR for the current line." | |
2147 (save-excursion | |
2148 (beginning-of-line) | |
2149 (if (re-search-forward ":\\s-*.\\([-+?]\\)" (save-excursion (end-of-line) | |
2150 (point)) t) | |
2151 (speedbar-with-writable | |
2152 (goto-char (match-beginning 1)) | |
2153 (delete-char 1) | |
22735 | 2154 (insert-char char 1 t) |
2155 (put-text-property (point) (1- (point)) 'invisible nil))))) | |
21650 | 2156 |
2157 | |
2158 ;;; Build button lists | |
2159 ;; | |
2160 (defun speedbar-insert-files-at-point (files level) | |
2161 "Insert list of FILES starting at point, and indenting all files to LEVEL. | |
2162 Tag expandable items with a +, otherwise a ?. Don't highlight ? as we | |
2163 don't know how to manage them. The input parameter FILES is a cons | |
22735 | 2164 cell of the form ( 'DIRLIST . 'FILELIST )" |
21650 | 2165 ;; Start inserting all the directories |
2166 (let ((dirs (car files))) | |
2167 (while dirs | |
2168 (speedbar-make-tag-line 'angle ?+ 'speedbar-dired (car dirs) | |
2169 (car dirs) 'speedbar-dir-follow nil | |
2170 'speedbar-directory-face level) | |
2171 (setq dirs (cdr dirs)))) | |
22735 | 2172 (let ((lst (car (cdr files))) |
2173 (case-fold-search t)) | |
21650 | 2174 (while lst |
2175 (let* ((known (string-match speedbar-file-regexp (car lst))) | |
2176 (expchar (if known ?+ ??)) | |
2177 (fn (if known 'speedbar-tag-file nil))) | |
2178 (if (or speedbar-show-unknown-files (/= expchar ??)) | |
2179 (speedbar-make-tag-line 'bracket expchar fn (car lst) | |
2180 (car lst) 'speedbar-find-file nil | |
2181 'speedbar-file-face level))) | |
2182 (setq lst (cdr lst))))) | |
2183 | |
2184 (defun speedbar-default-directory-list (directory index) | |
2185 "Insert files for DIRECTORY with level INDEX at point." | |
2186 (speedbar-insert-files-at-point | |
2187 (speedbar-file-lists directory) index) | |
2188 (speedbar-reset-scanners) | |
2189 (if (= index 0) | |
2190 ;; If the shown files variable has extra directories, then | |
2191 ;; it is our responsibility to redraw them all | |
2192 ;; Luckilly, the nature of inserting items into this list means | |
2193 ;; that by reversing it, we can easilly go in the right order | |
2194 (let ((sf (cdr (reverse speedbar-shown-directories)))) | |
2195 (setq speedbar-shown-directories | |
2196 (list (expand-file-name default-directory))) | |
2197 ;; exand them all as we find them | |
2198 (while sf | |
2199 (if (speedbar-goto-this-file (car sf)) | |
2200 (progn | |
2201 (beginning-of-line) | |
2202 (if (looking-at "[0-9]+:[ ]*<") | |
2203 (progn | |
2204 (goto-char (match-end 0)) | |
2205 (speedbar-do-function-pointer))) | |
2206 (setq sf (cdr sf))))) | |
2207 ))) | |
2208 | |
22735 | 2209 (defun speedbar-apply-one-tag-hierarchy-method (lst method) |
2210 "Adjust the tag hierarchy LST by METHOD." | |
2211 (cond | |
2212 ((eq method 'sort) | |
2213 (sort (copy-alist lst) | |
2214 (lambda (a b) (string< (car a) (car b))))) | |
2215 ((eq method 'prefix-group) | |
2216 (let ((newlst nil) | |
2217 (sublst nil) | |
2218 (work-list nil) | |
2219 (junk-list nil) | |
2220 (short-group-list nil) | |
2221 (short-start-name nil) | |
2222 (short-end-name nil) | |
2223 (num-shorts-grouped 0) | |
2224 (bins (make-vector 256 nil)) | |
2225 (diff-idx 0)) | |
2226 ;; Break out sub-lists | |
2227 (while lst | |
2228 (if (listp (cdr-safe (car-safe lst))) | |
2229 (setq newlst (cons (car lst) newlst)) | |
2230 (setq sublst (cons (car lst) sublst))) | |
2231 (setq lst (cdr lst))) | |
2232 ;; Now, first find out how long our list is. Never let a | |
2233 ;; list get-shorter than our minimum. | |
2234 (if (<= (length sublst) speedbar-tag-split-minimum-length) | |
2235 (setq work-list (nreverse sublst)) | |
2236 (setq diff-idx (length (try-completion "" sublst))) | |
2237 ;; Sort the whole list into bins. | |
2238 (while sublst | |
2239 (let ((e (car sublst)) | |
2240 (s (car (car sublst)))) | |
2241 (cond ((<= (length s) diff-idx) | |
2242 ;; 0 storage bin for shorty. | |
2243 (aset bins 0 (cons e (aref bins 0)))) | |
2244 (t | |
2245 ;; stuff into a bin based on ascii value at diff | |
2246 (aset bins (aref s diff-idx) | |
2247 (cons e (aref bins (aref s diff-idx))))))) | |
2248 (setq sublst (cdr sublst))) | |
2249 ;; Go through all our bins Stick singles into our | |
2250 ;; junk-list, everything else as sublsts in work-list. | |
2251 ;; If two neighboring lists are both small, make a grouped | |
2252 ;; group combinding those two sub-lists. | |
2253 (setq diff-idx 0) | |
2254 (while (> 256 diff-idx) | |
2255 (let ((l (aref bins diff-idx))) | |
2256 (if l | |
2257 (let ((tmp (cons (try-completion "" l) l))) | |
2258 (if (or (> (length l) speedbar-tag-regroup-maximum-length) | |
2259 (> (+ (length l) (length short-group-list)) | |
2260 speedbar-tag-split-minimum-length)) | |
2261 (progn | |
2262 ;; We have reached a longer list, so we | |
2263 ;; must finish off a grouped group. | |
2264 (cond | |
2265 ((and short-group-list | |
2266 (= (length short-group-list) | |
2267 num-shorts-grouped)) | |
2268 ;; All singles? Junk list | |
2269 (setq junk-list (append short-group-list | |
2270 junk-list))) | |
2271 ((= num-shorts-grouped 1) | |
2272 ;; Only one short group? Just stick it in | |
2273 ;; there by itself. | |
2274 (setq work-list | |
2275 (cons (cons (try-completion | |
2276 "" short-group-list) | |
2277 (nreverse short-group-list)) | |
2278 work-list))) | |
2279 (short-group-list | |
2280 ;; Multiple groups to be named in a special | |
2281 ;; way by displaying the range over which we | |
2282 ;; have grouped them. | |
2283 (setq work-list | |
2284 (cons (cons (concat short-start-name | |
2285 " to " | |
2286 short-end-name) | |
2287 (nreverse short-group-list)) | |
2288 work-list)))) | |
2289 ;; Reset short group list information every time. | |
2290 (setq short-group-list nil | |
2291 short-start-name nil | |
2292 short-end-name nil | |
2293 num-shorts-grouped 0))) | |
2294 ;; Ok, now that we cleaned up the short-group-list, | |
2295 ;; we can deal with this new list, to decide if it | |
2296 ;; should go on one of these sub-lists or not. | |
2297 (if (< (length l) speedbar-tag-regroup-maximum-length) | |
2298 (setq short-group-list (append short-group-list l) | |
2299 num-shorts-grouped (1+ num-shorts-grouped) | |
2300 short-end-name (car tmp) | |
2301 short-start-name (if short-start-name | |
2302 short-start-name | |
2303 (car tmp))) | |
2304 (setq work-list (cons tmp work-list)))))) | |
2305 (setq diff-idx (1+ diff-idx)))) | |
2306 ;; Did we run out of things? Drop our new list onto the end. | |
2307 (cond | |
2308 ((and short-group-list (= (length short-group-list) num-shorts-grouped)) | |
2309 ;; All singles? Junk list | |
2310 (setq junk-list (append short-group-list junk-list))) | |
2311 ((= num-shorts-grouped 1) | |
2312 ;; Only one short group? Just stick it in | |
2313 ;; there by itself. | |
2314 (setq work-list | |
2315 (cons (cons (try-completion "" short-group-list) | |
2316 (nreverse short-group-list)) | |
2317 work-list))) | |
2318 (short-group-list | |
2319 ;; Multiple groups to be named in a special | |
2320 ;; way by displaying the range over which we | |
2321 ;; have grouped them. | |
2322 (setq work-list | |
2323 (cons (cons (concat short-start-name " to " short-end-name) | |
2324 (nreverse short-group-list)) | |
2325 work-list)))) | |
2326 ;; Now, stick our new list onto the end of | |
2327 (if work-list | |
2328 (if junk-list | |
2329 (append (nreverse newlst) | |
2330 (nreverse work-list) | |
2331 junk-list) | |
2332 (append (nreverse newlst) | |
2333 (nreverse work-list))) | |
2334 (append (nreverse newlst) junk-list)))) | |
2335 ((eq method 'trim-words) | |
2336 (let ((newlst nil) | |
2337 (sublst nil) | |
2338 (trim-prefix nil) | |
2339 (trim-chars 0) | |
2340 (trimlst nil)) | |
2341 (while lst | |
2342 (if (listp (cdr-safe (car-safe lst))) | |
2343 (setq newlst (cons (car lst) newlst)) | |
2344 (setq sublst (cons (car lst) sublst))) | |
2345 (setq lst (cdr lst))) | |
2346 ;; Get the prefix to trim by. Make sure that we don't trim | |
2347 ;; off silly pieces, only complete understandable words. | |
2348 (setq trim-prefix (try-completion "" sublst)) | |
2349 (if (or (= (length sublst) 1) | |
2350 (not trim-prefix) | |
2351 (not (string-match "\\(\\w+\\W+\\)+" trim-prefix))) | |
2352 (append (nreverse newlst) (nreverse sublst)) | |
2353 (setq trim-prefix (substring trim-prefix (match-beginning 0) | |
2354 (match-end 0))) | |
2355 (setq trim-chars (length trim-prefix)) | |
2356 (while sublst | |
2357 (setq trimlst (cons | |
2358 (cons (substring (car (car sublst)) trim-chars) | |
2359 (cdr (car sublst))) | |
2360 trimlst) | |
2361 sublst (cdr sublst))) | |
2362 ;; Put the lists together | |
2363 (append (nreverse newlst) trimlst)))) | |
2364 ((eq method 'simple-group) | |
2365 (let ((newlst nil) | |
2366 (sublst nil)) | |
2367 (while lst | |
2368 (if (listp (cdr-safe (car-safe lst))) | |
2369 (setq newlst (cons (car lst) newlst)) | |
2370 (setq sublst (cons (car lst) sublst))) | |
2371 (setq lst (cdr lst))) | |
2372 (if (not newlst) | |
2373 (nreverse sublst) | |
2374 (setq newlst (cons (cons "Tags" (nreverse sublst)) newlst)) | |
2375 (nreverse newlst)))) | |
2376 (t lst))) | |
2377 | |
2378 (defun speedbar-create-tag-hierarchy (lst) | |
2379 "Adjust the tag hierarchy in LST, and return it. | |
2380 This uses `speedbar-tag-hierarchy-method' to determine how to adjust | |
2381 the list. See it's value for details." | |
2382 (let ((methods speedbar-tag-hierarchy-method)) | |
2383 (while methods | |
2384 (setq lst (speedbar-apply-one-tag-hierarchy-method lst (car methods)) | |
2385 methods (cdr methods))) | |
2386 lst)) | |
2387 | |
21650 | 2388 (defun speedbar-insert-generic-list (level lst expand-fun find-fun) |
2389 "At LEVEL, insert a generic multi-level alist LST. | |
2390 Associations with lists get {+} tags (to expand into more nodes) and | |
2391 those with positions just get a > as the indicator. {+} buttons will | |
2392 have the function EXPAND-FUN and the token is the CDR list. The token | |
2393 name will have the function FIND-FUN and not token." | |
2394 ;; Remove imenu rescan button | |
2395 (if (string= (car (car lst)) "*Rescan*") | |
2396 (setq lst (cdr lst))) | |
22735 | 2397 ;; Adjust the list. |
2398 (setq lst (speedbar-create-tag-hierarchy lst)) | |
21650 | 2399 ;; insert the parts |
2400 (while lst | |
2401 (cond ((null (car-safe lst)) nil) ;this would be a separator | |
2402 ((or (numberp (cdr-safe (car-safe lst))) | |
2403 (markerp (cdr-safe (car-safe lst)))) | |
2404 (speedbar-make-tag-line nil nil nil nil ;no expand button data | |
2405 (car (car lst)) ;button name | |
2406 find-fun ;function | |
2407 (cdr (car lst)) ;token is position | |
2408 'speedbar-tag-face | |
2409 (1+ level))) | |
2410 ((listp (cdr-safe (car-safe lst))) | |
2411 (speedbar-make-tag-line 'curly ?+ expand-fun (cdr (car lst)) | |
2412 (car (car lst)) ;button name | |
2413 nil nil 'speedbar-tag-face | |
2414 (1+ level))) | |
2415 (t (message "Ooops!"))) | |
2416 (setq lst (cdr lst)))) | |
2417 | |
2418 ;;; Timed functions | |
2419 ;; | |
2420 (defun speedbar-update-contents () | |
2421 "Generically update the contents of the speedbar buffer." | |
2422 (interactive) | |
2423 ;; Set the current special buffer | |
2424 (setq speedbar-desired-buffer nil) | |
22735 | 2425 ;; Check for special modes |
2426 (speedbar-maybe-add-localized-support (current-buffer)) | |
2427 ;; Choose the correct method of doodling. | |
21650 | 2428 (if (and speedbar-mode-specific-contents-flag |
22735 | 2429 (listp speedbar-special-mode-expansion-list) |
21650 | 2430 speedbar-special-mode-expansion-list |
2431 (local-variable-p | |
2432 'speedbar-special-mode-expansion-list | |
2433 (current-buffer))) | |
2434 ;;(eq (get major-mode 'mode-class 'special))) | |
2435 (speedbar-update-special-contents) | |
2436 (speedbar-update-directory-contents))) | |
2437 | |
2438 (defun speedbar-update-directory-contents () | |
2439 "Update the contents of the speedbar buffer based on the current directory." | |
2440 (let ((cbd (expand-file-name default-directory)) | |
2441 cbd-parent | |
22735 | 2442 (funclst (speedbar-initial-expansion-list)) |
21650 | 2443 (cache speedbar-full-text-cache) |
2444 ;; disable stealth during update | |
2445 (speedbar-stealthy-function-list nil) | |
2446 (use-cache nil) | |
2447 (expand-local nil) | |
2448 ;; Because there is a bug I can't find just yet | |
2449 (inhibit-quit nil)) | |
2450 (save-excursion | |
2451 (set-buffer speedbar-buffer) | |
2452 ;; If we are updating contents to where we are, then this is | |
2453 ;; really a request to update existing contents, so we must be | |
2454 ;; careful with our text cache! | |
2455 (if (member cbd speedbar-shown-directories) | |
22735 | 2456 (progn |
2457 (setq cache nil) | |
2458 ;; If the current directory is not the last element in the dir | |
2459 ;; list, then we ALSO need to zap the list of expanded directories | |
2460 (if (/= (length (member cbd speedbar-shown-directories)) 1) | |
2461 (setq speedbar-shown-directories (list cbd)))) | |
21650 | 2462 |
2463 ;; Build cbd-parent, and see if THAT is in the current shown | |
2464 ;; directories. First, go through pains to get the parent directory | |
2465 (if (and speedbar-smart-directory-expand-flag | |
2466 (save-match-data | |
2467 (setq cbd-parent cbd) | |
2468 (if (string-match "/$" cbd-parent) | |
22735 | 2469 (setq cbd-parent (substring cbd-parent 0 |
2470 (match-beginning 0)))) | |
21650 | 2471 (setq cbd-parent (file-name-directory cbd-parent))) |
2472 (member cbd-parent speedbar-shown-directories)) | |
2473 (setq expand-local t) | |
2474 | |
2475 ;; If this directory is NOT in the current list of available | |
2476 ;; paths, then use the cache, and set the cache to our new | |
2477 ;; value. Make sure to unhighlight the current file, or if we | |
2478 ;; come back to this directory, it might be a different file | |
2479 ;; and then we get a mess! | |
2480 (if (> (point-max) 1) | |
2481 (progn | |
2482 (speedbar-clear-current-file) | |
2483 (setq speedbar-full-text-cache | |
2484 (cons speedbar-shown-directories (buffer-string))))) | |
2485 | |
2486 ;; Check if our new directory is in the list of directories | |
2487 ;; shown in the text-cache | |
2488 (if (member cbd (car cache)) | |
2489 (setq speedbar-shown-directories (car cache) | |
2490 use-cache t) | |
2491 ;; default the shown directories to this list... | |
2492 (setq speedbar-shown-directories (list cbd))) | |
2493 )) | |
23073
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2494 (if (not expand-local) (setq speedbar-last-selected-file nil)) |
21650 | 2495 (speedbar-with-writable |
2496 (if (and expand-local | |
2497 ;; Find this directory as a speedbar node. | |
2498 (speedbar-path-line cbd)) | |
2499 ;; Open it. | |
2500 (speedbar-expand-line) | |
2501 (erase-buffer) | |
2502 (cond (use-cache | |
2503 (setq default-directory | |
2504 (nth (1- (length speedbar-shown-directories)) | |
2505 speedbar-shown-directories)) | |
2506 (insert (cdr cache))) | |
2507 (t | |
2508 (while funclst | |
2509 (setq default-directory cbd) | |
2510 (funcall (car funclst) cbd 0) | |
2511 (setq funclst (cdr funclst)))))) | |
2512 (goto-char (point-min))))) | |
22735 | 2513 (speedbar-reconfigure-keymaps)) |
21650 | 2514 |
2515 (defun speedbar-update-special-contents () | |
2516 "Used the mode-specific variable to fill in the speedbar buffer. | |
2517 This should only be used by modes classified as special." | |
2518 (let ((funclst speedbar-special-mode-expansion-list) | |
2519 (specialbuff (current-buffer))) | |
2520 (save-excursion | |
2521 (setq speedbar-desired-buffer specialbuff) | |
2522 (set-buffer speedbar-buffer) | |
2523 ;; If we are leaving a directory, cache it. | |
2524 (if (not speedbar-shown-directories) | |
2525 ;; Do nothing | |
2526 nil | |
2527 ;; Clean up directory maintenance stuff | |
2528 (speedbar-clear-current-file) | |
2529 (setq speedbar-full-text-cache | |
2530 (cons speedbar-shown-directories (buffer-string)) | |
2531 speedbar-shown-directories nil)) | |
2532 ;; Now fill in the buffer with our newly found specialized list. | |
2533 (speedbar-with-writable | |
2534 (while funclst | |
2535 ;; We do not erase the buffer because these functions may | |
2536 ;; decide NOT to update themselves. | |
2537 (funcall (car funclst) specialbuff) | |
2538 (setq funclst (cdr funclst)))) | |
2539 (goto-char (point-min)))) | |
22735 | 2540 (speedbar-reconfigure-keymaps)) |
21650 | 2541 |
2542 (defun speedbar-timer-fn () | |
22735 | 2543 "Run whenever Emacs is idle to update the speedbar item." |
21650 | 2544 (if (not (and (frame-live-p speedbar-frame) |
2545 (frame-live-p speedbar-attached-frame))) | |
2546 (speedbar-set-timer nil) | |
2547 ;; Save all the match data so that we don't mess up executing fns | |
2548 (save-match-data | |
23073
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2549 ;; Only do stuff if the frame is visible, not an icon, and if |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2550 ;; it is currently flagged to do something. |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2551 (if (and speedbar-update-flag |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2552 (frame-visible-p speedbar-frame) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2553 (not (eq (frame-visible-p speedbar-frame) 'icon))) |
21650 | 2554 (let ((af (selected-frame))) |
2555 (save-window-excursion | |
2556 (select-frame speedbar-attached-frame) | |
2557 ;; make sure we at least choose a window to | |
2558 ;; get a good directory from | |
23073
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2559 (if (window-minibuffer-p (selected-window)) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2560 nil |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2561 ;; Check for special modes |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2562 (speedbar-maybe-add-localized-support (current-buffer)) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2563 ;; Update for special mode all the time! |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2564 (if (and speedbar-mode-specific-contents-flag |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2565 (listp speedbar-special-mode-expansion-list) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2566 speedbar-special-mode-expansion-list |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2567 (local-variable-p |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2568 'speedbar-special-mode-expansion-list |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2569 (current-buffer))) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2570 ;;(eq (get major-mode 'mode-class 'special))) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2571 (progn |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2572 (if (<= 2 speedbar-verbosity-level) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2573 (message "Updating speedbar to special mode: %s..." |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2574 major-mode)) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2575 (speedbar-update-special-contents) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2576 (if (<= 2 speedbar-verbosity-level) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2577 (progn |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2578 (message "Updating speedbar to special mode: %s...done" |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2579 major-mode) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2580 (message nil)))) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2581 ;; Update all the contents if directories change! |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2582 (if (or (member (expand-file-name default-directory) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2583 speedbar-shown-directories) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2584 (and speedbar-ignored-path-regexp |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2585 (string-match |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2586 speedbar-ignored-path-regexp |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2587 (expand-file-name default-directory))) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2588 (member major-mode speedbar-ignored-modes) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2589 (eq af speedbar-frame) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2590 (not (buffer-file-name))) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2591 nil |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2592 (if (<= 1 speedbar-verbosity-level) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2593 (message "Updating speedbar to: %s..." |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2594 default-directory)) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2595 (speedbar-update-directory-contents) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2596 (if (<= 1 speedbar-verbosity-level) |
22906
adfc04c48002
Updated refresh messages to clear themselves.
Eric M. Ludlam <zappo@gnu.org>
parents:
22893
diff
changeset
|
2597 (progn |
23073
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2598 (message "Updating speedbar to: %s...done" |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2599 default-directory) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2600 (message nil))))) |
a0e975baf1e1
(speedbar-timer-fn): Disable updating if the frame
Eric M. Ludlam <zappo@gnu.org>
parents:
23015
diff
changeset
|
2601 (select-frame af))) |
21650 | 2602 ;; Now run stealthy updates of time-consuming items |
22735 | 2603 (speedbar-stealthy-updates))) |
2604 ;; Now run the mouse tracking system | |
2605 (speedbar-show-info-under-mouse))) | |
21650 | 2606 (run-hooks 'speedbar-timer-hook)) |
2607 | |
2608 | |
2609 ;;; Stealthy activities | |
2610 ;; | |
22735 | 2611 (defvar speedbar-stealthy-update-recurse nil |
2612 "Recursion avoidance variable for stealthy update.") | |
2613 | |
21650 | 2614 (defun speedbar-stealthy-updates () |
2615 "For a given speedbar, run all items in the stealthy function list. | |
2616 Each item returns t if it completes successfully, or nil if | |
2617 interrupted by the user." | |
22735 | 2618 (if (not speedbar-stealthy-update-recurse) |
2619 (let ((l (speedbar-initial-stealthy-functions)) | |
2620 (speedbar-stealthy-update-recurse t)) | |
2621 (unwind-protect | |
23085
46deaf6e62a9
(speedbar-stealthy-updates): Do all updates w/ the the buffer writable.
Eric M. Ludlam <zappo@gnu.org>
parents:
23084
diff
changeset
|
2622 (speedbar-with-writable |
46deaf6e62a9
(speedbar-stealthy-updates): Do all updates w/ the the buffer writable.
Eric M. Ludlam <zappo@gnu.org>
parents:
23084
diff
changeset
|
2623 (while (and l (funcall (car l))) |
46deaf6e62a9
(speedbar-stealthy-updates): Do all updates w/ the the buffer writable.
Eric M. Ludlam <zappo@gnu.org>
parents:
23084
diff
changeset
|
2624 ;;(sit-for 0) |
46deaf6e62a9
(speedbar-stealthy-updates): Do all updates w/ the the buffer writable.
Eric M. Ludlam <zappo@gnu.org>
parents:
23084
diff
changeset
|
2625 (setq l (cdr l)))) |
22735 | 2626 ;;(message "Exit with %S" (car l)) |
2627 )))) | |
21650 | 2628 |
2629 (defun speedbar-reset-scanners () | |
2630 "Reset any variables used by functions in the stealthy list as state. | |
2631 If new functions are added, their state needs to be updated here." | |
22735 | 2632 (setq speedbar-vc-to-do-point t |
2633 speedbar-obj-to-do-point t) | |
21650 | 2634 (run-hooks 'speedbar-scanner-reset-hook) |
2635 ) | |
2636 | |
22950
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2637 (defun speedbar-find-selected-file (file) |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2638 "Goto the line where FILE is." |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2639 (goto-char (point-min)) |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2640 (let ((m nil)) |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2641 (while (and (setq m (re-search-forward |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2642 (concat " \\(" (file-name-nondirectory file) |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2643 "\\)\\(" speedbar-indicator-regex "\\)?\n") |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2644 nil t)) |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2645 (not (string= file |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2646 (concat |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2647 (speedbar-line-path |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2648 (save-excursion |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2649 (goto-char (match-beginning 0)) |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2650 (beginning-of-line) |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2651 (save-match-data |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2652 (looking-at "[0-9]+:") |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2653 (string-to-number (match-string 0))))) |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2654 (match-string 1)))))) |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2655 (if m |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2656 (progn |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2657 (goto-char (match-beginning 1)) |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2658 (match-string 1))))) |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2659 |
21650 | 2660 (defun speedbar-clear-current-file () |
2661 "Locate the file thought to be current, and remove its highlighting." | |
2662 (save-excursion | |
2663 (set-buffer speedbar-buffer) | |
2664 (if speedbar-last-selected-file | |
2665 (speedbar-with-writable | |
22950
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2666 (if (speedbar-find-selected-file speedbar-last-selected-file) |
21650 | 2667 (put-text-property (match-beginning 1) |
2668 (match-end 1) | |
2669 'face | |
2670 'speedbar-file-face)))))) | |
2671 | |
2672 (defun speedbar-update-current-file () | |
2673 "Find the current file, and update our visuals to indicate its name. | |
2674 This is specific to file names. If the file name doesn't show up, but | |
2675 it should be in the list, then the directory cache needs to be | |
2676 updated." | |
2677 (let* ((lastf (selected-frame)) | |
2678 (newcfd (save-excursion | |
2679 (select-frame speedbar-attached-frame) | |
2680 (let ((rf (if (buffer-file-name) | |
2681 (buffer-file-name) | |
2682 nil))) | |
2683 (select-frame lastf) | |
2684 rf))) | |
22950
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2685 (newcf (if newcfd newcfd)) |
21650 | 2686 (lastb (current-buffer)) |
22735 | 2687 (sucf-recursive (boundp 'sucf-recursive)) |
2688 (case-fold-search t)) | |
21650 | 2689 (if (and newcf |
2690 ;; check here, that way we won't refresh to newcf until | |
2691 ;; its been written, thus saving ourselves some time | |
2692 (file-exists-p newcf) | |
2693 (not (string= newcf speedbar-last-selected-file))) | |
2694 (progn | |
2695 ;; It is important to select the frame, otherwise the window | |
2696 ;; we want the cursor to move in will not be updated by the | |
2697 ;; search-forward command. | |
2698 (select-frame speedbar-frame) | |
2699 ;; Remove the old file... | |
2700 (speedbar-clear-current-file) | |
2701 ;; now highlight the new one. | |
2702 (set-buffer speedbar-buffer) | |
2703 (speedbar-with-writable | |
22950
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2704 (if (speedbar-find-selected-file newcf) |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2705 ;; put the property on it |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2706 (put-text-property (match-beginning 1) |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2707 (match-end 1) |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2708 'face |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2709 'speedbar-selected-face) |
21650 | 2710 ;; Oops, it's not in the list. Should it be? |
2711 (if (and (string-match speedbar-file-regexp newcf) | |
2712 (string= (file-name-directory newcfd) | |
2713 (expand-file-name default-directory))) | |
2714 ;; yes, it is (we will ignore unknowns for now...) | |
2715 (progn | |
2716 (speedbar-refresh) | |
22950
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
2717 (if (speedbar-find-selected-file newcf) |
21650 | 2718 ;; put the property on it |
2719 (put-text-property (match-beginning 1) | |
2720 (match-end 1) | |
2721 'face | |
2722 'speedbar-selected-face))) | |
2723 ;; if it's not in there now, whatever... | |
2724 )) | |
2725 (setq speedbar-last-selected-file newcf)) | |
2726 (if (not sucf-recursive) | |
22893
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
2727 (progn |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
2728 (speedbar-center-buffer-smartly) |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
2729 (speedbar-position-cursor-on-line) |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
2730 )) |
21650 | 2731 (set-buffer lastb) |
2732 (select-frame lastf) | |
2733 ))) | |
2734 ;; return that we are done with this activity. | |
2735 t) | |
2736 | |
22735 | 2737 (defun speedbar-add-indicator (indicator-string &optional replace-this) |
2738 "Add INDICATOR-STRING to the end of this speedbar line. | |
2739 If INDICATOR-STRING is space, and REPLACE-THIS is a character, then | |
2740 an the existing indicator is removed. If there is already an | |
2741 indicator, then do not add a space." | |
2742 (beginning-of-line) | |
2743 ;; The nature of the beast: Assume we are in "the right place" | |
2744 (end-of-line) | |
2745 (skip-chars-backward (concat " " speedbar-vc-indicator | |
2746 (car speedbar-obj-indicator) | |
2747 (cdr speedbar-obj-indicator))) | |
2748 (if (and (not (looking-at speedbar-indicator-regex)) | |
2749 (not (string= indicator-string " "))) | |
2750 (insert speedbar-indicator-separator)) | |
2751 (speedbar-with-writable | |
2752 (save-excursion | |
2753 (if (and replace-this | |
2754 (re-search-forward replace-this (save-excursion (end-of-line) | |
2755 (point)) | |
2756 t)) | |
2757 (delete-region (match-beginning 0) (match-end 0)))) | |
2758 (end-of-line) | |
2759 (if (not (string= " " indicator-string)) | |
2760 (insert indicator-string)))) | |
2761 | |
2762 ;; Load efs/ange-ftp only if compiling to remove byte-compiler warnings. | |
21650 | 2763 ;; Steven L Baur <steve@xemacs.org> said this was important: |
22735 | 2764 (eval-when-compile (or (featurep 'xemacs) |
2765 (condition-case () (require 'efs) | |
2766 (error (require 'ange-ftp))))) | |
21650 | 2767 |
2768 (defun speedbar-check-vc () | |
2769 "Scan all files in a directory, and for each see if it's checked out. | |
2770 See `speedbar-this-file-in-vc' and `speedbar-vc-check-dir-p' for how | |
2771 to add more types of version control systems." | |
2772 ;; Check for to-do to be reset. If reset but no RCS is available | |
2773 ;; then set to nil (do nothing) otherwise, start at the beginning | |
2774 (save-excursion | |
2775 (set-buffer speedbar-buffer) | |
2776 (if (and speedbar-vc-do-check (eq speedbar-vc-to-do-point t) | |
2777 (speedbar-vc-check-dir-p default-directory) | |
22735 | 2778 (not (or (and (featurep 'ange-ftp) |
2779 (string-match | |
2780 (car (if speedbar-xemacsp | |
2781 ange-ftp-path-format | |
2782 ange-ftp-name-format)) | |
2783 (expand-file-name default-directory))) | |
2784 ;; efs support: Bob Weiner | |
2785 (and (featurep 'efs) | |
2786 (string-match | |
2787 (car efs-path-regexp) | |
2788 (expand-file-name default-directory)))))) | |
21650 | 2789 (setq speedbar-vc-to-do-point 0)) |
2790 (if (numberp speedbar-vc-to-do-point) | |
2791 (progn | |
2792 (goto-char speedbar-vc-to-do-point) | |
2793 (while (and (not (input-pending-p)) | |
2794 (re-search-forward "^\\([0-9]+\\):\\s-*\\[[+-]\\] " | |
2795 nil t)) | |
2796 (setq speedbar-vc-to-do-point (point)) | |
2797 (if (speedbar-check-vc-this-line (match-string 1)) | |
22735 | 2798 (speedbar-add-indicator speedbar-vc-indicator |
2799 (regexp-quote speedbar-vc-indicator)) | |
2800 (speedbar-add-indicator " " | |
2801 (regexp-quote speedbar-vc-indicator)))) | |
21650 | 2802 (if (input-pending-p) |
2803 ;; return that we are incomplete | |
2804 nil | |
2805 ;; we are done, set to-do to nil | |
2806 (setq speedbar-vc-to-do-point nil) | |
2807 ;; and return t | |
2808 t)) | |
2809 t))) | |
2810 | |
2811 (defun speedbar-check-vc-this-line (depth) | |
2812 "Return t if the file on this line is check of of a version control system. | |
2813 Parameter DEPTH is a string with the current depth of indentation of | |
2814 the file being checked." | |
2815 (let* ((d (string-to-int depth)) | |
2816 (f (speedbar-line-path d)) | |
2817 (fn (buffer-substring-no-properties | |
2818 ;; Skip-chars: thanks ptype@dra.hmg.gb | |
2819 (point) (progn | |
2820 (skip-chars-forward "^ " | |
2821 (save-excursion (end-of-line) | |
2822 (point))) | |
2823 (point)))) | |
2824 (fulln (concat f fn))) | |
2825 (if (<= 2 speedbar-verbosity-level) | |
2826 (message "Speedbar vc check...%s" fulln)) | |
2827 (and (file-writable-p fulln) | |
2828 (speedbar-this-file-in-vc f fn)))) | |
2829 | |
2830 (defun speedbar-vc-check-dir-p (path) | |
2831 "Return t if we should bother checking PATH for version control files. | |
2832 This can be overloaded to add new types of version control systems." | |
2833 (or | |
2834 ;; Local RCS | |
2835 (file-exists-p (concat path "RCS/")) | |
2836 ;; Local SCCS | |
2837 (file-exists-p (concat path "SCCS/")) | |
2838 ;; Remote SCCS project | |
2839 (let ((proj-dir (getenv "PROJECTDIR"))) | |
2840 (if proj-dir | |
2841 (file-exists-p (concat proj-dir "/SCCS")) | |
2842 nil)) | |
2843 ;; User extension | |
2844 (run-hook-with-args 'speedbar-vc-path-enable-hook path) | |
2845 )) | |
2846 | |
2847 (defun speedbar-this-file-in-vc (path name) | |
2848 "Check to see if the file in PATH with NAME is in a version control system. | |
2849 You can add new VC systems by overriding this function. You can | |
2850 optimize this function by overriding it and only doing those checks | |
2851 that will occur on your system." | |
2852 (or | |
2853 ;; RCS file name | |
2854 (file-exists-p (concat path "RCS/" name ",v")) | |
22893
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
2855 (file-exists-p (concat path "RCS/" name)) |
21650 | 2856 ;; Local SCCS file name |
2857 (file-exists-p (concat path "SCCS/p." name)) | |
2858 ;; Remote SCCS file name | |
2859 (let ((proj-dir (getenv "PROJECTDIR"))) | |
2860 (if proj-dir | |
2861 (file-exists-p (concat proj-dir "/SCCS/p." name)) | |
2862 nil)) | |
2863 ;; User extension | |
2864 (run-hook-with-args 'speedbar-vc-in-control-hook path name) | |
2865 )) | |
22735 | 2866 |
2867 ;; Objet File scanning | |
2868 (defun speedbar-check-objects () | |
2869 "Scan all files in a directory, and for each see if there is an object. | |
2870 See `speedbar-check-obj-this-line' and `speedbar-obj-alist' for how | |
2871 to add more object types." | |
2872 ;; Check for to-do to be reset. If reset but no RCS is available | |
2873 ;; then set to nil (do nothing) otherwise, start at the beginning | |
2874 (save-excursion | |
2875 (set-buffer speedbar-buffer) | |
2876 (if (and speedbar-obj-do-check (eq speedbar-obj-to-do-point t)) | |
2877 (setq speedbar-obj-to-do-point 0)) | |
2878 (if (numberp speedbar-obj-to-do-point) | |
2879 (progn | |
2880 (goto-char speedbar-obj-to-do-point) | |
2881 (while (and (not (input-pending-p)) | |
2882 (re-search-forward "^\\([0-9]+\\):\\s-*\\[[+-]\\] " | |
2883 nil t)) | |
2884 (setq speedbar-obj-to-do-point (point)) | |
2885 (let ((ind (speedbar-check-obj-this-line (match-string 1)))) | |
2886 (if (not ind) (setq ind " ")) | |
2887 (speedbar-add-indicator ind (concat | |
2888 (car speedbar-obj-indicator) | |
2889 "\\|" | |
2890 (cdr speedbar-obj-indicator))))) | |
2891 (if (input-pending-p) | |
2892 ;; return that we are incomplete | |
2893 nil | |
2894 ;; we are done, set to-do to nil | |
2895 (setq speedbar-obj-to-do-point nil) | |
2896 ;; and return t | |
2897 t)) | |
2898 t))) | |
2899 | |
2900 (defun speedbar-check-obj-this-line (depth) | |
2901 "Return t if the file on this line has an associated object. | |
2902 Parameter DEPTH is a string with the current depth of indentation of | |
2903 the file being checked." | |
2904 (let* ((d (string-to-int depth)) | |
2905 (f (speedbar-line-path d)) | |
2906 (fn (buffer-substring-no-properties | |
2907 ;; Skip-chars: thanks ptype@dra.hmg.gb | |
2908 (point) (progn | |
2909 (skip-chars-forward "^ " | |
2910 (save-excursion (end-of-line) | |
2911 (point))) | |
2912 (point)))) | |
2913 (fulln (concat f fn))) | |
2914 (if (<= 2 speedbar-verbosity-level) | |
2915 (message "Speedbar obj check...%s" fulln)) | |
2916 (let ((oa speedbar-obj-alist)) | |
2917 (while (and oa (not (string-match (car (car oa)) fulln))) | |
2918 (setq oa (cdr oa))) | |
2919 (if (not (and oa (file-exists-p (concat (file-name-sans-extension fulln) | |
2920 (cdr (car oa)))))) | |
2921 nil | |
2922 ;; Find out if the object is out of date or not. | |
2923 (let ((date1 (nth 5 (file-attributes fulln))) | |
2924 (date2 (nth 5 (file-attributes (concat | |
2925 (file-name-sans-extension fulln) | |
2926 (cdr (car oa))))))) | |
2927 (if (or (< (car date1) (car date2)) | |
2928 (and (= (car date1) (car date2)) | |
2929 (< (nth 1 date1) (nth 1 date2)))) | |
2930 (car speedbar-obj-indicator) | |
2931 (cdr speedbar-obj-indicator))))))) | |
21650 | 2932 |
2933 ;;; Clicking Activity | |
2934 ;; | |
2935 (defun speedbar-quick-mouse (e) | |
2936 "Since mouse events are strange, this will keep the mouse nicely positioned. | |
2937 This should be bound to mouse event E." | |
2938 (interactive "e") | |
2939 (mouse-set-point e) | |
2940 (speedbar-position-cursor-on-line) | |
2941 ) | |
2942 | |
2943 (defun speedbar-position-cursor-on-line () | |
2944 "Position the cursor on a line." | |
2945 (let ((oldpos (point))) | |
2946 (beginning-of-line) | |
2947 (if (looking-at "[0-9]+:\\s-*..?.? ") | |
2948 (goto-char (1- (match-end 0))) | |
2949 (goto-char oldpos)))) | |
2950 | |
2951 (defun speedbar-power-click (e) | |
2952 "Activate any speedbar button as a power click. | |
2953 This should be bound to mouse event E." | |
2954 (interactive "e") | |
2955 (let ((speedbar-power-click t)) | |
2956 (speedbar-click e))) | |
2957 | |
2958 (defun speedbar-click (e) | |
2959 "Activate any speedbar buttons where the mouse is clicked. | |
2960 This must be bound to a mouse event. A button is any location of text | |
2961 with a mouse face that has a text property called `speedbar-function'. | |
2962 This should be bound to mouse event E." | |
2963 (interactive "e") | |
2964 (mouse-set-point e) | |
2965 (speedbar-do-function-pointer) | |
2966 (speedbar-quick-mouse e)) | |
2967 | |
2968 (defun speedbar-double-click (e) | |
2969 "Activate any speedbar buttons where the mouse is clicked. | |
2970 This must be bound to a mouse event. A button is any location of text | |
2971 with a mouse face that has a text property called `speedbar-function'. | |
2972 This should be bound to mouse event E." | |
2973 (interactive "e") | |
2974 ;; Emacs only. XEmacs handles this via `mouse-track-click-hook'. | |
2975 (cond ((eq (car e) 'down-mouse-1) | |
2976 (mouse-set-point e)) | |
2977 ((eq (car e) 'mouse-1) | |
2978 (speedbar-quick-mouse e)) | |
2979 ((or (eq (car e) 'double-down-mouse-1) | |
22735 | 2980 (eq (car e) 'triple-down-mouse-1)) |
21650 | 2981 (mouse-set-point e) |
2982 (speedbar-do-function-pointer) | |
2983 (speedbar-quick-mouse e)))) | |
2984 | |
2985 (defun speedbar-do-function-pointer () | |
2986 "Look under the cursor and examine the text properties. | |
2987 From this extract the file/tag name, token, indentation level and call | |
2988 a function if appropriate" | |
2989 (let* ((fn (get-text-property (point) 'speedbar-function)) | |
2990 (tok (get-text-property (point) 'speedbar-token)) | |
2991 ;; The 1-,+ is safe because scaning starts AFTER the point | |
2992 ;; specified. This lets the search include the character the | |
2993 ;; cursor is on. | |
2994 (tp (previous-single-property-change | |
2995 (1+ (point)) 'speedbar-function)) | |
2996 (np (next-single-property-change | |
2997 (point) 'speedbar-function)) | |
2998 (txt (buffer-substring-no-properties (or tp (point-min)) | |
2999 (or np (point-max)))) | |
3000 (dent (save-excursion (beginning-of-line) | |
3001 (string-to-number | |
3002 (if (looking-at "[0-9]+") | |
3003 (buffer-substring-no-properties | |
3004 (match-beginning 0) (match-end 0)) | |
3005 "0"))))) | |
3006 ;;(message "%S:%S:%S:%s" fn tok txt dent) | |
3007 (and fn (funcall fn txt tok dent))) | |
3008 (speedbar-position-cursor-on-line)) | |
3009 | |
3010 ;;; Reading info from the speedbar buffer | |
3011 ;; | |
3012 (defun speedbar-line-file (&optional p) | |
3013 "Retrieve the file or whatever from the line at P point. | |
3014 The return value is a string representing the file. If it is a | |
3015 directory, then it is the directory name." | |
3016 (save-excursion | |
3017 (save-match-data | |
3018 (beginning-of-line) | |
3019 (if (looking-at (concat | |
3020 "\\([0-9]+\\): *[[<][-+?][]>] \\([^ \n]+\\)\\(" | |
22735 | 3021 speedbar-indicator-regex "\\)?")) |
21650 | 3022 (let* ((depth (string-to-int (match-string 1))) |
3023 (path (speedbar-line-path depth)) | |
3024 (f (match-string 2))) | |
3025 (concat path f)) | |
3026 nil)))) | |
3027 | |
3028 (defun speedbar-goto-this-file (file) | |
3029 "If FILE is displayed, goto this line and return t. | |
3030 Otherwise do not move and return nil." | |
3031 (let ((path (substring (file-name-directory (expand-file-name file)) | |
3032 (length (expand-file-name default-directory)))) | |
3033 (dest (point))) | |
3034 (save-match-data | |
3035 (goto-char (point-min)) | |
3036 ;; scan all the directories | |
3037 (while (and path (not (eq path t))) | |
3038 (if (string-match "^/?\\([^/]+\\)" path) | |
3039 (let ((pp (match-string 1 path))) | |
3040 (if (save-match-data | |
3041 (re-search-forward (concat "> " (regexp-quote pp) "$") | |
3042 nil t)) | |
3043 (setq path (substring path (match-end 1))) | |
3044 (setq path nil))) | |
3045 (setq path t))) | |
3046 ;; find the file part | |
3047 (if (or (not path) (string= (file-name-nondirectory file) "")) | |
3048 ;; only had a dir part | |
3049 (if path | |
3050 (progn | |
3051 (speedbar-position-cursor-on-line) | |
3052 t) | |
3053 (goto-char dest) nil) | |
3054 ;; find the file part | |
3055 (let ((nd (file-name-nondirectory file))) | |
3056 (if (re-search-forward | |
3057 (concat "] \\(" (regexp-quote nd) | |
22735 | 3058 "\\)\\(" speedbar-indicator-regex "\\)$") |
21650 | 3059 nil t) |
3060 (progn | |
3061 (speedbar-position-cursor-on-line) | |
3062 t) | |
3063 (goto-char dest) | |
3064 nil)))))) | |
3065 | |
3066 (defun speedbar-line-path (depth) | |
3067 "Retrieve the pathname associated with the current line. | |
3068 This may require traversing backwards from DEPTH and combining the default | |
3069 directory with these items." | |
22735 | 3070 (cond |
3071 ((string= speedbar-initial-expansion-list-name "files") | |
3072 (save-excursion | |
3073 (save-match-data | |
3074 (let ((path nil)) | |
3075 (setq depth (1- depth)) | |
3076 (while (/= depth -1) | |
3077 (if (not (re-search-backward (format "^%d:" depth) nil t)) | |
3078 (error "Error building path of tag") | |
3079 (cond ((looking-at "[0-9]+:\\s-*<->\\s-+\\([^\n]+\\)$") | |
3080 (setq path (concat (buffer-substring-no-properties | |
3081 (match-beginning 1) (match-end 1)) | |
3082 "/" | |
3083 path))) | |
3084 ((looking-at "[0-9]+:\\s-*[-]\\s-+\\([^\n]+\\)$") | |
3085 ;; This is the start of our path. | |
3086 (setq path (buffer-substring-no-properties | |
3087 (match-beginning 1) (match-end 1)))))) | |
3088 (setq depth (1- depth))) | |
3089 (if (and path | |
3090 (string-match (concat speedbar-indicator-regex "$") | |
3091 path)) | |
3092 (setq path (substring path 0 (match-beginning 0)))) | |
3093 (concat default-directory path))))) | |
3094 (t | |
3095 ;; If we aren't in file mode, then return an empty string to make | |
3096 ;; sure that we can still get some stuff done. | |
3097 ""))) | |
21650 | 3098 |
3099 (defun speedbar-path-line (path) | |
3100 "Position the cursor on the line specified by PATH." | |
3101 (save-match-data | |
3102 (if (string-match "/$" path) | |
3103 (setq path (substring path 0 (match-beginning 0)))) | |
3104 (let ((nomatch t) (depth 0) | |
3105 (fname (file-name-nondirectory path)) | |
3106 (pname (file-name-directory path))) | |
3107 (if (not (member pname speedbar-shown-directories)) | |
22735 | 3108 (error "Internal Error: File %s not shown in speedbar" path)) |
21650 | 3109 (goto-char (point-min)) |
3110 (while (and nomatch | |
3111 (re-search-forward | |
3112 (concat "[]>] \\(" (regexp-quote fname) | |
22735 | 3113 "\\)\\(" speedbar-indicator-regex "\\)?$") |
21650 | 3114 nil t)) |
3115 (beginning-of-line) | |
3116 (looking-at "\\([0-9]+\\):") | |
3117 (setq depth (string-to-int (match-string 0)) | |
3118 nomatch (not (string= pname (speedbar-line-path depth)))) | |
3119 (end-of-line)) | |
3120 (beginning-of-line) | |
3121 (not nomatch)))) | |
3122 | |
3123 (defun speedbar-edit-line () | |
3124 "Edit whatever tag or file is on the current speedbar line." | |
3125 (interactive) | |
3126 (or (save-excursion | |
3127 (beginning-of-line) | |
3128 ;; If this fails, then it is a non-standard click, and as such, | |
3129 ;; perfectly allowed. | |
22950
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
3130 (if (re-search-forward "[]>?}] [^ ]" |
21650 | 3131 (save-excursion (end-of-line) (point)) |
3132 t) | |
3133 (speedbar-do-function-pointer) | |
3134 nil)) | |
3135 (speedbar-do-function-pointer))) | |
3136 | |
3137 (defun speedbar-expand-line () | |
3138 "Expand the line under the cursor." | |
3139 (interactive) | |
3140 (beginning-of-line) | |
3141 (re-search-forward ":\\s-*.\\+. " (save-excursion (end-of-line) (point))) | |
3142 (forward-char -2) | |
3143 (speedbar-do-function-pointer)) | |
3144 | |
3145 (defun speedbar-contract-line () | |
3146 "Contract the line under the cursor." | |
3147 (interactive) | |
3148 (beginning-of-line) | |
3149 (re-search-forward ":\\s-*.-. " (save-excursion (end-of-line) (point))) | |
3150 (forward-char -2) | |
3151 (speedbar-do-function-pointer)) | |
3152 | |
3153 (if speedbar-xemacsp | |
3154 (defalias 'speedbar-mouse-event-p 'button-press-event-p) | |
3155 (defun speedbar-mouse-event-p (event) | |
3156 "Return t if the event is a mouse related event" | |
3157 ;; And Emacs does it this way | |
3158 (if (and (listp event) | |
3159 (member (event-basic-type event) | |
3160 '(mouse-1 mouse-2 mouse-3))) | |
3161 t | |
3162 nil))) | |
3163 | |
3164 (defun speedbar-maybee-jump-to-attached-frame () | |
3165 "Jump to the attached frame ONLY if this was not a mouse event." | |
3166 (if (or (not (speedbar-mouse-event-p last-input-event)) | |
3167 speedbar-activity-change-focus-flag) | |
3168 (progn | |
3169 (select-frame speedbar-attached-frame) | |
3170 (other-frame 0)))) | |
3171 | |
3172 (defun speedbar-find-file (text token indent) | |
3173 "Speedbar click handler for filenames. | |
3174 TEXT, the file will be displayed in the attached frame. | |
3175 TOKEN is unused, but required by the click handler. INDENT is the | |
3176 current indentation level." | |
3177 (let ((cdd (speedbar-line-path indent))) | |
3178 (speedbar-find-file-in-frame (concat cdd text)) | |
3179 (speedbar-stealthy-updates) | |
3180 (run-hooks 'speedbar-visiting-file-hook) | |
3181 ;; Reset the timer with a new timeout when cliking a file | |
3182 ;; in case the user was navigating directories, we can cancel | |
3183 ;; that other timer. | |
3184 (speedbar-set-timer speedbar-update-speed)) | |
3185 (speedbar-maybee-jump-to-attached-frame)) | |
3186 | |
3187 (defun speedbar-dir-follow (text token indent) | |
3188 "Speedbar click handler for directory names. | |
3189 Clicking a directory will cause the speedbar to list files in the | |
3190 the subdirectory TEXT. TOKEN is an unused requirement. The | |
3191 subdirectory chosen will be at INDENT level." | |
3192 (setq default-directory | |
3193 (concat (expand-file-name (concat (speedbar-line-path indent) text)) | |
3194 "/")) | |
3195 ;; Because we leave speedbar as the current buffer, | |
3196 ;; update contents will change directory without | |
22735 | 3197 ;; having to touch the attached frame. Turn off smart expand just |
3198 ;; in case. | |
3199 (let ((speedbar-smart-directory-expand-flag nil)) | |
3200 (speedbar-update-contents)) | |
21650 | 3201 (speedbar-set-timer speedbar-navigating-speed) |
3202 (setq speedbar-last-selected-file nil) | |
3203 (speedbar-stealthy-updates)) | |
3204 | |
3205 (defun speedbar-delete-subblock (indent) | |
3206 "Delete text from point to indentation level INDENT or greater. | |
3207 Handles end-of-sublist smartly." | |
3208 (speedbar-with-writable | |
22950
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
3209 (save-excursion |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
3210 (end-of-line) (forward-char 1) |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
3211 (let ((start (point))) |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
3212 (while (and (looking-at "^\\([0-9]+\\):") |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
3213 (> (string-to-int (match-string 1)) indent) |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
3214 (not (eobp))) |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
3215 (forward-line 1) |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
3216 (beginning-of-line)) |
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
3217 (delete-region start (point)))))) |
21650 | 3218 |
3219 (defun speedbar-dired (text token indent) | |
3220 "Speedbar click handler for directory expand button. | |
3221 Clicking this button expands or contracts a directory. TEXT is the | |
3222 button clicked which has either a + or -. TOKEN is the directory to be | |
3223 expanded. INDENT is the current indentation level." | |
3224 (cond ((string-match "+" text) ;we have to expand this dir | |
3225 (setq speedbar-shown-directories | |
3226 (cons (expand-file-name | |
3227 (concat (speedbar-line-path indent) token "/")) | |
3228 speedbar-shown-directories)) | |
3229 (speedbar-change-expand-button-char ?-) | |
3230 (speedbar-reset-scanners) | |
3231 (save-excursion | |
3232 (end-of-line) (forward-char 1) | |
3233 (speedbar-with-writable | |
3234 (speedbar-default-directory-list | |
3235 (concat (speedbar-line-path indent) token "/") | |
3236 (1+ indent))))) | |
3237 ((string-match "-" text) ;we have to contract this node | |
3238 (speedbar-reset-scanners) | |
3239 (let ((oldl speedbar-shown-directories) | |
3240 (newl nil) | |
3241 (td (expand-file-name | |
3242 (concat (speedbar-line-path indent) token)))) | |
3243 (while oldl | |
3244 (if (not (string-match (concat "^" (regexp-quote td)) (car oldl))) | |
3245 (setq newl (cons (car oldl) newl))) | |
3246 (setq oldl (cdr oldl))) | |
3247 (setq speedbar-shown-directories newl)) | |
3248 (speedbar-change-expand-button-char ?+) | |
3249 (speedbar-delete-subblock indent) | |
3250 ) | |
22735 | 3251 (t (error "Ooops... not sure what to do"))) |
21650 | 3252 (speedbar-center-buffer-smartly) |
3253 (setq speedbar-last-selected-file nil) | |
3254 (save-excursion (speedbar-stealthy-updates))) | |
3255 | |
3256 (defun speedbar-directory-buttons-follow (text token indent) | |
3257 "Speedbar click handler for default directory buttons. | |
3258 TEXT is the button clicked on. TOKEN is the directory to follow. | |
3259 INDENT is the current indentation level and is unused." | |
22893
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
3260 (if (string-match "^[A-z]:$" token) |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
3261 (setq default-directory (concat token (char-to-string directory-sep-char))) |
22735 | 3262 (setq default-directory token)) |
21650 | 3263 ;; Because we leave speedbar as the current buffer, |
3264 ;; update contents will change directory without | |
3265 ;; having to touch the attached frame. | |
3266 (speedbar-update-contents) | |
3267 (speedbar-set-timer speedbar-navigating-speed)) | |
3268 | |
3269 (defun speedbar-tag-file (text token indent) | |
3270 "The cursor is on a selected line. Expand the tags in the specified file. | |
3271 The parameter TEXT and TOKEN are required, where TEXT is the button | |
3272 clicked, and TOKEN is the file to expand. INDENT is the current | |
3273 indentation level." | |
3274 (cond ((string-match "+" text) ;we have to expand this file | |
3275 (let* ((fn (expand-file-name (concat (speedbar-line-path indent) | |
3276 token))) | |
3277 (lst (if speedbar-use-imenu-flag | |
3278 (let ((tim (speedbar-fetch-dynamic-imenu fn))) | |
3279 (if (eq tim t) | |
3280 (speedbar-fetch-dynamic-etags fn) | |
3281 tim)) | |
3282 (speedbar-fetch-dynamic-etags fn)))) | |
3283 ;; if no list, then remove expando button | |
3284 (if (not lst) | |
3285 (speedbar-change-expand-button-char ??) | |
3286 (speedbar-change-expand-button-char ?-) | |
3287 (speedbar-with-writable | |
3288 (save-excursion | |
3289 (end-of-line) (forward-char 1) | |
3290 (speedbar-insert-generic-list indent | |
3291 lst 'speedbar-tag-expand | |
3292 'speedbar-tag-find)))))) | |
3293 ((string-match "-" text) ;we have to contract this node | |
3294 (speedbar-change-expand-button-char ?+) | |
3295 (speedbar-delete-subblock indent)) | |
22735 | 3296 (t (error "Ooops... not sure what to do"))) |
21650 | 3297 (speedbar-center-buffer-smartly)) |
3298 | |
3299 (defun speedbar-tag-find (text token indent) | |
3300 "For the tag TEXT in a file TOKEN, goto that position. | |
3301 INDENT is the current indentation level." | |
3302 (let ((file (speedbar-line-path indent))) | |
3303 (speedbar-find-file-in-frame file) | |
3304 (save-excursion (speedbar-stealthy-updates)) | |
3305 ;; Reset the timer with a new timeout when cliking a file | |
3306 ;; in case the user was navigating directories, we can cancel | |
3307 ;; that other timer. | |
3308 (speedbar-set-timer speedbar-update-speed) | |
3309 (goto-char token) | |
3310 (run-hooks 'speedbar-visiting-tag-hook) | |
3311 ;;(recenter) | |
3312 (speedbar-maybee-jump-to-attached-frame) | |
3313 )) | |
3314 | |
3315 (defun speedbar-tag-expand (text token indent) | |
3316 "Expand a tag sublist. Imenu will return sub-lists of specialized tag types. | |
3317 Etags does not support this feature. TEXT will be the button | |
3318 string. TOKEN will be the list, and INDENT is the current indentation | |
3319 level." | |
3320 (cond ((string-match "+" text) ;we have to expand this file | |
3321 (speedbar-change-expand-button-char ?-) | |
3322 (speedbar-with-writable | |
3323 (save-excursion | |
3324 (end-of-line) (forward-char 1) | |
22735 | 3325 (speedbar-insert-generic-list indent token 'speedbar-tag-expand |
21650 | 3326 'speedbar-tag-find)))) |
3327 ((string-match "-" text) ;we have to contract this node | |
3328 (speedbar-change-expand-button-char ?+) | |
3329 (speedbar-delete-subblock indent)) | |
22735 | 3330 (t (error "Ooops... not sure what to do"))) |
21650 | 3331 (speedbar-center-buffer-smartly)) |
3332 | |
3333 ;;; Loading files into the attached frame. | |
3334 ;; | |
3335 (defun speedbar-find-file-in-frame (file) | |
3336 "This will load FILE into the speedbar attached frame. | |
3337 If the file is being displayed in a different frame already, then raise that | |
3338 frame instead." | |
3339 (let* ((buff (find-file-noselect file)) | |
3340 (bwin (get-buffer-window buff 0))) | |
3341 (if bwin | |
3342 (progn | |
3343 (select-window bwin) | |
3344 (raise-frame (window-frame bwin))) | |
3345 (if speedbar-power-click | |
3346 (let ((pop-up-frames t)) (select-window (display-buffer buff))) | |
3347 (select-frame speedbar-attached-frame) | |
3348 (switch-to-buffer buff)))) | |
22735 | 3349 ) |
21650 | 3350 |
3351 ;;; Centering Utility | |
3352 ;; | |
3353 (defun speedbar-center-buffer-smartly () | |
3354 "Recenter a speedbar buffer so the current indentation level is all visible. | |
3355 This assumes that the cursor is on a file, or tag of a file which the user is | |
3356 interested in." | |
3357 (if (<= (count-lines (point-min) (point-max)) | |
22893
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
3358 (1- (window-height (selected-window)))) |
21650 | 3359 ;; whole buffer fits |
3360 (let ((cp (point))) | |
3361 (goto-char (point-min)) | |
3362 (recenter 0) | |
3363 (goto-char cp)) | |
3364 ;; too big | |
3365 (let (depth start end exp p) | |
3366 (save-excursion | |
3367 (beginning-of-line) | |
3368 (setq depth (if (looking-at "[0-9]+") | |
3369 (string-to-int (buffer-substring-no-properties | |
3370 (match-beginning 0) (match-end 0))) | |
3371 0)) | |
3372 (setq exp (format "^%d:\\s-*[[{<]\\([?+-]\\)[]>}]" depth))) | |
3373 (save-excursion | |
3374 (end-of-line) | |
3375 (if (re-search-backward exp nil t) | |
3376 (setq start (point)) | |
22950
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
3377 (setq start (point-min))) |
21650 | 3378 (save-excursion ;Not sure about this part. |
3379 (end-of-line) | |
3380 (setq p (point)) | |
3381 (while (and (not (re-search-forward exp nil t)) | |
3382 (>= depth 0)) | |
3383 (setq depth (1- depth)) | |
3384 (setq exp (format "^%d:\\s-*[[{<]\\([?+-]\\)[]>}]" depth))) | |
3385 (if (/= (point) p) | |
3386 (setq end (point)) | |
3387 (setq end (point-max))))) | |
3388 ;; Now work out the details of centering | |
3389 (let ((nl (count-lines start end)) | |
3390 (cp (point))) | |
3391 (if (> nl (window-height (selected-window))) | |
3392 ;; We can't fit it all, so just center on cursor | |
3393 (progn (goto-char start) | |
3394 (recenter 1)) | |
3395 ;; we can fit everything on the screen, but... | |
3396 (if (and (pos-visible-in-window-p start (selected-window)) | |
3397 (pos-visible-in-window-p end (selected-window))) | |
3398 ;; we are all set! | |
3399 nil | |
3400 ;; we need to do something... | |
3401 (goto-char start) | |
3402 (let ((newcent (/ (- (window-height (selected-window)) nl) 2)) | |
3403 (lte (count-lines start (point-max)))) | |
3404 (if (and (< (+ newcent lte) (window-height (selected-window))) | |
3405 (> (- (window-height (selected-window)) lte 1) | |
3406 newcent)) | |
3407 (setq newcent (- (window-height (selected-window)) | |
3408 lte 1))) | |
3409 (recenter newcent)))) | |
3410 (goto-char cp))))) | |
3411 | |
3412 | |
3413 ;;; Tag Management -- Imenu | |
3414 ;; | |
3415 (if (not speedbar-use-imenu-flag) | |
3416 | |
3417 nil | |
3418 | |
3419 (eval-when-compile (if (locate-library "imenu") (require 'imenu))) | |
3420 | |
3421 (defun speedbar-fetch-dynamic-imenu (file) | |
3422 "Load FILE into a buffer, and generate tags using Imenu. | |
3423 Returns the tag list, or t for an error." | |
3424 ;; Load this AND compile it in | |
3425 (require 'imenu) | |
3426 (save-excursion | |
3427 (set-buffer (find-file-noselect file)) | |
3428 (if speedbar-power-click (setq imenu--index-alist nil)) | |
3429 (condition-case nil | |
3430 (let ((index-alist (imenu--make-index-alist t))) | |
3431 (if speedbar-sort-tags | |
3432 (sort (copy-alist index-alist) | |
3433 (lambda (a b) (string< (car a) (car b)))) | |
3434 index-alist)) | |
3435 (error t)))) | |
3436 ) | |
3437 | |
3438 ;;; Tag Management -- etags (old XEmacs compatibility part) | |
3439 ;; | |
3440 (defvar speedbar-fetch-etags-parse-list | |
3441 '(;; Note that java has the same parse-group as c | |
3442 ("\\.\\([cChH]\\|c\\+\\+\\|cpp\\|cc\\|hh\\|java\\)\\'" . | |
3443 speedbar-parse-c-or-c++tag) | |
3444 ("^\\.emacs$\\|.\\(el\\|l\\|lsp\\)\\'" . | |
3445 "def[^i]+\\s-+\\(\\(\\w\\|[-_]\\)+\\)\\s-*\C-?") | |
22735 | 3446 ; ("\\.\\([fF]\\|for\\|FOR\\|77\\|90\\)\\'" . |
3447 ; speedbar-parse-fortran77-tag) | |
21650 | 3448 ("\\.tex\\'" . speedbar-parse-tex-string) |
3449 ("\\.p\\'" . | |
3450 "\\(\\(FUNCTION\\|function\\|PROCEDURE\\|procedure\\)\\s-+\\([a-zA-Z0-9_.:]+\\)\\)\\s-*(?^?") | |
3451 ) | |
3452 "Associations of file extensions and expressions for extracting tags. | |
3453 To add a new file type, you would want to add a new association to the | |
3454 list, where the car is the file match, and the cdr is the way to | |
3455 extract an element from the tags output. If the output is complex, | |
3456 use a function symbol instead of regexp. The function should expect | |
3457 to be at the beginning of a line in the etags buffer. | |
3458 | |
3459 This variable is ignored if `speedbar-use-imenu-flag' is non-nil.") | |
3460 | |
3461 (defvar speedbar-fetch-etags-command "etags" | |
3462 "*Command used to create an etags file. | |
3463 | |
3464 This variable is ignored if `speedbar-use-imenu-flag' is t") | |
3465 | |
3466 (defvar speedbar-fetch-etags-arguments '("-D" "-I" "-o" "-") | |
3467 "*List of arguments to use with `speedbar-fetch-etags-command'. | |
3468 This creates an etags output buffer. Use `speedbar-toggle-etags' to | |
3469 modify this list conveniently. | |
3470 | |
3471 This variable is ignored if `speedbar-use-imenu-flag' is t") | |
3472 | |
3473 (defun speedbar-toggle-etags (flag) | |
3474 "Toggle FLAG in `speedbar-fetch-etags-arguments'. | |
3475 FLAG then becomes a member of etags command line arguments. If flag | |
3476 is \"sort\", then toggle the value of `speedbar-sort-tags'. If its | |
3477 value is \"show\" then toggle the value of | |
3478 `speedbar-show-unknown-files'. | |
3479 | |
3480 This function is a convenience function for XEmacs menu created by | |
3481 Farzin Guilak <farzin@protocol.com>" | |
3482 (interactive) | |
3483 (cond | |
3484 ((equal flag "sort") | |
3485 (setq speedbar-sort-tags (not speedbar-sort-tags))) | |
3486 ((equal flag "show") | |
3487 (setq speedbar-show-unknown-files (not speedbar-show-unknown-files))) | |
3488 ((or (equal flag "-C") | |
3489 (equal flag "-S") | |
3490 (equal flag "-D")) | |
3491 (if (member flag speedbar-fetch-etags-arguments) | |
3492 (setq speedbar-fetch-etags-arguments | |
3493 (delete flag speedbar-fetch-etags-arguments)) | |
3494 (add-to-list 'speedbar-fetch-etags-arguments flag))) | |
3495 (t nil))) | |
3496 | |
3497 (defun speedbar-fetch-dynamic-etags (file) | |
3498 "For FILE, run etags and create a list of symbols extracted. | |
3499 Each symbol will be associated with its line position in FILE." | |
3500 (let ((newlist nil)) | |
3501 (unwind-protect | |
3502 (save-excursion | |
3503 (if (get-buffer "*etags tmp*") | |
3504 (kill-buffer "*etags tmp*")) ;kill to clean it up | |
3505 (if (<= 1 speedbar-verbosity-level) (message "Fetching etags...")) | |
3506 (set-buffer (get-buffer-create "*etags tmp*")) | |
3507 (apply 'call-process speedbar-fetch-etags-command nil | |
3508 (current-buffer) nil | |
3509 (append speedbar-fetch-etags-arguments (list file))) | |
3510 (goto-char (point-min)) | |
3511 (if (<= 1 speedbar-verbosity-level) (message "Fetching etags...")) | |
3512 (let ((expr | |
3513 (let ((exprlst speedbar-fetch-etags-parse-list) | |
3514 (ans nil)) | |
3515 (while (and (not ans) exprlst) | |
3516 (if (string-match (car (car exprlst)) file) | |
3517 (setq ans (car exprlst))) | |
3518 (setq exprlst (cdr exprlst))) | |
3519 (cdr ans)))) | |
3520 (if expr | |
3521 (let (tnl) | |
3522 (while (not (save-excursion (end-of-line) (eobp))) | |
3523 (save-excursion | |
3524 (setq tnl (speedbar-extract-one-symbol expr))) | |
3525 (if tnl (setq newlist (cons tnl newlist))) | |
3526 (forward-line 1))) | |
3527 (message "Sorry, no support for a file of that extension")))) | |
3528 ) | |
3529 (if speedbar-sort-tags | |
3530 (sort newlist (lambda (a b) (string< (car a) (car b)))) | |
3531 (reverse newlist)))) | |
3532 | |
3533 ;; This bit donated by Farzin Guilak <farzin@protocol.com> but I'm not | |
3534 ;; sure it's needed with the different sorting method. | |
3535 ;; | |
3536 ;(defun speedbar-clean-etags() | |
3537 ; "Removes spaces before the ^? character, and removes `#define', | |
3538 ;return types, etc. preceding tags. This ensures that the sort operation | |
3539 ;works on the tags, not the return types." | |
3540 ; (save-excursion | |
3541 ; (goto-char (point-min)) | |
3542 ; (while | |
3543 ; (re-search-forward "(?[ \t](?\C-?" nil t) | |
3544 ; (replace-match "\C-?" nil nil)) | |
3545 ; (goto-char (point-min)) | |
3546 ; (while | |
3547 ; (re-search-forward "\\(.*[ \t]+\\)\\([^ \t\n]+.*\C-?\\)" nil t) | |
3548 ; (delete-region (match-beginning 1) (match-end 1))))) | |
3549 | |
3550 (defun speedbar-extract-one-symbol (expr) | |
22735 | 3551 "At point, return nil, or one alist in the form: (SYMBOL . POSITION) |
21650 | 3552 The line should contain output from etags. Parse the output using the |
3553 regular expression EXPR" | |
3554 (let* ((sym (if (stringp expr) | |
3555 (if (save-excursion | |
3556 (re-search-forward expr (save-excursion | |
3557 (end-of-line) | |
3558 (point)) t)) | |
3559 (buffer-substring-no-properties (match-beginning 1) | |
3560 (match-end 1))) | |
3561 (funcall expr))) | |
3562 (pos (let ((j (re-search-forward "[\C-?\C-a]\\([0-9]+\\),\\([0-9]+\\)" | |
3563 (save-excursion | |
3564 (end-of-line) | |
3565 (point)) | |
3566 t))) | |
3567 (if (and j sym) | |
3568 (1+ (string-to-int (buffer-substring-no-properties | |
3569 (match-beginning 2) | |
3570 (match-end 2)))) | |
3571 0)))) | |
3572 (if (/= pos 0) | |
3573 (cons sym pos) | |
3574 nil))) | |
3575 | |
3576 (defun speedbar-parse-c-or-c++tag () | |
3577 "Parse a c or c++ tag, which tends to be a little complex." | |
3578 (save-excursion | |
3579 (let ((bound (save-excursion (end-of-line) (point)))) | |
3580 (cond ((re-search-forward "\C-?\\([^\C-a]+\\)\C-a" bound t) | |
3581 (buffer-substring-no-properties (match-beginning 1) | |
3582 (match-end 1))) | |
3583 ((re-search-forward "\\<\\([^ \t]+\\)\\s-+new(" bound t) | |
3584 (buffer-substring-no-properties (match-beginning 1) | |
3585 (match-end 1))) | |
3586 ((re-search-forward "\\<\\([^ \t(]+\\)\\s-*(\C-?" bound t) | |
3587 (buffer-substring-no-properties (match-beginning 1) | |
3588 (match-end 1))) | |
3589 (t nil)) | |
3590 ))) | |
3591 | |
3592 (defun speedbar-parse-tex-string () | |
3593 "Parse a Tex string. Only find data which is relevant." | |
3594 (save-excursion | |
3595 (let ((bound (save-excursion (end-of-line) (point)))) | |
3596 (cond ((re-search-forward "\\(\\(sub\\)*section\\|chapter\\|cite\\)\\s-*{[^\C-?}]*}?" bound t) | |
3597 (buffer-substring-no-properties (match-beginning 0) | |
3598 (match-end 0))) | |
3599 (t nil))))) | |
3600 | |
3601 | |
22735 | 3602 ;;; BUFFER DISPLAY mode. |
3603 ;; | |
3604 (defvar speedbar-buffers-key-map nil | |
3605 "Keymap used when in the buffers display mode.") | |
3606 | |
3607 (if speedbar-buffers-key-map | |
3608 nil | |
3609 (setq speedbar-buffers-key-map (speedbar-make-specialized-keymap)) | |
3610 | |
3611 ;; Basic tree features | |
3612 (define-key speedbar-buffers-key-map "e" 'speedbar-edit-line) | |
3613 (define-key speedbar-buffers-key-map "\C-m" 'speedbar-edit-line) | |
3614 (define-key speedbar-buffers-key-map "+" 'speedbar-expand-line) | |
3615 (define-key speedbar-buffers-key-map "-" 'speedbar-contract-line) | |
3616 | |
3617 ;; Buffer specific keybindings | |
3618 (define-key speedbar-buffers-key-map "k" 'speedbar-buffer-kill-buffer) | |
3619 (define-key speedbar-buffers-key-map "r" 'speedbar-buffer-revert-buffer) | |
3620 | |
3621 ) | |
3622 | |
3623 (defvar speedbar-buffer-easymenu-definition | |
3624 '(["Jump to buffer" speedbar-edit-line t] | |
3625 ["Expand File Tags" speedbar-expand-line | |
3626 (save-excursion (beginning-of-line) | |
3627 (looking-at "[0-9]+: *.\\+. "))] | |
3628 ["Contract File Tags" speedbar-contract-line | |
3629 (save-excursion (beginning-of-line) | |
3630 (looking-at "[0-9]+: *.-. "))] | |
3631 ) | |
3632 "Menu item elements shown when displaying a buffer list.") | |
3633 | |
3634 (defun speedbar-buffer-buttons (directory zero) | |
3635 "Create speedbar buttons based on the buffers currently loaded. | |
3636 DIRECTORY is the path to the currently active buffer, and ZERO is 0." | |
3637 (speedbar-buffer-buttons-engine nil)) | |
3638 | |
3639 (defun speedbar-buffer-buttons-temp (directory zero) | |
3640 "Create speedbar buttons based on the buffers currently loaded. | |
3641 DIRECTORY is the path to the currently active buffer, and ZERO is 0." | |
3642 (speedbar-buffer-buttons-engine t)) | |
3643 | |
3644 (defun speedbar-buffer-buttons-engine (temp) | |
3645 "Create speedbar buffer buttons. | |
3646 If TEMP is non-nil, then clicking on a buffer restores the previous display." | |
3647 (insert "Active Buffers:\n") | |
3648 (let ((bl (buffer-list))) | |
3649 (while bl | |
3650 (if (string-match "^[ *]" (buffer-name (car bl))) | |
3651 nil | |
3652 (let* ((known (string-match speedbar-file-regexp | |
3653 (buffer-name (car bl)))) | |
3654 (expchar (if known ?+ ??)) | |
3655 (fn (if known 'speedbar-tag-file nil)) | |
3656 (fname (save-excursion (set-buffer (car bl)) | |
3657 (buffer-file-name)))) | |
3658 (speedbar-make-tag-line 'bracket expchar fn fname | |
3659 (buffer-name (car bl)) | |
3660 'speedbar-buffer-click temp | |
3661 'speedbar-file-face 0))) | |
3662 (setq bl (cdr bl))) | |
3663 (setq bl (buffer-list)) | |
3664 (insert "Scratch Buffers:\n") | |
3665 (while bl | |
3666 (if (not (string-match "^\\*" (buffer-name (car bl)))) | |
3667 nil | |
3668 (if (eq (car bl) speedbar-buffer) | |
3669 nil | |
3670 (speedbar-make-tag-line 'bracket ?? nil nil | |
3671 (buffer-name (car bl)) | |
3672 'speedbar-buffer-click temp | |
3673 'speedbar-file-face 0))) | |
3674 (setq bl (cdr bl))) | |
3675 (setq bl (buffer-list)) | |
3676 (insert "Hidden Buffers:\n") | |
3677 (while bl | |
3678 (if (not (string-match "^ " (buffer-name (car bl)))) | |
3679 nil | |
3680 (if (eq (car bl) speedbar-buffer) | |
3681 nil | |
3682 (speedbar-make-tag-line 'bracket ?? nil nil | |
3683 (buffer-name (car bl)) | |
3684 'speedbar-buffer-click temp | |
3685 'speedbar-file-face 0))) | |
3686 (setq bl (cdr bl))))) | |
3687 | |
3688 (defun speedbar-buffer-click (text token indent) | |
3689 "When the users clicks on a buffer-button in speedbar. | |
3690 TEXT is the buffer's name, TOKEN and INDENT are unused." | |
3691 (if speedbar-power-click | |
3692 (let ((pop-up-frames t)) (select-window (display-buffer text))) | |
3693 (select-frame speedbar-attached-frame) | |
3694 (switch-to-buffer text) | |
3695 (if token (speedbar-change-initial-expansion-list | |
3696 speedbar-previously-used-expansion-list-name)))) | |
3697 | |
3698 (defun speedbar-buffer-kill-buffer () | |
3699 "Kill the buffer the cursor is on in the speedbar buffer." | |
3700 (interactive) | |
3701 (or (save-excursion | |
3702 (beginning-of-line) | |
3703 ;; If this fails, then it is a non-standard click, and as such, | |
3704 ;; perfectly allowed. | |
22950
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
3705 (if (re-search-forward "[]>?}] [^ ]" |
22735 | 3706 (save-excursion (end-of-line) (point)) |
3707 t) | |
3708 (let ((text (progn | |
3709 (forward-char -1) | |
3710 (buffer-substring (point) (save-excursion | |
3711 (end-of-line) | |
3712 (point)))))) | |
3713 (if (and (get-buffer text) | |
3714 (y-or-n-p (format "Kill buffer %s? " text))) | |
22893
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
3715 (kill-buffer text)) |
322179a8fd20
(speedbar-update-current-file): Added call to
Eric M. Ludlam <zappo@gnu.org>
parents:
22735
diff
changeset
|
3716 (speedbar-refresh)))))) |
22735 | 3717 |
3718 (defun speedbar-buffer-revert-buffer () | |
3719 "Revert the buffer the cursor is on in the speedbar buffer." | |
3720 (interactive) | |
3721 (save-excursion | |
3722 (beginning-of-line) | |
3723 ;; If this fails, then it is a non-standard click, and as such, | |
3724 ;; perfectly allowed | |
22950
606be1490be7
(speedbar-edit-line, speedbar-buffer-kill-buffer,
Eric M. Ludlam <zappo@gnu.org>
parents:
22906
diff
changeset
|
3725 (if (re-search-forward "[]>?}] [^ ]" |
22735 | 3726 (save-excursion (end-of-line) (point)) |
3727 t) | |
3728 (let ((text (progn | |
3729 (forward-char -1) | |
3730 (buffer-substring (point) (save-excursion | |
3731 (end-of-line) | |
3732 (point)))))) | |
3733 (if (get-buffer text) | |
3734 (progn | |
3735 (set-buffer text) | |
3736 (revert-buffer t))))))) | |
3737 | |
3738 | |
3739 | |
21650 | 3740 ;;; Color loading section This is messy *Blech!* |
3741 ;; | |
3742 (defface speedbar-button-face '((((class color) (background light)) | |
3743 (:foreground "green4")) | |
3744 (((class color) (background dark)) | |
3745 (:foreground "green3"))) | |
3746 "Face used for +/- buttons." | |
3747 :group 'speedbar-faces) | |
3748 | |
3749 (defface speedbar-file-face '((((class color) (background light)) | |
3750 (:foreground "cyan4")) | |
3751 (((class color) (background dark)) | |
3752 (:foreground "cyan")) | |
3753 (t (:bold t))) | |
3754 "Face used for file names." | |
3755 :group 'speedbar-faces) | |
3756 | |
3757 (defface speedbar-directory-face '((((class color) (background light)) | |
3758 (:foreground "blue4")) | |
3759 (((class color) (background dark)) | |
3760 (:foreground "light blue"))) | |
3761 "Faced used for directory names." | |
3762 :group 'speedbar-faces) | |
3763 (defface speedbar-tag-face '((((class color) (background light)) | |
3764 (:foreground "brown")) | |
3765 (((class color) (background dark)) | |
3766 (:foreground "yellow"))) | |
3767 "Face used for displaying tags." | |
3768 :group 'speedbar-faces) | |
3769 | |
3770 (defface speedbar-selected-face '((((class color) (background light)) | |
3771 (:foreground "red" :underline t)) | |
3772 (((class color) (background dark)) | |
3773 (:foreground "red" :underline t)) | |
3774 (t (:underline t))) | |
3775 "Face used to underline the file in the active window." | |
3776 :group 'speedbar-faces) | |
3777 | |
3778 (defface speedbar-highlight-face '((((class color) (background light)) | |
3779 (:background "green")) | |
3780 (((class color) (background dark)) | |
3781 (:background "sea green")) | |
3782 (((class grayscale monochrome) | |
3783 (background light)) | |
3784 (:background "black")) | |
3785 (((class grayscale monochrome) | |
3786 (background dark)) | |
3787 (:background "white"))) | |
3788 "Face used for highlighting buttons with the mouse." | |
3789 :group 'speedbar-faces) | |
3790 | |
3791 ;; some edebug hooks | |
3792 (add-hook 'edebug-setup-hook | |
3793 (lambda () | |
3794 (def-edebug-spec speedbar-with-writable def-body))) | |
3795 | |
3796 (provide 'speedbar) | |
3797 ;;; speedbar ends here | |
3798 | |
3799 ;; run load-time hooks | |
3800 (run-hooks 'speedbar-load-hook) |