1.Mac版的emacs配置
(custom-set-variables
'(show-paren-mode t))
(custom-set-faces
'(default ((t (:family "Andale Mono" :foundry "monotype" :slant normal :weight normal :height 113 :width normal)))))
;;Load site-lisp
(add-to-list 'load-path "~/.emacs.d/site-lisp")
;;去掉启动界面
(setq inhibit-startup-message t)
;;打开文件默认只读模式
(defun read-only-setup () (read-only-mode))
(add-hook 'find-file-hook #'read-only-setup)
;;cflow
(require 'cflow-mode)
;;显示行号
(add-to-list 'load-path "/usr/share/emacs/site-lisp")
(require 'linum)
(global-linum-mode t)
(setq column-number-mode t);显示列号
(global-set-key [f3] 'find-name-dired)
(global-set-key [(f4)] 'grep-find)
(global-set-key [f5] 'compile)
(global-set-key [(f6)] 'replace-regexp)
;;显示括号匹配, 而不是匹配后短暂的跳到另一个括号
(show-paren-mode t)
(setq show-paren-style 'parentheses)
;; ;;让Emacs可以直接打开和显示图片。
(setq auto-image-file-mode t)
;; ;打开压缩文件时自动解压缩。
(auto-compression-mode 1)
;; ;自动保存模式
;;(setq auto-save-mode t)
;; ;;不生成临时文件
(setq-default make-backup-files nil)
;; ;;exit shell后,buffer自动关闭
(add-hook 'shell-mode-hook 'wcy-shell-mode-hook-func)
(global-set-key (kbd "C-j") 'goto-line)
;; ;;窗口全屏
(global-set-key [f11] 'my-fullscreen)
(defun my-fullscreen ()
(interactive)
(x-send-client-message
nil 0 nil "_NET_WM_STATE" 32
'(2 "_NET_WM_STATE_FULLSCREEN" 0))
)
(global-set-key [f12] 'my-maximized)
(defun my-maximized ()
(interactive)
(x-send-client-message
nil 0 nil "_NET_WM_STATE" 32
'(2 "_NET_WM_STATE_MAXIMIZED_HORZ" 0))
(x-send-client-message
nil 0 nil "_NET_WM_STATE" 32
'(2 "_NET_WM_STATE_MAXIMIZED_VERT" 0))
)
;; 启动emacs时窗口最大化
;;(my-maximized)
;; ;;自动补全全部括号
(electric-pair-mode 1)
(setq electric-pair-pairs '(
(?\" . ?\")
(?\{ . ?\})
) )
;;切换输入法: Ctrl + \
;;自动补全
(add-to-list 'load-path "~/.emacs.d/modules")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict")
(ac-config-default)
;;支持emacs和外部程序的粘贴;仅对图形化emacs有效,对命令行无效
;;(setq x-select-enable-clipboard t)
;;(Mac有效)emacs共享剪贴板,支持emacs和外部程序的粘贴
(defun copy-from-osx ()
(shell-command-to-string "pbpaste"))
(defun paste-to-osx (text &optional push)
(let ((process-connection-type nil))
(let ((proc (start-process"pbcopy" "*Messages*" "pbcopy")))
(process-send-string proc text)
(process-send-eof proc))))
(setq interprogram-cut-function 'paste-to-osx)
(setq interprogram-paste-function 'copy-from-osx)
;;缩进和vs2008一样
(setq c-default-style
'((Java-mode . "java")(other . "awk")))
;; ;; 设置字体
;; ;; 方法为: emacs->options->Set Default Font->"M-x describe-font"查看当前使用的字体名称、字体大小
(set-default-font " -bitstream-Courier 10 Pitch-normal-normal-normal-*-15-*-*-*-m-0-iso10646-1")
;; ;; 设置默认tab宽度为2
(setq tab-width 2
indent-tabs-mode t
c-basic-offset 2)
;; ;;保存上次打开的文件记录
(desktop-save-mode t)
(load "desktop")
(desktop-load-default)
(desktop-read)
;;cscope
(require 'cc-mode)
(add-to-list 'load-path "~/.emacs.d/site-lisp")
(require 'xcscope)
;;但是如果工程十分庞大,即使是判断文件更新与否也很费时,可以告诉 Emacs 别自动更新 cscope.out:
(setq cscope-do-not-update-database t)
;;绑定快捷键
;;查找字符串
(global-set-key (kbd "M-1") 'cscope-find-egrep-pattern)
;;查找文件
(global-set-key (kbd "M-2") 'cscope-find-this-file)
;;创建索引
;;(define-key global-map [(M-3)] 'cscope-index-files)
(global-set-key (kbd "M-3") 'cscope-index-files)
;;查找调用
;;(define-key global-map [(control f4)] 'cscope-find-this-symbol)
(global-set-key (kbd "M-4") 'cscope-find-this-symbol)
;;查找定义
;;(define-key global-map [(control f5)] 'cscope-find-global-definition)
(global-set-key (kbd "M-5") 'cscope-find-global-definition)
;;回到查找函数
;;(define-key global-map [(control f6)] 'cscope-pop-mark)
;;(global-set-key (kbd "M-6") 'cscope-pop-mark)
;;prev symbol
(global-set-key (kbd "M-6") 'cscope-prev-symbol)
;;next symbol
(global-set-key (kbd "M-7") 'cscope-next-symbol)
;;(define-key global-map [(meta f9)] 'compile)
;; ;;python
;; (require 'python-mode)
;; (global-set-key [f8] 'py-execute-buffer)
(display-time-mode t)
(setq display-time-24hr-format t);;时间使用24小时制
(setq display-time-day-and-date t);;时间显示包括日期和具体时间
(setq inhibit-startup-message t);;关闭emacs启动时的画面
(ansi-color-for-comint-mode-on);;真正shell-mode乱码解决
(mouse-avoidance-mode 'animate);;光标靠近鼠标指针时,让鼠标指针自动让开,别挡住视线
;;双重补全,好用的很呐
(global-set-key (kbd "M-/") 'hippie-expand)
;; ;;对付重命名的buffer
(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)
;;Add find-name-dired and find-grep-dired Command.
(add-hook 'shell-mode-hook 'wcy-shell-mode-hook-func) ;;;每当我在M-x shell启动shell ,然后执行 exit 退出 shell 之后,buffer 并不自动关 闭,很不爽, 下面的指令,可以让其自动关闭。
(defun wcy-shell-mode-hook-func ()
(set-process-sentinel (get-buffer-process (current-buffer))
#'wcy-shell-mode-kill-buffer-on-exit)
)
(defun wcy-shell-mode-kill-buffer-on-exit (process state)
(message "%s" state)
(if (or
(string-match "exited abnormally with code.*" state)
(string-match "finished" state))
(kill-buffer (current-buffer))))
(defun kill-buffer-when-shell-command-exit ()
"Close current buffer when `shell-command' exit."
(let ((process (ignore-errors (get-buffer-process (current-buffer)))))
(when process
(set-process-sentinel process
(lambda (proc change)
(when (string-match "\\(finished\\|exited\\)" change)
(kill-buffer (process-buffer proc))))))))
;;自动添加c/c++头文件宏定义
(setq auto-insert t)
(setq auto-insert-query t)
(add-hook 'find-file-hooks 'auto-insert)
(setq auto-insert-directory "~/insert/")
(define-auto-insert '("^build\\.xml\\'" . "Ant编译脚本") "build.xml")
;;解决emacs23以前无法正常拷贝-粘贴中文
(set-clipboard-coding-system 'ctext)
;;选择标记
;;(global-set-key (kbd "C-q") 'set-mark-command)
;;灰黑色主题
(load-theme 'tsdh-dark)
;;括号自动补全
(electric-pair-mode t)
;自动清除行位空格
(global-set-key [f2] 'delete-trailing-whitespace)
;;显示空格
(global-set-key [f1] 'whitespace-newline-mode)
;;高亮当前行
(global-hl-line-mode 1)
;;显示下划线
(set-face-attribute hl-line-face nil :underline t)