;================全屏与最大化============================
(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.
;;)
Emacs C++ 编程环境设置
最新推荐文章于 2024-06-25 09:47:11 发布