speedbar.el 158 KB
Newer Older
1
;;; speedbar.el --- quick access to files and tags in a frame
Dan Nicolaescu's avatar
Dan Nicolaescu committed
2

3
;;; Copyright (C) 1996, 97, 98, 99, 2000, 01 Free Software Foundation
Karl Heuer's avatar
Karl Heuer committed
4 5

;; Author: Eric M. Ludlam <zappo@gnu.org>
6
;; Version: 0.11a
Karl Heuer's avatar
Karl Heuer committed
7 8
;; Keywords: file, tags, tools

Dan Nicolaescu's avatar
Dan Nicolaescu committed
9
;; This file is part of GNU Emacs.
Karl Heuer's avatar
Karl Heuer committed
10

Dan Nicolaescu's avatar
Dan Nicolaescu committed
11 12 13 14
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
Karl Heuer's avatar
Karl Heuer committed
15

Dan Nicolaescu's avatar
Dan Nicolaescu committed
16 17 18 19
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
Karl Heuer's avatar
Karl Heuer committed
20

Dan Nicolaescu's avatar
Dan Nicolaescu committed
21 22 23 24 25 26 27 28 29 30 31 32 33
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Commentary:
;;
;;   The speedbar provides a frame in which files, and locations in
;; files are displayed.  These items can be clicked on with mouse-2
;; in order to make the last active frame display that file location.
;;
;; Starting Speedbar:
;;
34 35
;;   Simply type `M-x speedbar', and it will be autoloaded for you.

Karl Heuer's avatar
Karl Heuer committed
36
;;   If you want to choose it from a menu, such as "Tools", you can do this:
Dan Nicolaescu's avatar
Dan Nicolaescu committed
37 38 39 40 41 42
;;
;;   (define-key-after (lookup-key global-map [menu-bar tools])
;;      [speedbar] '("Speedbar" . speedbar-frame-mode) [calendar])
;;
;;   If you want to access speedbar using only the keyboard, do this:
;;
43
;;   (global-set-key [f4] 'speedbar-get-focus)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
;;
;;   This will let you hit f4 (or whatever key you choose) to jump
;; focus to the speedbar frame.  Pressing it again will bring you back
;; to the attached frame.  Pressing RET or e to jump to a file
;; or tag will move you back to the attached frame.  The command
;; `speedbar-get-focus' will also create a speedbar frame if it does
;; not exist.
;;
;; Customizing Speedbar:
;;
;;   Once a speedbar frame is active, it takes advantage of idle time
;; to keep its contents updated.  The contents is usually a list of
;; files in the directory of the currently active buffer.  When
;; applicable, tags in the active file can be expanded.
;;
;;   To add new supported files types into speedbar, use the function
60
;; `speedbar-add-supported-extension'.  If speedbar complains that the
Dan Nicolaescu's avatar
Dan Nicolaescu committed
61 62 63 64 65 66
;; file type is not supported, that means there is no built in
;; support from imenu, and the etags part wasn't set up correctly.  You
;; may add elements to `speedbar-supported-extension-expressions' as long
;; as it is done before speedbar is loaded.
;;
;;   To prevent speedbar from following you into certain directories
67
;; use the function `speedbar-add-ignored-path-regexp' to add a new
Dan Nicolaescu's avatar
Dan Nicolaescu committed
68 69 70 71 72
;; regular expression matching a type of path.  You may add list
;; elements to `speedbar-ignored-path-expressions' as long as it is
;; done before speedbar is loaded.
;;
;;   To add new file types to imenu, see the documentation in the
Karl Heuer's avatar
Karl Heuer committed
73
;; file imenu.el that comes with Emacs.  To add new file types which
Dan Nicolaescu's avatar
Dan Nicolaescu committed
74 75 76 77 78 79 80 81 82 83 84 85
;; etags supports, you need to modify the variable
;; `speedbar-fetch-etags-parse-list'.
;;
;;    If the updates are going too slow for you, modify the variable
;; `speedbar-update-speed' to a longer idle time before updates.
;;
;;    If you navigate directories, you will probably notice that you
;; will navigate to a directory which is eventually replaced after
;; you go back to editing a file (unless you pull up a new file.)
;; The delay time before this happens is in
;; `speedbar-navigating-speed', and defaults to 10 seconds.
;;
Karl Heuer's avatar
Karl Heuer committed
86 87 88 89 90 91 92
;;    To enable mouse tracking with information in the minibuffer of
;; the attached frame, use the variable `speedbar-track-mouse-flag'.
;;
;;    Tag layout can be modified through `speedbar-tag-hierarchy-method',
;; which controls how tags are layed out.  It is actually a list of
;; functions that filter the data.  The default groups large tag lists
;; into sub-lists.  A long flat list can be used instead if needed.
93
;; Other filters can be easily added.
Karl Heuer's avatar
Karl Heuer committed
94
;;
95
;;    AUC-TEX users: The imenu tags for AUC-TEX mode doesn't work very
Dan Nicolaescu's avatar
Dan Nicolaescu committed
96 97
;; well.  Use the imenu keywords from tex-mode.el for better results.
;;
98 99
;; This file requires the library package assoc (association lists)
;;
Karl Heuer's avatar
Karl Heuer committed
100
;;; Developing for speedbar
Dan Nicolaescu's avatar
Dan Nicolaescu committed
101
;;
Karl Heuer's avatar
Karl Heuer committed
102
;; Adding a speedbar specialized display mode:
Dan Nicolaescu's avatar
Dan Nicolaescu committed
103
;;
Karl Heuer's avatar
Karl Heuer committed
104
;; Speedbar can be configured to create a special display for certain
105
;; modes that do not display traditional file/tag data.  Rmail, Info,
Karl Heuer's avatar
Karl Heuer committed
106 107 108 109 110 111 112 113 114 115 116 117 118
;; and the debugger are examples.  These modes can, however, benefit
;; from a speedbar style display in their own way.
;;
;; If your `major-mode' is `foo-mode', the only requirement is to
;; create a function called `foo-speedbar-buttons' which takes one
;; argument, BUFFER.  BUFFER will be the buffer speedbar wants filled.
;; In `foo-speedbar-buttons' there are several functions that make
;; building a speedbar display easy.  See the documentation for
;; `speedbar-with-writable' (needed because the buffer is usually
;; read-only) `speedbar-make-tag-line', `speedbar-insert-button', and
;; `speedbar-insert-generic-list'.  If you use
;; `speedbar-insert-generic-list', also read the doc for
;; `speedbar-tag-hierarchy-method' in case you wish to override it.
119
;; The macro `speedbar-with-attached-buffer' brings you back to the
Karl Heuer's avatar
Karl Heuer committed
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
;; buffer speedbar is displaying for.
;;
;; For those functions that make buttons, the "function" should be a
;; symbol that is the function to call when clicked on.  The "token"
;; is extra data you can pass along.  The "function" must take three
;; parameters.  They are (TEXT TOKEN INDENT).  TEXT is the text of the
;; button clicked on.  TOKEN is the data passed in when you create the
;; button.  INDENT is an indentation level, or 0.  You can store
;; indentation levels with `speedbar-make-tag-line' which creates a
;; line with an expander (eg.  [+]) and a text button.
;;
;; Some useful functions when writing expand functions, and click
;; functions are `speedbar-change-expand-button-char',
;; `speedbar-delete-subblock', and `speedbar-center-buffer-smartly'.
;; The variable `speedbar-power-click' is set to t in your functions
135
;; when the user shift-clicks.  This is an indication of anything from
Karl Heuer's avatar
Karl Heuer committed
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
;; refreshing cached data to making a buffer appear in a new frame.
;;
;; If you wish to add to the default speedbar menu for the case of
;; `foo-mode', create a variable `foo-speedbar-menu-items'.  This
;; should be a list compatible with the `easymenu' package.  It will
;; be spliced into the main menu.  (Available with click-mouse-3).  If
;; you wish to have extra key bindings in your special mode, create a
;; variable `foo-speedbar-key-map'.  Instead of using `make-keymap',
;; or `make-sparse-keymap', use the function
;; `speedbar-make-specialized-keymap'.  This lets you inherit all of
;; speedbar's default bindings with low overhead.
;;
;; Adding a speedbar top-level display mode:
;;
;; Unlike the specialized modes, there are no name requirements,
;; however the methods for writing a button display, menu, and keymap
;; are the same.  Once you create these items, you can call the
;; function `speedbar-add-expansion-list'.  It takes one parameter
;; which is a list element of the form (NAME MENU KEYMAP &rest
;; BUTTON-FUNCTIONS).  NAME is a string that will show up in the
;; Displays menu item.  MENU is a symbol containing the menu items to
;; splice in.  KEYMAP is a symbol holding the keymap to use, and
;; BUTTON-FUNCTIONS are the function names to call, in order, to create
;; the display.
160
;;  Another tweakable variable is `speedbar-stealthy-function-list'
161 162 163 164 165
;; which is of the form (NAME &rest FUNCTION ...).  NAME is the string
;; name matching `speedbar-add-expansion-list'.  (It does not need to
;; exist.). This provides additional display info which might be
;; time-consuming to calculate.
;;  Lastly, `speedbar-mode-functions-list' allows you to set special
166 167
;; function overrides.  At the moment very few functions may be
;; overridden, but more will be added as the need is discovered.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
168 169 170 171 172 173 174 175

