Using tags with Perl

Dmitri Tikhonov

DCBPW 2015

Outline

Short Demo

Tools to create tag files

Exuberant Ctags

Supports Many Languages

Ant Asm Asp Awk Basic BETA C C++ C# Cobol DosBatch Eiffel Erlang Flex Fortran Go HTML Java JavaScript Lisp Lua Make MatLab ObjectiveC OCaml Pascal Perl PHP Python REXX Ruby Scheme Sh SLang SML SQL Tcl Tex Vera Verilog VHDL Vim YACC

ctags command line

Which files to index

# Index one file:
ctags my-file.pm

# Index recursively:
ctags -R dir dir dir

# Index everything in @INC:
ctags -R `perl -e 'print "@INC"'`

# A bunch of files:
ctags -L list-of-files.txt

Specifying output

Kinds of Perl tags

Ask ctags --list-kinds=Perl

Very small example

package My::Package;
use constant ABC => 123;
sub do_this;
do_this @ARGV;
sub do_this {
    AGAIN: write; shift;
    goto AGAIN if @_;
}
format =
@#####
$_[0]
.

What is inside a tag file?

Basic Vim commands

Jump to tag:

Jump back:

See where you've been:

Fully qualified tags: why

Use case 1

# For calls like this:
File::Temp::unlink0($fh, $local);

Use case 2

vi -t Edit::This::function

Fully qualified tags: how

extra option to ctags

ctags --extra=+q

I like them: ~/.ctags

--extra=+q

Setting up Vim

:au FileType perl setlocal iskeyword+=:

Tags for non-Perl source

Seen in Perl code:

Using multiple tag files

LC_ALL=C sort tags1 tags2 > tags

or

perl -e 'print sort <>' tags1 tags2 > tags

Write your own tag-producing code

Contribute to development