From b9d8116734c3ae153e1406970916e1f3167be973 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 2 Feb 2018 14:52:18 -0500 Subject: [PATCH] feature/evil: switch to initial state on change window This used to change to normal mode, but now it respects the buffer's initial state. --- modules/feature/evil/autoload/evil.el | 12 ++++++------ modules/feature/evil/config.el | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/feature/evil/autoload/evil.el b/modules/feature/evil/autoload/evil.el index ea6c0a0c4..5d6caa281 100644 --- a/modules/feature/evil/autoload/evil.el +++ b/modules/feature/evil/autoload/evil.el @@ -205,12 +205,12 @@ evil-window-move-* (e.g. `evil-window-move-far-left')" (save-excursion (apply orig-fn args))) ;;;###autoload -(defun +evil*restore-normal-state-on-windmove (orig-fn &rest args) - "If in anything but normal or motion mode when moving to another window, -restore normal mode. This prevents insert state from bleeding into other modes -across windows." - (unless (memq evil-state '(normal motion emacs)) - (evil-normal-state +1)) +(defun +evil*restore-initial-state-on-windmove (orig-fn &rest args) + "Revert buffer to its initial state when switching to another window. This +prevents states from bleeding into other modes across windows." + (let ((initial-state (evil-initial-state major-mode 'normal))) + (unless (eq evil-state initial-state) + (evil-change-state initial-state))) (apply orig-fn args)) ;;;###autoload diff --git a/modules/feature/evil/config.el b/modules/feature/evil/config.el index 85855eedc..c94ce0c76 100644 --- a/modules/feature/evil/config.el +++ b/modules/feature/evil/config.el @@ -94,8 +94,8 @@ (add-hook 'after-save-hook #'+evil|save-buffer) ;; Make ESC (from normal mode) the universal escaper. See `doom-escape-hook'. (advice-add #'evil-force-normal-state :after #'doom/escape) - ;; Ensure buffer is in normal mode when we leave it and return to it. - (advice-add #'windmove-do-window-select :around #'+evil*restore-normal-state-on-windmove) + ;; Ensure buffer is in initial mode when we leave it and return to it. + (advice-add #'windmove-do-window-select :around #'+evil*restore-initial-state-on-windmove) ;; Don't move cursor when indenting (advice-add #'evil-indent :around #'+evil*static-reindent) ;; monkey patch `evil-ex-replace-special-filenames' to add more ex