ETAGS(1)

๐Ÿ“ฆ
version 31.1 ยท 3 versions
, in arch rolling, nixpkgs unstable

๐Ÿ’… GNU etags(1) โ€” tag table era, bestie ๐Ÿ’…

okay so this is the GNU etags manual page, and honestly? Itโ€™s giving โ€œquiet little tool that secretly runs your whole code-navigation situation.โ€ No cap. Letโ€™s get into it ๐Ÿซถ

๐ŸŽ€ NAME ๐ŸŽ€

etags โ€” generate tag file for Emacs, vi

โœจ SYNOPSIS โœจ

There are two synopsis moods here, and yes, the second one starts with --ctags. Keep the options exactly as they are, bestie โ€” no renaming, no merging, no โ€œfixingโ€ the vibes.

etags [-aCDGIQRVh] [-i file] [-l language]
[-o tagfile] [-r regexp] [--parse-stdin=file]
[--append] [--no-defines] [--globals] [--no-globals]
[--no-line-directive] [--include=file] [--ignore-indentation]
[--language=language] [--members] [--no-members] [--output=tagfile]
[--class-qualify] [--regex=regexp] [--no-regex] [--no-fallback-lang]
[--fallback-lang] [--no-empty-file-entries] [--empty-file-entries]
[--help] [--version] file ...

And the --ctags form:

etags --ctags [-aCdgIQRVh] [-BtTuvwx] [-l language]
[-o tagfile] [-r regexp] [--parse-stdin=file]
[--append] [--backward-search] [--cxref] [--no-defines] [--globals]
[--no-globals] [--no-line-directive] [--ignore-indentation]
[--language=language] [--members] [--no-members] [--class-qualify]
[--output=tagfile] [--regex=regexp] [--update] [--help] [--version] file
...

๐ŸŒธ DESCRIPTION ๐ŸŒธ

So the etags program is used to create a tag table file, in a format understood by emacs(1). If the first argument is the obsolescent option --ctags, the program instead creates a similar table in a format understood by vi(1). Obsolescent is the key word there, bestie โ€” noted, not erased ๐Ÿ’…

The program understands the syntax of C, Objective C, C++, Java, Fortran, Ada, Cobol, Erlang, Forth, Go, HTML, LaTeX, Emacs Lisp/Common Lisp, Lua, Makefile, Mercury, Pascal, Perl, Ruby, Rust, PHP, PostScript, Python, Prolog, Scheme and most assembler-like syntaxes. Like, the range? Iconic. ๐ŸŒˆ

It reads the files specified on the command line and writes a tag table in the current working directory. The default tag table name is TAGS, or tags if --ctags is used. Defaults stay exactly as they are โ€” we donโ€™t improvise here, periodt.

Files specified with relative file names will be recorded in the tag table with file names relative to the directory where the tag table resides. If the tag table is in /dev or is the standard output, however, the file names are made relative to the working directory. Files specified with absolute file names will be recorded with absolute file names. The path rules are lowkey doing the most, but theyโ€™re doing it consistently โœจ

Files generated from a source file โ€” like a C file generated from a source Cweb file โ€” will be recorded with the name of the source file. That detail matters, so it stays ๐Ÿ’–

Compressed files are supported using gzip, bzip2, xz, and zstd. The programs recognize the language used in an input file based on its file name and contents. And if you need to override the guessy-guess era, the --language switch can be used to force parsing of the file names following the switch according to the given language, overriding guesses based on filename extensions. Slay. ๐Ÿฆ‹

โœจ OPTIONS โœจ

