这就说明,Emacs+gtags的组合,就可以是能够创建工程项目的编辑软件了。
(基本等于sourceinsight,如果在加上cedet和ecb就更完美了)
GNU GLOBAL is a source code tagging system that works the same way across diverse environments (emacs, vi, less, bash, web browser, etc). You can locate objects in source files and move there easily. It is useful for hacking a large project containing many subdirectories, many
#ifdef
and many
main()
functions. It is similar to ctags or etags but is different from them at the point of independence of any editor. It runs on a UNIX(POSIX) compatible operating system like GNU and BSD.
GNU GLOBAL is part of the GNU project , and is free software . You can freely copy, modify and redistribute this program under GNU GPL .
support C, C++, Yacc, Java and PHP4.
下载地址:
http://www.gnu.org/software/global/
How to install.
$ ./configure $ make
$ sudo make install (此处可能没有权限,所以使用sudo切换到root权限)
与gtags相似的组件:cscope;
支持的基本环境:
* Shell command line
* Bash shell
* Vi editor (Nvi, Elvis, vim)
* Less viewer
* Emacs editor (Emacs, Mule, Xemacs)
* Web browser
* Doxygen documentation system
基本用法:
①下载安装gtags后,在源文件的目录中,键入"gtags -v"命令,就会生成相应文件。
例:source code(/usr/src/sys) 123MB[xx@localhost sys]$ gtags -v
GPATH 1MB `GPATH' path name database GTAGS 26MB `GTAGS' definition database GRTAGS 22MB `GRTAGS' reference database GSYMS 23MB `GSYMS' symbol database ------------------------------------- total of tag files 72MB
gtags的其他options的含义,请参考man手册。
(辅助: http://blog.chinaunix.net/u3/98822/showart_2129660.html )
②下载安装gtags后,会有名为gtags.el的文件,注意看安装时make install的list,即可找到gtags.el的安装位置(默认目录是:/usr/local/share/gtags/)。
将gtags.el的路径设置为Emacs的<load-path>。
例:在`$HOME/.emacs'文件中加入下记代码例。
从此启动Emacs后,及在<load-path>中load了gtags.el文件,并将gtags-mode设置为真(等同于每次启动后,都在Emacs中的M-x,手动键入gtags-mode)。(setq load-path (cons "/home/owner/global" load-path));gtags.el load-path (autoload 'gtags-mode "gtags" "" t);gtags-mode is true
个人.emacs文件中的内容:
;##global(GNU GLOBAL source code tag system);;;;;;;;;;;;;;;;;;;;; ;to use global from Emacs, you need to load the `gtags.el' and execute gtags-mode function in it. ;you need to add it to load-path. for `gtags.el'file. ;(add-to-list 'load-path "<path to gtags.el>");已经在之前的代码中load完了 (autoload 'gtags-mode "gtags" "" t);;start Emacs and execute gtags-mode function. (setq c-mode-hook '(lambda () (gtags-mode 1)));get into gtags-mode whenever you get into c-mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
③当源程序的源文件的内容变化了(导致行号变化),或追加删除了源文件等等。只要有改变,就要更新gtags生成的那4个文件。
例:source code(/usr/src/sys)
[xx@localhost sys]$ gtags -vi or [xx@localhost sys]$ global -u (推荐)
详细用法:
直接参考gtags的英文的Tutorial(指导)。
有很多章节可以跳过,因为那是global在别的编辑软件中的应用方法的说明。(例如shell,vi等)
章节还是要必看的。
看了gtags的英文的Tutorial(指导)后,发现htags也蛮有用的。
gtags完成的基本动作(具备键盘的快捷键):$ htags -Ff -sanohIvt 'Welcome to XXX source tour!' --table-flist=1 $
* 鼠标滚轮键(下按):根据上下文,找到"函数或常量或变量"的"定义或调用"的位置。
或,按【enter】。
* 鼠标右键:返回。(就是按完滚轮键后,想返回到原来刚才的位置的话,就按右键)
鼠标右键(返回),我想应该是emacs的功能,而不是Global的功能。
如果键盘操作的话,应该是:
①调用处搜索关键字→ 结果列表→ [Enter]键选择→ 被选部分的代码表示
②被选部分处,再次搜索相同关键字→ 结果列表→ [Enter]键选择→ 原调用处的代码再表示
* 光标+Enter:当按滚轮键后,出现的调用位置的结果为多个时,将光标调整到相应行,按下回车即可跳转到对应位置。
(如图,名为_exit_ts的函数在整个项目中,有多个位置调用他)