From 26eb33e36e2e1225a193f58ea0be195e4ad323c9 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 26 Apr 2018 22:27:08 -0400 Subject: [PATCH] feature/evil: fix :vs/:sp not focusing split w/ a file argument #552 --- modules/feature/evil/autoload/evil.el | 31 +++++++++++++++++++++++++++ modules/feature/evil/config.el | 13 +++-------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/modules/feature/evil/autoload/evil.el b/modules/feature/evil/autoload/evil.el index f2be7d76f..a92bf127d 100644 --- a/modules/feature/evil/autoload/evil.el +++ b/modules/feature/evil/autoload/evil.el @@ -308,3 +308,34 @@ more information on modifiers." path file-name t t 1)))) (replace-regexp-in-string regexp "\\1" file-name t))) +;;;###autoload (autoload '+evil*window-split "feature/evil/autoload/evil" nil t) +(evil-define-command +evil*window-split (&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)) + (recenter) + (when (and (not count) evil-auto-balance-windows) + (balance-windows (window-parent))) + (if file (evil-edit file))) + +;;;###autoload (autoload '+evil*window-vsplit "feature/evil/autoload/evil" nil t) +(evil-define-command +evil*window-vsplit (&optional count file) + "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)) + (recenter) + (when (and (not count) evil-auto-balance-windows) + (balance-windows (window-parent))) + (if file (evil-edit file))) diff --git a/modules/feature/evil/config.el b/modules/feature/evil/config.el index 456e67243..a4da7d186 100644 --- a/modules/feature/evil/config.el +++ b/modules/feature/evil/config.el @@ -128,16 +128,9 @@ table))) (add-hook 'minibuffer-inactive-mode-hook #'+evil*fix-dabbrev-in-minibuffer) - ;; Move to new split -- setting `evil-split-window-below' & - ;; `evil-vsplit-window-right' to non-nil mimics this, but that doesn't update - ;; window history. That means when you delete a new split, Emacs leaves you on - ;; the 2nd to last window on the history stack, which is jarring. - ;; - ;; Also recenters window on cursor in new split - (defun +evil*window-follow (&rest _) (evil-window-down 1) (recenter)) - (advice-add #'evil-window-split :after #'+evil*window-follow) - (defun +evil*window-vfollow (&rest _) (evil-window-right 1) (recenter)) - (advice-add #'evil-window-vsplit :after #'+evil*window-vfollow) + ;; Focus and recenter new splits + (advice-add #'evil-window-split :override #'+evil*window-split) + (advice-add #'evil-window-vsplit :override #'+evil*window-vsplit) ;; These arg types will highlight matches in the current buffer (evil-ex-define-argument-type buffer-match :runner +evil-ex-buffer-match)