okay so quick heads-up before the list: some of these options only make sense for vi style tag files, the ones you get with --ctags โ€” otherwise they just get ignored, no drama. also, both programs are chill and accept unambiguous abbreviations for long option names (so you can be lazy, but not ambiguous lazy ๐Ÿ’…).

  • -a, --append โ€” append to the existing tag file instead of starting fresh. (For vi-format tag files, also go look at --update.)
  • -B, --backward-search โ€” so tag files written in the format vi expects contain regular expression search instructions, right? -B writes those using the delimiter "?", which searches backwards through files. the default is the delimiter "/", which searches forwards. only makes sense if --ctags is in play.
  • --declarations โ€” in C and derived languages, this creates tags for function declarations, and creates tags for extern variables unless --no-globals is used. in Lisp, it creates tags for (defvar foo) declarations. in Mercury, declarations start a line with ":-" and are always tagged. bonus: this option also tags predicates or functions in first rules of clauses, as in Prolog. iconic multitasker behavior ๐ŸŽ€
  • -D, --no-defines โ€” do not create tag entries for C preprocessor constant definitions and enum constants. ngl this can make the tags file way smaller if you've got a ton of header files being tagged.
  • --globals โ€” create tag entries for global variables in Perl and Makefile. this one is already the default in C and derived languages.
  • --no-globals โ€” do not tag global variables in C and derived languages. typically this cuts the file size by one fourth, so, slay for your disk.
  • --no-line-directive โ€” ignore #line preprocessor directives in C and derived languages. the default is to honor those directives and record the tags as if the file scanned was the one named in the #line directive. this switch is your bestie when the original file named by #line isn't available anymore ๐Ÿซถ
  • -i file, --include=file โ€” drops a note in the tag file saying that when you're searching for a tag, you should also consult the tags file file after checking the current file. only etags accepts this option, ctags said no thanks.
  • -I, --ignore-indentation โ€” don't rely on indentation as much as we normally do. currently that means: don't assume a closing brace in the first column is the final brace of a function or structure definition in C and C++. this matters for code that does not follow the GNU Coding conventions of putting only top-level braces in column zero. honestly, chaotic formatting deserves love too ๐Ÿ˜ญ
  • -l language, --language=language โ€” parse the files that come after according to the given language. you can mix more than one of these in with filenames, no problem. use --help to get a list of the available languages and their default filename extensions. for example, since Mercury and Objective-C both rock the same filename extension .m, a test based on contents tries to detect the language. if that test fails, use --language=mercury or --language=objc. the "auto" language restores automatic detection of language based on the file name. the "none" language disables language parsing altogether โ€” in that case only regexp matching happens (see the --regex option).
  • --members โ€” create tag entries for variables that are members of structure-like constructs in PHP. this is the default for C and derived languages.
  • --no-members โ€” do not tag member variables. simple as that ๐Ÿฆ‹
  • --packages-only โ€” only tag packages in Ada files. that's it, that's the whole vibe.
  • --parse-stdin=file โ€” may 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. one-time guest star energy โญ
  • -Q, --class-qualify โ€” qualify tag names with their class name in C++, ObjC, Java, and Perl. this gives you tag names of the form class::member for C++ and Perl, class(category) for Objective C, and class.member for Java. for Objective C, it also produces class methods qualified with their arguments, as in foo:bar:baz:more. very demure, very qualified ๐Ÿ’…
  • -o tagfile, --output=tagfile โ€” explicit name of the file for the tag table. for etags only, a file name of - means standard output. overrides the default TAGS or tags. (but it gets ignored with -v or -x, sorry bestie.)
  • -r regexp, --regex=regexp โ€” makes tags based on regexp matching for the files that follow this option, in addition to the tags made with the standard parsing based on language. you can freely intermix it with filenames and the -R option. the regexps are cumulative, i.e., each such option adds to the previous ones. the regexps are one of these two forms:
[{language}]/tagregexp/[nameregexp/]modifiers
@regexfile

where tagregexp is used to match the tag. it should not match useless characters. if the match is such that more characters than needed are unavoidably matched by tagregexp, it may be useful to add a nameregexp to narrow down the tag scope. --ctags ignores regexps without a nameregexp. the syntax of regexps is the same as in Emacs, except that backslash escapes are the same as GNU grep (which means, for example, that shy groups are not supported), and [:ascii:], [:multibyte:], [:nonascii:], [:word:], and [:unibyte:] are not supported. these character escape sequences are supported: \a, \b, \d, \e, \f, \n, \r, \t, \v, which respectively stand for the ASCII characters BEL, BS, DEL, ESC, FF, NL, CR, TAB, VT.

the modifiers are a sequence of 0 or more characters among i, which means to ignore case when matching; m, which means the tagregexp will be matched against the whole file contents at once rather than line by line, and the matching sequence can match multiple lines; and s, which implies m and means the dot character in tagregexp matches the newline char as well.

the separator, which is / in the examples, can be any character different from space, tab, braces and @. if the separator character is needed inside the regular expression, it must be quoted by preceding it with \.

the optional {language} prefix means the tag should be created only for files of language language, and ignored otherwise. this is especially handy when you're storing a bunch of predefined regexps in a file.

