Ctags Explained

Ctags (BSD)
Developer:Ken Arnold
Operating System:Unix and Unix-like
Platform:Cross-platform
Genre:Programming tool (Specifically: Code navigation tool)
License:BSD

Ctags is a programming tool that generates an index file (or tag file) of names found in source and header files of various programming languages to aid code comprehension. Depending on the language, functions, variables, class members, macros and so on may be indexed. These tags allow definitions to be quickly and easily located by a text editor, a code search engine, or other utility. Alternatively, there is also an output mode that generates a cross reference file, listing information about various names found in a set of language files in human-readable form.

The original Ctags was introduced in BSD Unix 3.0 and was written by Ken Arnold, with Fortran support by Jim Kleckner and Pascal support by Bill Joy. It is part of the initial release of Single Unix Specification and XPG4 of 1992.

Editors that support ctags

Tag index files are supported by many source code editors, including:

Variants of ctags

There are a few other implementations of the ctags program:

Etags

GNU Emacs comes with two ctags utilities, etags and ctags, which are compiled from the same source code. Etags generates a tag table file for Emacs, while the ctags command is used to create a similar table in a format understood by vi. They have different sets of command line options:etags does not recognize and ignores options which only make sense for vi style tag files produced by the ctags command.

Exuberant Ctags

Exuberant Ctags, written and maintained by Darren Hiebert until 2009,[4] was initially distributed with Vim, but became a separate project upon the release of Vim 6. It includes support for Emacs and compatibility.[5]

Exuberant Ctags includes support for over 40 programming languages with the ability to add support for even more using regular expressions.

Universal Ctags

Universal Ctags is a fork of Exuberant Ctags, with the objective of continuing its development. A few parsers are rewritten to better support the languages.[6]

Language-specific

creates ctags compatible tag files for Haskell source files.[7] It includes support for creating Emacs etags files.[8]

is a ctags-compatible code indexing solution for JavaScript.[9] It is specialized for JavaScript and uses the CommonJS packaging system. It outperforms Exuberant Ctags for JavaScript code, finding more tags than the latter.[10]

Tags file formats

There are multiple tag file formats. Some of them are described below. In the following, represents the byte with hexadecimal representation . Every line ends with a line feed (LF, =).

Ctags and descendants

The original ctags and the Exuberant/Universal descendants have similar file formats:[11]

Ctags

This is the format used by vi and various clones. The tags file is normally named "tags".

The tags file is a list of lines, each line in the format:

\t\t

The fields are specified as follows:

The tags file is sorted on the field which allows for fast searching of the tags file.

Extended Ctags

This is the format used by Vim's Exuberant Ctags and Universal Ctags. These programs can generate an original ctags file format or an extended format that attempts to retain backward compatibility.

The extended tags file is a list of lines, each line in the format:

\t\t[;"\<u>t</u>{'''tagfield'''...}]

The fields up to and including are the same as for ctags above.

Optional additional fields are indicated by square brackets ("[...]") and include:

This format is compatible with non-POSIX vi as the additional data is interpreted as a comment. POSIX implementations of vi must be changed to support it, however.[11]

Etags

This is the format used by Emacs etags. The tags file is normally named "TAGS".

The etags files consists of multiple sections - one section per input source file. Sections are plain-text with several non-printable ascii characters used for special purposes. These characters are represented as underlined hexadecimal codes below.

A section starts with a two line header (the first two bytes make up a magic number):

\x0c,

The header is followed by tag definitions, one definition per line, with the format:

\x7f\x01,

can be omitted if the name of the tag can be deduced from the text at the tag definition.

Example

Given a single line test.c source code:

#define CCC(x)

The TAGS (etags) file would look like this:

\x0c test.c,21 #define CCC(\x7fCCC\x011,0

The tags (ctags) file may look like:

CCC(test.c	1

or more flexibly using a search:

CCC(test.c	/^#define CCC(/

See also

External links

Notes and References

  1. Web site: Language Server Protocol . CodeLite Documentation . 2022-06-12.
  2. Web site: Aminet - dev/C/Ctags.lha.
  3. https://donjayamanne.github.io/pythonVSCodeDocs/docs/workspaceSymbols/ Workspace Symbols
  4. Web site: Exuberant Ctags . ctags.sourceforge.net.
  5. Web site: Vim documentation: version6: ctags-gone. 2007-04-28.
  6. Web site: Universal Ctags Documentation. 2018-08-02.
  7. Web site: GHC documentation: Other Haskell utility programs. 2010-03-05.
  8. Web site: hasktags: Produces ctags "tags" and etags "TAGS" files for Haskell programs. 2010-03-05.
  9. Web site: pcwalton github repository for jsctags. . 2016-09-10. https://web.archive.org/web/20100822181929/http://github.com/pcwalton/jsctags. 2010-08-22. dead.
  10. Web site: Introducing jsctags. Patrick Walton. 25 May 2010. 2010-05-25.
  11. Web site: Proposal for extended Vi tags file format. 2007-06-30.