将 ctags 和 vim 与新文件扩展名映射结合使用

发布于 2024-10-03 00:49:30 字数 793 浏览 0 评论 0原文

Drupal 模块是带有 .module 文件扩展名的 php 文件。为了在这些文件上生成标签,我使用以下 langmap 设置运行 ctags:

ctags -R --langmap=php:+.module .

此命令生成 tags 文件,其中包含属于 .module 文件的多个标签。但是,当我使用 TlistToggle 打开标签列表窗口时,没有显示任何标签。但是,当打开带有 .php 扩展名的 php 文件时,标签列表窗口会在导航树中显示所有标签。

我是否需要以某种方式向 Vim 的 taglist 插件指定 .module 文件扩展名属于 php 语言?

更新: 我运行taglist's faq中描述的以下诊断命令:

ctags  -f - --format=2 --excmd=pattern --fields=nks test_module.module

回复什么也没有。但是当我使用 php 文件运行此命令时,它会显示标签列表:

ctags  -f - --format=2 --excmd=pattern --fields=nks test_module.php

Drupal modules are php files with .module file extensions. To generate tags on these files I run ctags with the following langmap settings:

ctags -R --langmap=php:+.module .

This command produces tags file with several tags belonging to .module file. But when I open the taglist window with TlistToggle none of the tags are shown. However, when opening a php file with .php extension, taglist window displays all the tags in a navigation tree.

Do I need to specify somehow to Vim's taglist plugin that .module file extension belongs to php language?

Update:
I run the following diagnose command described in taglist's faq:

ctags  -f - --format=2 --excmd=pattern --fields=nks test_module.module

The reply is nothing. But when I run this command with a php file it displays a list of tags:

ctags  -f - --format=2 --excmd=pattern --fields=nks test_module.php

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北方的韩爷 2024-10-10 00:49:30

Vim 和 Emacs 都会读取文件中的“编辑器提示”:通常嵌入注释中的文本,其中包含编辑器在打开文件时要遵循的命令或设置。您可以使用它来告诉编辑器如何处理该文件,无论文件名如何。

有关适用于 Emacs 和 Vim 的提示,请在文件末尾放置一个注释块:(

# Local variables:
# coding: utf-8
# mode: php
# End:
# vim: fileencoding=utf-8 filetype=php :

您的问题并不需要指定字符编码,但这显示了如何在一个注释块中组合多个设置。 )

Both Vim and Emacs will read “editor hints” in the file: text, usually embedded in a comment, that contains commands or settings for the editor to obey when opening the file. You can use that to tell the editor what to do with the file, regardless of the filename.

For hints that will work with both Emacs and Vim, place a comment block at the end of the file:

# Local variables:
# coding: utf-8
# mode: php
# End:
# vim: fileencoding=utf-8 filetype=php :

(Your question doesn't entail the need to specify character encoding, but this shows how you can combine multiple settings in one comment block.)

旧梦荧光笔 2024-10-10 00:49:30

您可以看到带有 ctags --verbose 的默认语言映射

Drupal 扩展可能默认不包含在内。对于 PHP,您可能会看到类似这样的内容: PHP: .php .php3 .phtml

有时长文件可能会产生错误,因此我通常会排除那些往往会缩小输出的扩展。 Drupal 也经常使用“.inc”。这个命令应该有效:

ctags -R --langmap=PHP:+.inc.module --exclude='*.js' --exclude='*.html' --exclude='*.css' *

在 ~/.vimrc 中确保添加: :set Tags=/path/to/your/tags

然后你应该能够使用 Ctrl+ ] 跳转到类/函数定义。

You can see the default language-mappings with ctags --verbose

Drupal extensions probably aren't included by default. You might see something like this for PHP: PHP: .php .php3 .phtml

Sometimes long files can create errors, so I typically exclude extensions that tend to have minified output. Drupal uses ".inc" often as well. This command should work:

ctags -R --langmap=PHP:+.inc.module --exclude='*.js' --exclude='*.html' --exclude='*.css' *

In ~/.vimrc make sure to add: :set tags=/path/to/your/tags

Then you should be able to use Ctrl+] to jump to class/function definitions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文