ctags4emacs用emacs和ectags看源代码 - Tao of programmer - CSDNBlog
TAGS
Use tags to navigate source code. It's not hard to set up. This takes advantage of a popular tool called "Exuberant Ctags" (AKA ctags, or etags) that scans your source code and indexes the symbols into a TAGS file.
Note: emacs comes with a tool called "etags" that does almost the same thing as Exuberant Ctags. In cygwin, the "etags" binary is actually Exuberant Ctags. Confused yet? My advice is, ignore Emacs etags, and use Exuberant Ctags, whatever it happens to be called in your part of the universe.
To generate a TAGS file, do this in the root of your code tree (stick this in a script or Makefile):
#ETAGS=/cygdrive/c/emacs-21.3/bin/etags.exe
ETAGS=etags # Exuberant ctags
rm TAGS
find . -name '*.cpp' -o -name '*.h' -o -name '*.c' -print0 \
| xargs $(ETAGS) --extra=+q --fields=+fksaiS --c++-kinds=+px --append
此句在Open Suse 11下运行无正确结果。
我经过man, 得出结果是:
find . -name *.cpp -print -exec etags -a {} \; -o -name *.h -print -exec etags -a {};\
绝对有更好的办法,不过我不确定,呵呵
Then, when you're reading code and want to see the definition(s) of a symbol:
M-. goes to the symbol definition 到符号定义处
M-0 M-. goes to the next matching definition 找到下一个满足匹配的定义处
M-* return to your starting point 回到开始点
ctags一个比较恼人的地方在于,它只索引符号的声明和定义,而不索引其他。幸亏,emacs为此功能有内置的命令,叫"tags-search"。这个命令基本上来说是一个命令,grep所有TAGS提到的源代码。这个命令非常快。
One pretty annoying thing about ctags is that it only indexes declarations and definitions of symbols, not invocations. Fortunately emacs has a built-in workaround for this, called "tags-search". This is basically a grep that looks through all the source files mentioned in your TAGS file. It's fast, so you can pretty quickly zip through all the matches in your codebase:
M-x tags-search <type your regexp> initiate a search 启动一个搜索
M-, go to the next m
你可以搜索所有的正则表达式,而不只是代码符号。match 下一个匹配
You can search for any regexp, not just source code symbols.
Bugs/annoyances with ctags:
-
doesn't understand C++ scoping. So if you're looking for SomeClass::IsValid(), you get shown every damn class in the codebase that has an IsValid() method, every IsValid member, global function, etc. This makes ctags useless in some situations.
-
tags-search doesn't seem to have a "go backwards" command.
使用M-.调用find-tags函数,然后在提示符后要查找的函数名,比如mark-whole-buffer。Emacs将转到显示该函数源码缓冲区。
符号表'tags table'通常是一个名为TAGS的文件。Emacs源码的TAGS存储在/usr/local/share/emacs目录中。但可以通过M-x visit-tags-table命令指定一个符号表。
通过etags命令可以创建符号表。使用M-x cd命令或C-x d(dired)切换到要建立符号表的目录,然后运行编译命令执行etags *.el命令。例:
M-x compile RET etags *.el RET
2,在阅读某一个源代码文件的时候,可以使用emacs的书签功能和“Alt . ”来回的调转,十分的方便。
3,还是要说一下emacs的书签功能。这是一个很好用的,而且十分容易上手的功能。具体的几个操作如下:
ctrl x r m :建立书签
ctrl x r l :打开书签列表
ctrl x r b :调转到书签指示的位置
M-x bookmark-write :把书签保存到一个指定的文件,这很有用,一个项目的书签可以保存在一个单独的文件中
M-x bookmark-load :从指定的文件中加载书签。
ESC .(英文句号) : find-tag 可以找到当前光标住函数或者字符串的定义
0 评论:
发表评论