;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; a simple config of .emacs
;; File:.emacs
;; Author: shiwenqiang
;; Version: 0.1
;; Date: 2015.8.22
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; default to better frame titles
;; 设置frame 的标题
(setq frame-title-format
(concat "%b - emacs@" (system-name)))
;;环境变量
(setenv "HOME" "D:\DevTool\emacs-24.3")
(setenv "PATH" "D:\DevTool\emacs-24.3")
;;disable tool-bar
(tool-bar-mode 0)
;;enable menu-bar
(menu-bar-mode t)
;;display line num
(global-linum-mode t)
;;display column num
(setq column-number-mode t)
;;disable scroll stripe
(scroll-bar-mode 0)
;;display time
(display-time-mode t)
(setq display-time-24hr-format t)
(setq display-time-day-and-date t)
;; 设置桌面会话保存
(load "desktop")
(setq desktop-save-mode t)
(setq desktop-read t)
;;auto-load file which has changed
(global-auto-revert-mode 1)
;;set color theme
(set-background-color "gray14")
(set-foreground-color "gray99")
;; 回车缩进
(global-set-key "\C-m" 'newline-and-indent)
(global-set-key (kbd "C-<return>") 'newline)
;; 设置缩进【重点推荐这里的linux C编码风格及4空格替换TAB】
(setq c-default-style "linux"
c-basic-offset 4)
(setq-default indent-tabs-mode nil)
(setq default-tab-width 4)
(setq tab-width 4)
(setq tab-stop-list ())
;;emacs和外部程序的粘贴
(setq x-select-enable-clipboard t)
;; 默认显示 80列就换行
(setq default-fill-column 80)
;; 加载xcscope,如果有的话
(add-to-list 'load-path' "~/.emacs.d/auto-load/xcscope")
(require 'xcscope)
;; set new method of kill a whole line
;; 改造后的C-w ,在未选中目标时,剪切当前行
(defadvice kill-ring-save (before slickcopy activate compile)
"When called interactively with no active region, copy a single line instead."
(interactive
(if mark-active (list (region-beginning) (region-end))
(list (line-beginning-position)
(line-beginning-position 2)))))
;; 改造后的M-w , 在未选中目标时,复制当前行
(defadvice kill-region (before slickcut activate compile)
"When called interactively with no active region, kill a single line instead."
(interactive
(if mark-active (list (region-beginning) (region-end))
(list (line-beginning-position)
(line-beginning-position 2)))))
;;分别设置中英字体,在windows下经常因为中英文字体问题导致emacs异常卡顿,按照如下分别设置即可解决。
;;English-Font
(set-face-attribute
'default nil :font "Courier New 15")
;;中文字体
(dolist (charset '(kana han symbol cjk-misc bopomofo))
(set-fontset-font (frame-parameter nil 'font)
charset
(font-spec :family "Microsoft Yahei" :size 16)))
;; 这里定义的是全局的cscope快捷键映射,不区分任何语言模式,全部起效。
;;(define-key global-map [(control f3)] 'cscope-set-initial-directory)
;;(define-key global-map [(control f4)] 'cscope-unset-initial-directory)
;;(define-key global-map [(control f5)] 'cscope-find-this-symbol)
;;(define-key global-map [(control f6)] 'cscope-find-global-definition)
;;(define-key global-map [(control f7)] 'cscope-find-global-definition-no-prompting)
;;(define-key global-map [(control f8)] 'cscope-pop-mark)
;;(define-key global-map [(control f9)] 'cscope-next-symbol)
;;(define-key global-map [(control f10)] 'cscope-next-file)
;;(define-key global-map [(control f11)] 'cscope-prev-symbol)
;;(define-key global-map [(control f12)] 'cscope-prev-file)
;;(define-key global-map [(meta f9)] 'cscope-display-buffer
;;(define-key global-map [(meta f10)] 'cscope-display-buffer-toggle)
;;
这里是博主的.emacs 文件内容。主要解决如下紧密关联的三个问题:
1.tab与4个whitespace替换,及4whitespace 缩进。
2.cscope配置起效。这里要特别注意下,之前博主一直希望的编程风格时linuxC, 且tab由4whitespace替换。而在使用参考了王垠、ann77的主页等拷贝过来的代码:“defconst my-c-style”,之后(defun my-c-mode-common-hook (),再(add-hook 'c-mode-common-hook 'my-c-mode-common-hook),以期望cscope在C语言时起效,然而本博主尝试多次此种配置cscope在C源文件编辑时并不能起效,二者TM不可兼得!(即在menu上没有显示Cscope这一栏,虽然M-x + cscope-cmd-string仍然可以干活.),或者说没有正确配置?后无奈不得不删掉这部分代码,在emacswiki上意外发现下面解决的问题3的方式,轻松解决该需求,cscope正常起效!
3.emacs linux C代码风格。 其他风格还有:
- “
gnu
”: The default style for GNU projects - “
k&r
”: What Kernighan and Ritchie, the authors of C used in their book - “
bsd
”: What BSD developers use, aka “Allman style” after Eric Allman. - “
whitesmith
”: Popularized by the examples that came with Whitesmiths C, an early commercial C compiler. - “
stroustrup
”: What Stroustrup, the author of C++ used in his book - “
ellemtel
”: Popular C++ coding standards as defined by “Programming in C++, Rules and Recommendations,” Erik Nyquist and Mats Henricson, Ellemtel - “
linux
”: What the Linux developers use for kernel development - “
python
”: What Python developers use for extension modules - “
java
”: The default style for java-mode (see below) - “
user
”: When you want to define your own style