ctags-client-tools - Man Page
Hints for developing a tool using ctags command and tags output
Synopsis
ctags [options] [file(s)] etags [options] [file(s)]
Description
Client tool means a tool running the ctags command and/or reading a tags file generated by ctags command. This man page gathers hints for people who develop client tools.
Pseudo-Tags
Pseudo-tags, stored in a tag file, indicate how ctags generated the tags file: whether the tags file is sorted or not, which version of tags file format is used, the name of tags generator, and so on. The opposite term for pseudo-tags is regular-tags. A regular-tag is for a language object in an input file. A pseudo-tag is for the tags file itself. Client tools may use pseudo-tags as reference for processing regular-tags.
A pseudo-tag is stored in a tags file in the same format as regular-tags as described in tags(5), except that pseudo-tag names are prefixed with "!_". For the general information about pseudo-tags, see "TAG FILE INFORMATION" in tags(5).
An example of a pseudo tag:
!_TAG_PROGRAM_NAME Universal Ctags /Derived from Exuberant Ctags/
The value, "Universal Ctags", associated with the pseudo tag TAG_PROGRAM_NAME, is used in the field for input file. The description, "Derived from Exuberant Ctags", is used in the field for pattern.
Universal Ctags extends the naming scheme of the classical pseudo-tags available in Exuberant Ctags for emitting language specific information as pseudo tags:
!_{pseudo-tag-name}!{language-name} {associated-value} /{description}/
The language-name is appended to the pseudo-tag name with a separator, "!".
An example of pseudo tag with a language suffix:
!_TAG_KIND_DESCRIPTION!C f,function /function definitions/
This pseudo-tag says "the function kind of C language is enabled when generating this tags file." --pseudo-tags is the option for enabling/disabling individual pseudo-tags. When enabling/disabling a pseudo tag with the option, specify the tag name only TAG_KIND_DESCRIPTION, without the prefix ("!_") or the suffix ("!C").
Redundant-Kinds
TBW (Write about --fields=+kKzZ)
Multiple-Languages for an Input File
Universal ctags can run multiple parsers. That means a parser, which supports multiple parsers (guest parsers or sub-parsers), may output tags for different languages.
Guest parsers
A parser can run guest pursers on the areas in a source file.
Consider the following text as a source file ("input.html"):
<html><head> <script>class MyObject {}</script> <style type="text/css">h1.heading { color: red; }</style> </htad> <h1 class='heading'>title</h1> </html>
If a user doesn't specify any extras, Universal ctags emits:
$ ctags -o - input.html title input.html /^<h1 class='heading'>title<\/h1>$/;" h
These is no issue here. running guest pursers extra is disabled by default.
If a user enables the running guest parsers extra with specifying --extras=+{guest} or --extras=+g, Universal ctags emits:
$ ctags -o - --extras='{guest}' input.html MyObject input.html /class MyObject {}/;" c h1.heading input.html /h1.heading { color: red; }/;" c title input.html /^<h1 class='heading'>title<\/h1>$/;" h
Universal ctags extracts the language objects for CSS and JavaScript; the HTML parser runs JavaScript parser on the area "<script>...</script>" area and CSS parser on the area "<style ...> ...</style>" area.
If a client tool assumes that ctags runs one parser for an input file, the tool may tell "MyObject is a class of HTML" and/or "h1.heading is a class of HTML" to its users. c is too few information to tell what is "MyObject" and what is "h1.heading" correctly. The client tool needs more information.
language/l field can be used to show the language for each tag.
$ ctags -o - --extras='{guest}' --fields=+'{language}' input.html MyObject input.html /class MyObject {}/;" c language:JavaScript h1.heading input.html /h1.heading { color: red; }/;" c language:CSS title input.html /^<h1 class='heading'>title<\/h1>$/;" h language:HTML
For some class tools, the language: field provides enough information. Universal ctags can emits more self-descriptive tag file.
Enabling K field with --fields=+K option, Universal ctags uses long-names instead of single-letter to represent kind fields:
$ ctags -o - --extras='{guest}' --fields=+'{language}K' input.html MyObject /tmp/input.html /class MyObject {}/;" class language:JavaScript h1.heading /tmp/input.html /h1.heading { color: red; }/;" class language:CSS title /tmp/input.html /^<h1 class='heading'>title<\/h1>$/;" heading1 language:HTML
The long-name representation makes tag files larger. If you want to keep a tag file small, you can make your tool utilize pseudo-tags instead of enabling K field. Universal ctags emits the following line at the beginning of a tags file by default:
$ cat ./tags ... !_TAG_KIND_DESCRIPTION!CSS c,class /classes/ ... !_TAG_KIND_DESCRIPTION!HTML c,class /classes/ !_TAG_KIND_DESCRIPTION!HTML h,heading1 /H1 headings/ ... !_TAG_KIND_DESCRIPTION!JavaScript c,class /classes/ ...
From the second field of the output, a tool can know the mapping between a single-letter for a kind and a long-name for the kind.
Universal ctags emits pseudo-tags to tag files by default. However, if you make ctags emit to standard output with -o - or -f - option, ctags doesn't print pseudo-tags. pseudo/p extra forces emitting.
$ ctags -o - --extras='{guest}{pseudo}' --fields=+'{language}' input.html ... !_TAG_KIND_DESCRIPTION!CSS c,class /classes/ ... !_TAG_KIND_DESCRIPTION!HTML c,class /classes/ !_TAG_KIND_DESCRIPTION!HTML h,heading1 /H1 headings/ ... !_TAG_KIND_DESCRIPTION!JavaScript c,class /classes/ ...
Sub-parsers
TBW
JSON Output
See ctags-json-output(5).
Changes
Version 6.0
- ctags enables TAG_KIND_DESCRIPTION, TAG_ROLE_DESCRIPTION, TAG_FIELD_DESCRIPTION, and TAG_EXTRA_DESCRIPTION pseudo tags by default.
- TAG_PARSER_VERSION is introduced.
See Also
ctags(1), ctags-lang-python(7), ctags-incompatibilities(7), tags(5), ctags-json-output(5), readtags(1), 7.2 Libtool’s versioning system <https://www.gnu.org/software/libtool/manual/libtool.html#Libtool-versioning>
Referenced By
ctags(1), ctags-json-output(5), ctags-lang-elm(7), ctags-lang-inko(7), ctags-lang-iPythonCell(7), ctags-lang-javascript(7), ctags-lang-julia(7), ctags-lang-python(7), ctags-lang-rmarkdown(7), ctags-lang-sql(7), ctags-lang-verilog(7), readtags(1), tags(5).