xref: /Universal-ctags/docs/output-xref.rst (revision 45e335ab6e42c701cb0966c081b8e1b20878ce01)
108ba6dabSMasatake YAMATO.. NOT REVIEWED YET
208ba6dabSMasatake YAMATO
3ef5b78aeSHiroo HAYASHI.. _output-xref:
4ef5b78aeSHiroo HAYASHI
508ba6dabSMasatake YAMATO======================================================================
608ba6dabSMasatake YAMATOXref output
708ba6dabSMasatake YAMATO======================================================================
808ba6dabSMasatake YAMATO
9ef5b78aeSHiroo HAYASHIXref output is a tabular, human-readable cross reference (xref) format.
10ef5b78aeSHiroo HAYASHI
11ef5b78aeSHiroo HAYASHIThe default information contained in the output includes:
12ef5b78aeSHiroo HAYASHI
13ef5b78aeSHiroo HAYASHI* the tag name
14ef5b78aeSHiroo HAYASHI* the kind of tag
15ef5b78aeSHiroo HAYASHI* the line number
16ef5b78aeSHiroo HAYASHI* file name
17ef5b78aeSHiroo HAYASHI* source line (with extra white space condensed) of the file
18ef5b78aeSHiroo HAYASHI
19ef5b78aeSHiroo HAYASHI``--_xformat`` option allows a user to customize the output information.  See
20ef5b78aeSHiroo HAYASHI:ref:`Customizing xref output <xformat>` for more details.
21ef5b78aeSHiroo HAYASHI
22ef5b78aeSHiroo HAYASHIXref output goes to standard output by default.
23ef5b78aeSHiroo HAYASHI
24ef5b78aeSHiroo HAYASHINotes:
25ef5b78aeSHiroo HAYASHI
26e25cbcacSK.Takata    * Printing `z`{kind} field in xref format doesn't include `kind:` prefix.
27e25cbcacSK.Takata    * Printing `Z`{scope} field in xref format doesn't include `scope:` prefix.
2804213d62SHiroo HAYASHI
2904213d62SHiroo HAYASHI.. _xformat:
3004213d62SHiroo HAYASHI
3104213d62SHiroo HAYASHICustomizing xref output
3204213d62SHiroo HAYASHI~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3304213d62SHiroo HAYASHI
3404213d62SHiroo HAYASHI``--_xformat`` option allows a user to customize the cross reference
3504213d62SHiroo HAYASHI(xref) output enabled with ``-x``.
3604213d62SHiroo HAYASHI::
3704213d62SHiroo HAYASHI
3804213d62SHiroo HAYASHI   --_xformat=FORMAT
3904213d62SHiroo HAYASHI
4004213d62SHiroo HAYASHI
4104213d62SHiroo HAYASHIThe notation for FORMAT is similar to that employed by `printf(3)` in
4204213d62SHiroo HAYASHIthe C language; `%` represents a slot which is substituted with a
4304213d62SHiroo HAYASHIfield value when printing. You can specify multiple slots in FORMAT.
4404213d62SHiroo HAYASHIHere field means an item listed with ``--list-fields`` option.
4504213d62SHiroo HAYASHI
4604213d62SHiroo HAYASHIThe notation of a slot::
4704213d62SHiroo HAYASHI
4804213d62SHiroo HAYASHI   %[-][.][WIDTH-AND-ADJUSTMENT]FIELD-SPECIFIER
4904213d62SHiroo HAYASHI
5004213d62SHiroo HAYASHI``FIELD-SPECIFIER`` specifies a field whose value is printed.
5104213d62SHiroo HAYASHIShort notation and long notation are available. They can be mixed
5204213d62SHiroo HAYASHIin a FORMAT. Specifying a field with either notation, one or more
5304213d62SHiroo HAYASHIfields are activated internally.
5404213d62SHiroo HAYASHI
5504213d62SHiroo HAYASHIThe short notation is just a letter listed in the LETTER column of
5604213d62SHiroo HAYASHIthe ``--list-fields`` output.
5704213d62SHiroo HAYASHI
5804213d62SHiroo HAYASHIThe long notation is a name string surrounded by braces(`{` and
5904213d62SHiroo HAYASHI`}`). The name string is listed in the NAME column of the output of
6004213d62SHiroo HAYASHIthe same option. To specify a field owned by a parser, prepend
6104213d62SHiroo HAYASHIthe parser name to the name string with `.` as a separator.
6204213d62SHiroo HAYASHI
6304213d62SHiroo HAYASHIWild card (`*`) can be used where a parser name is specified. In this
6404213d62SHiroo HAYASHIcase both common and parser specific fields are activated and printed.
6504213d62SHiroo HAYASHIIf a common field and a parser specific field have the same name,
6604213d62SHiroo HAYASHIthe common field has higher priority.
6704213d62SHiroo HAYASHI
6804213d62SHiroo HAYASHI`WIDTH-AND-ADJUSTMENT` is a positive number.
6904213d62SHiroo HAYASHIThe value of the number is used as the width of
7004213d62SHiroo HAYASHIthe column where a field is printed. The printing is
7104213d62SHiroo HAYASHIright adjusted by default, and left
7204213d62SHiroo HAYASHIadjusted when `-` is given as prefix.
7304213d62SHiroo HAYASHIThe output is not truncated by default even if its field width is
7404213d62SHiroo HAYASHIspecified and smaller than width of output value. For truncating
7504213d62SHiroo HAYASHIthe output to the specified width, use `.` as prefix.
7604213d62SHiroo HAYASHI
7704213d62SHiroo HAYASHIAn example of specifying common fields:
7804213d62SHiroo HAYASHI
7904213d62SHiroo HAYASHI.. code-block:: console
8004213d62SHiroo HAYASHI
81*45e335abSHiroo HAYASHI    $  ctags -x --_xformat="%-20N %4n %-16{input}|" main/main.c | head
8204213d62SHiroo HAYASHI    CLOCKS_PER_SEC        360 main/main.c     |
8304213d62SHiroo HAYASHI    CLOCKS_PER_SEC        364 main/main.c     |
8404213d62SHiroo HAYASHI    CLOCK_AVAILABLE       358 main/main.c     |
8504213d62SHiroo HAYASHI    CLOCK_AVAILABLE       363 main/main.c     |
8604213d62SHiroo HAYASHI    Totals                 87 main/main.c     |
8704213d62SHiroo HAYASHI    __anonae81ef0f0108     87 main/main.c     |
8804213d62SHiroo HAYASHI    addTotals             100 main/main.c     |
8904213d62SHiroo HAYASHI    batchMakeTags         436 main/main.c     |
9004213d62SHiroo HAYASHI    bytes                  87 main/main.c     |
9104213d62SHiroo HAYASHI    clock                 365 main/main.c     |
9204213d62SHiroo HAYASHI
9304213d62SHiroo HAYASHIHere `%-20N %4n %-16{input}|` is a format string. Let's look at the
9404213d62SHiroo HAYASHIelements of the format.
9504213d62SHiroo HAYASHI
9604213d62SHiroo HAYASHI`%-20N`
9704213d62SHiroo HAYASHI
9804213d62SHiroo HAYASHI	The short notation is used here.
9904213d62SHiroo HAYASHI	The element means filling the slot with the name of the tag.
10004213d62SHiroo HAYASHI	The width of the column is 20 characters and left adjusted.
10104213d62SHiroo HAYASHI
10204213d62SHiroo HAYASHI`%4n`
10304213d62SHiroo HAYASHI
10404213d62SHiroo HAYASHI	The short notation is used here.
10504213d62SHiroo HAYASHI	The element means filling the slot with the line number of
10604213d62SHiroo HAYASHI	the tag. The width of the column is 4 characters and right
10704213d62SHiroo HAYASHI        adjusted.
10804213d62SHiroo HAYASHI
10904213d62SHiroo HAYASHI`%-16{input}`
11004213d62SHiroo HAYASHI
11104213d62SHiroo HAYASHI	The long notation is used here.
11204213d62SHiroo HAYASHI	The element means filling the slot with the input file name
11304213d62SHiroo HAYASHI	where the tag is defined. The width of column is 16
11404213d62SHiroo HAYASHI        characters and left adjusted.
11504213d62SHiroo HAYASHI
11604213d62SHiroo HAYASHI`|`
11704213d62SHiroo HAYASHI
11804213d62SHiroo HAYASHI	Printed as is.
11904213d62SHiroo HAYASHI
12004213d62SHiroo HAYASHIAnother example of specifying parser specific fields:
12104213d62SHiroo HAYASHI
12204213d62SHiroo HAYASHI.. code-block:: console
12304213d62SHiroo HAYASHI
124*45e335abSHiroo HAYASHI	$  ctags -x --_xformat="%-20N [%10{C.properties}]" main/main.c
12504213d62SHiroo HAYASHI	CLOCKS_PER_SEC       [          ]
12604213d62SHiroo HAYASHI	CLOCK_AVAILABLE      [          ]
12704213d62SHiroo HAYASHI	Totals               [          ]
12804213d62SHiroo HAYASHI	__anonae81ef0f0108   [          ]
12904213d62SHiroo HAYASHI	addTotals            [    extern]
13004213d62SHiroo HAYASHI	batchMakeTags        [    static]
13104213d62SHiroo HAYASHI	bytes                [          ]
13204213d62SHiroo HAYASHI	clock                [          ]
13304213d62SHiroo HAYASHI	clock                [    static]
13404213d62SHiroo HAYASHI	...
13504213d62SHiroo HAYASHI
13604213d62SHiroo HAYASHIHere `"%-20N [%10{C.properties}]"` is a format string. Let's look at
13704213d62SHiroo HAYASHIthe elements of the format.
13804213d62SHiroo HAYASHI
13904213d62SHiroo HAYASHI`%-20N`
14004213d62SHiroo HAYASHI
14104213d62SHiroo HAYASHI	Already explained in the first example.
14204213d62SHiroo HAYASHI
14304213d62SHiroo HAYASHI`[` and `]`
14404213d62SHiroo HAYASHI
14504213d62SHiroo HAYASHI	Printed as is.
14604213d62SHiroo HAYASHI
14704213d62SHiroo HAYASHI`%10{C.properties}`
14804213d62SHiroo HAYASHI
14904213d62SHiroo HAYASHI	The long notation is used here.
15004213d62SHiroo HAYASHI	The element means filling the slot with the value
15104213d62SHiroo HAYASHI	of the properties field of the C parser.
15204213d62SHiroo HAYASHI	The width of the column is 10 characters and right adjusted.
15304213d62SHiroo HAYASHI
15404213d62SHiroo HAYASHI
15504213d62SHiroo HAYASHI.. TODO: An example of using WILDCARD
156