Ctags: gtags 不尊重 .ctags 文件

创建于 2017-12-08  ·  25评论  ·  资料来源: universal-ctags/ctags

我已经用通用 ctags 构建了全局变量。 我可以验证在执行 ctags --version 时我得到了通用 ctags 版本而不是其他任何版本。

我创建了一个 .ctags 文件,其中包含:

-exclude=foo

执行 gtags 时,我没有看到它尊重 .ctags 文件。 相反,它只是继续为工作目录中的所有内容提取标签。

我究竟做错了什么?

所有25条评论

Universal-ctags 不读取 .ctags。 请参见 ctags.1 手册页的 FILES 部分。

你指的是这个吗?

/ctags.cnf (on MSDOS, MSWindows only)
/etc/ctags.conf
/usr/local/etc/ctags.conf
$HOME/.ctags
$HOME/ctags.cnf (on MSDOS, MSWindows only)
.ctags
ctags.cnf (on MSDOS, MSWindows only)

If any of these configuration files exist, each will be expected to contain a set of default options which are read in the order listed when ctags starts, but before the CTAGS environment variable is read or any command line options are read. This makes it possible to set up site-wide, personal or project-level defaults. It is possible to compile ctags to read an additional configuration file before any of those shown above, which will be indicated if the output produced by the --version option lists the "custom-conf" feature. Options appearing in the CTAGS environment variable or on the command line will override options specified in these files. Only options will be read from these files. Note that the option files are read in line-oriented mode in which spaces are significant (since shell quoting is not possible). Each line of the file is read as one command line parameter (as if it were quoted with single quotes). Therefore, use new lines to indicate separate command-line arguments.

我确实将 .ctags 视为一种可能性!

据推测,他指的是当前的手册页

感谢 codebrainz 的回应。 所以我创建了这个文件:
/pathtorepo/ctags.d/.ctags

其中包括我需要的 -R --excludes 。

从 repos 目录执行此命令时:

ctags --verbose

它告诉我它正在等待输入。

当我做

ctags --vertbose --options=ctags.d/.ctags

它做正确的事情并从所有 repo 中提取标签,除了 .ctags 文件中的 excludes 之外。

我究竟做错了什么?

当只执行“ctags”时,我需要 ctags 来尊重 ctags.d/.ctags(或它需要的任何文件)。

原因是我在 emacs 中使用了 ggtags,而 ggtags 需要 ggtags 与 ctags 一起工作。

所以基本上我想进入一种状态,当我可以在命令提示符下执行“gtags”并自动执行时:

  1. 使用通用 ctags
  2. 尊重通用 ctags (ctags.d/.ctags) 文件

我怎样才能做到这一点?

/pathtorepo/.ctags.d/exclude.ctags 怎么样?
查看 Universal-ctags 本身的源代码树。 您可以在其中找到 .ctags.d 目录。
https://github.com/universal-ctags/ctags/tree/master/.ctags.d

很抱歉反复更新我的评论。

在 /pathtorepo 运行 u-ctags 时,u-ctags 必须加载 /pathtorepo/.ctags.d/exclude.ctags。
如果 u-ctags 没有加载您的 exclude.ctags,请随时重新打开它。

masatake,感谢您的回复。 似乎正在提取排除文件,但我有几个问题:

  1. 这会解析未排除的文件:
    ctags --verbose --options=.ctags
    但这不会:
    ctags --verbose
    虽然它说它拾取了排除文件,但我收到了这条消息:

ctags:未指定文件。 试试“ctags --help”。

但为什么? 它不应该像这样:
ctags --verbose --options=.ctags
并只解析当前目录中的所有内容,除了排除?

  1. 如何让 gtags 使用通用 ctags 并获取它的排除文件?
    当我执行 gtags 时,它会解析所有内容并忽略 exclude.ctags 文件,尽管全局已构建 --with-universal-ctags

关于 1. 我需要有关环境的信息来回答问题。

我英语不好。 我希望下面的输出可以告诉你你需要的一切。

请检查您是否真的在使用 u-ctags。

$ ./ctags --version | grep Universal
Universal Ctags 0.0.0(248cffc9), Copyright (C) 2015 Universal Ctags Team
Universal Ctags is derived from Exuberant Ctags.

u-ctags 在 ./.ctags.d 下加载以.ctags作为后缀的文件。

$  ls -l .ctags.d
-rw-r--r--. 1 jet jet 104 Oct 14 02:46 exclusion.ctags

--verbose选项告诉您加载了哪些文件。

