Emacs配置小记录一下

说实话,配置emacs那可谓异常多的文章,也有一篇广为流传,几乎大家都是以那一篇为基础来作自己的配置。既然有现成的,肯定用这个来作小修该就好了~~

其实自己很久以前就已经配过,只不过弄好之后自己一直没怎么用。。。今天又拿出来写了下代码,所以就下决心把之前的没配好的小修该一下。

自己主要是针对c/c++来配。安装的话超简单,因为强大的Debian都会帮你准备好。直接apt-get install就行:emacs23,cscope,cedet,ecb,gbd。在~/.emacs里写个人配置,网上那些对插件add-to-list或者load的命令都不需要了,直接从require开始就好,这个就是用Debian源来安装的好处。

自己的几点体会:

1.不用主题

都说主题会导致启动慢,个人感觉个人喜好吧,反正肯定比你打开IDE的速度快很多。我自己是不用的,直接改以下配色就好。

黑底灰字或者黑底绿字是比较舒服的,蛮多人会选择不要工具栏,不要垂直滚动条,显示行/列号,关闭emacs启动的信息页,显示括号匹配。

2.C/C++编辑策略

这个参考网上某大神的:高亮、自动补全、候选列表,也是网上流传较广的一份。不过快捷键需要自己的需求分配好,毕竟有些网上的东拼西凑的东西会有冲突的。

配置.emacs文件特别有用的快捷键前缀是C-h,然后再按f,输入想查询的function就有帮助出来了。这里主要是用来查询LIST的函数。不明白别人配置这一行是什么意思的话,就好好用这个帮助,这样自己也知道这一句命令是干嘛的。

3.ECB和speedbar

这两个是很多同志的推荐:提供了四个小窗窗针对文件目录,变量和函数的显示;speedbar提供类似的功能。

主要问题是ecb启动时会提供蛋碎的帮助,say,每天提示和显示在buffer里的info。第一次使用,会提示保存设置到emacs的配置文件里,点save就好,然后发现~/.emacs的最后加了一段代码。完成这一步之后每次启动就会有个ecb info的buffer。不过帮助是个好东西,因为可以找到关掉他们的方法(`。`)。。。

给emacs配置文件里加上
(setq ecb-tip-of-the-day nil)
(setq ecb-help-info-start-file nil)

然后是ecb窗口大小的问题,因为大小是按百分比来设置的,所以改变emacs窗口时它也变。觉得不爽可以固定它的大小(setq ecb-fix-window-size t)

activate它的话用(ecb-activate),不过记得放在ecb的设置之后

PS:不过不知道什么原因,我emacs里面的ecb菜单里的设置,点开之后都是看不到的(弹出的空白的buffer)。。。用C-x输入ecb的setting也是看不到的,好像之前能看到的,现在不行了,不知道为什么。

----------------------------------

配置的选项多不胜数,选自己需要的就好。推荐几个别人的总结:

比较全的一个 http://blog.csdn.net/xljiulong/article/details/7829598

这个也比较具体,而且有针对gdb-many-windows的配置 http://blog.chinaunix.net/uid-24948934-id-59822.html

不过他们会有小错,还是需要自己慢慢尝试~

-----------------------------------

20/12/2012更新

4. 关于many windows

上面说到的一个有gdb-many-windows的配置好像不行,也有可能是自己的问题。

gdb-many-windows的命令在gdb被激活后才能用,而且gdb命令的默认打开方式是单窗口的,所以就不知道怎么能一键打开到多窗口的gdb

此外ecb与多窗口有冲突。

所以想要用多窗口就需要:关闭ecb,打开gdb,换到多窗口模式。

其实退出gdb也有个蛋疼的问题就是退出了buffer还会在。。。(这个网上有方法去掉)

尝试用kdb macro来录制操作,不过效果不太理想。

 

5. 关于编译快捷键

原来用的f8,然后把compile命令改成“g++ -g -o ”,用的时间长了有点烦。所以参照别人的分享,写了个自定义函数来添加文件名。

(defun mycom()
(interactive)
(compile
(concat "g++ -g -Wall "(buffer-name(current-buffer))" -o "(buffer-name(current-buffer))".out")
))

然后把原来的快捷键改为C-f8,把f8绑到mycom这个自定义函数来实现编译

 

-----------------------------------

 最后贴自己的简单配置

