Emacs C++ 編程環境設置


;================全屏與最大化============================

(defun my-fullscreen ()

  (interactive)

  (x-send-client-message

   nil 0 nil "_NET_WM_STATE" 32

   '(2 "_NET_WM_STATE_FULLSCREEN" 0)))

 

(defun my-maximized-horz ()

  (interactive)

  (x-send-client-message

   nil 0 nil "_NET_WM_STATE" 32

   '(1 "_NET_WM_STATE_MAXIMIZED_HORZ" 0)))

(defun my-maximized-vert ()

  (interactive)

  (x-send-client-message

   nil 0 nil "_NET_WM_STATE" 32

   '(1 "_NET_WM_STATE_MAXIMIZED_VERT" 0)))

(defun my-maximized ()

  (interactive)

  (x-send-client-message

   nil 0 nil "_NET_WM_STATE" 32

   '(1 "_NET_WM_STATE_MAXIMIZED_HORZ" 0))

  (interactive)

  (x-send-client-message

   nil 0 nil "_NET_WM_STATE" 32

   '(1 "_NET_WM_STATE_MAXIMIZED_VERT" 0)))

(my-maximized)

;;設置tab標籤,在http://www-cdf.fnal.gov/~sthrlnd/emacs/tabbar.el下載tabbar.el,並複製到/usr/local/share/emacs/site-lisp/
;;(require 'tabbar)
;;(tabbar-mode)
;;(global-set-key (kbd "C-`") 'tabbar-backward)
;;(global-set-key (kbd "C-<tab>") 'tabbar-forward)
;;set-face-attribute 'tabbar-default-face nil :family "Tahoma")

;;========================語言環境設置=================================

 (set-language-environment 'Chinese-GB)

 (set-keyboard-coding-system 'utf-8)

 (set-clipboard-coding-system 'utf-8)

 (set-terminal-coding-system 'utf-8)

 (set-buffer-file-coding-system 'utf-8)

 (set-default-coding-systems 'utf-8)

 (set-selection-coding-system 'utf-8)

 (modify-coding-system-alist 'process "*" 'utf-8)

 (setq default-process-coding-system '(utf-8 . utf-8))

 (setq-default pathname-coding-system 'utf-8)

 (set-file-name-coding-system 'utf-8)

 (setq ansi-color-for-comint-mode t)

 

;;============================設置窗口界面===============================

(set-foreground-color "grey")

(set-background-color "black")

(set-cursor-color "gold1")

(set-mouse-color "gold1")

 

(set-face-foreground 'highlight "white")

(set-face-background 'highlight "blue")

(set-face-foreground 'region "cyan")

(set-face-background 'region "blue")

(set-face-foreground 'secondary-selection "skyblue")

(set-face-background 'secondary-selection "darkblue")

 

;;============================顯示時間=====================================

(display-time-mode 1)

(setq display-time-24hr-format t)

(setq display-time-day-and-date t)

(setq display-time-use-mail-icon t)

(setq display-time-interval 10)

 

;============================關閉啓動畫面==================================

(setq inhibit-startup-message t)

(setq gnus-inhibit-startup-message t)

;======================語法高亮顯示,不包含text和shell模式===============

(setq font-lock-maximum-decoration t)

(setq font-lock-global-modes '(not shell-mode text-mode))

(setq font-lock-verbose t)

(setq font-lock-maximum-size '((t . 1048576) (vm-mode . 5250000)))

;=======================顯示行號==========================================

(setq column-number-mode t)

(setq line-number-mode t)

;======================括號匹配,不回到下一個括號===================

(setq show-paren-mode t)

(setq show-paren-style 'parenthesis)

;=====================加載cedet,ecb,scscope=============================
;;(load-file "/usr/local/share/emacs/site-lisp/cedet-common/cedet.el")

(setq load-path (append load-path '("/usr/share/emacs/site-lisp/ecb")))

;(require 'ecb)

(require 'ecb-autoloads)

(require 'xcscope)

;============================GDB設置===================================

(setq load-path (append load-path '("/usr/share/emacs/site-lisp/gdb")))

(setq gdb-many-windows t)

(require 'gud)

;;for gdb-many-window mode

(load-library "multi-gud.el")

(load-library "multi-gdb-ui.el")

 

;===========================C語言設置爲k&r風格=============================

(add-hook 'c-mode-hook

'(lambda ()

(c-set-style "k&r")))

;==========================C++設置爲strousstrup風格===========================

(add-hook 'c++-mode-hook

'(lambda()

(c-set-style "stroustrup")))

;==========================代碼摺疊====================================

(load-library "hideshow")

(add-hook 'c-mode-hook 'hs-minor-mode)

(add-hook 'c++-mode-hook 'hs-minor-mode)

(add-hook 'java-mode-hook 'hs-minor-mode)

(add-hook 'perl-mode-hook 'hs-minor-mode)

(add-hook 'php-mode-hook 'hs-minor-mode)

(add-hook 'emacs-lisp-mode-hook 'hs-minor-mode)

;;這裏是用法

;;  M-x              hs-minor-mode

;;  C-c @ ESC C-s    show all

;;  C-c @ ESC C-h    hide all

;;  C-c @ C-s        show block

;;  C-c @ C-h        hide block

;;  C-c @ C-c toggle hide/show

;=========================輸入左括號,自動補齊括號中內容===================

(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)

;===================配置semantic的搜索範圍====================================

(semantic-load-enable-code-helpers)

(setq semantic-load-turn-everything-on t)

(add-hook 'semantic-init-hooks 'semantic-idle-completions-mode)

;======================配置semantic cache的路徑================================

(setq semanticdb-project-roots

        (list

        (expand-file-name "/")))

(setq semanticdb-default-save-directory "~/")

;===================綁定hippie-expand M-/====================================

(global-set-key [(meta ?/)] 'hippie-expand)

;=================設置hippie-expand的補齊方式,從上到下優先匹配==============

(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-complete-file-name-partially

    try-complete-file-name

    try-expand-all-abbrevs

    try-expand-list

    try-expand-line

    try-complete-lisp-symbol-partially

    try-complete-lisp-symbol))

;=======================CC-mode配置==============

(require 'cc-mode)

(c-set-offset 'inline-open 0)

(c-set-offset 'friend '-)

(c-set-offset 'substatement-open 0)

 

;;;;根據後綴判斷模式

;;;xxx .h關聯到C++模式

(setq auto-mode-alist

           (append '(("//.h$" . c++-mode)) auto-mode-alist))

 

;;;;C/C++語言編輯策略

;;設置縮進爲4字符,這裏的代碼格式是

;;void func(argv){

;;   ………

;;}

;;還沒搞清楚設置成左括號獨佔一行的設置

(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)

 

;(defun my-indent-or-complete ()

;  (interactive)

;  (if (looking-at "//>")

;      (hippie-expand nil)

;    (indent-for-tab-command)))

  ;;快捷鍵定義

  (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-map [(f7)] 'compile)
 

  (define-key c-mode-base-map [(f8)] 'ff-get-other-file)

  (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)

(global-set-key [(f4)] 'speedbar-get-focus)

(global-set-key [(f12)] 'ecb-activate)

 

  ;;預處理設置

 (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)

  (setq tab-width 4 indent-tabs-mode nil)

)

(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)

)

 

(add-hook 'c++-mode-hook 'my-c++-mode-hook)

;;C++啓動時自動加載semantic對/usr/include的索引數據庫

(setq semanticdb-search-system-databases t)

  (add-hook 'c-mode-common-hook

          (lambda ()

            (setq semanticdb-project-system-databases

                  (list (semanticdb-create-database

                           semanticdb-new-database-class

                           "/usr/include")))))

;;(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.

 ;;)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章