为了更好的使用emacs编程,需要安装插件。
一、安装好GNU Emacs 23.1.1
二、安装cedet-1.0pre6。安装cedet时,直接将其解压到硬盘上,然后在shell中进入此目录,按照INSTALL文件的指示执行sudo make,然后增加.emacs相关内容。(最好使用cvs版本,可通过脚本 cvs -z3 -d:pserver:anonymous@cedet.cvs.sourceforge.net:/cvsroot/cedet co -P cedet 得到 )
三、安装ecb 2.40。只需将其解压到硬盘,修改相关.emacs文件内容即可。
四、安装cscope 15.7a。将其解压到硬盘,按照INSTALL文件指示依次执行sudo ./configure、sudo make、sudo make install,然后修改相关.emacs文件内容即可。
五、修改.emacs文件内容增加三个脚本的执行:multi-gud.el、multi-gdb-ui.el、display-line-number.el。
六、在默认emacs工作目录中增加脚本cscope.sh,内容如下:
#!/bin/bash
LNX=~/linux
find $LNX /
-path "$LNX/arch/*" ! -path "$LNX/arch/i386*" -prune -o /
-path "$LNX/include/asm-*" ! -path "$LNX/include/asm-i386*" -prune -o /
-path "$LNX/tmp*" -prune -o /
-path "$LNX/Documentation*" -prune -o /
-path "$LNX/scripts*" -prune -o /
-path "$LNX/drivers*" -prune -o /
-name "*.[chxsS]" -print > cscope.files
cscope -b -k
然后执行此脚本,然后执行Emacs。
七、emacs中开启ecb:ecb-activate
开启gdb:gdb
开启cscope:cscope-b
附录:设置后的.emacs文件内容
(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-D???ì?-normal-r-normal-normal-14-*-96-96-c-*-gb2312")
;; Load CEDET
(load-file "~/software/cedet-1.0pre6/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)
(global-set-key [(f4)] 'speedbar-get-focus)
(require 'cc-mode)
(c-set-offset 'inline-open 0)
;;(c-set-offset 'friend '-)
(c-set-offset 'substatement-open 0)
(defun my-c-mode-common-hook()
(setq tab-width 8 indent-tabs-mode nil)
;;; hungry-delete and auto-newline
(c-toggle-auto-hungry-state 1)
(define-key c-mode-base-map [(control /')] 'hs-toggle-hiding)
;; (define-key c-mode-base-map [(return)] 'newline-and-indent)
;; (define-key c-mode-base-map [(f6)] 'compile)
(define-key c-mode-base-map [(meta /')] 'c-indent-command)
;; (define-key c-mode-base-map [(tab)] 'hippie-expand)
(define-key c-mode-base-map [(tab)] 'my-indent-or-complete)
(define-key c-mode-base-map [(meta /)] 'semantic-ia-complete-symbol-menu)
(setq c-macro-shrink-window-flag t)
(setq c-macro-preprocessor "cpp")
(setq c-macro-cppflags " ")
(setq c-macro-prompt-flag t)
(setq hs-minor-mode t)
(setq abbrev-mode t)
)
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
(defun my-c++-mode-hook()
(setq tab-width 8 indent-tabs-mode nil)
(c-set-style "stroustrup")
;; (define-key c++-mode-map [f3] 'replace-regexp)
)
(setq gdb-many-windows t)
(add-to-list 'load-path "~/software/emacs_el")
(require 'gud)
(require 'display-line-number)
(load-library "linum.el")
(global-display-line-number-mode 1)
;;(setq display-line-number-mode-on t)
(add-hook 'c-mode-hook 'display-line-number-mode)
(add-hook 'cc-mode-hook 'display-line-number-mode)
(add-to-list 'load-path "~/software/ecb-2.40")
;;(require 'ecb)
(require 'ecb-autoloads)
;;for gdb-many-window mode
(load-library "multi-gud.el")
(load-library "multi-gdb-ui.el")
;; cscope in emacs
(add-to-list 'load-path "~/software/cscope-15.7a/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)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(ecb-source-path (quote ("/home/zhouyi198631/linux"))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)