ReverseFlux

evil complete

Feb 13th, 2017
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.45 KB | None | 0 0
  1. ;;; core-evil.el --- the root of all evil
  2.  
  3. (use-package evil
  4. :init
  5. (setq evil-magic t
  6. evil-want-C-u-scroll t
  7. evil-ex-visual-char-range t ; column range for ex commands
  8. evil-want-visual-char-semi-exclusive t
  9. evil-ex-search-vim-style-regexp t
  10. evil-ex-interactive-search-highlight 'selected-window
  11. evil-echo-state nil
  12. evil-ex-substitute-global t
  13. evil-insert-skip-empty-lines t
  14. evil-want-fine-undo nil
  15.  
  16. evil-normal-state-tag "N"
  17. evil-insert-state-tag "I"
  18. evil-visual-state-tag "V"
  19. evil-emacs-state-tag "E"
  20. evil-operator-state-tag "O"
  21. evil-motion-state-tag "M"
  22. evil-replace-state-tag "R"
  23.  
  24. ;; Set cursor colors
  25. evil-default-cursor (face-attribute 'cursor :background nil t)
  26. evil-normal-state-cursor 'box
  27. evil-emacs-state-cursor `(,(face-attribute 'warning :foreground nil nil) box)
  28. evil-insert-state-cursor 'bar
  29. evil-visual-state-cursor 'hollow)
  30.  
  31. ;; highlight matching delimiters where it's important
  32. (defun show-paren-mode-off () (show-paren-mode -1))
  33. (add-hook 'evil-insert-state-entry-hook 'show-paren-mode)
  34. (add-hook 'evil-insert-state-exit-hook 'show-paren-mode-off)
  35. (add-hook 'evil-visual-state-entry-hook 'show-paren-mode)
  36. (add-hook 'evil-visual-state-exit-hook 'show-paren-mode-off)
  37. (add-hook 'evil-operator-state-entry-hook 'show-paren-mode)
  38. (add-hook 'evil-operator-state-exit-hook 'show-paren-mode-off)
  39. (add-hook 'evil-normal-state-entry-hook 'show-paren-mode-off)
  40. ;; Disable highlights on insert-mode
  41. (add-hook 'evil-insert-state-entry-hook 'evil-ex-nohighlight)
  42.  
  43. :config
  44. (evil-mode 1)
  45. (evil-select-search-module 'evil-search-module 'evil-search)
  46.  
  47. (mapc (lambda (r) (evil-set-initial-state (car r) (cdr r)))
  48. '((compilation-mode . normal)
  49. (help-mode . normal)
  50. (message-mode . normal)
  51. (debugger-mode . normal)
  52. (image-mode . normal)
  53. (doc-view-mode . normal)
  54. (eww-mode . normal)
  55. (tabulated-list-mode . emacs)
  56. (profile-report-mode . emacs)
  57. (Info-mode . emacs)
  58. (view-mode . emacs)
  59. (comint-mode . emacs)
  60. (cider-repl-mode . emacs)
  61. (term-mode . emacs)
  62. (calendar-mode . emacs)
  63. (Man-mode . emacs)
  64. (grep-mode . emacs)))
  65.  
  66. ;; Popups
  67. (def-popup! "*evil-registers*" :align below :size 0.3)
  68. (def-popup! "*Command Line*" :align below :size 8 :select t)
  69.  
  70. ;;; Evil hacks
  71. ;; Don't interfere with neotree + auto move to new split
  72. (advice-add 'evil-window-split :around 'doom*evil-window-split)
  73. (advice-add 'evil-window-vsplit :around 'doom*evil-window-vsplit)
  74. ;; Integrate evil's command window into shackle
  75. (advice-add 'evil-command-window :override 'doom*evil-command-window)
  76. (add-hook 'evil-command-window-mode-hook 'doom-hide-mode-line-mode)
  77. ;; Close popups, disable search highlights and quit the minibuffer if open
  78. (advice-add 'evil-force-normal-state :after 'doom*evil-esc-quit)
  79.  
  80. ;; Fix harmless (yet disruptive) error reporting w/ hidden buffers caused by
  81. ;; workgroups killing windows
  82. ;; TODO Delete timer on dead windows?
  83. (defadvice evil-ex-hl-do-update-highlight
  84. (around evil-ex-hidden-buffer-ignore-errors activate)
  85. (ignore-errors ad-do-it))
  86.  
  87. ;; Hide keystroke display while isearch is active
  88. (add-hook! isearch-mode (setq echo-keystrokes 0))
  89. (add-hook! isearch-mode-end (setq echo-keystrokes 0.02))
  90.  
  91. (def-repeat! evil-ex-search-next evil-ex-search-next evil-ex-search-previous)
  92. (def-repeat! evil-ex-search-previous evil-ex-search-next evil-ex-search-previous)
  93. (def-repeat! evil-ex-search-forward evil-ex-search-next evil-ex-search-previous)
  94. (def-repeat! evil-ex-search-backward evil-ex-search-next evil-ex-search-previous)
  95.  
  96. ;; monkey patch `evil-ex-replace-special-filenames' to add most of vim's file
  97. ;; ex substitution flags to evil-mode
  98. (advice-add 'evil-ex-replace-special-filenames
  99. :override 'doom*evil-ex-replace-special-filenames)
  100.  
  101. ;; Extra argument types for highlight buffer (or global) regexp matches
  102. (evil-ex-define-argument-type buffer-match :runner doom/evil-ex-buffer-match)
  103. (evil-ex-define-argument-type global-match :runner doom/evil-ex-global-match)
  104.  
  105. (evil-define-interactive-code "<//>"
  106. :ex-arg buffer-match
  107. (list (when (evil-ex-p) evil-ex-argument)))
  108. (evil-define-interactive-code "<g//>"
  109. :ex-arg global-match
  110. (when (evil-ex-p) (evil-ex-parse-global evil-ex-argument)))
  111.  
  112. (evil-define-operator doom:evil-ex-global (beg end pattern command &optional invert)
  113. "Rewritten :g[lobal] that will highlight buffer matches. Takes the same arguments."
  114. :motion mark-whole-buffer :move-point nil
  115. (interactive "<r><g//><!>")
  116. (evil-ex-global beg end pattern command invert))
  117.  
  118. (evil-define-operator doom:align (&optional beg end bang pattern)
  119. "Ex interface to `align-regexp'. Accepts vim-style regexps."
  120. (interactive "<r><!><//>")
  121. (align-regexp
  122. beg end
  123. (concat "\\(\\s-*\\)"
  124. (if bang
  125. (regexp-quote pattern)
  126. (evil-transform-vim-style-regexp pattern)))
  127. 1 1)))
  128.  
  129. ;; evil plugins
  130. (use-package evil-numbers
  131. :commands (evil-numbers/inc-at-pt evil-numbers/dec-at-pt))
  132.  
  133. (use-package evil-anzu
  134. :defer t
  135. :init
  136. ;; evil-anzu is strangely slow on startup. Byte compiling doesn't help. We use
  137. ;; this to lazy load it instead.
  138. (defun doom*evil-search (&rest _)
  139. (require 'evil-anzu)
  140. (advice-remove 'evil-ex-start-search 'doom*evil-search))
  141. (advice-add 'evil-ex-start-search :before 'doom*evil-search)
  142. :config
  143. (setq anzu-cons-mode-line-p nil
  144. anzu-minimum-input-length 1
  145. anzu-search-threshold 250))
  146.  
  147. (use-package evil-args
  148. :commands (evil-inner-arg evil-outer-arg evil-forward-arg evil-backward-arg evil-jump-out-args)
  149. :init (def-text-obj! "a" 'evil-inner-arg 'evil-outer-arg))
  150.  
  151. (use-package evil-commentary
  152. :commands (evil-commentary evil-commentary-yank evil-commentary-line)
  153. :config (evil-commentary-mode 1))
  154.  
  155. (use-package evil-exchange
  156. :commands evil-exchange
  157. :config (advice-add 'evil-force-normal-state :after 'doom*evil-exchange-off))
  158.  
  159. (use-package evil-multiedit
  160. :commands (evil-multiedit-match-all
  161. evil-multiedit-match-and-next
  162. evil-multiedit-match-and-prev
  163. evil-multiedit-match-symbol-and-next
  164. evil-multiedit-match-symbol-and-prev
  165. evil-multiedit-toggle-or-restrict-region
  166. evil-multiedit-next
  167. evil-multiedit-prev
  168. evil-multiedit-abort
  169. evil-multiedit-ex-match)
  170. :config (evil-multiedit-default-keybinds))
  171.  
  172. (use-package evil-indent-plus
  173. :commands (evil-indent-plus-i-indent
  174. evil-indent-plus-a-indent
  175. evil-indent-plus-i-indent-up
  176. evil-indent-plus-a-indent-up
  177. evil-indent-plus-i-indent-up-down
  178. evil-indent-plus-a-indent-up-down)
  179. :init
  180. (def-text-obj! "i" 'evil-indent-plus-i-indent 'evil-indent-plus-a-indent)
  181. (def-text-obj! "I" 'evil-indent-plus-i-indent-up 'evil-indent-plus-a-indent-up)
  182. (def-text-obj! "J" 'evil-indent-plus-i-indent-up-down 'evil-indent-plus-a-indent-up-down))
  183.  
  184. (use-package evil-matchit
  185. :commands (evilmi-jump-items evilmi-text-object global-evil-matchit-mode)
  186. :config (global-evil-matchit-mode 1)
  187. :init (def-text-obj! "%" 'evilmi-text-object))
  188.  
  189. (use-package evil-textobj-anyblock
  190. :commands (evil-textobj-anyblock-inner-block evil-textobj-anyblock-a-block)
  191. :init (def-text-obj! "B" 'evil-textobj-anyblock-inner-block 'evil-textobj-anyblock-a-block))
  192.  
  193. (use-package evil-search-highlight-persist
  194. :config
  195. (global-evil-search-highlight-persist t)
  196. (advice-add 'evil-force-normal-state :after 'evil-search-highlight-persist-remove-all))
  197.  
  198. (use-package evil-easymotion
  199. :defer 1
  200. :init (defvar doom--evil-snipe-repeat-fn)
  201. :config
  202. (evilem-default-keybindings "g SPC")
  203. (evilem-define (kbd "g SPC n") 'evil-ex-search-next)
  204. (evilem-define (kbd "g SPC N") 'evil-ex-search-previous)
  205. (evilem-define "gs" 'evil-snipe-repeat
  206. :pre-hook (save-excursion (call-interactively #'evil-snipe-s))
  207. :bind ((evil-snipe-scope 'buffer)
  208. (evil-snipe-enable-highlight)
  209. (evil-snipe-enable-incremental-highlight)))
  210. (evilem-define "gS" 'evil-snipe-repeat-reverse
  211. :pre-hook (save-excursion (call-interactively #'evil-snipe-s))
  212. :bind ((evil-snipe-scope 'buffer)
  213. (evil-snipe-enable-highlight)
  214. (evil-snipe-enable-incremental-highlight)))
  215.  
  216. (setq doom--evil-snipe-repeat-fn
  217. (evilem-create 'evil-snipe-repeat
  218. :bind ((evil-snipe-scope 'whole-buffer)
  219. (evil-snipe-enable-highlight)
  220. (evil-snipe-enable-incremental-highlight)))))
  221.  
  222. (use-package evil-snipe
  223. :init
  224. (setq-default
  225. evil-snipe-smart-case t
  226. evil-snipe-repeat-keys nil ; using space to repeat
  227. evil-snipe-scope 'line
  228. evil-snipe-repeat-scope 'visible
  229. evil-snipe-override-evil-repeat-keys nil ; causes problems with remapped ;
  230. evil-snipe-char-fold t
  231. evil-snipe-aliases '((?\[ "[[{(]")
  232. (?\] "[]})]")
  233. (?\; "[;:]")))
  234. :config
  235. (evil-snipe-mode 1)
  236. (evil-snipe-override-mode 1)
  237.  
  238. (define-key evil-snipe-parent-transient-map (kbd "C-;") 'doom/evil-snipe-easymotion)
  239.  
  240. (def-repeat! evil-snipe-f evil-snipe-repeat evil-snipe-repeat-reverse)
  241. (def-repeat! evil-snipe-F evil-snipe-repeat evil-snipe-repeat-reverse)
  242. (def-repeat! evil-snipe-t evil-snipe-repeat evil-snipe-repeat-reverse)
  243. (def-repeat! evil-snipe-T evil-snipe-repeat evil-snipe-repeat-reverse)
  244. (def-repeat! evil-snipe-s evil-snipe-repeat evil-snipe-repeat-reverse)
  245. (def-repeat! evil-snipe-S evil-snipe-repeat evil-snipe-repeat-reverse)
  246. (def-repeat! evil-snipe-x evil-snipe-repeat evil-snipe-repeat-reverse)
  247. (def-repeat! evil-snipe-X evil-snipe-repeat evil-snipe-repeat-reverse))
  248.  
  249. (use-package evil-surround
  250. :commands (global-evil-surround-mode
  251. evil-surround-edit
  252. evil-Surround-edit
  253. evil-surround-region)
  254. :config
  255. (global-evil-surround-mode 1))
  256.  
  257. (use-package evil-embrace
  258. :after evil-surround
  259. :config
  260. (setq evil-embrace-show-help-p nil)
  261. (evil-embrace-enable-evil-surround-integration)
  262. (push (cons ?\\ (make-embrace-pair-struct
  263. :key ?\\
  264. :read-function 'doom/embrace-escaped
  265. :left-regexp "\\[[{(]"
  266. :right-regexp "\\[]})]"))
  267. (default-value 'embrace--pairs-list))
  268.  
  269. (add-hook 'LaTeX-mode-hook 'embrace-LaTeX-mode-hook)
  270. (add-hook 'org-mode-hook 'embrace-org-mode-hook)
  271. (add-hook! emacs-lisp-mode
  272. (embrace-add-pair ?\` "`" "'"))
  273. (add-hook! (emacs-lisp-mode lisp-mode)
  274. (embrace-add-pair-regexp ?f "([^ ]+ " ")" 'doom/embrace-elisp-fn))
  275. (add-hook! (org-mode latex-mode)
  276. (embrace-add-pair-regexp ?l "\\[a-z]+{" "}" 'doom/embrace-latex)))
  277.  
  278. (use-package evil-visualstar
  279. :commands (global-evil-visualstar-mode
  280. evil-visualstar/begin-search
  281. evil-visualstar/begin-search-forward
  282. evil-visualstar/begin-search-backward)
  283. :config
  284. (global-evil-visualstar-mode 1)
  285.  
  286. (def-repeat! evil-visualstar/begin-search-forward
  287. evil-ex-search-next evil-ex-search-previous)
  288. (def-repeat! evil-visualstar/begin-search-backward
  289. evil-ex-search-previous evil-ex-search-next))
  290.  
  291. (use-package evil-escape
  292. :config
  293. (setq evil-escape-key-sequence "jk"
  294. evil-escape-delay 0.25)
  295. (push 'neotree-mode evil-escape-excluded-major-modes)
  296. ;; evil-escape causes noticable lag in commands that start with j, so we
  297. ;; enable it only where we need it.
  298. (defun doom|evil-escape-disable () (evil-escape-mode -1))
  299. (defun doom|evil-escape-enable () (evil-escape-mode +1))
  300. (add-hook 'evil-insert-state-entry-hook 'doom|evil-escape-enable)
  301. (add-hook 'evil-insert-state-exit-hook 'doom|evil-escape-disable)
  302. (add-hook 'evil-replace-state-entry-hook 'doom|evil-escape-enable)
  303. (add-hook 'evil-replace-state-exit-hook 'doom|evil-escape-disable))
  304.  
  305. (provide 'core-evil)
  306. ;;; core-evil.el ends here
Advertisement
Add Comment
Please, Sign In to add comment