关闭

emacs 中配置cscope

标签: emacsbufferbindingautocompletelistdatabase
3881人阅读 评论(0) 收藏 举报
分类:

emacs+autocomplete+cscope三者配合编程能极大提高编程效率,前面已介绍emacs配置autocomplete,接下来介绍一下如何配置cscope

1在emacs的配置文件~/.emacs中添加

;;LOAD_PATH       

(add-to-list 'load-path' "~/.emacs.d/xcscope")

 

2在.emacs文件中加入下面的语句

(require 'xcscope)

或者,你希望只在打开c/c++文件的时候才加载xcscope,可以加入

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

 

3.xcscope默认的快捷键都是绑定到C-c s的前缀上面,如果你经常使用xcscope.el,可以自己进行按键绑定,减少击键次数。不要担心别人笑你懒,xcscope.el的编写者就鼓励我们这样做:-)。具体方法是,在.emacs文件中加入

(define-key global-map [(control f3)]  'cscope-set-initial-directory)

(define-key global-map [(control f4)]  'cscope-unset-initial-directory)

(define-key global-map [(control f5)]  'cscope-find-this-symbol)

(define-key global-map [(control f6)]  'cscope-find-global-definition)

(define-key global-map [(control f7)]  'cscope-find-global-definition-no-prompting)

(define-key global-map [(control f8)]  'cscope-pop-mark)

(define-key global-map [(control f9)]  'cscope-next-symbol)

(define-key global-map [(control f10)] 'cscope-next-file)

(define-key global-map [(control f11)] 'cscope-prev-symbol)

(define-key global-map [(control f12)] 'cscope-prev-file)

(define-key global-map [(meta f9)]     'cscope-display-buffer)

(define-key global-map [(meta f10)]    'cscope-display-buffer-toggle)

 

4.重启emacs,使配置生效。


基本使用

这里以内核源码为例,介绍Cscope的基本用法。

1.首先,在源码根目录下,如~/kernerl/linux-0.11,利用cscope-indexer脚本生成文件列表和数据库,方法是执行

cscope-indexer -r

 

2. C-s搜索sched_init函数,将光标停在函数名上,按C-c s d,回车

 


附:默认的按键绑定

;; * Keybindings:

;;

;; All keybindings use the "C-c s" prefix, but are usable only while

;; editing a source file, or in the cscope results buffer:

;;

;;      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.

;;

;; These pertain to navigation through the search results:

;;

;;      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.

;;

;; These pertain to setting and unsetting the variable,

;; `cscope-initial-directory', (location searched for the cscope database

;;  directory):

;;

;;      C-c s a         Set initial directory.

;;      C-c s A         Unset initial directory.

;;

;; These pertain to cscope database maintenance:

;;

;;      C-c s L         Create list of files to index.

;;      C-c s I         Create list and index.

;;      C-c s E         Edit list of files to index.

;;      C-c s W         Locate this buffer's cscope directory

;;                      ("W" --> "where").

;;      C-c s S         Locate this buffer's cscope directory.

;;                      (alternate binding: "S" --> "show").

;;      C-c s T         Locate this buffer's cscope directory.

;;                      (alternate binding: "T" --> "tell").

;;      C-c s D         Dired this buffer's directory.

 

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:162355次
    • 积分:2050
    • 等级:
    • 排名:第18823名
    • 原创:52篇
    • 转载:18篇
    • 译文:0篇
    • 评论:15条
    最新评论