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