emacs 使用积累5.2 cscope

cscope:

     方法是调用Cscope时,使用-q参数。真的假的,一试便知。

     修改cscope-indexer脚本,将 cscope -b -i $LIST_FILE -f $DATABASE_FILE  替换为 cscope -q -b -i $LIST_FILE -f $DATABASE_FILE

  建立索引:

/mnt/trunk/base/3pp/linux-st7109/linux-2.6.23# gencsfil xkernel

/mnt/trunk/base/3pp/linux-st7109/linux-2.6.23# cscope-indexer  -r

        /mnt/trunk# gencsfil

        /mnt/trunk# cscope-indexer  -r  //不能使用, 生成的索引太大了!!!--->>>>在trunk竟然生成了;

        /mnt/trunk# cscope -Rbq           --->>>>在trunk竟然生成了;



Cscope 基本快捷健:   cscope-minor-mode  模式; 只有进入c,cpp, .h 等文件时才能使用下面的快捷键以及 menu菜单;

       cscope-minor-mode  http://www.gnu.org/software/emacs/manual/html_node/emacs/Minor-Modes.html

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

     C-c C-h   查看所有的 cscope 相关的按键  输入M+x cscope  之后Tab健,就给出各种命令可以选择;

     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.; 看看指定的文件被哪些文件include

 

    C-c s a    设定索引文件所在目录; 一般是你代码的根目录

    C-c s I          //只要执行 C-c s I  (cscope-index-files) 就可以 生成 Cscope 的数据库;   对目录中的相关文件建立列表并进行索引

 

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

    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.




1,copy 相关配置文件  and database file.

Cscope的源码包里面有个xcscope.el文件,为(X)Emacs提供了Cscope 接口。它处于源码包的 contrib/xcscope 目录下。

该目录下面还有一个名为cscope-indexer的脚本文件,用于创建文件列表和数据库。

         xcscope.el文件::::     http://opensource.apple.com/source/cscope/cscope-6/cscope/contrib/xcscope/xcscope.el?txt

leosu@leosu:/home/tools$ find . -name xcscope.el

./devtools/trunk/elisp/xcscope.el

 leosu@leosu:/mnt/sda3/dev_iptv/ELYMUS_work$ which cscope-indexer

/home/leosu/bin/cscope-indexer

 

生成 cscope 索引文件, 方法1:detail reference: http://hi.baidu.com/bamboolsu/blog/item/e61082632cca0dfde6113a90.html

 find . \( -path "*3pp" \

                           -o -path "*testcases*" \

                           -o -path "*test*" \

                           -o -path "*applications*" \

                           -o -path "*Mock*" \

                           -o -path "*.svn*" \

                           -o -path "*.pc*" \

                           -o -path "*.idlcpp*" \

                           -o -path "*.idljs*" \

                           -o -path "*bcm*" \

                           -o -path "*dist*" \

                           -o -path "*st40*" \

                           -o -path "*mocks*" \) -prune -o -regex ".*\.\(cpp\|c\|h\|s\|S\|cc\)" -print > cscope.files

生成 cscope 索引文件, 方法2:

      生成 project 文件列表,可以用如下命令完成。例如kernel代码,找出所以 .h, .c, .S文件

      leosu@leosu:/mnt/sda3/dev_iptv/ELYMUS_work$find -type f | grep -E '\.[chS]$' > cscope.files

           $ find . -name "*.cpp" -o -name "*.c" -o -name "*.h" > cscope.files

   生成 cscope 索引文件, -k 专门用于生成 linux kernel 源码的索引

   leosu@leosu:/mnt/sda3/dev_iptv/ELYMUS_work$cscope -b -k 

      

生成 cscope 索引文件, 方法3:

      leosu@leosu:/mnt/sda3/dev_iptv/ELYMUS_work$ cscope-indexer

,可以根据自己的需要 hack   cscope-indexer ,比如我通常用 quilt 管理 patch,会在源代码目录生成/.pc/目录, 里面是拷贝的 c 文件,我并不希望 cscope-indexer 去搜索这些文件,看了一下这个文件,无非就多加一个规则,虑除.pc 下所有文件

             egrep -i '\.([chly](xx|pp)*|cc|hh)$' | \

           - sed -e '/\/CVS\//d' -e '/\/RCS\//d' -e 's/^\.\///' | \

            + sed -e '/\/CVS\//d' -e '/\/RCS\//d' -e '/\/\.pc\//d' -e 's/^\.\///'| \

 

生成 cscope database:  this need cscope.files  files

    # cscope -bkq

    #cscope -b -i cscope.files   //根据 cscope.files 生成 database


 

 

 

2, 修改.emacs 文件

#vim .emacs

;;LOAD_PATH-------

;;;(add-to-list 'load-path' "/home/tools/devtools/trunk/elisp/")

;;(load "/home/tools/devtools/trunk/elisp/xcscope+.el")

;;(require 'cscope )

(setq cscope-do-not-update-database t)

(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)

(require 'xcscope "/home/tools/devtools/trunk/elisp/xcscope.el")

 

 

hack xcscope.el 文件

      xcscope.el 也比较简单,很多配置项都写死了,没法修改,比如在跳出的 cscope 窗口中, 选择要跳转到哪一个位置, 有 2 种方式: 一个是光标移动到函数位置,按回车。另一个是用鼠标中键点击。       

       第 2 种方式是在是太奇怪了,我想把它改到鼠标左键上, 修改 xcscope.el 文件,mouse-2 改成 mouse-1 就大功告成

           (if cscope-running-in-xemacs

              (define-key cscope-list-entry-keymap [button2] 'cscope-mouse-select-entry-other-window)

             - (define-key cscope-list-entry-keymap [mouse-2] 'cscope-mouse-select-entry-other-window))

             + (define-key cscope-list-entry-keymap [mouse-1] 'cscope-mouse-select-entry-other-window))


 

3 . 运行 emacs,以下是一些常用的按键

  C-c s C-h 查看所有的 cscope 相关的按键

  C-c s a 设定索引文件所在目录

  C-c s c 查找调用该函数的地方

  C-c s g 查找该符号的全局定义

  C-c s f 查找该符号对应的文件

;; 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 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 cscope database maintanance:

;;

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


 

 

4, 不用快捷键操作 cscope, 

从之后打开emacs后,输入M+x cscope  之后Tab健,就给出各种命令可以选择;

Possible completions are:

cscope-bury-buffer                      cscope-create-list-of-files-to-index

cscope-dired-directory                 cscope-display-buffer

cscope-display-buffer-toggle       cscope-edit-list-of-files-to-index

cscope-find-called-functions       cscope-find-egrep-pattern

cscope-find-files-including-file

cscope-find-functions-calling-this-function

cscope-find-global-definition

cscope-find-global-definition-no-prompting

cscope-find-this-file                            cscope-find-this-symbol

cscope-find-this-text-string               cscope-help

cscope-index-files                             cscope-mouse-select-entry-other-window

cscope-next-file                                 cscope-next-symbol

cscope-pop-mark                               cscope-prev-file

cscope-prev-symbol                           cscope-quit

cscope-select-entry-one-window         cscope-select-entry-other-window

cscope-select-entry-specified-window       cscope-set-initial-directory

cscope-show-entry-other-window                 cscope-tell-user-about-directory

cscope-unset-initial-directory                     cscope:menu

 

 

 

 

 

 

 

 Reference: 

     http://blog.youkuaiyun.com/intrepyd/article/details/4202312

     http://lifegoo.pluskid.org/wiki/EmacsCscope.html

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值