Ctags heap support

Moops enhances perl syntax with constructs such as:

class MyPkg::MyClass { # ... } 

and adds the ability to declare signatures for member functions by introducing new fun and method keywords:

 class MyPkg::MyClass { method run(ArrayRef $ar){ } } 

I use vim and tag files to navigate my code base, but these new keywords are unknown to ctags , so classes, functions and methods are not indexed. How can I improve the situation?

+7
vim perl ctags exuberant-ctags moops
source share
2 answers

I can add regular expressions for ctags extending the built-in perl language as follows:

 $ ctags \ --regex-Perl="/^[ \t]*method\s+([a-zA-Z0-9]+)/\1/s/" \ --regex-Perl="/^\s*class\s+([a-zA-Z0-9:]+)/\1/p/" \ -R . 

or I can put them in my ~/.ctags file (excluding quotes)

Assuming we have a small project:

 $ tree . ├── MyPkg │  ├── MyClass.pm │  └── MyOtherClass.pm └── myscript.pl 

From MyPkg/MyClass.pm :

 use Moops; class MyPkg::MyClass { method run( ArrayRef $args ){ } } 

and MyPkg/MyOtherClass.pm :

 use Moops; package MyPkg; class MyOtherClass { method run( ArrayRef $args ){ } } 

Check out the alternative syntax here. The package name is appended to the class name, resulting in MyPkg::MyOtherClass .

Finally, myscript.pl :

 #!/usr/bin/env perl use MyPkg::MyClass; use MyPkg::MyOtherClass; MyPkg::MyClass->new()->run(\@ARGV); MyPkg::MyOtherClass->new()->run(\@ARGV); 

Calling ctags with the optional regex definitions mentioned above, the resulting tag file looks like this:

 MyOtherClass MyPkg/MyOtherClass.pm /^class MyOtherClass {$/;" p MyPkg MyPkg/MyOtherClass.pm /^package MyPkg;$/;" p MyPkg::MyClass MyPkg/MyClass.pm /^class MyPkg::MyClass {$/;" p run MyPkg/MyClass.pm /^ method run( ArrayRef $args ){$/;" s run MyPkg/MyOtherClass.pm /^ method run( ArrayRef $args ){$/;" s 

This almost works:

  • moving the cursor over MyPkg::MyClass and pressing CTRL-] vim can find the class definition
  • moving the cursor over the first call to run() vim finds a definition for the function

But there are two problems here:

  • in the case of the first run() call, vim cannot unambiguously decide which function to call, since it has no context; you must decide for yourself (using :ts )
  • moving the cursor over MyPkg::MyOtherClass vim cannot find the tag at all

So in conclusion, my best practice for Moops , vim and ctags would be to always declare classes fully qualified.

+6
source share

Thanks!

I find this very useful for other sugar syntax libraries (e.g. Function :: Parameters), although the regex for method lookups is slightly improved:

--regex-Perl="/^[ \t]*method\s+([a-zA-Z0-9_]+)/\1/s/"

+1
source share

All Articles