emacs-init.el配置

;+=======================================================================+
;|                               单行代码                                 |
;+=======================================================================+
(menu-bar-mode -1)                                               ;; 隐藏菜单栏
(blink-cursor-mode 1)                                            ;; 开启光标闪烁
(tool-bar-mode -1)                                               ;; 隐藏工具栏
(scroll-bar-mode -1)                                             ;; 滚动栏隐藏
(global-linum-mode -1)                                           ;; 关闭行号
(show-paren-mode t)                                              ;; 括号配对
(electric-pair-mode t)                                           ;; 自动补全括号
(global-hl-line-mode 1)                                          ;; 高亮当前行
(global-auto-revert-mode 1)                                      ;; 自动加载外部修改过的文件
(delete-selection-mode 1)                                        ;; 当你选中一段文字 之后输入一个字符会替换掉你选中部分的文字。
(fset 'yes-or-no-p 'y-or-n-p)                                    ;; 简化yes no
;(setq user-mail-address "1434513612@qq.com")                    ;; 设置用户邮箱
(setq-default cursor-type 'bar)                                  ;; 设置光标为线状
(setq user-full-name "xiebiao"                                   ;; 设置用户名
      frame-title-mode t                                         ;; 在窗口的标题栏上显示文件名称
      frame-title-format "emacs@%b"                              ;; 设置标题栏
      inhibit-splash-screen t                                    ;; 关闭启动画面
      gnus-inhibit-startup-message t                             ;; 关闭引导界面
      make-backup-files nil                                      ;; 关闭自动备份文件~
      backup-inhibited t                                         ;; 不产生备份
      auto-save-mode nil                                         ;; 自动保存模式
      truncate-lines nil                                         ;; 自动换行
      transient-mark-mode t                                      ;; 高亮显示选择区域
      blink-cursor-blinks 2                                      ;; 光标闪烁3次
      global-font-lock-mode t                                    ;; 进行语法加亮
      show-paren-style 'parenthesis                              ;; 只高亮括号
      require-final-newline t                                    ;; 自动的在文件末增加一新行
      track-eol t                                                ;; 当光标在行尾上下移动的时候,始终保持在行尾。
      c-default-style "awk"                                      ;; 设置c++编译颜色风格
      visible-bell t                                             ;; 关闭提示音
      ring-bell-function 'ignore                                 ;; 没有提示音,也不闪屏
      initial-frame-alist (quote ((fullscreen . maximized)))     ;; 默认全屏
)


;+=======================================================================+
;|                               子龙山人                                 |
;+=======================================================================+
(require 'package)
(package-initialize)
(setq package-archives '(
    ("melpa" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/") 
    ("gnu" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/")
    ("org" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/org/")))

 (require 'cl)

;; Add Packages
 (defvar my/packages '(
        yasnippet           ;; 自定义补全
                monokai-theme       ;; material-theme
        org-bullets         ;; org-mode列表字符
        ;htmlize            ;; 导出html
        ;ox-reveal          ;; 幻灯片
        ;ycmd
        ;company-ycmd
        ;flycheck-ycmd
                company             ;; 补全
        cdlatex             ;; latex
                auctex              ;; latex
        which-key           ;; 关键词提示
        undo-tree           ;; 撤销树
        ;linum              ;; 行号控制
        neotree             ;; 文件树
                flycheck            ;; 语言检查
                better-defaults
        ggtags              ;; 代码跳转
        ivy
        counsel
        swiper              ;; 搜索
        avy                 ;; 快速定位跳转
        iedit               ;; 批量换名
        window-numbering    ;; buffer编号
        expand-region       ;; 快速选择区域
        projectile          ;; 项目文件管理
        multiple-cursors    ;; 多光标
                ) "Default packages")

 (setq package-selected-packages my/packages)

 (defun my/packages-installed-p ()
     (loop for pkg in my/packages
           when (not (package-installed-p pkg)) do (return nil)
           finally (return t)))

 (unless (my/packages-installed-p)
     (message "%s" "Refreshing package database...")
     (package-refresh-contents)
     (dolist (pkg my/packages)
       (when (not (package-installed-p pkg))
         (package-install pkg))))

(add-to-list 'my/packages 'monokai-theme);; 安装主题
(load-theme ' monokai t)  ;; monokai, material, atom-one-dark, dracula



;+=======================================================================+
;|                               字体代码                                 |
;+=======================================================================+
(set-frame-font "Source Code Pro 11")
;(set-default-font "Courier New 11")
(set-fontset-font "fontset-default" 'unicode "仿宋 11") ;; for windows

;;org-table字体
(custom-set-faces
 '(org-table ((t (:foreground "#6c71c4" :family "Ubuntu Mono")))))




;+=======================================================================+
;|                               orgmode                                 |
;+=======================================================================+
;; GTD : 收集-处理-管理-执行-回顾-反省
(require 'org)

;; 设置todo关键词
(setq org-todo-keywords '((sequence "TODO(t!)" "DOING(i!)" "NEXT(n!)" "|"
                    "DONE(d@/!)" "ABORT(a@/!)")))

;; 设置todo颜色
(setq org-todo-keyword-faces
  '(("TODO" .       (:foreground "red"     :weight bold))
    ("DOING" .      (:foreground "yellow"  :weight bold))
    ("NEXT" .       (:foreground "orange"  :weight bold))
    ("DONE" .       (:foreground "green"   :weight bold)) ;;完成
    ("ABORT" .      (:foreground "ForestGreen"));;异常终止
));red ForestGreen Goldenrod OrangeRed Brown green orange magenta
;yellow gray white DarkOrange DodgerBlue SkyBlue

;; 优先级范围和默认任务的优先级
(setq org-highest-priority ?A)
(setq org-lowest-priority  ?E)
(setq org-default-priority ?B)

;; 优先级醒目外观
(setq org-priority-faces
  '((?A . (:foreground "DarkOrange" :weight bold))
    (?B . (:foreground "yellow"     :weight bold))
    (?C . (:foreground "DarkGreen"  :weight bold))
    (?D . (:foreground "SkyBlue"    :weight bold))
    (?E . (:foreground "black"      :weight bold))
));;(?B . (:background "DarkOrange" :foreground "white" :weight bold))

;; 设置标签
(setq org-tag-alist '(("read"    . ?r)
              ("work"    . ?w)
                      ("study"   . ?s)
                      ("program" . ?p)
              ("cpp"     . ?c)
              ("mind"    . ?m)
              ("idea"    . ?i)
              ("leetcode". ?l)))


(setq org-src-fontify-natively t);; 添加 Org-mode 文本内语法高亮
;(setq default-major-mode 'org-mode)

;;设置初始目录为project项目目录
(setq default-directory "~/.emacs.d/document/Orgmode")

;; 设置 org-agenda 打开快捷
(global-set-key (kbd "C-c a") 'org-agenda)

;; 设置默认的笔记
;(setq org-default-notes-file "~/.emacs.d/document/Inboxs/Inbox.org")

;; orgmode子弹符号
(add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)));;需要安装org-bullets包


;; 设置默认 Org Agenda 文件目 方法二
(setq org-agenda-files '("~/.emacs.d/document/GTD/Task.org"
             "~/.emacs.d/document/GTD/Plan.org"
             "~/.emacs.d/document/GTD/Todo.org"))



;+=======================================================================+
;|                               org中插入截图                            |
;+=======================================================================+
;; 让图片不要真实大小显示
(setq org-image-actual-width nil)

;; 截图函数
(defun my-org-screenshot ()
  "Take a screenshot into a time stamped unique-named file in the
same directory as the org-buffer and insert a link to this file."
  (interactive)
  (setq filename
        (concat
         (make-temp-name
          (concat (buffer-file-name)
                  "_"
                  (format-time-string "%Y%m%d_%H%M%S_")) ) ".png"))
  (shell-command "snippingtool /clip")
  (shell-command (concat "powershell -command \"
Add-Type -AssemblyName System.Windows.Forms;
if ($([System.Windows.Forms.Clipboard]::ContainsImage()))
{$image = [System.Windows.Forms.Clipboard]::GetImage();
[System.Drawing.Bitmap]$image.Save('" filename "',
[System.Drawing.Imaging.ImageFormat]::Png);
Write-Output 'clipboard content saved as file'}
else {
Write-Output 'clipboard does not contain image data'}\""))
  (insert (concat "[[file:" filename "]]"))
  (org-display-inline-images))

;; 绑定快捷键C-x C-a
(define-key org-mode-map (kbd "C-x C-a") 'my-org-screenshot)




;+=======================================================================+
;|                               capture                                 |
;+=======================================================================+

(global-set-key (kbd "C-c c") 'org-capture);;打开capture的快捷键

;; 设置capture模板
(setq org-capture-templates
'(
  ;; agenda
  ;("a" "Agenda" table-line
  ; (file "~/.emacs.d/document/Orgmode/Agenda.org")
  ; "| %^{项目} | %^{姓名} | %^{手机号}| %U |"))

  ;; 插入链接
  ("l" "Links " entry
   (file+headline "~/.emacs.d/document/Inboxs/Link.org" "Links")
   "* %^L" :prepend t)

  ;; todo 项目
  ("t" "ToDo" entry
   (file+datetree "~/.emacs.d/document/GTD/Todo.org")
   "* TODO %? \n  时间:%T" :prepend t)

  ;; inbox 快速记录未归类的文本
  ("i" "Inbox" entry
    (file+headline "~/.emacs.d/document/Inboxs/Inbox.org" "Inbox")
    "* %U - %^{heading} %^g \n %i \n")

  ;; 日志记录
  ("j" "Journal" entry
   (file+datetree "~/.emacs.d/document/Inboxs/Journal.org")
   "* %U - %^{heading} \n %^g \n %? \n %i \n")

  ;; 笔记
  ("n" "Note" entry
   (file+headline "~/.emacs.d/document/Notes/Note1.org" "Notes")
   "* %^{heading} \n %^g \n %? \n %i \n 时间:%U")

  ;; 博客
  ("b" "Blog" entry
   (file+headline "~/.emacs.d/document/Inboxs/Blog.org" "Blog Topics")
   "*  %^{博客名} \n %^g \n %? \n 时间:%U" :prepend t :clock-in t :clock-resume  t)

  ;; 读书记录
  ("r" "Book" entry
   (file+headline "~/.emacs.d/document/Inboxs/Book.org" "Book")
   "* %^{书名} \n 时间:%U \n %? \n %i \n":clock-in t :clock-resume  t)

  ;; 工作情况
  ("w" "Work" entry
   (file+headline "~/.emacs.d/document/Inboxs/Work.org" "Work")
   "* TODO [#B] %^{任务名} \n 时间:%U \n":clock-in t :clock-resume t)
))




;+=======================================================================+
;|                               C++配置                                 |
;+=======================================================================+
(global-set-key [f11] 'gdb)
(global-set-key [f10] 'gud-gdb)
(global-set-key [f9] 'compile-file-gcc)
(global-set-key [f12] 'compile-file-g++)

(defun compile-file-gcc ()
  (interactive)
;   (compile (format "g++ -o %s %s -lm -Wall -g -std=c++11 -Ofast"
  (compile (format "gcc -o %s %s -lm -Wall -g && c.exe"
           (file-name-sans-extension (buffer-name))(buffer-name)
           (file-name-sans-extension (buffer-name))))
  )

(defun compile-file-g++ ()
  (interactive)
  (compile (format "g++ -o %s %s -lm -Wall -g -std=c++11 -O2 && t.exe"
           (file-name-sans-extension (buffer-name))(buffer-name)
           (file-name-sans-extension (buffer-name)))))





;+=======================================================================+
;|                               company                                 |
;+=======================================================================+
(require 'company)
(add-hook 'after-init-hook 'global-company-mode)
;; 全局开启
(global-company-mode t)

(setq company-idle-delay 0.1 ;菜单延迟
      company-minimum-prefix-length 2 ;开始补全字数
      company-require-match nil
      company-dabbrev-ignore-case nil
      company-dabbrev-downcase nil
      company-show-numbers t ;显示序号
      company-transformers '(company-sort-by-backend-importance)
      company-continue-commands '(not helm-dabbrev))


;; 补全快捷键
(global-set-key (kbd "<C-tab>") 'company-complete)
(global-set-key (kbd "RET") 'newline-and-indent)

;; 补全菜单选项快捷键
(define-key company-active-map (kbd "C-n") 'company-select-next)
(define-key company-active-map (kbd "C-p") 'company-select-previous)

;; Company 有时候补全功能并不是非常理想,这时就可以使用 Hippie Expand 来完成补全
(setq hippie-expand-try-function-list '(try-expand-debbrev
                                        try-expand-debbrev-all-buffers
                                        try-expand-debbrev-from-kill
                                        try-complete-file-name-partially
                                        try-complete-file-name
                                        try-expand-all-abbrevs
                                        try-expand-list
                                        try-expand-line
                                        try-complete-lisp-symbol-partially
                                        try-complete-lisp-symbol))


;+=======================================================================+
;|                               Latex                                   |
;+=======================================================================+
;; cdlatex 模块
(require 'cdlatex)
(add-hook 'LaTeX-mode-hook 'turn-on-cdlatex)
(add-hook 'LaTex-mode-hook 'turn-on-reftex)


;; outline 设置
(outline-minor-mode t)
(setq outline-minor-mode-prefix [(control o)])
(add-hook 'LaTex-mode-hook 'outline-minor-mode)
(add-hook 'LaTex-mode-hook 'outline-hide-body)
;;outline 好像没有效果

;; 默认编辑器设置
;(setq TeX-command-default "XeLaTeX")
;(setq TeX-save-query  nil )
;(setq TeX-show-compilation t);;可用代码

;;----------- 新加的代码,如果有影响可以删除---;
(load "auctex.el" nil t t)

(setq TeX-output-view-style (quote (("^pdf$" "." "evince %o %(outpage)"))))
;(add-hook 'LaTeX-mode-hook
; (lambda()
; (add-to-list 'TeX-command-list '("XeLaTeX" "%`xelatex%(mode)%' %t" TeX-run-TeX nil t))
; (setq TeX-command-default "XeLaTeX")))

(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil)
(setq preview-scale-function 1.3)
(setq LaTeX-math-menu-unicode t)
(setq TeX-insert-braces nil)
(add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)

;;Auctex for Latex
(add-hook 'LaTeX-mode-hook 'LaTeX-install-toolbar)
(add-hook 'LaTeX-mode-hook 'turn-on-auto-fill)
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)

(add-hook 'LaTeX-mode-hook (lambda()
;;调用latex命令
(add-to-list 'TeX-command-list (list "LaTeX" "latex %s.tex" 'TeX-run-command nil t))
;;调用dvipdfmx命令
(add-to-list 'TeX-command-list (list "dvi2pdf" "dvipdfmx %s.dvi" 'TeX-run-command nil t))
;;调用pdflatex命令;;调用pdflatex命令;;调用pdflatex命令
(add-to-list 'TeX-command-list (list "pdf Latex" "pdflatex %s.tex" 'TeX-run-command nil t))
; View PDF
(add-to-list 'TeX-command-list (list "View pdf" "start .\\\"%s.pdf\""'TeX-run-command nil t))
;;设置环境为xelatex
(add-to-list 'TeX-command-list '("XeLaTeX" "%`xelatex%(mode)%' %t" TeX-run-TeX nil t))
;;(setq TeX-command-default "XeLaTeX")
;;(setq TeX-save-query nil )
;;(setq TeX-show-compilation t)
))

;;======================== latex-math-mode =================
;; latex-math-mode (add math symbols to menu and shortcuts)
;; So that you can use, e.g., `a, to input \alpha. You may also define
;; your own customized shortcuts by setting the variable
;; LaTeX-math-list before loading LaTeX-math-mode.
;; to enable maths support

(setq LaTeX-math-mode t)
(setq TeX-electric-escape t) ;; you may like it or dislike it.
;; I found it useful when inputting repeated commands -- you just
;; need to type \ and ENTER to repeat the last latex command. 

(add-hook 'LaTeX-mode-hook 'latex-math-mode)   ; with AUCTeX LaTeX mode
(add-hook 'latex-mode-hook 'latex-math-mode)   ; with Emacs latex mode
(add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)

;; ===================在.org文档中使用latex===========
(require 'ox-latex)
(setq org-latex-create-formula-image-program 'dvipng)

(org-babel-do-load-languages
 'org-babel-load-languages
 '(
   (R . t)
   (dot . t)
   (haskell . t)
   (python . t)
   (C . t)
   (emacs-lisp . nil)
   (latex . t)
   ))




;+=======================================================================+
;|                               自动保存                                 |
;+=======================================================================+

(defgroup auto-save nil
  "Auto save file when emacs idle."
  :group 'auto-save)

(defcustom auto-save-idle 0.1;;!!!!!!!!!!!!
  "The idle seconds to auto save file."
  :type 'integer
  :group 'auto-save)

(defcustom auto-save-slient nil
  "Nothing to dirty minibuffer if this option is non-nil."
  :type 'boolean
  :group 'auto-save)

(setq auto-save-default nil)

;; 前方高能核心代码, 请集中注意力
(defun auto-save-buffers ()
  (interactive)
  (let ((autosave-buffer-list))
    (save-excursion
      (dolist (buf (buffer-list))
        (set-buffer buf)
        (if (and (buffer-file-name) (buffer-modified-p))
            (progn              
              (push (buffer-name) autosave-buffer-list)
              (if auto-save-slient                  
                  (with-temp-message ""
                    (basic-save-buffer))
                (basic-save-buffer))
              )))
      (unless auto-save-slient
        (cond
         ((= (length autosave-buffer-list) 1)
          (message "# Saved %s" (car autosave-buffer-list)))
         ((> (length autosave-buffer-list) 1)
          (message "# Saved %d files: %s"
                   (length autosave-buffer-list)
                   (mapconcat 'identity autosave-buffer-list ", "))))))))

(defun auto-save-enable ()
  (interactive)
  (run-with-idle-timer auto-save-idle t #'auto-save-buffers))
(auto-save-enable);; 开启自动保存功能
(setq auto-save-slient t);; 自动保存的时候静悄悄的, 不要打扰我




;+=======================================================================+
;|                              杂碎的代码                                 |
;+=======================================================================+
;; 记住光标上次打开文件时的位置
(require 'saveplace)
(save-place-mode 1)   

;; 时间,窗口
;(display-time-mode 1)  ;; 常显 
;(setq display-time-24hr-format t)  ;;格式 
;(setq display-time-day-and-date t)  ;;显示时间、星期、日期
;;(set-frame-parameter (selected-frame) 'alpha (list 85 50));; 设置屏幕透明
;;(set-frame-width (selected-frame) 77);;设置初始窗口宽度
;;(set-frame-height (selected-frame) 34);;设置初始窗口高度


;; 防止页面滚动时跳动scroll-margin 3可以在靠近屏幕边沿3行时就开始滚动,可以很好的看到上下文。
(setq scroll-step 1
      scroll-margin 3;;可以在靠近屏幕边沿3行时就开始滚动
      scroll-conservatively 10000);;设置为每次翻滚一行,可以使页面更连续


;;鼠标滚轮,默认的滚动太快,这里改为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)


;;设置最近访问文件可见
(require 'recentf)
(recentf-mode t)
(setq recentf-max-saved-items 200
      recentf-max-menu-items 15);; 设置最近访问文件数量为10
;; 打开最近文件快捷键,这个快捷键绑定可以用之后的插件 counsel 代替
(global-set-key (kbd "C-x C-r") 'recentf-open-files)

;; 设定删除保存记录为200,可以方便以后无限恢复
(setq kill-ring-max 200)



;; 窗口管理:将当前窗口分割为上下两个,并切换到另外一个 buffer
(defun split-window-new-buffer ()
(interactive)
(split-window-below)
(call-interactively 'switch-to-buffer))

;; 代码缩进,一次重新缩进全部缓冲区的代码
(defun indent-buffer()
  (interactive)
  (indent-region (point-min) (point-max)))

(defun indent-region-or-buffer()
  (interactive)
  (save-excursion
    (if (region-active-p)
        (progn
          (indent-region (region-beginning) (region-end))
          (message "Indent selected region."))
      (progn
        (indent-buffer)
        (message "Indent buffer.")))))

(global-set-key (kbd "C-M-\\") 'indent-region-or-buffer)


;; 窗口光标后退,C-x o的相反操作
(defun prev-window ()
  (interactive)
  (other-window -1))
(global-set-key (kbd "C-x p") 'prev-window)

;; 加载延迟模块start
(require 'dired-x)  ;; 使得 C-x C-j 就可以进入当前文件夹的所在路径

;; 让 Emacs 重用唯一的一个缓冲区作为 Dired Mode 显示专用缓冲区
(put 'dired-find-alternate-file 'disabled nil)
;; 主动加载 Dired Mode
;; (require 'dired)
;; (defined-key dired-mode-map (kbd "RET") 'dired-find-alternate-file)
;; 延迟加载
(with-eval-after-load 'dired
    (define-key dired-mode-map (kbd "RET") 'dired-find-alternate-file))


;; 递归删除和复制目录
(setq dired-recursive-deletes 'always)
(setq dired-recursive-copies 'always)


(setq gc-cons-threshold most-positive-fixnum);设置垃圾回收阈值,加速启动速度。

(auto-image-file-mode t);; 打开图片显示功能


;; 快速打开link.org
(defun open-key-info-file1 ()  
(interactive)  
(split-window-horizontally)  
(find-file-other-window "~/.emacs.d/document/Inboxs/Link.org")
;;(outline-mode)  
(hide-body))    
(global-set-key (kbd "C-x C-1") 'open-key-info-file1)


;; 快速打开emacskey.org
(defun open-key-info-file2 ()  
(interactive)  
(split-window-horizontally)  
(find-file-other-window "~/.emacs.d/document/Orgmode/emacsKeys.org")
;;(outline-mode)  
(hide-body))    
(global-set-key (kbd "C-x C-2") 'open-key-info-file2)


; 设置打开init.el文件的快捷键
(defun open-my-init-file()
  (interactive)
  (find-file "~/.emacs.d/init.el"))
(global-set-key (kbd "<f7>") 'open-my-init-file); 设置init.el文件的快捷键


;; 剪切,复制,粘贴,全选
;(cua-mode t) ;; window的剪切粘贴
(global-set-key (kbd "C-z") 'undo);; 撤消
(global-set-key (kbd "C-q") 'mark-whole-buffer);; 全选ctrl+a


;; 自定义缩写补全表
(setq-default abbrev-mode t)
(define-abbrev-table 'global-abbrev-table '
  (
   ("8zl" "zilongshanren")
   ("yasn" "yas-new-snippet")
   ))


;; 初始显示界面
(setq initial-scratch-message nil)
(setq initial-major-mode 'text-mode)
;(setq initial-scratch-message "hello")
;; 启动后直接显示工作目录
(setq initial-buffer-choice "c:/User/Project/EmacsProject/t.cpp")


;; 启动优化
;;增加启动期间垃圾回收的阈值,启动结束后还原。
;;设置启动时file-name-handler-alist为nil
(defvar  mage--file-name-handler-alist file-name-handler-alist)
(defun mage|pre-init()
  (setq gc-cons-threshold 402653184
    gc-cons-percentage 1.0
    file-name-handler-alist nil))

(defun mage|post-init ()
  (setq gc-cons-threshold 16777216
        gc-cons-percentage 0.15
        file-name-handler-alist mage--file-name-handler-alist))
(add-hook 'before-init-hook #'mage|pre-init)
(add-hook 'emacs-startup-hook #'mage|post-init)

;自定义缩进长度
(setq standard-indent 4)

;; 设置默认tab宽度
(setq tab-width 4
      indent-tabs-mode t
      c-basic-offset 4)
(setq default-tab-width 4)


;; 设置 sentence-end 可以识别中文标点
(setq sentence-end
      "\\([。!?]\\|……\\|[.?!][]\"')}]*\\($\\|[ \t]\\)\\)[ \t\n]*")
(setq sentence-end-double-space nil)


;; 语法高亮
(setq font-lock-maximum-decoration t)
(setq font-lock-global-modes '(not shell-mode text-mode));;除 shell-mode 和 text-mode 之外的模式中使用语法高亮。
(setq font-lock-verbose t)
(global-font-lock-mode 1)


;; ;; 设置另外一些颜色:语法高亮显示的背景和主题,区域选择的背景和主题,二次选择的背景和选择
(set-face-foreground 'highlight "white")
(set-face-background 'highlight "DarkOrange");;#3e9d6a
(set-face-foreground 'region "cyan")
(set-face-background 'region "gray10")
(set-face-foreground 'secondary-selection "skyblue");;skyblue
(set-face-background 'secondary-selection "darkblue");;darkblue




;+=======================================================================+
;|                         ivy counsel swiper                            |
;+=======================================================================+
;; ivy counsel swiper
(require 'ivy)
(ivy-mode 1)
(setq ivy-use-virtual-buffers t)
(setq enable-recursive-minibuffers t)
;; enable this if you want swiper to use it
;; (setq search-default-mode #'char-fold-to-regexp)

(global-set-key (kbd "<f6>") 'ivy-resume)
(define-key minibuffer-local-map (kbd "C-r") 'counsel-minibuffer-history)

;; Ivy-based interface to standard commands
;;(global-set-key "\C-s" 'swiper-isearch)
(global-set-key (kbd "C-s") 'swiper)
(global-set-key (kbd "M-x") 'counsel-M-x)
(global-set-key (kbd "C-x C-f") 'counsel-find-file)
(global-set-key (kbd "M-y") 'counsel-yank-pop)
(global-set-key (kbd "<f2> f") 'counsel-describe-function)
(global-set-key (kbd "<f2> v") 'counsel-describe-variable)
(global-set-key (kbd "<f2> l") 'counsel-find-library)
(global-set-key (kbd "<f1> i") 'counsel-info-lookup-symbol)
(global-set-key (kbd "<f1> u") 'counsel-unicode-char)
(global-set-key (kbd "<f1> j") 'counsel-set-variable)
(global-set-key (kbd "C-x b") 'ivy-switch-buffer)
(global-set-key (kbd "C-c v") 'ivy-push-view)
(global-set-key (kbd "C-c V") 'ivy-pop-view)

;; Ivy-based interface to shell and system tools
(global-set-key (kbd "C-x l") 'counsel-locate)
(global-set-key (kbd "C-c J") 'counsel-file-jump)


;; Ivy-resume and other commands
(global-set-key (kbd "C-c C-r") 'ivy-resume)
(global-set-key (kbd "C-c b") 'counsel-bookmark)
(global-set-key (kbd "C-c d") 'counsel-descbinds)
;(global-set-key (kbd "C-c g") 'counsel-git)
(global-set-key (kbd "C-c o") 'counsel-outline)
(global-set-key (kbd "C-c t") 'counsel-load-theme)
(global-set-key (kbd "C-c F") 'counsel-org-file)

(setq ivy-use-virtual-buffers t 
      ivy-initial-inputs-alist nil 
      ivy-count-format "%d/%d " 
      enable-recursive-minibuffers t 
      ivy-re-builders-alist '((t . ivy--regex-ignore-order))) 

 (setq swiper-action-recenter t 
                swiper-include-line-number-in-search t)


;; counsel-gtags 设置
(add-hook 'c-mode-hook 'counsel-gtags-mode)
(add-hook 'c++-mode-hook 'counsel-gtags-mode)

(with-eval-after-load 'counsel-gtags
  (define-key counsel-gtags-mode-map (kbd "M-t") 'counsel-gtags-find-definition)
  (define-key counsel-gtags-mode-map (kbd "M-r") 'counsel-gtags-find-reference)
  (define-key counsel-gtags-mode-map (kbd "M-s") 'counsel-gtags-find-symbol)
  (define-key counsel-gtags-mode-map (kbd "M-,") 'counsel-gtags-go-backward))





;+=======================================================================+
;|                              其他小模块                                 |
;+=======================================================================+
;; 调整背景色
;(set-background-color "grey15");; 背景颜色
;(set-foreground-color "grey");;颜色


;; 单词补全
;(add-to-list 'load-path "~/.emacs.d/elpa/company-english-helper")
;(require 'company-english-helper);可以用
;M-x toggle-company-english-helper 激活


;; 幻灯片模块oxreveal
;(require 'ox-reveal)


;; linum
;(global-linum-mode t)
;(setq linum-format "%4d  ");;行号控制4位数


;; yasnippet自定义补全
(require 'yasnippet)
(yas-global-mode 1)


;;  flycheck
(require 'flycheck)
(add-hook 'elpy-mode-hook 'flycheck-mode)
(global-flycheck-mode t)


;设置系统的编码,避免各处的乱码。
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8) 
(set-terminal-coding-system 'utf-8) 
(set-keyboard-coding-system 'utf-8) 
(setq default-buffer-file-coding-system 'utf-8)


;; which-key
(require 'which-key)
(which-key-mode t)
(which-key-setup-side-window-bottom)


;; undo-tree
(require 'undo-tree)
(global-undo-tree-mode)
(defadvice undo-tree-visualizer-mode (after undo-tree-face activate)
(buffer-face-mode))


;; 快速选择区域
(require 'expand-region)
(global-set-key (kbd "C-=")'er/expand-region)


;;开启buffer编号
;(require 'window-numbering)
(window-numbering-mode 1)
(setq window-numbering-assign-func
      (lambda () (when (equal (buffer-name) "*Calculator*") 9)))


;; iedit
(require 'iedit)
(define-key global-map (kbd "C-c ;") 'iedit-mode)


;; neotree
(require 'neotree)
(setq neo-smart-open t)
(setq neo-window-fixed-size nil)
(setq-default neo-show-hidden-files nil)
(global-set-key [f4] 'neotree-delete-node)
(global-set-key [f8] 'neotree-toggle)


;; avy
(global-set-key (kbd "C-:") 'avy-goto-char)      ;; 跳转一个字符
(global-set-key (kbd "C-'") 'avy-goto-char-2)    ;; 跳转两个字符
(global-set-key (kbd "M-g f") 'avy-goto-line)    ;; 跳转行
(global-set-key (kbd "M-g w") 'avy-goto-word-1)  ;; 跳转词,一个输入
(global-set-key (kbd "M-g e") 'avy-goto-word-0)  ;; 跳转词,不需输入
(avy-setup-default)
(global-set-key (kbd "C-c C-j") 'avy-resume)


;; projectile
(projectile-mode 1)
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)


;;multiple-cursor
(require 'multiple-cursors)
(global-set-key (kbd "C-c m c") 'mc/edit-lines)
(global-set-key (kbd "C->") 'mc/mark-next-like-this)
(global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)
(global-set-key (kbd "C-M->") 'mc/skip-to-next-like-this)
(global-set-key (kbd "C-M-<") 'mc/skip-to-previous-like-this)
(global-unset-key (kbd "M-<down-mouse-1>"))
(global-set-key (kbd "M-<mouse-1>") 'mc/add-cursor-on-click)



;; gtags
(setenv "PATH" (concat "C:/Program Files/Emacs26.3/.emacs.d/elpa/global-6.6.3/bin;" (getenv "PATH")))
(setq exec-path (append exec-path '("C:/Program Files/Emacs26.3/.emacs.d/elpa/global-6.6.3/bin")))

(add-to-list 'load-path "~/.emacs.d/elpa/gtags/")
(require 'gtags)

(global-set-key (kbd "C-c f") 'ggtags-find-file)
(global-set-key (kbd "M-.") 'ggtags-find-tag-dwim)


;;---------------
(autoload 'gtags-mode "gtags" "" t)
(add-hook 'gtags-mode-hook
  '(lambda ()
        ; Local customization (overwrite key mapping)
        (define-key gtags-mode-map "\C-f" 'scroll-up)
        (define-key gtags-mode-map "\C-b" 'scroll-down)
    ))

(add-hook 'gtags-select-mode-hook
  '(lambda ()
        (setq hl-line-face 'underline)
        (hl-line-mode 1)
))
(add-hook 'c-mode-common-hook 'gtags-mode)
(add-hook 'c++-mode-common-hook 'gtags-mode)
;(add-hook 'java-mode-common-hook 'gtags-mode)

; Customization
(setq gtags-suggested-key-mapping t);; 以建议的使用键绑定
(setq gtags-auto-update t)
;(setq ggtags-global-ignore-case t)
(setq ggtags-sort-by-nearness t)




;;------------------------------代码测试部分-------------------------------

 

posted @ 2020-04-05 10:48  hello.world!  阅读(1136)  评论(0编辑  收藏  举报