.emacs

;;start the emacs with the server mode
;;(server-start)

;;close startup screen
(tool-bar-mode -1)
(menu-bar-mode -1)
(setq inhibit-startup-message t)
(setq initial-scratch-message "")

;;显示行号
(global-linum-mode 1)
;; (global-linum-mode 0)

;; (define-key key-translation-map [(meta v)] [(control v)])


(global-set-key (kbd "M-j") 'newline-and-indent)
(global-set-key (kbd "C-j") (kbd "RET"))


;;允许使用C-z作为命令前缀
(define-prefix-command 'ctl-z-map)
(global-set-key (kbd "C-z") 'ctl-z-map)
;; (global-set-key (kbd "M-h") 'ctl-z-map)
;;用C-z i快速打开~/.emacs文件。
(defun open-init-file ( )
(interactive)
(find-file "~/.emacs"))

(global-set-key "\C-zi" 'open-init-file)


;;用C-z r重新加载~/.emacs文件。
(defun reload-init-file ( )
(interactive)
(load-file "~/.emacs")
(eval-buffer))

(global-set-key "\C-zr" 'reload-init-file)


;;C-Space输入法占用,改用C-c C-m来标记文本块
(global-set-key "\C-cm" 'set-mark-command)
;(global-set-key "\C-c<RET>" 'set-mark-command)
;;以y/n替代yes/no
(fset 'yes-or-no-p 'y-or-n-p)

;;用C-z k快速打开自定义的按键说明文件
(defun open-key-info-file ()
(interactive)
(split-window-horizontally)
(find-file-other-window "~/emacskeys.txt")
(outline-mode)
(hide-body))

(global-set-key "\C-zk" 'open-key-info-file)


;;启动0.3秒后自动最大化 (windows下)
(run-with-idle-timer 0.3 nil 'w32-send-sys-command 61488)


;(setq menu-bar-showhide-tool-bar-menu-customize-disable t)

;(setenv "HOME" "F:/emacs")
;(setenv "PATH" "F:/emacs")
;;set the default file path
(setq default-directory "~/")

;(setq load-path (cons "~/Emacs" load-path))
;(global-font-lock-mode t)

;;;;;;;;;;;;;;;;;set the font begin
;; Setting English Font
;; (set-face-attribute
;; 'default nil :font "Consolas 16")
;; ;; 'default nil :font "Monaco 10")
;; ;; Chinese Font
;; (dolist (charset '(kana han symbol cjk-misc bopomofo))
;; (set-fontset-font (frame-parameter nil 'font)
;; charset
;; (font-spec :family "Microsoft Yahei" :size 16)))
;;;;;(setq face-font-rescale-alist '(("微软雅黑" . 1.2) ("Microsoft Yahei" . 1.2) ("WenQuanYi Zen Hei" . 1.2)))
;;;;;;;;;;;;;;;;;set the font end


;;settting the font again begin p

;; This script is set for a `text-scale-mode-step` of `1.04`
;; (setq text-scale-mode-step 1.04)
(setq text-scale-mode-step 1.1)

(defun qiang-font-existsp (font)
(if (null (x-list-fonts font))
nil t))

(defun qiang-make-font-string (font-name font-size)
(if (and (stringp font-size)
(equal ":" (string (elt font-size 0))))
(format "%s%s" font-name font-size)
(format "%s-%s" font-name font-size)))

(defun qiang-set-font (english-fonts
english-font-size
chinese-fonts)
"english-font-size could be set to \":pixelsize=18\" or a integer.
If set/leave chinese-font-size to nil, it will follow english-font-spize"
(require 'cl) ; for find if
(let ((en-font (qiang-make-font-string
(find-if #'qiang-font-existsp english-fonts)
english-font-size))
(zh-font (font-spec :family (find-if #'qiang-font-existsp chinese-fonts))))

;; Set the default English font
;;
;; The following 2 method cannot make the font settig work in new frames.
;; (set-default-font "Consolas:pixelsize=18")
;; (add-to-list 'default-frame-alist '(font . "Consolas:pixelsize=18"))
;; We have to use set-face-attribute
(message "Set English Font to %s" en-font)
(set-face-attribute
'default nil :font en-font)

;; Set Chinese font
;; Do not use 'unicode charset, it will cause the english font setting invalid
(message "Set Chinese Font to %s" zh-font)
(dolist (charset '(kana han symbol cjk-misc bopomofo))
(set-fontset-font t
charset
zh-font))))

(setq face-font-rescale-alist '(("Microsoft Yahei" . 1.2) ("WenQuanYi Zen Hei" . 1.2)))
(qiang-set-font
'("Monaco" "Consolas" "DejaVu Sans Mono" "Monospace" "Courier New") 10.5
'("Microsoft Yahei" "文泉驿等宽微米黑" "黑体" "新宋体" "宋体"))


(set-face-attribute 'default nil :font (font-spec))

; here are 20 hanzi and 40 english chars, see if they are the same width
; 你你你你你你你你你你你你你你你你你你你你
; aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

;;;;;;;;;;;;;;;;;setting the fond again end


;; (defun qiang-comment-dwim-line (&optional arg)
;; "Replacement for the comment-dwim command."
;; (interactive "*P")
;; (comment-normalize-vars)
;; (if (and (not (region-active-p)) (not (looking-at "[ \t]*$")))
;; (comment-or-uncomment-region (line-beginning-position) (line-end-position))
;; (comment-dwim arg)))
;; (global-set-key (kbd "C-;") 'qiang-comment-dwim-line)

(defun qiang-comment-dwim-line (&optional arg)
"Replacement for the comment-dwim command. If no region is selected and current line is not blank and we are not at the end of the line, then comment current line. Replaces default behaviour of comment-dwim, when it inserts comment at the end of the line."
(interactive "*P")
(comment-normalize-vars)
(if (and (not (region-active-p)) (not (looking-at "[ \t]*$")))
(comment-or-uncomment-region (line-beginning-position) (line-end-position))
(comment-dwim arg)))
(global-set-key "\M-;" 'qiang-comment-dwim-line)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;for cc mode
(setq c-basic-offset 8)


;;w3m配置项(用于上网)
;(add-to-list 'load-path "f:/emacs/.emacs.d/w3m-lisp") ;;w3m所需要的lisp文件,所在路径
;(add-to-list 'load-path "f:/emacs/site-lisp") ;;w3m所需要的lisp文件,所在路径
;(add-to-list 'load-path "f:/emacs/site-lisp/w3m") ;;w3m所需要的lisp文件,所在路径
(add-to-list 'load-path "f:/emacs/site-lisp/emacs-w3m") ;;w3m所需要的lisp文件,所在路径
;(add-to-list 'exec-path "f:/emacs/.emacs.d/w3m") ;;指定w3m可执行程序,所在的执行路径

(require 'w3m-load)
(setq w3m-use-favicon nil)
(setq w3m-command-arguments '("-cookie" "-F"))
(setq w3m-use-cookies t) ;打开cookie支持
;(setq w3m-home-page "www.google.com") ;设置主页
;(setq w3m-home-page "www.google.com.hk") ;设置主页
(setq w3m-home-page "www.baidu.com") ;设置主页
;(setq w3m-home-page "g.cn") ;设置主页
(setq w3m-default-display-inline-image t) ;显示图片
(setq w3m-default-toggle-inline-images t)
;(setq w3m-link-numbering-mode t);by default set the number of the web link
(w3m-link-numbering-mode 1);by default set the number of the web link
(setq browse-url-browser-function 'w3m-browse-url)
(setq w3m-use-title-buffer-name t)
;;;;;;;;;;;;;;end of configuration of w3m


;; rectangle
(require 'rect-mark)
(global-set-key (kbd "C-x r C-@") 'rm-set-mark)
(global-set-key (kbd "C-x r C-x C-x") 'rm-exchange-point-and-mark)
(global-set-key (kbd "C-x r C-w") 'rm-kill-region)
(global-set-key (kbd "C-x r M-w") 'rm-kill-ring-save)
(global-set-key (kbd "C-x r C-y") 'yank-rectangle)

(add-to-list 'load-path "~/.emacs.d/")
(require 'color-theme)
(color-theme-initialize)
;; (color-theme-matrix)
;; (color-theme-vim-colors)
(color-theme-oswald)


;for lots of plugin
(add-to-list 'load-path "f:/emacs/.emacs.d")

;;;for the auto-complete

;;-------------------------------------------------------------
;;Auto complete
;;-------------------------------------------------------------

(add-to-list 'load-path "~/.emacs.d/auto-complete-1.3.1/")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "f:/emacs/.emacs.d/ac-dict")
(ac-config-default)

;;;;;setting my cedet

;;avoid compile error
(setq byte-compile-warnings nil)

(load-file "~/.emacs.d/cedet-1.1/common/cedet.el")
(require 'cedet)

;; (semantic-load-enable-minimum-features)
(semantic-load-enable-code-helpers)
;; (semantic-load-enable-guady-code-helpers)
;; (semantic-load-enable-excessive-code-helpers)
(semantic-load-enable-semantic-debugging-helpers)

;; (setq semanticdb-project-roots (list (expand-file-name "/")))
(defconst cedet-user-include-dirs
(list ".." "../include" "../inc" "../common" "../public"
"../.." "http://www.cnblogs.com/include" "http://www.cnblogs.com/inc" "http://www.cnblogs.com/common" "http://www.cnblogs.com/public"))
(defconst cedet-win32-include-dirs
;; (list "C:/MinGW/include"
;; "C:/MinGW/include/c++/3.4.5"
;; "C:/MinGW/include/c++/3.4.5/mingw32"
;; "C:/MinGW/include/c++/3.4.5/backward"
;; "C:/MinGW/lib/gcc/mingw32/3.4.5/include"
;; "C:/Program Files/Microsoft Visual Studio/VC98/MFC/Include"
(list "c:/Program Files/Microsoft Visual Studio 8/VC/include"))

(require 'semantic-c nil 'noerror)
(let ((include-dirs cedet-user-include-dirs))
(when (eq system-type 'windows-nt)
(setq include-dirs (append include-dirs cedet-win32-include-dirs)))
(mapc (lambda (dir)
(semantic-add-system-include dir 'c++-mode)
(semantic-add-system-include dir 'c-mode))
include-dirs))

(global-set-key (kbd "C-c C-j") 'semantic-ia-fast-jump)

;; (global-set-key [S-F12]
;; (lambda ()
;; (interactive)
;; (if (ring-empty-p (oref semantic-mru-bookmark-ring ring))
;; (error "Semantic Bookmark ring is currently empty"))
;; (let* ((ring (oref semantic-mru-bookmark-ring ring))
;; (alist (semantic-mrub-ring-to-assoc-list ring))
;; (first (cdr (car alist))))
;; (if (semantic-equivalent-tag-p (oref first tag)
;; (semantic-current-tag))
;; (setq first (cdr (car (cdr alist)))))
;; (semantic-mrub-switch-tags first))))

;; (define-key c-mode-base-map [M-S-f12] 'semantic-analyze-proto-impl-toggle)

;; (define-key c-mode-base-map (kbd "M-n") 'semantic-ia-complete-symbol-menu)

;; ;;------------------------------------------------
;; ;;cedet 安装
;; ;;------------------------------------------------
;; ;Currently CEDET issues a warning
;; ;“Warning: cedet-called-interactively-p called with 0 arguments, but requires 1”,
;; ; which can be suppressed by
;; ;adding (setq byte-compile-warnings nil) in your .emacs filebeforeCEDET is loaded
;; (setq byte-compile-warnings nil)

;; (add-hook 'texinfo-mode-hook (lambda () (require 'sb-texinfo)))
;; (load-file "~/.emacs.d/cedet-1.1/common/cedet.el")
;; (require 'cedet)
;; ;;(semantic-load-enable-minimum-features)
;; (semantic-load-enable-code-helpers)
;; ;;(semantic-load-enable-guady-code-helpers)
;; ;(semantic-load-enable-excessive-code-helpers)
;; ;(semantic-load-enable-semantic-debugging-helpers)
;; ;(autoload 'speedbar-frame-mode "speedbar" "Popup a speedbar frame" t)
;; ;(autoload 'speedbar-get-focus "speedbar" "Jump to speedbar frame" t)
;; ;(define-key-after (lookup-key global-map [menu-bar tools])
;; ; [speedbar]
;; ; '("Speedbar" .
;; ; speedbar-frame-mode)
;; ; [calendar])
;; ;; 指定semantic临时文件的路径,避免到处都是临时文件
;; (setq semanticdb-default-save-directory "~/backups/emacs/semantic")
;; ;;;;C/C++语言启动时自动加载semantic对/usr/include的索引数据库
;; ;setq semanticdb-search-system-databases t)
;; ;add-hook 'c-mode-common-hook
;; ;lambda ()
;; ;setq semanticdb-project-system-databases
;; ;list (semanticdb-create-database
;; ;emanticdb-new-database-class
;; ;/usr/include")))))
;; (enable-visual-studio-bookmarks) ;开启高亮书签
;; (require 'eassist nil 'noerror) ;开启头文件和源文件之间的跳转功能
;; (require 'semantic-tag-folding nil 'noerror) ;;使用semantic的代码折叠功能


;; ;; ;;for the ecb
;; (add-to-list 'load-path
;; "~/.emacs.d/ecb-2.40")
;; (require 'ecb-autoloads)

;; ;;for yasnippet
;; (add-to-list 'load-path
;; "~/.emacs.d/yasnippet")
;; (require 'yasnippet)
;; (yas-global-mode 1)

;; ;;for the auto-complete-clang


;; ;(add-to-list 'load-path (concat myoptdir "AC"))
;; ;(require 'auto-complete-config)
;; ;(add-to-list 'ac-dictionary-directories (concat myoptdir "AC/ac-dict"))
;; (add-to-list 'load-path "~/.emacs.d/auto-complete-clang")
;; (require 'auto-complete-clang)

;; (setq ac-auto-start nil)
;; (setq ac-quick-help-delay 0.5)
;; ;; (ac-set-trigger-key "TAB")
;; ;; (define-key ac-mode-map [(control tab)] 'auto-complete)
;; (define-key ac-mode-map [(control tab)] 'auto-complete)
;; (defun my-ac-config ()
;; (setq-default ac-sources '(ac-source-abbrev ac-source-dictionary ac-source-words-in-same-mode-buffers))
;; (add-hook 'emacs-lisp-mode-hook 'ac-emacs-lisp-mode-setup)
;; ;; (add-hook 'c-mode-common-hook 'ac-cc-mode-setup)
;; (add-hook 'ruby-mode-hook 'ac-ruby-mode-setup)
;; (add-hook 'css-mode-hook 'ac-css-mode-setup)
;; (add-hook 'auto-complete-mode-hook 'ac-common-setup)
;; (global-auto-complete-mode t))
;; (defun my-ac-cc-mode-setup ()
;; (setq ac-sources (append '(ac-source-clang ac-source-yasnippet) ac-sources)))
;; (add-hook 'c-mode-common-hook 'my-ac-cc-mode-setup)
;; ;; ac-source-gtags
;; (my-ac-config)

;;;for tabbar
;;-----------------------------------------------------------------------
;;加载tabbar
;;-----------------------------------------------------------------------
(require 'tabbar)
(tabbar-mode 1)


;(global-set-key [(meta j)] 'tabbar-backward)
;(global-set-key [(meta k)] 'tabbar-forward)

;; 设置tabbar外观
;; 设置默认主题: 字体, 背景和前景颜色,大小
;;(set-face-attribute 'tabbar-default-face nil
;; :family "DejaVu Sans Mono"
;; :background "gray80"
;; :foreground "gray30"
;; :height 1.0
;; )
;; 设置左边按钮外观:外框框边大小和颜色
;;(set-face-attribute 'tabbar-button-face nil
;; :inherit 'tabbar-default
;; :box '(:line-width 1 :color "yellow70")
;; )
;; 设置当前tab外观:颜色,字体,外框大小和颜色
;;(set-face-attribute 'tabbar-selected-face nil
;; :inherit 'tabbar-default
;; :foreground "DarkGreen"
;; :background "LightGoldenrod"
;; :box '(:line-width 2 :color "DarkGoldenrod")
;; :overline "black"
;; :underline "black"
;; :weight 'bold
;; )
;; ;; 设置非当前tab外观:外框大小和颜色
;; (set-face-attribute 'tabbar-unselected-face nil
;; :inherit 'tabbar-default
;; :box '(:line-width 2 :color "#00B2BF")
;; )

;;;;;;;;;;for;; highlight-symbol
;; ;(add-to-list 'load-path "/path/to/highlight-symbol")
;; (require 'highlight-symbol)

;; (global-set-key [(control f3)] 'highlight-symbol-at-point)
;; (global-set-key [f3] 'highlight-symbol-next)
;; (global-set-key [(shift f3)] 'highlight-symbol-prev)
;; (global-set-key [(meta f3)] 'highlight-symbol-prev)


;; ;; ;;;;;;;;;;; for character setting
;; ;; (if (equal current-language-environment "UTF-8")

;; ;; (prefer-coding-system 'gb2312)

;; ;; (prefer-coding-system 'Utf-8)

;; ;; )

;; ;; )

;; ;; )
;; ;; (add-hook 'set-language-environment-hook 'utf8gbk)

;; ;; (set-lanaguage-environment 'UTF-8)

;; ;; for indent
;; ;; emacs的缩进方式和其它编辑器有些不同,text-mode下不能tab,只能用C-q tab才行。
;; ;; c-mode或cc-mode下缩进只有2格,这个当然不符合大多数人的习惯,如果要设为4:
;; ;; (add-hook 'c-mode-hook
;; ;; '(lambda ()
;; ;; (c-set-style "Stroustrup")))

;; ;;;; CC-mode配置 http://cc-mode.sourceforge.net/
;; (require 'cc-mode)
;; (c-set-offset 'inline-open 0)
;; (c-set-offset 'friend '-)
;; (c-set-offset 'substatement-open 0)

;; ;;;;我的C/C++语言编辑策略

;; (defun my-c-mode-common-hook()
;; (setq tab-width 4 indent-tabs-mode nil)
;; ;;; hungry-delete and auto-newline
;; (c-toggle-auto-hungry-state 1)
;; ;;按键定义
;; (define-key c-mode-base-map [(control \`)] 'hs-toggle-hiding)
;; (define-key c-mode-base-map [(return)] 'newline-and-indent)
;; (define-key c-mode-base-map [(f7)] 'compile)
;; (define-key c-mode-base-map [(meta \`)] 'c-indent-command)
;; ;; (define-key c-mode-base-map [(tab)] 'hippie-expand)
;; (define-key c-mode-base-map [(tab)] 'my-indent-or-complete)
;; (define-key c-mode-base-map [(meta ?/)] 'semantic-ia-complete-symbol-menu)

;; ;注意一下,上面最后两行是代码自动补齐的快捷键。后面我会提到代码自动补齐。

;; ;;预处理设置
;; (setq c-macro-shrink-window-flag t)
;; (setq c-macro-preprocessor "cpp")
;; (setq c-macro-cppflags " ")
;; (setq c-macro-prompt-flag t)
;; (setq hs-minor-mode t)
;; (setq abbrev-mode t)
;; )
;; (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)

;; ;;;;我的C++语言编辑策略
;; (defun my-c++-mode-hook()
;; (setq tab-width 4 indent-tabs-mode nil)
;; (c-set-style "stroustrup")
;; ;; (define-key c++-mode-map [f3] 'replace-regexp)
;; )
;;;;;;;;;;;;;;;

;;;;;;;begin ahei configuration test

;; (defconst my-emacs-path "~/emacs/" "我的emacs相关配置文件的路径")
;; (defconst my-emacs-my-lisps-path (concat my-emacs-path "my-lisps/") "我自己写的emacs lisp包的路径")
;; (defconst my-emacs-lisps-path (concat my-emacs-path "lisps/") "我下载的emacs lisp包的路径")
;; (defconst my-emacs-templates-path (concat my-emacs-path "templates/") "Path for templates")

;; ;; 把`my-emacs-lisps-path'的所有子目录都加到`load-path'里面
;; (load (concat my-emacs-my-lisps-path "my-subdirs"))
;; (my-add-subdirs-to-load-path my-emacs-lisps-path)
;; (my-add-subdirs-to-load-path my-emacs-my-lisps-path)

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

(add-to-list 'load-path "f:\emacs\site-lisp")
;; 方便的在kill-ring里寻找需要的东西

(require 'browse-kill-ring)

;;gen error
;(require 'browse-kill-ring-settings)

;; 图片mode
(require 'image-mode-settings)

;;error
;; 高亮当前行
;;(require 'hl-line-settings)


;; 重新定义`help-command',因为C-h已经绑定为删除前面的字符
;;(global-set-key (kbd "C-x /") 'help-command)

;;(require 'help-mode-settings)


;; (custom-set-faces
;; '(my-tab-face ((((class color)) (:background "grey10"))) t)
;; '(my-trailing-space-face ((((class color)) (:background "gray10"))) t)
;; '(my-long-line-face ((((class color)) (:background "gray10"))) t))

;; (add-hook 'font-lock-mode-hook
;; (function
;; (lambda ()
;; (setq font-lock-keywords
;; (append font-lock-keywords
;; '(("\t+" (0 'my-tab-face t))
;; ("^.\\{81,\\}$" (0 'my-long-line-face t))
;; ("[ \t]+$" (0 'my-trailing-space-face t))))))))


;; smart-compile
(require 'smart-compile)

;;
;; (when (fboundp 'winner-mode) (winner-mode) (windmove-default-keybindings))


;;;for the org-mode
(add-hook 'org-mode-hook 'turn-on-font-lock) ; not needed when global-font-lock-mode is on
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cb" 'org-iswitchb)

原文地址:https://www.cnblogs.com/vimmer/p/2971339.html