·ChinaUnix首页 ·论坛 ·博客 
Linux首页 | Linux新闻 | Linux论坛 | Linux文档 | Linux下载 | Linux博客 | Linux搜索 | 开源项目孵化平台 | 《开源时代》
新手入门 | 安装启动 | 管理员指南 | 开发手册 | 桌面应用 | 程序开发 | 数据库 | 网络技术| CentOS | Fedora | MySQL | Apache | Ubuntu | Gentoo| OSCON08
  Linux时代 >> 技术文档 >> 程序开发
 
程序员的emacs配置大全(cedet+ecb+cscope+gdb-ui)-jzj
来源: ChinaUnix博客  日期: 2007.09.18 13:02 (共有条评论) 我要评论
 

                               
[/url]
本文主要讨论以下几方面的设置:
1.字体2.cedet3.ecb4.cscope5.gdb-many-window6.行号
7.缩进


环境:
openSUSE 10.2
默认装的是Emacs 21,我从网上下了Emacs 22.1的tar包,编译安装。
1.字体
    默认的字体非常之小,以下是一篇非常详细的Emacs下设置字体的教程
http://www.yuanma.org/data/2006/0503/article_355.htm
可惜太长了,长到我实在是懒得看。我抄了个现成的:
(set-default-font "-adobe-courier-medium-r-normal--14-100-100-100-m-90-iso10646-1")
或者只写:
(set-default-font "10x20")
第二种方法效果不错:)
2.cedet
   下载cedet:
[url=http://cedet.sourceforge.net/]http://cedet.sourceforge.net/

按照INSTALL安装就行,然后设置.emacs。INSTALL里有一段关于设置的,粘贴过来即可,另外最好在.emacs中设一个speedbar的快捷键:
(global-set-key [(f4)] 'speedbar-get-focus)
这样按一个F4,speedbar就出来了。
再加一条:
  (define-key c-mode-base-map [(meta ?/)] 'semantic-ia-complete-symbol-menu)
于是,在程序中按下Alt+/,就会弹出菜单让你自动补全。
3.ecb
   
http://ecb.sourceforge.net/
.emacs里:
(add-to-list 'load-path "~/software/ecb-2.32")
;;(require 'ecb)
(require 'ecb-autoloads)
打开emacs,然后M-x ecb-activate即可打开ecb。

4.cscope
   这个应该和ecb的有些功能是重复的
先装好cscope,再把/cscope-15.6/contrib/xcscope目录下的xcscope.el加载到emacs中去:
(add-to-list 'load-path "~/software/cscope-15.6/contrib/xcscope")
(require 'xcscope)
之后先M-x !,然后cscope -b,之后就可以在源代码中进行跳转了。命令见cscope菜单
这里有篇讲怎么在emacs下安装和使用cscope的:
http://ann77.stu.cdut.edu.cn/EmacsCscope.html
5.gdb-many-window
   这个功能插件可以使emacs的调试界面像VC一样,有watch, stacktrace等窗口,真正实现图形化gdb.
下载:
http://www.inet.net.nz/~nickrob/multi-gud.el
http://www.inet.net.nz/~nickrob/multi-gdb-ui.el
设置.emacs:
(setq gdb-many-windows t)
;;...
(load-library "multi-gud.el")
(load-library "multi-gdb-ui.el")
在emacs中编译好程序,然后M-x gdb,连按两次ret,多窗口gdb就出来了
还不行的看详细官方教程:
http://www.inet.net.nz/
一遍使用gdb-ui的教程:
http://blog.chinaunix.net/u/5958/showart_137996.html

6.行号
见:
http://ann77.stu.cdut.edu.cn/EmacsDisplayLineNumber.html
然后在.emacs里加上:
(add-to-list 'load-path "~/backup/emacs") ;;这行根据你放el文件的地方改
(require 'display-line-number)
(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)
这个感觉比setnu.el那个好用,setnu.el有时候行号会乱掉的。
7.缩进
emacs的缩进方式和其它编辑器有些不同,text-mode下不能tab,只能用C-q tab才行。
c-mode或cc-mode下缩进只有2格,这个当然不符合大多数人的习惯,如果要设为4:
(add-hook 'c-mode-hook
          '(lambda ()
             (c-set-style "Stroustrup")))
如果要设成8:
options->Customize Emacs->Browse Customization Group->Programming->Language->C->C-Basic-offset,设成8就行,保存

主要参考文献:
Emacs安装一个扩展包的方法
http://ann77.stu.cdut.edu.cn/EmacsInstallPackege.html
一个比较全的.emacs配置文件:
http://www.cppblog.com/guangping/archive/2006/08/25/11683.html
在emacs下用c/c++编程
http://www.caole.net/diary/emacs_write_cpp.html

我的.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-新宋体-normal-r-normal-normal-14-*-96-96-c-*-gb2312")
;; Load CEDET
(load-file "~/software/cedet-1.0pre4/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 "~/backup/emacs")
(require 'gud)
(require 'display-line-number)
(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.32")
;;(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.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)


               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/17420/showart_384371.html
  发表评论 查看评论(共有条评论) 我要提问
 
 


最新资讯更多>> 
· 金山卫士开源计划首周源码下载..
· 谷歌劝说诺基亚采用Android操作..
· 11月份Linux市场占有率升至5%
· Apache 基金会确认退出 JCP 执..
· Chrome 10 新功能探秘:新增GP..
· 金山宣布开源其安全软件
· 开源FTP服务器ProFTPD发现后门
· 女黑客在开源会议上抱受骚扰
· 21款值得关注的Linux游戏
· 马化腾:腾讯半年后彻底转型,..
论坛热点更多>> 
· Linux系统移植从零开始!参与..
· 学习linux的意义在哪里
· 使用netfilter在哪能获取到原..
· 哥纠结了
· 一个在线读开源代码的工具,..
· 为什么我的目录下没有.cshrc..
· 初学linux从哪里开始
· linux 系统无法上网
· 新手安装UCenter 时总是出错..
· cacti添加主机显示的状态都是..
文档更新更多>> 
· 菜鸟入门三星ARM11嵌入式系统,是..
· 寻redhat 5.3 的中文手册 for ia64
· 请问redhat 5.3 企业版的用户手册..
· LINUX与UNIX SHELL编程指南(中文)
· 一些基本用户管理以及基本安装方法
· 菜鸟学习linux笔记与练习-----第..
· 菜鸟学习linux笔记与练习-----第..
· 服务器配置:Squid配置详解
· linux下u盘使用
· ubuntu dynamips 绑定网卡到虚拟机
 
关于我们 | 联系方式 | 广告合作 | 诚聘英才 | 网站地图 | 友情链接 | 免费注册

Copyright © 2001-2009 ChinaUnix.net All Rights Reserved

感谢所有关心和支持过ChinaUnix的朋友们

京ICP证:060528号