Ctags: Difference between revisions

From wikinotes
 
(3 intermediate revisions by the same user not shown)
Line 12: Line 12:
|}
|}
</blockquote><!-- Documentation -->
</blockquote><!-- Documentation -->
= Locations =
<blockquote>
{| class="wikitable"
|-
| <code>~/.config/ctags/*.ctags</code> || custom language definitions
|-
|}
</blockquote><!-- Locations -->


= History =
= History =
Line 48: Line 57:
<blockquote>
<blockquote>
<source lang="bash">
<source lang="bash">
ctags -R . # generate tags
ctags --list-languages  # list builtin languages
ctags -R .             # generate tags
</source>
</source>
</blockquote><!-- usage -->
</blockquote><!-- usage -->
= Configuration =
<blockquote>
== Adding Custom Languages ==
<blockquote>
{{ expand
| Define language
|
<syntaxhighlight lang="ctags">
# ~/.config/ctags/graphql.ctags
# src: https://gist.github.com/hoop33/b0a33cf8fdcf4d64689f58efed75c15e
--langdef=graphql
--langmap=graphql:.graphql
--regex-graphql=/^[ \t]*enum[ \t]+([_A-Za-z][_0-9A-Za-z]*)/\1/e,enum/
--regex-graphql=/^[ \t]*query[ \t]+([_A-Za-z][_0-9A-Za-z]*)/\1/q,query/
--regex-graphql=/^[ \t]*fragment[ \t]+([_A-Za-z][_0-9A-Za-z]*)/\1/f,fragment/
--regex-graphql=/^[ \t]*type[ \t]+([_A-Za-z][_0-9A-Za-z]*)/\1/t,type/
--regex-graphql=/^[ \t]*input[ \t]+([_A-Za-z][_0-9A-Za-z]*)/\1/i,input/
--regex-graphql=/^[ \t]*mutation[ \t]+([_A-Za-z][_0-9A-Za-z]*)/\1/m,mutation/
--regex-graphql=/^[ \t]*interface[ \t]+([_A-Za-z][_0-9A-Za-z]*)/\1/i,interface/
</syntaxhighlight>
}}
{{ expand
| Confirm language present
|
<syntaxhighlight lang="bash">
ctags --list-languages | grep -i 'YOUR_LANG'
</syntaxhighlight>
}}
</blockquote><!-- Adding Custom Languages -->
</blockquote><!-- Configuration -->

Latest revision as of 02:26, 25 October 2021

ctags recurses through your source tree, and records classes, methods etc.
Currently, the most active derivative of ctags is universal-ctags .

Documentation

universal-ctags home https://ctags.io/
universal-ctags github https://github.com/universal-ctags/ctags

Locations

~/.config/ctags/*.ctags custom language definitions

History

                   ctags (bsd 3.0  - ships w/ base-system in FreeBSD)
                         |
                         |
                         |
           +-------------+----------+
           |                        |
           |                        |
  exuberant-ctags (e-ctags)      gnu-ctags
           |
           |
  universal-ctags (u-ctags)

Install

# Archlinux
pacman -S ctags  # (upstream: universal-ctags -- see https://archlinux.org/packages/extra/x86_64/ctags/ )

# nixos
nix-env -i universal-ctags

# FreeBSD
pkg install ctags            # (upstream: exuberant-ctags -- see https://svnweb.freebsd.org/ports/head/devel/ctags/pkg-descr?revision=426827&view=markup )
pkg install universal-ctags  # (upstream: universal-ctags )

Usage

ctags --list-languages  # list builtin languages
ctags -R .              # generate tags

Configuration

Adding Custom Languages

Define language


# ~/.config/ctags/graphql.ctags
# src: https://gist.github.com/hoop33/b0a33cf8fdcf4d64689f58efed75c15e
--langdef=graphql
--langmap=graphql:.graphql
--regex-graphql=/^[ \t]*enum[ \t]+([_A-Za-z][_0-9A-Za-z]*)/\1/e,enum/
--regex-graphql=/^[ \t]*query[ \t]+([_A-Za-z][_0-9A-Za-z]*)/\1/q,query/
--regex-graphql=/^[ \t]*fragment[ \t]+([_A-Za-z][_0-9A-Za-z]*)/\1/f,fragment/
--regex-graphql=/^[ \t]*type[ \t]+([_A-Za-z][_0-9A-Za-z]*)/\1/t,type/
--regex-graphql=/^[ \t]*input[ \t]+([_A-Za-z][_0-9A-Za-z]*)/\1/i,input/
--regex-graphql=/^[ \t]*mutation[ \t]+([_A-Za-z][_0-9A-Za-z]*)/\1/m,mutation/
--regex-graphql=/^[ \t]*interface[ \t]+([_A-Za-z][_0-9A-Za-z]*)/\1/i,interface/


Confirm language present


ctags --list-languages | grep -i 'YOUR_LANG'