免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2433 | 回复: 1
打印 上一主题 下一主题

我的.emacs文件,用于C/C++及shell编程 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-01-14 11:30 |只看该作者 |倒序浏览
我的.emacs文件,用于C/C++及shell编程。参考了互联网上很多教程,在注释里都有网址。注意,有的设置还要下载相应的插件文件并复制到emacs安装目录相应位置,直接用可能会出错。
  1. ;;我的配置
  2. ;;1.基本配置
  3. ;;外观配置***************
  4. ;;禁用启动画面
  5. (setq inhibit-startup-message t)

  6. ;;设置字体大小 参考http://www.linuxsir.org/bbs/thread326299.html
  7. (set-default-font "-unknown-DejaVu Sans Mono-normal-normal-normal-*-13-*-*-*-m-0-iso10646-1")
  8. (add-to-list 'default-frame-alist '(font, "-unknown-DejaVu Sans Mono-normal-normal-normal-*-15-*-*-*-m-0-iso10646-1"))

  9. ;;设定启动时窗口大小
  10. (setq default-frame-alist
  11. '((height . 20) (width . 85) (top . 20) (left . 20) (menu-bar-lines . 0) (tool-bar-lines . 0)))

  12. ;;去掉工具栏
  13. (tool-bar-mode nil)

  14. ;;去掉滚动条
  15. (scroll-bar-mode nil)

  16. ;;键绑定****************
  17. ;;WIN+s进入shell
  18. (global-set-key (kbd "s-s") 'shell)

  19. ;;缓冲区****************
  20. ;;设定行距
  21. (setq default-line-spacing 4)

  22. ;;页宽
  23. (setq default-fill-column 80)

  24. ;;缺省模式
  25. (setq default-mojor-mode 'text-mode)

  26. ;;语法加亮
  27. (global-font-lock-mode t)

  28. ;;高亮显示区域选择
  29. (transient-mark-mode t)

  30. ;;页面平滑滚动
  31. (setq scroll-margin 3
  32. scroll-conservatively 10000)

  33. ;;高亮显示成对括号,但不来回弹跳
  34. (show-paren-mode t)
  35. (setq show-paren-style 'parentheses)

  36. ;;鼠标指针规避光标
  37. (mouse-avoidance-mode 'animate)

  38. ;;在标题栏提示目前我的位置
  39. (setq frame-title-format "zym@%b")

  40. ;;状态栏******************
  41. ;;标题栏显示%f缓冲区完整路径%p页面百分数%l行号
  42. (setq frame-title-format "%f")

  43. ;;编辑器设定***************
  44. ;;使用X剪贴板
  45. (setq x-select-enable-clipboard t)
  46. ;;设定剪贴板内容格式 适应firefox
  47. (set-clipboard-coding-system 'ctext)

  48. ;;其它设置****************
  49. ;;打开图片显示功能
  50. (auto-image-file-mode t)

  51. ;;.颜色设置 参考http://www.nongnu.org/color-theme/
  52. (add-to-list 'load-path' "/usr/share/emacs/23.1/site-lisp/emacs-goodies-el")
  53. (require 'color-theme) ;导入主题
  54. ;(eval-after-load "color-theme"
  55. ;  '(progn
  56. ;   (color-theme-initialize)
  57. ;   (color-theme-hober)))
  58. ;(color-theme-initialize);初始化
  59. ;(load-file "/usr/share/emacs/23.1/lisp/color-theme.el")
  60. (color-theme-calm-forest);选用的主题
  61. (custom-set-variables
  62.   ;; custom-set-variables was added by Custom.
  63.   ;; If you edit it by hand, you could mess it up, so be careful.
  64.   ;; Your init file should contain only one such instance.
  65.   ;; If there is more than one, they won't work right.
  66. '(ecb-primary-secondary-mouse-buttons (quote mouse-1--mouse-2)))
  67. (custom-set-faces
  68.   ;; custom-set-faces was added by Custom.
  69.   ;; If you edit it by hand, you could mess it up, so be careful.
  70.   ;; Your init file should contain only one such instance.
  71.   ;; If there is more than one, they won't work right.
  72. )

  73. ;;以下参考http://www.douban.com/group/topic/12115962/
  74. ;;退出gdb,term,compilation时关闭对应的buffer
  75. ;;关闭函数
  76. (defun kill-buffer-when-shell-command-exit ()
  77. "Close current buffer when `shell-command' exit."
  78. (let ((process (ignore-errors (get-buffer-process (current-buffer)))))
  79. (when process
  80. (set-process-sentinel process
  81. (lambda (proc change)
  82. (when (string-match "\\(finished\\|exited\\)" change)
  83. (kill-buffer (process-buffer proc))))))))

  84. (add-hook 'gdb-mode-hook 'kill-buffer-when-shell-command-exit)  
  85. (add-hook 'term-mode-hook 'kill-buffer-when-shell-command-exit)
  86. (defun kill-buffer-when-compile-success (process)
  87. "Close current buffer when `shell-command' exit."
  88. (set-process-sentinel process
  89. (lambda (proc change)
  90. (when (string-match "finished" change)
  91. (delete-windows-on (process-buffer proc))))))
  92. ;;编译成功后自动关闭"compilation* buffer
  93. (add-hook 'compilation-start-hook 'kill-buffer-when-compile-success)

  94. ;;2.C/C++编程设置,参考:http://www.caole.net/diary/emacs_write_cpp.html

  95. ;;CC-mode配置***************
  96. (require 'cc-mode)
  97. (c-set-offset 'inline-open 0)
  98. (c-set-offset 'friend '-)
  99. (c-set-offset 'substatement-open 0)

  100. ;;C/C++语言编辑策略**********
  101. (defun my-c-mode-common-hook()
  102.    (setq tab-width 4 indent-tabs-mode nil)
  103.    (setq c-basic-offset 4)
  104.    ;;饥饿删除(hungry-delete)和自动新行
  105.    ;;(c-toggle-auto-hungry-state 1)
  106.    ;;按键定义
  107.    (define-key c-mode-base-map [(control \`)] 'hs-toggle-hiding)
  108.    (define-key c-mode-base-map [(return)] 'newline-and-indent)
  109.    (define-key c-mode-base-map [(f9)] 'compile)
  110.    (define-key c-mode-base-map [(f10)] 'gdb)
  111.    (define-key c-mode-base-map [(meta \`)] 'c-indent-command)
  112.    ;;预处理设置
  113.    (setq c-macro-shrink-window-flag t)
  114.    (setq c-macro-preprocessor "cpp")
  115.    (setq c-macro-cppflags " ")
  116.    (setq c-macro-prompt-flag t)
  117.    (setq hs-minor-mode t)
  118.    (setq abbrev-mode t)
  119. )

  120. ;;C/C++语言编辑策略**********
  121. (defun my-c-mode-common-hook()
  122.    (setq tab-width 4 indent-tabs-mode nil)
  123.    (setq c-basic-offset 4)
  124.    (setq gdb-many-windows t)
  125.    ;;饥饿删除(hungry-delete)和自动新行
  126.    ;;(c-toggle-auto-hungry-state 1)
  127.    ;;按键定义
  128.    (define-key c-mode-base-map [(control \`)] 'hs-toggle-hiding)
  129.    (define-key c-mode-base-map [(return)] 'newline-and-indent)
  130.    (define-key c-mode-base-map [(f3)] 'gdb-many-windows)
  131.    (define-key c-mode-base-map [(f9)] 'compile)
  132.    (define-key c-mode-base-map [(f10)] 'gdb)
  133.    (define-key c-mode-base-map [(meta \`)] 'c-indent-command)
  134.    ;;预处理设置
  135.    (setq c-macro-shrink-window-flag t)
  136.    (setq c-macro-preprocessor "cpp")
  137.    (setq c-macro-cppflags " ")
  138.    (setq c-macro-prompt-flag t)
  139.    (setq hs-minor-mode t)
  140.    (setq abbrev-mode t)
  141. )
  142. (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)

  143. ;;gdb按键绑定 参考http://emacser.com/emacs-gdb.htm
  144. (add-hook 'gdb-mode-hook '(lambda()
  145.                          (define-key c-mode-base-map [(f4)] 'gud-go)
  146.                          (define-key c-mode-base-map [(f5)] 'gud-next)
  147.                          (define-key c-mode-base-map [(f6)] 'gud-step)
  148.                          (define-key c-mode-base-map [(f7)] 'gud-finish)
  149.                          (define-key c-mode-base-map [(f8)] 'gud-until)))

  150. ;;C++语言编辑策略**********
  151. (defun my-c++-mode-hook()
  152.   (setq tab-width 4 indent-tabs-mode nil)
  153.   (c-set-style "BSD")
  154. )

  155. ;;自动补全设置*************
  156. (add-to-list 'load-path "/usr/share/emacs/23.1/lisp/company"
  157. "/usr/share/emacs/23.1/lisp/cedet-1.0/common") ;拓展文件(插件)目录
  158. (load "/usr/share/emacs/23.1/lisp/cedet-1.0/common/cedet" nil t)
  159. (autoload 'company-mode "company" nil t)
  160. (setq company-idle-delay t)

  161. ;;semantic配置
  162. (setq semanticdb-default-save-director "~/.emacs.d/semanticdb")
  163. (semantic-load-enable-code-helpers)
  164. (semantic-load-enable-gaudy-code-helpers)

  165. ;自动补全快捷键
  166. (define-key c-mode-base-map (kbd "M-n") 'semantic-ia-complete-symbol-menu)
  167. ;代码跳转快捷键
  168. (global-set-key [f12] 'semantic-ia-fast-jump)
  169. ;跳转后再跳回原来的地方
  170. (global-set-key [f11]
  171.       (lambda()
  172.         (interactive)
  173.         (if (ring-empty-p (oref semantic-mru-bookmark-ring ring))
  174.             (error "Semantic Bookmark ring is currently empty"))
  175.         (let* ((ring (oref semantic-mru-bookmark-ring ring))
  176.                (alist (semantic-mrub-ring-to-assoc-list ring))
  177.                (first (cdr (car alist))))
  178.         (if (semantic-equivalent-tag-p (oref first tag)
  179.                                        (semantic-current-tag))
  180.             (setq first (cdr (car (cdr alist)))))
  181.         (semantic-mrub-switch-tags first))))
  182. ;设置semantic检索范围
  183. (setq semanticdb-project-roots
  184.       (list
  185.        (expand-file-name "/")))
  186. ;;设置semantic cache临时文件的路径
  187. (setq semanticdb-default-save-directory "~/.emacs.d/")
  188. ;;避免semantic占用CPU过多
  189. (setq-default semantic-idle-scheduler-idle-time 432000)

  190. ;;配置cscope
  191. (require 'xcscope)
  192. ;;跳转到全局定义
  193. (global-set-key "\C-xg" 'cscope-find-global-definition-no-prompting)

  194. ;;配置ecb
  195. (add-to-list 'load-path "/usr/share/emacs/23.1/site-lisp/ecb-2.40/")
  196. ;(load-file "/usr/share/emacs/23.1/site-lisp/ecb-2.40/ecb.el")
  197. (require 'ecb)
  198. (setq ecb-auto-activate nil
  199.       ecb-tip-of-the-day nil
  200.       ecb-free-indent 4
  201.       ecb-windows-height 0.5
  202.       ecb-windows-width 0.20)
  203. ecb-auto-compatibility-check nil
  204. ecb-version-check nil
  205. inhibit-startup-message t
复制代码

论坛徽章:
0
2 [报告]
发表于 2011-01-14 11:52 |只看该作者
不怎么用emacs,只用vim
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP