Emacs + etags + cscope 阅读代码

用Emacs+etags+cscope可以让你的Emacs拥有比Source Insight强大的代码阅读功能。

etags: 这个是Emacs内置的功能,etags主要的功能是寻找一个变量或者函数的定义。用法如下:

1,生成TAGS索引文件:

      etags `find . -name "*.[chS]"`

或  etags `find . -name "*.h" -o "*.cpp"

2,打开Emacs,读入TAGS

      M-x visit-tags-table

3,

      M-. :跳至相应的函数定义处;
      M-* :返回刚才的函数名处;
      C-u M-. :查找下一个tags

 

cscope:

首先到 Cscope 的主页 上去下载最新的源代码包,编译安装。要在 Emacs 里面 使用,首先必须把 xcscope.el 拷贝到 load-path 里面包含的目录里面。并在 ~/.emacs 里面加上 (require 'xcscope) 就可以了,或者,如果你希望在打开 c 或者 c++ 文件的时候才加载 xcsope ,可以写:

(add-hook 'c-mode-common-hook
	  '(lambda ()
	    (require 'xcscope)))

如果源代码全部处于同一个目录下面,现在就可以使用了。否则,如果源代码有 多层目录,或者其他地方还有附加的源代码,则需要 cscope-indexer 脚本。把 那个脚本拷贝到系统 PATH 里面去(如/usr/bin/)。如果所有的源代码以及子目 录都是在同一个目录下面的,只要执行 C-c s I(cscope-index-files) 就可以 生成 Cscope 的数据库,接下来就可以使用了。

默认是的快捷键都是绑定到 C-c s 的前缀上面,如果嫌麻烦的话可以自己更改 快捷键绑定。这是默认的用于查找的键绑定:

C-c s s         Find symbol.
C-c s d         Find global definition.
C-c s g         Find global definition (alternate binding).
C-c s G         Find global definition without prompting.
C-c s c         Find functions calling a function.
C-c s C         Find called functions (list functions called
                from a function).
C-c s t         Find text string.
C-c s e         Find egrep pattern.
C-c s f         Find a file.
C-c s i         Find files #including a file.

下面是在搜索到的结果之间切换用的快捷键:

C-c s b         Display *cscope* buffer.
C-c s B         Auto display *cscope* buffer toggle.
C-c s n         Next symbol.
C-c s N         Next file.
C-c s p         Previous symbol.
C-c s P         Previous file.
C-c s o 跳转到定义处 C-c s u Pop mark.
posted @ 2013-09-30 13:58  CobbLiu  阅读(2644)  评论(0)    收藏  举报