emacs code navigate 浏览代码

在使用emacs 基本文本编辑熟悉后,就是将它作为程序开发工具了,如果面对的是大工程,看每个文件C-X C-F肯定不是现实的。下面介绍一下find-tag的使用

建TAGS文件

TAGS文件是将代码中函数、类、宏等符号建立的索引文件,cd到代码的根目录。

find . -name '*.[ch]' -o -name '*.cpp' | xargs etags #找到所有的.c .h .cpp文件并建立索引文件TAGS

在emacs中location the TAGS file,M-x visit-tags-table,至此emacs已经能够定位所有的符号了。

直接查找符号

M-X find-tag,输入符号名 或 光标在符号中 M-X find-tag 就可以跳转到符号定义

快捷键 M-.

快捷命令

  • M-.     当将光标移到某个函数上时,键入此命令可以跳到此函数的一个tag处,如函数定义。
  • C-u M-.  键入这个命令,将会查找函数的下一个tag
  • M-*     键入这个命令,返回上一次执行M-.的地方,非常有用的命令,查看函数定义后可以返回。

更全的命令

  • `M-.’ (‘find-tag’) – find a tag, that is, use the Tags file to look up a definition. If there are multiple tags in the project with the same name, use `C-u M-.’ to go to the next match.
  • ‘M-*’ (‘pop-tag-mark’) – jump back
  • ‘M-x tags-search’ – regexp-search through the source files indexed by a tags file (a bit like ‘grep’)
  • ‘M-x tags-query-replace’ – query-replace through the source files indexed by a tags file
  • `M-,’ (`tags-loop-continue’) – resume ‘tags-search’ or ‘tags-query-replace’ starting at point in a source file
  • ‘M-x tags-apropos’ – list all tags in a tags file that match a regexp
  • ‘M-x list-tags’ – list all tags defined in a source file
posted @ 2013-09-15 14:53  kelvinkuo  阅读(509)  评论(0编辑  收藏  举报