in its second form, regexfile is the name of a file containing a number of arguments to the --regex= option, one per line. lines beginning with a space or tab are assumed to be comments, and ignored.

here are some examples. all the regexps are quoted to protect them from shell interpretation, bestie, don't forget:

tag the DEFVAR macros in the emacs source files:

--regex='/[ \t]*DEFVAR_[A-Z_ \t(]+"\([^"]+\)"/'

tag VHDL files (this example is a single long line, broken here for formatting reasons):

--language=none --regex='/[ \t]*\(ARCHITECTURE\|\ CONFIGURAโ€
TION\) +[^ ]* +OF/' --regex='/[ \t]*\ \(ATTRIBUTE\|ENTITY\|FUNCโ€
TION\|PACKAGE\( BODY\)?\ \|PROCEโ€
DURE\|PROCESS\|TYPE\)[ \t]+\([^ \t(]+\)/\3/'

tag Tcl files (this last example shows the usage of a tagregexp):

--lang=none --regex='/proc[ \t]+\([^ \t]+\)/\1/'

a regexp can be preceded by {lang}, which restricts it to match lines of files of the specified language. use etags --help to obtain a list of the recognized languages. this feature is particularly useful inside regex files. a regex file contains one regex per line. empty lines, and those lines beginning with space or tab, are ignored. lines beginning with @ are references to regex files whose name follows the @ sign. other lines are considered regular expressions like those following --regex. for example, the command

etags --regex=@regex.file *.c

reads the regexes contained in the file regex.file. extremely efficient, we love a shortcut ๐ŸŒธ

  • -R, --no-regex โ€” don't do any more regexp matching on the following files. can be freely intermixed with filenames and the --regex option. it's giving "we're done here" energy ๐Ÿ’€
  • --fallback-lang โ€” if a file's language cannot be determined, attempt to parse it as Fortran and C/C++. this is the default, so it's already doing the most for you.
  • --no-fallback-lang โ€” do not fall back to Fortran and C/C++ for files whose language could not be determined.
  • --empty-file-entries โ€” produce file entries for files with no tags. this is the default.
  • --no-empty-file-entries โ€” do not output file entries for files with no tags.
  • -u, --update โ€” update tag entries for files specified on the command line, leaving tag entries for other files in place. currently this is implemented by deleting the existing entries for the given files and then rewriting the new entries at the end of the tags file. honestly it's often faster to simply rebuild the entire tag file than to use this. only makes sense if --ctags is used, iykyk.
  • -v, --vgrind โ€” instead of generating a tag file, write an index (in vgrind format) to standard output. only makes sense if --ctags is used.
  • -x, --cxref โ€” instead of generating a tag file, write a cross reference (in cxref format) to standard output. only makes sense if --ctags is used.
  • -h, -H, --help โ€” print usage information. follow it with one or more --language=LANG and it prints detailed information about how tags are created for LANG. the little helper we all deserve ๐Ÿซถ
  • -V, --version โ€” print the current version of the program (same as the version of the emacs etags it is shipped with).

๐ŸŒธ SEE ALSO ๐ŸŒธ

๐Ÿ“œ COPYING ๐Ÿ“œ

Okay so legal time, bestie โ€” don't scroll, this actually matters ๐Ÿ’…

Copyright 1992, 1999, 2001โ€“2026 Free Software Foundation, Inc.

Here's the deal, in three little permission slips:

  • Permission is granted to make and distribute verbatim copies of this document โ€” provided the copyright notice and this permission notice are preserved on all copies. That's it. Keep the receipts attached and you're golden ๐Ÿซถ
  • Permission is granted to copy and distribute modified versions of this document under the same conditions as verbatim copying โ€” provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. So like, remix it, slay, but the fine print has to stay the same fine print โœจ
  • Permission is granted to copy and distribute translations of this document into another language, under the above conditions for modified versions โ€” with one exception: this permission notice may be stated in a translation approved by the Free Software Foundation. No freelance translating the legal notice without FSF approval, iykyk ๐ŸŒธ

And that's the whole page, bestie โ€” you made it to the end ๐ŸŽ€

This iconic little artifact is from GNU Tools, dated 2025-03-22, and it lives in the man page universe as ETAGS(1). Go tag some files, you absolute main character ๐Ÿ‘‘๐Ÿ’–