在windows环境下使用emacs + cscope + ecb替代source insight(转)

 source insight是windows环境下用于代码开发和阅读的利器,功能强大,对于大规模代码的维护和开发几乎不可或缺(这里
指它提供的功能,类似的商业工具还有很多)。使用emacs替代source insight原因有:a,si是商业软件,使用需要付费,虽然可以从网上
找到破解版本;b,对于unix/linux爱好者或者需要同时工作于unix和windows环境下的开发人员,emacs是通用工具;emacs其它的强大
功能暂且不表。
下面是基于windows xp平台的安装方法,其中大部分步骤和unix环境下的一样,只有cscope的有所不同。

1)准备工作
首先,你得下载一下一些工具(扩展),emacs,cscope,ecb,cedet是必须的,session,doxymacs不是必要的,但是装上会
更方便。下载这些东西的网址链接如下:(当然,下面这些东西都可以从google找到下载链接,下面提供的网址都是google出来的,如果
下面提供的链接不可用了,大家可以自己google一把)
i)emacs:http://www.gnu.org/software/emacs/
从gnu的ftp网站上下载windows版本,最新的版本是emacs-22.1。下面的设置都是在这个版本上进行的。

ii)cscope:cscope的主页http://cscope.sourceforge.net/,其中有一个download的链接,从那里可以下载到编译好的压缩包。
win32版本的下载地址:http://iamphet.nm.ru/cscope/index.html,压缩包中有两个编译好的exe文件:cscope.exe, sort.exe

iii)ecb:主页地址http://ecb.sourceforge.net/,download页面中还有一个Xemcas的安装程序setup.exe,可以试试,我没有使用这个。
sourceforg下载地址http://sourceforge.net/project/showfiles.php?group_id=17484

iv)cedet:主页http://cedet.sourceforge.net/,下载release压缩包1.0pre4.tar.gz,这个包中已经包含了semantic,ede,eieio,
speedbar,因此下载了这个大包后不用分别下载这些扩展插件。

v)session:sf下载地址http://sourceforge.net/project/showfiles.php?group_id=46019

vi)doxymacs:地址http://doxymacs.sourceforge.net/
下载http://sourceforge.net/project/s ... p;release_id=514962

vii)下载windows下的bash工具,主要是用到其中的find工具,用来手工生成cscope.files。如果安装了cygwin则不用安装这个了。
地址:http://folk.uio.no/andreass/unix_tools.html

2)安装
安装emacs:这个很简单,只要将压缩包解开,放到你想放的位置就可以用了,如果要在windows的开始菜单中添加菜单项,点击bin目录下
的addpm运行,就会在菜单中加入gnu菜单项。

安装cscope:a,解压平台不相关的那个tar.gz包,将/contrib/xscope/xscope.el拷贝到emacs-22.1/site-lisp目录下(emacs-22.1是
你安装emacs的目录);b,解压win32版本的cscope,将cscope.ext sort.exe拷贝到emacs-22.1/bin目录下(这个路径不是必要的,因为
cscope在windows下要用起来还得费点劲,4)点会讲到)

安装ecb:解压,将解压后的ecb目录拷贝到site-lisp目录下。

安装cedet:解压,将解压后的cedet目录拷贝到site-lisp目录下。

安装session:解压,将解压后的session目录拷贝到site-lisp目录下。

安装doxymacs:解压,将解压后的doxymacs目录拷贝到site-lisp目录下。

安装win32bash:点击user.exe安装文件一步步点到最后就行了。
到此安装工作完成。

