本emacs配置参考了很多人的配置,本人只是做了一下组合而已
我的emacs的整体配置在http://code.google.com/p/my-research-back/ 有, 大家如果感兴趣可以去看下
;;设置用户名和邮件地址
(setq user-full-name "XXX")
(setq user-mail-address "XXX")
(defconst my-company "XXX" "公司名称")
;;设置emacs的插件搜索路径 递归搜索
(defconst my-emacs-path "~/.emacs.d/" "我的emacs相关配置文件的路径")
(defconst my-emacs-lisps-path (concat my-emacs-path "mylisps/") "我自己写的emacs lisp包的路径")
(defconst system-emacs-lisps-path "/usr/share/emacs23/" "emacs自带插件的路径")
(defconst system-emacs23-lisps-path "/usr/share/emacs/" "emacs23自带插件路径")
(defconst yas-snippets (concat my-emacs-lisps-path "yasnippet/snippets") "yasnippets模板库")
(defconst yas-snippets-extra (concat my-emacs-lisps-path "yasnippet/extras/imported") "yasnipets模板库扩展")
;; 把`my-emacs-lisps-path'的所有子目录都加到`load-path'里面
(load (concat my-emacs-lisps-path "my-subdirs"))
(my-add-subdirs-to-load-path my-emacs-lisps-path)
(my-add-subdirs-to-load-path system-emacs-lisps-path)
(my-add-subdirs-to-load-path system-emacs23-lisps-path)
;;不显示GNU emacs启动界面
(setq inhibit-startup-message t)
;; 尽快显示按键序列
(setq echo-keystrokes 0.1)
;; 显示列号
(setq column-number-mode t)
;; 不要总是没完没了的问yes or no, 为什么不能用y/n
(fset 'yes-or-no-p 'y-or-n-p)
;; 防止页面滚动时跳动,scroll-margin 3可以在靠近屏幕边沿3行时就开始滚动,可以很好的看到上下文
;;(setq scroll-margin 3
;; scroll-conservatively 10000)
;; 可以保存你上次光标所在的位置
(require 'saveplace)
(setq-default save-place t)
;;菜单栏设置
(menu-bar-mode 1) ;;显示菜单栏
;;工具栏设置
(tool-bar-mode -1) ;;不显示工具栏 工具栏太丑
;;滚动条设置
(scroll-bar-mode -1) ;;不显示滚动条 太丑
;语法高亮
(global-font-lock-mode t)
(which-function-mode t) ;在状态条上显示当前光标在哪个函数体内部
(auto-compression-mode 1) ;打开压缩文件时自动解压缩
;; 用一个很大的kill ring. 这样防止我不小心删掉重要的东西
(setq kill-ring-max 1024)
(setq max-lisp-eval-depth 40000) ;lisp最大执行深度
(setq max-specpdl-size 10000) ;最大容量
(setq undo-outer-limit 5000000) ;撤销限制
(setq message-log-max t) ;设置message记录全部消息, 而不用截去
(setq eval-expression-print-length nil) ;设置执行表达式的长度没有限制
(setq eval-expression-print-level nil) ;设置执行表达式的深度没有限制
(setq global-mark-ring-max 1024) ;设置最大的全局标记容量
(setq history-delete-duplicates t) ;删除minibuffer的重复历史
;;; ### Coding ###
;;; --- 编码设置
(setq default-buffer-file-coding-system 'utf-8-unix) ;缓存文件编码
(setq default-file-name-coding-system 'utf-8-unix) ;文件名编码
(setq default-keyboard-coding-system 'utf-8-unix) ;键盘输入编码
(setq default-process-coding-system '(utf-8-unix . utf-8-unix)) ;进程输出输入编码
(setq default-sendmail-coding-system 'utf-8-unix) ;发送邮件编码
(setq default-terminal-coding-system 'utf-8-unix) ;终端编码
;;; ### Indent ###
;;; --- 缩进设置
(setq-default indent-tabs-mode t) ;默认不用空格替代TAB
(setq default-tab-width 4) ;设置TAB默认的宽度
(dolist (hook (list ;设置用空格替代TAB的模式
'emacs-lisp-mode-hook
'lisp-mode-hook
'lisp-interaction-mode-hook
'scheme-mode-hook
'c-mode-hook
'c++-mode-hook
'java-mode-hook
'haskell-mode-hook
'asm-mode-hook
'emms-tag-editor-mode-hook
'sh-mode-hook
))
(add-hook hook '(lambda () (setq indent-tabs-mode nil))))
;;; ### Scroll-mode-line ###
;;; --- 滚动 Mode-line 的信息
;;http://www.emacswiki.org/emacs/scroll-mode-line-mode.el
;;(scroll-mode-line-mode 1)
;;在同一个窗口显示speedbar而不是另开一个窗口
;;http://www.emacswiki.org/emacs/SpeedBar
;;http://www.emacswiki.org/emacs/SrSpeedbar
;;http://www.emacswiki.org/emacs/sr-speedbar.el
(require 'sr-speedbar)
(require 'speedbar-extension)
(global-set-key (kbd "C-c / C-s") 'sr-speedbar-toggle) ;;sr-speedbar按键绑定
;;; ### Modeline-posn ###
;;; --- 在 Mode-line 显示当前Buffer的大小
(size-indication-mode 1)
;;; ### Files ###
;;; --- 文件设置
(setq require-final-newline nil) ;不自动添加换行符到末尾, 有些情况会出现错误
;如果需要手动添加
;;show help
;;ShowHelp is mode that popup help information for elisp symbol at cursor
(require 'showtip)
(require 'show-help)
;;设置wrap at windows edge
;;;http://www.emacswiki.org/emacs/TruncateLines
;;;http://xahlee.org/emacs/emacs23_features.html
(global-visual-line-mode 1) ; 1 for on, 0 for off.
;;默认链接网络浏览器打开为chrome
(setq browse-url-generic-program (executable-find "google-chrome")
browse-url-browser-function 'browse-url-generic)
;;; ### Modeline-posn-column-limit ###
;;; --- 列数限制
;;;(setq modelinepos-column-limit 80) ;设置列数限制, 并在mode-line上显示
;;CEDET配置
;;cedet1.0初始化必须要放在前面,因为cedet-called-interactively-p在cedet-compat.el中有定义,这个和后面的东西有冲突,必须放在前面初始化
(load "cedet") ;集成开发环境
(load "ede")
(require 'ecb) ;Emacs代码浏览器
;;(defun ede-dired-minor-mode (&optional arg) nil)
(require 'semantic) ;semantic
(require 'semantic-ia) ;semantic-ia
;;(require 'semantic-gcc) ;; 没找到这个插件 ;;自动将gcc的头文件目录添加到semantic解析的路径中
;; Semanticdb can use databases generated by external utilities — gtags from GNU Global, ctags, ebrowse & cscope
(require 'semanticdb);;semantic 工具解析文件设置的database
(require 'ede-dired) ;;
;;; ### ECB ###
;;; --- 代码浏览器
(setq ecb-primary-secondary-mouse-buttons 'mouse-1--C-mouse-1) ;;设置可以使用鼠标点击各个窗口的东东
;;(custom-set-variables '(ecb-options-version "2.4")) ;ECB的版本, 以使启动时不检查
(setq ecb-layout-window-sizes ;定制ECB窗口的布局
(quote (("left8" (0.20967741935483872 . 0.27586206896551724)
(0.20967741935483872 . 0.2413793103448276)
(0.20967741935483872 . 0.27586206896551724)
(0.20967741935483872 . 0.1724137931034483)))))
(setq ecb-tip-of-the-day nil) ;启动ECB时不显示每日提示
(semantic-load-enable-minimum-features)
(semantic-load-enable-code-helpers)
;;(semantic-load-enable-guady-code-helpers)
(global-semantic-stickyfunc-mode 0) ;;关闭将函数名显示在Buffer顶的功能,因为容易和tabbar冲突
(global-semantic-idle-completions-mode 0);;;关闭semantic的自动补全功能,因为会很慢,而且和补全插件有点冲突额
(global-semantic-decoration-mode 1);;启用函数名装饰一条蓝色线的功能
;;(semantic-load-enable-excessive-code-helpers)
(semantic-load-enable-semantic-debugging-helpers)
(semantic-load-enable-all-exuberent-ctags-support)
(setq semanticdb-project-roots (list (expand-file-name "/"))) ;配置Semantic的检索范围
(autoload 'senator-try-expand-semantic "senator") ;优先调用了senator的分析结果
;;semantic 头文件目录设置
(defconst cedet-user-include-dirs
(list "." ".." "../include" "../inc" "../common" "../public"
"../.." "../../include" "../../inc" "../../common" "../../public"))
(defconst cedet-linux-include-dirs
(list "~/CodeSourcery/Sourcery_G++_Lite/arm-none-eabi/include"
))
(require 'semantic-c nil 'noerror)
(let ((include-dirs cedet-user-include-dirs))
(when (eq system-type 'gnu/linux)
(setq include-dirs (append include-dirs cedet-linux-include-dirs)))
(mapc (lambda (dir)
(semantic-add-system-include dir 'c++-mode)
(semantic-add-system-include dir 'c-mode))
include-dirs))
;;通过鼠标在直接点击就可以打开和折叠代码
(require 'semantic-tag-folding nil 'noerror)
(global-semantic-tag-folding-mode 1)
(global-srecode-minor-mode 1)
;;semantic折叠快捷键设置 主要是为了防止其他配置和该配置的鼠标点击冲突造成点击折叠失败
(define-key semantic-tag-folding-mode-map (kbd "C-c , -") 'semantic-tag-folding-fold-block)
(define-key semantic-tag-folding-mode-map (kbd "C-c , =") 'semantic-tag-folding-show-block)
(define-key semantic-tag-folding-mode-map (kbd "C-c ' -") 'semantic-tag-folding-fold-all)
(define-key semantic-tag-folding-mode-map (kbd "C-c ' =") 'semantic-tag-folding-show-all)
(global-ede-mode 1) ;;启用全局EDE(工程管理)特性 有时候会不出现project菜单项,当将其建立的工程导入时就可以出现菜单了
;;编码自动识别 http://www.emacswiki.org/emacs/Unicad
(require 'unicad)
;;显示行号 http://www.emacswiki.org/emacs/LinumPlus
(require 'linum+)
(global-linum-mode 1);;启用全局显示行号模式
(global-set-key (kbd "C-x N") 'linum-mode)
;;颜色主题设置
(require 'color-theme)
(color-theme-initialize)
(require 'color-theme-ahei)
(color-theme-ahei)
(global-set-key (kbd "C-c / a") 'color-theme-ahei)
;;窗口设置
;窗口缩放 http://www.emacswiki.org/emacs/WindowResize
(require 'windresize)
(global-set-key (kbd "S-C-
") 'shrink-window-horizontally)
(global-set-key (kbd "S-C-") 'enlarge-window-horizontally)
(global-set-key (kbd "S-C-") 'shrink-window)
(global-set-key (kbd "S-C-") 'enlarge-window)
;;窗口标号导航 http://www.emacswiki.org/emacs/NumberedWindows
;(require 'window-number)
;(window-number-mode) ;;采用C-x C-j x x为数字进行导航
;(window-number-meta-mode) ;;采用M-x x为数字进行窗口导航
(require 'window-numbering) ;;功能稍微好用于NumberedWindows http://nschum.de/src/emacs/window-numbering-mode/
(window-numbering-mode 1) ;;采用M-x进行窗口导航切换 M-0切换到激活的minibuffer
;;复制剪切等文本编辑设置
(setq x-select-enable-clipboard t) ;;设置剪切板为全局
(setq mouse-drag-copy-region nil) ;;禁止采用鼠标选取后就进入剪切板
(setq x-select-enable-primary nil) ;; stops killing/yanking interacting with primary X11 selection
(setq select-active-regions t) ; active region sets primary X11 selection
;;CUA-MODE 矩形块复制粘贴操作 http://www.emacswiki.org/emacs/CuaMode
(cua-mode t)
(setq cua-auto-tabify-rectangles nil) ;; Don't tabify after rectangle commands 矩形操作后不TAB对齐
(transient-mark-mode 1) ;; No region when it is not highlighted
(setq cua-keep-region-after-copy t) ;; Standard Windows behaviour
;;emacs的重做命令模拟
(require 'redo+)
(global-set-key (kbd "C-?") 'redo)
;;智能括号
(require 'autopair) ;;智能自动补全括号 http://www.emacswiki.org/emacs/AutoPairs
;;(require 'auto-pair+)
(autopair-global-mode 1) ;; 全局启用智能补全括号
(require 'highlight-parentheses) ;智能括号匹配高亮 http://www.emacswiki.org/emacs/HighlightParentheses
;;;使autopair模式和highlight-parentheses集成交互使用
(add-hook 'highlight-parentheses-mode-hook
'(lambda ()
(setq autopair-handle-action-fns
(append
(if autopair-handle-action-fns
autopair-handle-action-fns
'(autopair-default-handle-action))
'((lambda (action pair pos-before)
(hl-paren-color-update)))))))
;;Enables highlight-parentheses-mode on all buffers:
(define-globalized-minor-mode global-highlight-parentheses-mode
highlight-parentheses-mode
(lambda ()
(highlight-parentheses-mode t)))
(global-highlight-parentheses-mode t)
(setq show-paren-style 'parentheses) ;括号匹配显示但不是烦人的跳到另一个括号。
;;平滑滚动 貌似效果不好 取消这个插件
;;(require 'smooth-scroll)
;;(smooth-scroll-mode t)
;;(setq scroll-step 1
;; scroll-conservatively 10000)
;;高亮显示设置
(require 'generic-x);;更加丰富的高亮
;;(require 'crosshairs) ;;高亮显示光标所在行和列 没啥好用的http://www.emacswiki.org/emacs/CrosshairHighlighting
(require 'hl-line+) ;;http://www.emacswiki.org/emacs/HighlightCurrentLine
(toggle-hl-line-when-idle 1) ;;仅在emacs空闲时高亮本行
;;高亮显示关键字
(require 'highlight-fixmes-mode)
(highlight-fixmes-mode);;启用关键字高亮功能
(global-set-key (kbd "C-c / M-f") 'highlight-fixmes-mode)
;; 高亮显示当前buffer中的一个符号 Quickly highlight a symbol throughout the buffer and cycle through its locations.
(require 'highlight-symbol)
(global-set-key (kbd "C-c / M-h a") 'highlight-symbol-at-point)
(global-set-key (kbd "C-c / M-h n") 'highlight-symbol-next)
(global-set-key (kbd "C-c / M-h p") 'highlight-symbol-prev)
;;高亮显示c语言的变量类型
;;(require 'ctypes) ;;暂时没看出效果
;;(setq ctypes-write-types-at-exit t)
;;(ctypes-read-file nil nil t t)
;;(ctypes-auto-parse-mode 1)
;;显示空格
(require 'show-wspace) ;空格提示 http://www.emacswiki.org/emacs/ShowWhiteSpace
;;菜单增强
(require 'menu-bar+)
;;Buffer管理
;; 按下C-x k立即关闭掉当前的buffer
(global-set-key (kbd "C-x k") 'kill-this-buffer)
;;标签式管理buffer
;;http://www.emacswiki.org/emacs/TabBarMode
;;将TAB按照类别进行分类 这个必须放在tabbar require前面 测试发现还是有问题就没有解决了
;; (defun tabbar-buffer-groups (buffer)
;; "Return the list of group names BUFFER belongs to.
;; Return only one group for each buffer."
;; (with-current-buffer (get-buffer buffer)
;; (cond
;; ((string-equal "*" (substring (buffer-name) 0 1))
;; '("Emacs Buffer"))
;; ((eq major-mode 'dired-mode)
;; '("Dired"))
;; (t
;; '("User Buffer"))
;; )))
;; (setq tabbar-buffer-groups-function 'tabbar-buffer-groups)
;;忽略指定的buffer 测试发现有问题
;; (setq *tabbar-ignore-buffers* '("SPEEDBAR"))
;; (setq tabbar-buffer-list-function
;; (lambda ()
;; (remove-if
;; (lambda (buffer)
;; (and (not (eq (current-buffer) buffer)) ; Always include the current buffer.
;; (loop for name in *tabbar-ignore-buffers* ;remove buffer name in this list.
;; thereis (string-equal (buffer-name buffer) name))))
;; (buffer-list))))
(require 'tabbar) ;标签管理 http://www.emacswiki.org/emacs/TabBarMode
;;tabbar设置
;;;这个功能会导致tabbar显示不是很流畅
;;(setq tabbar-ruler-global-tabbar 't) ; If you want tabbar
;;(setq tabbar-ruler-global-ruler 't) ; if you want a global ruler
;;;下面的功能不好用
;;(setq tabbar-ruler-popup-menu 't) ; If you want a popup menu.
;;(setq tabbar-ruler-popup-toolbar 't) ; If you want a popup toolbar
;;Setup tabbar to look pretty..
(require 'tabbar-ruler)
;;(require 'tabbar-extension) ;;不是很好用
;;使能tabbar
(tabbar-mode 1)
;;Icicles an Emacs library that enhances minibuffer completion
;;这个插件很耗时间啊
;;(require 'icicles)
;;(icy-mode 1)
;;emacs的模板系统
(require 'yasnippet) ;类似TextMate超酷的模版模式
;;(setq yas/snippet-dirs '(yas-snippets yas-snippets-extra)) ;;测试发现不行 不能载入模板文件 不明白原因
;;(setq yas/snippet-dirs '('(concat my-emacs-lisps-path "yasnippet/snippets") '(concat my-emacs-lisps-path "yasnippet/extras/imported")));;同上
(setq yas/snippet-dirs '("~/.emacs.d/mylisps/yasnippet/snippets" "~/.emacs.d/mylisps/yasnippet/extras/imported")) ;;测试发现可以载入模板文件
(yas/global-mode 1)
;; The `dropdown-list.el' extension is bundled with YASnippet, you
;; can optionally use it the preferred "prompting method"
(require 'dropdown-list)
(setq yas/prompt-functions '(yas/dropdown-prompt
yas/ido-prompt
yas/completing-prompt))
;;自动补全设置
;;http://cx4a.org/software/auto-complete/
(require 'auto-complete)
(require 'ac-dabbrev)
(require 'ac-math) ;;用于latex补全
(add-to-list 'ac-dictionary-directories (concat my-emacs-lisps-path "auto-complete-1.3.1/dict"))
(require 'auto-complete-config)
(require 'auto-complete+) ;;ahei写的加强auto-complete功能的插件
(require 'auto-complete-extension nil t) ;optional
(require 'auto-complete-yasnippet nil t) ;optional
(require 'auto-complete-semantic nil t) ;optional
(require 'auto-complete-etags nil t) ;optional
;;(require 'auto-complete-cpp nil t) ;optional 这个模式和最新的auto-complete模式冲突
(ac-config-default)
;; The sources for common all 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.
'(ac-sources (quote (ac-source-yasnippet ac-source-semantic ac-source-imenu ac-source-abbrev ac-source-words-in-buffer ac-source-files-in-current-dir ac-source-filename)) t)
'(bmkp-last-as-first-bookmark-file "~/.emacs.bmk")
'(safe-local-variable-values (quote ((eval add-hook (quote write-file-hooks) (quote time-stamp))))))
(defun ac-common-setup ()
(setq ac-sources (append ac-sources '(ac-source-dabbrev))))
(add-hook 'auto-complete-mode-hook 'ac-common-setup)
;; The mode that automatically startup.
(setq ac-modes
'(emacs-lisp-mode lisp-interaction-mode lisp-mode scheme-mode
c-mode c++-mode java-mode org-mode
perl-mode cperl-mode python-mode ruby-mode
ecmascript-mode javascript-mode php-mode css-mode
makefile-mode sh-mode fortran-mode f90-mode ada-mode
xml-mode sgml-mode latex-mode
haskell-mode literate-haskell-mode
asm-mode))
;;;http://code.google.com/p/ac-math latex模式下补全
;;;;增加补全项到latex-mode补全时用
(defun ac-latex-mode-setup () ; add ac-sources to default ac-sources
(setq ac-sources
(append '(ac-source-math-unicode ac-source-math-latex ac-source-latex-commands)
ac-sources))
)
(add-hook 'LaTeX-mode-hook 'ac-latex-mode-setup) ;;latex-mode调用时启用补全源增加函数,见上
(setq ac-math-unicode-in-math-p t) ;;use unicode input
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; C-common-mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Enables omnicompletion with `c-mode-common'.
(add-hook 'c-mode-common-hook
'(lambda ()
(add-to-list 'ac-omni-completion-sources
(cons "\\." '(ac-source-semantic)))
(add-to-list 'ac-omni-completion-sources
(cons "->" '(ac-source-semantic)))
(add-to-list 'ac-sources 'ac-source-etags)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; C++-mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Keywords.
(add-hook 'c++-mode-hook '(lambda ()
(add-to-list 'ac-sources )))
(add-to-list 'ac-trigger-commands 'org-self-insert-command) ; if you want enable auto-complete at org-mode, uncomment this line
(global-set-key (kbd "C-c a") 'auto-complete) ;全局设置补全快捷键
;;设置采用TAB键进行选中补全项 回车键换行不补全
(define-key ac-completing-map "\t" 'ac-complete)
(define-key ac-completing-map "\r" nil)
(global-auto-complete-mode 1)
(setq ac-auto-start 2) ;;输入两个字符后开始补全
;; Show 0.8 second later
(setq ac-auto-show-menu 0.1)
(setq ac-dwim t) ;Do what i mean
;;company-mode补全 Company stands for "complete anything" and is a modular in-buffer completion mechanism.
;;http://www.emacswiki.org/emacs/CompanyMode
(require 'company) ;代码自动补全
(require 'ac-company)
(autoload 'company-mode "company" nil t)
(setq company-idle-delay 0.2) ;延迟时间
(setq company-minimum-prefix-length 2) ;触发补全的字符数量
(setq company-show-numbers nil) ;不显示数字
(setq company-begin-commands '(self-insert-command)) ;;只有插入文字时才进行补全
(dolist (hook (list
'emacs-lisp-mode-hook
'lisp-mode-hook
'lisp-interaction-mode-hook
'scheme-mode-hook
'c-mode-hook
'c++-mode-hook
'java-mode-hook
'haskell-mode-hook
'asm-mode-hook
'emms-tag-editor-mode-hook
'sh-mode-hook
'org-mode
))
(add-hook hook 'company-mode))
(ac-company-define-source ac-source-company-elisp company-elisp)
(add-hook 'emacs-lisp-mode-hook
(lambda ()
(add-to-list 'ac-sources 'ac-source-company-elisp)))
;;CC-MODE c语言开发环境
;; Make a non-standard key binding. We can put this in
;; c-mode-base-map because c-mode-map, c++-mode-map, and so on,
;; inherit from it.
(require 'cc-mode)
(defun my-c-initialization-hook ()
(define-key c-mode-base-map "\C-m" 'c-context-line-break))
(add-hook 'c-initialization-hook 'my-c-initialization-hook)
;; offset customizations not in my-c-style
;; This will take precedence over any setting of the syntactic symbol
;; made by a style.
(setq c-offsets-alist '((member-init-intro . ++)))
;; Create my personal style.
(defconst my-c-style
'((c-tab-always-indent . t)
(c-comment-only-line-offset . 4)
(c-hanging-braces-alist . ((substatement-open after)
(brace-list-open)))
(c-hanging-colons-alist . ((member-init-intro before)
(inher-intro)
(case-label after)
(label after)
(access-label after)))
(c-cleanup-list . (scope-operator
empty-defun-braces
defun-close-semi))
(c-offsets-alist . ((arglist-close . c-lineup-arglist)
(substatement-open . 0)
(case-label . 4)
(block-open . 0)
(knr-argdecl-intro . -)))
(c-echo-syntactic-information-p . t))
"My C Programming Style")
(c-add-style "PERSONAL" my-c-style)
;; Customizations for all modes in CC Mode.
(defun my-c-mode-common-hook ()
;; set my personal style for the current buffer
(c-set-style "PERSONAL")
;; other customizations
(setq tab-width 4
;; this will make sure spaces are used instead of tabs
indent-tabs-mode nil)
;; we like auto-newline, but not hungry-delete
(c-toggle-auto-newline 1))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
;;代码浏览
;;;头文件导航
;;(require 'cedet)
(require 'eassist) ;;这个工具不错 ;h, cpp文件跳转函数, 支持即时按键选择 http://www.emacswiki.org/emacs/EAssist
(require 'sourcepair) ;;头文件导航
(define-key global-map "\C-xz" 'sourcepair-jump-to-headerfile) ;;跳转到头文件的设置
(setq sourcepair-source-path '( "." "../*" "../../*" ))
(setq sourcepair-header-path '( "." "include" "../include" "../*" "../../*"))
(setq sourcepair-recurse-ignore '( "CVS" "Debug" "Release" ))
(defun my-c-mode-common-hook ()
(define-key c-mode-base-map (kbd "M-o") 'eassist-switch-h-cpp)
(define-key c-mode-base-map (kbd "M-m") 'eassist-list-methods))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
(defun my-python-mode-hook ()
(define-key python-mode-map (kbd "M-m") 'eassist-list-methods))
(add-hook 'python-mode-hook 'my-python-mode-hook)
(define-key lisp-mode-shared-map (kbd "M-m") 'eassist-list-methods)
;;emacs 里面进行工程项目管理
;;;http://www.emacswiki.org/emacs/ProjectBufferMode
;;;http://www.emacswiki.org/emacs/FindFileInProject TODO
;;;http://www.emacswiki.org/emacs/eproject
(require 'etags) ;源代码导航 emacs库 http://www.emacswiki.org/emacs/EmacsTags
(require 'etags-extension) ;;etags加强插件
;;https://github.com/mattkeller/etags-update
(require 'etags-update);;自动更新etags
(global-set-key (kbd "") 'find-tag+) ;全局设置函数跳转快捷键
(global-set-key (kbd "") 'pop-tag-mark) ;全局设置函数跳转返回
;;select from mutiple tags
(require 'etags-select)
(global-set-key (kbd "C-c / M-t p") 'etags-select-find-tag-at-point)
(global-set-key (kbd "C-c / M-t s") 'etags-select-find-tag)
;;xCscope配置
;;;http://www.emacswiki.org/emacs/CScopeAndEmacs
(require 'xcscope)
(require 'xcscope+);;;;;;cscope的插件扩展 http://www.emacswiki.org/emacs/xcscope+.el
(setq cscope-do-not-update-database t)
;;Outline模式 大纲模式 用于隐藏一些不必要的文字
;;hideshow 模式设置
;;http://www.emacswiki.org/emacs/HideShow
;;;(require 'hideshow-fringe)
(load-library "hideshow")
;;Add markers to the fringe for regions foldable by hideshow.el
(autoload 'hideshowvis-enable "hideshowvis" "Highlight foldable regions")
(autoload 'hideshowvis-minor-mode
"hideshowvis"
"Will indicate regions foldable with hideshow in the fringe."
'interactive)
;;指定模式激活Hideshowvis 必须放在这个激活hideshow前面
(dolist (hook (list
'c-mode-hook
'java-mode-hook
'perl-mode-hook
'php-mode-hook
'emacs-lisp-mode-hook
'lisp-mode-hook
))
(add-hook hook 'hideshowvis-enable))
;;指定模式自动激活hideshow
(dolist (hook (list
'c-mode-hook
'java-mode-hook
'perl-mode-hook
'php-mode-hook
'emacs-lisp-mode-hook
'lisp-mode-hook
))
(add-hook hook 'hs-minor-mode))
;;Displaying overlay content in echo area or tooltip
(defun display-code-line-counts (ov)
(when (eq 'code (overlay-get ov 'hs))
(overlay-put ov 'help-echo
(buffer-substring (overlay-start ov)
(overlay-end ov)))))
(setq hs-set-up-overlay 'display-code-line-counts)
;;Other Options
;; Hide the comments too when you do a 'hs-hide-all'
(setq hs-hide-comments nil)
;; Set whether isearch opens folded comments, code, or both
;; where x is code, comments, t (both), or nil (neither)
(setq hs-isearch-open 'x)
;; Add more here
;;intel Hex 读取模式 http://www.emacswiki.org/emacs/IntelHexMode
(require 'intel-hex-mode)
;;在历史编辑中跳转 http://www.emacswiki.org/emacs/GotoChg
(require 'goto-last-change)
(global-set-key "\C-x\C-\\" 'goto-last-change) ;;设置跳转快捷键
;;历史文件访问
(require 'recentf)
(require 'recentf-ext)
(setq recentf-max-saved-items 100) ;最近打开文件的最大数量
(setq recentf-auto-cleanup 300) ;自动清理最近打开文件列表中重复或其他文件的时间间隔 (秒)
;;;(setq recentf-auto-cleanup 'never) ;; disable before we start recentf!
(recentf-mode 1) ;;启用历史文件模式
(load "recentf-buffer")
(global-set-key [?\C-c ?r ?f] 'recentf-open-files-in-simply-buffer)
;;通过TAGS文件访问头文件 不是很好用 http://www.emacswiki.org/emacs/find-file-in-tags
(require 'find-file-in-tags)
(global-set-key (read-kbd-macro "C-c / M-i") 'find-file-in-tags)
;;; ### Uniquify ###
;;; --- 相同缓存名字时加上路径以区别
(require 'uniquify) ;如果有两个重名buffer, 则再前面加上路径区别 emacs库
(setq uniquify-buffer-name-style 'post-forward-angle-brackets) ;反方向的显示重复的Buffer名字
(setq uniquify-separator "/") ;分隔符
(setq uniquify-after-kill-buffer-p t) ;删除重复名字的Buffer后重命名
(require 'color-moccur) ;人性化的搜索功能 http://www.emacswiki.org/emacs/color-moccur.el
(require 'moccur-edit) ;搜索编辑 依赖于color-moccur http://www.emacswiki.org/emacs/moccur-edit.el
;;; ### Color moccur ###
;;; --- 增强的Buffer搜索
(setq moccur-kill-moccur-buffer t) ;退出buffer时自动关闭其buffer
(setq moccur-edit-highlight-edited-text t) ;高亮编辑过的内容
(defadvice moccur-edit-change-file ;编辑过后自动保存buffer
(after save-after-moccur-edit-buffer activate)
"Automatically save buffer when edit in moccur."
(save-buffer))
(require 'ediff) ;文件比较功能 emacs库 http://www.emacswiki.org/emacs/EdiffMode
(require 'ediff+) ;ediff增强 http://www.emacswiki.org/emacs/ediff+.el
(require 'browse-kill-ring) ;超强恢复 http://www.emacswiki.org/emacs/BrowseKillRing
(require 'org-extension) ;;org模式增强
(require 'buffer-extension) ;;buffer操作增强
;;用M-x执行某个命令的时候,在输入的同时给出可选的命令名提示
(require 'icomplete)
(icomplete-mode 99) ;;启用M-x命令提示
(eval-after-load "icomplete" '(progn (require 'icomplete+))) ;;icomplete模式增强
;; ;;Mcomplete Mode == IcompleteMode + IswitchBuffers 这个 模式容易出问题
;; (require 'mcomplete)
;; (load "mcomplete-history")
;; (autoload 'mcomplete-mode "mcomplete"
;; "Toggle minibuffer completion with prefix and substring matching."
;; t nil)
;; (autoload 'turn-on-mcomplete-mode "mcomplete"
;; "Turn on minibuffer completion with prefix and substring matching."
;; t nil)
;; (autoload 'turn-off-mcomplete-mode "mcomplete"
;; "Turn off minibuffer completion with prefix and substring matching."
;; t nil)
;; (turn-on-mcomplete-mode)
;; 用ibuffer代替默认的buffer switch
;; 参考 http://www.emacswiki.org/emacs/IbufferMode
;; http://www.emacswiki.org/emacs/ibuffer%E6%A8%A1%E5%BC%8F
;; ibuffer是emacs自带的,可用 M-x ibuffer 调出来
;; 下面只是将快捷键 C-x C-b 映射为调出ibuffer的命令
;; 在ibuffer中的操作方式和dired mode一样
;; n和p是上下,m是选中该文件,可选多个,D是kill buffer
;; 回车或者按e(就是edit)来编辑文件
;; 在ibuffer页面,用英文斜线来通过关键字过滤缩小显示文件范围
;; 比如 “ /日记 ” ,就会只显示buffer名称中有日记这两个字的
;; / 后面支持正则表达式 如 /200?
;; 撤销过滤按两下/,就是按 “ // ”
;; 在ibuffer中,按英文等号 “ = ” 对为保存文件和它上一个保存版本做diff
;; 按 g 刷新文件目录
(require 'ibuffer)
(global-set-key (kbd "C-x C-b") 'ibuffer)
(autoload 'ibuffer "ibuffer" "List buffers." t)
;;显示时默认隐藏所有以*开头的的文件
(require 'ibuf-ext)
;;(add-to-list 'ibuffer-never-show-predicates "^\\*") ;;启用这句话时就忽略所有以*开头的文件
;;http://www.emacswiki.org/emacs/BufferMenuPlus
(require 'buff-menu+)
;;; --- 交互式Buffer
(setq ibuffer-sorting-mode 'recency) ;用最近打开模式显示
;;emacs中管理多个终端的工具
;;http://www.emacswiki.org/emacs/MultiTerm
(require 'multi-term)
(setq multi-term-program "/bin/bash")
;;注释工具
;;;代码加框注释
;;;还未添加其快捷键
(require 'rebox2)
(require 'edit-misc) ;;ahei写的一些快捷编辑的插件
(global-set-key (kbd "C-c / C-c") 'comment) ;;智能加注释
(global-set-key (kbd "C-c / M-c") 'uncomment) ;;智能去注释
;;doxymacs注释工具
(require 'doxymacs)
(add-hook 'c-mode-common-hook 'doxymacs-mode);;访问C/C++文件时启用doxymacs模式
;;If you want Doxygen keywords fontified use M-x doxymacs-font-lock
;;doxymacs 快捷键
;; 命令
英文解释
中文解释
;; C-c d ?
will look up documentation for the symbol under the point.
查找当前鼠标点下的符号的文档
;; C-c d r
will rescan your Doxygen tags file.
重新扫描tags文件
;; C-c d f
will insert a Doxygen comment for the next function.
为函数插入Doxygen注释
;; C-c d i
will insert a Doxygen comment for the current file.
为文件插入Doxygen注释
;; C-c d ;
will insert a Doxygen comment for the current member.
为当前成员插入Doxygen注释
;; C-c d m
will insert a blank multiline Doxygen comment.
插入多行注释
;; C-c d s
will insert a blank singleline Doxygen comment.
插入单行注释
;; C-c d @
will insert grouping comments around the current region.
插入环绕当前区域的注释
(defun my-doxymacs-font-lock-hook ()
(if (or (eq major-mode 'c-mode) (eq major-mode 'c++-mode))
(doxymacs-font-lock)))
(add-hook 'font-lock-mode-hook 'my-doxymacs-font-lock-hook)
(setq doxymacs-doxygen-style "C++") ;;设置默认模板为C++
;;Doxymacs C/C++注释模板
;;;doxymacs C/C++文件头注释模板
(defconst doxymacs-C++-file-comment-template
'(
"/*" > n
"*" " =====================================================================================" > n
"*" > n
"*" " Filename: "
(if (buffer-file-name)
(file-name-nondirectory (buffer-file-name))
"") > n
"*" > n
"*" " Description: " (p "Brief description of this file: ") > n
"*" > n
"*" " "> n
"*" > n
"*" " Version: " "0.1"> n
"*" " Created: " (current-time-string) > n
"*" > n
"*" " Authors: " (user-full-name) (concat " , " user-mail-address) > n
"*" " Company: " my-company > n
"*" " Revision: " > n
"*" " ======================================================================================" > n
"*" " @0.1 " (concat (user-full-name) " ") (concat (current-time-string) " , create orignal file") > n
"*" " ======================================================================================" > n
"*" " Copyright (c) 2012, " my-company > n
"*" " ======================================================================================" > n
"*/" > n)
"Default C++-style template for file documentation.")
;;;Doxymacs C/C++函数注释模板
(defconst doxymacs-C++-function-comment-template
'((let ((next-func (doxymacs-find-next-func)))
(if next-func
(list
'l
"/** " '> 'n
" * " 'p '> 'n
" * " '> 'n
;" * === FUNCTION ======================================================================" > n
(doxymacs-parm-tempo-element (cdr (assoc 'args next-func)))
(unless (string-match
(regexp-quote (cdr (assoc 'return next-func)))
doxymacs-void-types)
'(l " * " > n " * " (doxymacs-doxygen-command-char)
"return " (p "Returns: ") > n))
" */" '>)
(progn
(error "Can't find next function declaration.")
nil))))
"Default C++-style template for function documentation.")
(defconst doxymacs-C++-function-comment-template
'((let ((next-func (doxymacs-find-next-func)))
(if next-func
(list
'l
" " '> 'n
"/* " '> 'n
"*" " === FUNCTION ========================================================================" '> 'n
"*" " Name: " (cdr (assoc 'func (doxymacs-find-next-func)))
(if (string-match (regexp-quote "static") (cdr (assoc 'return next-func)))
"") '> 'n
"*" " Description: " '(p "Brief description of this file: ") '> 'n
"*" " Parameters: " '> 'n
(doxymacs-parm-tempo-element (cdr (assoc 'args next-func)))
(unless (string-match
(regexp-quote (cdr (assoc 'return next-func)))
doxymacs-void-types)
'(l "* " > n "* "
"Return Value: " (p "Returns: ") > n))
"*" " Created: " (current-time-string) (concat " by" (user-full-name)) '> 'n
"*" " Revision: " '> 'n
"*" " =======================================================================================" '> 'n
"*" " @0.1 " (concat (user-full-name) " ") (concat (current-time-string) " , create orignal file") '> 'n
"*" " =======================================================================================" '> 'n
"*" " Copyright (c) 2012, " my-company '> 'n
"*" " =======================================================================================" '> 'n
"*/" '> 'n)
(progn
(error "Can't find next function declaraton.")
nil))))
"Default C++-style template for function documentation.")
;;;Doxymacs 单行C/C++注释模板
(defconst doxymacs-C++-blank-singleline-comment-template
'("/* " p " */")
"Default C++-style template for a blank single line doxygen comment.")
;;;Doxymacs 多行C/C++注释模板
(defconst doxymacs-C++-blank-multiline-comment-template
'(
> n
"/*" > n
"* " p > n
"* " > n
"* " "Add by " (user-full-name) (concat " , " (current-time-string)) > n
"*/" > n)
"Default C++-style template for a blank multiline doxygen comment.")
;;flymake语法检测
;;flymake是一个实时的语法检查工具,好像是从emacs22开始已经自带flymake,自带的flymake提供了对C,C++,XML,HTML,C#,perl,php,java,tex,idl的支持。
;;http://emacser.com/flymake.htm
;;http://www.emacswiki.org/emacs/FlyMake
;;http://flymake.sourceforge.net/
(require 'flymake)
(require 'flymake-shell)
;;flymake-extension 依赖于fringehelper
;;http://www.emacswiki.org/emacs/FringeHelper http://nschum.de/src/emacs/fringe-helper/
(require 'fringe-helper)
(require 'flymake-extension)
;;flymake
(dolist (hook (list
'c-mode-hook
'c++-mode-hook
'java-mode-hook
))
(add-hook hook 'flymake-find-file-hook))
;; flymake-shell
(add-hook 'sh-mode-hook 'flymake-shell-load)
;; flymake extension
(setq flymake-extension-use-showtip t) ;use `shotip' display error or warning.
;;flymake快捷键设置
(global-set-key (kbd "C-c \ f C-n") 'flymake-show-next-error);;显示下一个错误
(global-set-key (kbd "C-c \ f C-p") 'flymake-show-prev-error);;显示前一个错误
;;emacs中处理链接
;;Linkd模式 http://dto.github.com/notebook/linkd.html
(require 'linkd)
(setq linkd-use-icons t)
(setq linkd-icons-directory (concat my-emacs-lisps-path ".linkd-icons")) ;; 设置linked模式的图标所在位置
(add-hook 'emacs-lisp-mode-hook 'linkd-mode)
(add-hook 'lisp-mode-hook 'linkd-mode)
(add-hook 'sh-mode-hook 'linkd-mode)
(add-hook 'text-mode-hook 'linkd-mode)
(add-hook 'cc-mode 'linkd-mode)
(global-set-key [(control \&)] 'linkd-follow-on-this-line)
;;由于滚轮上滚和linkd模式的 linkd-back 所以将linkd.el中的快捷键设置注释掉了,这里需要注意
;;(global-set-key [mouse-4] 'mwheel-scroll);;去掉滚轮上滚时和Linkd-back快捷键冲突,导致鼠标无法控制上下滚动
;; (global-set-key [(control f3)] 'linkd-process-block)
;; (global-set-key (kbd "M-[") 'linkd-previous-link)
;; (global-set-key (kbd "M-]") 'linkd-next-link)
;; (global-set-key (kbd "M-RET") 'linkd-follow-at-point)
;;IDO模式
;;lets you interactively do things with buffers and files.
;;http://www.masteringemacs.org/articles/2010/10/10/introduction-to-ido-mode/
;;http://www.emacswiki.org/emacs/InteractivelyDoThings
(require 'ido)
(require 'idomenu)
(autoload 'idomenu "idomenu" nil t)
(setq ido-enable-flex-matching t)
(setq ido-everywhere t)
(ido-mode t);;启用ido模式 有一段时间无法启用ido的原因 是由于ido.el是emacs23自带的 而我在我的插件目录下有ido.el有冲突,所以去掉就可以初始化了
;;(setq ido-enable-flex-matching t) ;模糊匹配
;;Dired增强 http://www.emacswiki.org/emacs/DiredPlus
;;http://lifegoo.pluskid.org/wiki/EnhanceDired.html 中文介绍
(require 'dired+)
(require 'files+)
(require 'thingatpt+)
(require 'misc-fns)
(require 'strings)
;;(require 'dired-details+);;不是很好用啊
(require 'mouse3) ;;Customizable behavior for `mouse-3'.
;;Bookmark增强 http://www.emacswiki.org/emacs/BookmarkPlus
(require 'bookmark+)
;;在dired中使用同一buffer打开dired子目录
(setq dired-listing-switches "-aluh") ;传给 ls 的参数
(setq directory-free-space-args "-Pkh") ;目录空间选项
(setq dired-omit-size-limit nil) ;dired忽略的上限
(setq dired-dwim-target t) ;Dired试着猜处默认的目标目录
(setq my-dired-omit-status t) ;设置默认忽略文件
(setq my-dired-omit-regexp "^\\.?#\\|^\\..*") ;设置忽略文件的匹配正则表达式
(setq my-dired-omit-extensions '(".cache")) ;设置忽略文件的扩展名列表
(add-hook 'dired-after-readin-hook 'dired-sort-method) ;先显示目录, 然后显示文件
(add-hook 'dired-mode-hook 'dired-omit-method) ;隐藏文件的方法
(diredp-toggle-find-file-reuse-dir 1) ;;设置在同一个buffer中打开文件夹,而不是另开窗口
(require 'find-dired-)
(require 'find-dired)
(require 'find-dired+)
(require 'wuxch-dired)
(setq autofit-frames-flag nil) ;;禁止自动适应窗口
;;(put 'dired-find-alternate-file 'disabled nil)
(require 'dired-extension);;Some extension for dired
(global-set-key (kbd "C-x d") 'dired-jump)
(require 'dired+-face-settings)
;;使用单个 buffer
;;;dired-single专门为这个问题而设计,他可以保证所有的 dired buffer 都 使用同一个名字,换句话说,总是只会有一个 dired buffer 存在,并且我们可 以方便地跳到那个 buffer ,如果 buffer 不存在的话
;; (require 'dired-single)
;; (defun my-dired-init ()
;; "Bunch of stuff to run for dired, either immediately or when it's
;; loaded."
;; ;;
;; (define-key dired-mode-map [return] 'joc-dired-single-buffer)
;; (define-key dired-mode-map [mouse-1] 'joc-dired-single-buffer-mouse)
;; (define-key dired-mode-map "^"
;; (function
;; (lambda nil (interactive) (joc-dired-single-buffer "..")))))
;; ;; if dired's already loaded, then the keymap will be bound
;; (if (boundp 'dired-mode-map)
;; ;; we're good to go; just add our bindings
;; (my-dired-init)
;; ;; it's not loaded yet, so add our bindings to the load-hook
;; (add-hook 'dired-load-hook 'my-dired-init))
(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.
'(diredp-date-time ((((type tty)) :foreground "yellow") (t :foreground "goldenrod1")))
'(diredp-dir-heading ((((type tty)) :background "yellow" :foreground "blue") (t :background "Pink" :foreground "DarkOrchid1")))
'(diredp-display-msg ((((type tty)) :foreground "blue") (t :foreground "cornflower blue"))))
;;Tex排版开发环境设置
;;;http://www.emacswiki.org/emacs/AUCTeX
;;;http://www.gnu.org/software/auctex/
;;;http://www.emacswiki.org/emacs/LaTeX
;;;http://www.emacswiki.org/emacs/TeXmacs
;;;http://www.emacswiki.org/emacs/LaTeXMathPreview
;;;http://www.emacswiki.org/emacs/WhizzyTeX
(require 'flyspell)
(load "auctex")
(load "preview-latex")
(require 'tex-mik)
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil)
(add-hook 'LaTeX-mode-hook 'visual-line-mode)
(add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
(add-hook 'LaTeX-mode-hook 'flyspell-mode)
(setq reftex-plug-into-AUCTeX t)
(setq TeX-PDF-mode t)
;;anything插件 暂时没有研究 不会使用 据说很牛B
;;It provides a totally new Emacs experience. While normal Emacs way is specifying action then selecting candidates,
;;the anything way is narrowing and selecting candidates then executing action for selected candidates.
;;http://www.emacswiki.org/emacs/Anything
;;http://metasandwich.com/2010/07/30/what-can-i-get-for-10-dolla-anything-el/
;;http://metasandwich.com/2010/08/01/anything-else/
(require 'anything)
(require 'anything-match-plugin)
;;(require 'anything-config) ;;开启这个会有很多bug,暂时不想解决
;;自动下载插件的插件 autoinstall
;;;http://www.emacswiki.org/emacs/auto-install.el
;;http://www.emacswiki.org/emacs/AutoInstall
(require 'auto-install)
(setq auto-install-directory "~/.emacs.d/auto-install/");;设置插件下载目录
;;emacs的server设置 只在emacs server没有启动时开启服务
;;;http://www.emacswiki.org/emacs/EmacsClient
;;;http://www.emacswiki.org/emacs/EmacsAsDaemon
;;;http://www.emacswiki.org/emacs/RemoteEmacs
;;;http://lifegoo.pluskid.org/wiki/FasterEmacs.html
;;; only start emacs server when it's not started, I hate warnings.
(setq server-socket-file "/tmp/emacs1000/server")
(unless (file-exists-p server-socket-file)
(server-start))
;; (add-hook 'server-switch-hook
;;
(lambda nil
;;
(let ((server-buf (current-buffer)))
;;
(bury-buffer)
;;
(switch-to-buffer-other-frame server-buf))))
;;This function may be useful if you are always in a client. I bind it to C-c q. So I don't need to use C-x # or C-x 5 0 any more.
(defun exit-emacs-client ()
"consistent exit emacsclient.
if not in emacs client, echo a message in minibuffer, don't exit emacs.
if in server mode
and editing file, do C-x # server-edit
else do C-x 5 0 delete-frame"
(interactive)
(if server-buffer-clients
(server-edit)
(delete-frame)))
(global-set-key (kbd "C-c q") 'exit-emacs-client)