editor/evil: revert focus-on-split behavior (and refactor advice)

Focus-on-split is being disabled to achieve vim parity. The advice is
still necessary to ensure splitting updates the window buffer list, so
operations like winner-undo undoes correctly.
This commit is contained in:
Henrik Lissner 2019-10-28 23:04:12 -04:00
parent be08f9794e
commit 43030c789e
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 21 additions and 29 deletions

View file

@ -149,22 +149,15 @@ more information on modifiers."
(let ((evil-auto-indent evil-auto-indent))
(funcall orig-fn count)))))
;;;###autoload
(defun +evil--static-reindent-a (orig-fn &rest args)
"Don't move cursor on indent."
(save-excursion (apply orig-fn args)))
;;;###autoload (autoload '+evil-window-split-a "editor/evil/autoload/advice" nil t)
(evil-define-command +evil-window-split-a (&optional count file)
"Same as `evil-window-split', but focuses (and recenters) the new split."
:repeat nil
(interactive "P<f>")
(split-window (selected-window) count
(if evil-split-window-below 'above 'below))
(call-interactively
(if evil-split-window-below
#'evil-window-up
#'evil-window-down))
(let ((win (selected-window)))
(split-window (selected-window) count
(if evil-split-window-below 'above 'below))
(select-window win))
(recenter)
(when (and (not count) evil-auto-balance-windows)
(balance-windows (window-parent)))
@ -175,22 +168,15 @@ more information on modifiers."
"Same as `evil-window-vsplit', but focuses (and recenters) the new split."
:repeat nil
(interactive "P<f>")
(split-window (selected-window) count
(if evil-vsplit-window-right 'left 'right))
(call-interactively
(if evil-vsplit-window-right
#'evil-window-left
#'evil-window-right))
(let ((win (selected-window)))
(split-window (selected-window) count
(if evil-vsplit-window-right 'left 'right))
(select-window win))
(recenter)
(when (and (not count) evil-auto-balance-windows)
(balance-windows (window-parent)))
(if file (evil-edit file)))
;;;###autoload
(defun +evil--make-numbered-markers-global-a (orig-fn char)
(or (and (>= char ?2) (<= char ?9))
(funcall orig-fn char)))
;;;###autoload
(defun +evil--fix-dabbrev-in-minibuffer-h ()
"Make `try-expand-dabbrev' from `hippie-expand' work in minibuffer. See

View file

@ -25,8 +25,6 @@ directives. By default, this only recognizes C directives.")
(defvar evil-want-C-w-scroll t)
(defvar evil-want-Y-yank-to-eol t)
(defvar evil-want-abbrev-expand-on-insert-exit nil)
(defvar evil-split-window-below t)
(defvar evil-vsplit-window-right t)
(use-package! evil
:hook (doom-init-modules . evil-mode)
@ -122,10 +120,21 @@ directives. By default, this only recognizes C directives.")
(buffer-name))
(count-lines (point-min) (point-max))
(buffer-size)))))
;; 'gq' moves the cursor to the beginning of selection. Disable this, since
;; it's more disruptive than helpful.
(defadvice! +evil--dont-move-cursor-a (orig-fn &rest args)
:around #'evil-indent
(save-excursion (apply orig-fn args)))
;; In evil, registers 2-9 are buffer-local. In vim, they're global, so...
(defadvice! +evil--make-numbered-markers-global-a (arg)
:after-until #'evil-global-marker-p
(and (>= char ?2) (<= char ?9)))
;; Make ESC (from normal mode) the universal escaper. See `doom-escape-hook'.
(advice-add #'evil-force-normal-state :after #'+evil-escape-a)
;; Don't move cursor when indenting
(advice-add #'evil-indent :around #'+evil--static-reindent-a)
;; monkey patch `evil-ex-replace-special-filenames' to improve support for
;; file modifiers like %:p:h. This adds support for most of vim's modifiers,
;; and one custom one: %:P (expand to the project root).
@ -138,9 +147,6 @@ directives. By default, this only recognizes C directives.")
(advice-add #'evil-window-split :override #'+evil-window-split-a)
(advice-add #'evil-window-vsplit :override #'+evil-window-vsplit-a)
;; In evil, registers 2-9 are buffer-local. In vim, they're global, so...
(advice-add #'evil-global-marker-p :around #'+evil--make-numbered-markers-global-a)
;; Make o/O continue comments (see `+evil-want-o/O-to-continue-comments')
(advice-add #'evil-open-above :around #'+evil--insert-newline-above-and-respect-comments-a)
(advice-add #'evil-open-below :around #'+evil--insert-newline-below-and-respect-comments-a)