Ctags和gtags有何区别?如何取舍?

接手的工程都不大,所以之前看了一下ctags/etags怎么用,几个项目生成了几个TAGS就没怎么用。或者说最需要的跳转到变量定义这个功能,之前一直在写js,js2-mode自带即时parse跳到定义,最近又要写php了,虽然发现新版spacemacs的spacemacs/jump-to-definition不需要配置就很强大了,但还是想搞一下tags,就根据论坛里这个帖子去下了人家编译的win32的gnu-global(global官网有链接),生成tags,加上gtags layer,就可以用了。

我所知的ctags/etags和gtags的区别是:前者需要自己写parse需要的正则(虽然可以抄),后者原版也是一样,只支持C/C++/php等几个语言的很老的标准,但是有python的一个叫做pygments的parser做插件(我下的win32 build自带pygments-parser.dll),支持所有常见的不常见的语言,commimts记录看来也一直在活跃开发中,自己只要配一下ignore就好了。

###Most Common Tags Programe

  • Etags Etags is a command to generate ‘TAGS’ file which is the tag file for Emacs. You can use the file with etags.el which is part of emacs package.

  • Ctags Ctags is a command to generate ‘tags’ file which is the tag file for vi. Now Exuberant Ctags can generate ‘TAGS’ file by the -e option, and support 41 programming languages.

  • Cscope Cscope is an all-in-one source code browsing tool for C language. It has own fine CUI (character user interface) and tag databases (cscope.in.out, cscope.out, cscope.po.out). You can use cscope from Emacs using xcscope.el which is part of cscope package.

  • GNU GLOBAL GNU GLOBAL is a source code tagging system. Though it is similar to above tools, it differs from them at the point of that it is independent from any editor, and it has no user interface except for command line. Gtags is a command to generate tag files for GLOBAL (GTAGS, GRTAGS, GPATH). You can use GLOBAL from emacs using gtags.el which is part of GLOBAL package. In addition to this, there are many elisp libraries for it (xgtags.el, ggtags.el, anything-gtags.el, helm-gtags.el, etc).

  • Ebrowse Ebrowse is a C program shipped with Emacs. It indexes C/C++ code and generates a BROWSE file. ebrowse.el provides the usual find definition and completion. You can also open the BROWSE file directly in Emacs to get an overview of the classes/function defined a codebase.

###Comparison

  1. Ctags and etags treat only definitions. Cscope and GNU GLOBAL treat not only definitions but also references.
  2. Ctags and etags use a flat text tag file. Cscope and GNU GLOBAL use key-value tag databases.
  3. Cscope and GNU GLOBAL have a grep like search engine and incremental updating facility of tag files.

###Reference

8 个赞