使用 vim、ctags 可视化对全局变量的依赖
我想突出显示我的(Maple 代码,但并不重要)代码中的变量,这些变量对于例程来说是全局的。
例如,我
global_var1:=1;
global_var2:=2;
...
some_proc:=proc()
local local_var1, global_var2;
local_var1:=1;
local_var2:=local_var1*global_var1+global_var2;
end proc;
想在此示例中突出显示 some_proc()
内部的 global_var1
。显然,命名并不像示例中那样微不足道。
我可以使用 ctags 来做到这一点吗?
I'd like to highlight variables in my (Maple-code, but doesn't matter much) code which are global for routines.
e.g. I have
global_var1:=1;
global_var2:=2;
...
some_proc:=proc()
local local_var1, global_var2;
local_var1:=1;
local_var2:=local_var1*global_var1+global_var2;
end proc;
I want to highlight global_var1
inside of some_proc()
in this example. Obviously the naming is not so trivial in general as in the example.
Can I use ctags to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于 ctag。对于某些语言,它无法提取局部变量(viml),对于其他语言,它不能检测所有局部变量(C++)。因此,您要做的第一件事就是看看 ctags 可以为您的语言(Maple)做什么。
另一个困难是将突出显示限制为一个特定函数,并在每次将换行符插入到编辑的文件中时保持同步。我不知道有什么简单的方法可以做到这一点——可能是使用一个从
local.*{global-name}
开始并在end proc
结束的 vim 语法区域来中和突出显示所有全局变量?一项更容易的任务是突出显示变量屏蔽,即在函数中将其声明为本地的位置突出显示
global_var2
。唉,这不是你要找的。It depends on ctags. With some languages it is unable to extract local variables (viml), with other languages, it doesn't detect all local variables (C++). Hence, the first thing you'll have to do is to see what ctags can do for your language (Maple).
The other difficulty is to restrict the highlighting to one specific function, and to stay synchronized every time newlines are inserted to the edited file. I know no easy way to do this -- may be with a vim syntax region that starts at
local.*{global-name}
and ends atend proc
to neutralize the highlighting of all global variables?One task that'll be much more easier would be to highlight variable masking, i.e. highlight
global_var2
at the point in the function where it is declared local. Alas, it's not what you're looking for.