Ctags
Encyclopedia
Ctags is a program that generates an index
(or tag) file of names found in source and header files of various programming language
s.
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
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 and was written by Ken Arnold
, with Fortran support by Jim Kleckner and Pascal support by Bill Joy
.
s, including:
style tag files produced by ctags, etags could not recognize them and would ignore them.
, but became a separate project upon the release of Vim 6. It includes support for Emacs compatibility.
Exuberant Ctags includes support for over 40 programming languages with the ability to add support for even more using regular expression
s.
source files. It includes support for creating Emacs etags files.
. It is specialized for JavaScript and its packaging system CommonJS
and outperforms Exuberant Ctags for JavaScript code, finding more tags than the latter.
The tags file is a list of lines, each line in the format:
{tagname}<Tab>{tagfile}<Tab>{tagaddress}
The fields are specified as follows:
The tags file is sorted on the {tagname} field which allows for fast searching of the tags file.
. It can generate an original ctags file format or an extended format that attempts to retain backward compatibility.
The fields are specified as follows:
{tagname}<Tab>{tagfile}<Tab>{tagaddress}[;"<Tab>{tagfield}...]
The fields up to and including {tagaddress} are the same as for ctags above.
Optional additional fields:
Extended format extends the {tagaddress} field under certain circumstances to include a set of extension fields embedded in an ex comment immediately appended to the ex command, which leaves it backward-compatible with original vi implementations. These extension fields are tab separated "key:value" pairs, documented in the ctags manual.
The etags files consists of multiple sections—one section per input source file. Sections are plain-text with several non-ascii characters used for special purposes. These characters are represented as bracketed hexadecimal codes below.
A section starts with a two line header, one line containing a single <\x0c> character, followed by a line which consists of:
{src_file},{size_of_tag_definition_data_in_bytes}
The header is followed by tag definitions, one definition per line, with the format:
{tag_definition_text}<\x7f>{tagname}<\x01>{line_number},{byte_offset}
{tagname} (along with \x01) can be omitted if the name of the tag can be deduced from the text at the tag definition.
#define CCC(x)
The TAGS file would look like this:
<\x0c>
test.c,21
#define CCC(<\x7f>CCC<\x01>1,0
Index (publishing)
An index is a list of words or phrases and associated pointers to where useful material relating to that heading can be found in a document...
(or tag) file of names found in source and header files of various programming language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....
s.
Depending on the language,
functions,
variables
Variable (programming)
In computer programming, a variable is a symbolic name given to some known or unknown quantity or information, for the purpose of allowing the name to be used independently of the information it represents...
,
class
Class (computer science)
In object-oriented programming, a class is a construct that is used as a blueprint to create instances of itself – referred to as class instances, class objects, instance objects or simply objects. A class defines constituent members which enable these class instances to have state and behavior...
members,
macros and so on
may be indexed.
These tags allow definitions to be quickly and easily located by a text editor
Text editor
A text editor is a type of program used for editing plain text files.Text editors are often provided with operating systems or software development packages, and can be used to change configuration files and programming language source code....
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
Human-readable
A human-readable medium or human-readable format is a representation of data or information that can be naturally read by humans.In computing, human-readable data is often encoded as ASCII or Unicode text, rather than presented in a binary representation...
form.
The original Ctags was introduced in BSD Unix and was written by Ken Arnold
Ken Arnold
Kenneth Cutts Richard Cabot Arnold is an American computer programmer well known as one of the developers of the 1980s dungeon-crawling computer game Rogue, for his contributions to the original Berkeley distribution of Unix, for his books and articles about C and C++ Kenneth Cutts Richard Cabot ...
, with Fortran support by Jim Kleckner and Pascal support by Bill Joy
Bill Joy
William Nelson Joy , commonly known as Bill Joy, is an American computer scientist. Joy co-founded Sun Microsystems in 1982 along with Vinod Khosla, Scott McNealy and Andy Bechtolsheim, and served as chief scientist at the company until 2003...
.
Editors that support ctags
Tag index files are supported by many source code editorSource code editor
A source code editor is a text editor program designed specifically for editing source code of computer programs by programmers. It may be a standalone application or it may be built into an integrated development environment ....
s, including:
- AcroEdit
- BBEdit 8+BBEditBBEdit is a proprietary text editor made by Bare Bones Software. It was originally developed for Macintosh System Software 6 and is now available for Mac OS X.BBEdit is marketed under the trademark slogan, "It doesn't suck."-History:...
- codeliteCodeliteCodeLite is a free, open-source, cross-platform IDE for the C/C++ programming languages.- History :On August 2006 Eran Ifrah, CodeLite's author, started a project named CodeLite...
use ctags as its tag indexer for code completion. - EmacsEmacsEmacs is a class of text editors, usually characterized by their extensibility. GNU Emacs has over 1,000 commands. It also allows the user to combine these commands into macros to automate work.Development began in the mid-1970s and continues actively...
and XEmacsXEmacsXEmacs is a graphical- and console-based text editor which runs on almost any Unix-like operating system as well as Microsoft Windows. XEmacs is a fork, based on a version of GNU Emacs from the late 1980s... - EmEditor ProfessionalEmEditorEmEditor is a lightweight extensible commercial text editor for Microsoft Windows. It was developed by Yutaka Emura of Emurasoft, Inc. EmEditor includes full Unicode support, 32-bit and 64-bit builds, syntax highlighting, find and replace with regular expressions, vertical selection editing,...
- GeditGeditgedit is a text editor for the GNOME desktop environment, Mac OS X and Microsoft Windows. Designed as a general purpose text editor, gedit emphasizes simplicity and ease of use...
(via gedit-symbol-browser-plugin found on http://www.micahcarrick.com/11-14-2007/gedit-symbol-browser-plugin.html) - JEDJED (text editor)JED is a text editor that makes extensive use of the S-Lang library. It is highly cross-platform compatible; JED runs on Windows and all flavors on Linux and Unix. Older versions are available for DOS. It is also very lightweight , which makes it an ideal editor for older systems, embedded systems,...
- jEditJEditjEdit is a text editor for programmers, available under the GNU General Public License version 2.0. It is written in Java and runs on any operating system with Java support, including Windows, Linux, Mac OS X, and BSD.-Development:...
(via plugins CodeBrowser, Tags, ClassBrowser, CtagsSideKick, and Jump) - JOEJoe's Own EditorJOE or Joe's Own Editor is a terminal-based text editor for Unix systems, available under the GPL. It is designed to be easy to use.JOE is distributed in most major Linux distributions and open-source BSD systems.- Description of features :...
- KDevelopKDevelopKDevelop is a free software integrated development environment for the KDE Platform on Unix-like computer operating systems. KDevelop includes no compiler. Instead, it uses an external compiler such as gcc to produce executable code....
- KateKate (text editor)In computing, Kate is a text editor by KDE. The name Kate is an acronym for KDE Advanced Text Editor.-History:Kate has been part of KDE Software Compilation since release 2.2 in 2001. Because of the KParts technology, it is possible to embed Kate as an editing component in other KDE applications...
- Multi-Edit 2008
- NEditNEditNEdit, the Nirvana editor, is a text editor and source code editor for the X Window System. It has an interface similar to text editors on Microsoft Windows and Macintosh, rather than to older UNIX editors like Emacs...
- Notepad++Notepad++Notepad++ is a text editor and source code editor for Windows. One advantage of Notepad++ over the built-in Windows text editor, Notepad, is tabbed editing, which allows working with multiple open files.Notepad++ is distributed as free software...
(via OpenCTags plug-in) - Programmer's NotepadProgrammer's NotepadProgrammer's Notepad is an open-source text editor targeted at users who work with source code. It was released in 1998 by Echo Software . PN1's successor, Programmer's Notepad 2 , was released in 2002 and is now based on Scintilla...
- QDevelopQDevelopQDevelop is a free software integrated development environment specialized on the Qt4 framework and C++.It uses gcc for building and gdb for debugging....
- TSE (via macro)The SemWare EditorThe SemWare Editor is a text editor computer program for MSDOS, Microsoft Windows, and OS/2.Starting in November 1985 as a shareware program called "Qedit" , Qedit was eventually modified to run as a Terminate and Stay Resident program, and ported to OS/2 and eventually evolved to TSE...
- TextMateTextMateTextMate is a general-purpose GUI text editor for Mac OS X created by Allan Odgaard. Popular with programmers, some notable features include declarative customizations, tabs for open documents, recordable macros, folding sections and snippets, shell integration, and an extensible bundle...
(via CodeBrowser-PlugIn) - UltraEditUltraEditUltraEdit is a commercial text editor for Microsoft Windows, Linux and created in 1994 by Ian D. Mead. The editor contains tools for programmers, including macros, configurable syntax highlighting, code folding, file type conversions, project management, regular expressions for search-and-replace,...
- TextPadTextPadTextPad is a text editor for the Microsoft Windows family of operating systems.First released in 1992, this software is currently in its fifth major version...
- VEDITVEDITVedit is a commercial text editor for Microsoft Windows and MS-DOS from Greenview Data, Inc.Vedit was one of the pioneers in visual editing. Today, it is a powerful and feature-rich general-purpose text editor....
- viVivi is a screen-oriented text editor originally created for the Unix operating system. The portable subset of the behavior of vi and programs based on it, and the ex editor language supported within these programs, is described by the Single Unix Specification and POSIX.The original code for vi...
(and derivatives such as ElvisElvis (text editor)Elvis is a powerful vi/ex clone, i.e. it resembles the Unix text editor "vi" very much but adds quite a few commands and features. Elvis is written by Steve Kirkendall and is distributed under the Clarified Artistic License which is used by Perl....
, NviNvinvi is a re-implementation of the classic Berkeley text editor, ex/vi, traditionally distributed with BSD, and later, Unix systems. It was originally distributed as part of the Fourth Berkeley Software Distribution ....
, VimVim (text editor)Vim is a text editor written by Bram Moolenaar and first released publicly in 1991. Based on the vi editor common to Unix-like systems, Vim is designed for use both from a command line interface and as a standalone application in a graphical user interface...
, vile, etc.) - Zeus IDE http://www.zeusedit.com
- mcedit (Midnight Commander builtin editor) http://www.midnight-commander.org
Etags
Etags is the ctags utility that comes with Emacs. For those options which only make sense for viVi
vi is a screen-oriented text editor originally created for the Unix operating system. The portable subset of the behavior of vi and programs based on it, and the ex editor language supported within these programs, is described by the Single Unix Specification and POSIX.The original code for vi...
style tag files produced by ctags, etags could not recognize them and would ignore them.
Exuberant Ctags
Exuberant Ctags, written and maintained by Darren Hiebert, was initially distributed with VimVim (text editor)
Vim is a text editor written by Bram Moolenaar and first released publicly in 1991. Based on the vi editor common to Unix-like systems, Vim is designed for use both from a command line interface and as a standalone application in a graphical user interface...
, but became a separate project upon the release of Vim 6. It includes support for Emacs compatibility.
Exuberant Ctags includes support for over 40 programming languages with the ability to add support for even more using regular expression
Regular expression
In computing, a regular expression provides a concise and flexible means for "matching" strings of text, such as particular characters, words, or patterns of characters. Abbreviations for "regular expression" include "regex" and "regexp"...
s.
Hasktags
Hasktags creates ctags compatible tag files for HaskellHaskell (programming language)
Haskell is a standardized, general-purpose purely functional programming language, with non-strict semantics and strong static typing. It is named after logician Haskell Curry. In Haskell, "a function is a first-class citizen" of the programming language. As a functional programming language, the...
source files. It includes support for creating Emacs etags files.
jsctags
jsctags is a ctags-compatible code indexing solution for JavaScriptJavaScript
JavaScript is a prototype-based scripting language that is dynamic, weakly typed and has first-class functions. It is a multi-paradigm language, supporting object-oriented, imperative, and functional programming styles....
. It is specialized for JavaScript and its packaging system CommonJS
CommonJS
CommonJS is a project with the goal of specifying an ecosystem for JavaScript outside the browser . The project was started by Kevin Dangoor in January 2009 and initially named ServerJS....
and outperforms Exuberant Ctags for JavaScript code, finding more tags than the latter.
Tags file formats
There are multiple tag file formats. Some of them are described below. In the following, <\x##> represents the byte with hexadecimal representation ##.Ctags and Exuberant Ctags
The original ctags and Exuberant Ctags have similar file formats: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:
{tagname}<Tab>{tagfile}<Tab>{tagaddress}
The fields are specified as follows:
- {tagname} – Any identifier, not containing white space
- <Tab> – Exactly one tabTab keyTab key on a keyboard is used to advance the cursor to the next tab stop.- Origin :The word tab derives from the word tabulate, which means "to arrange data in a tabular, or table, form"...
character, although many versions of vi can handle any amount of white space - {tagfile} – The name of the file where {tagname} is defined, relative to the current directory
- {tagaddress} – An ex mode command that will take the editor to the location of the tag. For POSIX implementations of vi this may only be a search or a line number.
The tags file is sorted on the {tagname} field which allows for fast searching of the tags file.
Exuberant Ctags
This is the format used by VimVim (text editor)
Vim is a text editor written by Bram Moolenaar and first released publicly in 1991. Based on the vi editor common to Unix-like systems, Vim is designed for use both from a command line interface and as a standalone application in a graphical user interface...
. It can generate an original ctags file format or an extended format that attempts to retain backward compatibility.
The fields are specified as follows:
{tagname}<Tab>{tagfile}<Tab>{tagaddress}[;"<Tab>{tagfield}...]
The fields up to and including {tagaddress} are the same as for ctags above.
Optional additional fields:
;" – semicolon + doublequote: Ends the {tagaddress} in way that looks like the start of a comment to vi.- {tagfield}
Extended format extends the {tagaddress} field under certain circumstances to include a set of extension fields embedded in an ex comment immediately appended to the ex command, which leaves it backward-compatible with original vi implementations. These extension fields are tab separated "key:value" pairs, documented in the ctags manual.
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-ascii characters used for special purposes. These characters are represented as bracketed hexadecimal codes below.
A section starts with a two line header, one line containing a single <\x0c> character, followed by a line which consists of:
{src_file},{size_of_tag_definition_data_in_bytes}
The header is followed by tag definitions, one definition per line, with the format:
{tag_definition_text}<\x7f>{tagname}<\x01>{line_number},{byte_offset}
{tagname} (along with \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 file would look like this:
<\x0c>
test.c,21
#define CCC(<\x7f>CCC<\x01>1,0