emacs配置(自动注释)

事先声明:我的这个配置只是菜鸟级别的,可以应付平时的c++编写了,由于本人也是初学所以有些地方配置还不是很完善,但是随着我后续学习的深入,我会不断更新我的博客,有什么需要交流的可以邮件我,谢谢,十分愿意接受前辈和牛人的指导。

我的系统是:ubuntu 12.04LTS ,emacs 版本是:emacs 23.3.1

1.首先建议个为emacs的文件夹在主文件夹下。

2.下载一些需要用到的软件包,我都已经打包好了(你下载后直接解压就可以了),地址是:百度网盘,用户名是:zhaopin_hospital@163.com,密码是:123qwe(请不要随意更改里面的内容,谢谢)下载结束后直接解压到emacs文件夹下即可。

3.在打开终端的那个目录下,加你一个.emacs的文件,具体的运行命令:gedit .emacs  

不要忘了在emacs前面有个.的符号。然后在里面粘贴我下面的一些代码即可。

;;(add-to-list 'load-path "~/emacs/cedet-1.0.1/common/")
;;(require 'cedet)
;;(require 'semantic-ia)


(add-hook 'texinfo-mode-hook (lambda () (require 'sb-texinfo)))
     (load-file "~/emacs/cedet-1.0.1/common/cedet.el")
     (semantic-load-enable-code-helpers)
     (autoload 'speedbar-frame-mode "speedbar" "Popup a speedbar frame" t)
     (autoload 'speedbar-get-focus "speedbar" "Jump to speedbar frame" t)
     (define-key-after (lookup-key global-map [menu-bar tools])
                [speedbar]
                '("Speedbar" .
                speedbar-frame-mode)
                [calendar])




(add-to-list 'load-path "~/emacs/site-lisp/ecb-2.40")
(require 'ecb)
;;;(load -file "~/emacs/site-lisp/ecb-2.40/ecb.el")
(add-to-list 'load-path "~/emacs/site-lisp/")
;;;设置主题,需要下载.el的文件
(require 'color-theme)
(color-theme-classic)
;;;当你再次打开emacs的时候还会显示你上次所编辑的文件
(require 'session)
(add-hook 'after-init-hook 'session-initialize)
(load "desktop")
(desktop-save-mode)
;;;显示行号
(require 'display-line-number)
(setq display-line-number-format "%3d ")
(add-hook 'c-mode-hook 'display-line-number-mode)
(add-hook 'c++-mode-hook 'display-line-number-mode)
;;;阅读代码
(require 'xcscope)
;;;cscope的主要功能与用法如下:
;; C-c s a             设定初始化的目录,一般是你代码的根目录
;; C-s s I             对目录中的相关文件建立列表并进行索引
;; C-c s s             序找符号
;; C-c s g             寻找全局的定义
;; C-c s c             看看指定函数被哪些函数所调用
;; C-c s C             看看指定函数调用了哪些函数
;; C-c s e             寻找正则表达式
;; C-c s f             寻找文件
;; C-c s i             看看指定的文件被哪些文件include)




(setq ecb-auto-activate t
          ecb-tip-of-the-day nil
          ecb-tree-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
;;;cc-mode配置  http://cc-mode.sourceforge.net/
(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)
;;;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 [(f7)] '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)
;;;;我的C++语言编辑策略
(defun my-c++-mode-hook())
(setq tab-width 4 indent-tabs-mode nil)
(add-hook 'c++-mode-hook
'(lambda()
(c-set-style "stroustrup")))
;;(define-key c++-mode-map [f3] 'replace-regexp)

;;;配置semantic的检索范围
(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)
;;;hippie的自动补齐策略,优先调用了senator的分析结果
(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
        )
)
;;;cedet中还有一个比较不错的工具speedbar,你可以用它在多个文件中快速切换。
(global-set-key [(f5)] 'speedbar)

;;;输入左边的括号就会补全右边的部分
(defun my-c-mode-auto-pair ()
  (interactive)
  (make-local-variable 'skeleton-pair-alist)
  (setq skeleton-pair-alist  '(
    (?` ?` _ "''")
    (?\( ?  _ " )")
    (?\[ ?  _ " ]")
    (?{ \n > _ \n ?} >)))
  (setq skeleton-pair t)
  (local-set-key (kbd "(") 'skeleton-pair-insert-maybe)
  (local-set-key (kbd "{") 'skeleton-pair-insert-maybe)
  (local-set-key (kbd "`") 'skeleton-pair-insert-maybe)
  (local-set-key (kbd "[") 'skeleton-pair-insert-maybe))
(add-hook 'c-mode-hook 'my-c-mode-auto-pair)
(add-hook 'c++-mode-hook 'my-c-mode-auto-pair)
;;;语法加亮
(setq global-font-lock-mode t)





;;Enable EDE (Project Management) features,ede用来管理project工具
(global-ede-mode t)
;;代码折叠
(require 'semantic-tag-folding nil 'noerror)
(global-semantic-tag-folding-mode 1)
;;可视化书签
(enable-visual-studio-bookmarks)
;;颜色定制
(set-background-color "black") ;; 使用黑色背景
(set-foreground-color "white") ;; 使用白色前景
 
(set-face-foreground 'region "red")  ;; 区域前景颜色设为红色
(set-face-background 'region "blue") ;; 区域背景色设为蓝色


(semantic-load-enable-minimum-features)
(semantic-load-enable-code-helpers)
(semantic-load-enable-guady-code-helpers)
(semantic-load-enable-excessive-code-helpers)
(semantic-load-enable-semantic-debugging-helpers)
 
;; Enable SRecode (Template management) minor-mode.
(global-srecode-minor-mode 1)


(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.40")
 '(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.
 )


;;;字体
;; Fonts setting
;; 设置两个字体变量,一个中文的一个英文的
;; 之所以两个字体大小是因为有的中文和英文相同字号的显示大小不一样,需要手动调整一下。
(setq cjk-font-size 36)
(setq ansi-font-size 16)

;; 设置一个字体集,用的是create-fontset-from-fontset-spec内置函数
;; 中文一个字体,英文一个字体混编。显示效果很好。
(defun set-font()
  (interactive)
  (create-fontset-from-fontset-spec
   (concat
    "-*-fixed-medium-r-normal-*-*-*-*-*-*-*-fontset-myfontset," 
    (format "ascii:-outline-Consolas-normal-normal-normal-mono-%d-*-*-*-c-*-iso8859-1," ansi-font-size)
    (format "unicode:-microsoft-Microsoft YaHei-normal-normal-normal-*-%d-*-*-*-*-0-iso8859-1," cjk-font-size)
    (format "chinese-gb2312:-microsoft-Microsoft YaHei-normal-normal-normal-*-%d-*-*-*-*-0-iso8859-1," cjk-font-size)
    ;; (format "unicode:-outline-文泉驿等宽微米黑-normal-normal-normal-sans-*-*-*-*-p-*-gb2312.1980-0," cjk-font-size)
    ;; (format "chinese-gb2312:-outline-文泉驿等宽微米黑-normal-normal-normal-sans-*-*-*-*-p-*-gb2312.1980-0," cjk-font-size)
    )))

;; 函数字体增大,每次增加2个字号,最大48号
(defun increase-font-size()
  "increase font size"
  (interactive)
  (if (< cjk-font-size 48)
      (progn
        (setq cjk-font-size (+ cjk-font-size 2))
        (setq ansi-font-size (+ ansi-font-size 2))))
  (message "cjk-size:%d pt, ansi-size:%d pt" cjk-font-size ansi-font-size)
  (set-font)
  (sit-for .5))

;; 函数字体增大,每次减小2个字号,最小2号
(defun decrease-font-size()
  "decrease font size"
  (interactive)
  (if (> cjk-font-size 2)
      (progn 
        (setq cjk-font-size (- cjk-font-size 2))
        (setq ansi-font-size (- ansi-font-size 2))))
  (message "cjk-size:%d pt, ansi-size:%d pt" cjk-font-size ansi-font-size)
  (set-font)
  (sit-for .5))

;; 恢复成默认大小16号
(defun default-font-size()
  "default font size"
  (interactive)
  (setq cjk-font-size 16)
  (setq ansi-font-size 16)
  (message "cjk-size:%d pt, ansi-size:%d pt" cjk-font-size ansi-font-size)
  (set-font)
  (sit-for .5))

;; 只在GUI情况下应用字体。Console时保持终端字体。
(if window-system
    (progn
      (set-font)
      ;; 把上面的字体集设置成默认字体
      ;; 这个字体名使用是create-fontset-from-fontset-spec函数的第一行的最后两个字段
      (set-frame-font "fontset-myfontset")

      ;; 鼠标快捷键绑定
      (global-set-key '[C-wheel-up] 'increase-font-size)
      (global-set-key '[C-wheel-down] 'decrease-font-size)
      ;; 键盘快捷键绑定
      (global-set-key (kbd "C--") 'decrease-font-size) ;Ctrl+-
      (global-set-key (kbd "C-0") 'default-font-size)  ;Ctrl+0
      (global-set-key (kbd "C-=") 'increase-font-size) ;Ctrl+=
      ))

然后重新打开你的emacs,看看是不是跟我的这个一样了?


转载于:https://my.oschina.net/u/251931/blog/63336

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值