Emacs 的标签:etags、ebrowse、cscope、GNU Global 和 exuberant ctags 之间的关系 [英] Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctags

查看:18
本文介绍了Emacs 的标签:etags、ebrowse、cscope、GNU Global 和 exuberant ctags 之间的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从事 C++ 项目,并阅读了 Alex Ott 的 CEDET 指南 和其他关于 StackOverflow 中标签的线程,但我仍然对 Emacs 如何与这些不同的标签系统交互以促进自动完成、定义的查找、源代码库的导航或文档字符串的预览感到困惑.>

I work on C++ projects, and I went through Alex Ott's guide to CEDET and other threads about tags in StackOverflow, but I am still confused about how Emacs interfaces with these different tag systems to facilitate autocompletion, the looking up of definitions, navigation of source code base or the previewing of doc-strings.

  1. etagsebrowse丰富的 ctags, cscope代码>、GNU GlobalGTags?我需要做什么才能在 Emacs 中使用它们?

  1. What is the difference (e.g. in terms of features) between etags, ebrowse, exuberant ctags, cscope, GNU Global and GTags? What do I need to do to use them in Emacs?

如果我想使用标签来导航/自动完成符号,我需要语义/参议员 (CEDET) 吗?

Do I need semantic/senator (CEDET) if I want to use tags to navigate/autocomplete symbols?

语义为这些不同的标签实用程序带来了什么?它如何与这些工具交互?

What does semantic bring to the table on top of these different tag utilities? How does it interface with these tools?

推荐答案

这是一个很好的问题,因为我最近在这里读到过,所以我会尝试更详细地解释差异:

That's as a good question as I've recently read here, so I'll try explain the difference in more detail:

第 1 点:

etagsctags 都生成在源文件中找到的语言对象的索引(又名 tag/TAGS)文件,允许通过文本编辑器或其他实用程序.标签表示索引条目可用的语言对象(或者,为该对象创建的索引条目).ctags 生成的标签在元数据方面更丰富,但 Emacs 无论如何都无法解释额外的数据,所以你应该认为它们或多或少是相同的(ctags 的主要优点是它支持更多语言).标签文件的主要用途是查找类/方法/函数/常量/等声明/定义.

etags and ctags both generate an index (a.k.a. tag/TAGS) file of language objects found in source files that allows these items to be quickly and easily located by a text editor or other utility. A tag signifies a language object for which an index entry is available (or, alternatively, the index entry created for that object). The tags generated by ctags are richer in terms of metadata, but Emacs cannot interpret the additional data anyways, so you should consider them more or less the same (the main advantage of ctags would be its support for more languages). The primary use for the tags files is looking up class/method/function/constant/etc declaration/definitions.

cscope 是更强大的野兽(至少就 C/C++ 和 Java 而言).虽然它或多或少地以相同的原理运行(生成一个有用的元数据文件),但它允许您做一些更有趣的事情,例如查找对符号的所有引用,查看调用函数的位置等(您也可以找到定义).

cscope is much more powerful beast (at least as far as C/C++ and Java are concerned). While it operates on more or less the same principle (generating a file of useful metadata) it allows you do some fancier things like find all references to a symbol, see where a function is being invoked, etc (you can find definitions as well).

总结一下:

ctags 允许您导航到符号声明/定义(有些人称之为单向查找).ctags 是一种通用工具,可用于多种语言.

ctags one allows you to navigate to symbol declaration/definitions (what some would call a one-way lookup). ctags is a general purpose tool useful for many languages.

另一方面(如项目页面所述)cscope 允许您:

On the other hand (as mentioned on the project's page) cscope allows you to:

  • 转到符号的声明
  • 显示对符号的所有引用的可选列表
  • 搜索任何全局定义
  • 函数调用的函数
  • 函数调用函数
  • 搜索文本字符串
  • 搜索正则表达式模式
  • 查找文件
  • 查找包括文件在内的所有文件

在这一点上任何人都不会感到惊讶,当我处理 C/C++ 项目时,我大量使用 cscope 而很少关心 ctags.在处理其他语言时,情况显然会相反.

It should come as no surprise to anyone at this point, that when I deal with C/C++ projects I make heavy use of cscope and care very little about ctags. When dealing with other languages the situation would obviously be reversed.

第 2 点.

要实现智能自动完成,您需要一个真正的源代码解析器(如语义),否则您将不知道应用程序中的对象类型(例如)以及可以对它们调用的方法.您可以根据许多不同的来源进行自动完成,但为了获得最佳结果,您最终需要一个解析器.语法高亮也是如此——目前 Emacs 主要模式中的语法高亮只是基于正则表达式,非常脆弱且容易出错.希望在 Emacs 23.2 中包含语义(在此之前它曾经是一个外部包),我们将开始看到它的更多用途(例如使用它来分析缓冲区源代码以正确突出显示它)

To have intelligent autocompletion you need a true source code parser (like semantic), otherwise you won't know the types of the objects (for instance) in your applications and the methods that can be invoked on them. You can have an autocompletion based on many different sources, but to get the best results you'll ultimately need a parser. Same goes for syntax highlighting - currently syntax highlighting in Emacs major modes is based simply on regular expressions and that's very fragile and error prone. Hopefully with the inclusion of semantic in Emacs 23.2 (it used to be an external package before that) we'll start seeing more uses for it (like using it to analyse a buffer source code to properly highlight it)

由于 Emacs 24.1 语义可从 Emacs 完成框架中使用.测试它的最简单方法是打开一个 C 源代码文件并输入 M-TABC-M-i 并观察语义自动为您完成.对于默认情况下未启用语义的语言,您可以将以下行添加到您选择的主要模式挂钩中:

Since Emacs 24.1 semantic is usable from the Emacs completion framework. The easiest way to test it is to open up a C source code file and typing M-TAB or C-M-i and watch as semantic automagically completes for you. For languages where semantic is not enabled by default, you can add it the following line to your major mode hook of choice:

(add-to-list 'completion-at-point-functions 'semantic-completion-at-point-function)

第 3 点.

语义带来了真正的代码意识(对于它目前支持的少数语言)并缩小了 IDE 和 Emacs 之间的差距.它并没有真正与 etagscscope 等工具交互,但这并不意味着您不能将它们一起使用.

semantic brings true code awareness (for the few languages it currently supports) and closes the gap between IDEs and Emacs. It doesn't really interface with tools like etags and cscope, but it doesn't mean you cannot use them together.

希望我的解释有意义并且对您有用.

Hopefully my explanations make sense and will be useful to you.

附言我不太熟悉 globalebrowse,但如果没记错的话,他们使用了 etags.

P.S. I'm not quite familiar with global and ebrowse, but if memory serves me they made use of etags.

这篇关于Emacs 的标签:etags、ebrowse、cscope、GNU Global 和 exuberant ctags 之间的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