Using CEDET and ECB with Emacs

(I tested the following procedure about installing and customizing CEDET for Emacs with GNU Emacs 23 under Ubuntu and Snow Leopard.)

Installation

  • Install CEDET
    1. Download the source package of CEDET
    2. Unpack to ~/.emacs.d/cedet (or other places)
    3. Compile the package using command
      emacs -Q -nw -l cedet-build.el -f cedet-build -f save-buffers-kill-terminal
  • Install external tag systems (optionally required by CEDET)
    1. GNU Global, and/or
    2. exuberent ctags
  • Install ECB
    1. Download the source package of ECB.
    2. Unpack into ~/.emacs.d/ecb (or any other directory)

Customization

An excellent tutorial about customizing CEDET is here. The author also published his .emacs file which contains a few flaws. Mine based on his is as follows:

;; CEDET
(load-file "~/.emacs.d/cedet-1.0pre7/common/cedet.el")

(global-ede-mode 'nil)                  ; do NOT use project manager

(semantic-load-enable-excessive-code-helpers)

(require 'semantic-ia)          ; names completion and display of tags
(require 'semantic-gcc)         ; auto locate system include files

(semantic-add-system-include "~/3rd-party/boost-1.43.0/include/" 'c++-mode)
(semantic-add-system-include "~/3rd-party/protobuf-2.3.0/include" 'c++-mode)

(require 'semanticdb)
(global-semanticdb-minor-mode 1)

(defun my-cedet-hook ()
  (local-set-key [(control return)] 'semantic-ia-complete-symbol)
  (local-set-key "\C-c?" 'semantic-ia-complete-symbol-menu)
  (local-set-key "\C-c>" 'semantic-complete-analyze-inline)
  (local-set-key "\C-c=" 'semantic-decoration-include-visit)
  (local-set-key "\C-cj" 'semantic-ia-fast-jump)
  (local-set-key "\C-cq" 'semantic-ia-show-doc)
  (local-set-key "\C-cs" 'semantic-ia-show-summary)
  (local-set-key "\C-cp" 'semantic-analyze-proto-impl-toggle)
  (local-set-key "\C-c+" 'semantic-tag-folding-show-block)
  (local-set-key "\C-c-" 'semantic-tag-folding-fold-block)
  (local-set-key "\C-c\C-c+" 'semantic-tag-folding-show-all)
  (local-set-key "\C-c\C-c-" 'semantic-tag-folding-fold-all)
  )
(add-hook 'c-mode-common-hook 'my-cedet-hook)

(global-semantic-tag-folding-mode 1)

(require 'eassist)

;(concat essist-header-switches ("hh" "cc"))
(defun alexott/c-mode-cedet-hook ()
  (local-set-key "\C-ct" 'eassist-switch-h-cpp)
  (local-set-key "\C-xt" 'eassist-switch-h-cpp)
  (local-set-key "\C-ce" 'eassist-list-methods)
  (local-set-key "\C-c\C-r" 'semantic-symref)
  )
(add-hook 'c-mode-common-hook 'alexott/c-mode-cedet-hook)

;; gnu global support
(require 'semanticdb-global)
(semanticdb-enable-gnu-global-databases 'c-mode)
(semanticdb-enable-gnu-global-databases 'c++-mode)

;; ctags
(require 'semanticdb-ectag)
(semantic-load-enable-primary-exuberent-ctags-support)

(global-semantic-idle-tag-highlight-mode 1)

Using CEDET

  1. control return: whatever the symbol you are typing, this hot key automatically complete it for you.
  2. C-c?: another way to complete the symbol you are typing
  3. C-c>: when you typed . or -> after an object name, use this key to show possible public member functions or data members.
  4. C-cj: jump to the definition of the symbol under cursor
  5. C-cs: show a summary about the symbol under cursor
  6. C-cq: show the document of the symbol under cursor
  7. C-c=: visit the header file under cursor
  8. C-cp: toggle between the implementation and a prototype of symbol under cursor
  9. C-ce: when your cursor is in the scope of a class or one of its member function, list all methods in the class
  10. C-cC-r: show references of the symbol under cursor
  11. C-cC-c-: fold all
  12. C-cC-c+: unfold all
  13. C-c-: fold the block under cursor
  14. C-c+: unfold the block under cursor

Using ECB

Once CEDET is installed and customized, we can use ECB. Add the following lines into your .emacs file:

(add-to-list 'load-path "~/.emacs.d/ecb-2.40")
(require 'ecb)
(require 'ecb-autoloads)

In Emacs, we can use M-x ecb-activate to turn on ECB mode. This page shows how to byte compile ECB to make it runs fast.