28.4.2.2 Creating Tags Tables
The etags
program is used to create a tags table file. It knows
the syntax of several languages, as described in
Source File Tag Syntax.
Here is how to run etags
:
etags inputfiles…
The etags
program reads the specified files, and writes a tags
table named TAGS
in the current working directory. You can
optionally specify a different file name for the tags table by using the
‘ --output=file
’ option; specifying -
as a file name
prints the tags table to standard output. You can also append the
newly created tags table to an existing file by using the ‘ --append
’
option.
If the specified files don’t exist, etags
looks for
compressed versions of them and uncompresses them to read them. Under
MS-DOS, etags
also looks for file names like mycode.cgz
if it is given ‘ mycode.c
’ on the command line and mycode.c
does not exist.
If the tags table becomes outdated due to changes in the files
described in it, you can update it by running the etags
program again. If the tags table does not record a tag, or records it
for the wrong file, then Emacs will not be able to find that
definition until you update the tags table. But if the position
recorded in the tags table becomes a little bit wrong (due to other
editing), Emacs will still be able to find the right position, with a
slight delay.
Thus, there is no need to update the tags table after each edit. You should update a tags table when you define new tags that you want to have listed, or when you move tag definitions from one file to another, or when changes become substantial.
You can make a tags table include another tags table, by
passing the ‘ --include=file
’ option to etags
. It
then covers all the files covered by the included tags file, as well
as its own.
If you specify the source files with relative file names when you run
etags
, the tags file will contain file names relative to the
directory where the tags file was initially written. This way, you can
move an entire directory tree containing both the tags file and the
source files, and the tags file will still refer correctly to the source
files. If the tags file is -
or is in the /dev
directory,
however, the file names are
made relative to the current working directory. This is useful, for
example, when writing the tags to the standard output.
When using a relative file name, it should not be a symbolic link pointing to a tags file in a different directory, because this would generally render the file names invalid.
If you specify absolute file names as arguments to etags
, then
the tags file will contain absolute file names. This way, the tags file
will still refer to the same files even if you move it, as long as the
source files remain in the same place. Absolute file names start with
‘ /
’, or with ‘ device:/
’ on MS-DOS and MS-Windows.
When you want to make a tags table from a great number of files,
you may have problems listing them on the command line, because some
systems have a limit on its length. You can circumvent this limit by
telling etags
to read the file names from its standard
input, by typing a dash in place of the file names, like this:
find . -name "*.[chCH]" -print | etags -
etags
recognizes the language used in an input file based on
its file name and contents. It first tries to match the file’s name and
extension to the ones commonly used with certain languages. Some
languages have interpreters with known names (e.g., perl
for
Perl or pl
for Prolog), so etags
next looks for an
interpreter specification of the form ‘ #!interp
’ on the first
line of an input file, and matches that against known interpreters. If
none of that works, or if you want to override the automatic detection of
the language, you can specify the language explicitly with the
‘ --language=name
’ option. You can intermix these options with
file names; each one applies to the file names that follow it. Specify
‘ --language=auto
’ to tell etags
to resume guessing the
language from the file names and file contents. Specify
‘ --language=none
’ to turn off language-specific processing entirely;
then etags
recognizes tags by regexp matching alone
(see Etags Regexps). This comes in handy when an input file uses a
language not yet supported by etags
, and you want to avoid
having etags
fall back on Fortran and C as the default
languages.
The option ‘ --parse-stdin=file
’ is mostly useful when
calling etags
from programs. It can be used (only once) in
place of a file name on the command line. etags
will read from
standard input and mark the produced tags as belonging to the file
file.
For C and C++, if the source files don’t observe the GNU Coding
Standards’ convention if having braces (‘ {
’ and ‘ }
’) in
column zero only for top-level definitions, like functions and
struct
definitions, we advise that you use the
‘ --ignore-indentation
’ option, to prevent etags
from
incorrectly interpreting closing braces in column zero.
‘ etags --help
’ outputs the list of the languages etags
knows, and the file name rules for guessing the language. It also prints
a list of all the available etags
options, together with a short
explanation. If followed by one or more ‘ --language=lang
’
options, it outputs detailed information about how tags are generated for
lang.