有没有一个 vim 插件可以让 Moose 属性显示在 Tag_List 中?
我正在编辑使用 Moose 的包,我想知道是否有一个插件可以使 Moose 属性显示在标签列表中。
例如,在以下代码中,属性 options
不会显示在 Tag_List 中,但 print_out_site
会显示:
use Moose;
use MooseX::AttributeHelpers;
...
has 'options' => (
metaclass => 'Collection::Hash',
isa => 'HashRef[Str]',
is => 'ro',
provides => {
exists => 'exists',
get => 'get',
set => 'set',
},
);
...
sub print_out_site {
my $self = shift;
my $key = shift;
$self->fasta_out_fh->print(">", $key, "\n");
$self->fasta_out_fh->print($self->sites->{$key}, "\n");
}
I am editing packages that use Moose, and I was wondering if there were a plugin for making Moose attributes show up in the Tag List.
For example, in the following code, the attribute options
does not show up in Tag_List, but print_out_site
does:
use Moose;
use MooseX::AttributeHelpers;
...
has 'options' => (
metaclass => 'Collection::Hash',
isa => 'HashRef[Str]',
is => 'ro',
provides => {
exists => 'exists',
get => 'get',
set => 'set',
},
);
...
sub print_out_site {
my $self = shift;
my $key = shift;
$self->fasta_out_fh->print(">", $key, "\n");
$self->fasta_out_fh->print($self->sites->{$key}, "\n");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将这一行添加
到 ~/.ctags 中,它应该会显示出来。您可能需要调整正则表达式以避免其他文件中的虚假匹配或适应其他文件中属性声明的不同格式。
这扩展了 ctags,以便在解析 perl 文件时根据正则表达式检测另一种类型的标记。
然后,您需要通过将以下内容添加到 vimrc 文件来告诉 taglist 插件有关新标签类型的信息:
Add the line
to ~/.ctags and it should show up. You may need to tweak the regular expression to avoid spurious matches in other files or to accommodate different formatting for the attribute declarations in other files.
This extends ctags so that it detects another type of tag based on the regular expression when parsing perl files.
Then you need to tell the taglist plugin about the new tag type by adding this to your vimrc file:
杰夫,我尝试了你的代码,但它对我使用的语法不起作用。这可能是版本问题吗?我正在使用 exuberant ctags 版本 5.8。
我还对正则表达式进行了一些修改,因为引号是可选的,并且您可能希望在“has”关键字之前允许空格(但没有其他内容)。
这对我有用。
我创建了一个 $HOME/.ctags 文件(还没有,否则只需添加到它),其中包含以下行:
然后按照您的建议在 .vimrc 中添加了该行
现在它列出了 Moose 模块中的我的属性。
此外,我发现在标签列表中显示有关父类、角色和使用的模块的信息也很有用,所以这是我完整的 $HOME/.ctags 文件:
这就是我在 .vimrc 中的内容(您可以只需更改 tlist_par_settings 中的顺序即可更改标签列表中标签的顺序):
由于存在附加内容,我发现使用 Tlist_Show_One_File 选项很有用,该选项强制标签列表仅显示当前所选文件的标签。
要暂时隐藏某些标签,您可以随时将光标移动到标签名称并点击“zc”(和“zo”以重新打开)折叠。
Geoff, I tried your code but it didn't work for me with the syntax you use. Could this be a version problem? I'm using exuberant ctags version 5.8.
I also modified the regex a bit because the quotes are optional and you might want to allow spaces (but nothing else) preceeding the 'has' keyword.
Here is what worked for me.
I created a $HOME/.ctags file (didn't have one yet, otherwise just add to it) with the following line:
Then added the line in .vimrc as you suggested
Now it lists my attributes in Moose modules.
In addition, I find it useful to also have information about the parent class, roles and used modules show up in the taglist, so here is my complete $HOME/.ctags file:
and this is what I have in .vimrc (you can change the order of tags in the taglist simply by changing the order in the tlist_par_settings):
Because of the additional content I find it useful to use the Tlist_Show_One_File option, which forces the taglist to show only the tags of the currently selected file.
To temporarily hide some of the tags you can always move the cursor to the tag name and hit "zc" (and "zo" to reopen) the fold.