evil-mode: refactor config

This commit is contained in:
Henrik Lissner 2016-04-19 22:17:03 -04:00
parent ef8731a3c3
commit c02c77a2aa
3 changed files with 111 additions and 121 deletions

View file

@ -8,15 +8,13 @@
(add-hook 'evil-insert-state-exit-hook 'show-paren-mode-off)
(add-hook 'evil-visual-state-entry-hook 'show-paren-mode)
(add-hook 'evil-visual-state-exit-hook 'show-paren-mode-off)
(add-hook 'evil-motion-state-entry-hook 'show-paren-mode)
(add-hook 'evil-motion-state-exit-hook 'show-paren-mode-off)
(add-hook 'evil-operator-state-entry-hook 'show-paren-mode)
(add-hook 'evil-operator-state-exit-hook 'show-paren-mode-off)
;; Disable highlights on insert-mode
(add-hook 'evil-insert-state-entry-hook 'evil-ex-nohighlight)
:config
(setq-default
(setq
evil-magic t
evil-want-C-u-scroll t ; enable C-u for scrolling
evil-ex-visual-char-range t ; column range for ex commands
@ -26,6 +24,7 @@
evil-echo-state nil
evil-ex-substitute-global t
evil-insert-skip-empty-lines t
evil-search-module 'evil-search
evil-normal-state-tag "N"
evil-insert-state-tag "I"
@ -37,25 +36,26 @@
;; Color-coded state cursors
evil-default-cursor "orange"
evil-normal-state-cursor 'box
evil-emacs-state-cursor '("cyan" box)
evil-insert-state-cursor 'bar
evil-visual-state-cursor 'hollow)
evil-normal-state-cursor 'box
evil-emacs-state-cursor '("cyan" box)
evil-insert-state-cursor 'bar
evil-visual-state-cursor 'hollow)
;; NOTE: a bug in emacs 25 breaks undoing in evil. See
;; https://bitbucket.org/lyro/evil/issues/594/undo-doesnt-behave-like-vim
(setq-default evil-want-fine-undo (if (> emacs-major-version 24) 'fine 'no))
(evil-mode 1)
(evil-select-search-module 'evil-search-module 'evil-search)
(evil-define-key 'normal evil-command-window-mode-map [escape] 'kill-buffer-and-window)
(map! :map evil-command-window-mode-map :n [escape] 'kill-buffer-and-window)
;; modes to map to different default states
(dolist (mode-map '((compilation-mode . normal)
(help-mode . normal)
(message-mode . normal)
(debugger-mode . normal)
(image-mode . normal)
(doc-view-mode . normal)
(profile-report-mode . emacs)
(Info-mode . emacs)
(view-mode . emacs)
@ -64,33 +64,12 @@
(term-mode . emacs)
(calendar-mode . emacs)
(Man-mode . emacs)
(grep-mode . emacs)
(image-mode . normal)
(doc-view-mode . normal)
))
(grep-mode . emacs)))
(evil-set-initial-state `,(car mode-map) `,(cdr mode-map)))
;; Shortcuts for the evil expression register
(defmacro $= (str &rest args)
`(calc-eval (format ,str ,@args)))
(defmacro $r (char)
`(evil-get-register ,char))
(defmacro $expand (path)
`(evil-ex-replace-special-filenames ,path))
;; buffer-local ex commands, thanks to:
;; http://emacs.stackexchange.com/questions/13186
(defun evil-ex-define-cmd-local (cmd function)
"Locally binds the function FUNCTION to the command CMD."
(unless (local-variable-p 'evil-ex-commands)
(setq-local evil-ex-commands (copy-alist evil-ex-commands)))
(evil-ex-define-cmd cmd function))
;; Shortcuts for `evil-ex-define-cmd'
(defalias 'exmap 'evil-ex-define-cmd)
(defalias 'exmap! 'evil-ex-define-cmd-local)
(progn ; evil hacks
(defadvice evil-force-normal-state (after evil-esc-quit activate)
(advice-add 'evil-force-normal-state :after 'narf*evil-esc-quit)
(defun narf*evil-esc-quit ()
"Close popups, disable search highlights and quit the minibuffer if open."
(when (minibuffer-window-active-p (minibuffer-window))
(abort-recursive-edit))
@ -106,7 +85,8 @@
(narf--popup-remove w)))
narf-popup-windows)))
;; Fix disruptive errors w/ hidden buffers caused by workgroups killing windows
;; Fix harmless (yet disruptive) error reporting w/ hidden buffers caused by
;; workgroups killing windows
;; TODO Delete timer on dead windows
(defadvice evil-ex-hl-do-update-highlight (around evil-ex-hidden-buffer-ignore-errors activate)
(ignore-errors ad-do-it))
@ -231,7 +211,7 @@
:move-point nil
(interactive "<r><g//><!>")
(evil-ex-global beg end pattern command invert))
(exmap "g[lobal]" 'narf:evil-ex-global))
(evil-ex-define-cmd "g[lobal]" 'narf:evil-ex-global))
;; evil plugins
(use-package evil-anzu
@ -270,11 +250,11 @@
:nv "M-d" 'evil-multiedit-match-and-next
:nv "M-D" 'evil-multiedit-match-and-prev)
:config
(map! :v "RET" 'evil-multiedit-toggle-or-restrict-region
(:map evil-multiedit-state-map
(map! (:map evil-multiedit-state-map
"RET" 'evil-multiedit-toggle-or-restrict-region
"C-n" 'evil-multiedit-next
"C-p" 'evil-multiedit-prev)
"C-p" 'evil-multiedit-prev
:v "RET" 'evil-multiedit-toggle-or-restrict-region)
(:map evil-multiedit-insert-state-map
"C-n" 'evil-multiedit-next
"C-p" 'evil-multiedit-prev)))
@ -287,22 +267,22 @@
evil-indent-plus-i-indent-up-down
evil-indent-plus-a-indent-up-down)
:init
(map! (:map evil-inner-text-objects-map
"i" 'evil-indent-plus-i-indent
"I" 'evil-indent-plus-i-indent-up
"J" 'evil-indent-plus-i-indent-up-down)
(:map evil-outer-text-objects-map
"i" 'evil-indent-plus-a-indent
"I" 'evil-indent-plus-a-indent-up
"J" 'evil-indent-plus-a-indent-up-down)))
(map! :map evil-inner-text-objects-map
"i" 'evil-indent-plus-i-indent
"I" 'evil-indent-plus-i-indent-up
"J" 'evil-indent-plus-i-indent-up-down
:map evil-outer-text-objects-map
"i" 'evil-indent-plus-a-indent
"I" 'evil-indent-plus-a-indent-up
"J" 'evil-indent-plus-a-indent-up-down))
(use-package evil-matchit
:commands (evilmi-jump-items evilmi-text-object global-evil-matchit-mode)
:config (global-evil-matchit-mode 1)
:init
(define-key evil-normal-state-map "%" #'evilmi-jump-items)
(define-key evil-inner-text-objects-map "%" #'evilmi-text-object)
(define-key evil-outer-text-objects-map "%" #'evilmi-text-object))
(map! :n "%" 'evilmi-jump-items
:map evil-inner-text-objects-map "%" 'evilmi-text-object
:map evil-outer-text-objects-map "%" 'evilmi-text-object))
(use-package evil-numbers
:commands (evil-numbers/inc-at-pt evil-numbers/dec-at-pt))
@ -310,8 +290,8 @@
(use-package evil-textobj-anyblock
:commands (evil-textobj-anyblock-inner-block evil-textobj-anyblock-a-block)
:init
(define-key evil-inner-text-objects-map "B" 'evil-textobj-anyblock-inner-block)
(define-key evil-outer-text-objects-map "B" 'evil-textobj-anyblock-a-block))
(map! :map evil-inner-text-objects-map "B" 'evil-textobj-anyblock-inner-block
:map evil-outer-text-objects-map "B" 'evil-textobj-anyblock-a-block))
(use-package evil-search-highlight-persist
:config
@ -368,16 +348,12 @@
(global-evil-surround-mode 1)
(add-hook! org-mode
(mapc (lambda (p) (add-to-list 'evil-surround-pairs-alist p))
'((?l . narf/evil-surround-latex))))
(push '(?l . narf/evil-surround-latex) evil-surround-pairs-alist))
(add-hook! emacs-lisp-mode
(setq evil-surround-pairs-alist
(cons '(?\` . ("`" . "'")) evil-surround-pairs-alist)))
(push '(?\` . ("`" . "'")) evil-surround-pairs-alist))
(add-hook! python-mode
(setq evil-surround-pairs-alist
(cons '(?d . ("\"\"\"" . "\"\"\"")) evil-surround-pairs-alist)))
(push '((?d . ("\"\"\"" . "\"\"\"")))
evil-surround-pairs-alist))
;; Escaped surround characters
(setq-default evil-surround-pairs-alist
@ -395,7 +371,7 @@
(use-package evil-escape
:config
(setq evil-escape-key-sequence "jk"
evil-escape-delay 0.2)
evil-escape-delay 0.25)
;; evil-escape causes noticable lag in linewise motions in visual mode, so only enable
;; it in insert mode. (I only need jk for insert mode anyway)

View file

@ -24,5 +24,19 @@
(mapc (lambda (cmd) (narf/evil-ex-undefine-cmd (car cmd)))
',commands))))
;; Shortcuts for the evil expression register
;;;###autoload
(defmacro $= (str &rest args)
`(calc-eval (format ,str ,@args)))
;;;###autoload
(defmacro $r (char)
`(evil-get-register ,char))
;;;###autoload
(defmacro $expand (path)
`(evil-ex-replace-special-filenames ,path))
(provide 'macros-evil)
;;; macros-evil.el ends here

View file

@ -1,90 +1,90 @@
;;; my-commands.el
;; Emacs utilities
(exmap "echo" 'narf:echo)
(exmap "minor" 'helm-describe-modes) ; list minor modes
(evil-ex-define-cmd "echo" 'narf:echo)
(evil-ex-define-cmd "minor" 'helm-describe-modes) ; list minor modes
;; Quick mapping keys to commands, allows :nmap \m !make
(exmap "nmap" 'narf:nmap)
(exmap "imap" 'narf:imap)
(exmap "vmap" 'narf:vmap)
(exmap "mmap" 'narf:mmap)
(exmap "omap" 'narf:omap)
(evil-ex-define-cmd "nmap" 'narf:nmap)
(evil-ex-define-cmd "imap" 'narf:imap)
(evil-ex-define-cmd "vmap" 'narf:vmap)
(evil-ex-define-cmd "mmap" 'narf:mmap)
(evil-ex-define-cmd "omap" 'narf:omap)
;; Editing
(exmap "@" 'narf/evil-macro-on-all-lines) ; run macro on each line
(exmap "al[ign]" 'narf:align) ; align by regexp
(exmap "na[rrow]" 'narf:narrow) ; narrow buffer to selection
(exmap "ref[actor]" 'emr-show-refactor-menu) ; open emr menu
(exmap "retab" 'narf:whitespace-retab)
(exmap "settr[im]" 'narf:toggle-delete-trailing-whitespace)
(exmap "snip[pets]" 'narf:yas-snippets) ; visit a snippet
(exmap "tsnip[pets]" 'narf:yas-file-templates) ; visit a file template
(exmap "wal[ign]" 'narf:whitespace-align) ; align spaces
(exmap "rec[ent]" 'narf:helm-recentf) ; show recent files in helm
(exmap "reo[rient]" 'narf/window-reorient) ; scroll all windows to left
(exmap "ie[dit]" 'evil-multiedit-ex-match)
(evil-ex-define-cmd "@" 'narf/evil-macro-on-all-lines) ; run macro on each line
(evil-ex-define-cmd "al[ign]" 'narf:align) ; align by regexp
(evil-ex-define-cmd "na[rrow]" 'narf:narrow) ; narrow buffer to selection
(evil-ex-define-cmd "ref[actor]" 'emr-show-refactor-menu) ; open emr menu
(evil-ex-define-cmd "retab" 'narf:whitespace-retab)
(evil-ex-define-cmd "settr[im]" 'narf:toggle-delete-trailing-whitespace)
(evil-ex-define-cmd "snip[pets]" 'narf:yas-snippets) ; visit a snippet
(evil-ex-define-cmd "tsnip[pets]" 'narf:yas-file-templates) ; visit a file template
(evil-ex-define-cmd "wal[ign]" 'narf:whitespace-align) ; align spaces
(evil-ex-define-cmd "rec[ent]" 'narf:helm-recentf) ; show recent files in helm
(evil-ex-define-cmd "reo[rient]" 'narf/window-reorient) ; scroll all windows to left
(evil-ex-define-cmd "ie[dit]" 'evil-multiedit-ex-match)
;; External resources
(exmap "dash" 'narf:dash) ; look up in Dash.app
(exmap "http" 'httpd-start) ; start http server
(exmap "re[gex]" 'narf:regex) ; open re-builder
(exmap "repl" 'narf:repl) ; invoke or send to repl
(exmap "t[mux]" 'narf:tmux) ; send to tmux
(exmap "tcd" 'narf:tmux-cd) ; cd to default-directory in tmux
(exmap "x" 'narf:send-to-scratch-or-org)
(evil-ex-define-cmd "dash" 'narf:dash) ; look up in Dash.app
(evil-ex-define-cmd "http" 'httpd-start) ; start http server
(evil-ex-define-cmd "re[gex]" 'narf:regex) ; open re-builder
(evil-ex-define-cmd "repl" 'narf:repl) ; invoke or send to repl
(evil-ex-define-cmd "t[mux]" 'narf:tmux) ; send to tmux
(evil-ex-define-cmd "tcd" 'narf:tmux-cd) ; cd to default-directory in tmux
(evil-ex-define-cmd "x" 'narf:send-to-scratch-or-org)
;; GIT
(exmap "gbr[owse]" 'narf:git-remote-browse) ; show file in github/gitlab
(evil-ex-define-cmd "gbr[owse]" 'narf:git-remote-browse) ; show file in github/gitlab
;; Dealing with buffers
(exmap "k[ill]" 'narf/kill-real-buffer) ; Kill current buffer
(exmap "k[ill]all" 'narf:kill-all-buffers) ; Kill all buffers (bang = in project)
(exmap "k[ill]buried" 'narf:kill-buried-buffers) ; Kill all buried buffers (bang = in project)
(exmap "k[ill]o" 'narf:kill-other-buffers) ; kill all other buffers
(exmap "k[ill]unreal" 'narf/kill-unreal-buffers) ; kill unreal buffers
(exmap "k[ill]match" 'narf:kill-matching-buffers) ; kill buffers that match regexp
(exmap "l[ast]" 'narf/popup-last-buffer) ; pop up last popup
(exmap "m[sg]" 'narf/popup-messages) ; open *messages* in popup
(evil-ex-define-cmd "k[ill]" 'narf/kill-real-buffer) ; Kill current buffer
(evil-ex-define-cmd "k[ill]all" 'narf:kill-all-buffers) ; Kill all buffers (bang = in project)
(evil-ex-define-cmd "k[ill]buried" 'narf:kill-buried-buffers) ; Kill all buried buffers (bang = in project)
(evil-ex-define-cmd "k[ill]o" 'narf:kill-other-buffers) ; kill all other buffers
(evil-ex-define-cmd "k[ill]unreal" 'narf/kill-unreal-buffers) ; kill unreal buffers
(evil-ex-define-cmd "k[ill]match" 'narf:kill-matching-buffers) ; kill buffers that match regexp
(evil-ex-define-cmd "l[ast]" 'narf/popup-last-buffer) ; pop up last popup
(evil-ex-define-cmd "m[sg]" 'narf/popup-messages) ; open *messages* in popup
;; Project navigation
(exmap "a" 'helm-projectile-find-other-file) ; open alternate file
(exmap "ag" 'narf:helm-ag-search) ; project text search
(exmap "ag[cw]d" 'narf:helm-ag-search-cwd) ; current directory search
(exmap "cd" 'narf:cd)
(exmap "se[arch]" 'narf:helm-swoop) ; in-file search
(evil-ex-define-cmd "a" 'helm-projectile-find-other-file) ; open alternate file
(evil-ex-define-cmd "ag" 'narf:helm-ag-search) ; project text search
(evil-ex-define-cmd "ag[cw]d" 'narf:helm-ag-search-cwd) ; current directory search
(evil-ex-define-cmd "cd" 'narf:cd)
(evil-ex-define-cmd "se[arch]" 'narf:helm-swoop) ; in-file search
;; Project tools
(exmap "ma[ke]" 'narf:build)
(exmap "build" 'narf:build)
(evil-ex-define-cmd "ma[ke]" 'narf:build)
(evil-ex-define-cmd "build" 'narf:build)
;; File operations
(exmap "mv" 'narf:file-move)
(exmap "rm" 'narf:file-delete) ; rm[!]
(evil-ex-define-cmd "mv" 'narf:file-move)
(evil-ex-define-cmd "rm" 'narf:file-delete) ; rm[!]
;; Presentation/demo
(exmap "big" 'big-mode)
(exmap "full[scr]" 'narf:toggle-fullscreen)
(evil-ex-define-cmd "big" 'big-mode)
(evil-ex-define-cmd "full[scr]" 'narf:toggle-fullscreen)
;; Sessions/tabs
(exmap "sl[oad]" 'narf:load-session)
(exmap "ss[ave]" 'narf:save-session)
(exmap "tabs" 'narf/tab-display)
(exmap "tabn[ew]" 'narf:tab-create)
(exmap "tabr[ename]" 'narf:tab-rename)
(exmap "tabc[lose]" 'narf:kill-tab)
(exmap "tabc[lose]o" 'narf:kill-other-tabs)
(exmap "tabn[ext]" 'narf:switch-to-tab-right)
(exmap "tabp[rev]" 'narf:switch-to-tab-left)
(exmap "tabl[ast]" 'narf:switch-to-tab-last)
(evil-ex-define-cmd "sl[oad]" 'narf:load-session)
(evil-ex-define-cmd "ss[ave]" 'narf:save-session)
(evil-ex-define-cmd "tabs" 'narf/tab-display)
(evil-ex-define-cmd "tabn[ew]" 'narf:tab-create)
(evil-ex-define-cmd "tabr[ename]" 'narf:tab-rename)
(evil-ex-define-cmd "tabc[lose]" 'narf:kill-tab)
(evil-ex-define-cmd "tabc[lose]o" 'narf:kill-other-tabs)
(evil-ex-define-cmd "tabn[ext]" 'narf:switch-to-tab-right)
(evil-ex-define-cmd "tabp[rev]" 'narf:switch-to-tab-left)
(evil-ex-define-cmd "tabl[ast]" 'narf:switch-to-tab-last)
;; Org-mode
(exmap "link" 'narf:org-link)
(exmap "att[ach]" 'narf:org-attach) ; attach file to org file
(exmap "org" 'narf:org-helm-search) ; search org notes
(evil-ex-define-cmd "link" 'narf:org-link)
(evil-ex-define-cmd "att[ach]" 'narf:org-attach) ; attach file to org file
(evil-ex-define-cmd "org" 'narf:org-helm-search) ; search org notes
;; Plugins
(after! flycheck
(exmap "er[rors]" (λ! (flycheck-buffer) (flycheck-list-errors))))
(evil-ex-define-cmd "er[rors]" (λ! (flycheck-buffer) (flycheck-list-errors))))
;; Debuggers
(exmap "debug" 'narf:debug)
(evil-ex-define-cmd "debug" 'narf:debug)
(provide 'my-commands)
;;; my-commands.el ends here