$ ./ctags --verbose 2>&1 | grep 'Considering option file'
Considering option file .ctags.d/exclusion.ctags: reading...

可以使用--options指定目录或文件。 如果给出目录,
加载目录下以.ctags为后缀的文件。
但是,同一个文件不会加载两次。

$ ./ctags --verbose --options=.ctags.d 2>&1 | grep 'Considering option file'
Considering option file .ctags.d/exclusion.ctags: reading...
Considering option file .ctags.d/exclusion.ctags: already considered

除非使用 --options 明确指定文件,否则不会加载没有后缀的文件。

$ touch ./.ctags.d/please-load-me
$ ./ctags --verbose  2>&1 | grep 'Considering option file'
Considering option file .ctags.d/exclusion.ctags: reading...
$ mv ./.ctags.d/please-load-me ./.ctags.d/please-load-me.ctags
$ ./ctags --verbose  2>&1 | grep 'Considering option file'
Considering option file .ctags.d/exclusion.ctags: reading...
Considering option file .ctags.d/please-load-me.ctags: reading...

就这样。 请参阅手册页。 如果手册页写得不好,请考虑提出拉取请求并向我展示我们如何改进它。

关于2,对不起,我不太了解gtags。

我想我们会反复收到这样的问题。 在收到问题之前我可以做什么?

如果您仍然加载 $HOME/.ctags,您将不会收到此问题。 兼容性很好,我不明白你为什么停止加载那个文件。 提交 ce0617a7be7a4d33a09ac60f21b8a9ce26690853 改变了这一点,但没有说明原因。

现在我必须移动我的文件并更新我关于配置文件的记录。

提交是#1519 的一部分,所以在那里描述了原因。

破坏兼容性是一个坏主意。 但是,我会做一次,只有在发布u-ctags的初始版本时才做一次(我希望)。 我认为最后一个是标签文件格式。 最重要的事情由@b4n 完成。 我要做的是assigning version 3 tags file format并为其制作文档。

我有与原始海报相同的问题,同时使用~/.ctags.d/*.ctags和(本地) ./.ctags.d/*.ctags
我正在使用 GNU Global 6.6.3,编译有通用 Ctags 支持。 GTAGSCONF指向默认的gtags.conf安装路径, GTAGSLABELnew-ctags

我还查看了 Global 的/plugin-factory/exuberant-ctags.c (用于调用 Universal Ctags;从第 193 行开始)中的源代码,但似乎调用 Universal Ctags 时没有选项会禁用.ctags.d/*.ctags的加载.

如果我更愿意向全球开发人员报告此事,请告诉我,我会这样做。 :)

重现:

git clone -b tests --single-branch https://github.com/janEbert/julia-ctags.git
cd julia-ctags
mkdir -p ~/.ctags.d
mkdir -p .ctags.d
ln -s $PWD/ctags ~/.ctags.d/julia.ctags  # or cp if you want to be safe
ln -s $PWD/ctags ./.ctags.d/julia.ctags
gtags
global greet  # returns nothing

直接调用 ctags 怎么样:

$ new-ctags --version
$ new-ctags -o - JULIA-FILE

你得到预期的结果吗?

是的,无论是否通过--options指定的 .ctags 文件,调用 Universal Ctags(在我的机器上uctagsGTAGSLABEL不是二进制文件的名称)都可以完美地工作。
所以通用 Ctags 使用 ~/.ctags.d 文件,但不知何故这种行为不会转移到全局。

请不要使用--options。 uctags 应该加载 ~/.ctags.d/julia.ctags 和 ./.ctags.d/julia.ctags 而不指定 --options。

所以我希望你运行的是:

$ uctags --version
$ uctags -o - JULIA-FILE

我想看看命令输出。

顺便说一句,你在 GNU/Linux 上使用 ctags 吗?

抱歉,我没说清楚。 uctags根据需要使用~/.ctags.d的内容,即使我没有给出--options标志。 但是,如果我使用gtagsuctags作为后端,则不使用~/.ctags.d

是的,我在 GNU/Linux,特别是 Ubuntu 上使用它。 输出如下:

$ uctags --version
Universal Ctags 0.0.0(1a94658c), Copyright (C) 2015 Universal Ctags Team
Universal Ctags is derived from Exuberant Ctags.
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
  Compiled: Jul 29 2019, 13:42:51
  URL: https://ctags.io/
  Optional compiled features: +wildcards, +regex, +iconv, +option-directory, +xpath, +packcc
$ uctags -o - testfile.jl
CtagsTest   testfile.jl /^module CtagsTest$/;"  f
ImmutablePoint  testfile.jl /^struct ImmutablePoint{T}$/;"  f
MutablePoint    testfile.jl /^mutable struct MutablePoint{T}$/;"    f
addcoment   testfile.jl /^addcoment(string::AbstractString, comment, spaces=1) = begin  # Maybe write without `begin`?$/;"  f
addone! testfile.jl /^function addone!(x::T) where {T <: Number}$/;"    f
deprecated_returnsquarepower    testfile.jl /^deprecated_returnsquarepower() = 2.0$/;"  f
multiply    testfile.jl /^multiply(x, y) = x * y$/;"    f
multiply    testfile.jl /^multiply(x, y...) = begin$/;" f
printgreeting   testfile.jl /^    function printgreeting(x)$/;" f
square  testfile.jl /^function square(x)$/;"    f

编辑:编译了更新版本的 Universal Ctags,输出保持不变。

输出没有显示我在示例中用于进一步重现greet函数。 这是由于我链接到的分支中有一个过时的解析器——只需将global greet替换global square ,它仍然不会给出任何输出。

好的 作为一个独立的程序,uctags 工作得很好。

您正在使用 GNU/Linux。 好的! 我可以帮助你更多。

请安装strace包。 我不太了解 Ubuntu,但是 apt-get 可能是安装 strace 的命令。

然后运行

$ strace -s 4096 -f -e execve,execveat gtags

我想看看输出。

好的 作为一个独立的程序,uctags 工作得很好。

是的,它独立运行非常好!

您正在使用 GNU/Linux。 好的! 我可以帮助你更多。

抱歉,我之前没有提到这一点。

$ strace -s 4096 -f -e execve,execveat gtags
execve("/usr/local/bin/gtags", ["gtags"], 0x7ffe7e8d0fe8 /* 83 vars */) = 0
strace: Process 2210 attached
[pid  2210] execve("/usr/bin/sort", ["/usr/bin/sort", "-k", "1,1"], 0x562714c855b0 /* 84 vars */) = 0
strace: Process 2211 attached
[pid  2211] execve("/usr/bin/sort", ["/usr/bin/sort", "-k", "1,1"], 0x562714c97410 /* 84 vars */) = 0
[pid  2210] +++ exited with 0 +++
[pid  2209] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=2210, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
[pid  2211] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=2211, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
+++ exited with 0 +++

