2.2.5Using Tags
As an application grows in size, it also grows in complexity. As the number of subroutines,
variables, functions and files increases, it becomes much more difficult to keep track of every
piece and to quickly find the portion of code that one needs to work on. To address this issue,
Emacs has the ability to read a file that contains a table of tags that reference various parts of an
These tags are stored in a
file that is created by the
command. Once this file
is built, Emacs can read this table and use it to quickly locate a specific portion of code, regard-
less of whether it is in a currently open file or not.
From the command line the
command is issued with a list of file names to be read:
$ etags *.[ch]
This command will read all files in the current directory that have a
and build a tags table file in the current directory. The output file is, by default, called
To build a single
table for a project that has source code spread through any number
of subdirectories, the following command may be used:
$ find . –name \*.[ch] | xargs etags –
Just be aware if there are too many files, then this command may need to be run several
times with varying arguments in order to build a complete table. To do this, you must use the
–append option to the
command as shown:
$ find . –name \*.c | xargs etags –
$ find . –name \*.h | xargs etags –-append –
Any of these commands may be issued from within Emacs itself by using the
mand to issue a shell command. Simply type
and press return.
Once you have built a
table, it must first be read into Emacs before you can use it to
search. To accomplish this, type
M-x visit-tags-table
, specify the location of the
file to be read in, and then the name of the
file. The default value for the location is the
current working directory, and the default tags file name is
Once the
file has been read in, you may issue search commands against the table.
There are several commands that can be used. The one most commonly used is
searches for a tag that matches the search parameter. The default search parameter is the word at
the current pointer position. For example, if the pointer were on the character string
, the default search string that Emacs presents would be
If you are not sure of the name of the function that you are looking for, you can type the
first few characters of the function name and press the
key. This invokes the completion
function of Emacs and, if the function is unique, it will display that function name. If the func-
tion name is not unique, Emacs will complete as much of the function name as it can and then
prompt you for the rest. Pressing
again after Emacs has completed as much of the function
Next Page >>
<< Previous Page
Back to the Table of Contents