LinuxCommandLibrary

etags

Create tag files for source code

SYNOPSIS

etags [options] [file ...]

PARAMETERS

-a, --append
    Appends new tags to an existing TAGS file instead of overwriting it.

-f TAGSFILE, --output=TAGSFILE
    Specifies the name of the output tags file. The default is TAGS.

-r REGEXP, --regex=REGEXP
    Uses the specified regular expression to find additional tags. This allows customizing tag generation for specific patterns or languages.

-L FILE, --file-list=FILE
    Reads filenames from FILE, one per line. Useful when dealing with a large number of files generated by other commands like find.

-v, --verbose
    Displays the names of files being processed and other progress information to standard error.

-u, --update
    Updates tags for modified files in the TAGS file. If a file is not listed, it's ignored; if a file is deleted, its entries are removed.

-C LANGUAGE, --language=LANGUAGE
    Forces etags to use the specified LANGUAGE mode for all input files, overriding its automatic language detection.

--exclude=PATTERN
    Excludes files whose names match the shell PATTERN from being processed.

DESCRIPTION

etags is a powerful utility used to generate a TAGS file for GNU Emacs. This file contains a list of definitions found in source code files, such as functions, variables, classes, and macros, along with their locations. When used within Emacs, the TAGS file allows developers to quickly navigate through large codebases using commands like M-. (find-tag) to jump directly to the definition of a symbol, or M-* to return to the previous location.

etags supports a wide array of programming languages, including C, C++, Java, Python, Lisp, and many more, by employing language-specific parsers or regular expressions. It is an indispensable tool for enhancing productivity in code exploration and development, enabling seamless jumps between relevant parts of a project without manual searching.

CAVEATS

While incredibly useful, etags has a few considerations:
1. For very large projects, the generated TAGS file can become quite big, potentially impacting performance slightly within Emacs or requiring significant disk space.
2. The tag file needs to be regenerated (or updated with -u) whenever the source code structure changes significantly (e.g., new functions added, functions renamed).
3. etags uses heuristic parsing for many languages, which means it might occasionally miss definitions or generate incorrect tags, especially for complex or unconventional code constructs.
4. It is primarily designed for Emacs. Users of other editors might prefer ctags, which produces a more general format.

COMMON USAGE WITH <I>FIND</I>

A very common pattern for generating tags for an entire project is to combine etags with the find command. For example, to tag all C and C++ source files in the current directory and its subdirectories:
find . -name "*.c" -o -name "*.h" -o -name "*.cpp" | etags -L -
The -L - option tells etags to read the list of files from standard input.

To append to an existing TAGS file:
find . -name "*.js" | etags -a -L -

INTEGRATING WITH <I>EMACS</I>

Once a TAGS file is generated, you need to tell Emacs about it. Use M-x visit-tags-table RET TAGS RET to load the tags file. After loading, you can use:
- M-. (find-tag): Jump to the definition of a symbol at point.
- M-* (pop-tag-mark): Return to the previous location in the tag stack.
- M-x tags-search: Search for a regular expression in all tagged files.
- M-x tags-query-replace: Perform query-replace across all tagged files.
This deep integration makes etags an indispensable tool for Emacs users working on large software projects.

HISTORY

etags has been an integral part of the GNU Emacs ecosystem for decades. Its development has closely tracked that of Emacs itself, evolving to support an ever-growing list of programming languages and advanced features for code navigation. It emerged as a dedicated tags generator for Emacs, building upon the concept of "tags" files common in Unix development environments. Its continuous integration and reliance within the Emacs community underscore its role as a stable and essential utility for source code management and exploration.

SEE ALSO

ctags(1), find(1)

Copied to clipboard