3)配置.emacs启动文件
显示指定扩展插件的加载地址(这一步好像不是必要的,只列出一个地址,其它类似)
(add-to-list 'load-path "e:/emacs/site-lisp/ecb-2.31"
加载相应插件:
(require 'xcscope) ;;加载xcscope
(require 'cedet) ;;加载cedet
(require 'ecb) ;;加载ecb
(require 'session) ;;加载session
(add-hook 'after-init-hook 'session-initialize) ;; 启动时初始化session
(require 'doxymacs) ;; 启动doxymacs
在配置文件中加入这些语句后,保存重启emacs,重启后查看一下Message窗口中的加载信息,可以看到各个插件加载成功。
在.emacs中加入一些方便的设置就可以使用了,完整的配置文件附在后面。(这些配置都是从google上到处搜刮来的,其中王垠博士的
网页上有很多emacs设置的好东西可以参考,还有一些英文网站上贴出的配置文件中也有很多好东西,大家可以根据自己的习惯写自己的
配置)

4)问题及解决
安装进行到这里,大部分功能都没有问题了,存在的问题有:
i)cscope的创建文件列表和创建代码符号索引两个命令不可用,按下C-c s L和C-c s I后minibuffer中显示cscope-indexer找不到。在
cscope的安装包中确实有一个cscope-indexer的文件,我们安装时没有将它拷贝到emacs的安装路径中去,但是即使将它拷贝到bin目录下
也还是不能工作,用文本编辑器打开cscope-indexer会发现它其实是个shell脚本文件,从脚本中可以看到,它首先通过find,grep等工具
生成一个cscope.files的文件,然后调用cscope使用cscope.files作为输入生成cscope.out的索引文件。
因此,只要能生成一个文件列表的文件就可以使用win32版本的cscope.exe来生成cscope.out文件。到此,我们可以使用win32bash中的find
工具生成一个源代码文件列表了(与unix下一样:find /my-project-source -name "*.[chs]" -print > cscope.files,不知windows下
是否有类似find这样功能的命令,xp下的find好像不能用通配符,如果有这样的东西就可以不安装win32bash)。
生成了cscope.files源码文件列表后就可以使用它像si一样在代码间穿梭了:
C-c s a设定代码根目录,cscope.files必须放在这个设定目录下,否则cscope找不到;在第一次使用如下几条命令时cscope会自动生成
cscope.out,也可以在windows的cmd中调用cscope.exe -b -i cscope.files -f cscope.out生成cscope.out。
C-c s g查找函数(或变量)定义;
C-c s c查看调用者;
C-c s C查看函数中调用的子函数;

ii)semantic中设置的项目根目录好像不起作用,在进行tag查找时semantic只查了当前目录中的代码文件,如果引用的是其它目录中的函数
或变量,查找相应定义时就找不到。这个问题还不知道原因,可能是设置的问题,semantic的设置项太多了。遇到相同问题的朋友请解答一下。

到此,si中常用的几个动作实现了。

还有个si中类似功能的实现:跳到函数定义后如何在跳回刚才的调用函数的地方。
在王垠的网页中找到了一个实现
;;;临时记号
(global-set-key [(control ?/.)] 'ska-point-to-register)
(global-set-key [(control ?/,)] 'ska-jump-to-register)
(defun ska-point-to-register()
  "Store cursorposition _fast_ in a register.
Use ska-jump-to-register to jump back to the stored
position."
  (interactive)
  (setq zmacs-region-stays t)
  (point-to-register )

(defun ska-jump-to-register()
  "Switches between current cursorposition and position
that was stored with ska-point-to-register."
  (interactive)
  (setq zmacs-region-stays t)
  (let ((tmp (point-marker)))
        (jump-to-register 
        (set-register 8 tmp)))
这样就可以在函数间跳来跳去,
结合cscope的pop-mark,就可以跳来跳去了,这样基本可以满足大多数情况下的使用。
还有一些有用扩展:http://docs.huihoo.com/homepage/shredderyin/emacs_elisp.html

ecb,cedet(semantic)提供了很多功能,不过由于太多了,需要慢慢摸索,目前使用cscope已经基本上实现了si上的几个常用功能,
ecb + semantic可以实现像si中的函数/变量上下文显示功能,但是由于4)ii)中提到的问题,这个显示上下文功能有时候不起作用。

 

 C-c s s 序找符號
            C-c s g 尋找全局的定義(即是 cscope-find-global-definition)
            C-c s c 看看指定函數被哪些函數所調用
            C-c s C 看看指定函數調用了哪些函數
            C-c s e 尋找正則表達式
            C-c s f 尋找文件
            C-c s i 看看指定的文件被哪些文件include
            C-c s u 回到上一個 symbol  (即cscope-pop-mark)

補充:修改 .emacs 取代常用的 cscope 命令,在 (require 'xcscope) 後加上
(define-key global-map [f7] 'cscope-pop-mark)
(define-key global-map [f8] 'cscope-find-global-definition)
(define-key global-map [f9] 'cscope-find-global-definition-no-prompting)
(define-key global-map [M-up] 'cscope-prev-symbol)
(define-key global-map [M-down] 'cscope-next-symbol)
(define-key global-map [f12] 'c-down-conditional-with-else)
(define-key global-map [M-f12] 'c-up-conditional-with-else)

 

查找配置文件目录:C-x C-f ~

 

本人_emac配置文件:

;;(setq initial-frame-alist '((top . 0) (left . 0) (width . 1024) (height . 768)))

(column-number-mode t)
(transient-mark-mode t)
(setq line-number-mode t)
(setq default-tab-width 8)

(customize-set-variable 'scroll-bar-mode' right)
;;(setq default-directory "home/jzj/backup/emacs/")
(setq inhibit-startup-message t)
(setq global-font-lock-mode t)
(setq make-backup-files nil)
(setq auto-save-mode nil)
(setq x-select-enable-clipboard t)
(setq mouse-yank-at-point t)
;;(global-set-key [home] 'beginning-of-buffer)

;;(global-set-key [end] 'end-of-buffer)
(global-set-key [f3] 'display-line-number-mode-on)
;;(global-set-key [f4] 'other-window)
(global-set-key [f5] 'compile)
(setq-default compile-command "make")
;;(global-set-key [f7] 'du-onekey-compile)
(global-set-key [f6] 'gdb)
(global-set-key [C-f7] 'previous-error)
(global-set-key [f7] 'next-error)

;;(set-default-font "9x15")
;;(set-default-font "-adobe-courier-medium-r-normal--14-100-100-100-m-90-iso10646-1")
(set-default-font "10x20")
;;(set-default-font "-outline-新宋体-normal-r-normal-normal-14-*-96-96-c-*-gb2312")

;; cscope in emacs
(add-to-list 'load-path "~/software/cscope-15.6/contrib/xcscope")
(require 'xcscope)

;; hotkey for cscope
(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)

(set-face-background 'default "#334455")
(set-face-foreground 'default "wheat")
(set-cursor-color "white")


;;(add-to-list 'load-path "~/software/color-theme-6.6.0")
;;(require 'color-theme)
;;(color-theme-dark-blue)

 

========================================================================

 

emacs是个强大的编辑器.在linux/unix下有广泛的使用群体.它既可以当做文字处理软件.也可以作为集成开发环境来用.很多人用emacs编程序的时候只用到了内置的一些模式.其实emacs有个很好的集成开发环境ecb.安装之后可以让emacs有类似VS的样子.和自动补全等诸多功能.本文会指导你在emacs下安装ecb和cedet.

我其实很懒的.如果网上能找到我也不会写出来了.如何在emacs下安装ecb和cedet的中文文章确实很少.所以我来写一篇.本文内容都可以在.
ecb            http://ecb.sourceforge.net/
cedet         http://cedet.sourceforge.net/
网站上找到.但都是英文的.而且很罗嗦.我这个是精简版.如果还有安装问题.以上面两个网站的内容为主.
ecb的主要功能是图形界面.有好几种模式可选
cedet里面又有好几个包semantic是语法分析.eieio是面向对象设计的工具等等

本文目的:
指导安装ecb和cedet,搭建c,c++,lisp的开发环境

前提:
你有个linux或unix系统.
GNU emacs

如果你不能满足这俩个条件,请现安装一个linux发行版.并且安装emacs.

好吧,那么先展示一下装好的样子.很酷吧.


更多图片请看http://ecb.sourceforge.net/

先下载这两个软件的安装包
ecb      http://ftp1.sourceforge.net/ecb/ecb-2.32.tar.gz
cedet
http://sourceforge.net/project/showfiles.php?group_id=17886&release_id=513873

然后
tar zxvf ecb-2.32.tar.gz
tar zxvf cedet-1.0div4.tar.gz
cd cedet-1.0div4
make
等cedet生成完毕
在你的用户目录下面应该有一个.emacs文件(前面有个点).这个文件是emacs的配置文件.现在我们要改这个文件(如果没有就自己创建一个).添加下面一段.注意,load-file那一行的目录要自己改一下
;; Load CEDET
(load-file "你存放cedet的目录/common/cedet.el")
;;我的是(load-file "~/cedet-1.0/common/cedet.el")

;; Enabling various SEMANTIC minor modes.  See semantic/INSTALL for more ideas.
;; Select one of the following:

;; * This enables the database and idle reparse engines
;;(semantic-load-enable-minimum-features)

;; * This enables some tools useful for coding, such as summary mode
;;   imenu support, and the semantic navigator
(semantic-load-enable-code-helpers)

;; * This enables even more coding tools such as the nascent intellisense mode
;;   decoration mode, and stickyfunc mode (plus regular code helpers)
;; (semantic-load-enable-guady-code-helpers)

;; * This turns on which-func support (Plus all other code helpers)
;; (semantic-load-enable-excessive-code-helpers)

;; This turns on modes that aid in grammar writing and semantic tool
;; development.  It does not enable any other features such as code
;; helpers above.
;; (semantic-load-enable-semantic-debugging-helpers)

这样cedet就装好了

接下来安装ecb
在.emacs里面加入

(add-to-list 'load-path "你放ecb的目录")
;;例如(add-to-list 'load-path "~/.emacs.d/ecb-2.32")
(require 'ecb)

注意这个段要加在cedet配置的后面

重启emacs

在emacs中打开一个c或者c++文件.选tool中的
Start Code Browser(ECB)
呵呵,看看有什么变化吧.

ecb和cedet都有多得吓人的功能.具体请看M-x ecb-show-help 和cedet包里面的install文件.

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值