.emacs的配置文件(windows下)

Vim、Emacs配置和使用
回复
zpc987
帖子: 6
注册时间: 2010-08-06 22:58

.emacs的配置文件(windows下)

#1

帖子 zpc987 » 2013-10-28 20:30

1.windows下emacs的HOME设置方法
注册表"HKEY_CURRENT_USER"-"Software"-"GNU"
在下面新建项"Emacs","Emacs"里面新建项"HOME",值设置为希望的目录。
2.右键添加Edit with Emacs选项
HKEY_CLASSES_ROOT\*\shell\Edit with Emacs\command
如果没有shell,就新建项。
将command的默认值设置为
"path\to\emacsclientw.exe" --no-wait --alternate-editor="path\to\runemacs.exe" "%1"
path to的值要修改一下。

;;;;;;;;;;;;;;;;;;;;;;.emacs文件
;; .emacs
(server-start)
;;支持中文显示
(set-language-environment `chinese-GB)

;;;;;;;;;;In Windows you can add this to to your .emacs to enable hyper and super
;(setq w32-apps-modifier 'hyper)
(setq w32-lwindow-modifier 'super)
;(setq w32-rwindow-modifier 'hyper)

(setq make-backup-files nil); 设定不产生备份文件
(setq auto-save-mode nil);自动保存模式
(setq-default make-backup-files nil); 不生成临时文件
(setq backup-inhibited t);;不产生备份
(setq auto-save-default nil);不生成名为#filename# 的临时文件

(global-set-key (kbd "C-c w") 'copy-lines)
(defun copy-lines(&optional arg)
(interactive "p")
(save-excursion
(beginning-of-line)
(set-mark (point))
(next-line arg)
(kill-ring-save (mark) (point))))

;;hide red underline
(setq semantic-show-unmatched-syntax-mode nil )

;;set C-z to a map key,not suspend Emacs
(define-prefix-command 'ctl-z-map)
(global-set-key (kbd "C-z") 'ctl-z-map)


;;; uncomment this line to disable loading of "default.el" at 'my-fullscreen)
;(setq initial-frame-alist '((top . 0) (left . 0) (width . 120) (height . 40)))

(global-set-key (kbd "C-,") 'scroll-left)
;; "C-,"设为屏幕左移命令

(global-set-key (kbd "C-.") 'scroll-right)
;; "C-."设为屏幕右移命令

; (global-set-key (kbd "C-x") 'nil)
;;取消control+space键设为mark

(global-set-key (kbd "s-SPC") 'set-mark-command)
;;用win+space键来set-mark,这样,C-SPC就可以用来调用外部输入法了。

(setq inhibit-startup-message t)
;;关闭emacs启动时的画面

(setq gnus-inhibit-startup-message t)
;;关闭gnus启动时的画面

(setq enable-recursive-minibuffers t)
;;可以递归的使用 minibuffer

;(mouse-avoidance-mode 'animate)
;;光标靠近鼠标指针时,让鼠标指针自动让开,别挡住视线。

(setq frame-title-format "%b")
;;在标题栏显示buffer的名字,而不是 emacs@wangyin.com 这样没用的提示。

(setq track-eol t)
;; 当光标在行尾上下移动的时候,始终保持在行尾。

(setq Man-notify-method 'pushy)
;; 当浏览 man page 时,直接跳转到 man buffer。

(global-set-key [home] 'beginning-of-buffer)
(global-set-key [end] 'end-of-buffer)
;;设置home键指向buffer开头,end键指向buffer结尾


;;用一个很大的 kill ring. 这样防止我不小心删掉重要的东西。
(setq kill-ring-max 200)

;;显示括号匹配
(show-paren-mode t)

;;显示80列就换行
;;(add-hook 'message-mode-hook (lambda ()
;;(setq default-fill-column 80)
;;(turn-on-auto-fill)))


;;禁止终端响铃
(setq visiable-bell nil)

;;增大使用查找函数和变量的寻找范围
(setq apropos-do-all t)

;;是用aspell程序作为Emacs的拼写检查成学
(setq-default ispell-program-name "aspell")

;;启动Emacs自动设置为两个窗口(上下各一个)
;;(split-window-vertically)

;;代码折叠
(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 'cperl-mode-hook 'hs-minor-mode)
(add-hook 'php-mode-hook 'hs-minor-mode)
(add-hook 'emacs-lisp-mode-hook 'hs-minor-mode)


;;字体设置
(set-default-font "Consolas-12")
;;(set-default-font "monospace\14")

;;verilog-mod
(autoload 'verilog-mode "verilog-mode" "Verilog mode" t )
(add-to-list 'auto-mode-alist '("\\.[ds]?vh?\\'" . verilog-mode))
;; User customization for Verilog mode
; (setq verilog-indent-level 3
; verilog-indent-level-module 3
; verilog-indent-level-declaration 3
; verilog-indent-level-behavioral 3
; verilog-indent-level-directive 1
; verilog-case-indent 2
; verilog-auto-newline t
; verilog-auto-indent-on-newline t
; verilog-tab-always-indent t
; verilog-auto-endcomments t
; verilog-minimum-comment-distance 40
; verilog-indent-begin-after-if t
; verilog-auto-lineup '(all)
; verilog-highlight-p1800-keywords nil
; verilog-linter "my_lint_shell_command"
; )

;;vera-mode
(autoload 'vera-mode "vera-mode" "Vera Mode" t)
(setq auto-mode-alist (cons '("\\.vr[hi]?\\'" . vera-mode) auto-mode-alist))
;; turn-on-setnu-mode
;;(add-hook 'text-mode-hook 'turn-on-setnu-mode)

;(add-to-list 'load-path "~/.emacs.d/")
;(require 'display-line-number)
;(global-display-line-number-mode 1)
;;(setq display-line-number-mode-on t)
;(add-hook 'c-mode-hook 'display-line-number-mode)
;(add-hook 'cc-mode-hook 'display-line-number-mode)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(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.
'(blink-cursor-mode nil)
'(column-number-mode t)
'(display-time-mode t)
'(show-paren-mode t)
'(size-indication-mode 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.
;'(default ((t (:inherit nil :stipple nil :background "SystemWindow" :foreground "SystemWindowText" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 98 :width normal :foundry "outline" :family "新宋体")))))
;解决emacs shell 乱码
(setq ansi-color-for-comint-mode t)
(customize-group 'ansi-colors)
(kill-this-buffer);关闭customize窗口
;;(setq default-major-mode 'text-mode);一打开就起用 text 模式
;自定义按键
(setq backup-inhibited t);;不产生备份
(setq auto-save-default nil);不生成名为#filename# 的临时文件
;; 用M-x执行某个命令的时候,在输入的同时给出可选的命令名提示
(icomplete-mode 1)
(define-key minibuffer-local-completion-map (kbd "SPC") 'minibuffer-complete-word)
(setq column-number-mode t)
(global-linum-mode t)

(setq scroll-margin 3 scroll-conservatively 10000)
;(setq line-number-mode t)
;(global-linum-mode 'linum-mode);;在左边显示行号
;;(global-set-key (kbd "C-a") 'view-file-other-window)
(global-font-lock-mode t);语法高亮
(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-default kill-whole-line t);;C-k 删除该行
(fset 'yes-or-no-p 'y-or-n-p);以 y/n代表 yes/no
(show-paren-mode t);显示括号匹配
(setq show-paren-mode t) ;;打开括号匹配显示模式
(setq show-paren-style 'parenthesis)
(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);;时间的变化频率,单位多少来着?
(auto-save-mode nil);;禁止自动保存
(put 'scroll-left 'disabled nil);;允许屏幕左移
(put 'scroll-right 'disabled nil);;允许屏幕右移
(put 'set-goal-column 'disabled nil)
(put 'narrow-to-region 'disabled nil)
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)
(put 'LaTeX-hide-environment 'disabled nil)
;(mouse-avoidance-mode 'animate);光标靠近鼠标指针时,让鼠标指针自动让开
(setq mouse-yank-at-point t);支持中键粘贴
(transient-mark-mode t);允许临时设置标记
;; 高亮显示C/C++中的可能的错误(CWarn mode)
(global-cwarn-mode 1)
(global-set-key (kbd "<C-down-mouse-1>") nil) ;; 去掉原来的帮定关系
(global-set-key (kbd "<C-mouse-1>") 'mouse-buffer-menu);;ctrl+鼠标左键调出选择切换buffer功能
(global-set-key (kbd "<C-down-mouse-2>") 'mouse-popup-menuar-stuff);;ctrl+鼠标右键调出和编辑相关功能
(setq speedbar-show-unknown-files t);;可以显示所有目录以及文件
;;让 dired 可以递归的拷贝和删除目录。
(setq dired-recursive-copies 'top)
(setq dired-recursive-deletes 'top)
;(global-set-key (kbd "C-e") 'ecb-activate);;启动Ecb
;(global-set-key [C-f9] 'dired);;设置[C-f9]为调用dired命令
;;(global-set-key [C-f10] 'undo);;设置C-F10为撤销
(global-set-key [C-f11] 'calendar) ;;设置C-F11快捷键指定Emacs 的日历系统
(global-set-key [C-f12] 'list-bookmarks);;设置C-F12 快速察看日程安排
(global-set-key (kbd "C-|") 'other-window);窗口间跳转
;(global-set-key [f2] 'kill-this-buffer);F2关闭当前buffer
;(global-set-key [M-return] 'kill-this-buffer);M-return关闭当前buffer
;(global-set-key [C-return] 'kill-this-buffer);C-return关闭当前buffer
(global-set-key [f10] 'split-window-vertically);F10分割窗口
(global-set-key [f11] 'delete-other-windows);F11 关闭其它窗口
;(global-set-key [f12] 'my-fullscreen);F12 全屏
;(global-set-key (kbd "M-,") 'backward-page);文件首
;(global-set-key (kbd "C-.") 'forward-page);文件尾
(global-set-key (kbd "C-'") 'next-buffer);转到下一个buffer
(global-set-key (kbd "C-;") 'previous-buffer);转到上一个buffer
;(global-set-key (kbd "C-/") 'next-multiframe-window);;转到下一个窗口
;(global-set-key (kbd "C-?") 'previous-multiframe-window);;转到上一个窗口
;(global-set-key (kbd "C-<") 'beginning-of-line);;跳转到行首
;(global-set-key (kbd "C->") 'end-of-line);;跳转到行尾
(global-set-key (kbd "C-c C-g") 'goto-char) ;;跳转到行任意位子
(setq mouse-drag-copy-region nil);;取消鼠标选择即复制
;普通设置
(setq inhibit-startup-message t);关闭起动时闪屏
(setq visible-bell t);关闭出错时的提示声

;;shell,gdb退出后,自动关闭该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))))))))

;; 退出gdb的时候关闭gdb对应的buffer
(add-hook 'gdb-mode-hook 'kill-buffer-when-shell-command-exit)
;; 退出term的时候关闭term对应的buffer
(add-hook 'term-mode-hook 'kill-buffer-when-shell-command-exit)
;;编译成功后自动关闭*compilation* 函数
(defun kill-buffer-when-compile-success (process)
"Close current buffer when `shell-command' exit."
(set-process-sentinel process
(lambda (proc change)
(when (string-match "finished" change)
(delete-windows-on (process-buffer proc))))))

