VIM:VIM Taglist 元素和代码片段之间的双射?
C 代码中的我的标签列表:
宏
|| MIN_LEN
|| 最多迭代次数
||- typedef
|| 细胞
|| 源单元
||- 变量
|| 给定长度
标签列表元素(域):
A = {MIN_LEN, MAX_ITERATIONS, cell, source_cell, len_given}
代码片段(共域):
B = {"code_MIN_LEN", "code_MAX_ITERATIONS", ..., "code_len_given"}
目标:在集合 A 和 B 之间进行双射。
示例:我想通过删除A或B中的元素来从A和B中删除A中的任何元素,例如MIN_LEN。
问题:有没有办法保证双射A 和 B 之间的变化是否会导致 A 或 B 的变化导致另一组变化?
My Taglist in a C code:
macro
|| MIN_LEN
|| MAX_ITERATIONS
||- typedef
|| cell
|| source_cell
||- variable
|| len_given
Taglist elements (domain):
A = {MIN_LEN, MAX_ITERATIONS, cell, source_cell, len_given}
Code snippets (codomain):
B = {"code_MIN_LEN", "code_MAX_ITERATIONS", ..., "code_len_given"}
Goal: to have bijection between the sets A and B.
Example: I want to remove any element in A, such as the MIN_LEN, from A and B by removing either its element in A or B.
Question: Is there a way to quarantee a bijection between A and B so that a change either in A or in B results in a change in the other set?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我强烈怀疑你能做到这一点。 taglist 插件使用 ctags 收集代码中的符号并以横向拆分方式显示它们。 横向分割包含只读信息(如果您尝试在该窗口上工作,vim 会告诉您该缓冲区的可修改功能已关闭)。
您想要实现的目标意味着对您正在修改的源代码进行相当复杂的解析。 即使像自动重命名这样的简单任务(假设您修改标签列表缓冲区中的函数名称条目并且源中的所有实例都已更新)也需要相当复杂的解析,这超出了 ctags 功能或标签列表本身。 删除所有内容并使其与双射关系保持同步甚至更加复杂。 假设您有一个 printf 行,其中使用了要删除的宏。 那条线应该发生什么? 如果整行消失,或者只是宏消失(在这种情况下,该行可能在语法上不正确。taglist
是浏览代码的一个不错的插件,但它不适合自动重构(这正是您想要实现的目标)。
编辑:至于计算复杂度,最坏的情况是你必须在每次击键时搜索整个文档,寻找可以集成的新标签,所以从这个意义上说,你可以说它是 O(n)这当然是矫枉过正,也是最糟糕的实现方法,我不知道 vim 中语法突出显示的计算复杂性(通过适当的标记化,这对于提取标签也很有用),但我会。估计它非常低,并且解析的数据量非常有限(您不太可能有大型构造来解析以提取标记并理解其上下文),这不是 taglist 每次运行 ctags 的方式。 vim 调用,它不会在您键入时实时解析文档。 然而,这是由 Eclipse、XCode 和 KDevelop 等完成的,它们还提供自动或半自动重构工具,并最终可以将 vim 集成为编辑器。 如果您需要这些功能,那么您肯定使用了错误的工具。
I strongly doubt you can do that. The taglist plugin uses ctags to collect the symbols in your code and display them in a lateral split. The lateral split contains readonly information (if you try to work on that window, vim tells you that modifiable is off for that buffer).
What you want to achieve would imply quite complex parsing of the source code you are modifying. Even a simple task like automatic renaming (assuming you modify a function name entry in the taglist buffer and all the instances in your source are updated) requires pretty complex parsing, which is beyond the ctags features or taglist itself. Deleting and keeping everything in sync with a bijective relationship is even more complex. Suppose you have a printf line where you use a macro you want to remove. What should happen to that line? should the whole line disappear, or just the macro (in that case, the line will probably be syntactically incorrect.
taglist is a nice plugin for browsing your code, but it's unsuited for automatic refactoring (which is what you want to achieve).
Edit: as for the computational complexity, well, the worst case scenario is that you have to scout the whole document at every keystroke, looking for new occurrence of labels that could be integrated, so in this sense you could say it's O(n) at each keystroke. This is of course overkill and the worst method to implement it. I am not aware of the computational complexity of the syntax highlight in vim, (which would be useful to extract tags as well, via proper tokenization), but I would estimate it very low, and very limited in the amount of parsed data (you are unlikely to have large constructs to parse to extract the token and understand its context). In any case, this is not how taglist works. Taglist runs ctags at every vim invocation, it does not parse the document live while you type. This is however done by Eclipse, XCode and KDevelop for example, which also provide tools for automatic or semiautomatic refactoring, and can eventually integrate vim as an editor. If you need these features, you are definitely using the wrong tool.