View Code
;;配色和窗口大小
(setq default-frame-alist
             '((top . 0)
               (left . 0)                             
               (width . 143)
               (height . 38)         
               (background-color . "black")
               (foreground-color . "grey")
               ;(cursor-color     . "gold1")
               ;(mouse-color      . "gold1")
               ;(tool-bar-lines . 0)
               ;(menu-bar-lines . 1)
               (vertical-scroll-bars)
               (right-fringe)
               (left-fringe)
              )
)
;;去掉工具栏
(tool-bar-mode nil)
;;去掉菜单栏
;(menu-bar-mode nil)
;;去掉滚动栏
;(scroll-bar-mode nil)
;;置背景颜色和字体颜色  
;(set-foreground-color "green")  
;(set-background-color "black")
;;显示列号
(column-number-mode t)
;;显示行号
(global-linum-mode t)
;;显示括号匹配
(show-paren-mode t)
;;显示时间,格式如下
(display-time-mode 1)
;;光标靠近鼠标指针时,让鼠标指针自动让开,别挡住视线。很好玩阿,这个功能
(mouse-avoidance-mode 'animate)
;;默认显示80列就换行
(setq default-fill-column 80)
;;在标题栏提示你目前在什么位置。你要把ethan改成自己的用户名
(setq frame-title-format "ethan@%b")
;;支持emacs和外部程序的粘贴
(setq x-select-enable-clipboard t)
;;关闭起动时的emacs帮助页
(setq inhibit-startup-message t)
;;键盘输入的编码方式 
;(set-keyboard-coding-system 'utf-8) 
;;读取或写入文件名的编码方式
;(setq file-name-coding-system 'utf-8) 
;;不产生备份
(setq backup-inhibited t)
;;不自动保存
;(setq auto-save-default nil)

;;;;cscope
;;直接安装的就不需要load path
;(load-file "/xxx/cscope-15.8a/contrib/xcscope/xcscope.el")
;;第一行加载xcscope,第二行只在打开c/c++才加载xcscope
(require 'xcscope)
(add-hook 'c-mode-common-hook '(lambda() (require 'xcscope)))
;;索引时不进行数据库的更新-速度优化
(setq cscope-do-not-update-database t)

;;;;cc-mode
(require 'cc-mode)
(c-set-offset 'inline-open 0)
(c-set-offset 'friend '-)
(c-set-offset 'substatement-open 0)

;;;; c/c++语言编辑策略
(defun my-c-mode-common-hook()
(setq tab-width 4 indent-tabs-mode nil)
;;换行后缩进空格数
(setq c-basic-offset 4)

;;; hungry-delete and auto-newline
(c-toggle-auto-hungry-state 1)
;;这个应该是用来注释的吧,不知道为什么用不了。可以用M-;代替
(define-key c-mode-base-map [(control \`)] 'hs-toggle-hiding)
;;回车->换行且自动对齐
(define-key c-mode-base-map [(return)] 'newline-and-indent)
;;设置C-F9为complie
(define-key c-mode-base-map [(control f9)] 'compile)
;;default是make -k,通过下一行修改为其他gcc or g++
(setq compile-command "g++ -g -Wall -o ")
;;定义F9为只能compile
(defun mycom()
(interactive)
(compile
(concat "g++ -g -Wall "(buffer-name(current-buffer))" -o "(buffer-name(current-buffer))".out")
))
(define-key c-mode-base-map [(f9)] 'mycom)
;;自动对齐(行头)
(define-key c-mode-base-map [(meta \`)] 'c-indent-command)
;;另一种补全方案hippie-expand
;;(define-key c-mode-base-map [(tab)] 'hippie-expand)
;;按Tab补全
(define-key c-mode-base-map [(tab)] 'my-indent-or-complete)
;;按M-/打开函数列表
(define-key c-mode-base-map [(meta ?/)] 'semantic-ia-complete-symbol-menu)
;;按F5打开speedbar
(global-set-key [(f5)] 'speedbar)


;;;预处理设置
(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)

;;;;C++编辑策略
(defun my-c++-mode-hook()
(setq tab-width 4 indent-tabs-mode nil)
(c-set-style "stroustrup")
;; (define-key c++-mode-map [f3] 'replace-regexp)
)


;;;;cedet
;(add-to-list 'load-path "/xxx/cedet-1.0/common")
;(add-to-list 'load-path "/xxx/cedet-1.0/semantic")
(require 'cedet)

;;;自动补全
(setq semanticdb-project-roots 
      (list
        (expand-file-name "/")))

(defun my-indent-or-complete ()
   (interactive)
   (if (looking-at "\\>")
      (hippie-expand nil)
      (indent-for-tab-command))
 )
(global-set-key [(control tab)] 'my-indent-or-complete)

(autoload 'senator-try-expand-semantic "senator")

(setq hippie-expand-try-functions-list
      '(
        senator-try-expand-semantic
        try-expand-dabbrev
        try-expand-dabbrev-visible
        try-expand-dabbrev-all-buffers
        try-expand-dabbrev-from-kill
        try-expand-list
        try-expand-list-all-buffers
        try-expand-line
        try-expand-line-all-buffers
        try-complete-file-name-partially
        try-complete-file-name
        try-expand-whole-kill
        )
)


;;;;ecb
;(add-to-list 'load-path "/xxx/site-lisp/ecb")
(require 'ecb)
;;ecb启动的时候会弹出一个每天提示,如果不想看到它,可以在emacs配置文件(~/.emacs)里加这一句:
(setq ecb-tip-of-the-day nil)
;;启动ecb后不显示帮助文件,first step blahblah
(setq ecb-help-info-start-file nil)
;;设置宽度
(setq ecb-windows-width 0.35)
;;固定ecb窗口大小
(setq ecb-fix-window-size t)

;;activate要放显示设置之后最后
(ecb-activate)
(global-set-key [f6] 'ecb-activate) ;;定义F6键为激活ecb
(global-set-key [f7] 'ecb-deactivate) ;;定义F7为停止ecb

;;打开GDB
(global-set-key [f8] 'gdb)


;;;; 各窗口间切换
(global-set-key [M-left] 'windmove-left)
(global-set-key [M-right] 'windmove-right)
(global-set-key [M-up] 'windmove-up)
(global-set-key [M-down] 'windmove-down)


;;;; ecb自动保存的设置
(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-options-version "2.32"))
(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.
 )

 

  

 

 

posted @ 2012-12-17 17:04  loveGlory  阅读(894)  评论(0编辑  收藏  举报