;; 编译成功后自动关闭*compilation* buffer
(add-hook 'compilation-start-hook 'kill-buffer-when-compile-success)
;;退出时寻问
;(setq kill-emacs-query-functions
;(lambda ()
;(y-or-n-p "Do you really want to quit? ")))

;; 设置时间戳,标识出最后一次保存文件的时间。
(setq time-stamp-active t)
(setq time-stamp-warn-inactive t)
(setq time-stamp-format "%:y-%02m-%02d %3a %02H:%02M:%02S chunyu")
(global-set-key (kbd "M-g") 'goto-line);;设置M-g为goto-line
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 设置日历 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;设置日历的一些颜色
(setq calendar-load-hook
'(lambda ()
(set-face-foreground 'diary-face "skyblue")
(set-face-background 'holiday-face "slate blue")
(set-face-foreground 'holiday-face "white")))
;;设置我所在地方的经纬度,calendar里有个功能是日月食的预测,和你的经纬度相联系的。
;; 让emacs能计算日出日落的时间,在 calendar 上用 S 即可看到
(setq calendar-latitude +39.54)
(setq calendar-longitude +116.28)
(setq calendar-location-name "北京")
;; 设置 calendar 的显示
(setq calendar-remove-frame-by-deleting t)
(setq calendar-week-start-day 1);; 设置星期一为每周的第一天
(setq mark-diary-entries-in-calendar t);; 标记calendar上有diary的日期
(setq mark-holidays-in-calendar nil); ; 为了突出有diary的日期,calendar上不标记节日
(setq view-calendar-holidays-initially nil) ; 打开calendar的时候不显示一堆节日
;; 去掉不关心的节日,设定自己在意的节日,在 calendar 上用 h 显示节日
(setq christian-holidays nil)
(setq hebrew-holidays nil)
(setq islamic-holidays nil)
(setq solar-holidays nil)
(setq general-holidays '((holiday-fixed 1 1 "元旦")
(holiday-float 5 0 2 "母亲节")
(holiday-float 6 0 3 "父亲节")
(holiday-fixed 12 25 "圣诞节")))
;; q 退出calendar模式

(setq compile-command "make")
;;emacs的默认compile命令是调用make -k,我把它改成了make。你也可以把它改成其他的,比如gcc之类的.
;;把c语言风格设置为k&r风格
(add-hook 'c-mode-hook
'(lambda ()
(c-set-style "k&r")))
;;把C++语言风格设置为stroustrup风格
(add-hook 'c++-mode-hook
'(lambda()
(c-set-style "stroustrup")))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;C/C++设定;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;缩进策略
(defun my-indent-or-complete ()
(interactive)
(if (looking-at "\\>")
(hippie-expand nil)
(indent-for-tab-command)))
;;按键定义
(define-key c-mode-base-map [(return)] 'newline-and-indent)
(define-key c-mode-base-map [(meta \`)] 'c-indent-command)

;;能把一个代码块缩起来,需要的时候再展开
;; 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

(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 'emacs-lisp-mode-hook 'hs-minor-mode)
(add-hook 'lisp-mode-hook 'hs-minor-mode)
(add-hook 'scheme-mode-hook 'hs-minor-mode)
(add-hook 'css-mode-hook 'hs-minor-mode)
(add-hook 'html-mode-hook 'hs-minor-mode)
(global-set-key (kbd "C-c C-:") 'hs-show-all);;显示
(global-set-key (kbd "C-c C-\"") 'hs-hide-all);;隐藏

;
(setq x-select-enable-clipboard t);支持emacs和外部程序的粘贴


;;ido的配置,这个可以使你在用C-x C-f打开文件的时候在后面有提示;
;;这里是直接打开了ido的支持,在emacs23中这个是自带的.
(ido-mode t)
(setq visible-bell t)
;;设置 sentence-end 可以识别中文标点。不用在 fill 时在句号后插入两个空格。
(setq sentence-end "\\([。!?]\\|……\\|[.?!][]\"')}]*\\($\\|[ \t]\\)\\)[ \t\n]*")
(setq sentence-end-double-space nil)
;;可以递归的使用 minibuffer
(setq enable-recursive-minibuffers t)
;;设置个人信息
(setq user-full-name "")
(setq user-mail-address "")
(setq track-eol t);; 当光标在行尾上下移动的时候,始终保持在行尾。
(setq Man-notify-method 'pushy);; 当浏览 man page 时,直接跳转到 man buffer。

;;设置home键指向buffer开头,end键指向buffer结尾
(global-set-key [home] 'beginning-of-buffer)
(global-set-key [end] 'end-of-buffer)
(setq default-fill-column 80);;把 fill-column 设为 80. 这样的文字更好读

;; 实现程序变量得自动对齐
(require 'align)
(global-set-key "\C-x\C-j" 'align)

;鼠标滚轮,默认的滚动太快,这里改为3行
(defun up-slightly () (interactive) (scroll-up 1))
(defun down-slightly () (interactive) (scroll-down 1))
(global-set-key [mouse-4] 'down-slightly)
(global-set-key [mouse-5] 'up-slightly)

;;全屏
;(defun my-fullscreen ()
;(interactive)
;(x-send-client-message
;nil 0 nil "_NET_WM_STATE" 32
;'(2 "_NET_WM_STATE_FULLSCREEN" 0)))

;; 启动窗口大小
;(when window-system
;(setq default-frame-alist
;'((height . 50) (width . 100) (menu-bar-lines . 20) (tool-bar-lines . 0))))

;(setq default-directory "G:\test");;默认目录
;(add-to-list 'load-path
;"~/.emacs.d/plugins/")
;(require 'yasnippet-bundle)
;(add-to-list 'load-path
;"~/.emacs.d/")
;(require 'auto-complete+)
;(require 'auto-complete-config)
;(add-to-list 'ac-dictionary-directories "~/.emacs.d//ac-dict")
;(ac-config-default)

;;Emacs背景主题
(add-to-list 'load-path "~/.emacs.d/")
(require 'color-theme)
(color-theme-initialize)
(color-theme-deep-blue)

;(require 'color-theme)
;(color-theme-deep-blue)
;(color-theme-matrix)
;(setq org-hide-leading-stars t)
;(define-key global-map "\C-ca" 'org-agenda)
;(setq org-log-done 'time)

;;显示图片
(auto-image-file-mode 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.
)
;;;;;;;;;; buffer 间切换
(global-set-key (kbd "s-j") 'windmove-left)
(global-set-key (kbd "s-k") 'windmove-right)
(global-set-key (kbd "s-n") 'other-window)

;(menu-bar-mode -1)
(tool-bar-mode -1)
;(scroll-bar-mode -1)

;;;;;;;;;;F8 key binding
(defun open-eshell-other-buffer ()
(interactive)
(split-window-horizontally)
(eshell))
(global-set-key [(f8)] 'open-eshell-other-buffer)
(global-set-key [C-f8] 'eshell)

;光标变成竖线
(setq-default cursor-type 'bar)

(setq-default indent-tabs-mode nil)
(setq default-tab-width 4);tab键为4个字符宽度
(setq tab-stop-list ())
;不用 TAB 字符来indent

;;;;;;;;;;markdown mode
(autoload 'markdown-mode "markdown-mode"
"Major mode for editing Markdown files" t)
(add-to-list 'auto-mode-alist '("\\.text\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))


(w32-send-sys-command 61488)
回复