strace 的输出告诉 gtags 没有调用 uctags。

非常感谢。很抱歉给您带来麻烦。
然后写信给GLOBAL的开发者!
再次感谢! 通用 Ctags 很棒。 :)

嘿,我试了一下。 我不知道该写信给你还是 Shigio。

GNU Global 使用 GTAGSCONF 文件中的langmap设置来过滤gtags处理的文件,并将这些设置传递给 Universal Ctags。

有一次,我将 Julia (.jl) 的文件扩展名添加到全局配置中,但是,Universal Ctags 因警告而停止:
未知语言“[语言映射列表]”

出现问题是因为 Universal Ctags 首先解析其参数,然后在.ctags.d加载选项。 我修改了 Global 以明确传递--options=[...].ctags _before_ 它传递了--langmap选项。
之后,一切再次完美运行,我得到了全局表。

正如我所说,我不确定这是否是您想要更改的内容(以便在通用 Ctags 的参数之前处理.ctags.d文件),或者我是否应该向 Global 提交报告。

出现问题是因为 Universal Ctags 首先解析其参数,然后加载 .ctags.d 中的选项。

我没有这么执行。
只有少数例外,Universal-ctags 加载 .ctags.d/*.ctags 然后解析 cmdline 选项。
正如我在 ctags-optlib.7 手册页中所写,您可以使用 --_echo=MSG 选项来了解和调试 u-ctags 如何加载配置文件。

 [yamato@slave]~% ls ~/.ctags.d 
config.ctags
[yamato@slave]~% cat ~/.ctags.d/config.ctags
--_echo=hello from dot-ctags


[yamato@slave]~% u-ctags --_echo="hello from cmdline" --_force-quit
u-ctags: Notice: hello from dot-ctags
u-ctags: Notice: hello from cmdline

请参见 ctags.1 手册页。 我不明白您为什么要将 --options 传递给 ctags。
将 julia.ctags 放在 ~/.ctags.d 可能足以满足您的目的。 u-ctags 自动加载 julia.ctags。 所以你不必明确指定 --options 。

好的,我刚刚再次测试,我也不再出现错误。 再次抱歉给您添麻烦了。

此页面是否有帮助?
0 / 5 - 0 等级