ctags | Début | Suivant | Sommaire | Préc.page.lue | Accueil |
NAME | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
SYNOPSIS | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
DESCRIPTION | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
Alternatively, ctags can generate a cross reference file which lists, in human readable form, information about the various source objects found in a set of language files.
Tag index files are supported by numerous editors, which allow the user to locate the object associated with a name appearing in a source file and jump to the file and line which defines the name. Those known about at the time of this release are:
Ctags is capable of generating different kinds of tags for each of many different languages. For a complete list of supported languages, the names by which they are recognized, and the kinds of tags which are generated for each, see the --list-languages and --list-kinds options.
SOURCE FILES | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
Unless the --language-force option is specified, the language of each source file is automatically selected based upon a mapping of file names to languages. The mappings in effect for each language may be display using the --list-maps option and may be changed using the --langmap option. On platforms which support it, if the name of a file is not mapped to a language and the file is executable, the first line of the file is checked to see if the file is a "#!" script for a recognized language.
By default, all other files names are ignored. This permits running ctags on all files in either a single directory (e.g. "ctags *"), or on all files in an entire source directory tree (e.g. "ctags -R"), since only those files whose names are mapped to languages will be scanned.
[The reason that .h extensions are mapped to C++ files rather than C files is because it is common to use .h extensions in C++, and no harm results in treating them as C++ files.]
OPTIONS | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
Despite the wealth of available options, defaults are set so that ctags is most commonly executed without any options (e.g. "ctags *", or "ctags -R"), which will create a tag file in the current directory for all recognized source files. The options described below are provided merely to allow custom tailoring to meet special needs.
Note that spaces separating the single-letter options from their parameters are optional.
Note also that the boolean parameters to the long form options (those beginning with "--" and that take a "[=yes|no]" parameter) may be omitted, in which case "=yes" is implied. (e.g. --sort is equivalent to --sort=yes). Note further that "=1" and "=on" are considered synonyms for "=yes", and that "=0" and "=off" are considered synonyms for "=no".
Some options are either ignored or useful only when used while running in etags mode (see -e option). Such options will be noted.
Most options may appear anywhere on the command line, affecting only those files which follow the option. A few options, however, must appear before the first file name and will be noted as such.
Options taking language names will accept those names in either upper or lower case. See the --list-languages option for a complete list of the built-in language names.
This feature is useful when preprocessor macros are used in such a way that they cause syntactic confusion due to their presence. Indeed, this is the best way of working around a number of problems caused by the presence of syntax-busting macros in source files (see CAVEATS, below). Some examples will illustrate this point.
If pattern begins with the character '@', then the rest of the string is interpreted as a file name from which to read exclusion patterns, one per line. If pattern is empty, the list of excluded patterns is cleared. Note that at program startup, the default exclude list contains "EIFGEN", "SCCS", "RCS", and "CVS", which are names of directories for which it is generally not desirable to descend while processing the --recurse option.
The valid values for type (either the entire word or the first letter is accepted) are:
As an example for the C language, in order to add prototypes and external variable declarations to the default set of tag kinds, but exclude macros, use --c-kinds=+px-d; to include only tags for functions, use --c-kinds=f.
If the first character in a map is a plus sign, then the extensions and file name patterns in that map will be appended to the current map for that language; otherwise, the map will replace the current map. For example, to specify that only files with extensions of .c and .x are to be treated as C language files, use "--langmap=c:.c.x"; to also add files with extensions of .j as Java language files, specify "--langmap=c:.c.x,java:+.j". To map makefiles (e.g. files named either "Makefile", "makefile", or having the extension ".mak") to a language called "make", specify "--langmap=make:([Mm]akefile).mak". To map files having no extension, specify a period not followed by a non-period character (e.g. ".", "..x", ".x."). To clear the mapping for a particular language (thus inhibiting automatic generation of tags for that language), specify an empty extension list (e.g. "--langmap=fortran:"). To restore the default language mappings for all a particular language, supply the keyword "default" for the mapping. To specify restore the default language mappings for all languages, specify "--langmap=default". Note that file extensions are tested before file name patterns when inferring the language of a file.
Unless modified by flags, regexp is interpreted as a Posix extended regular expression. The replacement should expand for all matching lines to a non-empty string of characters, or a warning message will be reported. An optional kind specifier for tags matching regexp may follow replacement, which will determine what kind of tag is reported in the "kind" extension field (see TAG FILE FORMAT, below). The full form of kind-spec is in the form of a single letter, a comma, a name (without spaces), a comma, a description, followed by a separator, which specify the short and long forms of the kind value and its textual description (displayed using --list-kinds). Either the kind name and/or the description may be omitted. If kind-spec is omitted, it defaults to "r,regex". Finally, flags are one or more single-letter characters having the following effect upon the interpretation of regexp:
For more information on the regular expressions used by ctags, see either the regex(5,7) man page, or the GNU info documentation for regex (e.g. "info regex").
OPERATIONAL DETAILS | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
As ctags considers each file name in turn, it tries to determine the language of the file by applying the following three tests in order: if the file extension has been mapped to a language, if the file name matches a shell pattern mapped to a language, and finally if the file is executable and its first line specifies an interpreter using the Unix-style "#!" specification (if supported on the platform). If a language was identified, the file is opened and then the appropriate language parser is called to operate on the currently open file. The parser parses through the file and adds an entry to the tag file for each language object it is written to handle. See TAG FILE FORMAT, below, for details on these entries.
This implementation of ctags imposes no formatting requirements on C code as do legacy implementations. Older implementations of ctags tended to rely upon certain formatting assumptions in order to help it resolve coding dilemmas caused by preprocessor conditionals.
In general, ctags tries to be smart about conditional preprocessor directives. If a preprocessor conditional is encountered within a statement which defines a tag, ctags follows only the first branch of that conditional (except in the special case of "#if 0", in which case it follows only the last branch). The reason for this is that failing to pursue only one branch can result in ambiguous syntax, as in the following example:
Both branches cannot be followed, or braces become unbalanced and ctags would be unable to make sense of the syntax.
If the application of this heuristic fails to properly parse a file, generally due to complicated and inconsistent pairing within the conditionals, ctags will retry the file using a different heuristic which does not selectively follow conditional preprocessor branches, but instead falls back to relying upon a closing brace ("}") in column 1 as indicating the end of a block once any brace imbalance results from following a #if conditional branch.
Ctags will also try to specially handle arguments lists enclosed in double sets of parentheses in order to accept the following conditional construct:
Any name immediately preceding the "((" will be automatically ignored and the previous name will be used.
C++ operator definitions are specially handled. In order for consistency with all types of operators (overloaded and conversion), the operator name in the tag file will always be preceded by the string "operator " (i.e. even if the actual operator definition was written as "operator<<").
After creating or appending to the tag file, it is sorted by the tag name, removing identical tag lines.
TAG FILE FORMAT | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
When not running in etags mode, each entry in the tag file consists of a separate line, each looking like this in the most general case:
The fields and separators of these lines are specified as follows:
A few special tags are written into the tag file for internal purposes. These tags are composed in such a way that they always sort to the top of the file. Therefore, the first two characters of these tags are used a magic number to detect a tag file for purposes of determining whether a valid tag file is being overwritten rather than a source file.
Note that the name of each source file will be recorded in the tag file exactly as it appears on the command line. Therefore, if the path you specified on the command line was relative to the current directory, then it will be recorded in that same manner in the tag file. See, however, the --tag-relative option for how this behavior can be modified.
Extension fields are tab-separated key-value pairs appended to the end of the EX command as a comment, as described above. These key value pairs appear in the general form "key:value". Their presence in the lines of the tag file are controlled by the --fields option. The possible keys and the meaning of their values are as follows:
In addition, information on the scope of the tag definition may be available, with the key portion equal to some language-dependent construct name and its value the name declared for that construct in the program. This scope entry indicates the scope in which the tag was found. For example, a tag generated for a C structure member would have a scope looking like "struct:myStruct".
HOW TO USE WITH VI | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
HOW TO USE WITH GNU EMACS | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
For more commands, see the Tags topic in the Emacs info document.
HOW TO USE WITH NEDIT | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
CAVEATS | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
Note that since ctags generates patterns for locating tags (see the --excmd option), it is entirely possible that the wrong line may be found by your editor if there exists another source line which is identical to the line containing the tag. The following example demonstrates this condition:
/* ... */
void foo(variable)
int variable;
{
Depending upon which editor you use and where in the code you happen to be, it is possible that the search pattern may locate the local parameter declaration in foo() before it finds the actual global variable definition, since the lines (and therefore their search patterns are identical). This can be avoided by use of the --excmd=n option.
BUGS | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
When parsing a C++ member function definition (e.g. "className::function"), ctags cannot determine whether the scope specifier is a class name or a namespace specifier and always lists it as a class name in the scope portion of the extension fields. Also, if a C++ function is defined outside of the class declaration (the usual case), the access specification (i.e. public, protected, or private) and implementation information (e.g. virtual, pure virtual) contained in the function declaration are not known when the tag is generated for the function definition. It will, however be available for prototypes (e.g --c++-kinds=+p).
No qualified tags are generated for language objects inherited into a class.
ENVIRONMENT VARIABLES | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
FILES | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
SEE ALSO | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
Also ex(1), vi(1), elvis, or, better yet, vim, the official editor of ctags. For more information on vim, see the VIM Pages web site at:
AUTHOR | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
MOTIVATION | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
"All effort and exertion put forth by man from the fullness of his heart is worship, if it is prompted by the highest motives and the will to do service to humanity."
CREDITS | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
Credit is also due Bram Moolenaar <Bram@vim.org>, the author of vim, who has devoted so much of his time and energy both to developing the editor as a service to others, and to helping the orphans of Uganda.
The section entitled "HOW TO USE WITH GNU EMACS" was shamelessly stolen from the info page for GNU etags.
Sommaire | Début | Suivant | Sommaire | Préc.page.lue | Accueil |
Table des mots clés | Début | Suivant | Sommaire | Préc.page.lue | Accueil |