普通
跳转
开发时,通常要在成对标签中跳转,这有利于我们清楚程序结构。默认键绑定情 况下,将光标移动到 "{" (或其他) 上,按下面键:
| C-M-f | 跳转到结束符号,如 "}" |
| C-M-b | 返回开始符号,如 "{" |
也可以用:
| C-M-n | 至结束 |
| C-M-p | 至开头 |
用 C-h-k 可以看到这些键默认绑定情况:
| C-M-f | forward-sexp |
| C-M-b | backward-sexp |
| C-M-n | forward-list |
| C-M-p | backward-list |
可以这样重新定义绑定键(摘录别人的,我不用 :-)
;;模拟vim % 的作用
(global-set-key "%" 'match-paren)
(defun match-paren (arg)
"Go to the matching paren if on a paren; otherwise insert %."
(interactive "p")
(cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
((looking-at "\\s\)") (forward-char 1) (backward-list 1))
(t (self-insert-command (or arg 1)))))
浏览代码
etags
使用 etags 生成 TAGS 索引文件后,就可以使用 Emacs 查找。
生成索引
find . -name '*.py'|xargs etags --members --language=python
Emacs 里使用
先加载 TAGS 表:
M-x visit-tags-table
或者在 .emacs 文件中加载:
(setq tags-file-name "~/work/tcd/TAGS")
使用
M-. (同时按下 alt 和 . 键) 搜索当前光标处字符串的定义 M-* (同时按下 alt , shift, 8 键) 返回上一次搜索处
cscope
参考: http://lifegoo.pluskid.org/wiki/EmacsCscope.html
要在 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 u Pop mark.
更详细的使用说明可参见 xcscope.el 文件头部的注释。
ecb
主页: http://ecb.sourceforge.net/
安装启用
基本各个发行版安装起来很方便,安装完在 ~/.emacs 文件中添加:
(require 'ecb)
启用 ecb ("M-x ecb-activate")
