From 43030c789eb608e8db9cd84849a3a322aa69692f Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 28 Oct 2019 23:04:12 -0400 Subject: [PATCH] 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. --- modules/editor/evil/autoload/advice.el | 30 +++++++------------------- modules/editor/evil/config.el | 20 +++++++++++------ 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/modules/editor/evil/autoload/advice.el b/modules/editor/evil/autoload/advice.el index 0287244fb..1e79a43ab 100644 --- a/modules/editor/evil/autoload/advice.el +++ b/modules/editor/evil/autoload/advice.el @@ -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") - (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") - (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 diff --git a/modules/editor/evil/config.el b/modules/editor/evil/config.el index 5c9532c31..32a10194d 100644 --- a/modules/editor/evil/config.el +++ b/modules/editor/evil/config.el @@ -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)