SpeedBar

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:

 (speedbar 1)

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.

Speedbar Without A Separate Frame

Use SrSpeedbar.

Questions

Question: is there a way to tell speed-bar to expand ALL groups? – Badari
Answer: Not by default, but you could easily write that function, like for example:
 (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)))
Please note, though, that this may take a while since it has to open all the files and parse them.
If you just want to open all items in the current file, you’d have to write a function that
* goes back to the last line that has a “0” at the beginning (instead of point-min above). These lines determine filenames in the speedbar buffer.
* checks for another line with a “0” at the beginning or end of buffer to stop (instead of just eobp above).

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))))
NateMurray

:::Newer versions of speedbar (a part of the CEDET package CollectionOfEmacsDevelopmentEnvironmentTools) bind the “[” and “]” keys to expand/contract all descendants. – EricLudlam

Question: how difficult should it be to add support for sql, javascript etc? (the languages I use quite alot right now, what a coincidence ☺?MathiasDahl
First, about javascript. If you’re editing files that are only javascript, you can just use C++ type syntax along with either etags, imenu, or the SemanticBovinator. If they are mixed html and javascript it gets more problematic. You might want to look at MultipleModes, although I’m not sure how to integrate this in with speedbar.
I am editing asp-pages (jscript + javascript + html intermixed) and today use java-mode and it works quite well. Will this mix f*k up the way etags, imenu and SemanticBovinator work?
About sql, I’m not sure what you mean? What types of views would you want speedbar to give? Are you editing files that have lots of stored procedures in them and you would want to list those procedures? Were you just saying, “I deal with a lot of sql” or did you have something in mind how speedbar could interface with sql?
Sorry for being to vague. Yes I edit LARGE files with pl/sql procedures anf functions (up to 5000-6000 rows of code) that are included in our oracle packages. Being able to get a quick list of all methods would be a great thing, using imenu or speedbar.
(Hmm, maybe we should take this discussion to the newsgroup, or after I got my answers I’ll edit this page and get rid of this little chat.)
On javascript: the following two expressions probably do not do everything you want for javascript (the code gets interpreted as c or c++), but at least they do more than nothing:
   (speedbar-add-supported-extension ".js")
   (add-to-list 'speedbar-fetch-etags-parse-list
		'("\\.js" . speedbar-parse-c-or-c++tag))

--pft

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


I think the EmacsCodeBrowser is the same thing as SpeedBar. Fulfills the same purpose maybe? What do you guys think? --ShaeErisson

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


Question: is it possible to control the size and position of the speedbar when it is loaded? For example, I want it to appear at the right side of the screen, maximized vertcally, with a width of 150 pixels.
How about customizing ‘speedbar-frame-parameters’ (Emacs) or ‘speedbar-frame-plist’ (XEmacs) ?
You could also look up the lisp variables and functions controlling the speedbar. M-x describe-variable RET speedbar and press tab to see the rest of the speedbar variables. M-x describe-functions RET speedbar and press tab to see the rest of the speedbar functions. You now have enough knowledge to change it around using LISP.

Question: is it possible to tell the speedbar to go into the buffer mode when it is loaded? I was unable to find the appropriate function… --Andrius Kurtinaitis
Yes, see the documentation for: speedbar-change-initial-expansion-list – EricLudlam

Is it possible to set speedbar’s font size in my InitFile? In my installation SpeedBar shows much larger font than that of the main emacs frame.

You should just add this, so that when you create a new frame (like when you call speedbar), it will have the font here
        (add-to-list 'default-frame-alist '(font . "-schumacher-clean-medium-r-normal--8-*-*-*-c-50-iso8859-1"))
I use it before the (speedbar 1) line so that when the speedbar is created, it uses the font I selected before.
Here’s a hint (Charlie Martin): set up the speedbar frame the way you like it, then type
        (pp (current-frame-configuration))^J
in the scratch buffer to find out all the frame parameters. --darksonxd

Question: is it possible to make the speedarbar hide files and directories beginning with “.”?

Question: can speedbar use some other mode-detection-scheme than filename extensions? I do have the habit to name “minor” perl-programs “something.pl” and larger projects without extension. I desperately need speedbar in the larger projects whereas navigation in smaller scripts is easy without it.

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")

to my InitFile lets me see my javascript files in the speedbar- note that (speedbar 1) or (speedbar 0) has to come first to load the package. -yary h


Want to set up CategoryProgrammerUtils CategoryNavigation


Integrate speedbar with projectile http://www.emacswiki.org/emacs/projectile-speedbar.el

-AnshulVerma