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.
This commit is contained in:
Henrik Lissner 2018-02-02 14:52:18 -05:00
parent eaeb495b18
commit b9d8116734
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 8 additions and 8 deletions

View file

@ -205,12 +205,12 @@ evil-window-move-* (e.g. `evil-window-move-far-left')"
(save-excursion (apply orig-fn args))) (save-excursion (apply orig-fn args)))
;;;###autoload ;;;###autoload
(defun +evil*restore-normal-state-on-windmove (orig-fn &rest args) (defun +evil*restore-initial-state-on-windmove (orig-fn &rest args)
"If in anything but normal or motion mode when moving to another window, "Revert buffer to its initial state when switching to another window. This
restore normal mode. This prevents insert state from bleeding into other modes prevents states from bleeding into other modes across windows."
across windows." (let ((initial-state (evil-initial-state major-mode 'normal)))
(unless (memq evil-state '(normal motion emacs)) (unless (eq evil-state initial-state)
(evil-normal-state +1)) (evil-change-state initial-state)))
(apply orig-fn args)) (apply orig-fn args))
;;;###autoload ;;;###autoload

View file

@ -94,8 +94,8 @@
(add-hook 'after-save-hook #'+evil|save-buffer) (add-hook 'after-save-hook #'+evil|save-buffer)
;; Make ESC (from normal mode) the universal escaper. See `doom-escape-hook'. ;; Make ESC (from normal mode) the universal escaper. See `doom-escape-hook'.
(advice-add #'evil-force-normal-state :after #'doom/escape) (advice-add #'evil-force-normal-state :after #'doom/escape)
;; Ensure buffer is in normal mode when we leave it and return to it. ;; Ensure buffer is in initial mode when we leave it and return to it.
(advice-add #'windmove-do-window-select :around #'+evil*restore-normal-state-on-windmove) (advice-add #'windmove-do-window-select :around #'+evil*restore-initial-state-on-windmove)
;; Don't move cursor when indenting ;; Don't move cursor when indenting
(advice-add #'evil-indent :around #'+evil*static-reindent) (advice-add #'evil-indent :around #'+evil*static-reindent)
;; monkey patch `evil-ex-replace-special-filenames' to add more ex ;; monkey patch `evil-ex-replace-special-filenames' to add more ex