LinuxCommandLibrary

etags

Create tag files for source code

SYNOPSIS

etags [-a | --append] [-f | --output=FILE] [--language=LANG] [--regex=REGEXP] ... [FILE ...]

PARAMETERS

-a, --append
    Append to existing tags file instead of overwriting.

-f FILE, --output=FILE
    Use FILE as the tags file name (default: TAGS).

--decls
    Store declarative forms in tags table (for Lisp).

--etags-include=FILE
    Include FILE as if -i used on command line.

--help
    Print this help and exit.

--ignore-indentation
    Ignore indentation when matching tags.

--include=FILE
    Include a note in the tags file about FILE.

--language=LANG
    Recognize LANG language (e.g., C, Java, Python).

--no-regex
    Do no regexp processing (use parser only).

--parse-options=OPTIONS
    Specific language parsing options.

--pattern=REGEXP
    Match non-regexp pattern for tags.

--regex=REGEXP
    Use REGEXP to describe header/tag line.

--symbol=SYMBOL
    Tag only SYMBOL occurrences.

--version
    Print version information and exit.

DESCRIPTION

etags creates a TAGS file for the Emacs editor, enabling fast navigation to symbols like functions, variables, and classes across source files. It scans files in various languages, extracting tag locations (byte offsets) and storing them in a compact database format.

Emacs uses this file for commands such as M-. (find-tag), M-x tags-search, and code browsing. etags supports built-in parsers for languages like C/C++, Java, Python, Perl, Lisp, and more. Custom tags are defined via regular expressions with --regex.

Basic usage: run etags *.c in a project directory to tag all C files. For large projects, append incrementally with -a or include subdirectories recursively via find. Output defaults to TAGS unless specified with -o.

Unlike ctags (for Vi), etags handles Emacs-specific features like regex groups for tag names, arguments, and types, making it powerful for multi-language codebases.

CAVEATS

Emacs-specific; incompatible with Vi ctags format. Large projects may need recursive invocation (e.g., via find). Regex patterns must capture tag name in group 1.

EXAMPLES

etags *.c *.h
find . -name '*.c' -o -name '*.h' | etags -
etags --regex='/def[ ]+[a-zA-Z_][a-zA-Z0-9_]*/' *.py

EMACS USAGE

Load with M-x visit-tags-table RET TAGS RET or set TAGS env var. Navigate: M-. on symbol, C-x 4 . in other window.

HISTORY

Developed for GNU Emacs by Richard Stallman in 1985; evolved with Emacs releases, adding language support and regex features over decades. Maintained in Emacs source tree.

SEE ALSO

ctags(1), emacs(1)

Copied to clipboard