Speedbar is another frame which displays information about the current buffer, allowing you to better navigate your sources. In a way, it’s similar to ImenuMode, but much more powerful. It is a part of GNU Emacs since version 23.2.
Speedbar can use etags, imenu, or the SemanticBovinator to parse C, C++, Java, texinfo, Makefiles, etc. and provides alternate views into each individual files. For example, for C files, function list and variable lists are provided for quick navigation within files.
Speedbar also supports special displays for buffers, rmail, info, projects, xslt, vhdl, and others which use the speedbar extension API.
To automatically start speedbar from your InitFile, just call the speedbar function with a positive argument like this:
If you use emacs both on the console and in X a lot, you may want to disable speedbar when you’re not in X. To do that use the following in your InitFile:
(when window-system ; start speedbar if we're using a window system (speedbar t))
Something that might annoy you under certain X window managers (WindowMaker?, for example) and in Carbon Emacs when speedbar starts is that it’s window will appear to have focus but keyboard input goes to the original Emacs window. You can make things look right again by defining this mode hook before starting speedbar:
(setq speedbar-mode-hook '(lambda () (interactive) (other-frame 0)))
If this fails, you can call other-frame right after you call speedbar.
Beware: doing this may make your MousePointer jump somewhere you don’t expect it to in X.
(defun speedbar-expand-all-lines () "Expand all items in the speedbar buffer. But be careful: this opens all the files to parse them." (interactive) (goto-char (point-min)) (while (not (eobp)) (forward-line) (speedbar-expand-line)))
Here’s some code that will open the directory tree to the current buffer relative to `project-root`. http://solovyov.net/project-root/
(defun nm-speedbar-expand-line-list (&optional arg) (when arg (message (car arg)) (re-search-forward (concat " " (car arg) "$")) (speedbar-expand-line (car arg)) (speedbar-next 1) ;; Move into the list. (nm-speedbar-expand-line-list (cdr arg)))) (defun nm-speedbar-open-current-buffer-in-tree () (interactive) (let* ((root-dir (cdr (project-root-fetch))) (original-buffer-file-directory (file-name-directory (buffer-file-name))) (relative-buffer-path (car (cdr (split-string original-buffer-file-directory root-dir)))) (parents (butlast (split-string relative-buffer-path "/")))) (save-excursion (sr-speedbar-open) ;; <--- or whatever speedbar you have e.g. (speedbar 1) (set-buffer speedbar-buffer) (beginning-of-buffer) (nm-speedbar-expand-line-list parents))))
(speedbar-add-supported-extension ".js") (add-to-list 'speedbar-fetch-etags-parse-list '("\\.js" . speedbar-parse-c-or-c++tag))
SqlMode does have Imenu support; but by default the regular expressions don’t match PL/SQL stuff. At work I have code that does it. But then again, I switched to using PlsqlMode for PL/SQL stuff. Perhaps it reuses the SqlMode imenu code, I can’t remember. -- AlexSchroeder
EmacsCodeBrowser (ecb) overlaps much of Speedbar, and requires Speedbar and other parts of the CEDET suite to function. In fact, ecb will display Speedbar without a separate frame in one of its supplied configurations. Its built-in directory and class browsers (which you can hide/not use, if you only want Speedbar in your editing frame) are similar in function but different in look/feel from Speedbar’s. I’ve used it on Win32/GNU Emacs successfully. --yary h
(add-to-list 'default-frame-alist '(font . "-schumacher-clean-medium-r-normal--8-*-*-*-c-50-iso8859-1"))
(speedbar 1)line so that when the speedbar is created, it uses the font I selected before.
To override the the default behavior that identifies files by extension, you can set the variable ‘speedbar-file-regexp’ to something like “.*”. I just tried it, and it seems to work ok. This variable will be re-set when speedbar loads, or if the supported extension list is customized.
Thanks, it seems to work and I will give it a try. If I don’t come back to this page, it will be a good solution ;-)
Try this tip, from the help text for
‘speedbar-supported-extension-expressions’: “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 InitFile.” Just now I menued Options > Customize Emacs > Settings Matching Regexp, typed in “speedbar”, and got a good listing of options. Adding
(speedbar 1) (speedbar-add-supported-extension ".js")
(speedbar 1) or
(speedbar 0) has to come first to load the package. -yary h
Integrate speedbar with projectile http://www.emacswiki.org/emacs/projectile-speedbar.el