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