代码: 全选
;在窗口环境中设定字体
(if window-system
(progn
(set-default-font "DejaVu Sans Mono-13")
(add-to-list 'default-frame-alist '(font . "DejaVu Sans Mono-13"))
(set-fontset-font (frame-parameter nil 'font) 'han
'("Microsoft YaHei" . "unicode-bmp"))))
;(setq semantic-idle-scheduler-idle-time 432000) ;workaround for ecb
(setq abbrev-file-name "~/.emacs.d/abbrev-def.el") ;缩写(abbrev)的定义文件
(setq default-indicate-empty-lines 't) ;显示文件末尾的空行
(setq visible-bell 't) ;用闪屏代替振铃
(menu-bar-mode -1) ;关掉菜单条
(tool-bar-mode -1) ;关掉工具栏
(mouse-wheel-mode 1) ;响应鼠标滚轮
(blink-cursor-mode 1) ;光标闪烁
(transient-mark-mode nil) ;关掉临时标记
(ido-mode 1) ;好用的打开文件和切换buffer
(setq ido-ignore-buffers ;不需要切换到的buffer
'("\\` " "^\\*ESS\\*" "^\\*Messages\\*" "^\\*Help\\*" "^\\*Buffer"
"^\\*.*Completions\\*$" "^\\*Ediff" "^\\*tramp" "^\\*cvs-"
"_region_" " output\\*$" "^TAGS$" "^\*Ido")
ido-ignore-directories ;不需要打开的目录
'("\\`auto/" "\\.prv/" "\\`CVS/" "\\`\\.\\./" "\\`\\./")
ido-ignore-files ;不需要打开的文件
'("\\`auto/" "\\.prv/" "_region_" "\\`CVS/" "\\`#" "\\`.#" "\\`\\.\\./" "\\`\\./"))
(define-key ido-file-dir-completion-map [remap set-mark-command] 'ido-restrict-to-matches)
(if (fboundp 'ibuffer) ;ibuffer代替buffer菜单
(global-set-key (kbd "C-x C-b") 'ibuffer))
(set-scroll-bar-mode nil) ;关掉滚动条
(setq require-final-newline 't) ;自动提示文件结尾的空行
(global-font-lock-mode 1 't) ;彩色
(setq font-lock-maximum-decoration 't)
(show-paren-mode 't) ;括号配对显示
(setq compilation-window-height 16) ;编译窗口的大小
(temp-buffer-resize-mode 1) ;临时窗口会自动调整大小
(setq temp-buffer-max-height ;临时窗口的最大限制
(lambda (buffer)
(min 20 (/ (- (frame-height) 2) 2))))
(fset 'yes-or-no-p 'y-or-n-p) ;按y/n代替yes/no
;; show more info in taskbar/icon than just "Emacs"
;;(setq-default frame-title-format (list "%F %b"))
(setq-default frame-title-format (list "Emacs")) ;标题栏只显示Emacs
(setq tramp-default-method "ssh") ;tramp远程访问默认用ssh
(setq-default ispell-program-name "aspell");拼写检查程序是aspell
(defun toggle-variable (var) ;切换(开关)变量的函数
"toggles boolean variable"
(interactive "vToggle variable: ")
(set var (not (symbol-value var)))
(message "%s set to %s" var (symbol-value var))
)
;一些常用功能的热键定义
(global-set-key (kbd "C-`") 'set-mark-command);因为C-SPC被输入法用了
(global-set-key (kbd "C-;") 'set-mark-command)
(global-set-key [f1] 'ispell-word) ;拼写检查
(global-set-key [(shift f1)] 'ispell-region)
(global-set-key [(ctrl f1)] 'ispell)
(global-set-key [f2] 'menu-bar-mode) ;切换界面元素
(global-set-key [(shift f2)] 'speedbar)
(global-set-key [(ctrl f2)] 'tool-bar-mode)
(global-set-key [(shift ctrl f2)] 'scroll-bar-mode)
;; F3 and F4 for macros
(global-set-key [f5] 'grep) ;文件查找
(global-set-key [(shift f5)] 'rgrep)
(global-set-key [(ctrl f5)] 'occur)
(global-set-key [(shift ctrl f5)] 'multi-occur-in-matching-buffers)
(global-set-key [f6] 'gud-up) ;调试程序用
(global-set-key [(shift f6)] 'gud-down)
(global-set-key [f7] 'gud-step)
(global-set-key [(shift f7)] 'gud-stepi)
(global-set-key [f8] 'gud-next)
(global-set-key [(shift f8)] 'gud-finish)
(global-set-key [(ctrl f8)] 'gud-until)
(global-set-key [f9] 'humble-recompile) ;编译(见下面)
(global-set-key [(shift f9)] 'compile)
(global-set-key [f10] 'humble-gud) ;调试(见下面)
;切换一些小模式
(global-set-key (kbd "C-=") 'abbrev-mode) ;缩写自动补全
(global-set-key (kbd "C-x t a") 'abbrev-mode)
(global-set-key (kbd "C-x t c") 'highlight-changes-mode);高亮显示改变
(global-set-key (kbd "C-x t v") 'view-mode);只读
(global-set-key (kbd "C-x t f") 'auto-fill-mode);自动换行
(global-set-key (kbd "C-x t h") 'hs-minor-mode) ;hide-show
(defun toggle-show-trailing-whitespace ()
"Toggle show-trailing-whitespace"
(interactive)
(toggle-variable 'show-trailing-whitespace))
(global-set-key (kbd "C-x t s") 'toggle-show-trailing-whitespace);显示行尾的空白
(global-set-key (kbd "C-x t l") 'flyspell-mode);即时拼写检查
(global-set-key (kbd "C-x t k") 'flyspell-prog-mode);程序中的即时拼写检查(注释)
(global-set-key (kbd "C-x t o") 'outline-minor-mode);提纲模式
;isearch的时候用C-o调用occur列出所有match(新版本中是M-s o)
(define-key isearch-mode-map (kbd "C-o")
(lambda ()
(interactive)
(let ((case-fold-search isearch-case-fold-search))
(occur (if isearch-regexp isearch-string
(regexp-quote isearch-string))))))
(when (fboundp 'windmove-default-keybindings)
(windmove-default-keybindings)) ; shift+箭头 切换窗口
(setq load-path (append load-path (list "~/.emacs.d")))
;; 设定matlab-mode
(autoload 'matlab-mode "matlab" "Enter MATLAB mode." t)
(autoload 'matlab-shell "matlab" "Interactive MATLAB mode." t)
(setq matlab-indent-function t) ; if you want function bodies indented
(setq matlab-verify-on-save-flag nil) ; turn off auto-verify on save
(setq matlab-shell-command-switches '("-nojvm"))
(setq auto-mode-alist
(append
'(("\\.octave$" . octave-mode) ;octave script
("\\.m$" . matlab-mode) ;matlab file
;; ("\\.java$" . java-mode)
)
auto-mode-alist))
(ansi-color-for-comint-mode-on)
;谦虚的重新编译
(defun humble-recompile ()
"recompile if possible"
(interactive)
(if (fboundp 'recompile)
(recompile)
(call-interactively 'compile)))
;下面要用到的模式和调试命令的配对
(setq preferred-debugger-alist
'((c-mode . gdb)
(c++-mode . gdb)
(cperl-mode . perldb)
(jde-mode . jdb)
))
;谦虚的调试
(defun humble-gud ()
"gdb if not already running, otherwise bring to front"
(interactive)
(require 'gud)
(if (and (boundp 'gud-comint-buffer) ;find running gdb process
gud-comint-buffer
(buffer-name gud-comint-buffer)
(get-buffer-process gud-comint-buffer))
(if (fboundp 'gdb-restore-windows)
(gdb-restore-windows)
(pop-to-buffer gud-comint-buffer))
(call-interactively
(or (cdr (assq major-mode preferred-debugger-alist))
'gdb))))
;c/c++ 模式
(defun my-c-mode-common-hook ()
(define-key c-mode-base-map "\C-m" 'newline-and-indent);换行就缩进
(define-key c-mode-base-map (kbd "C-x t d") 'doxymacs-mode)
(define-key c-mode-base-map (kbd "C-x t w") 'cwarn-mode)
(setq c-electric-pound-behavior '(alignleft)) ;make a #define left-aligned
)
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
(add-hook 'text-mode-hook 'auto-fill-mode);文本模式自动换行
;; cperl-mode is preferred to perl-mode
(defalias 'perl-mode 'cperl-mode)
(add-hook 'cperl-mode-hook
(lambda ()
(define-key cperl-mode-map (kbd "C-h f") 'cperl-perldoc);查找函数
(define-key cperl-mode-map "\C-m" 'newline-and-indent)
(setq cperl-invalid-face nil)
(setq cperl-electric-parens nil);带电的括号 :)
(setq cperl-electric-keywords nil);和关键字
(setq cperl-indent-level 4)
(define-key cperl-mode-map (kbd "C-(");热键切换这两个功能
(lambda () "toggle electric parens"
(interactive)
(toggle-variable 'cperl-electric-parens)))
(define-key cperl-mode-map (kbd "C-)")
(lambda () "toggle electric keywords"
(interactive)
(toggle-variable 'cperl-electric-keywords)))
))
(add-hook 'gdb-mode-hook
(lambda ()
(setq gdb-many-windows 't) ;新的多窗口调试
(define-key gud-mode-map [f9] 'gdb-many-windows)
;;(setq gdb-use-separate-io-buffer 't)
;;(tool-bar-mode 't)
))
;auctex提供的latex模式
(add-hook 'LaTeX-mode-hook
(lambda ()
(define-key LaTeX-mode-map [f9] 'TeX-command-master);编译和查看
(define-key LaTeX-mode-map (kbd "C-x `") 'next-error)
(turn-on-reftex)
(setq reftex-plug-into-AUCTeX t)
(setq TeX-auto-save t)
(setq TeX-parse-self t)))
(load "tempo-def" t) ;调用模板定义文件
(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.
'(bold ((t (:bold t :foreground "SteelBlue1"))))
'(bold-italic ((t (:bold t :italic t :foreground "DarkKhaki"))))
'(cperl-array-face ((((class color) (background dark)) (:foreground "#CCCC30" :weight bold))))
'(cperl-hash-face ((((class color) (background dark)) (:foreground "#CC2020" :weight bold))))
'(ebrowse-root-class ((((min-colors 88)) (:foreground "lightblue3" :weight bold))))
'(fringe ((((class color) (background dark)) (:foreground "steelblue1"))))
'(header-line ((((class color grayscale) (background dark)) (:inherit mode-line :background "navy" :foreground "grey90" :box nil))))
'(info-node ((t (:italic t :foreground "salmon"))))
'(info-xref ((t (:foreground "DarkSalmon"))))
'(italic ((t (:italic t :foreground "orange1"))))
'(variable-pitch ((t (:family "Sans")))))
(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.
'(inhibit-startup-screen t))