我的.emacs文件,用于C/C++及shell编程。

1. [代码]我的.emacs文件,用于C/C++及shell编程。
;;我的配置
;;1.基本配置
;;外观配置***************
;;禁用启动画面
(setq inhibit-startup-message t)
 
;;设置字体大小 参考http://www.linuxsir.org/bbs/thread326299.html
(set-default-font "-unknown-DejaVu Sans Mono-normal-normal-normal-*-13-*-*-*-m-0-iso10646-1")
(add-to-list 'default-frame-alist '(font, "-unknown-DejaVu Sans Mono-normal-normal-normal-*-15-*-*-*-m-0-iso10646-1"))
 
;;设定启动时窗口大小
(setq default-frame-alist
'((height . 20) (width . 85) (top . 20) (left . 20) (menu-bar-lines . 0) (tool-bar-lines . 0)))
 
;;去掉工具栏
(tool-bar-mode nil)
 
;;去掉滚动条
(scroll-bar-mode nil)
 
;;键绑定****************
;;WIN+s进入shell
(global-set-key (kbd "s-s") 'shell)
 
;;缓冲区****************
;;设定行距
(setq default-line-spacing 4)
 
;;页宽
(setq default-fill-column 80)
 
;;缺省模式
(setq default-mojor-mode 'text-mode)
 
;;语法加亮
(global-font-lock-mode t)
 
;;高亮显示区域选择
(transient-mark-mode t)
 
;;页面平滑滚动
(setq scroll-margin 3
 scroll-conservatively 10000)
 
;;高亮显示成对括号,但不来回弹跳
(show-paren-mode t)
(setq show-paren-style 'parentheses)
 
;;鼠标指针规避光标
(mouse-avoidance-mode 'animate)
 
;;在标题栏提示目前我的位置
(setq frame-title-format "zym@%b")
 
;;状态栏******************
;;标题栏显示%f缓冲区完整路径%p页面百分数%l行号
(setq frame-title-format "%f")
 
;;编辑器设定***************
;;使用X剪贴板
(setq x-select-enable-clipboard t)
;;设定剪贴板内容格式 适应firefox
(set-clipboard-coding-system 'ctext)
 
;;其它设置****************
;;打开图片显示功能
(auto-image-file-mode t)
 
;;.颜色设置 参考http://www.nongnu.org/color-theme/
(add-to-list 'load-path' "/usr/share/emacs/23.1/site-lisp/emacs-goodies-el")
(require 'color-theme) ;导入主题
;(eval-after-load "color-theme"
;  '(progn
;   (color-theme-initialize)
;   (color-theme-hober)))
;(color-theme-initialize);初始化
;(load-file "/usr/share/emacs/23.1/lisp/color-theme.el")
(color-theme-calm-forest);选用的主题
(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-primary-secondary-mouse-buttons (quote mouse-1--mouse-2)))
(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.
 )
 
;;以下参考http://www.douban.com/group/topic/12115962/
;;退出gdb,term,compilation时关闭对应的buffer
;;关闭函数
(defun kill-buffer-when-shell-command-exit ()
"Close current buffer when `shell-command' exit."
(let ((process (ignore-errors (get-buffer-process (current-buffer)))))
(when process
(set-process-sentinel process
(lambda (proc change)
(when (string-match "\(finished\|exited\)" change)
(kill-buffer (process-buffer proc))))))))
 
(add-hook 'gdb-mode-hook 'kill-buffer-when-shell-command-exit)
(add-hook 'term-mode-hook 'kill-buffer-when-shell-command-exit)
(defun kill-buffer-when-compile-success (process)
"Close current buffer when `shell-command' exit."
(set-process-sentinel process
(lambda (proc change)
(when (string-match "finished" change)
(delete-windows-on (process-buffer proc))))))
;;编译成功后自动关闭"compilation* buffer
(add-hook 'compilation-start-hook 'kill-buffer-when-compile-success)
 
;;2.C/C++编程设置,参考:http://www.caole.net/diary/emacs_write_cpp.html
 
;;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)和自动新行
   ;;(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 [(f9)] 'compile)
   (define-key c-mode-base-map [(f10)] 'gdb)
   (define-key c-mode-base-map [(meta \`)] 'c-indent-command)
   ;;预处理设置
   (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)
)
 
;;C/C++语言编辑策略**********
(defun my-c-mode-common-hook()
   (setq tab-width 4 indent-tabs-mode nil)
   (setq c-basic-offset 4)
   (setq gdb-many-windows t)
   ;;饥饿删除(hungry-delete)和自动新行
   ;;(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 [(f3)] 'gdb-many-windows)
   (define-key c-mode-base-map [(f9)] 'compile)
   (define-key c-mode-base-map [(f10)] 'gdb)
   (define-key c-mode-base-map [(meta \`)] 'c-indent-command)
   ;;预处理设置
   (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)
 
;;gdb按键绑定 参考http://emacser.com/emacs-gdb.htm
(add-hook 'gdb-mode-hook '(lambda()
             (define-key c-mode-base-map [(f4)] 'gud-go)
             (define-key c-mode-base-map [(f5)] 'gud-next)
             (define-key c-mode-base-map [(f6)] 'gud-step)
             (define-key c-mode-base-map [(f7)] 'gud-finish)
             (define-key c-mode-base-map [(f8)] 'gud-until)))
 
;;C++语言编辑策略**********
(defun my-c++-mode-hook()
  (setq tab-width 4 indent-tabs-mode nil)
  (c-set-style "BSD")
)
 
;;自动补全设置*************
(add-to-list 'load-path "/usr/share/emacs/23.1/lisp/company"
"/usr/share/emacs/23.1/lisp/cedet-1.0/common") ;拓展文件(插件)目录
(load "/usr/share/emacs/23.1/lisp/cedet-1.0/common/cedet" nil t)
(autoload 'company-mode "company" nil t)
(setq company-idle-delay t)
 http://www.enterdesk.com/special/huangguantp/
;;semantic配置皇冠图片
(setq semanticdb-default-save-director "~/.emacs.d/semanticdb")
(semantic-load-enable-code-helpers)
(semantic-load-enable-gaudy-code-helpers)
 
;自动补全快捷键
(define-key c-mode-base-map (kbd "M-n") 'semantic-ia-complete-symbol-menu)
;代码跳转快捷键
(global-set-key [f12] 'semantic-ia-fast-jump)
;跳转后再跳回原来的地方
(global-set-key [f11]
      (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))))
;设置semantic检索范围
(setq semanticdb-project-roots
      (list
       (expand-file-name "/")))
;;设置semantic cache临时文件的路径
(setq semanticdb-default-save-directory "~/.emacs.d/")
;;避免semantic占用CPU过多
(setq-default semantic-idle-scheduler-idle-time 432000)
 
;;配置cscope
(require 'xcscope)
;;跳转到全局定义
(global-set-key "C-xg" 'cscope-find-global-definition-no-prompting)
 
;;配置ecb
(add-to-list 'load-path "/usr/share/emacs/23.1/site-lisp/ecb-2.40/")
;(load-file "/usr/share/emacs/23.1/site-lisp/ecb-2.40/ecb.el")
(require 'ecb)
(setq ecb-auto-activate nil
      ecb-tip-of-the-day nil
      ecb-free-indent 4
      ecb-windows-height 0.5
      ecb-windows-width 0.20)
ecb-auto-compatibility-check nil
ecb-version-check nil
inhibit-startup-message t