折腾半年多了,总算是找到个比较合适的方式。
我的选择是cedet+ecb+global
gnu-global是一个兼容tag工具,看名字就知道它打算怎么干活的了。gtags是emacs下与global交互的插件
首先一次去下载上面三个的源码,global是gtags,
cedet官网http://cedet.sourceforge.net/
ecb官网http://ecb.sourceforge.net/
然后ubuntu下不要使用sudo apt-get install 来的global,版本问题可能会和你下载gtags不兼容,有个参数不识别。
下载地址http://www.gnu.org/s/global/download.html
下载后解压,$./configure
$make
$sudo make install
然后源码包里有个gtags.el这是我们的emacs插件
把cedet,ecb,gtags插件放到你保存插件的位置,我的都在~/emacs/下面,然后每个插件有自己单独的目录。
;;配置cedet (add-to-list 'load-path "~/emacs/cedet-1.0pre7/common") (add-to-list 'load-path "~/emacs/cedet-1.0pre7/contrib") ;;(load-file "~/emacs/cedet-1.0pre7/common/cedet.el") (require 'cedet) (require 'semantic-ia) (global-ede-mode 1) ; Enable the Project management system (semantic-load-enable-code-helpers) ; Enable prototype help and smart completion (global-srecode-minor-mode 1) ; Enable template insertion menu (require 'semantic-tag-folding nil 'noerror) (global-semantic-tag-folding-mode 1) (global-set-key [f12] 'semantic-ia-fast-jump) (global-set-key [S-f12] (lambda () (interactive) (if (ring-empty-p (oref semantic-mru-bookmark-ring ring)) (error "Semantic Bookmark ring is currently empty")) (let* ((ring (oref semantic-mru-bookmark-ring ring)) (alist (semantic-mrub-ring-to-assoc-list ring)) (first (cdr (car alist)))) (if (semantic-equivalent-tag-p (oref first tag) (semantic-current-tag)) (setq first (cdr (car (cdr alist))))) (semantic-mrub-switch-tags first)))) ;(define-key c-mode-map [M-S-f12] 'semantic-analyze-proto-impl-toggle) (global-set-key (kbd "M-q") 'semantic-ia-complete-symbol-menu) (define-key semantic-tag-folding-mode-map (kbd "C-c , -") 'semantic-tag-folding-fold-block) (define-key semantic-tag-folding-mode-map (kbd "C-c , +") 'semantic-tag-folding-show-block) (define-key semantic-tag-folding-mode-map (kbd "C-_") 'semantic-tag-folding-fold-all) (define-key semantic-tag-folding-mode-map (kbd "C-+") 'semantic-tag-folding-show-all) ;; (setq semanticdb-project-roots (list (expand-file-name "/"))) (defconst cedet-user-include-dirs (list "/home/backfire/work/android/kernel/include" "/home/backfire/work/android/kernel/arch/arm/include" "/home/backfire/work/android/kernel/arch/arm/mach-XXX/include" "")) ;; (defconst cedet-win32-include-dirs ;; (list "C:/MinGW/include" ;; "C:/MinGW/include/c++/3.4.5" ;; "C:/MinGW/include/c++/3.4.5/mingw32" ;; "C:/MinGW/include/c++/3.4.5/backward" ;; "C:/MinGW/lib/gcc/mingw32/3.4.5/include" ;; "C:/Program Files/Microsoft Visual Studio/VC98/MFC/Include")) (require 'semantic-c nil 'noerror) (let ((include-dirs cedet-user-include-dirs)) ;; (when (eq system-type 'windows-nt) ;; (setq include-dirs (append include-dirs cedet-win32-include-dirs))) (mapc (lambda (dir) (semantic-add-system-include dir 'c++-mode) (semantic-add-system-include dir 'c-mode)) include-dirs))
F12快速跳转,shift+F12跳回。这个不是很好用,一般我只是在本文见内跳转采用。
然后是代码折叠的配置,不想用鼠标的话就可以看看。
include路径是用来补全的,我用的是M-q,但是用ac+gtags的时候比较多。这个大部分时间是闲置了
然后配置ecb,这个是分隔窗口类似ide的配件,主要用的就是tag-list类似的功能,别的其实很少用。
;;配置ecb (add-to-list 'load-path "~/emacs/ecb-2.40") (require 'ecb) ;;关掉每日提示 (setq ecb-tip-of-the-day nil) ;; 各窗口间切换 (global-set-key [C-left] 'windmove-left) (global-set-key [C-right] 'windmove-right) (global-set-key [C-up] 'windmove-up) (global-set-key [C-down] 'windmove-down) ;; 隐藏和显示ecb窗口 (define-key global-map [(control f1)] 'ecb-hide-ecb-windows) (define-key global-map [(control f2)] 'ecb-show-ecb-windows) ;; 使某一ecb窗口最大化 ;(define-key global-map "/C-c1" 'ecb-maximize-window-directories) ;(define-key global-map "/C-c2" 'ecb-maximize-window-sources) ;(define-key global-map "/C-c3" 'ecb-maximize-window-methods) ;(define-key global-map "/C-c4" 'ecb-maximize-window-history) ;; 恢复原始窗口布局 ;(define-key global-map "/C-c`" 'ecb-restore-default-window-sizes)
然后说几个常用的配置,你可以调整左边窗口的默认宽度,你可以配置分隔的样式,具体配置需要你去看看ecb的手册,
强制性的,否则你会觉得ecb不好用,查看ecb帮助,先启动ecb,然后M-x ecb-show-help。就会打开ecb的info。
配置global
;;配置gtags (add-to-list 'load-path "~/emacs/global") ;(autoload 'gtags-mode "gtags" "" t) ;(setq c-mode-hook '(lambda () ; (gtags-mode 1))) (global-set-key (kbd "C-c g f") 'gtags-find-tag) (global-set-key (kbd "C-c g p") 'gtags-pop-stack) (global-set-key (kbd "C-c g s") 'gtags-select-tag)
然后是我的3个常用快捷键,
C-c g f查找tag,C-c g p返回,C-c g s,多个tags时选择一个tags,这个还有待研究,手册上说的任何emacs命令就可以选择,但是我没用处来。gtags和ac可以配置补全,很好用,不过补全傻了点,不过基本是够用了。
这个配置搞android还是满合适的。