Sams Teach Yourself Emacs in 24 Hours |  | ContentsIndex
Hour 18: Editing C, C++, and Java Files |  | Previous HourNext Hour
Sections in this Hour: |  |

## File and Tag Browsing

As mentioned in Hour 8, "Searching for Text in Multiple Files," when working with almost any language, it is possible to create a TAGS file and jump to the function or variable of your choosing with simple commands. Under GNU Emacs, another program that can be used to a similar end is called imenu. When you enter the command M-x imenu-add-menubar-index, a new menu item titled Index appears. Every element of this menu is a symbol representing some function or variable in your language. Choosing a menu item jumps you to that location in the buffer. If you want this added to all your C buffers, add the command imenu-add-menubar-index to your c-mode-hook, c++-mode-hook, or java-mode-hook.

In XEmacs, the functions provided by imenu are replaced with a package called func-menu. You need to load this package yourself with the command M-x load-library RET func-menu RET before installing the menu item with the command M-x fume-add-menubar-entry RET.

Another program useful for browsing tags based on a filesystem view is called Speedbar. To start this program, enter the Speedbar command M-x speedbar. A thin frame should appear next to your Emacs frame with a listing of the current directory. Almost everything in Speedbar can be clicked. To select an item, either click it with the second mouse button or double-click it with the first mouse button. Sometimes you can power-click something. This means to hold Shift down while clicking on the item. A power click is useful if the cached information you are displaying is stale.

A version of Speedbar that works under Emacs and XEmacs has been included on the CD accompanying this book (see Figure 18.1). To use this program, follow the directions for installing an Emacs program on the CD-ROM and load it using M-x load-library RET speedbar RET.

Figure 18.1
Speedbar displaying tags for a source file in Emacs.

The first line contains a display of the full pathname. You can select any element of that directory to switch Speedbar's directory to that location. Each directory entry in the current directory appears with a <+> symbol next to it. You can open the directory in place by selecting the <+>. You can switch Speedbar's full path to that location by selecting the name.

Each file in the current directory that Emacs knows how to read will appear with a [+] next to it. Clicking on the filename switches the current buffer in the main frame to this file. Clicking on the [+] uses imenu to select all the tags in that file. Clicking on a tag group {+} token shows all that tags in that group. Clicking on a tag name jumps to that tag in the main Emacs frame. If the tags are stale or inaccurate because you have modified the source file, hold down Shift while clicking on the [+] to display the tags, and they are regenerated.

Note - XEmacs users might find that they do not have imenu installed. In this case Speedbar uses etags to generate tag lists instead. This has the side effect of a slightly less robust tag generation scheme.

Speedbar attempts to display additional information about each file as well. A * next to a filename means that file has been checked out of a version control system such as RCS, or SCCS. A # next to a filename means that the C, C++, Objective C, or Java file has an up-to-date object file. A ! next to a file means that the source file has an object file, but that the source is newer than the object file.

Speedbar has many other options available by clicking with the third mouse button to get a menu. It can perform file operations and has specialized displays for other purposes. Play with the items to get a feel for the capabilities. Speedbar can be used with other programming languages as well.

Sams Teach Yourself Emacs in 24 Hours |  | ContentsIndex
Hour 18: Editing C, C++, and Java Files |  | Previous HourNext Hour
Sections in this Hour: |  |

© Copyright Macmillan USA. All rights reserved.