emacs配置(自動註釋)

事先聲明:個人這個配置只是菜鳥級別的,能夠應付平時的c++編寫了,因爲本人也是初學因此有些地方配置還不是很完善,可是隨着我後續學習的深刻,我會不斷更新個人博客,有什麼須要交流的能夠郵件我,謝謝,十分願意接受前輩和牛人的指導。c++

個人系統是:ubuntu 12.04LTS ,emacs 版本是:emacs 23.3.1正則表達式

1.首先建議個爲emacs的文件夾在主文件夾下。ubuntu

2.下載一些須要用到的軟件包,我都已經打包好了(你下載後直接解壓就能夠了),地址是:百度網盤,用戶名是:zhaopin_hospital@163.com,密碼是:123qwe(請不要隨意更改裏面的內容,謝謝)下載結束後直接解壓到emacs文件夾下便可。windows

3.在打開終端的那個目錄下,加你一個.emacs的文件,具體的運行命令:gedit .emacs  session

不要忘了在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,看看是否是跟個人這個同樣了?工具

相關文章
相關標籤/搜索