;;; TODO:
;; - More functions to create buttons and options
;; - Timeout directories we haven't visited in a while.

(require 'assoc)
(require 'easymenu)

176 177 178 179
(condition-case nil
    (require 'image)
  (error nil))

Karl Heuer's avatar
Karl Heuer committed
180 181 182
(defvar speedbar-xemacsp (string-match "XEmacs" emacs-version)
  "Non-nil if we are running in the XEmacs environment.")
(defvar speedbar-xemacs20p (and speedbar-xemacsp
183
				(>= emacs-major-version 20)))
Karl Heuer's avatar
Karl Heuer committed
184

Dan Nicolaescu's avatar
Dan Nicolaescu committed
185 186 187 188
;; customization stuff
(defgroup speedbar nil
  "File and tag browser frame."
  :group 'tags
Dan Nicolaescu's avatar
Dan Nicolaescu committed
189
  :group 'tools
Dan Nicolaescu's avatar
Dan Nicolaescu committed
190
  :group 'convenience
Dan Nicolaescu's avatar
Dan Nicolaescu committed
191
  :version "20.3")
Dan Nicolaescu's avatar
Dan Nicolaescu committed
192 193 194 195 196 197 198 199 200 201 202 203 204

(defgroup speedbar-faces nil
  "Faces used in speedbar."
  :prefix "speedbar-"
  :group 'speedbar
  :group 'faces)

(defgroup speedbar-vc nil
  "Version control display in speedbar."
  :prefix "speedbar-"
  :group 'speedbar)

;;; Code:
Karl Heuer's avatar
Karl Heuer committed
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
(defvar speedbar-initial-expansion-mode-alist
  '(("buffers" speedbar-buffer-easymenu-definition speedbar-buffers-key-map
     speedbar-buffer-buttons)
    ("quick buffers" speedbar-buffer-easymenu-definition speedbar-buffers-key-map
     speedbar-buffer-buttons-temp)
    ;; Files last, means first in the Displays menu
    ("files" speedbar-easymenu-definition-special speedbar-file-key-map
     speedbar-directory-buttons speedbar-default-directory-list)
    )
  "List of named expansion elements for filling the speedbar frame.
These expansion lists are only valid for regular files.  Special modes
still get to override this list on a mode-by-mode basis.  This list of
lists is of the form (NAME MENU KEYMAP FN1 FN2 ...).  NAME is a string
representing the types of things to be displayed.  MENU is an easymenu
structure used when in this mode.  KEYMAP is a local keymap to install
over the regular speedbar keymap.  FN1 ...  are functions that will be
called in order.  These functions will always get the default
directory to use passed in as the first parameter, and a 0 as the
second parameter.  The 0 indicates the uppermost indentation level.
They must assume that the cursor is at the position where they start
inserting buttons.")

227
(defvar speedbar-initial-expansion-list-name "files"
Karl Heuer's avatar
Karl Heuer committed
228 229
  "A symbol name representing the expansion list to use.
The expansion list `speedbar-initial-expansion-mode-alist' contains
230
the names and associated functions to use for buttons in speedbar.")
Karl Heuer's avatar
Karl Heuer committed
231 232 233 234 235

(defvar speedbar-previously-used-expansion-list-name "files"
  "Save the last expansion list method.
This is used for returning to a previous expansion list method when
the user is done with the current expansion list.")
Dan Nicolaescu's avatar
Dan Nicolaescu committed
236 237

(defvar speedbar-stealthy-function-list
Karl Heuer's avatar
Karl Heuer committed
238 239 240
  '(("files"
     speedbar-update-current-file speedbar-check-vc speedbar-check-objects)
    )
Dan Nicolaescu's avatar
Dan Nicolaescu committed
241
  "List of functions to periodically call stealthily.
Karl Heuer's avatar
Karl Heuer committed
242 243 244 245 246
This list is of the form:
 '( (\"NAME\" FUNCTION ...)
    ...)
where NAME is the name of the major display mode these functions are
for, and the remaining elements FUNCTION are functions to call in order.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
247 248 249 250 251 252
Each function must return nil if interrupted, or t if completed.
Stealthy functions which have a single operation should always return
t.  Functions which take a long time should maintain a state (where
they are in their speedbar related calculations) and permit
interruption.  See `speedbar-check-vc' as a good example.")

253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
(defvar speedbar-mode-functions-list
  '(("files" (speedbar-item-info . speedbar-files-item-info)
     (speedbar-line-path . speedbar-files-line-path))
    ("buffers" (speedbar-item-info . speedbar-buffers-item-info)
     (speedbar-line-path . speedbar-buffers-line-path))
    ("quick buffers" (speedbar-item-info . speedbar-buffers-item-info)
     (speedbar-line-path . speedbar-buffers-line-path))
    )
  "List of function tables to use for different major display modes.
It is not necessary to define any functions for a specialized mode.
This just provides a simple way of adding lots of customizations.
Each sublist is of the form:
  (\"NAME\" (FUNCTIONSYMBOL . REPLACEMENTFUNCTION) ...)
Where NAME is the name of the specialized mode.  The rest of the list
is a set of dotted pairs of the form FUNCTIONSYMBOL, which is the name
of a function you would like to replace, and REPLACEMENTFUNCTION,
which is a function you can call instead.  Not all functions can be
replaced this way.  Replaceable functions must provide that
functionality individually.")

Dan Nicolaescu's avatar
Dan Nicolaescu committed
273 274 275 276 277 278 279 280
(defcustom speedbar-mode-specific-contents-flag t
  "*Non-nil means speedbar will show special mode contents.
This permits some modes to create customized contents for the speedbar
frame."
  :group 'speedbar
  :type 'boolean)

(defvar speedbar-special-mode-expansion-list nil
Karl Heuer's avatar
Karl Heuer committed
281 282 283 284 285
  "Default function list for creating specialized button lists.
This list is set by modes that wish to have special speedbar displays.
The list is of function names.  Each function is called with one
parameter BUFFER, the originating buffer.  The current buffer is the
speedbar buffer.")
Dan Nicolaescu's avatar
Dan Nicolaescu committed
286

Karl Heuer's avatar
Karl Heuer committed
287 288 289
(defvar speedbar-special-mode-key-map nil
  "Default keymap used when identifying a specialized display mode.
This keymap is local to each buffer that wants to define special keybindings
290
effective when its display is shown.")
Dan Nicolaescu's avatar
Dan Nicolaescu committed
291 292 293 294 295 296

(defcustom speedbar-visiting-file-hook nil
  "Hooks run when speedbar visits a file in the selected frame."
  :group 'speedbar
  :type 'hook)

297
(defcustom speedbar-visiting-tag-hook '(speedbar-highlight-one-tag-line)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
298 299
  "Hooks run when speedbar visits a tag in the selected frame."
  :group 'speedbar
300
  :type 'hook
301
  :version "21.1"
302 303 304 305
  :options '(speedbar-highlight-one-tag-line
	     speedbar-recenter-to-top
	     speedbar-recenter
	     ))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
306 307 308 309 310 311

(defcustom speedbar-load-hook nil
  "Hooks run when speedbar is loaded."
  :group 'speedbar
  :type 'hook)

312 313 314
(defcustom speedbar-reconfigure-keymaps-hook nil
  "Hooks run when the keymaps are regenerated."
  :group 'speedbar
315
  :version "21.1"
316 317
  :type 'hook)

Dan Nicolaescu's avatar
Dan Nicolaescu committed
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
(defcustom speedbar-show-unknown-files nil
  "*Non-nil show files we can't expand with a ? in the expand button.
nil means don't show the file in the list."
  :group 'speedbar
  :type 'boolean)

(defcustom speedbar-update-speed
  (if speedbar-xemacsp
      (if speedbar-xemacs20p
	  2				; 1 is too obrusive in XEmacs
	5)				; when no idleness, need long delay
    1)
  "*Idle time in seconds needed before speedbar will update itself.
Updates occur to allow speedbar to display directory information
relevant to the buffer you are currently editing."
  :group 'speedbar
  :type 'integer)

Karl Heuer's avatar
Karl Heuer committed
336 337 338 339
;; When I moved to a repeating timer, I had the horrible missfortune
;; of loosing the ability for adaptive speed choice.  This update
;; speed currently causes long delays when it should have been turned off.
(defcustom speedbar-navigating-speed speedbar-update-speed
Dan Nicolaescu's avatar
Dan Nicolaescu committed
340 341 342 343 344 345 346 347 348 349
  "*Idle time to wait after navigation commands in speedbar are executed.
Navigation commands included expanding/contracting nodes, and moving
between different directories."
  :group 'speedbar
  :type 'integer)

(defcustom speedbar-frame-parameters '((minibuffer . nil)
				       (width . 20)
				       (border-width . 0)
				       (menu-bar-lines . 0)
350
				       (tool-bar-lines . 0)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
351 352
				       (unsplittable . t))
  "*Parameters to use when creating the speedbar frame in Emacs.
353 354 355
Any parameter supported by a frame may be added.  The parameter `height'
will be initialized to the height of the frame speedbar is
attached to and added to this list before the new frame is initialized."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
356 357 358 359 360 361 362 363
  :group 'speedbar
  :type '(repeat (sexp :tag "Parameter:")))

;; These values by Hrvoje Niksic <hniksic@srce.hr>
(defcustom speedbar-frame-plist
  '(minibuffer nil width 20 border-width 0
	       internal-border-width 0 unsplittable t
	       default-toolbar-visible-p nil has-modeline-p nil
364
	       menubar-visible-p nil)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
365 366 367 368 369 370 371 372 373 374 375 376 377
  "*Parameters to use when creating the speedbar frame in XEmacs.
Parameters not listed here which will be added automatically are
`height' which will be initialized to the height of the frame speedbar
is attached to."
  :group 'speedbar
  :type '(repeat (group :inline t
			(symbol :tag "Property")
			(sexp :tag "Value"))))

(defcustom speedbar-use-imenu-flag (stringp (locate-library "imenu"))
  "*Non-nil means use imenu for file parsing.  nil to use etags.
XEmacs prior to 20.4 doesn't support imenu, therefore the default is to
use etags instead.  Etags support is not as robust as imenu support."
378
  :tag "Use Imenu for tags"
Dan Nicolaescu's avatar
Dan Nicolaescu committed
379 380 381
  :group 'speedbar
  :type 'boolean)

382 383 384
(defvar speedbar-dynamic-tags-function-list
  '((speedbar-fetch-dynamic-imenu . speedbar-insert-imenu-list)
    (speedbar-fetch-dynamic-etags . speedbar-insert-etags-list))
385
  "Set to a list of functions which will return and insert a list of tags.
386
Each element is of the form ( FETCH .  INSERT ) where FETCH
387
is a function which takes one parameter (the file to tag) and returns a
388 389
list of tags.  The tag list can be of any form as long as the
corresponding insert method can handle it.  If it returns t, then an
390
error occurred, and the next fetch routine is tried.
391 392 393
INSERT is a function which takes an INDENTation level, and a LIST of
tags to insert.  It will then create the speedbar buttons.")

Karl Heuer's avatar
Karl Heuer committed
394 395 396 397 398
(defcustom speedbar-track-mouse-flag t
  "*Non-nil means to display info about the line under the mouse."
  :group 'speedbar
  :type 'boolean)

Dan Nicolaescu's avatar
Dan Nicolaescu committed
399
(defcustom speedbar-sort-tags nil
Pavel Janík's avatar
Pavel Janík committed
400
  "*If non-nil, sort tags in the speedbar display.  *Obsolete*."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
401 402 403
  :group 'speedbar
  :type 'boolean)

Karl Heuer's avatar
Karl Heuer committed
404
(defcustom speedbar-tag-hierarchy-method
405 406 407 408 409
  '(speedbar-prefix-group-tag-hierarchy
    speedbar-trim-words-tag-hierarchy)
  "*List of hooks which speedbar will use to organize tags into groups.
Groups are defined as expandable meta-tags.  Imenu supports
such things in some languages, such as separating variables from
410
functions.  Each hook takes one argument LST, and may destructively
411 412 413 414 415 416
create a new list of the same form.  LST is a list of elements of the
form:
  (ELT1 ELT2 ... ELTn)
where each ELT is of the form
  (TAG-NAME-STRING . NUMBER-OR-MARKER)
or
417
  (GROUP-NAME-STRING ELT1 ELT2... ELTn)"
Karl Heuer's avatar
Karl Heuer committed
418
  :group 'speedbar
419 420 421 422 423 424
  :type 'hook
  :options '(speedbar-sort-tag-hierarchy
	     speedbar-trim-words-tag-hierarchy
	     speedbar-prefix-group-tag-hierarchy
	     speedbar-simple-group-tag-hierarchy)
  )
Karl Heuer's avatar
Karl Heuer committed
425

426 427 428 429 430 431 432 433 434 435 436 437
(defcustom speedbar-tag-group-name-minimum-length 4
  "*The minimum length of a prefix group name before expanding.
Thus, if the `speedbar-tag-hierarchy-method' includes `prefix-group'
and one such groups common characters is less than this number of
characters, then the group name will be changed to the form of:
  worda to wordb
instead of just
  word
This way we won't get silly looking listings."
  :group 'speedbar
  :type 'integer)

Karl Heuer's avatar
Karl Heuer committed
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
(defcustom speedbar-tag-split-minimum-length 20
  "*Minimum length before we stop trying to create sub-lists in tags.
This is used by all tag-hierarchy methods that break large lists into
sub-lists."
  :group 'speedbar
  :type 'integer)

(defcustom speedbar-tag-regroup-maximum-length 10
  "*Maximum length of submenus that are regrouped.
If the regrouping option is used, then if two or more short subgroups
are next to each other, then they are combined until this number of
items is reached."
  :group 'speedbar
  :type 'integer)

Dan Nicolaescu's avatar
Dan Nicolaescu committed
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
(defcustom speedbar-activity-change-focus-flag nil
  "*Non-nil means the selected frame will change based on activity.
Thus, if a file is selected for edit, the buffer will appear in the
selected frame and the focus will change to that frame."
  :group 'speedbar
  :type 'boolean)

(defcustom speedbar-directory-button-trim-method 'span
  "*Indicates how the directory button will be displayed.
Possible values are:
 'span - span large directories over multiple lines.
 'trim - trim large directories to only show the last few.
 nil   - no trimming."
  :group 'speedbar
  :type '(radio (const :tag "Span large directories over mutiple lines."
		       span)
		(const :tag "Trim large directories to only show the last few."
		       trim)
		(const :tag "No trimming." nil)))

(defcustom speedbar-smart-directory-expand-flag t
  "*Non-nil means speedbar should use smart expansion.
Smart expansion only affects when speedbar wants to display a
directory for a file in the attached frame.  When smart expansion is
enabled, new directories which are children of a displayed directory
are expanded in the current framework.  If nil, then the current
hierarchy would be replaced with the new directory."
  :group 'speedbar
  :type 'boolean)

483 484 485
(defcustom speedbar-indentation-width 1
  "*When sub-nodes are expanded, the number of spaces used for indentation."
  :group 'speedbar
486
  :version "21.1"
487 488 489 490 491
  :type 'integer)

(defcustom speedbar-hide-button-brackets-flag nil
  "*Non-nil means speedbar will hide the brackets around the + or -."
  :group 'speedbar
492
  :version "21.1"
493 494 495 496
  :type 'boolean)

(defcustom speedbar-use-images (and (or (fboundp 'defimage)
					(fboundp 'make-image-specifier))
497 498 499
				    (if (fboundp 'display-graphic-p)
					(display-graphic-p)
				      window-system))
500
  "*Non-nil if speedbar should display icons."
501
  :group 'speedbar
502
  :version "21.1"
503
  :type 'boolean)
Karl Heuer's avatar
Karl Heuer committed
504

Dan Nicolaescu's avatar
Dan Nicolaescu committed
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
(defcustom speedbar-before-popup-hook nil
  "*Hooks called before popping up the speedbar frame."
  :group 'speedbar
  :type 'hook)

(defcustom speedbar-before-delete-hook nil
  "*Hooks called before deleting the speedbar frame."
  :group 'speedbar
  :type 'hook)

(defcustom speedbar-mode-hook nil
  "*Hooks called after creating a speedbar buffer."
  :group 'speedbar
  :type 'hook)

(defcustom speedbar-timer-hook nil
  "*Hooks called after running the speedbar timer function."
  :group 'speedbar
  :type 'hook)

(defcustom speedbar-verbosity-level 1
  "*Verbosity level of the speedbar.  0 means say nothing.
1 means medium level verbosity.  2 and higher are higher levels of
verbosity."
  :group 'speedbar
  :type 'integer)

Karl Heuer's avatar
Karl Heuer committed
532 533 534
(defvar speedbar-indicator-separator " "
  "String separating file text from indicator characters.")

Dan Nicolaescu's avatar
Dan Nicolaescu committed
535 536
(defcustom speedbar-vc-do-check t
  "*Non-nil check all files in speedbar to see if they have been checked out.
537
Any file checked out is marked with `speedbar-vc-indicator'."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
538 539 540
  :group 'speedbar-vc
  :type 'boolean)

Karl Heuer's avatar
Karl Heuer committed
541
(defvar speedbar-vc-indicator "*"
Dan Nicolaescu's avatar
Dan Nicolaescu committed
542
  "Text used to mark files which are currently checked out.
543 544
Other version control systems can be added by examining the function
`speedbar-vc-path-enable-hook' and `speedbar-vc-in-control-hook'.")
Dan Nicolaescu's avatar
Dan Nicolaescu committed
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562

(defcustom speedbar-vc-path-enable-hook nil
  "*Return non-nil if the current path should be checked for Version Control.
Functions in this hook must accept one parameter which is the path
being checked."
  :group 'speedbar-vc
  :type 'hook)

(defcustom speedbar-vc-in-control-hook nil
  "*Return non-nil if the specified file is under Version Control.
Functions in this hook must accept two parameters.  The PATH of the
current file, and the FILENAME of the file being checked."
  :group 'speedbar-vc
  :type 'hook)

(defvar speedbar-vc-to-do-point nil
  "Local variable maintaining the current version control check position.")

Karl Heuer's avatar
Karl Heuer committed
563 564 565
(defcustom speedbar-obj-do-check t
  "*Non-nil check all files in speedbar to see if they have an object file.
Any file checked out is marked with `speedbar-obj-indicator', and the
566
marking is based on  `speedbar-obj-alist'."
Karl Heuer's avatar
Karl Heuer committed
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
  :group 'speedbar-vc
  :type 'boolean)

(defvar speedbar-obj-to-do-point nil
  "Local variable maintaining the current version control check position.")

(defvar speedbar-obj-indicator '("#" . "!")
  "Text used to mark files that have a corresponding hidden object file.
The car is for an up-to-date object.  The cdr is for an out of date object.
The expression `speedbar-obj-alist' defines who gets tagged.")

(defvar speedbar-obj-alist
  '(("\\.\\([cpC]\\|cpp\\|cc\\)$" . ".o")
    ("\\.el$" . ".elc")
    ("\\.java$" . ".class")
    ("\\.f\\(or\\|90\\|77\\)?$" . ".o")
    ("\\.tex$" . ".dvi")
    ("\\.texi$" . ".info"))
  "Alist of file extensions, and their corresponding object file type.")

(defvar speedbar-indicator-regex
  (concat (regexp-quote speedbar-indicator-separator)
	  "\\("
	  (regexp-quote speedbar-vc-indicator)
	  "\\|"
	  (regexp-quote (car speedbar-obj-indicator))
	  "\\|"
	  (regexp-quote (cdr speedbar-obj-indicator))
	  "\\)*")
  "Regular expression used when identifying files.
Permits stripping of indicator characters from a line.")

(defcustom speedbar-scanner-reset-hook nil
  "*Hook called whenever generic scanners are reset.
Set this to implement your own scanning / rescan safe functions with
state data."
  :group 'speedbar
  :type 'hook)

Dan Nicolaescu's avatar
Dan Nicolaescu committed
606 607 608 609 610
(defvar speedbar-ignored-modes nil
  "*List of major modes which speedbar will not switch directories for.")

(defun speedbar-extension-list-to-regex (extlist)
  "Takes EXTLIST, a list of extensions and transforms it into regexp.
Karl Heuer's avatar
Karl Heuer committed
611 612
All the preceding `.' are stripped for an optimized expression starting
with `.' followed by extensions, followed by full-filenames."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
  (let ((regex1 nil) (regex2 nil))
    (while extlist
      (if (= (string-to-char (car extlist)) ?.)
	  (setq regex1 (concat regex1 (if regex1 "\\|" "")
			       (substring (car extlist) 1)))
	(setq regex2 (concat regex2 (if regex2 "\\|" "") (car extlist))))
      (setq extlist (cdr extlist)))
    ;; concat all the sub-exressions together, making sure all types
    ;; of parts exist during concatination.
    (concat "\\("
	    (if regex1 (concat "\\(\\.\\(" regex1 "\\)\\)") "")
	    (if (and regex1 regex2) "\\|" "")
	    (if regex2 (concat "\\(" regex2 "\\)") "")
	    "\\)$")))

(defvar speedbar-ignored-path-regexp nil
  "Regular expression matching paths speedbar will not switch to.
Created from `speedbar-ignored-path-expressions' with the function
`speedbar-extension-list-to-regex' (A misnamed function in this case.)
Use the function `speedbar-add-ignored-path-regexp', or customize the
variable `speedbar-ignored-path-expressions' to modify this variable.")

(defcustom speedbar-ignored-path-expressions
636
  '("[/\\]logs?[/\\]\\'")
Dan Nicolaescu's avatar
Dan Nicolaescu committed
637 638 639 640 641 642 643 644 645 646 647 648 649
  "*List of regular expressions matching directories speedbar will ignore.
They should included paths to directories which are notoriously very
large and take a long time to load in.  Use the function
`speedbar-add-ignored-path-regexp' to add new items to this list after
speedbar is loaded.  You may place anything you like in this list
before speedbar has been loaded."
  :group 'speedbar
  :type '(repeat (regexp :tag "Path Regexp"))
  :set (lambda (sym val)
	 (setq speedbar-ignored-path-expressions val
	       speedbar-ignored-path-regexp
	       (speedbar-extension-list-to-regex val))))

Karl Heuer's avatar
Karl Heuer committed
650 651 652 653 654 655 656
(defcustom speedbar-directory-unshown-regexp "^\\(CVS\\|RCS\\|SCCS\\)\\'"
  "*Regular expression matching directories not to show in speedbar.
They should include commonly existing directories which are not
useful, such as version control."
  :group 'speedbar
  :type 'string)

Dan Nicolaescu's avatar
Dan Nicolaescu committed
657 658 659 660 661 662
(defvar speedbar-file-unshown-regexp
  (let ((nstr "") (noext completion-ignored-extensions))
    (while noext
      (setq nstr (concat nstr (regexp-quote (car noext)) "\\'"
			 (if (cdr noext) "\\|" ""))
	    noext (cdr noext)))
663 664
    ;;               backup      refdir      lockfile
    (concat nstr "\\|#[^#]+#$\\|\\.\\.?\\'\\|\\.#"))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
665 666 667 668 669 670
  "*Regexp matching files we don't want displayed in a speedbar buffer.
It is generated from the variable `completion-ignored-extensions'")

;; this is dangerous to customize, because the defaults will probably
;; change in the future.
(defcustom speedbar-supported-extension-expressions
Karl Heuer's avatar
Karl Heuer committed
671 672
  (append '(".[ch]\\(\\+\\+\\|pp\\|c\\|h\\|xx\\)?" ".tex\\(i\\(nfo\\)?\\)?"
	    ".el" ".emacs" ".l" ".lsp" ".p" ".java" ".f\\(90\\|77\\|or\\)?")
Dan Nicolaescu's avatar
Dan Nicolaescu committed
673
	  (if speedbar-use-imenu-flag
674
	      '(".ada" ".p[lm]" ".tcl" ".m" ".scm" ".pm" ".py" ".g"
Karl Heuer's avatar
Karl Heuer committed
675 676 677
		;; html is not supported by default, but an imenu tags package
		;; is available.  Also, html files are nice to be able to see.
		".s?html"
678
		"[Mm]akefile\\(\\.in\\)?")))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
679 680 681 682 683 684 685 686 687
  "*List of regular expressions which will match files supported by tagging.
Do not prefix the `.' char with a double \\ to quote it, as the period
will be stripped by a simplified optimizer when compiled into a
singular expression.  This variable will be turned into
`speedbar-file-regexp' for use with speedbar.  You should use the
function `speedbar-add-supported-extension' to add a new extension at
runtime, or use the configuration dialog to set it in your .emacs
file."
  :group 'speedbar
688
  :version "21.1"
Dan Nicolaescu's avatar
Dan Nicolaescu committed
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706
  :type '(repeat (regexp :tag "Extension Regexp"))
  :set (lambda (sym val)
	 (setq speedbar-supported-extension-expressions val
	       speedbar-file-regexp (speedbar-extension-list-to-regex val)))
  )

(defvar speedbar-file-regexp
  (speedbar-extension-list-to-regex speedbar-supported-extension-expressions)
  "Regular expression matching files we know how to expand.
Created from `speedbar-supported-extension-expression' with the
function `speedbar-extension-list-to-regex'")

(defun speedbar-add-supported-extension (extension)
  "Add EXTENSION as a new supported extension for speedbar tagging.
This should start with a `.' if it is not a complete file name, and
the dot should NOT be quoted in with \\.  Other regular expression
matchers are allowed however.  EXTENSION may be a single string or a
list of strings."
Pavel Janík's avatar
Pavel Janík committed
707
  (interactive "sExtension: ")
Dan Nicolaescu's avatar
Dan Nicolaescu committed
708 709 710 711 712 713 714 715 716 717 718 719 720 721
  (if (not (listp extension)) (setq extension (list extension)))
  (while extension
    (if (member (car extension) speedbar-supported-extension-expressions)
	nil
      (setq speedbar-supported-extension-expressions
	    (cons (car extension) speedbar-supported-extension-expressions)))
    (setq extension (cdr extension)))
  (setq speedbar-file-regexp (speedbar-extension-list-to-regex
			      speedbar-supported-extension-expressions)))

(defun speedbar-add-ignored-path-regexp (path-expression)
  "Add PATH-EXPRESSION as a new ignored path for speedbar tracking.
This function will modify `speedbar-ignored-path-regexp' and add
PATH-EXPRESSION to `speedbar-ignored-path-expressions'."
Karl Heuer's avatar
Karl Heuer committed
722
  (interactive "sPath regex: ")
Dan Nicolaescu's avatar
Dan Nicolaescu committed
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740
  (if (not (listp path-expression))
      (setq path-expression (list path-expression)))
  (while path-expression
    (if (member (car path-expression) speedbar-ignored-path-expressions)
	nil
      (setq speedbar-ignored-path-expressions
	    (cons (car path-expression) speedbar-ignored-path-expressions)))
    (setq path-expression (cdr path-expression)))
  (setq speedbar-ignored-path-regexp (speedbar-extension-list-to-regex
				      speedbar-ignored-path-expressions)))

;; If we don't have custom, then we set it here by hand.
(if (not (fboundp 'custom-declare-variable))
    (setq speedbar-file-regexp (speedbar-extension-list-to-regex
				speedbar-supported-extension-expressions)
	  speedbar-ignored-path-regexp (speedbar-extension-list-to-regex
					speedbar-ignored-path-expressions)))

Karl Heuer's avatar
Karl Heuer committed
741 742 743 744
(defvar speedbar-update-flag (and
			      (or (fboundp 'run-with-idle-timer)
				  (fboundp 'start-itimer)
				  (boundp 'post-command-idle-hook))
745 746 747
			      (if (fboundp 'display-graphic-p)
				  (display-graphic-p)
				window-system))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766
  "*Non-nil means to automatically update the display.
When this is nil then speedbar will not follow the attached frame's path.
When speedbar is active, use:

\\<speedbar-key-map> `\\[speedbar-toggle-updates]'

to toggle this value.")

(defvar speedbar-syntax-table nil
  "Syntax-table used on the speedbar.")

(if speedbar-syntax-table
    nil
  (setq speedbar-syntax-table (make-syntax-table))
  ;; turn off paren matching around here.
  (modify-syntax-entry ?\' " " speedbar-syntax-table)
  (modify-syntax-entry ?\" " " speedbar-syntax-table)
  (modify-syntax-entry ?( " " speedbar-syntax-table)
  (modify-syntax-entry ?) " " speedbar-syntax-table)
767 768
  (modify-syntax-entry ?{ " " speedbar-syntax-table)
  (modify-syntax-entry ?} " " speedbar-syntax-table)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783
  (modify-syntax-entry ?[ " " speedbar-syntax-table)
  (modify-syntax-entry ?] " " speedbar-syntax-table))

(defvar speedbar-key-map nil
  "Keymap used in speedbar buffer.")

(if speedbar-key-map
    nil
  (setq speedbar-key-map (make-keymap))
  (suppress-keymap speedbar-key-map t)

  ;; control
  (define-key speedbar-key-map "g" 'speedbar-refresh)
  (define-key speedbar-key-map "t" 'speedbar-toggle-updates)
  (define-key speedbar-key-map "q" 'speedbar-close-frame)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
784
  (define-key speedbar-key-map "Q" 'delete-frame)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
785 786 787 788

  ;; navigation
  (define-key speedbar-key-map "n" 'speedbar-next)
  (define-key speedbar-key-map "p" 'speedbar-prev)
Karl Heuer's avatar
Karl Heuer committed
789 790 791 792
  (define-key speedbar-key-map "\M-n" 'speedbar-restricted-next)
  (define-key speedbar-key-map "\M-p" 'speedbar-restricted-prev)
  (define-key speedbar-key-map "\C-\M-n" 'speedbar-forward-list)
  (define-key speedbar-key-map "\C-\M-p" 'speedbar-backward-list)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
793 794 795
  (define-key speedbar-key-map " " 'speedbar-scroll-up)
  (define-key speedbar-key-map [delete] 'speedbar-scroll-down)

Karl Heuer's avatar
Karl Heuer committed
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811
  ;; Short cuts I happen to find useful
  (define-key speedbar-key-map "r"
    (lambda () (interactive)
      (speedbar-change-initial-expansion-list
       speedbar-previously-used-expansion-list-name)))
  (define-key speedbar-key-map "b"
    (lambda () (interactive)
      (speedbar-change-initial-expansion-list "quick buffers")))
  (define-key speedbar-key-map "f"
    (lambda () (interactive)
      (speedbar-change-initial-expansion-list "files")))

  ;; Overrides
  (substitute-key-definition 'switch-to-buffer
			     'speedbar-switch-buffer-attached-frame
			     speedbar-key-map global-map)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
812 813 814 815 816 817

  (if speedbar-xemacsp
      (progn
	;; mouse bindings so we can manipulate the items on each line
	(define-key speedbar-key-map 'button2 'speedbar-click)
	(define-key speedbar-key-map '(shift button2) 'speedbar-power-click)
Karl Heuer's avatar
Karl Heuer committed
818 819 820 821 822 823 824
	;; Info doc fix from Bob Weiner
	(if (featurep 'infodoc)
	    nil
	  (define-key speedbar-key-map 'button3 'speedbar-xemacs-popup-kludge))
	(define-key speedbar-key-map '(meta button3) 'speedbar-mouse-item-info)
	)

Dan Nicolaescu's avatar
Dan Nicolaescu committed
825 826 827 828 829 830 831 832 833 834 835 836 837
    ;; mouse bindings so we can manipulate the items on each line
    (define-key speedbar-key-map [down-mouse-1] 'speedbar-double-click)
    (define-key speedbar-key-map [mouse-2] 'speedbar-click)
    ;; This is the power click for new frames, or refreshing a cache
    (define-key speedbar-key-map [S-mouse-2] 'speedbar-power-click)
    ;; This adds a small unecessary visual effect
    ;;(define-key speedbar-key-map [down-mouse-2] 'speedbar-quick-mouse)
    (define-key speedbar-key-map [M-mouse-2] 'speedbar-mouse-item-info)

    (define-key speedbar-key-map [down-mouse-3] 'speedbar-emacs-popup-kludge)

    ;; This lets the user scroll as if we had a scrollbar... well maybe not
    (define-key speedbar-key-map [mode-line mouse-2] 'speedbar-mouse-hscroll)
Karl Heuer's avatar
Karl Heuer committed
838 839 840 841
    ;; another handy place users might click to get our menu.
    (define-key speedbar-key-map [mode-line down-mouse-1]
      'speedbar-emacs-popup-kludge)

842 843 844
    ;; We can't switch buffers with the buffer mouse menu.  Lets hack it.
    (define-key speedbar-key-map [C-down-mouse-1] 'speedbar-hack-buffer-menu)

Karl Heuer's avatar
Karl Heuer committed
845 846 847 848 849
    ;; Lastly, we want to track the mouse.  Play here
    (define-key speedbar-key-map [mouse-movement] 'speedbar-track-mouse)
   ))

(defun speedbar-make-specialized-keymap ()
850
  "Create a keymap for use with a speedbar major or minor display mode.
Karl Heuer's avatar
Karl Heuer committed
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867
This basically creates a sparse keymap, and makes it's parent be
`speedbar-key-map'."
  (let ((k (make-sparse-keymap)))
    (set-keymap-parent k speedbar-key-map)
    k))

(defvar speedbar-file-key-map nil
  "Keymap used in speedbar buffer while files are displayed.")

(if speedbar-file-key-map
    nil
  (setq speedbar-file-key-map (speedbar-make-specialized-keymap))

  ;; Basic tree features
  (define-key speedbar-file-key-map "e" 'speedbar-edit-line)
  (define-key speedbar-file-key-map "\C-m" 'speedbar-edit-line)
  (define-key speedbar-file-key-map "+" 'speedbar-expand-line)
868
  (define-key speedbar-file-key-map "=" 'speedbar-expand-line)
Karl Heuer's avatar
Karl Heuer committed
869 870 871 872 873 874 875 876 877 878 879 880
  (define-key speedbar-file-key-map "-" 'speedbar-contract-line)

  ;; file based commands
  (define-key speedbar-file-key-map "U" 'speedbar-up-directory)
  (define-key speedbar-file-key-map "I" 'speedbar-item-info)
  (define-key speedbar-file-key-map "B" 'speedbar-item-byte-compile)
  (define-key speedbar-file-key-map "L" 'speedbar-item-load)
  (define-key speedbar-file-key-map "C" 'speedbar-item-copy)
  (define-key speedbar-file-key-map "D" 'speedbar-item-delete)
  (define-key speedbar-file-key-map "O" 'speedbar-item-object-delete)
  (define-key speedbar-file-key-map "R" 'speedbar-item-rename)
  )
Dan Nicolaescu's avatar
Dan Nicolaescu committed
881 882

(defvar speedbar-easymenu-definition-base
883 884 885 886 887 888 889
  (append
   '("Speedbar"
     ["Update" speedbar-refresh t]
     ["Auto Update" speedbar-toggle-updates
      :style toggle :selected speedbar-update-flag])
   (if (and (or (fboundp 'defimage)
		(fboundp 'make-image-specifier))
890 891 892
	    (if (fboundp 'display-graphic-p)
		(display-graphic-p)
	      window-system))
893 894 895 896
       (list
	["Use Images" speedbar-toggle-images
	 :style toggle :selected speedbar-use-images]))
   )
Dan Nicolaescu's avatar
Dan Nicolaescu committed
897 898 899 900 901 902
  "Base part of the speedbar menu.")

(defvar speedbar-easymenu-definition-special
  '(["Edit Item On Line" speedbar-edit-line t]
    ["Show All Files" speedbar-toggle-show-all-files
     :style toggle :selected speedbar-show-unknown-files]
Karl Heuer's avatar
Karl Heuer committed
903
    ["Expand File Tags" speedbar-expand-line
Dan Nicolaescu's avatar
Dan Nicolaescu committed
904 905
     (save-excursion (beginning-of-line)
		     (looking-at "[0-9]+: *.\\+. "))]
906 907 908
    ["Flush Cache & Expand" speedbar-flush-expand-line
     (save-excursion (beginning-of-line)
		     (looking-at "[0-9]+: *.\\+. "))]
Karl Heuer's avatar
Karl Heuer committed
909
    ["Contract File Tags" speedbar-contract-line
Dan Nicolaescu's avatar
Dan Nicolaescu committed
910 911
     (save-excursion (beginning-of-line)
		     (looking-at "[0-9]+: *.-. "))]
Karl Heuer's avatar
Karl Heuer committed
912 913
;    ["Sort Tags" speedbar-toggle-sorting
;     :style toggle :selected speedbar-sort-tags]
Dan Nicolaescu's avatar
Dan Nicolaescu committed
914
    "----"
Karl Heuer's avatar
Karl Heuer committed
915
    ["File/Tag Information" speedbar-item-info t]
Dan Nicolaescu's avatar
Dan Nicolaescu committed
916 917 918
    ["Load Lisp File" speedbar-item-load
     (save-excursion
       (beginning-of-line)
Karl Heuer's avatar
Karl Heuer committed
919
       (looking-at "[0-9]+: *\\[[+-]\\] .+\\(\\.el\\)\\( \\|$\\)"))]
Dan Nicolaescu's avatar
Dan Nicolaescu committed
920 921 922
    ["Byte Compile File" speedbar-item-byte-compile
     (save-excursion
       (beginning-of-line)
Karl Heuer's avatar
Karl Heuer committed
923 924
       (looking-at "[0-9]+: *\\[[+-]\\] .+\\(\\.el\\)\\( \\|$\\)"))]
    ["Copy File" speedbar-item-copy
Dan Nicolaescu's avatar
Dan Nicolaescu committed
925
     (save-excursion (beginning-of-line) (looking-at "[0-9]+: *\\["))]
Karl Heuer's avatar
Karl Heuer committed
926
    ["Rename File" speedbar-item-rename
Dan Nicolaescu's avatar
Dan Nicolaescu committed
927
     (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
Karl Heuer's avatar
Karl Heuer committed
928 929 930 931 932 933
    ["Delete File" speedbar-item-delete
     (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
    ["Delete Object" speedbar-item-object-delete
     (save-excursion (beginning-of-line)
		     (looking-at "[0-9]+: *\\[[+-]\\] [^ \n]+ \\*?[!#]$"))]
    )
Dan Nicolaescu's avatar
Dan Nicolaescu committed
934 935 936
  "Additional menu items while in file-mode.")
 
(defvar speedbar-easymenu-definition-trailer
937
  (append
Karl Heuer's avatar
Karl Heuer committed
938
   (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
939 940 941 942
       (list ["Customize..." speedbar-customize t]))
   (list
    ["Close" speedbar-close-frame t]
    ["Quit" delete-frame t] ))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
943 944 945
  "Menu items appearing at the end of the speedbar menu.")

(defvar speedbar-desired-buffer nil
946
  "Non-nil when speedbar is showing buttons specific to a special mode.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978
In this case it is the originating buffer.")
(defvar speedbar-buffer nil
  "The buffer displaying the speedbar.")
(defvar speedbar-frame nil
  "The frame displaying speedbar.")
(defvar speedbar-cached-frame nil
  "The frame that was last created, then removed from the display.")
(defvar speedbar-full-text-cache nil
  "The last open directory is saved in its entirety for ultra-fast switching.")
(defvar speedbar-timer nil
  "The speedbar timer used for updating the buffer.")
(defvar speedbar-attached-frame nil
  "The frame which started speedbar mode.
This is the frame from which all data displayed in the speedbar is
gathered, and in which files and such are displayed.")

(defvar speedbar-last-selected-file nil
  "The last file which was selected in speedbar buffer.")

(defvar speedbar-shown-directories nil
  "Maintain list of directories simultaneously open in the current speedbar.")

(defvar speedbar-directory-contents-alist nil
  "An association list of directories and their contents.
Each sublist was returned by `speedbar-file-lists'.  This list is
maintained to speed up the refresh rate when switching between
directories.")

(defvar speedbar-power-click nil
  "Never set this by hand.  Value is t when S-mouse activity occurs.")


979 980 981 982 983 984 985 986 987
;;; Compatibility
;;
(if (fboundp 'frame-parameter)

    (defalias 'speedbar-frame-parameter 'frame-parameter)
  
  (defun speedbar-frame-parameter (frame parameter)
    "Return FRAME's PARAMETER value."
    (cdr (assoc parameter (frame-parameters frame)))))
988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002

(if (fboundp 'make-overlay)
    (progn
      (defalias 'speedbar-make-overlay 'make-overlay)
      (defalias 'speedbar-overlay-put 'overlay-put)
      (defalias 'speedbar-delete-overlay 'delete-overlay)
      (defalias 'speedbar-overlay-start 'overlay-start)
      (defalias 'speedbar-overlay-end 'overlay-end)
      (defalias 'speedbar-mode-line-update 'force-mode-line-update))
  (defalias 'speedbar-make-overlay 'make-extent)
  (defalias 'speedbar-overlay-put 'set-extent-property)
  (defalias 'speedbar-delete-overlay 'delete-extent)
  (defalias 'speedbar-overlay-start 'extent-start)
  (defalias 'speedbar-overlay-end 'extent-end)
  (defalias 'speedbar-mode-line-update 'redraw-modeline))
1003

Dan Nicolaescu's avatar
Dan Nicolaescu committed
1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058
;;; Mode definitions/ user commands
;;

;;;###autoload
(defalias 'speedbar 'speedbar-frame-mode)
;;;###autoload
(defun speedbar-frame-mode (&optional arg)
  "Enable or disable speedbar.  Positive ARG means turn on, negative turn off.
nil means toggle.  Once the speedbar frame is activated, a buffer in
`speedbar-mode' will be displayed.  Currently, only one speedbar is
supported at a time.
`speedbar-before-popup-hook' is called before popping up the speedbar frame.
`speedbar-before-delete-hook' is called before the frame is deleted."
  (interactive "P")
  ;; toggle frame on and off.
  (if (not arg) (if (and (frame-live-p speedbar-frame)
			 (frame-visible-p speedbar-frame))
		    (setq arg -1) (setq arg 1)))
  ;; turn the frame off on neg number
  (if (and (numberp arg) (< arg 0))
      (progn
	(run-hooks 'speedbar-before-delete-hook)
	(if (and speedbar-frame (frame-live-p speedbar-frame))
	    (progn
	      (setq speedbar-cached-frame speedbar-frame)
	      (make-frame-invisible speedbar-frame)))
	(setq speedbar-frame nil)
	(speedbar-set-timer nil)
	;; Used to delete the buffer.  This has the annoying affect of
	;; preventing whatever took its place from ever appearing
	;; as the default after a C-x b was typed
	;;(if (bufferp speedbar-buffer)
	;;    (kill-buffer speedbar-buffer))
	)
    ;; Set this as our currently attached frame
    (setq speedbar-attached-frame (selected-frame))
    (run-hooks 'speedbar-before-popup-hook)
    ;; Get the frame to work in
    (if (frame-live-p speedbar-cached-frame)
	(progn
	  (setq speedbar-frame speedbar-cached-frame)
	  (make-frame-visible speedbar-frame)
	  ;; Get the buffer to play with
	  (speedbar-mode)
	  (select-frame speedbar-frame)
	  (if (not (eq (current-buffer) speedbar-buffer))
	      (switch-to-buffer speedbar-buffer))
	  (set-window-dedicated-p (selected-window) t)
	  (raise-frame speedbar-frame)
	  (speedbar-set-timer speedbar-update-speed)
	  )
      (if (frame-live-p speedbar-frame)
	  (raise-frame speedbar-frame)
	(setq speedbar-frame
	      (if speedbar-xemacsp
1059 1060 1061 1062 1063 1064 1065 1066 1067
		  ;; Only guess height if it is not specified.
		  (if (member 'height speedbar-frame-plist)
		      (make-frame speedbar-frame-plist)
		    (make-frame (nconc (list 'height
					     (speedbar-needed-height))
				       speedbar-frame-plist)))
		(let* ((mh (speedbar-frame-parameter nil 'menu-bar-lines))
		       (cfx (speedbar-frame-parameter nil 'left))
		       (cfy (speedbar-frame-parameter nil 'top))
1068 1069
		       (cfw (frame-pixel-width))
		       (params
1070 1071 1072 1073 1074 1075 1076
			;; Only add a guessed height if one is not specified
			;; in the input parameters.
			(if (assoc 'height speedbar-frame-parameters)
			    speedbar-frame-parameters
			  (append
			   speedbar-frame-parameters
			   (list (cons 'height (+ mh (frame-height)))))))
1077 1078 1079 1080 1081 1082 1083 1084
		       (frame
			(if (or (< emacs-major-version 20)
				(not (eq window-system 'x)))
			    (make-frame params)
			  (let ((x-pointer-shape x-pointer-top-left-arrow)
				(x-sensitive-text-pointer-shape
				 x-pointer-hand2))
			    (make-frame params)))))
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128
		  ;; Position speedbar frame.
		  (if (or (not window-system) (eq window-system 'pc)
			  (assoc 'left speedbar-frame-parameters)
			  (assoc 'top speedbar-frame-parameters))
		      ;; Do no positioning if not on a windowing system,
		      ;; or if left/top were specified in the parameters.
		      frame
		    (let ((cfx
			   (if (not (consp cfx))
			       cfx
			     ;; If cfx is a list, that means we grow
			     ;; from a specific edge of the display.
			     ;; Convert that to the distance from the
			     ;; left side of the display.
			     (if (eq (car cfx) '-)
				 ;; A - means distance from the right edge
				 ;; of the display, or DW - cfx - framewidth
				 (- (x-display-pixel-width) (car (cdr cfx))
				    (frame-pixel-width))
			       (car (cdr cfx))))))
		      (modify-frame-parameters
		       frame
		       (list
			(cons
			 'left
			 ;; Decide which side to put it
			 ;; on.  200 is just a buffer
			 ;; for the left edge of the
			 ;; screen.  The extra 10 is just
			 ;; dressings for window decorations.
			 (let ((sfw (frame-pixel-width frame)))
			   (let ((left-guess (- cfx 10 sfw))
				 (right-guess (+ cfx cfw 5)))
			     (let ((left-margin left-guess)
				   (right-margin
				    (- (x-display-pixel-width)
				       right-guess 5 sfw)))
			       (cond ((>= left-margin 0) left-guess)
				     ((>= right-margin 0) right-guess)
				     ;; otherwise choose side we overlap less
				     ((> left-margin right-margin) 0)
				     (t (- (x-display-pixel-width) sfw 5)))))))
			(cons 'top cfy)))
		      frame)))))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1129 1130 1131 1132 1133 1134 1135 1136 1137
	;; reset the selection variable
	(setq speedbar-last-selected-file nil)
	;; Put the buffer into the frame
	(save-window-excursion
	  ;; Get the buffer to play with
	  (speedbar-mode)
	  (select-frame speedbar-frame)
	  (switch-to-buffer speedbar-buffer)
	  (set-window-dedicated-p (selected-window) t))
1138 1139
	(if (and (or (null window-system) (eq window-system 'pc))
		 (fboundp 'set-frame-name))
1140 1141 1142
	    (progn
	      (select-frame speedbar-frame)
	      (set-frame-name "Speedbar")))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153
	(speedbar-set-timer speedbar-update-speed)))))

;;;###autoload
(defun speedbar-get-focus ()
  "Change frame focus to or from the speedbar frame.
If the selected frame is not speedbar, then speedbar frame is
selected.  If the speedbar frame is active, then select the attached frame."
  (interactive)
  (if (eq (selected-frame) speedbar-frame)
      (if (frame-live-p speedbar-attached-frame)
	  (select-frame speedbar-attached-frame))
Karl Heuer's avatar
Karl Heuer committed
1154 1155 1156 1157
    ;; If updates are off, then refresh the frame (they want it now...)
    (if (not speedbar-update-flag)
	(let ((speedbar-update-flag t))
	  (speedbar-timer-fn)))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1158 1159 1160
    ;; make sure we have a frame
    (if (not (frame-live-p speedbar-frame)) (speedbar-frame-mode 1))
    ;; go there
Karl Heuer's avatar
Karl Heuer committed
1161 1162
    (select-frame speedbar-frame)
    )
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1163 1164 1165 1166 1167 1168 1169 1170 1171
  (other-frame 0))

(defun speedbar-close-frame ()
  "Turn off a currently active speedbar."
  (interactive)
  (speedbar-frame-mode -1)
  (select-frame speedbar-attached-frame)
  (other-frame 0))

Karl Heuer's avatar
Karl Heuer committed
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183
(defun speedbar-switch-buffer-attached-frame (&optional buffer)
  "Switch to BUFFER in speedbar's attached frame, and raise that frame.
This overrides the default behavior of `switch-to-buffer' which is
broken because of the dedicated speedbar frame."
  (interactive)
  ;; Assume we are in the speedbar frame.
  (speedbar-get-focus)
  ;; Now switch buffers
  (if buffer
      (switch-to-buffer buffer)
    (call-interactively 'switch-to-buffer nil nil)))

Dan Nicolaescu's avatar
Dan Nicolaescu committed
1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221
(defmacro speedbar-frame-width ()
  "Return the width of the speedbar frame in characters.
nil if it doesn't exist."
  '(frame-width speedbar-frame))

;; XEmacs function only.
(defun speedbar-needed-height (&optional frame)
  "The needed height for the tool bar FRAME (in characters)."
  (or frame (setq frame (selected-frame)))
  ;; The 1 is the missing modeline/minibuffer
  (+ 1 (/ (frame-pixel-height frame)
	  (face-height 'default frame))))

(defun speedbar-mode ()
  "Major mode for managing a display of directories and tags.
\\<speedbar-key-map>
The first line represents the default path of the speedbar frame.
Each directory segment is a button which jumps speedbar's default
directory to that path.  Buttons are activated by clicking `\\[speedbar-click]'.
In some situations using `\\[speedbar-power-click]' is a `power click' which will
rescan cached items, or pop up new frames.

Each line starting with <+> represents a directory.  Click on the <+>
to insert the directory listing into the current tree.  Click on the
<-> to retract that list.  Click on the directory name to go to that
directory as the default.

Each line starting with [+] is a file.  If the variable
`speedbar-show-unknown-files' is t, the lines starting with [?] are
files which don't have imenu support, but are not expressly ignored.
Files are completely ignored if they match `speedbar-file-unshown-regexp'
which is generated from `completion-ignored-extensions'.

Files with a `*' character after their name are files checked out of a
version control system.  (currently only RCS is supported.)  New
version control systems can be added by examining the documentation
for `speedbar-this-file-in-vc' and `speedbar-vc-check-dir-p'

Karl Heuer's avatar
Karl Heuer committed
1222 1223 1224 1225 1226
Files with a `#' or `!' character after them are source files that
have an object file associated with them.  The `!' indicates that the
files is out of date.   You can control what source/object associations
exist through the variable `speedbar-obj-alist'.

Dan Nicolaescu's avatar
Dan Nicolaescu committed
1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248
Click on the [+] to display a list of tags from that file.  Click on
the [-] to retract the list.  Click on the file name to edit the file
in the attached frame.

If you open tags, you might find a node starting with {+}, which is a
category of tags.  Click the {+} to expand the category.  Jump-able
tags start with >.  Click the name of the tag to go to that position
in the selected file.

\\{speedbar-key-map}"
  ;; NOT interactive
  (save-excursion
    (setq speedbar-buffer (set-buffer (get-buffer-create " SPEEDBAR")))
    (kill-all-local-variables)
    (setq major-mode 'speedbar-mode)
    (setq mode-name "Speedbar")
    (set-syntax-table speedbar-syntax-table)
    (setq font-lock-keywords nil) ;; no font-locking please
    (setq truncate-lines t)
    (make-local-variable 'frame-title-format)
    (setq frame-title-format "Speedbar")
    ;; Set this up special just for the speedbar buffer
Karl Heuer's avatar
Karl Heuer committed
1249
    ;; Terminal minibuffer stuff does not require this.
1250 1251
    (if (and window-system (not (eq window-system 'pc))
	     (null default-minibuffer-frame))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1252 1253 1254
	(progn
	  (make-local-variable 'default-minibuffer-frame)
	  (setq default-minibuffer-frame speedbar-attached-frame)))
Karl Heuer's avatar
Karl Heuer committed
1255 1256 1257 1258 1259
    ;; Correct use of `temp-buffer-show-function': Bob Weiner
    (if (and (boundp 'temp-buffer-show-hook)
	     (boundp 'temp-buffer-show-function))
	(progn (make-local-variable 'temp-buffer-show-hook)
	       (setq temp-buffer-show-hook temp-buffer-show-function)))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274
    (make-local-variable 'temp-buffer-show-function)
    (setq temp-buffer-show-function 'speedbar-temp-buffer-show-function)
    (if speedbar-xemacsp
	(progn
	  ;; Argh!  mouse-track-click-hook doesn't understand the
	  ;; make-local-hook conventions.
	  (make-local-variable 'mouse-track-click-hook)
	  (add-hook 'mouse-track-click-hook
		    (lambda (event count)
		      (if (/= (event-button event) 1)
			  nil		; Do normal operations.
			(cond ((eq count 1)
			       (speedbar-quick-mouse event))
			      ((or (eq count 2)
				   (eq count 3))
1275
			       (speedbar-mouse-set-point event)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286
			       (speedbar-do-function-pointer)
			       (speedbar-quick-mouse event)))
			;; Don't do normal operations.
			t)))))
    (add-hook 'kill-buffer-hook (lambda () (let ((skilling (boundp 'skilling)))
					     (if skilling
						 nil
					       (if (eq (current-buffer)
						       speedbar-buffer)
						   (speedbar-frame-mode -1)))))
	      t t)
1287
    (toggle-read-only 1)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1288
    (speedbar-set-mode-line-format)
Karl Heuer's avatar
Karl Heuer committed
1289
    (if speedbar-xemacsp
1290 1291
	(set (make-local-variable 'mouse-motion-handler)
	     'speedbar-track-mouse-xemacs)
Karl Heuer's avatar
Karl Heuer committed
1292
      (if speedbar-track-mouse-flag
1293
	  (set (make-local-variable 'track-mouse) t))	;this could be messy.
Karl Heuer's avatar
Karl Heuer committed
1294
      (setq auto-show-mode nil))	;no auto-show for Emacs
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1295 1296 1297 1298
    (run-hooks 'speedbar-mode-hook))
  (speedbar-update-contents)
  speedbar-buffer)

1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323
(defmacro speedbar-with-attached-buffer (&rest forms)
  "Execute FORMS in the attached frame's special buffer.
Optionally select that frame if necessary."
  `(save-selected-window
     (speedbar-set-timer speedbar-update-speed)
     (select-frame speedbar-attached-frame)
     ,@forms
     (speedbar-maybee-jump-to-attached-frame)))

(defun speedbar-message (fmt &rest args)
  "Like message, but for use in the speedbar frame.
Argument FMT is the format string, and ARGS are the arguments for message."
  (save-selected-window
    (select-frame speedbar-attached-frame)
    (apply 'message fmt args)))

(defun speedbar-y-or-n-p (prompt)
  "Like `y-or-n-p', but for use in the speedbar frame.
Argument PROMPT is the prompt to use."
  (save-selected-window
    (if (and default-minibuffer-frame (not (eq default-minibuffer-frame
					       speedbar-attached-frame)))
	(select-frame speedbar-attached-frame))
    (y-or-n-p prompt)))

Karl Heuer's avatar
Karl Heuer committed
1324 1325 1326 1327 1328 1329 1330 1331 1332 1333
(defun speedbar-show-info-under-mouse (&optional event)
  "Call the info function for the line under the mouse.
Optional EVENT is currently not used."
  (let ((pos (mouse-position)))  ; we ignore event until I use it later.
    (if (equal (car pos) speedbar-frame)
	(save-excursion
	  (save-window-excursion
	    (apply 'set-mouse-position pos)
	    (speedbar-item-info))))))

Dan Nicolaescu's avatar
Dan Nicolaescu committed
1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362
(defun speedbar-set-mode-line-format ()
  "Set the format of the mode line based on the current speedbar environment.
This gives visual indications of what is up.  It EXPECTS the speedbar
frame and window to be the currently active frame and window."
  (if (and (frame-live-p speedbar-frame)
	   (or (not speedbar-xemacsp)
	       (specifier-instance has-modeline-p)))
      (save-excursion
	(set-buffer speedbar-buffer)
	(let* ((w (or (speedbar-frame-width) 20))
	       (p1 "<<")
	       (p5 ">>")
	       (p3 (if speedbar-update-flag "SPEEDBAR" "SLOWBAR"))
	       (blank (- w (length p1) (length p3) (length p5)
			 (if line-number-mode 4 0)))
	       (p2 (if (> blank 0)
		       (make-string (/ blank 2) ? )
		     ""))
	       (p4 (if (> blank 0)
		       (make-string (+ (/ blank 2) (% blank 2)) ? )
		     ""))
	       (tf
		(if line-number-mode
		    (list (concat p1 p2 p3) '(line-number-mode " %3l")
			  (concat p4 p5))
		  (list (concat p1 p2 p3 p4 p5)))))
	  (if (not (equal mode-line-format tf))
	      (progn
		(setq mode-line-format tf)
1363
		(speedbar-mode-line-update)))))))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1364 1365 1366 1367 1368 1369 1370 1371

(defun speedbar-temp-buffer-show-function (buffer)
  "Placed in the variable `temp-buffer-show-function' in `speedbar-mode'.
If a user requests help using \\[help-command] <Key> the temp BUFFER will be
redirected into a window on the attached frame."
  (if speedbar-attached-frame (select-frame speedbar-attached-frame))
  (pop-to-buffer buffer nil)
  (other-window -1)
1372 1373 1374 1375
  ;; Fix for using this hook on some platforms: Bob Weiner
  (cond ((not speedbar-xemacsp)
	 (run-hooks 'temp-buffer-show-hook))
	((fboundp 'run-hook-with-args)
Karl Heuer's avatar
Karl Heuer committed
1376 1377 1378 1379 1380 1381
	 (run-hook-with-args 'temp-buffer-show-hook buffer))
	((and (boundp 'temp-buffer-show-hook)
	      (listp temp-buffer-show-hook))
	 (mapcar (function (lambda (hook) (funcall hook buffer)))
		 temp-buffer-show-hook))))

1382 1383 1384
(defvar speedbar-previous-menu nil
  "The menu before the last `speedbar-reconfigure-keymaps' was called.")

Karl Heuer's avatar
Karl Heuer committed
1385
(defun speedbar-reconfigure-keymaps ()
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1386 1387 1388
  "Reconfigure the menu-bar in a speedbar frame.
Different menu items are displayed depending on the current display mode
and the existence of packages."